Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

436 lines
18 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.DomHelper"></div>/**
  16. * @class Ext.DomHelper
  17. * <p>The DomHelper class provides a layer of abstraction from DOM and transparently supports creating
  18. * elements via DOM or using HTML fragments. It also has the ability to create HTML fragment templates
  19. * from your DOM building code.</p>
  20. *
  21. * <p><b><u>DomHelper element specification object</u></b></p>
  22. * <p>A specification object is used when creating elements. Attributes of this object
  23. * are assumed to be element attributes, except for 4 special attributes:
  24. * <div class="mdetail-params"><ul>
  25. * <li><b><tt>tag</tt></b> : <div class="sub-desc">The tag name of the element</div></li>
  26. * <li><b><tt>children</tt></b> : or <tt>cn</tt><div class="sub-desc">An array of the
  27. * same kind of element definition objects to be created and appended. These can be nested
  28. * as deep as you want.</div></li>
  29. * <li><b><tt>cls</tt></b> : <div class="sub-desc">The class attribute of the element.
  30. * This will end up being either the "class" attribute on a HTML fragment or className
  31. * for a DOM node, depending on whether DomHelper is using fragments or DOM.</div></li>
  32. * <li><b><tt>html</tt></b> : <div class="sub-desc">The innerHTML for the element</div></li>
  33. * </ul></div></p>
  34. *
  35. * <p><b><u>Insertion methods</u></b></p>
  36. * <p>Commonly used insertion methods:
  37. * <div class="mdetail-params"><ul>
  38. * <li><b><tt>{@link #append}</tt></b> : <div class="sub-desc"></div></li>
  39. * <li><b><tt>{@link #insertBefore}</tt></b> : <div class="sub-desc"></div></li>
  40. * <li><b><tt>{@link #insertAfter}</tt></b> : <div class="sub-desc"></div></li>
  41. * <li><b><tt>{@link #overwrite}</tt></b> : <div class="sub-desc"></div></li>
  42. * <li><b><tt>{@link #createTemplate}</tt></b> : <div class="sub-desc"></div></li>
  43. * <li><b><tt>{@link #insertHtml}</tt></b> : <div class="sub-desc"></div></li>
  44. * </ul></div></p>
  45. *
  46. * <p><b><u>Example</u></b></p>
  47. * <p>This is an example, where an unordered list with 3 children items is appended to an existing
  48. * element with id <tt>'my-div'</tt>:<br>
  49. <pre><code>
  50. var dh = Ext.DomHelper; // create shorthand alias
  51. // specification object
  52. var spec = {
  53. id: 'my-ul',
  54. tag: 'ul',
  55. cls: 'my-list',
  56. // append children after creating
  57. children: [ // may also specify 'cn' instead of 'children'
  58. {tag: 'li', id: 'item0', html: 'List Item 0'},
  59. {tag: 'li', id: 'item1', html: 'List Item 1'},
  60. {tag: 'li', id: 'item2', html: 'List Item 2'}
  61. ]
  62. };
  63. var list = dh.append(
  64. 'my-div', // the context element 'my-div' can either be the id or the actual node
  65. spec // the specification object
  66. );
  67. </code></pre></p>
  68. * <p>Element creation specification parameters in this class may also be passed as an Array of
  69. * specification objects. This can be used to insert multiple sibling nodes into an existing
  70. * container very efficiently. For example, to add more list items to the example above:<pre><code>
  71. dh.append('my-ul', [
  72. {tag: 'li', id: 'item3', html: 'List Item 3'},
  73. {tag: 'li', id: 'item4', html: 'List Item 4'}
  74. ]);
  75. * </code></pre></p>
  76. *
  77. * <p><b><u>Templating</u></b></p>
  78. * <p>The real power is in the built-in templating. Instead of creating or appending any elements,
  79. * <tt>{@link #createTemplate}</tt> returns a Template object which can be used over and over to
  80. * insert new elements. Revisiting the example above, we could utilize templating this time:
  81. * <pre><code>
  82. // create the node
  83. var list = dh.append('my-div', {tag: 'ul', cls: 'my-list'});
  84. // get template
  85. var tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'});
  86. for(var i = 0; i < 5, i++){
  87. tpl.append(list, [i]); // use template to append to the actual node
  88. }
  89. * </code></pre></p>
  90. * <p>An example using a template:<pre><code>
  91. var html = '<a id="{0}" href="{1}" class="nav">{2}</a>';
  92. var tpl = new Ext.DomHelper.createTemplate(html);
  93. tpl.append('blog-roll', ['link1', 'http://www.jackslocum.com/', "Jack&#39;s Site"]);
  94. tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin&#39;s Site"]);
  95. * </code></pre></p>
  96. *
  97. * <p>The same example using named parameters:<pre><code>
  98. var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  99. var tpl = new Ext.DomHelper.createTemplate(html);
  100. tpl.append('blog-roll', {
  101. id: 'link1',
  102. url: 'http://www.jackslocum.com/',
  103. text: "Jack&#39;s Site"
  104. });
  105. tpl.append('blog-roll', {
  106. id: 'link2',
  107. url: 'http://www.dustindiaz.com/',
  108. text: "Dustin&#39;s Site"
  109. });
  110. * </code></pre></p>
  111. *
  112. * <p><b><u>Compiling Templates</u></b></p>
  113. * <p>Templates are applied using regular expressions. The performance is great, but if
  114. * you are adding a bunch of DOM elements using the same template, you can increase
  115. * performance even further by {@link Ext.Template#compile "compiling"} the template.
  116. * The way "{@link Ext.Template#compile compile()}" works is the template is parsed and
  117. * broken up at the different variable points and a dynamic function is created and eval'ed.
  118. * The generated function performs string concatenation of these parts and the passed
  119. * variables instead of using regular expressions.
  120. * <pre><code>
  121. var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  122. var tpl = new Ext.DomHelper.createTemplate(html);
  123. tpl.compile();
  124. //... use template like normal
  125. * </code></pre></p>
  126. *
  127. * <p><b><u>Performance Boost</u></b></p>
  128. * <p>DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead
  129. * of DOM can significantly boost performance.</p>
  130. * <p>Element creation specification parameters may also be strings. If {@link #useDom} is <tt>false</tt>,
  131. * then the string is used as innerHTML. If {@link #useDom} is <tt>true</tt>, a string specification
  132. * results in the creation of a text node. Usage:</p>
  133. * <pre><code>
  134. Ext.DomHelper.useDom = true; // force it to use DOM; reduces performance
  135. * </code></pre>
  136. * @singleton
  137. */
  138. Ext.DomHelper = function(){
  139. var tempTableEl = null,
  140. emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i,
  141. tableRe = /^table|tbody|tr|td$/i,
  142. confRe = /tag|children|cn|html$/i,
  143. tableElRe = /td|tr|tbody/i,
  144. cssRe = /([a-z0-9-]+)\s*:\s*([^;\s]+(?:\s*[^;\s]+)*);?/gi,
  145. endRe = /end/i,
  146. pub,
  147. // kill repeat to save bytes
  148. afterbegin = 'afterbegin',
  149. afterend = 'afterend',
  150. beforebegin = 'beforebegin',
  151. beforeend = 'beforeend',
  152. ts = '<table>',
  153. te = '</table>',
  154. tbs = ts+'<tbody>',
  155. tbe = '</tbody>'+te,
  156. trs = tbs + '<tr>',
  157. tre = '</tr>'+tbe;
  158. // private
  159. function doInsert(el, o, returnElement, pos, sibling, append){
  160. var newNode = pub.insertHtml(pos, Ext.getDom(el), createHtml(o));
  161. return returnElement ? Ext.get(newNode, true) : newNode;
  162. }
  163. // build as innerHTML where available
  164. function createHtml(o){
  165. var b = '',
  166. attr,
  167. val,
  168. key,
  169. cn;
  170. if(typeof o == "string"){
  171. b = o;
  172. } else if (Ext.isArray(o)) {
  173. for (var i=0; i < o.length; i++) {
  174. if(o[i]) {
  175. b += createHtml(o[i]);
  176. }
  177. };
  178. } else {
  179. b += '<' + (o.tag = o.tag || 'div');
  180. for (attr in o) {
  181. val = o[attr];
  182. if(!confRe.test(attr)){
  183. if (typeof val == "object") {
  184. b += ' ' + attr + '="';
  185. for (key in val) {
  186. b += key + ':' + val[key] + ';';
  187. };
  188. b += '"';
  189. }else{
  190. b += ' ' + ({cls : 'class', htmlFor : 'for'}[attr] || attr) + '="' + val + '"';
  191. }
  192. }
  193. };
  194. // Now either just close the tag or try to add children and close the tag.
  195. if (emptyTags.test(o.tag)) {
  196. b += '/>';
  197. } else {
  198. b += '>';
  199. if ((cn = o.children || o.cn)) {
  200. b += createHtml(cn);
  201. } else if(o.html){
  202. b += o.html;
  203. }
  204. b += '</' + o.tag + '>';
  205. }
  206. }
  207. return b;
  208. }
  209. function ieTable(depth, s, h, e){
  210. tempTableEl.innerHTML = [s, h, e].join('');
  211. var i = -1,
  212. el = tempTableEl,
  213. ns;
  214. while(++i < depth){
  215. el = el.firstChild;
  216. }
  217. // If the result is multiple siblings, then encapsulate them into one fragment.
  218. if(ns = el.nextSibling){
  219. var df = document.createDocumentFragment();
  220. while(el){
  221. ns = el.nextSibling;
  222. df.appendChild(el);
  223. el = ns;
  224. }
  225. el = df;
  226. }
  227. return el;
  228. }
  229. /**
  230. * @ignore
  231. * Nasty code for IE's broken table implementation
  232. */
  233. function insertIntoTable(tag, where, el, html) {
  234. var node,
  235. before;
  236. tempTableEl = tempTableEl || document.createElement('div');
  237. if(tag == 'td' && (where == afterbegin || where == beforeend) ||
  238. !tableElRe.test(tag) && (where == beforebegin || where == afterend)) {
  239. return;
  240. }
  241. before = where == beforebegin ? el :
  242. where == afterend ? el.nextSibling :
  243. where == afterbegin ? el.firstChild : null;
  244. if (where == beforebegin || where == afterend) {
  245. el = el.parentNode;
  246. }
  247. if (tag == 'td' || (tag == 'tr' && (where == beforeend || where == afterbegin))) {
  248. node = ieTable(4, trs, html, tre);
  249. } else if ((tag == 'tbody' && (where == beforeend || where == afterbegin)) ||
  250. (tag == 'tr' && (where == beforebegin || where == afterend))) {
  251. node = ieTable(3, tbs, html, tbe);
  252. } else {
  253. node = ieTable(2, ts, html, te);
  254. }
  255. el.insertBefore(node, before);
  256. return node;
  257. }
  258. pub = {
  259. <div id="method-Ext.DomHelper-markup"></div>/**
  260. * Returns the markup for the passed Element(s) config.
  261. * @param {Object} o The DOM object spec (and children)
  262. * @return {String}
  263. */
  264. markup : function(o){
  265. return createHtml(o);
  266. },
  267. <div id="method-Ext.DomHelper-applyStyles"></div>/**
  268. * Applies a style specification to an element.
  269. * @param {String/HTMLElement} el The element to apply styles to
  270. * @param {String/Object/Function} styles A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or
  271. * a function which returns such a specification.
  272. */
  273. applyStyles : function(el, styles){
  274. if (styles) {
  275. var matches;
  276. el = Ext.fly(el);
  277. if (typeof styles == "function") {
  278. styles = styles.call();
  279. }
  280. if (typeof styles == "string") {
  281. <div id="prop-Ext.DomHelper-lastIndex"></div>/**
  282. * Since we're using the g flag on the regex, we need to set the lastIndex.
  283. * This automatically happens on some implementations, but not others, see:
  284. * http://stackoverflow.com/questions/2645273/javascript-regular-expression-literal-persists-between-function-calls
  285. * http://blog.stevenlevithan.com/archives/fixing-javascript-regexp
  286. */
  287. cssRe.lastIndex = 0;
  288. while ((matches = cssRe.exec(styles))) {
  289. el.setStyle(matches[1], matches[2]);
  290. }
  291. } else if (typeof styles == "object") {
  292. el.setStyle(styles);
  293. }
  294. }
  295. },
  296. <div id="method-Ext.DomHelper-insertHtml"></div>/**
  297. * Inserts an HTML fragment into the DOM.
  298. * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
  299. * @param {HTMLElement} el The context element
  300. * @param {String} html The HTML fragment
  301. * @return {HTMLElement} The new node
  302. */
  303. insertHtml : function(where, el, html){
  304. var hash = {},
  305. hashVal,
  306. setStart,
  307. range,
  308. frag,
  309. rangeEl,
  310. rs;
  311. where = where.toLowerCase();
  312. // add these here because they are used in both branches of the condition.
  313. hash[beforebegin] = ['BeforeBegin', 'previousSibling'];
  314. hash[afterend] = ['AfterEnd', 'nextSibling'];
  315. if (el.insertAdjacentHTML) {
  316. if(tableRe.test(el.tagName) && (rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html))){
  317. return rs;
  318. }
  319. // add these two to the hash.
  320. hash[afterbegin] = ['AfterBegin', 'firstChild'];
  321. hash[beforeend] = ['BeforeEnd', 'lastChild'];
  322. if ((hashVal = hash[where])) {
  323. el.insertAdjacentHTML(hashVal[0], html);
  324. return el[hashVal[1]];
  325. }
  326. } else {
  327. range = el.ownerDocument.createRange();
  328. setStart = 'setStart' + (endRe.test(where) ? 'After' : 'Before');
  329. if (hash[where]) {
  330. range[setStart](el);
  331. frag = range.createContextualFragment(html);
  332. el.parentNode.insertBefore(frag, where == beforebegin ? el : el.nextSibling);
  333. return el[(where == beforebegin ? 'previous' : 'next') + 'Sibling'];
  334. } else {
  335. rangeEl = (where == afterbegin ? 'first' : 'last') + 'Child';
  336. if (el.firstChild) {
  337. range[setStart](el[rangeEl]);
  338. frag = range.createContextualFragment(html);
  339. if(where == afterbegin){
  340. el.insertBefore(frag, el.firstChild);
  341. }else{
  342. el.appendChild(frag);
  343. }
  344. } else {
  345. el.innerHTML = html;
  346. }
  347. return el[rangeEl];
  348. }
  349. }
  350. throw 'Illegal insertion point -> "' + where + '"';
  351. },
  352. <div id="method-Ext.DomHelper-insertBefore"></div>/**
  353. * Creates new DOM element(s) and inserts them before el.
  354. * @param {Mixed} el The context element
  355. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  356. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  357. * @return {HTMLElement/Ext.Element} The new node
  358. */
  359. insertBefore : function(el, o, returnElement){
  360. return doInsert(el, o, returnElement, beforebegin);
  361. },
  362. <div id="method-Ext.DomHelper-insertAfter"></div>/**
  363. * Creates new DOM element(s) and inserts them after el.
  364. * @param {Mixed} el The context element
  365. * @param {Object} o The DOM object spec (and children)
  366. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  367. * @return {HTMLElement/Ext.Element} The new node
  368. */
  369. insertAfter : function(el, o, returnElement){
  370. return doInsert(el, o, returnElement, afterend, 'nextSibling');
  371. },
  372. <div id="method-Ext.DomHelper-insertFirst"></div>/**
  373. * Creates new DOM element(s) and inserts them as the first child of el.
  374. * @param {Mixed} el The context element
  375. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  376. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  377. * @return {HTMLElement/Ext.Element} The new node
  378. */
  379. insertFirst : function(el, o, returnElement){
  380. return doInsert(el, o, returnElement, afterbegin, 'firstChild');
  381. },
  382. <div id="method-Ext.DomHelper-append"></div>/**
  383. * Creates new DOM element(s) and appends them to el.
  384. * @param {Mixed} el The context element
  385. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  386. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  387. * @return {HTMLElement/Ext.Element} The new node
  388. */
  389. append : function(el, o, returnElement){
  390. return doInsert(el, o, returnElement, beforeend, '', true);
  391. },
  392. <div id="method-Ext.DomHelper-overwrite"></div>/**
  393. * Creates new DOM element(s) and overwrites the contents of el with them.
  394. * @param {Mixed} el The context element
  395. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  396. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  397. * @return {HTMLElement/Ext.Element} The new node
  398. */
  399. overwrite : function(el, o, returnElement){
  400. el = Ext.getDom(el);
  401. el.innerHTML = createHtml(o);
  402. return returnElement ? Ext.get(el.firstChild) : el.firstChild;
  403. },
  404. createHtml : createHtml
  405. };
  406. return pub;
  407. }();
  408. </pre>
  409. </body>
  410. </html>