Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

dom.js 2.3 KiB

14 år sedan
14 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. // add a new dom element
  23. wn.provide('wn.dom');
  24. wn.dom.by_id = function(id) {
  25. return document.getElementById(id);
  26. }
  27. wn.dom.eval = function(txt) {
  28. var el = document.createElement('script');
  29. el.appendChild(document.createTextNode(txt));
  30. // execute the script globally
  31. document.getElementsByTagName('head')[0].appendChild(el);
  32. }
  33. wn.dom.add = function(parent, newtag, className, cs, innerHTML, onclick) {
  34. if(parent && parent.substr)parent = wn.dom.by_id(parent);
  35. var c = document.createElement(newtag);
  36. if(parent)
  37. parent.appendChild(c);
  38. // if image, 3rd parameter is source
  39. if(className) {
  40. if(newtag.toLowerCase()=='img')
  41. c.src = className
  42. else
  43. c.className = className;
  44. }
  45. if(cs) wn.dom.css(c,cs);
  46. if(innerHTML) c.innerHTML = innerHTML;
  47. if(onclick) c.onclick = onclick;
  48. return c;
  49. }
  50. // add css to element
  51. wn.dom.css= function(ele, s) {
  52. if(ele && s) {
  53. for(var i in s) ele.style[i]=s[i];
  54. };
  55. return ele;
  56. }
  57. wn.get_cookie = function(c) {
  58. var t=""+document.cookie;
  59. var ind=t.indexOf(c);
  60. if (ind==-1 || c=="") return "";
  61. var ind1=t.indexOf(';',ind);
  62. if (ind1==-1) ind1=t.length;
  63. return unescape(t.substring(ind+c.length+1,ind1));
  64. }