JAVASCRIPT   97

logic.js

Guest on 27th September 2021 12:22:23 PM

  1. /*
  2.         Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3.         Available via Academic Free License >= 2.1 OR the modified BSD license.
  4.         see: http://dojotoolkit.org/license for details
  5. */
  6.  
  7.  
  8. if(!dojo._hasResource["dojox.dtl.tag.logic"]){
  9. dojo._hasResource["dojox.dtl.tag.logic"]=true;
  10. dojo.provide("dojox.dtl.tag.logic");
  11. dojo.require("dojox.dtl._base");
  12. (function(){
  13. var dd=dojox.dtl;
  14. var _1=dd.text;
  15. var _2=dd.tag.logic;
  16. _2.IfNode=dojo.extend(function(_3,_4,_5,_6){
  17. this.bools=_3;
  18. this.trues=_4;
  19. this.falses=_5;
  20. this.type=_6;
  21. },{render:function(_7,_8){
  22. var i,_9,_a,_b,_c;
  23. if(this.type=="or"){
  24. for(i=0;_9=this.bools[i];i++){
  25. _a=_9[0];
  26. _b=_9[1];
  27. _c=_b.resolve(_7);
  28. if((_c&&!_a)||(_a&&!_c)){
  29. if(this.falses){
  30. _8=this.falses.unrender(_7,_8);
  31. }
  32. return (this.trues)?this.trues.render(_7,_8,this):_8;
  33. }
  34. }
  35. if(this.trues){
  36. _8=this.trues.unrender(_7,_8);
  37. }
  38. return (this.falses)?this.falses.render(_7,_8,this):_8;
  39. }else{
  40. for(i=0;_9=this.bools[i];i++){
  41. _a=_9[0];
  42. _b=_9[1];
  43. _c=_b.resolve(_7);
  44. if(_c==_a){
  45. if(this.trues){
  46. _8=this.trues.unrender(_7,_8);
  47. }
  48. return (this.falses)?this.falses.render(_7,_8,this):_8;
  49. }
  50. }
  51. if(this.falses){
  52. _8=this.falses.unrender(_7,_8);
  53. }
  54. return (this.trues)?this.trues.render(_7,_8,this):_8;
  55. }
  56. return _8;
  57. },unrender:function(_d,_e){
  58. _e=(this.trues)?this.trues.unrender(_d,_e):_e;
  59. _e=(this.falses)?this.falses.unrender(_d,_e):_e;
  60. return _e;
  61. },clone:function(_f){
  62. var _10=(this.trues)?this.trues.clone(_f):null;
  63. var _11=(this.falses)?this.falses.clone(_f):null;
  64. return new this.constructor(this.bools,_10,_11,this.type);
  65. }});
  66. _2.IfEqualNode=dojo.extend(function(_12,_13,_14,_15,_16){
  67. this.var1=new dd._Filter(_12);
  68. this.var2=new dd._Filter(_13);
  69. this.trues=_14;
  70. this.falses=_15;
  71. this.negate=_16;
  72. },{render:function(_17,_18){
  73. var _19=this.var1.resolve(_17);
  74. var _1a=this.var2.resolve(_17);
  75. _19=(typeof _19!="undefined")?_19:"";
  76. _1a=(typeof _19!="undefined")?_1a:"";
  77. if((this.negate&&_19!=_1a)||(!this.negate&&_19==_1a)){
  78. if(this.falses){
  79. _18=this.falses.unrender(_17,_18,this);
  80. }
  81. return (this.trues)?this.trues.render(_17,_18,this):_18;
  82. }
  83. if(this.trues){
  84. _18=this.trues.unrender(_17,_18,this);
  85. }
  86. return (this.falses)?this.falses.render(_17,_18,this):_18;
  87. },unrender:function(_1b,_1c){
  88. return _2.IfNode.prototype.unrender.call(this,_1b,_1c);
  89. },clone:function(_1d){
  90. var _1e=this.trues?this.trues.clone(_1d):null;
  91. var _1f=this.falses?this.falses.clone(_1d):null;
  92. return new this.constructor(this.var1.getExpression(),this.var2.getExpression(),_1e,_1f,this.negate);
  93. }});
  94. _2.ForNode=dojo.extend(function(_20,_21,_22,_23){
  95. this.assign=_20;
  96. this.loop=new dd._Filter(_21);
  97. this.reversed=_22;
  98. this.nodelist=_23;
  99. this.pool=[];
  100. },{render:function(_24,_25){
  101. var i,j,k;
  102. var _26=false;
  103. var _27=this.assign;
  104. for(k=0;k<_27.length;k++){
  105. if(typeof _24[_27[k]]!="undefined"){
  106. _26=true;
  107. _24=_24.push();
  108. break;
  109. }
  110. }
  111. if(!_26&&_24.forloop){
  112. _26=true;
  113. _24=_24.push();
  114. }
  115. var _28=this.loop.resolve(_24)||[];
  116. for(i=_28.length;i<this.pool.length;i++){
  117. this.pool[i].unrender(_24,_25,this);
  118. }
  119. if(this.reversed){
  120. _28=_28.slice(0).reverse();
  121. }
  122. var _29=dojo.isObject(_28)&&!dojo.isArrayLike(_28);
  123. var _2a=[];
  124. if(_29){
  125. for(var key in _28){
  126. _2a.push(_28[key]);
  127. }
  128. }else{
  129. _2a=_28;
  130. }
  131. var _2b=_24.forloop={parentloop:_24.get("forloop",{})};
  132. var j=0;
  133. for(i=0;i<_2a.length;i++){
  134. var _2c=_2a[i];
  135. _2b.counter0=j;
  136. _2b.counter=j+1;
  137. _2b.revcounter0=_2a.length-j-1;
  138. _2b.revcounter=_2a.length-j;
  139. _2b.first=!j;
  140. _2b.last=(j==_2a.length-1);
  141. if(_27.length>1&&dojo.isArrayLike(_2c)){
  142. if(!_26){
  143. _26=true;
  144. _24=_24.push();
  145. }
  146. var _2d={};
  147. for(k=0;k<_2c.length&&k<_27.length;k++){
  148. _2d[_27[k]]=_2c[k];
  149. }
  150. dojo.mixin(_24,_2d);
  151. }else{
  152. _24[_27[0]]=_2c;
  153. }
  154. if(j+1>this.pool.length){
  155. this.pool.push(this.nodelist.clone(_25));
  156. }
  157. _25=this.pool[j++].render(_24,_25,this);
  158. }
  159. delete _24.forloop;
  160. if(_26){
  161. _24=_24.pop();
  162. }else{
  163. for(k=0;k<_27.length;k++){
  164. delete _24[_27[k]];
  165. }
  166. }
  167. return _25;
  168. },unrender:function(_2e,_2f){
  169. for(var i=0,_30;_30=this.pool[i];i++){
  170. _2f=_30.unrender(_2e,_2f);
  171. }
  172. return _2f;
  173. },clone:function(_31){
  174. return new this.constructor(this.assign,this.loop.getExpression(),this.reversed,this.nodelist.clone(_31));
  175. }});
  176. dojo.mixin(_2,{if_:function(_32,_33){
  177. var i,_34,_35,_36=[],_37=_33.contents.split();
  178. _37.shift();
  179. _33=_37.join(" ");
  180. _37=_33.split(" and ");
  181. if(_37.length==1){
  182. _35="or";
  183. _37=_33.split(" or ");
  184. }else{
  185. _35="and";
  186. for(i=0;i<_37.length;i++){
  187. if(_37[i].indexOf(" or ")!=-1){
  188. throw new Error("'if' tags can't mix 'and' and 'or'");
  189. }
  190. }
  191. }
  192. for(i=0;_34=_37[i];i++){
  193. var not=false;
  194. if(_34.indexOf("not ")==0){
  195. _34=_34.slice(4);
  196. not=true;
  197. }
  198. _36.push([not,new dd._Filter(_34)]);
  199. }
  200. var _38=_32.parse(["else","endif"]);
  201. var _39=false;
  202. var _33=_32.next_token();
  203. if(_33.contents=="else"){
  204. _39=_32.parse(["endif"]);
  205. _32.next_token();
  206. }
  207. return new _2.IfNode(_36,_38,_39,_35);
  208. },_ifequal:function(_3a,_3b,_3c){
  209. var _3d=_3b.split_contents();
  210. if(_3d.length!=3){
  211. throw new Error(_3d[0]+" takes two arguments");
  212. }
  213. var end="end"+_3d[0];
  214. var _3e=_3a.parse(["else",end]);
  215. var _3f=false;
  216. var _3b=_3a.next_token();
  217. if(_3b.contents=="else"){
  218. _3f=_3a.parse([end]);
  219. _3a.next_token();
  220. }
  221. return new _2.IfEqualNode(_3d[1],_3d[2],_3e,_3f,_3c);
  222. },ifequal:function(_40,_41){
  223. return _2._ifequal(_40,_41);
  224. },ifnotequal:function(_42,_43){
  225. return _2._ifequal(_42,_43,true);
  226. },for_:function(_44,_45){
  227. var _46=_45.contents.split();
  228. if(_46.length<4){
  229. throw new Error("'for' statements should have at least four words: "+_45.contents);
  230. }
  231. var _47=_46[_46.length-1]=="reversed";
  232. var _48=(_47)?-3:-2;
  233. if(_46[_46.length+_48]!="in"){
  234. throw new Error("'for' tag received an invalid argument: "+_45.contents);
  235. }
  236. var _49=_46.slice(1,_48).join(" ").split(/ *, */);
  237. for(var i=0;i<_49.length;i++){
  238. if(!_49[i]||_49[i].indexOf(" ")!=-1){
  239. throw new Error("'for' tag received an invalid argument: "+_45.contents);
  240. }
  241. }
  242. var _4a=_44.parse(["endfor"]);
  243. _44.next_token();
  244. return new _2.ForNode(_49,_46[_46.length+_48+1],_47,_4a);
  245. }});
  246. })();
  247. }

Raw Paste


Login or Register to edit or fork this paste. It's free.