3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">/*
\r
9 * This file corrects air eval issues and other issues found in the AIR application sandbox
\r
11 Ext.namespace('Ext.air', 'Ext.sql');
\r
13 Ext.Template.prototype.compile = function() {
\r
14 var fm = Ext.util.Format;
\r
15 var useF = this.disableFormats !== true;
\r
20 var fn = function(m, name, format, args, offset, s){
\r
21 if (prevOffset != offset) {
\r
22 var action = {type: 1, value: s.substr(prevOffset, offset - prevOffset)};
\r
25 prevOffset = offset + m.length;
\r
28 var re = /^\s*['"](.*)["']\s*$/;
\r
29 args = args.split(/,(?=(?:[^"]*"[^"]*")*(?![^"]*"))/);
\r
30 for(var i = 0, len = args.length; i < len; i++){
\r
31 args[i] = args[i].replace(re, "$1");
\r
33 args = [''].concat(args);
\r
37 if(format.substr(0, 5) != "this."){
\r
38 var action = {type: 3, value:name, format: fm[format], args: args, scope: fm};
\r
41 var action = {type: 3, value:name, format:tpl[format.substr(5)], args:args, scope: tpl};
\r
45 var action = {type: 2, value: name};
\r
51 var s = this.html.replace(this.re, fn);
\r
52 if (prevOffset != (s.length - 1)) {
\r
53 var action = {type: 1, value: s.substr(prevOffset, s.length - prevOffset)};
\r
57 this.compiled = function(values) {
\r
58 function applyValues(el) {
\r
63 return (values[el.value] ? values[el.value] : '');
\r
65 el.args[0] = values[el.value];
\r
66 return el.format.apply(el.scope, el.args);
\r
69 return arr.map(applyValues).join('');
\r
74 Ext.Template.prototype.call = function(fnName, value, allValues){
\r
75 return this[fnName](value, allValues);
\r
79 Ext.DomQuery = function(){
\r
80 var cache = {}, simpleCache = {}, valueCache = {};
\r
81 var nonSpace = /\S/;
\r
82 var trimRe = /^\s+|\s+$/g;
\r
83 var tplRe = /\{(\d+)\}/g;
\r
84 var modeRe = /^(\s?[\/>+~]\s?|\s|$)/;
\r
85 var tagTokenRe = /^(#)?([\w-\*]+)/;
\r
86 var nthRe = /(\d*)n\+?(\d*)/, nthRe2 = /\D/;
\r
88 function child(p, index){
\r
90 var n = p.firstChild;
\r
92 if(n.nodeType == 1){
\r
103 while((n = n.nextSibling) && n.nodeType != 1);
\r
108 while((n = n.previousSibling) && n.nodeType != 1);
\r
112 function children(d){
\r
113 var n = d.firstChild, ni = -1;
\r
115 var nx = n.nextSibling;
\r
116 if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
\r
119 n.nodeIndex = ++ni;
\r
126 function byClassName(c, a, v){
\r
130 var r = [], ri = -1, cn;
\r
131 for(var i = 0, ci; ci = c[i]; i++){
\r
132 if((' '+ci.className+' ').indexOf(v) != -1){
\r
139 function attrValue(n, attr){
\r
140 if(!n.tagName && typeof n.length != "undefined"){
\r
149 if(attr == "class" || attr == "className"){
\r
150 return n.className;
\r
152 return n.getAttribute(attr) || n[attr];
\r
156 function getNodes(ns, mode, tagName){
\r
157 var result = [], ri = -1, cs;
\r
161 tagName = tagName || "*";
\r
162 if(typeof ns.getElementsByTagName != "undefined"){
\r
166 for(var i = 0, ni; ni = ns[i]; i++){
\r
167 cs = ni.getElementsByTagName(tagName);
\r
168 for(var j = 0, ci; ci = cs[j]; j++){
\r
172 }else if(mode == "/" || mode == ">"){
\r
173 var utag = tagName.toUpperCase();
\r
174 for(var i = 0, ni, cn; ni = ns[i]; i++){
\r
175 cn = ni.children || ni.childNodes;
\r
176 for(var j = 0, cj; cj = cn[j]; j++){
\r
177 if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
\r
182 }else if(mode == "+"){
\r
183 var utag = tagName.toUpperCase();
\r
184 for(var i = 0, n; n = ns[i]; i++){
\r
185 while((n = n.nextSibling) && n.nodeType != 1);
\r
186 if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
\r
190 }else if(mode == "~"){
\r
191 for(var i = 0, n; n = ns[i]; i++){
\r
192 while((n = n.nextSibling) && (n.nodeType != 1 || (tagName == '*' || n.tagName.toLowerCase()!=tagName)));
\r
201 function concat(a, b){
\r
203 return a.concat(b);
\r
205 for(var i = 0, l = b.length; i < l; i++){
\r
206 a[a.length] = b[i];
\r
211 function byTag(cs, tagName){
\r
212 if(cs.tagName || cs == document){
\r
218 var r = [], ri = -1;
\r
219 tagName = tagName.toLowerCase();
\r
220 for(var i = 0, ci; ci = cs[i]; i++){
\r
221 if(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){
\r
228 function byId(cs, attr, id){
\r
229 if(cs.tagName || cs == document){
\r
235 var r = [], ri = -1;
\r
236 for(var i = 0,ci; ci = cs[i]; i++){
\r
237 if(ci && ci.id == id){
\r
245 function byAttribute(cs, attr, value, op, custom){
\r
246 var r = [], ri = -1, st = custom=="{";
\r
247 var f = Ext.DomQuery.operators[op];
\r
248 for(var i = 0, ci; ci = cs[i]; i++){
\r
251 a = Ext.DomQuery.getStyle(ci, attr);
\r
253 else if(attr == "class" || attr == "className"){
\r
255 }else if(attr == "for"){
\r
257 }else if(attr == "href"){
\r
258 a = ci.getAttribute("href", 2);
\r
260 a = ci.getAttribute(attr);
\r
262 if((f && f(a, value)) || (!f && a)){
\r
269 function byPseudo(cs, name, value){
\r
270 return Ext.DomQuery.pseudos[name](cs, value);
\r
274 // this eval is stop the compressor from
\r
275 // renaming the variable to something shorter
\r
276 eval("var batch = 30803;");
\r
280 function nodup(cs){
\r
284 var len = cs.length, c, i, r = cs, cj, ri = -1;
\r
285 if(!len || typeof cs.nodeType != "undefined" || len == 1){
\r
290 for(i = 1; c = cs[i]; i++){
\r
295 for(var j = 0; j < i; j++){
\r
298 for(j = i+1; cj = cs[j]; j++){
\r
299 if(cj._nodup != d){
\r
310 function quickDiff(c1, c2){
\r
311 var len1 = c1.length;
\r
316 for(var i = 0; i < len1; i++){
\r
320 for(var i = 0, len = c2.length; i < len; i++){
\r
321 if(c2[i]._qdiff != d){
\r
322 r[r.length] = c2[i];
\r
328 function quickId(ns, mode, root, id){
\r
330 var d = root.ownerDocument || root;
\r
331 return d.getElementById(id);
\r
333 ns = getNodes(ns, mode, "*");
\r
334 return byId(ns, null, id);
\r
337 function search(path, root, type) {
\r
338 type = type || "select";
\r
340 var n = root || document;
\r
342 var q = path, mode, lq;
\r
343 var tk = Ext.DomQuery.matchers;
\r
344 var tklen = tk.length;
\r
347 var lmode = q.match(modeRe);
\r
348 if(lmode && lmode[1]){
\r
349 mode=lmode[1].replace(trimRe, "");
\r
350 q = q.replace(lmode[1], "");
\r
352 while(path.substr(0, 1)=="/"){
\r
353 path = path.substr(1);
\r
355 while(q && lq != q){
\r
357 var tm = q.match(tagTokenRe);
\r
358 if(type == "select"){
\r
361 n = quickId(n, mode, root, tm[2]);
\r
363 n = getNodes(n, mode, tm[2]);
\r
365 q = q.replace(tm[0], "");
\r
366 }else if(q.substr(0, 1) != '@'){
\r
367 n = getNodes(n, mode, "*");
\r
372 n = byId(n, null, tm[2]);
\r
374 n = byTag(n, tm[2]);
\r
376 q = q.replace(tm[0], "");
\r
379 while(!(mm = q.match(modeRe))){
\r
380 var matched = false;
\r
381 for(var j = 0; j < tklen; j++){
\r
383 var m = q.match(t.re);
\r
387 n = byClassName(n, null, " " + m[1] +" ");
\r
390 n = byPseudo(n, m[1], m[2]);
\r
393 n = byAttribute(n, m[2], m[4], m[3], m[1]);
\r
396 n = byId(n, null, m[1]);
\r
399 return {firstChild:{nodeValue:attrValue(n, m[1])}};
\r
402 q = q.replace(m[0], "");
\r
409 throw 'Error parsing selector, parsing failed at "' + q + '"';
\r
413 mode=mm[1].replace(trimRe, "");
\r
414 q = q.replace(mm[1], "");
\r
421 getStyle : function(el, name){
\r
422 return Ext.fly(el).getStyle(name);
\r
425 compile: function(path, type) {
\r
426 return function(root) {
\r
427 return search(path, root, type);
\r
431 <div id="method-Ext.air.DragType-select"></div>/**
\r
432 * Selects a group of elements.
\r
433 * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
\r
434 * @param {Node} root (optional) The start of the query (defaults to document).
\r
437 select : function(path, root, type){
\r
438 if(!root || root == document){
\r
441 if(typeof root == "string"){
\r
442 root = document.getElementById(root);
\r
444 var paths = path.split(",");
\r
446 for(var i = 0, len = paths.length; i < len; i++){
\r
447 var p = paths[i].replace(trimRe, "");
\r
449 cache[p] = Ext.DomQuery.compile(p);
\r
451 throw p + " is not a valid selector";
\r
454 var result = cache[p](root);
\r
455 if(result && result != document){
\r
456 results = results.concat(result);
\r
459 if(paths.length > 1){
\r
460 return nodup(results);
\r
465 <div id="method-Ext.air.DragType-selectNode"></div>/**
\r
466 * Selects a single element.
\r
467 * @param {String} selector The selector/xpath query
\r
468 * @param {Node} root (optional) The start of the query (defaults to document).
\r
469 * @return {Element}
\r
471 selectNode : function(path, root){
\r
472 return Ext.DomQuery.select(path, root)[0];
\r
475 <div id="method-Ext.air.DragType-selectValue"></div>/**
\r
476 * Selects the value of a node, optionally replacing null with the defaultValue.
\r
477 * @param {String} selector The selector/xpath query
\r
478 * @param {Node} root (optional) The start of the query (defaults to document).
\r
479 * @param {String} defaultValue
\r
481 selectValue : function(path, root, defaultValue){
\r
482 path = path.replace(trimRe, "");
\r
483 if(!valueCache[path]){
\r
484 valueCache[path] = Ext.DomQuery.compile(path, "select");
\r
486 var n = valueCache[path](root);
\r
487 n = n[0] ? n[0] : n;
\r
488 var v = (n && n.firstChild ? n.firstChild.nodeValue : null);
\r
489 return ((v === null||v === undefined||v==='') ? defaultValue : v);
\r
492 <div id="method-Ext.air.DragType-selectNumber"></div>/**
\r
493 * Selects the value of a node, parsing integers and floats.
\r
494 * @param {String} selector The selector/xpath query
\r
495 * @param {Node} root (optional) The start of the query (defaults to document).
\r
496 * @param {Number} defaultValue
\r
499 selectNumber : function(path, root, defaultValue){
\r
500 var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
\r
501 return parseFloat(v);
\r
504 <div id="method-Ext.air.DragType-is"></div>/**
\r
505 * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
\r
506 * @param {String/HTMLElement/Array} el An element id, element or array of elements
\r
507 * @param {String} selector The simple selector to test
\r
508 * @return {Boolean}
\r
510 is : function(el, ss){
\r
511 if(typeof el == "string"){
\r
512 el = document.getElementById(el);
\r
514 var isArray = Ext.isArray(el);
\r
515 var result = Ext.DomQuery.filter(isArray ? el : [el], ss);
\r
516 return isArray ? (result.length == el.length) : (result.length > 0);
\r
519 <div id="method-Ext.air.DragType-filter"></div>/**
\r
520 * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
\r
521 * @param {Array} el An array of elements to filter
\r
522 * @param {String} selector The simple selector to test
\r
523 * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
\r
524 * the selector instead of the ones that match
\r
527 filter : function(els, ss, nonMatches){
\r
528 ss = ss.replace(trimRe, "");
\r
529 if(!simpleCache[ss]){
\r
530 simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");
\r
532 var result = simpleCache[ss](els);
\r
533 return nonMatches ? quickDiff(result, els) : result;
\r
536 <div id="prop-Ext.air.DragType-matchers"></div>/**
\r
537 * Collection of matching regular expressions and code snippets.
\r
541 select: 'n = byClassName(n, null, " {1} ");'
\r
543 re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
\r
544 select: 'n = byPseudo(n, "{1}", "{2}");'
\r
546 re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
\r
547 select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
\r
550 select: 'n = byId(n, null, "{1}");'
\r
553 select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
\r
557 <div id="method-Ext.air.DragType-operators"></div>/**
\r
558 * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
\r
559 * New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, > <.
\r
562 "=" : function(a, v){
\r
565 "!=" : function(a, v){
\r
568 "^=" : function(a, v){
\r
569 return a && a.substr(0, v.length) == v;
\r
571 "$=" : function(a, v){
\r
572 return a && a.substr(a.length-v.length) == v;
\r
574 "*=" : function(a, v){
\r
575 return a && a.indexOf(v) !== -1;
\r
577 "%=" : function(a, v){
\r
578 return (a % v) == 0;
\r
580 "|=" : function(a, v){
\r
581 return a && (a == v || a.substr(0, v.length+1) == v+'-');
\r
583 "~=" : function(a, v){
\r
584 return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
\r
588 <div id="prop-Ext.air.DragType-pseudos"></div>/**
\r
589 * Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
\r
590 * and the argument (if any) supplied in the selector.
\r
593 "first-child" : function(c){
\r
594 var r = [], ri = -1, n;
\r
595 for(var i = 0, ci; ci = n = c[i]; i++){
\r
596 while((n = n.previousSibling) && n.nodeType != 1);
\r
604 "last-child" : function(c){
\r
605 var r = [], ri = -1, n;
\r
606 for(var i = 0, ci; ci = n = c[i]; i++){
\r
607 while((n = n.nextSibling) && n.nodeType != 1);
\r
615 "nth-child" : function(c, a) {
\r
616 var r = [], ri = -1;
\r
617 var m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a);
\r
618 var f = (m[1] || 1) - 0, l = m[2] - 0;
\r
619 for(var i = 0, n; n = c[i]; i++){
\r
620 var pn = n.parentNode;
\r
621 if (batch != pn._batch) {
\r
623 for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
\r
624 if(cn.nodeType == 1){
\r
625 cn.nodeIndex = ++j;
\r
631 if (l == 0 || n.nodeIndex == l){
\r
634 } else if ((n.nodeIndex + l) % f == 0){
\r
642 "only-child" : function(c){
\r
643 var r = [], ri = -1;;
\r
644 for(var i = 0, ci; ci = c[i]; i++){
\r
645 if(!prev(ci) && !next(ci)){
\r
652 "empty" : function(c){
\r
653 var r = [], ri = -1;
\r
654 for(var i = 0, ci; ci = c[i]; i++){
\r
655 var cns = ci.childNodes, j = 0, cn, empty = true;
\r
656 while(cn = cns[j]){
\r
658 if(cn.nodeType == 1 || cn.nodeType == 3){
\r
670 "contains" : function(c, v){
\r
671 var r = [], ri = -1;
\r
672 for(var i = 0, ci; ci = c[i]; i++){
\r
673 if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
\r
680 "nodeValue" : function(c, v){
\r
681 var r = [], ri = -1;
\r
682 for(var i = 0, ci; ci = c[i]; i++){
\r
683 if(ci.firstChild && ci.firstChild.nodeValue == v){
\r
690 "checked" : function(c){
\r
691 var r = [], ri = -1;
\r
692 for(var i = 0, ci; ci = c[i]; i++){
\r
693 if(ci.checked == true){
\r
700 "not" : function(c, ss){
\r
701 return Ext.DomQuery.filter(c, ss, true);
\r
704 "any" : function(c, selectors){
\r
705 var ss = selectors.split('|');
\r
706 var r = [], ri = -1, s;
\r
707 for(var i = 0, ci; ci = c[i]; i++){
\r
708 for(var j = 0; s = ss[j]; j++){
\r
709 if(Ext.DomQuery.is(ci, s)){
\r
718 "odd" : function(c){
\r
719 return this["nth-child"](c, "odd");
\r
722 "even" : function(c){
\r
723 return this["nth-child"](c, "even");
\r
726 "nth" : function(c, a){
\r
727 return c[a-1] || [];
\r
730 "first" : function(c){
\r
734 "last" : function(c){
\r
735 return c[c.length-1] || [];
\r
738 "has" : function(c, ss){
\r
739 var s = Ext.DomQuery.select;
\r
740 var r = [], ri = -1;
\r
741 for(var i = 0, ci; ci = c[i]; i++){
\r
742 if(s(ss, ci).length > 0){
\r
749 "next" : function(c, ss){
\r
750 var is = Ext.DomQuery.is;
\r
751 var r = [], ri = -1;
\r
752 for(var i = 0, ci; ci = c[i]; i++){
\r
754 if(n && is(n, ss)){
\r
761 "prev" : function(c, ss){
\r
762 var is = Ext.DomQuery.is;
\r
763 var r = [], ri = -1;
\r
764 for(var i = 0, ci; ci = c[i]; i++){
\r
766 if(n && is(n, ss)){
\r
776 Ext.query = Ext.DomQuery.select;
\r
778 Date.precompileFormats = function(s){
\r
779 var formats = s.split('|');
\r
780 for(var i = 0, len = formats.length;i < len;i++){
\r
781 Date.createNewFormat(formats[i]);
\r
782 Date.createParser(formats[i]);
\r
786 Date.precompileFormats("D n/j/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|YmdHis|F d, Y|l, F d, Y|H:i:s|g:i A|g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H|m/d/y|m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|Y-m-d H:i:s|d/m/y|d/m/Y|d-m-y|d-m-Y|d/m|d-m|dm|dmy|dmY|Y-m-d|l|D m/d|D m/d/Y|m/d/Y");
\r
788 // precompile instead of lazy init
\r
789 Ext.ColorPalette.prototype.tpl = new Ext.XTemplate(
\r
790 '<tpl for="."><a href="#" class="color-{.}" hidefocus="on"><em><span style="background:#{.}" unselectable="on"> </span></em></a></tpl>'
\r
793 Ext.grid.GroupingView.prototype.startTpl = new Ext.XTemplate(
\r
794 '<div id="{groupId}" class="x-grid-group {cls}">',
\r
795 '<div id="{groupId}-hd" class="x-grid-group-hd" style="{style}"><div>{text}</div></div>',
\r
796 '<div id="{groupId}-bd" class="x-grid-group-body">'
\r