PageRenderTime 72ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/web/js/sigma_grid2.4_release/src/gt_base.js

https://github.com/gitbuh/redskeleton
JavaScript | 1463 lines | 1200 code | 231 blank | 32 comment | 355 complexity | 181d317413f131fd4eee95e93cd3d56d MD5 | raw file
  1. //
  2. if (!window.Sigma){
  3. window.Sigma={};
  4. }
  5. Sigma.loaded=false;
  6. Sigma.init=function(win){
  7. win = win || window;
  8. Sigma.doc=document;
  9. win.undefined = win.undefined;
  10. var ua = win.navigator.userAgent.toLowerCase();
  11. Sigma.isIE = ua.indexOf("msie") > -1;
  12. Sigma.isIE7 = ua.indexOf("msie 7") > -1;
  13. Sigma.isIE8 = ua.indexOf("msie 8") > -1;
  14. Sigma.isIE9 = ua.indexOf("msie 9") > -1;
  15. Sigma.isFF = ua.indexOf("firefox") > -1 ;
  16. Sigma.isFF1 = ua.indexOf("firefox/1") > -1 ;
  17. Sigma.isFF2 = ua.indexOf("firefox/2") > -1 ;
  18. Sigma.isFF3 = ua.indexOf("firefox/3") > -1 ;
  19. Sigma.isOpera = ua.indexOf("opera") > -1;
  20. Sigma.isWebkit = (/webkit|khtml/).test(ua);
  21. Sigma.isSafari = ua.indexOf("safari") > -1 || Sigma.isWebkit ;
  22. Sigma.isChrome = ua.indexOf("chrome") > -1 || Sigma.isWebkit ;
  23. Sigma.isGecko = Sigma.isMoz =!Sigma.isSafari && ua.indexOf("gecko") > -1;
  24. Sigma.isStrict = Sigma.doc.compatMode == "CSS1Compat" || Sigma.isSafari ;
  25. Sigma.isBoxModel = Sigma.isIE && !Sigma.isIE8 && !Sigma.isIE9 && !Sigma.isStrict ;
  26. Sigma.isNotStrictIE = Sigma.isBoxModel;
  27. Sigma.isSecure = win.location.href.toLowerCase().indexOf("https") === 0;
  28. Sigma.isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1);
  29. Sigma.isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1);
  30. Sigma.isLinux = (ua.indexOf("linux") != -1);
  31. };
  32. Sigma.init();
  33. Sigma.$extend = function(original,extended, isDeep){
  34. if (arguments.length<2){
  35. extended = original;
  36. original = this;
  37. }
  38. for (var property in extended) {
  39. var v=extended[property];
  40. if (isDeep && v && Sigma.$type(v,'object','array') ){
  41. v=Sigma.$clone(v, isDeep);
  42. }
  43. if (v!==undefined) {
  44. original[property] = v;
  45. }
  46. }
  47. return original;
  48. };
  49. Sigma.$extend(Sigma , {
  50. $empty : function(){},
  51. $chk:function (obj){
  52. return !!(obj || obj === 0 || obj==='' );
  53. },
  54. //'string', 'array', 'object', 'arguments', 'collection','number'
  55. $type : function (obj){
  56. var argNum=arguments.length;
  57. if (argNum>1){
  58. for (var i=1;i<argNum;i++){
  59. if(Sigma.$type(obj)==arguments[i]) { return true; }
  60. }
  61. return false;
  62. }
  63. var type = typeof obj;
  64. if (obj === null) { return 'object'; }
  65. if (type == 'undefined') { return 'undefined'; }
  66. if (obj.htmlElement) { return 'element'; }
  67. if (type == 'object' && obj.nodeType && obj.nodeName){
  68. switch(obj.nodeType){
  69. case 1: return 'element';
  70. case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
  71. }
  72. }
  73. if (Sigma.U.isArray(obj)) {
  74. return 'array';
  75. }
  76. /*
  77. if (type == 'object' || type == 'function'){
  78. switch(obj.constructor){
  79. case RegExp: return 'regexp';
  80. case Sigma.Class: return 'class';
  81. }
  82. }
  83. */
  84. if (type == 'object' && typeof obj.length == 'number'){
  85. return (obj.callee) ? 'arguments' : 'collection';
  86. }else if (type == 'function' && typeof obj.length == 'number' && obj[0]!==undefined ){
  87. return 'collection';
  88. }
  89. return type;
  90. },
  91. $merge: function (){
  92. var mix = {};
  93. for (var i = 0; i < arguments.length; i++){
  94. for (var property in arguments[i]){
  95. var ap = arguments[i][property];
  96. var mp = mix[property];
  97. if (mp && Sigma.$type(ap,'object') && Sigma.$type(mp,'object') ) {
  98. mix[property] = Sigma.$merge(mp, ap);
  99. }else {
  100. mix[property] = ap;
  101. }
  102. }
  103. }
  104. return mix;
  105. },
  106. $indexOf : function(arr,item,start){
  107. if (arr){
  108. start = start || 0;
  109. for (var i=start,j=arr.length; i<j; i++) {
  110. if (arr[i]===item) {
  111. return i;
  112. }
  113. }
  114. }
  115. return -1;
  116. },
  117. $array : function(iterable,start, end ,isDeep) {
  118. var results = [];
  119. if (iterable) {
  120. if (!Sigma.$chk(start)){
  121. start=0;
  122. }
  123. if (!Sigma.$chk(end)){
  124. end=iterable.length;
  125. }
  126. if (Sigma.$type(iterable,'arguments', 'collection') || Sigma.$type(iterable,'array') && (start>0 || end<iterable.length) ){
  127. for (var i = start; i < end; i++) {
  128. results.push(iterable[i]);
  129. }
  130. }else if (Sigma.$type(iterable,'array') ){
  131. results=results.concat(iterable);
  132. }else{
  133. for (var k in iterable ){
  134. if (iterable.hasOwnProperty(k)){
  135. results.push( iterable[k] );
  136. }
  137. }
  138. }
  139. }
  140. return results;
  141. },
  142. $clone : function(obj,isDeep){
  143. var newObj;
  144. if (!obj){
  145. newObj=obj;
  146. }else if (Sigma.$type(obj,'array','arguments', 'collection')){
  147. newObj=Sigma.$array(obj,0,obj.length,isDeep);
  148. }else{
  149. newObj= Sigma.$extend({},obj,isDeep);
  150. }
  151. return newObj;
  152. },
  153. $msg : function(msgTemplate, msgs){
  154. for (var i=1;i<arguments.length ;i++ ){
  155. msgTemplate=Sigma.U.replaceAll(msgTemplate,"#{"+i+"}",arguments[i]);
  156. }
  157. return msgTemplate;
  158. },
  159. $clear : function (timer){
  160. window.clearTimeout(timer);
  161. window.clearInterval(timer);
  162. if ( CollectGarbage ){
  163. CollectGarbage();
  164. }
  165. return null;
  166. },
  167. $thread : function(fn,timeout){
  168. //fn();
  169. //return;
  170. var nfn=fn;
  171. window.setTimeout(nfn ,timeout || 20);
  172. },
  173. $each : function(iterable, fn, bind,arg){
  174. var resultList=[];
  175. if ( Sigma.$type(iterable,'array','arguments','collection') || iterable&&!Sigma.$type(iterable,'string')&&Sigma.$type(iterable.length,'number') ) {
  176. for (var i = 0, j = iterable.length; i < j; i++) {
  177. resultList.push( fn.call(bind || iterable, iterable[i], i, iterable,arg) );
  178. }
  179. } else {
  180. for (var name in iterable) {
  181. resultList.push( fn.call(bind || iterable, iterable[name], name,iterable,arg) );
  182. }
  183. }
  184. return resultList;
  185. },
  186. $getText : function(el){
  187. return el.innerText===undefined?el.textContent : el.innerText;
  188. },
  189. $element : function(el,props){
  190. if (Sigma.$type(el,'string') ){
  191. if (Sigma.isIE && props && (props.name || props.type)){
  192. var name = (props.name) ? ' name="' + props.name + '"' : '';
  193. var type = (props.type) ? ' type="' + props.type + '"' : '';
  194. delete props.name;
  195. delete props.type;
  196. el = '<' + el + name + type + '>';
  197. }
  198. el = Sigma.doc.createElement(el);
  199. }
  200. if (props){
  201. if (props.style){
  202. Sigma.$extend(el.style,props.style);
  203. delete props.style;
  204. }
  205. Sigma.$extend(el,props);
  206. }
  207. return el;
  208. }
  209. } );
  210. Sigma.Class=function(properties){
  211. properties = properties || {};
  212. var klass = function(){
  213. var prop=this.properties;
  214. if (Sigma.$type(prop, 'function')){
  215. prop=prop.apply(this, arguments);
  216. }
  217. if (Sigma.$type(prop, 'object')){
  218. Sigma.$extend(this, prop);
  219. }
  220. var methds=this.abstractMethods ;
  221. Sigma.$each(this.abstractMethods , function(_item){
  222. this[_item]=Sigma.$empty;
  223. },this);
  224. return (arguments[0]!==Sigma.$empty
  225. && Sigma.$type(this.initialize, 'function') ) ?
  226. this.initialize.apply(this, arguments) : this;
  227. };
  228. Sigma.$extend(klass, this);
  229. klass.constructor = Sigma.Class;
  230. klass.prototype = properties;
  231. return klass;
  232. };
  233. Sigma.Class.prototype={
  234. extend:function(){
  235. var proto = new this(Sigma.$empty);
  236. for (var i = 0, l = arguments.length; i < l; i++) {
  237. var properties=arguments[i];
  238. for (var property in properties){
  239. var pp = proto[property];
  240. proto[property] = Sigma.Class.merge(pp, properties[property]);
  241. }
  242. }
  243. return new Sigma.Class(proto);
  244. }
  245. };
  246. Sigma.Class.merge = function(previous, current){
  247. if (previous && previous != current){
  248. var type = Sigma.$type(current);
  249. if ( !Sigma.$type(previous,type) ) { return current; }
  250. switch(type){
  251. case 'function':
  252. var merged = function(){
  253. this._parent = arguments.callee._parent;
  254. return current.apply(this, arguments);
  255. };
  256. merged._parent = previous;
  257. return merged;
  258. case 'object': return Sigma.$merge(previous, current);
  259. }
  260. }
  261. return current;
  262. };
  263. //////////////////////////////////////////
  264. Sigma.$class = function(properties){
  265. return new Sigma.Class(properties);
  266. };
  267. Sigma.$e=Sigma.$element;
  268. Sigma.$A=Sigma.$array;
  269. Sigma.$byId=function(el,pros){
  270. if ( !Sigma.$chk(el) ) { return null; }
  271. var type = Sigma.$type(el);
  272. if (type == 'element'){
  273. return Sigma.$e(el,pros);
  274. }
  275. if (type == 'string' || type == 'number' ){
  276. el = Sigma.doc.getElementById(''+el);
  277. }
  278. if ( !el ) { return null; }
  279. if ( Sigma.U.contains(['object', 'embed'],!el.tagName?el.tagName.toLowerCase():'')) { return el; }
  280. return Sigma.$e(el);
  281. };
  282. Sigma.getDom = function(el){
  283. if(!el || !document){
  284. return null;
  285. }
  286. return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
  287. };
  288. Sigma.$byName=function(el){
  289. var elList=[];
  290. if ( !Sigma.$chk(el) ) { return elList; }
  291. var elColl=Sigma.doc.getElementsByName(''+el);
  292. if (!elColl || elColl.length<1 ){
  293. return elList;
  294. }
  295. for (var i=0;i<elColl.length;i++){
  296. el=elColl[i];
  297. elList.push( Sigma.U.contains(['object', 'embed'],el.tagName.toLowerCase())?el:Sigma.$e(el));
  298. }
  299. return elList;
  300. };
  301. Sigma.$=function(el){
  302. var tEl=Sigma.$byName(el);
  303. //if ( tEl && tEl.length===1 ){
  304. if ( tEl && tEl.length>0 ){
  305. return tEl[0];
  306. }
  307. return (!tEl||tEl.length<1)?Sigma.$byId(el):tEl;
  308. };
  309. /////////////////////////////////////
  310. Sigma.Utils={
  311. P_START : '@{',
  312. P_END : '}',
  313. P_VAR_NAME : 'obj_in',
  314. parseExpression : function(ex,pName,argNames,pStart,pEnd){
  315. pStart = pStart || Sigma.U.P_START;
  316. pEnd = pEnd || Sigma.U.P_END;
  317. pName = pName || Sigma.U.P_VAR_NAME;
  318. argNames = argNames || pName;
  319. var startLength= pStart.length;
  320. var endLength= pEnd.length;
  321. var templateC=[];
  322. var current=0;
  323. while(true){
  324. var start= ex.indexOf( pStart ,current);
  325. var sBegin=start+ startLength;
  326. var sEnd=ex.indexOf( pEnd ,sBegin);
  327. var str=null;
  328. var val=null;
  329. if (sBegin>= startLength && sEnd>sBegin){
  330. str=ex.substring(current,start);
  331. val=ex.substring(sBegin,sEnd);
  332. }else{
  333. str=ex.substring(current);
  334. }
  335. //if (!Sigma.U.isNumber(str)){
  336. str=Sigma.U.escapeString(str);
  337. //}
  338. templateC.push( str );
  339. if (val===null){
  340. break;
  341. }
  342. if (!Sigma.U.isNumber(val)){
  343. val=(pName?(pName+'.'):'')+ val ;
  344. }else{
  345. val=(pName?(pName+'['):'')+ val +(pName?']':'');
  346. }
  347. templateC.push( val );
  348. current=sEnd+ endLength;
  349. }
  350. var t="function(" + argNames + "){ return "+ templateC.join('+')+" }";
  351. eval("t="+t);
  352. return t;
  353. //return new Function(pName, 'return '+templateC.join(''));
  354. },
  355. isArray : function(a){
  356. return Object.prototype.toString.apply(a) === '[object Array]' ;
  357. },
  358. isNumber : function(n ,strict){
  359. return n===0 || (strict?Sigma.$type(n, 'number'):(n && !isNaN(n)));
  360. },
  361. parseInt : function(num,defaultNum){
  362. var t=parseInt(num);
  363. return isNaN(parseInt(num))? defaultNum || 0:t;
  364. },
  365. add2Map : function(key,value,map){
  366. map=map || {};
  367. if (map[key]===undefined) {
  368. map[key]=value;
  369. }else{
  370. map[key]=[].concat(map[key]);
  371. map[key].push(value);
  372. }
  373. return map;
  374. },
  375. moveItem : function (arr,fromIdx, toIdx){
  376. //fromIdx=fromIdx<0 ? 0:( fromIdx>arr.length-1?arr.length-1:fromIdx);
  377. //toIdx=toIdx<0 ? 0:( toIdx>arr.length-1?arr.length-1:toIdx);
  378. if (fromIdx==toIdx) {
  379. return arr;
  380. }
  381. var moveObj =arr[fromIdx];
  382. var dObj =arr[toIdx];
  383. arr.splice(toIdx,1,moveObj,dObj);
  384. if (fromIdx<toIdx) {
  385. arr.splice(fromIdx,1);
  386. }else{
  387. arr.splice(fromIdx+1,1);
  388. }
  389. return arr;
  390. },
  391. convert: function (sValue, sDataType) {
  392. switch(sDataType) {
  393. case "int":
  394. return parseInt(sValue);
  395. case "float":
  396. return parseFloat(sValue);
  397. case "date":
  398. return sValue; //(new Date(Date.parse(sValue))).getTime();
  399. default:
  400. return sValue;
  401. }
  402. return sValue;
  403. },
  404. getTagName : function(node){
  405. return node && node.tagName ? String(node.tagName).toUpperCase(): null;
  406. },
  407. getParentByTagName : function(tagName,node,event,deep){
  408. if (!node){
  409. event=Sigma.$event(event);
  410. node=Sigma.U.getEventTarget(event);
  411. }
  412. deep= deep || 6;
  413. if (!node){ return null; }
  414. tagName = tagName.toLowerCase();
  415. while( node && (deep--)>0 ) {
  416. if(node.tagName && node.tagName.toLowerCase()==tagName){
  417. return node;
  418. }
  419. /* todo */
  420. if ( Sigma.U.hasClass(node.className,'gt-grid') && tagName!="div" ){
  421. break;
  422. }
  423. node=node.parentNode;
  424. }
  425. return null;
  426. },
  427. focus : function(el){
  428. if (el) {
  429. try{
  430. el.focus();
  431. el.select && el.select();
  432. }catch(e){}
  433. }
  434. },
  435. hasClass: function(el,className){
  436. return el?Sigma.U.hasSubString(el.className,className, ' '):false;
  437. },
  438. addClass: function(el,className){
  439. if (el && !Sigma.U.hasClass(el,className)) {
  440. el.className = Sigma.U.clean(el.className + ' ' + className) ;
  441. }
  442. return el;
  443. },
  444. removeClass: function(el,className){
  445. if (el){
  446. el.className = Sigma.U.clean(el.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1') );
  447. }
  448. return el;
  449. },
  450. toggleClass: function(el,className){
  451. return Sigma.U.hasClass(el,className) ? Sigma.U.removeClass(el,className) : Sigma.U.addClass(el,className);
  452. },
  453. hasSubString: function(str,string, s){
  454. return (s) ? (s + str + s).indexOf(s + string + s) > -1 : str.indexOf(string) > -1;
  455. },
  456. childElement : function(p, index){
  457. var i = 0;
  458. var n = p?p.firstChild:null;
  459. while(n){
  460. if(n.nodeType == 1){
  461. if(++i == index){
  462. return n;
  463. }
  464. }
  465. n = n.nextSibling;
  466. }
  467. return null;
  468. },
  469. firstChildElement : function(el){
  470. return Sigma.U.childElement(el,1);
  471. },
  472. lastChildElement : function(el){
  473. var tEl=el.childNodes[el.childNodes.length-1];
  474. return tEl.nodeType == 1?tEl:Sigma.U.prevElement(tEl);
  475. },
  476. nextElement : function(n){
  477. while((n = n.nextSibling) && n.nodeType != 1){}
  478. return n;
  479. },
  480. prevElement : function(n){
  481. while((n = n.previousSibling) && n.nodeType != 1){}
  482. return n;
  483. },
  484. getCellIndex : function(td){
  485. if (Sigma.isIE){
  486. var cells=td.parentNode.cells;
  487. for (var i=0,j=cells.length;i<j;i++ ){
  488. if (cells[i]===td){
  489. return i;
  490. }
  491. }
  492. }
  493. return td.cellIndex;
  494. },
  495. insertNodeBefore : function(elA,elB){
  496. if (!elA || !elB || !elB.parentNode){
  497. return null;
  498. }
  499. elB.parentNode.insertBefore(elA, elB);
  500. return elA;
  501. },
  502. insertNodeAfter : function(elA,elB){
  503. elB.parentNode.insertBefore(elA, elB.nextSibling);
  504. return elA;
  505. },
  506. listToMap : function (list){
  507. var map={};
  508. for (var i=0;i<list.length;i++ ){
  509. map[list[i]]=list[i];
  510. }
  511. return map;
  512. },
  513. createSelect : function(map, defaultValue,opt, selectEl){
  514. selectEl=selectEl || Sigma.$e("select",opt||{});
  515. var sTemp=Sigma.doc.createDocumentFragment();
  516. Sigma.$each(map,
  517. function(text,value){
  518. var op=Sigma.$e("option",{'value' : value ,'text':''+text, innerHTML :text});
  519. if (Sigma.$chk(defaultValue) && value==defaultValue){
  520. op.selected=true;
  521. }
  522. sTemp.appendChild(op);
  523. }
  524. );
  525. selectEl.appendChild(sTemp);
  526. return selectEl;
  527. },
  528. createSelectHTML : function(map,defaultValue,opt){
  529. opt=opt||{};
  530. var id=opt.id?(' id="'+opt.id+'" '):' ' ,
  531. cls=opt.className || '' ,
  532. st =opt.style? (' style="'+opt.style+'" '):' ' ;
  533. var selectH= ['<select'+ id + st+'class="gt-input-select '+cls+'">'];
  534. for (var k in map ){
  535. var s='';
  536. if ( (defaultValue||defaultValue===0) && k==defaultValue){
  537. s=' selected="selected" ';
  538. }
  539. selectH.push('<option value="'+k+'" '+s+'>'+map[k]+'</option>');
  540. }
  541. selectH.push('</select>');
  542. return selectH.join('');
  543. },
  544. getEventTarget : function(evt){
  545. var targetEl=null;
  546. try{
  547. targetEl=evt.target || evt.srcElement;
  548. }catch(e){ return null; }
  549. return !targetEl?null:(targetEl.nodeType == 3 ? targetEl.parentNode: targetEl);
  550. },
  551. stopEvent : function(event) {
  552. event = event || window.event;
  553. if (event){
  554. //event = event || window.event;
  555. if (event.stopPropagation){
  556. event.stopPropagation();
  557. event.preventDefault();
  558. } else {
  559. event.cancelBubble = true;
  560. event.returnValue = false;
  561. }
  562. }
  563. //return event;
  564. },
  565. addEvent : function(el,type, fn,bind,args){
  566. if ( !fn || !el || !type ){ return false; }
  567. if (arguments.length>3) {
  568. fn=Sigma.U.bindAsEventListener(fn,bind,args);
  569. }
  570. if (el.addEventListener) {
  571. el.addEventListener(type,fn, false);
  572. }else{
  573. var _type= type=='selectstart'?type: 'on' + type;
  574. el.attachEvent(_type, fn);
  575. }
  576. Sigma.EventCache.add(el, type, fn, false);
  577. return el;
  578. },
  579. removeEvent: function(el,type, fn,bind,args){
  580. if ( !fn || !el || !type ){ return false; }
  581. if (arguments.length>3) {
  582. fn=Sigma.U.bindAsEventListener(fn,bind,args);
  583. }
  584. if (el.addEventListener) {
  585. el.removeEventListener(type,fn, false);
  586. }else {
  587. var _type= type=='selectstart'?type: 'on' + type;
  588. el.detachEvent(_type, fn);
  589. }
  590. Sigma.EventCache.remove(el, type, fn, false);
  591. return el;
  592. },
  593. onLoadFuncList : [] ,
  594. onLoadFuncCaller : function(){
  595. for (var i=0;i< Sigma.U.onLoadFuncList.length;i++ ){
  596. var func= Sigma.U.onLoadFuncList[i];
  597. //try{
  598. func.apply(this, arguments);
  599. //}catch(e){}
  600. }
  601. Sigma.loaded=true;
  602. },
  603. onLoad : function(fn, win){
  604. win = win || window;
  605. Sigma.U.onLoadFuncList.push(fn);
  606. if (!Sigma.U.onLoadFuncCaller.hasAdd){
  607. Sigma.U.addEvent(win, "load", Sigma.U.onLoadFuncCaller);
  608. Sigma.U.onLoadFuncCaller.hasAdd=true;
  609. }
  610. },
  611. orphanDiv : function(){
  612. var div=Sigma.doc.createElement('div');
  613. div.className="gt-orphan-div";
  614. return div; }(),
  615. createElementFromHTML : function(html,parentEl){
  616. Sigma.U.orphanDiv.innerHTML=html;
  617. var el=Sigma.U.firstChildElement(Sigma.U.orphanDiv);
  618. parentEl.appendChild(el);
  619. Sigma.U.orphanDiv.innerHTML='';
  620. return el;
  621. },
  622. createTrFromHTML : function(html,parentEl){
  623. Sigma.U.orphanDiv.innerHTML='<table><tbody>'+html+'</tbody></table>';
  624. var tr= Sigma.U.orphanDiv.getElementsByTagName('tr')[0];
  625. parentEl.appendChild(tr);
  626. Sigma.U.orphanDiv.innerHTML='';
  627. return tr;
  628. },
  629. removeNode : function(els){
  630. for (var i = 0; i < arguments.length; i++){
  631. var el=arguments[i];
  632. if (!el || !el.parentNode || el.tagName == 'BODY'){ return null;}
  633. Sigma.EventCache.remove(el);
  634. if (Sigma.isIE) {
  635. Sigma.U.orphanDiv.appendChild(el);
  636. Sigma.U.orphanDiv.innerHTML = '';
  637. }else{
  638. el.parentNode.removeChild(el);
  639. }
  640. }
  641. },
  642. removeNodeTree : function(el){
  643. if (el) {
  644. var els=el.getElementsByTagName("*");
  645. for (var i = 0; i < els.length; i++){
  646. //Sigma.U.removeNode(els[i]);
  647. Sigma.U.removeNodeTree(els[i]);
  648. }
  649. Sigma.U.removeNode(el);
  650. }
  651. },
  652. getLastChild : function(el){
  653. return el.childNodes[el.childNodes.length-1];
  654. },
  655. getPosLeftTop:function(elm,pEl) {
  656. pEl=pEl||window;
  657. var top = elm.offsetTop;
  658. var left = elm.offsetLeft;
  659. elm = elm.offsetParent;
  660. while(elm && elm != pEl) {
  661. top += (elm.offsetTop-elm.scrollTop);
  662. left += (elm.offsetLeft-elm.scrollLeft);
  663. elm = elm.offsetParent;
  664. }
  665. return [left,top];
  666. },
  667. getPosRight:function(elm){
  668. return Sigma.U.getPosLeftTop(elm)[0]+elm.offsetWidth;
  669. },
  670. getPosBottom:function(elm){
  671. return Sigma.U.getPosLeftTop(elm)[1]+elm.offsetHeight;
  672. },
  673. getHeight : function(el,content){
  674. var h = el.offsetHeight || 0;
  675. if (content !== true){
  676. return h;
  677. }
  678. var bws=Sigma.U.getBorderWidths(el);
  679. var pws=Sigma.U.getPaddings(el);
  680. return h-bws[0]-bws[2]-pws[0]-pws[2];
  681. },
  682. getWidth : function(el,content){
  683. var w = el.offsetWidth || 0;
  684. if (content !== true){
  685. return w;
  686. }
  687. var bws=Sigma.U.getBorderWidths(el);
  688. var pws=Sigma.U.getPaddings(el);
  689. return w-bws[1]-bws[3]-pws[1]-pws[3];
  690. },
  691. getBorderWidths : function(el){
  692. return [ Sigma.U.parseInt(el.style.borderTopWidth),
  693. Sigma.U.parseInt(el.style.borderRightWidth),
  694. Sigma.U.parseInt(el.style.borderBottomWidth),
  695. Sigma.U.parseInt(el.style.borderLeftWidth) ];
  696. },
  697. getPaddings : function(el){
  698. return [ Sigma.U.parseInt(el.style.paddingTop),
  699. Sigma.U.parseInt(el.style.paddingRight),
  700. Sigma.U.parseInt(el.style.paddingBottom),
  701. Sigma.U.parseInt(el.style.paddingLeft) ];
  702. },
  703. getPageX: function(ev) {
  704. ev = ev || window.event;
  705. var x = ev.pageX;
  706. if (!x && 0 !== x) {
  707. x = ev.clientX || 0;
  708. if (Sigma.isIE) {
  709. x += Sigma.U.getPageScroll()[0];
  710. }
  711. }
  712. return x;
  713. },
  714. getPageY: function(ev) {
  715. ev = ev || window.event;
  716. var y = ev.pageY;
  717. if (!y && 0 !== y) {
  718. y = ev.clientY || 0;
  719. if (Sigma.isIE) {
  720. y += Sigma.U.getPageScroll()[1];
  721. }
  722. }
  723. return y;
  724. },
  725. getPageScroll: function() {
  726. var dd = Sigma.doc.documentElement, db = Sigma.doc.body;
  727. if (dd && (dd.scrollLeft || dd.scrollTop )) {
  728. return [dd.scrollLeft,dd.scrollTop];
  729. } else if (db) {
  730. return [db.scrollLeft,dd.scrollTop];
  731. } else {
  732. return [0, 0];
  733. }
  734. },
  735. getScroll : function(el){
  736. var d = el, doc = Sigma.doc;
  737. if(d == doc || d == doc.body){
  738. var l = window.pageXOffset || doc.documentElement.scrollLeft || doc.body.scrollLeft || 0;
  739. var t = window.pageYOffset || doc.documentElement.scrollTop || doc.body.scrollTop || 0;
  740. return [ l, t];
  741. }else{
  742. return [ d.scrollLeft,d.scrollTop];
  743. }
  744. },
  745. getXY : function(el,pEl) {
  746. var p, pe, b, scroll, bd = Sigma.doc.body;
  747. if (el.getBoundingClientRect) {
  748. b = el.getBoundingClientRect();
  749. scroll = Sigma.U.getScroll(Sigma.doc);
  750. return [b.left + scroll[0], b.top + scroll[1]];
  751. }
  752. var x = 0, y = 0;
  753. p = el;
  754. pEl=pEl||bd;
  755. var hasAbsolute =el.style.position == "absolute";
  756. while (p) {
  757. x += p.offsetLeft;
  758. y += p.offsetTop;
  759. if (!hasAbsolute && p.style.position == "absolute") {
  760. hasAbsolute = true;
  761. }
  762. if (Sigma.isGecko) {
  763. pe = p;
  764. var bt = parseInt(pe.style.borderTopWidth, 10) || 0;
  765. var bl = parseInt(pe.style.borderLeftWidth, 10) || 0;
  766. x += bl;
  767. y += bt;
  768. if (p != el && pe.style.overflow!= 'visible') {
  769. x += bl;
  770. y += bt;
  771. }
  772. }
  773. p = p.offsetParent;
  774. }
  775. if (Sigma.isSafari && hasAbsolute) {
  776. x -= bd.offsetLeft;
  777. y -= bd.offsetTop;
  778. }
  779. if (Sigma.isGecko && !hasAbsolute) {
  780. var dbd = bd;
  781. x += parseInt(dbd.style.borderTopWidth, 10) || 0;
  782. y += parseInt(dbd.style.borderTopWidth, 10) || 0;
  783. }
  784. p = el.parentNode;
  785. while (p && p != bd) {
  786. if (!Sigma.isOpera || (p.tagName.toUpperCase() != 'TR' && p.style.display != "inline")) {
  787. x -= p.scrollLeft;
  788. y -= p.scrollTop;
  789. }
  790. p = p.parentNode;
  791. }
  792. return [x, y];
  793. },
  794. setXY : function(el, xy) {
  795. if(el.style.position == 'static'){
  796. el.style.position='relative';
  797. }
  798. var pts = Sigma.U.translatePoints(el,xy);
  799. if (xy[0] !== false) {
  800. el.style.left = pts.left + "px";
  801. }
  802. if (xy[1] !== false) {
  803. el.style.top = pts.top + "px";
  804. }
  805. },
  806. translatePoints : function(el,x, y){
  807. if(typeof x == 'object' || x instanceof Array){
  808. y = x[1]; x = x[0];
  809. }
  810. var p = el.style.position;
  811. var o = Sigma.U.getXY(el);
  812. var l = parseInt(el.style.left, 10);
  813. var t = parseInt(el.style.top, 10);
  814. if(isNaN(l)){
  815. l = (p == "relative") ? 0 : el.offsetLeft;
  816. }
  817. if(isNaN(t)){
  818. t = (p == "relative") ? 0 : el.offsetTop;
  819. }
  820. return {left: (x - o[0] + l), top: (y - o[1] + t)};
  821. },
  822. getContentWidthHeight : function(node){
  823. var mL=Sigma.U.parseInt(node.style.marginLeft);
  824. var mR=Sigma.U.parseInt(node.style.marginRight);
  825. var pL=Sigma.U.parseInt(node.style.paddingLeft);
  826. var pR=Sigma.U.parseInt(node.style.paddingRight);
  827. var w= node.clientWidth-pL-pR;
  828. var h= node.clientHeight;
  829. return [w,h];
  830. },
  831. getPixelValue : function(inval,parentVal){
  832. if (Sigma.$type(inval,'number')){
  833. return inval;
  834. }
  835. inval=''+inval;
  836. var nVal=Sigma.U.parseInt(inval);
  837. if ( inval.indexOf("%")>1 ) {
  838. return parentVal*nVal/100;
  839. }
  840. return nVal;
  841. },
  842. setValue: function(el,value){
  843. el=Sigma.$(el);
  844. if (!el){
  845. return;
  846. }
  847. var tag=el.tagName;
  848. tag=(''+tag).toUpperCase();
  849. switch( tag ){
  850. case 'SELECT':
  851. var values = [].concat(value);
  852. var firstOption=null;
  853. Sigma.$each(el.options, function(option,idx){
  854. if (idx===0) {
  855. firstOption = option;
  856. }
  857. option.selected=false;
  858. if (el.multiple){
  859. Sigma.$each(values,function(val){
  860. option.selected=option.value==val;
  861. });
  862. }else if(option.value==values[0]){
  863. option.selected=true;
  864. firstOption=false;
  865. }
  866. });
  867. if (!el.multiple && firstOption){
  868. firstOption.selected=true;
  869. }
  870. return (el.multiple) ? values : values[0];
  871. case 'INPUT':
  872. if (el.type=='checkbox' || el.type=='radio' ){
  873. el.checked= el.value==value;
  874. break;
  875. }
  876. case 'TEXTAREA':
  877. el.value=value;
  878. }
  879. return null;
  880. },
  881. getValue: function(el){
  882. el=Sigma.$(el);
  883. if (!el){
  884. return;
  885. }
  886. var tag=el.tagName;
  887. switch( tag ){
  888. case 'SELECT':
  889. var values = [];
  890. Sigma.$each(el.options, function(option){
  891. if (option.selected) { values.push(option.value); }
  892. });
  893. values = (el.multiple) ? values : values[0];
  894. if ( (values===null || values===undefined) && el.options[0] ) {
  895. values=el.options[0].value;
  896. }
  897. return values;
  898. case 'INPUT':
  899. if ( (el.type=='checkbox' || el.type=='radio' ) && !el.checked ){
  900. break;
  901. }
  902. case 'TEXTAREA': return el.value;
  903. }
  904. return null;
  905. },
  906. setOpacity: function(el,opacity){
  907. opacity=opacity>1?1:(opacity<0?0:opacity);
  908. if (!el.currentStyle || !el.currentStyle.hasLayout) { el.style.zoom = 1; }
  909. if (Sigma.isIE) {
  910. el.style.filter = (opacity == 1) ? '' : "alpha(opacity=" + opacity * 100 + ")";
  911. }
  912. el.style.opacity = opacity;
  913. if (opacity === 0){
  914. if (el.style.visibility != "hidden") { el.style.visibility = "hidden";}
  915. } else {
  916. if (el.style.visibility != "visible") { el.style.visibility = "visible";}
  917. }
  918. return el;
  919. },
  920. replaceAll: function(exstr,ov,value){
  921. var gc=Sigma.U.escapeRegExp(ov);
  922. if ( !Sigma.$chk(gc) || gc===''){
  923. return exstr;
  924. }
  925. var rep="/"+gc+"/gm";
  926. var r=null;
  927. var cmd="r=exstr.replace("+rep+","+Sigma.U.escapeString(value)+")";
  928. eval(cmd);
  929. return r;
  930. },
  931. trim: function(str, wh){
  932. if( !str || !str.replace || !str.length ){ return str; }
  933. var re = (wh > 0) ? (/^\s+/) : (wh < 0) ? (/\s+$/) : (/^\s+|\s+$/g);
  934. return str.replace(re, '');
  935. },
  936. escapeRegExp: function(str) {
  937. return !str?''+str:(''+str).replace(/\\/gm, "\\\\").replace(/([\f\b\n\t\r[\^$|?*+(){}])/gm, "\\$1");
  938. },
  939. escapeString: function(str){
  940. return str===''?'""':( !str?''+str:
  941. (
  942. '"' + (''+str).replace(/(["\\])/g, '\\$1') + '"'
  943. ).replace(/[\f]/g, "\\f"
  944. ).replace(/[\b]/g, "\\b"
  945. ).replace(/[\n]/g, "\\n"
  946. ).replace(/[\t]/g, "\\t"
  947. ).replace(/[\r]/g, "\\r") );
  948. },
  949. bind: function(fn,bindObj,args){
  950. args=[].concat(args);
  951. return function(){
  952. return fn.apply(bindObj||fn, Sigma.U.merge(Sigma.$A(arguments),args) );
  953. };
  954. },
  955. bindAsEventListener: function(fn,bindObj,args){
  956. return function(event){
  957. event= event||window.event;
  958. return fn.apply(bindObj||fn, [ Sigma.$event(event) ].concat(args));
  959. };
  960. },
  961. clean: function(str){
  962. return Sigma.U.trim(str.replace(/\s{2,}/g, ' '));
  963. },
  964. contains: function(arr,item, from){
  965. return Sigma.U.indexOf(arr,item, from) != -1;
  966. },
  967. merge:function(arr,coll,isOverride){
  968. var minEnd= arr.length<coll.length?arr.length:coll.length;
  969. var i,j;
  970. if (isOverride){
  971. for (i = 0, j = minEnd; i < j; i++) {
  972. arr[i]=coll[i];
  973. }
  974. }
  975. for (i = minEnd, j = coll.length; i < j; i++) {
  976. arr[i]=coll[i];
  977. }
  978. return arr;
  979. },
  980. each: function(arr,fn, bind){
  981. return Sigma.$each(arr,fn,bind);
  982. },
  983. indexOf: function(arr,item, from){
  984. var len = arr.length;
  985. for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
  986. if (arr[i] === item) { return i; }
  987. }
  988. return -1;
  989. },
  990. remove: function(arr,item,all){
  991. var i = 0;
  992. var len = arr.length;
  993. while (i < len){
  994. if (arr[i] === item){
  995. arr.splice(i, 1);
  996. if (!all){ return arr ;}
  997. len--;
  998. } else {
  999. i++;
  1000. }
  1001. }
  1002. return arr;
  1003. },
  1004. next : function(arr,item){
  1005. var t = Sigma.U.indexOf(arr,item);
  1006. if (t<0){
  1007. return null;
  1008. }
  1009. return arr[t+1];
  1010. },
  1011. previous : function(arr,item){
  1012. var t = Sigma.U.indexOf(arr,item);
  1013. if (t<1){
  1014. return null;
  1015. }
  1016. return arr[t-1];
  1017. },
  1018. createStyleSheet : function(id,doc){
  1019. doc = doc||Sigma.doc;
  1020. var styleS = doc.createElement("style");
  1021. styleS.id=id;
  1022. var head=doc.getElementsByTagName('head')[0];
  1023. head && head.appendChild(styleS);
  1024. return styleS;
  1025. },
  1026. getCheckboxState : function(inputs,name){
  1027. var rs={};
  1028. for (var i=0;i<inputs.length ;i++ ){
  1029. if (inputs[i].name==name && inputs[i].checked ){
  1030. rs[inputs[i].value]= inputs[i].checked;
  1031. }
  1032. }
  1033. return rs;
  1034. }
  1035. };
  1036. Sigma.Util = Sigma.Utils;
  1037. Sigma.U = Sigma.Utils;
  1038. //=============================================
  1039. Sigma.Utils.CSS = function(){
  1040. var rules = null;
  1041. return {
  1042. createStyleSheet : function(cssText, id, docT){
  1043. var ss;
  1044. docT = docT || Sigma.doc;
  1045. var heads=docT.getElementsByTagName("head");
  1046. if (!heads || heads.length<1){
  1047. heads=docT.createElement('head');
  1048. if (docT.documentElement) {
  1049. docT.documentElement.insertBefore(heads,docT.body);
  1050. }else{
  1051. docT.appendChild(heads);
  1052. }
  1053. heads=docT.getElementsByTagName("head");
  1054. }
  1055. var head=heads[0];
  1056. var rules = docT.createElement("style");
  1057. rules.setAttribute("type", "text/css");
  1058. if(id){
  1059. rules.setAttribute("id", id);
  1060. }
  1061. if(Sigma.isIE){
  1062. head.appendChild(rules);
  1063. ss = rules.styleSheet;
  1064. ss.cssText = cssText;
  1065. }else{
  1066. try{
  1067. rules.appendChild(docT.createTextNode(cssText));
  1068. }catch(e){
  1069. rules.cssText = cssText;
  1070. }
  1071. head.appendChild(rules);
  1072. ss = rules.styleSheet ? rules.styleSheet : (rules.sheet || docT.styleSheets[docT.styleSheets.length-1]);
  1073. }
  1074. this.cacheStyleSheet(ss);
  1075. return ss;
  1076. },
  1077. getRules : function(refreshCache,docT){
  1078. docT = docT || Sigma.doc;
  1079. if( !rules || refreshCache){
  1080. rules = {};
  1081. var ds = docT.styleSheets;
  1082. for(var i =0, len = ds.length; i < len; i++){
  1083. this.cacheStyleSheet(ds[i]);
  1084. }
  1085. }
  1086. return rules;
  1087. },
  1088. getRule : function(selector, refreshCache){
  1089. var rs = this.getRules(refreshCache);
  1090. return rs[selector.toLowerCase()];
  1091. },
  1092. updateRule : function(selector,property, value){
  1093. var rule = this.getRule(selector);
  1094. if(rule){
  1095. rule.style[property] = value ;
  1096. }
  1097. },
  1098. // private
  1099. cacheStyleSheet : function(ss){
  1100. rules = rules || {};
  1101. try{// try catch for cross domain access issue
  1102. var ssRules = ss.cssRules || ss.rules;
  1103. for(var j = ssRules.length-1; j >= 0; --j){
  1104. rules[ssRules[j].selectorText.toLowerCase()] = ssRules[j];
  1105. }
  1106. }catch(e){}
  1107. }
  1108. };
  1109. }();
  1110. ////////////////////////////////////////////
  1111. Sigma.$event= function(event){
  1112. event = event || window.event;
  1113. //event.fromElement=Sigma.U.getEventTarget(event);
  1114. return event;
  1115. };
  1116. Sigma.EventCache = (function (){
  1117. var listEvents = [];
  1118. var nodeList =[];
  1119. var eventList ={};
  1120. function getKey(n){
  1121. return ''+n+'_'+n.id;
  1122. }
  1123. return {
  1124. add : function (node, type, fn){
  1125. if(!node) { return; }
  1126. if (! Sigma.U.contains(listEvents,arguments)){
  1127. listEvents.push(arguments);
  1128. }
  1129. var idx= Sigma.U.indexOf(nodeList,node);
  1130. var key=idx+'_'+ node +'_'+ node.id;
  1131. if(idx<0){
  1132. key=nodeList.length+'_'+ node +'_'+ node.id;
  1133. nodeList.push(node);
  1134. eventList[key]={};
  1135. }
  1136. eventList[key][type]= eventList[key][type] || [];
  1137. if ( ! Sigma.U.contains(eventList[key][type],fn)) {
  1138. eventList[key][type].push(fn);
  1139. }
  1140. },
  1141. remove : function (node, type, fn){
  1142. if(!node) { return; }
  1143. var idx=Sigma.U.indexOf(nodeList,node);
  1144. var key=idx+'_'+ node +'_'+ node.id;
  1145. if(idx<0 || !eventList[key]) {return;}
  1146. if (!type){
  1147. eventList[key]=null;
  1148. nodeList[idx]=null;
  1149. return ;
  1150. }
  1151. if (!fn && eventList[key][type]){
  1152. eventList[key][type]=null;
  1153. delete eventList[key][type];
  1154. }
  1155. if (eventList[key][type]){
  1156. eventList[key][type].remove(fn);
  1157. }
  1158. },
  1159. clearUp : function (){
  1160. var i, item;
  1161. for (i = listEvents.length - 1;i>=0;i=i-1){
  1162. item = listEvents[i];
  1163. Sigma.EventCache.remove(item[0]);
  1164. if (item[0].removeEventListener){
  1165. item[0].removeEventListener(item[1], item[2], item[3]);
  1166. }
  1167. if (item[1].substring( 0 , 2 ) != "on" ){
  1168. item[1] = "on" + item[1];
  1169. }
  1170. if (item[0].detachEvent){
  1171. item[0].detachEvent(item[1], item[2]);
  1172. }
  1173. item[0][item[1]] = null ;
  1174. delete listEvents[i];
  1175. }
  1176. Sigma.destroyGrids && Sigma.destroyGrids();
  1177. Sigma.destroyWidgets && Sigma.destroyWidgets();
  1178. window.CollectGarbage && CollectGarbage();
  1179. }
  1180. };
  1181. })();
  1182. Sigma.toQueryString = function(source){
  1183. if ( !source || Sigma.$type(source,'string','number') ) {
  1184. return source;
  1185. }
  1186. var queryString = [];
  1187. for (var property in source) {
  1188. var value=source[property];
  1189. if (value!==undefined) {
  1190. value=[].concat(value);
  1191. }
  1192. for (var i=0;i<value.length;i++) {
  1193. var val =value[i];
  1194. if (Sigma.$type(val,'object')){
  1195. val=Sigma.$json(val);
  1196. }
  1197. queryString.push(encodeURIComponent(property) + '=' + encodeURIComponent(val) );
  1198. }
  1199. }
  1200. return queryString.join('&');
  1201. };
  1202. Sigma.toJSONString = function(source,format){
  1203. return Sigma.JSON.encode(source,'__gt_',format);
  1204. };
  1205. Sigma.$json = Sigma.toJSONString;
  1206. ////////////////////////
  1207. Sigma.FunctionCache={};
  1208. Sigma.$invoke = function(obj, funcName , argsList){
  1209. obj=obj||window;
  1210. var func= obj[funcName] || Sigma.$getFunction(funcName) ;
  1211. if (typeof(func)=='function'){
  1212. return func.apply(obj,argsList||[] );
  1213. }
  1214. };
  1215. Sigma.$getFunction = function(funName){
  1216. return Sigma.FunctionCache[funName];
  1217. };
  1218. Sigma.$callFunction = function(funName ,argsList ){
  1219. Sigma.$invoke(null , funName ,argsList );
  1220. };
  1221. Sigma.$putFunction = function(funName ,func ){
  1222. Sigma.FunctionCache[funName]=func;
  1223. };
  1224. Sigma.$removeFunction = function(funName){
  1225. Sigma.FunctionCache[funName]=null;
  1226. delete Sigma.FunctionCache[funName];
  1227. };
  1228. Sigma.U.onLoad(function(){
  1229. Sigma.U.addEvent(window,"unload",Sigma.EventCache.clearUp);
  1230. });
  1231. //