dtl.js.uncompressed.js 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865
  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. This is an optimized version of Dojo, built for deployment and not for
  8. development. To get sources and documentation, please visit:
  9. http://dojotoolkit.org
  10. */
  11. if(!dojo._hasResource["dojox.string.Builder"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  12. dojo._hasResource["dojox.string.Builder"] = true;
  13. dojo.provide("dojox.string.Builder");
  14. dojox.string.Builder = function(/*String?*/str){
  15. // summary:
  16. // A fast buffer for creating large strings.
  17. //
  18. // length: Number
  19. // The current length of the internal string.
  20. // N.B. the public nature of the internal buffer is no longer
  21. // needed because the IE-specific fork is no longer needed--TRT.
  22. var b = "";
  23. this.length = 0;
  24. this.append = function(/* String... */s){
  25. // summary: Append all arguments to the end of the buffer
  26. if(arguments.length>1){
  27. /*
  28. This is a loop unroll was designed specifically for Firefox;
  29. it would seem that static index access on an Arguments
  30. object is a LOT faster than doing dynamic index access.
  31. Therefore, we create a buffer string and take advantage
  32. of JS's switch fallthrough. The peformance of this method
  33. comes very close to straight up string concatenation (+=).
  34. If the arguments object length is greater than 9, we fall
  35. back to standard dynamic access.
  36. This optimization seems to have no real effect on either
  37. Safari or Opera, so we just use it for all.
  38. It turns out also that this loop unroll can increase performance
  39. significantly with Internet Explorer, particularly when
  40. as many arguments are provided as possible.
  41. Loop unroll per suggestion from Kris Zyp, implemented by
  42. Tom Trenka.
  43. Note: added empty string to force a string cast if needed.
  44. */
  45. var tmp="", l=arguments.length;
  46. switch(l){
  47. case 9: tmp=""+arguments[8]+tmp;
  48. case 8: tmp=""+arguments[7]+tmp;
  49. case 7: tmp=""+arguments[6]+tmp;
  50. case 6: tmp=""+arguments[5]+tmp;
  51. case 5: tmp=""+arguments[4]+tmp;
  52. case 4: tmp=""+arguments[3]+tmp;
  53. case 3: tmp=""+arguments[2]+tmp;
  54. case 2: {
  55. b+=""+arguments[0]+arguments[1]+tmp;
  56. break;
  57. }
  58. default: {
  59. var i=0;
  60. while(i<arguments.length){
  61. tmp += arguments[i++];
  62. }
  63. b += tmp;
  64. }
  65. }
  66. } else {
  67. b += s;
  68. }
  69. this.length = b.length;
  70. return this; // dojox.string.Builder
  71. };
  72. this.concat = function(/*String...*/s){
  73. // summary:
  74. // Alias for append.
  75. return this.append.apply(this, arguments); // dojox.string.Builder
  76. };
  77. this.appendArray = function(/*Array*/strings) {
  78. // summary:
  79. // Append an array of items to the internal buffer.
  80. // Changed from String.prototype.concat.apply because of IE.
  81. return this.append.apply(this, strings); // dojox.string.Builder
  82. };
  83. this.clear = function(){
  84. // summary:
  85. // Remove all characters from the buffer.
  86. b = "";
  87. this.length = 0;
  88. return this; // dojox.string.Builder
  89. };
  90. this.replace = function(/* String */oldStr, /* String */ newStr){
  91. // summary:
  92. // Replace instances of one string with another in the buffer.
  93. b = b.replace(oldStr,newStr);
  94. this.length = b.length;
  95. return this; // dojox.string.Builder
  96. };
  97. this.remove = function(/* Number */start, /* Number? */len){
  98. // summary:
  99. // Remove len characters starting at index start. If len
  100. // is not provided, the end of the string is assumed.
  101. if(len===undefined){ len = b.length; }
  102. if(len == 0){ return this; }
  103. b = b.substr(0, start) + b.substr(start+len);
  104. this.length = b.length;
  105. return this; // dojox.string.Builder
  106. };
  107. this.insert = function(/* Number */index, /* String */str){
  108. // summary:
  109. // Insert string str starting at index.
  110. if(index == 0){
  111. b = str + b;
  112. }else{
  113. b = b.slice(0, index) + str + b.slice(index);
  114. }
  115. this.length = b.length;
  116. return this; // dojox.string.Builder
  117. };
  118. this.toString = function(){
  119. // summary:
  120. // Return the string representation of the internal buffer.
  121. return b; // String
  122. };
  123. // initialize the buffer.
  124. if(str){ this.append(str); }
  125. };
  126. }
  127. if(!dojo._hasResource["dojox.string.tokenize"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  128. dojo._hasResource["dojox.string.tokenize"] = true;
  129. dojo.provide("dojox.string.tokenize");
  130. dojox.string.tokenize = function(/*String*/ str, /*RegExp*/ re, /*Function?*/ parseDelim, /*Object?*/ instance){
  131. // summary:
  132. // Split a string by a regular expression with the ability to capture the delimeters
  133. // parseDelim:
  134. // Each group (excluding the 0 group) is passed as a parameter. If the function returns
  135. // a value, it's added to the list of tokens.
  136. // instance:
  137. // Used as the "this" instance when calling parseDelim
  138. var tokens = [];
  139. var match, content, lastIndex = 0;
  140. while(match = re.exec(str)){
  141. content = str.slice(lastIndex, re.lastIndex - match[0].length);
  142. if(content.length){
  143. tokens.push(content);
  144. }
  145. if(parseDelim){
  146. if(dojo.isOpera){
  147. var copy = match.slice(0);
  148. while(copy.length < match.length){
  149. copy.push(null);
  150. }
  151. match = copy;
  152. }
  153. var parsed = parseDelim.apply(instance, match.slice(1).concat(tokens.length));
  154. if(typeof parsed != "undefined"){
  155. tokens.push(parsed);
  156. }
  157. }
  158. lastIndex = re.lastIndex;
  159. }
  160. content = str.slice(lastIndex);
  161. if(content.length){
  162. tokens.push(content);
  163. }
  164. return tokens;
  165. }
  166. }
  167. if(!dojo._hasResource["dojox.dtl._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  168. dojo._hasResource["dojox.dtl._base"] = true;
  169. dojo.provide("dojox.dtl._base");
  170. dojo.experimental("dojox.dtl");
  171. (function(){
  172. var dd = dojox.dtl;
  173. dd.TOKEN_BLOCK = -1;
  174. dd.TOKEN_VAR = -2;
  175. dd.TOKEN_COMMENT = -3;
  176. dd.TOKEN_TEXT = 3;
  177. dd._Context = dojo.extend(function(dict){
  178. // summary: Pass one of these when rendering a template to tell the template what values to use.
  179. if(dict){
  180. dojo._mixin(this, dict);
  181. if(dict.get){
  182. // Preserve passed getter and restore prototype get
  183. this._getter = dict.get;
  184. delete this.get;
  185. }
  186. }
  187. },
  188. {
  189. push: function(){
  190. var last = this;
  191. var context = dojo.delegate(this);
  192. context.pop = function(){ return last; }
  193. return context;
  194. },
  195. pop: function(){
  196. throw new Error("pop() called on empty Context");
  197. },
  198. get: function(key, otherwise){
  199. var n = this._normalize;
  200. if(this._getter){
  201. var got = this._getter(key);
  202. if(typeof got != "undefined"){
  203. return n(got);
  204. }
  205. }
  206. if(typeof this[key] != "undefined"){
  207. return n(this[key]);
  208. }
  209. return otherwise;
  210. },
  211. _normalize: function(value){
  212. if(value instanceof Date){
  213. value.year = value.getFullYear();
  214. value.month = value.getMonth() + 1;
  215. value.day = value.getDate();
  216. value.date = value.year + "-" + ("0" + value.month).slice(-2) + "-" + ("0" + value.day).slice(-2);
  217. value.hour = value.getHours();
  218. value.minute = value.getMinutes();
  219. value.second = value.getSeconds();
  220. value.microsecond = value.getMilliseconds();
  221. }
  222. return value;
  223. },
  224. update: function(dict){
  225. var context = this.push();
  226. if(dict){
  227. dojo._mixin(this, dict);
  228. }
  229. return context;
  230. }
  231. });
  232. var smart_split_re = /("(?:[^"\\]*(?:\\.[^"\\]*)*)"|'(?:[^'\\]*(?:\\.[^'\\]*)*)'|[^\s]+)/g;
  233. var split_re = /\s+/g;
  234. var split = function(/*String|RegExp?*/ splitter, /*Integer?*/ limit){
  235. splitter = splitter || split_re;
  236. if(!(splitter instanceof RegExp)){
  237. splitter = new RegExp(splitter, "g");
  238. }
  239. if(!splitter.global){
  240. throw new Error("You must use a globally flagged RegExp with split " + splitter);
  241. }
  242. splitter.exec(""); // Reset the global
  243. var part, parts = [], lastIndex = 0, i = 0;
  244. while(part = splitter.exec(this)){
  245. parts.push(this.slice(lastIndex, splitter.lastIndex - part[0].length));
  246. lastIndex = splitter.lastIndex;
  247. if(limit && (++i > limit - 1)){
  248. break;
  249. }
  250. }
  251. parts.push(this.slice(lastIndex));
  252. return parts;
  253. }
  254. dd.Token = function(token_type, contents){
  255. this.token_type = token_type;
  256. this.contents = new String(dojo.trim(contents));
  257. this.contents.split = split;
  258. this.split = function(){
  259. return String.prototype.split.apply(this.contents, arguments);
  260. }
  261. }
  262. dd.Token.prototype.split_contents = function(/*Integer?*/ limit){
  263. var bit, bits = [], i = 0;
  264. limit = limit || 999;
  265. while(i++ < limit && (bit = smart_split_re.exec(this.contents))){
  266. bit = bit[0];
  267. if(bit.charAt(0) == '"' && bit.slice(-1) == '"'){
  268. bits.push('"' + bit.slice(1, -1).replace('\\"', '"').replace('\\\\', '\\') + '"');
  269. }else if(bit.charAt(0) == "'" && bit.slice(-1) == "'"){
  270. bits.push("'" + bit.slice(1, -1).replace("\\'", "'").replace('\\\\', '\\') + "'");
  271. }else{
  272. bits.push(bit);
  273. }
  274. }
  275. return bits;
  276. }
  277. var ddt = dd.text = {
  278. _get: function(module, name, errorless){
  279. // summary: Used to find both tags and filters
  280. var params = dd.register.get(module, name.toLowerCase(), errorless);
  281. if(!params){
  282. if(!errorless){
  283. throw new Error("No tag found for " + name);
  284. }
  285. return null;
  286. }
  287. var fn = params[1];
  288. var require = params[2];
  289. var parts;
  290. if(fn.indexOf(":") != -1){
  291. parts = fn.split(":");
  292. fn = parts.pop();
  293. }
  294. dojo["require"](require);
  295. var parent = dojo.getObject(require);
  296. return parent[fn || name] || parent[name + "_"] || parent[fn + "_"];
  297. },
  298. getTag: function(name, errorless){
  299. return ddt._get("tag", name, errorless);
  300. },
  301. getFilter: function(name, errorless){
  302. return ddt._get("filter", name, errorless);
  303. },
  304. getTemplate: function(file){
  305. return new dd.Template(ddt.getTemplateString(file));
  306. },
  307. getTemplateString: function(file){
  308. return dojo._getText(file.toString()) || "";
  309. },
  310. _resolveLazy: function(location, sync, json){
  311. if(sync){
  312. if(json){
  313. return dojo.fromJson(dojo._getText(location)) || {};
  314. }else{
  315. return dd.text.getTemplateString(location);
  316. }
  317. }else{
  318. return dojo.xhrGet({
  319. handleAs: (json) ? "json" : "text",
  320. url: location
  321. });
  322. }
  323. },
  324. _resolveTemplateArg: function(arg, sync){
  325. if(ddt._isTemplate(arg)){
  326. if(!sync){
  327. var d = new dojo.Deferred();
  328. d.callback(arg);
  329. return d;
  330. }
  331. return arg;
  332. }
  333. return ddt._resolveLazy(arg, sync);
  334. },
  335. _isTemplate: function(arg){
  336. return (typeof arg == "undefined") || (typeof arg == "string" && (arg.match(/^\s*[<{]/) || arg.indexOf(" ") != -1));
  337. },
  338. _resolveContextArg: function(arg, sync){
  339. if(arg.constructor == Object){
  340. if(!sync){
  341. var d = new dojo.Deferred;
  342. d.callback(arg);
  343. return d;
  344. }
  345. return arg;
  346. }
  347. return ddt._resolveLazy(arg, sync, true);
  348. },
  349. _re: /(?:\{\{\s*(.+?)\s*\}\}|\{%\s*(load\s*)?(.+?)\s*%\})/g,
  350. tokenize: function(str){
  351. return dojox.string.tokenize(str, ddt._re, ddt._parseDelims);
  352. },
  353. _parseDelims: function(varr, load, tag){
  354. if(varr){
  355. return [dd.TOKEN_VAR, varr];
  356. }else if(load){
  357. var parts = dojo.trim(tag).split(/\s+/g);
  358. for(var i = 0, part; part = parts[i]; i++){
  359. dojo["require"](part);
  360. }
  361. }else{
  362. return [dd.TOKEN_BLOCK, tag];
  363. }
  364. }
  365. }
  366. dd.Template = dojo.extend(function(/*String|dojo._Url*/ template, /*Boolean*/ isString){
  367. // template:
  368. // The string or location of the string to
  369. // use as a template
  370. var str = isString ? template : ddt._resolveTemplateArg(template, true) || "";
  371. var tokens = ddt.tokenize(str);
  372. var parser = new dd._Parser(tokens);
  373. this.nodelist = parser.parse();
  374. },
  375. {
  376. update: function(node, context){
  377. // node: DOMNode|String|dojo.NodeList
  378. // A node reference or set of nodes
  379. // context: dojo._Url|String|Object
  380. // The context object or location
  381. return ddt._resolveContextArg(context).addCallback(this, function(contextObject){
  382. var content = this.render(new dd._Context(contextObject));
  383. if(node.forEach){
  384. node.forEach(function(item){
  385. item.innerHTML = content;
  386. });
  387. }else{
  388. dojo.byId(node).innerHTML = content;
  389. }
  390. return this;
  391. });
  392. },
  393. render: function(context, /*concatenatable?*/ buffer){
  394. buffer = buffer || this.getBuffer();
  395. context = context || new dd._Context({});
  396. return this.nodelist.render(context, buffer) + "";
  397. },
  398. getBuffer: function(){
  399. return new dojox.string.Builder();
  400. }
  401. });
  402. var qfRe = /\{\{\s*(.+?)\s*\}\}/g;
  403. dd.quickFilter = function(str){
  404. if(!str){
  405. return new dd._NodeList();
  406. }
  407. if(str.indexOf("{%") == -1){
  408. return new dd._QuickNodeList(dojox.string.tokenize(str, qfRe, function(token){
  409. return new dd._Filter(token);
  410. }));
  411. }
  412. }
  413. dd._QuickNodeList = dojo.extend(function(contents){
  414. this.contents = contents;
  415. },
  416. {
  417. render: function(context, buffer){
  418. for(var i=0, l=this.contents.length; i<l; i++){
  419. if(this.contents[i].resolve){
  420. buffer = buffer.concat(this.contents[i].resolve(context));
  421. }else{
  422. buffer = buffer.concat(this.contents[i]);
  423. }
  424. }
  425. return buffer;
  426. },
  427. dummyRender: function(context){ return this.render(context, dd.Template.prototype.getBuffer()).toString(); },
  428. clone: function(buffer){ return this; }
  429. });
  430. dd._Filter = dojo.extend(function(token){
  431. // summary: Uses a string to find (and manipulate) a variable
  432. if(!token) throw new Error("Filter must be called with variable name");
  433. this.contents = token;
  434. var cache = this._cache[token];
  435. if(cache){
  436. this.key = cache[0];
  437. this.filters = cache[1];
  438. }else{
  439. this.filters = [];
  440. dojox.string.tokenize(token, this._re, this._tokenize, this);
  441. this._cache[token] = [this.key, this.filters];
  442. }
  443. },
  444. {
  445. _cache: {},
  446. _re: /(?:^_\("([^\\"]*(?:\\.[^\\"])*)"\)|^"([^\\"]*(?:\\.[^\\"]*)*)"|^([a-zA-Z0-9_.]+)|\|(\w+)(?::(?:_\("([^\\"]*(?:\\.[^\\"])*)"\)|"([^\\"]*(?:\\.[^\\"]*)*)"|([a-zA-Z0-9_.]+)|'([^\\']*(?:\\.[^\\']*)*)'))?|^'([^\\']*(?:\\.[^\\']*)*)')/g,
  447. _values: {
  448. 0: '"', // _("text")
  449. 1: '"', // "text"
  450. 2: "", // variable
  451. 8: '"' // 'text'
  452. },
  453. _args: {
  454. 4: '"', // :_("text")
  455. 5: '"', // :"text"
  456. 6: "", // :variable
  457. 7: "'"// :'text'
  458. },
  459. _tokenize: function(){
  460. var pos, arg;
  461. for(var i = 0, has = []; i < arguments.length; i++){
  462. has[i] = (typeof arguments[i] != "undefined" && typeof arguments[i] == "string" && arguments[i]);
  463. }
  464. if(!this.key){
  465. for(pos in this._values){
  466. if(has[pos]){
  467. this.key = this._values[pos] + arguments[pos] + this._values[pos];
  468. break;
  469. }
  470. }
  471. }else{
  472. for(pos in this._args){
  473. if(has[pos]){
  474. var value = arguments[pos];
  475. if(this._args[pos] == "'"){
  476. value = value.replace(/\\'/g, "'");
  477. }else if(this._args[pos] == '"'){
  478. value = value.replace(/\\"/g, '"');
  479. }
  480. arg = [!this._args[pos], value];
  481. break;
  482. }
  483. }
  484. // Get a named filter
  485. var fn = ddt.getFilter(arguments[3]);
  486. if(!dojo.isFunction(fn)) throw new Error(arguments[3] + " is not registered as a filter");
  487. this.filters.push([fn, arg]);
  488. }
  489. },
  490. getExpression: function(){
  491. return this.contents;
  492. },
  493. resolve: function(context){
  494. if(typeof this.key == "undefined"){
  495. return "";
  496. }
  497. var str = this.resolvePath(this.key, context);
  498. for(var i = 0, filter; filter = this.filters[i]; i++){
  499. // Each filter has the function in [0], a boolean in [1][0] of whether it's a variable or a string
  500. // and [1][1] is either the variable name of the string content.
  501. if(filter[1]){
  502. if(filter[1][0]){
  503. str = filter[0](str, this.resolvePath(filter[1][1], context));
  504. }else{
  505. str = filter[0](str, filter[1][1]);
  506. }
  507. }else{
  508. str = filter[0](str);
  509. }
  510. }
  511. return str;
  512. },
  513. resolvePath: function(path, context){
  514. var current, parts;
  515. var first = path.charAt(0);
  516. var last = path.slice(-1);
  517. if(!isNaN(parseInt(first))){
  518. current = (path.indexOf(".") == -1) ? parseInt(path) : parseFloat(path);
  519. }else if(first == '"' && first == last){
  520. current = path.slice(1, -1);
  521. }else{
  522. if(path == "true"){ return true; }
  523. if(path == "false"){ return false; }
  524. if(path == "null" || path == "None"){ return null; }
  525. parts = path.split(".");
  526. current = context.get(parts[0]);
  527. if(dojo.isFunction(current)){
  528. var self = context.getThis && context.getThis();
  529. if(current.alters_data){
  530. current = "";
  531. }else if(self){
  532. current = current.call(self);
  533. }else{
  534. current = "";
  535. }
  536. }
  537. for(var i = 1; i < parts.length; i++){
  538. var part = parts[i];
  539. if(current){
  540. var base = current;
  541. if(dojo.isObject(current) && part == "items" && typeof current[part] == "undefined"){
  542. var items = [];
  543. for(var key in current){
  544. items.push([key, current[key]]);
  545. }
  546. current = items;
  547. continue;
  548. }
  549. if(current.get && dojo.isFunction(current.get) && current.get.safe){
  550. current = current.get(part);
  551. }else if(typeof current[part] == "undefined"){
  552. current = current[part];
  553. break;
  554. }else{
  555. current = current[part];
  556. }
  557. if(dojo.isFunction(current)){
  558. if(current.alters_data){
  559. current = "";
  560. }else{
  561. current = current.call(base);
  562. }
  563. }else if(current instanceof Date){
  564. current = dd._Context.prototype._normalize(current);
  565. }
  566. }else{
  567. return "";
  568. }
  569. }
  570. }
  571. return current;
  572. }
  573. });
  574. dd._TextNode = dd._Node = dojo.extend(function(/*Object*/ obj){
  575. // summary: Basic catch-all node
  576. this.contents = obj;
  577. },
  578. {
  579. set: function(data){
  580. this.contents = data;
  581. return this;
  582. },
  583. render: function(context, buffer){
  584. // summary: Adds content onto the buffer
  585. return buffer.concat(this.contents);
  586. },
  587. isEmpty: function(){
  588. return !dojo.trim(this.contents);
  589. },
  590. clone: function(){ return this; }
  591. });
  592. dd._NodeList = dojo.extend(function(/*Node[]*/ nodes){
  593. // summary: Allows us to render a group of nodes
  594. this.contents = nodes || [];
  595. this.last = "";
  596. },
  597. {
  598. push: function(node){
  599. // summary: Add a new node to the list
  600. this.contents.push(node);
  601. return this;
  602. },
  603. concat: function(nodes){
  604. this.contents = this.contents.concat(nodes);
  605. return this;
  606. },
  607. render: function(context, buffer){
  608. // summary: Adds all content onto the buffer
  609. for(var i = 0; i < this.contents.length; i++){
  610. buffer = this.contents[i].render(context, buffer);
  611. if(!buffer) throw new Error("Template must return buffer");
  612. }
  613. return buffer;
  614. },
  615. dummyRender: function(context){
  616. return this.render(context, dd.Template.prototype.getBuffer()).toString();
  617. },
  618. unrender: function(){ return arguments[1]; },
  619. clone: function(){ return this; },
  620. rtrim: function(){
  621. while(1){
  622. i = this.contents.length - 1;
  623. if(this.contents[i] instanceof dd._TextNode && this.contents[i].isEmpty()){
  624. this.contents.pop();
  625. }else{
  626. break;
  627. }
  628. }
  629. return this;
  630. }
  631. });
  632. dd._VarNode = dojo.extend(function(str){
  633. // summary: A node to be processed as a variable
  634. this.contents = new dd._Filter(str);
  635. },
  636. {
  637. render: function(context, buffer){
  638. var str = this.contents.resolve(context);
  639. if(!str.safe){
  640. str = dd._base.escape("" + str);
  641. }
  642. return buffer.concat(str);
  643. }
  644. });
  645. dd._noOpNode = new function(){
  646. // summary: Adds a no-op node. Useful in custom tags
  647. this.render = this.unrender = function(){ return arguments[1]; }
  648. this.clone = function(){ return this; }
  649. }
  650. dd._Parser = dojo.extend(function(tokens){
  651. // summary: Parser used during initialization and for tag groups.
  652. this.contents = tokens;
  653. },
  654. {
  655. i: 0,
  656. parse: function(/*Array?*/ stop_at){
  657. // summary: Turns tokens into nodes
  658. // description: Steps into tags are they're found. Blocks use the parse object
  659. // to find their closing tag (the stop_at array). stop_at is inclusive, it
  660. // returns the node that matched.
  661. var terminators = {}, token;
  662. stop_at = stop_at || [];
  663. for(var i = 0; i < stop_at.length; i++){
  664. terminators[stop_at[i]] = true;
  665. }
  666. var nodelist = new dd._NodeList();
  667. while(this.i < this.contents.length){
  668. token = this.contents[this.i++];
  669. if(typeof token == "string"){
  670. nodelist.push(new dd._TextNode(token));
  671. }else{
  672. var type = token[0];
  673. var text = token[1];
  674. if(type == dd.TOKEN_VAR){
  675. nodelist.push(new dd._VarNode(text));
  676. }else if(type == dd.TOKEN_BLOCK){
  677. if(terminators[text]){
  678. --this.i;
  679. return nodelist;
  680. }
  681. var cmd = text.split(/\s+/g);
  682. if(cmd.length){
  683. cmd = cmd[0];
  684. var fn = ddt.getTag(cmd);
  685. if(fn){
  686. nodelist.push(fn(this, new dd.Token(type, text)));
  687. }
  688. }
  689. }
  690. }
  691. }
  692. if(stop_at.length){
  693. throw new Error("Could not find closing tag(s): " + stop_at.toString());
  694. }
  695. this.contents.length = 0;
  696. return nodelist;
  697. },
  698. next_token: function(){
  699. // summary: Returns the next token in the list.
  700. var token = this.contents[this.i++];
  701. return new dd.Token(token[0], token[1]);
  702. },
  703. delete_first_token: function(){
  704. this.i++;
  705. },
  706. skip_past: function(endtag){
  707. while(this.i < this.contents.length){
  708. var token = this.contents[this.i++];
  709. if(token[0] == dd.TOKEN_BLOCK && token[1] == endtag){
  710. return;
  711. }
  712. }
  713. throw new Error("Unclosed tag found when looking for " + endtag);
  714. },
  715. create_variable_node: function(expr){
  716. return new dd._VarNode(expr);
  717. },
  718. create_text_node: function(expr){
  719. return new dd._TextNode(expr || "");
  720. },
  721. getTemplate: function(file){
  722. return new dd.Template(file);
  723. }
  724. });
  725. dd.register = {
  726. _registry: {
  727. attributes: [],
  728. tags: [],
  729. filters: []
  730. },
  731. get: function(/*String*/ module, /*String*/ name){
  732. var registry = dd.register._registry[module + "s"];
  733. for(var i = 0, entry; entry = registry[i]; i++){
  734. if(typeof entry[0] == "string"){
  735. if(entry[0] == name){
  736. return entry;
  737. }
  738. }else if(name.match(entry[0])){
  739. return entry;
  740. }
  741. }
  742. },
  743. getAttributeTags: function(){
  744. var tags = [];
  745. var registry = dd.register._registry.attributes;
  746. for(var i = 0, entry; entry = registry[i]; i++){
  747. if(entry.length == 3){
  748. tags.push(entry);
  749. }else{
  750. var fn = dojo.getObject(entry[1]);
  751. if(fn && dojo.isFunction(fn)){
  752. entry.push(fn);
  753. tags.push(entry);
  754. }
  755. }
  756. }
  757. return tags;
  758. },
  759. _any: function(type, base, locations){
  760. for(var path in locations){
  761. for(var i = 0, fn; fn = locations[path][i]; i++){
  762. var key = fn;
  763. if(dojo.isArray(fn)){
  764. key = fn[0];
  765. fn = fn[1];
  766. }
  767. if(typeof key == "string"){
  768. if(key.substr(0, 5) == "attr:"){
  769. var attr = fn;
  770. if(attr.substr(0, 5) == "attr:"){
  771. attr = attr.slice(5);
  772. }
  773. dd.register._registry.attributes.push([attr.toLowerCase(), base + "." + path + "." + attr]);
  774. }
  775. key = key.toLowerCase()
  776. }
  777. dd.register._registry[type].push([
  778. key,
  779. fn,
  780. base + "." + path
  781. ]);
  782. }
  783. }
  784. },
  785. tags: function(/*String*/ base, /*Object*/ locations){
  786. dd.register._any("tags", base, locations);
  787. },
  788. filters: function(/*String*/ base, /*Object*/ locations){
  789. dd.register._any("filters", base, locations);
  790. }
  791. }
  792. var escapeamp = /&/g;
  793. var escapelt = /</g;
  794. var escapegt = />/g;
  795. var escapeqt = /'/g;
  796. var escapedblqt = /"/g;
  797. dd._base.escape = function(value){
  798. // summary: Escapes a string's HTML
  799. return dd.mark_safe(value.replace(escapeamp, '&amp;').replace(escapelt, '&lt;').replace(escapegt, '&gt;').replace(escapedblqt, '&quot;').replace(escapeqt, '&#39;'));
  800. }
  801. dd._base.safe = function(value){
  802. if(typeof value == "string"){
  803. value = new String(value);
  804. }
  805. if(typeof value == "object"){
  806. value.safe = true;
  807. }
  808. return value;
  809. }
  810. dd.mark_safe = dd._base.safe;
  811. dd.register.tags("dojox.dtl.tag", {
  812. "date": ["now"],
  813. "logic": ["if", "for", "ifequal", "ifnotequal"],
  814. "loader": ["extends", "block", "include", "load", "ssi"],
  815. "misc": ["comment", "debug", "filter", "firstof", "spaceless", "templatetag", "widthratio", "with"],
  816. "loop": ["cycle", "ifchanged", "regroup"]
  817. });
  818. dd.register.filters("dojox.dtl.filter", {
  819. "dates": ["date", "time", "timesince", "timeuntil"],
  820. "htmlstrings": ["linebreaks", "linebreaksbr", "removetags", "striptags"],
  821. "integers": ["add", "get_digit"],
  822. "lists": ["dictsort", "dictsortreversed", "first", "join", "length", "length_is", "random", "slice", "unordered_list"],
  823. "logic": ["default", "default_if_none", "divisibleby", "yesno"],
  824. "misc": ["filesizeformat", "pluralize", "phone2numeric", "pprint"],
  825. "strings": ["addslashes", "capfirst", "center", "cut", "fix_ampersands", "floatformat", "iriencode", "linenumbers", "ljust", "lower", "make_list", "rjust", "slugify", "stringformat", "title", "truncatewords", "truncatewords_html", "upper", "urlencode", "urlize", "urlizetrunc", "wordcount", "wordwrap"]
  826. });
  827. dd.register.filters("dojox.dtl", {
  828. "_base": ["escape", "safe"]
  829. });
  830. })();
  831. }
  832. if(!dojo._hasResource["dojox.dtl"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  833. dojo._hasResource["dojox.dtl"] = true;
  834. dojo.provide("dojox.dtl");
  835. }
  836. if(!dojo._hasResource["dojox.dtl.Context"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  837. dojo._hasResource["dojox.dtl.Context"] = true;
  838. dojo.provide("dojox.dtl.Context");
  839. dojox.dtl.Context = dojo.extend(function(dict){
  840. this._this = {};
  841. dojox.dtl._Context.call(this, dict);
  842. }, dojox.dtl._Context.prototype,
  843. {
  844. getKeys: function(){
  845. var keys = [];
  846. for(var key in this){
  847. if(this.hasOwnProperty(key) && key != "_this"){
  848. keys.push(key);
  849. }
  850. }
  851. return keys;
  852. },
  853. extend: function(/*dojox.dtl.Context|Object*/ obj){
  854. // summary: Returns a clone of this context object, with the items from the
  855. // passed objecct mixed in.
  856. return dojo.delegate(this, obj);
  857. },
  858. filter: function(/*dojox.dtl.Context|Object|String...*/ filter){
  859. // summary: Returns a clone of this context, only containing the items
  860. // defined in the filter.
  861. var context = new dojox.dtl.Context();
  862. var keys = [];
  863. var i, arg;
  864. if(filter instanceof dojox.dtl.Context){
  865. keys = filter.getKeys();
  866. }else if(typeof filter == "object"){
  867. for(var key in filter){
  868. keys.push(key);
  869. }
  870. }else{
  871. for(i = 0; arg = arguments[i]; i++){
  872. if(typeof arg == "string"){
  873. keys.push(arg);
  874. }
  875. }
  876. }
  877. for(i = 0, key; key = keys[i]; i++){
  878. context[key] = this[key];
  879. }
  880. return context;
  881. },
  882. setThis: function(/*Object*/ _this){
  883. this._this = _this;
  884. },
  885. getThis: function(){
  886. return this._this;
  887. },
  888. hasKey: function(key){
  889. if(this._getter){
  890. var got = this._getter(key);
  891. if(typeof got != "undefined"){
  892. return true;
  893. }
  894. }
  895. if(typeof this[key] != "undefined"){
  896. return true;
  897. }
  898. return false;
  899. }
  900. });
  901. }
  902. if(!dojo._hasResource["dojox.dtl.tag.logic"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  903. dojo._hasResource["dojox.dtl.tag.logic"] = true;
  904. dojo.provide("dojox.dtl.tag.logic");
  905. (function(){
  906. var dd = dojox.dtl;
  907. var ddt = dd.text;
  908. var ddtl = dd.tag.logic;
  909. ddtl.IfNode = dojo.extend(function(bools, trues, falses, type){
  910. this.bools = bools;
  911. this.trues = trues;
  912. this.falses = falses;
  913. this.type = type;
  914. },
  915. {
  916. render: function(context, buffer){
  917. var i, bool, ifnot, filter, value;
  918. if(this.type == "or"){
  919. for(i = 0; bool = this.bools[i]; i++){
  920. ifnot = bool[0];
  921. filter = bool[1];
  922. value = filter.resolve(context);
  923. if((value && !ifnot) || (ifnot && !value)){
  924. if(this.falses){
  925. buffer = this.falses.unrender(context, buffer);
  926. }
  927. return (this.trues) ? this.trues.render(context, buffer, this) : buffer;
  928. }
  929. }
  930. if(this.trues){
  931. buffer = this.trues.unrender(context, buffer);
  932. }
  933. return (this.falses) ? this.falses.render(context, buffer, this) : buffer;
  934. }else{
  935. for(i = 0; bool = this.bools[i]; i++){
  936. ifnot = bool[0];
  937. filter = bool[1];
  938. value = filter.resolve(context);
  939. // If we ever encounter a false value
  940. if(value == ifnot){
  941. if(this.trues){
  942. buffer = this.trues.unrender(context, buffer);
  943. }
  944. return (this.falses) ? this.falses.render(context, buffer, this) : buffer;
  945. }
  946. }
  947. if(this.falses){
  948. buffer = this.falses.unrender(context, buffer);
  949. }
  950. return (this.trues) ? this.trues.render(context, buffer, this) : buffer;
  951. }
  952. return buffer;
  953. },
  954. unrender: function(context, buffer){
  955. buffer = (this.trues) ? this.trues.unrender(context, buffer) : buffer;
  956. buffer = (this.falses) ? this.falses.unrender(context, buffer) : buffer;
  957. return buffer;
  958. },
  959. clone: function(buffer){
  960. var trues = (this.trues) ? this.trues.clone(buffer) : null;
  961. var falses = (this.falses) ? this.falses.clone(buffer) : null;
  962. return new this.constructor(this.bools, trues, falses, this.type);
  963. }
  964. });
  965. ddtl.IfEqualNode = dojo.extend(function(var1, var2, trues, falses, negate){
  966. this.var1 = new dd._Filter(var1);
  967. this.var2 = new dd._Filter(var2);
  968. this.trues = trues;
  969. this.falses = falses;
  970. this.negate = negate;
  971. },
  972. {
  973. render: function(context, buffer){
  974. var var1 = this.var1.resolve(context);
  975. var var2 = this.var2.resolve(context);
  976. var1 = (typeof var1 != "undefined") ? var1 : "";
  977. var2 = (typeof var1 != "undefined") ? var2 : "";
  978. if((this.negate && var1 != var2) || (!this.negate && var1 == var2)){
  979. if(this.falses){
  980. buffer = this.falses.unrender(context, buffer, this);
  981. }
  982. return (this.trues) ? this.trues.render(context, buffer, this) : buffer;
  983. }
  984. if(this.trues){
  985. buffer = this.trues.unrender(context, buffer, this);
  986. }
  987. return (this.falses) ? this.falses.render(context, buffer, this) : buffer;
  988. },
  989. unrender: function(context, buffer){
  990. return ddtl.IfNode.prototype.unrender.call(this, context, buffer);
  991. },
  992. clone: function(buffer){
  993. var trues = this.trues ? this.trues.clone(buffer) : null;
  994. var falses = this.falses ? this.falses.clone(buffer) : null;
  995. return new this.constructor(this.var1.getExpression(), this.var2.getExpression(), trues, falses, this.negate);
  996. }
  997. });
  998. ddtl.ForNode = dojo.extend(function(assign, loop, reversed, nodelist){
  999. this.assign = assign;
  1000. this.loop = new dd._Filter(loop);
  1001. this.reversed = reversed;
  1002. this.nodelist = nodelist;
  1003. this.pool = [];
  1004. },
  1005. {
  1006. render: function(context, buffer){
  1007. var i, j, k;
  1008. var dirty = false;
  1009. var assign = this.assign;
  1010. for(k = 0; k < assign.length; k++){
  1011. if(typeof context[assign[k]] != "undefined"){
  1012. dirty = true;
  1013. context = context.push();
  1014. break;
  1015. }
  1016. }
  1017. if(!dirty && context.forloop){
  1018. dirty = true;
  1019. context = context.push();
  1020. }
  1021. var items = this.loop.resolve(context) || [];
  1022. for(i = items.length; i < this.pool.length; i++){
  1023. this.pool[i].unrender(context, buffer, this);
  1024. }
  1025. if(this.reversed){
  1026. items = items.slice(0).reverse();
  1027. }
  1028. var isObject = dojo.isObject(items) && !dojo.isArrayLike(items);
  1029. var arred = [];
  1030. if(isObject){
  1031. for(var key in items){
  1032. arred.push(items[key]);
  1033. }
  1034. }else{
  1035. arred = items;
  1036. }
  1037. var forloop = context.forloop = {
  1038. parentloop: context.get("forloop", {})
  1039. };
  1040. var j = 0;
  1041. for(i = 0; i < arred.length; i++){
  1042. var item = arred[i];
  1043. forloop.counter0 = j;
  1044. forloop.counter = j + 1;
  1045. forloop.revcounter0 = arred.length - j - 1;
  1046. forloop.revcounter = arred.length - j;
  1047. forloop.first = !j;
  1048. forloop.last = (j == arred.length - 1);
  1049. if(assign.length > 1 && dojo.isArrayLike(item)){
  1050. if(!dirty){
  1051. dirty = true;
  1052. context = context.push();
  1053. }
  1054. var zipped = {};
  1055. for(k = 0; k < item.length && k < assign.length; k++){
  1056. zipped[assign[k]] = item[k];
  1057. }
  1058. dojo.mixin(context, zipped);
  1059. }else{
  1060. context[assign[0]] = item;
  1061. }
  1062. if(j + 1 > this.pool.length){
  1063. this.pool.push(this.nodelist.clone(buffer));
  1064. }
  1065. buffer = this.pool[j++].render(context, buffer, this);
  1066. }
  1067. delete context.forloop;
  1068. if(dirty){
  1069. context = context.pop();
  1070. }else{
  1071. for(k = 0; k < assign.length; k++){
  1072. delete context[assign[k]];
  1073. }
  1074. }
  1075. return buffer;
  1076. },
  1077. unrender: function(context, buffer){
  1078. for(var i = 0, pool; pool = this.pool[i]; i++){
  1079. buffer = pool.unrender(context, buffer);
  1080. }
  1081. return buffer;
  1082. },
  1083. clone: function(buffer){
  1084. return new this.constructor(this.assign, this.loop.getExpression(), this.reversed, this.nodelist.clone(buffer));
  1085. }
  1086. });
  1087. dojo.mixin(ddtl, {
  1088. if_: function(parser, token){
  1089. var i, part, type, bools = [], parts = token.contents.split();
  1090. parts.shift();
  1091. token = parts.join(" ");
  1092. parts = token.split(" and ");
  1093. if(parts.length == 1){
  1094. type = "or";
  1095. parts = token.split(" or ");
  1096. }else{
  1097. type = "and";
  1098. for(i = 0; i < parts.length; i++){
  1099. if(parts[i].indexOf(" or ") != -1){
  1100. // Note, since we split by and, this is the only place we need to error check
  1101. throw new Error("'if' tags can't mix 'and' and 'or'");
  1102. }
  1103. }
  1104. }
  1105. for(i = 0; part = parts[i]; i++){
  1106. var not = false;
  1107. if(part.indexOf("not ") == 0){
  1108. part = part.slice(4);
  1109. not = true;
  1110. }
  1111. bools.push([not, new dd._Filter(part)]);
  1112. }
  1113. var trues = parser.parse(["else", "endif"]);
  1114. var falses = false;
  1115. var token = parser.next_token();
  1116. if(token.contents == "else"){
  1117. falses = parser.parse(["endif"]);
  1118. parser.next_token();
  1119. }
  1120. return new ddtl.IfNode(bools, trues, falses, type);
  1121. },
  1122. _ifequal: function(parser, token, negate){
  1123. var parts = token.split_contents();
  1124. if(parts.length != 3){
  1125. throw new Error(parts[0] + " takes two arguments");
  1126. }
  1127. var end = 'end' + parts[0];
  1128. var trues = parser.parse(["else", end]);
  1129. var falses = false;
  1130. var token = parser.next_token();
  1131. if(token.contents == "else"){
  1132. falses = parser.parse([end]);
  1133. parser.next_token();
  1134. }
  1135. return new ddtl.IfEqualNode(parts[1], parts[2], trues, falses, negate);
  1136. },
  1137. ifequal: function(parser, token){
  1138. return ddtl._ifequal(parser, token);
  1139. },
  1140. ifnotequal: function(parser, token){
  1141. return ddtl._ifequal(parser, token, true);
  1142. },
  1143. for_: function(parser, token){
  1144. var parts = token.contents.split();
  1145. if(parts.length < 4){
  1146. throw new Error("'for' statements should have at least four words: " + token.contents);
  1147. }
  1148. var reversed = parts[parts.length - 1] == "reversed";
  1149. var index = (reversed) ? -3 : -2;
  1150. if(parts[parts.length + index] != "in"){
  1151. throw new Error("'for' tag received an invalid argument: " + token.contents);
  1152. }
  1153. var loopvars = parts.slice(1, index).join(" ").split(/ *, */);
  1154. for(var i = 0; i < loopvars.length; i++){
  1155. if(!loopvars[i] || loopvars[i].indexOf(" ") != -1){
  1156. throw new Error("'for' tag received an invalid argument: " + token.contents);
  1157. }
  1158. }
  1159. var nodelist = parser.parse(["endfor"]);
  1160. parser.next_token();
  1161. return new ddtl.ForNode(loopvars, parts[parts.length + index + 1], reversed, nodelist);
  1162. }
  1163. });
  1164. })();
  1165. }
  1166. if(!dojo._hasResource["dojox.dtl.tag.loop"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1167. dojo._hasResource["dojox.dtl.tag.loop"] = true;
  1168. dojo.provide("dojox.dtl.tag.loop");
  1169. (function(){
  1170. var dd = dojox.dtl;
  1171. var ddtl = dd.tag.loop;
  1172. ddtl.CycleNode = dojo.extend(function(cyclevars, name, text, shared){
  1173. this.cyclevars = cyclevars;
  1174. this.name = name;
  1175. this.contents = text;
  1176. this.shared = shared || {counter: -1, map: {}};
  1177. },
  1178. {
  1179. render: function(context, buffer){
  1180. if(context.forloop && !context.forloop.counter0){
  1181. this.shared.counter = -1;
  1182. }
  1183. ++this.shared.counter;
  1184. var value = this.cyclevars[this.shared.counter % this.cyclevars.length];
  1185. var map = this.shared.map;
  1186. if(!map[value]){
  1187. map[value] = new dd._Filter(value);
  1188. }
  1189. value = map[value].resolve(context, buffer);
  1190. if(this.name){
  1191. context[this.name] = value;
  1192. }
  1193. this.contents.set(value);
  1194. return this.contents.render(context, buffer);
  1195. },
  1196. unrender: function(context, buffer){
  1197. return this.contents.unrender(context, buffer);
  1198. },
  1199. clone: function(buffer){
  1200. return new this.constructor(this.cyclevars, this.name, this.contents.clone(buffer), this.shared);
  1201. }
  1202. });
  1203. ddtl.IfChangedNode = dojo.extend(function(nodes, vars, shared){
  1204. this.nodes = nodes;
  1205. this._vars = vars;
  1206. this.shared = shared || {last: null, counter: 0};
  1207. this.vars = dojo.map(vars, function(item){
  1208. return new dojox.dtl._Filter(item);
  1209. });
  1210. }, {
  1211. render: function(context, buffer){
  1212. if(context.forloop){
  1213. if(context.forloop.counter <= this.shared.counter){
  1214. this.shared.last = null;
  1215. }
  1216. this.shared.counter = context.forloop.counter;
  1217. }
  1218. var change;
  1219. if(this.vars.length){
  1220. change = dojo.toJson(dojo.map(this.vars, function(item){
  1221. return item.resolve(context);
  1222. }));
  1223. }else{
  1224. change = this.nodes.dummyRender(context, buffer);
  1225. }
  1226. if(change != this.shared.last){
  1227. var firstloop = (this.shared.last === null);
  1228. this.shared.last = change;
  1229. context = context.push();
  1230. context.ifchanged = {firstloop: firstloop};
  1231. buffer = this.nodes.render(context, buffer);
  1232. context = context.pop();
  1233. }else{
  1234. buffer = this.nodes.unrender(context, buffer);
  1235. }
  1236. return buffer;
  1237. },
  1238. unrender: function(context, buffer){
  1239. return this.nodes.unrender(context, buffer);
  1240. },
  1241. clone: function(buffer){
  1242. return new this.constructor(this.nodes.clone(buffer), this._vars, this.shared);
  1243. }
  1244. });
  1245. ddtl.RegroupNode = dojo.extend(function(expression, key, alias){
  1246. this._expression = expression;
  1247. this.expression = new dd._Filter(expression);
  1248. this.key = key;
  1249. this.alias = alias;
  1250. },
  1251. {
  1252. _push: function(container, grouper, stack){
  1253. if(stack.length){
  1254. container.push({ grouper: grouper, list: stack });
  1255. }
  1256. },
  1257. render: function(context, buffer){
  1258. context[this.alias] = [];
  1259. var list = this.expression.resolve(context);
  1260. if(list){
  1261. var last = null;
  1262. var stack = [];
  1263. for(var i = 0; i < list.length; i++){
  1264. var id = list[i][this.key];
  1265. if(last !== id){
  1266. this._push(context[this.alias], last, stack);
  1267. last = id;
  1268. stack = [list[i]];
  1269. }else{
  1270. stack.push(list[i]);
  1271. }
  1272. }
  1273. this._push(context[this.alias], last, stack);
  1274. }
  1275. return buffer;
  1276. },
  1277. unrender: function(context, buffer){
  1278. return buffer;
  1279. },
  1280. clone: function(context, buffer){
  1281. return this;
  1282. }
  1283. });
  1284. dojo.mixin(ddtl, {
  1285. cycle: function(parser, token){
  1286. // summary: Cycle among the given strings each time this tag is encountered
  1287. var args = token.split_contents();
  1288. if(args.length < 2){
  1289. throw new Error("'cycle' tag requires at least two arguments");
  1290. }
  1291. if(args[1].indexOf(",") != -1){
  1292. var vars = args[1].split(",");
  1293. args = [args[0]];
  1294. for(var i = 0; i < vars.length; i++){
  1295. args.push('"' + vars[i] + '"');
  1296. }
  1297. }
  1298. if(args.length == 2){
  1299. var name = args[args.length - 1];
  1300. if(!parser._namedCycleNodes){
  1301. throw new Error("No named cycles in template: '" + name + "' is not defined");
  1302. }
  1303. if(!parser._namedCycleNodes[name]){
  1304. throw new Error("Named cycle '" + name + "' does not exist");
  1305. }
  1306. return parser._namedCycleNodes[name];
  1307. }
  1308. if(args.length > 4 && args[args.length - 2] == "as"){
  1309. var name = args[args.length - 1];
  1310. var node = new ddtl.CycleNode(args.slice(1, args.length - 2), name, parser.create_text_node());
  1311. if(!parser._namedCycleNodes){
  1312. parser._namedCycleNodes = {};
  1313. }
  1314. parser._namedCycleNodes[name] = node;
  1315. }else{
  1316. node = new ddtl.CycleNode(args.slice(1), null, parser.create_text_node());
  1317. }
  1318. return node;
  1319. },
  1320. ifchanged: function(parser, token){
  1321. var parts = token.contents.split();
  1322. var nodes = parser.parse(["endifchanged"]);
  1323. parser.delete_first_token();
  1324. return new ddtl.IfChangedNode(nodes, parts.slice(1));
  1325. },
  1326. regroup: function(parser, token){
  1327. var tokens = dojox.string.tokenize(token.contents, /(\s+)/g, function(spaces){
  1328. return spaces;
  1329. });
  1330. if(tokens.length < 11 || tokens[tokens.length - 3] != "as" || tokens[tokens.length - 7] != "by"){
  1331. throw new Error("Expected the format: regroup list by key as newList");
  1332. }
  1333. var expression = tokens.slice(2, -8).join("");
  1334. var key = tokens[tokens.length - 5];
  1335. var alias = tokens[tokens.length - 1];
  1336. return new ddtl.RegroupNode(expression, key, alias);
  1337. }
  1338. });
  1339. })();
  1340. }
  1341. if(!dojo._hasResource["dojo.date"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1342. dojo._hasResource["dojo.date"] = true;
  1343. dojo.provide("dojo.date");
  1344. dojo.getObject("date", true, dojo);
  1345. /*=====
  1346. dojo.date = {
  1347. // summary: Date manipulation utilities
  1348. }
  1349. =====*/
  1350. dojo.date.getDaysInMonth = function(/*Date*/dateObject){
  1351. // summary:
  1352. // Returns the number of days in the month used by dateObject
  1353. var month = dateObject.getMonth();
  1354. var days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  1355. if(month == 1 && dojo.date.isLeapYear(dateObject)){ return 29; } // Number
  1356. return days[month]; // Number
  1357. };
  1358. dojo.date.isLeapYear = function(/*Date*/dateObject){
  1359. // summary:
  1360. // Determines if the year of the dateObject is a leap year
  1361. // description:
  1362. // Leap years are years with an additional day YYYY-02-29, where the
  1363. // year number is a multiple of four with the following exception: If
  1364. // a year is a multiple of 100, then it is only a leap year if it is
  1365. // also a multiple of 400. For example, 1900 was not a leap year, but
  1366. // 2000 is one.
  1367. var year = dateObject.getFullYear();
  1368. return !(year%400) || (!(year%4) && !!(year%100)); // Boolean
  1369. };
  1370. // FIXME: This is not localized
  1371. dojo.date.getTimezoneName = function(/*Date*/dateObject){
  1372. // summary:
  1373. // Get the user's time zone as provided by the browser
  1374. // dateObject:
  1375. // Needed because the timezone may vary with time (daylight savings)
  1376. // description:
  1377. // Try to get time zone info from toString or toLocaleString method of
  1378. // the Date object -- UTC offset is not a time zone. See
  1379. // http://www.twinsun.com/tz/tz-link.htm Note: results may be
  1380. // inconsistent across browsers.
  1381. var str = dateObject.toString(); // Start looking in toString
  1382. var tz = ''; // The result -- return empty string if nothing found
  1383. var match;
  1384. // First look for something in parentheses -- fast lookup, no regex
  1385. var pos = str.indexOf('(');
  1386. if(pos > -1){
  1387. tz = str.substring(++pos, str.indexOf(')'));
  1388. }else{
  1389. // If at first you don't succeed ...
  1390. // If IE knows about the TZ, it appears before the year
  1391. // Capital letters or slash before a 4-digit year
  1392. // at the end of string
  1393. var pat = /([A-Z\/]+) \d{4}$/;
  1394. if((match = str.match(pat))){
  1395. tz = match[1];
  1396. }else{
  1397. // Some browsers (e.g. Safari) glue the TZ on the end
  1398. // of toLocaleString instead of putting it in toString
  1399. str = dateObject.toLocaleString();
  1400. // Capital letters or slash -- end of string,
  1401. // after space
  1402. pat = / ([A-Z\/]+)$/;
  1403. if((match = str.match(pat))){
  1404. tz = match[1];
  1405. }
  1406. }
  1407. }
  1408. // Make sure it doesn't somehow end up return AM or PM
  1409. return (tz == 'AM' || tz == 'PM') ? '' : tz; // String
  1410. };
  1411. // Utility methods to do arithmetic calculations with Dates
  1412. dojo.date.compare = function(/*Date*/date1, /*Date?*/date2, /*String?*/portion){
  1413. // summary:
  1414. // Compare two date objects by date, time, or both.
  1415. // description:
  1416. // Returns 0 if equal, positive if a > b, else negative.
  1417. // date1:
  1418. // Date object
  1419. // date2:
  1420. // Date object. If not specified, the current Date is used.
  1421. // portion:
  1422. // A string indicating the "date" or "time" portion of a Date object.
  1423. // Compares both "date" and "time" by default. One of the following:
  1424. // "date", "time", "datetime"
  1425. // Extra step required in copy for IE - see #3112
  1426. date1 = new Date(+date1);
  1427. date2 = new Date(+(date2 || new Date()));
  1428. if(portion == "date"){
  1429. // Ignore times and compare dates.
  1430. date1.setHours(0, 0, 0, 0);
  1431. date2.setHours(0, 0, 0, 0);
  1432. }else if(portion == "time"){
  1433. // Ignore dates and compare times.
  1434. date1.setFullYear(0, 0, 0);
  1435. date2.setFullYear(0, 0, 0);
  1436. }
  1437. if(date1 > date2){ return 1; } // int
  1438. if(date1 < date2){ return -1; } // int
  1439. return 0; // int
  1440. };
  1441. dojo.date.add = function(/*Date*/date, /*String*/interval, /*int*/amount){
  1442. // summary:
  1443. // Add to a Date in intervals of different size, from milliseconds to years
  1444. // date: Date
  1445. // Date object to start with
  1446. // interval:
  1447. // A string representing the interval. One of the following:
  1448. // "year", "month", "day", "hour", "minute", "second",
  1449. // "millisecond", "quarter", "week", "weekday"
  1450. // amount:
  1451. // How much to add to the date.
  1452. var sum = new Date(+date); // convert to Number before copying to accomodate IE (#3112)
  1453. var fixOvershoot = false;
  1454. var property = "Date";
  1455. switch(interval){
  1456. case "day":
  1457. break;
  1458. case "weekday":
  1459. //i18n FIXME: assumes Saturday/Sunday weekend, but this is not always true. see dojo.cldr.supplemental
  1460. // Divide the increment time span into weekspans plus leftover days
  1461. // e.g., 8 days is one 5-day weekspan / and two leftover days
  1462. // Can't have zero leftover days, so numbers divisible by 5 get
  1463. // a days value of 5, and the remaining days make up the number of weeks
  1464. var days, weeks;
  1465. var mod = amount % 5;
  1466. if(!mod){
  1467. days = (amount > 0) ? 5 : -5;
  1468. weeks = (amount > 0) ? ((amount-5)/5) : ((amount+5)/5);
  1469. }else{
  1470. days = mod;
  1471. weeks = parseInt(amount/5);
  1472. }
  1473. // Get weekday value for orig date param
  1474. var strt = date.getDay();
  1475. // Orig date is Sat / positive incrementer
  1476. // Jump over Sun
  1477. var adj = 0;
  1478. if(strt == 6 && amount > 0){
  1479. adj = 1;
  1480. }else if(strt == 0 && amount < 0){
  1481. // Orig date is Sun / negative incrementer
  1482. // Jump back over Sat
  1483. adj = -1;
  1484. }
  1485. // Get weekday val for the new date
  1486. var trgt = strt + days;
  1487. // New date is on Sat or Sun
  1488. if(trgt == 0 || trgt == 6){
  1489. adj = (amount > 0) ? 2 : -2;
  1490. }
  1491. // Increment by number of weeks plus leftover days plus
  1492. // weekend adjustments
  1493. amount = (7 * weeks) + days + adj;
  1494. break;
  1495. case "year":
  1496. property = "FullYear";
  1497. // Keep increment/decrement from 2/29 out of March
  1498. fixOvershoot = true;
  1499. break;
  1500. case "week":
  1501. amount *= 7;
  1502. break;
  1503. case "quarter":
  1504. // Naive quarter is just three months
  1505. amount *= 3;
  1506. // fallthrough...
  1507. case "month":
  1508. // Reset to last day of month if you overshoot
  1509. fixOvershoot = true;
  1510. property = "Month";
  1511. break;
  1512. // case "hour":
  1513. // case "minute":
  1514. // case "second":
  1515. // case "millisecond":
  1516. default:
  1517. property = "UTC"+interval.charAt(0).toUpperCase() + interval.substring(1) + "s";
  1518. }
  1519. if(property){
  1520. sum["set"+property](sum["get"+property]()+amount);
  1521. }
  1522. if(fixOvershoot && (sum.getDate() < date.getDate())){
  1523. sum.setDate(0);
  1524. }
  1525. return sum; // Date
  1526. };
  1527. dojo.date.difference = function(/*Date*/date1, /*Date?*/date2, /*String?*/interval){
  1528. // summary:
  1529. // Get the difference in a specific unit of time (e.g., number of
  1530. // months, weeks, days, etc.) between two dates, rounded to the
  1531. // nearest integer.
  1532. // date1:
  1533. // Date object
  1534. // date2:
  1535. // Date object. If not specified, the current Date is used.
  1536. // interval:
  1537. // A string representing the interval. One of the following:
  1538. // "year", "month", "day", "hour", "minute", "second",
  1539. // "millisecond", "quarter", "week", "weekday"
  1540. // Defaults to "day".
  1541. date2 = date2 || new Date();
  1542. interval = interval || "day";
  1543. var yearDiff = date2.getFullYear() - date1.getFullYear();
  1544. var delta = 1; // Integer return value
  1545. switch(interval){
  1546. case "quarter":
  1547. var m1 = date1.getMonth();
  1548. var m2 = date2.getMonth();
  1549. // Figure out which quarter the months are in
  1550. var q1 = Math.floor(m1/3) + 1;
  1551. var q2 = Math.floor(m2/3) + 1;
  1552. // Add quarters for any year difference between the dates
  1553. q2 += (yearDiff * 4);
  1554. delta = q2 - q1;
  1555. break;
  1556. case "weekday":
  1557. var days = Math.round(dojo.date.difference(date1, date2, "day"));
  1558. var weeks = parseInt(dojo.date.difference(date1, date2, "week"));
  1559. var mod = days % 7;
  1560. // Even number of weeks
  1561. if(mod == 0){
  1562. days = weeks*5;
  1563. }else{
  1564. // Weeks plus spare change (< 7 days)
  1565. var adj = 0;
  1566. var aDay = date1.getDay();
  1567. var bDay = date2.getDay();
  1568. weeks = parseInt(days/7);
  1569. mod = days % 7;
  1570. // Mark the date advanced by the number of
  1571. // round weeks (may be zero)
  1572. var dtMark = new Date(date1);
  1573. dtMark.setDate(dtMark.getDate()+(weeks*7));
  1574. var dayMark = dtMark.getDay();
  1575. // Spare change days -- 6 or less
  1576. if(days > 0){
  1577. switch(true){
  1578. // Range starts on Sat
  1579. case aDay == 6:
  1580. adj = -1;
  1581. break;
  1582. // Range starts on Sun
  1583. case aDay == 0:
  1584. adj = 0;
  1585. break;
  1586. // Range ends on Sat
  1587. case bDay == 6:
  1588. adj = -1;
  1589. break;
  1590. // Range ends on Sun
  1591. case bDay == 0:
  1592. adj = -2;
  1593. break;
  1594. // Range contains weekend
  1595. case (dayMark + mod) > 5:
  1596. adj = -2;
  1597. }
  1598. }else if(days < 0){
  1599. switch(true){
  1600. // Range starts on Sat
  1601. case aDay == 6:
  1602. adj = 0;
  1603. break;
  1604. // Range starts on Sun
  1605. case aDay == 0:
  1606. adj = 1;
  1607. break;
  1608. // Range ends on Sat
  1609. case bDay == 6:
  1610. adj = 2;
  1611. break;
  1612. // Range ends on Sun
  1613. case bDay == 0:
  1614. adj = 1;
  1615. break;
  1616. // Range contains weekend
  1617. case (dayMark + mod) < 0:
  1618. adj = 2;
  1619. }
  1620. }
  1621. days += adj;
  1622. days -= (weeks*2);
  1623. }
  1624. delta = days;
  1625. break;
  1626. case "year":
  1627. delta = yearDiff;
  1628. break;
  1629. case "month":
  1630. delta = (date2.getMonth() - date1.getMonth()) + (yearDiff * 12);
  1631. break;
  1632. case "week":
  1633. // Truncate instead of rounding
  1634. // Don't use Math.floor -- value may be negative
  1635. delta = parseInt(dojo.date.difference(date1, date2, "day")/7);
  1636. break;
  1637. case "day":
  1638. delta /= 24;
  1639. // fallthrough
  1640. case "hour":
  1641. delta /= 60;
  1642. // fallthrough
  1643. case "minute":
  1644. delta /= 60;
  1645. // fallthrough
  1646. case "second":
  1647. delta /= 1000;
  1648. // fallthrough
  1649. case "millisecond":
  1650. delta *= date2.getTime() - date1.getTime();
  1651. }
  1652. // Round for fractional values and DST leaps
  1653. return Math.round(delta); // Number (integer)
  1654. };
  1655. }
  1656. if(!dojo._hasResource["dojox.date.php"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1657. dojo._hasResource["dojox.date.php"] = true;
  1658. dojo.provide("dojox.date.php");
  1659. dojox.date.php.format = function(/*Date*/ date, /*String*/ format){
  1660. // summary: Get a formatted string for a given date object
  1661. var df = new dojox.date.php.DateFormat(format);
  1662. return df.format(date);
  1663. }
  1664. dojox.date.php.DateFormat = function(/*String*/ format){
  1665. // summary: Format the internal date object
  1666. if(!this.regex){
  1667. var keys = [];
  1668. for(var key in this.constructor.prototype){
  1669. if(dojo.isString(key) && key.length == 1 && dojo.isFunction(this[key])){
  1670. keys.push(key);
  1671. }
  1672. }
  1673. this.constructor.prototype.regex = new RegExp("(?:(\\\\.)|([" + keys.join("") + "]))", "g");
  1674. }
  1675. var replacements = [];
  1676. this.tokens = dojox.string.tokenize(format, this.regex, function(escape, token, i){
  1677. if(token){
  1678. replacements.push([i, token]);
  1679. return token;
  1680. }
  1681. if(escape){
  1682. return escape.charAt(1);
  1683. }
  1684. });
  1685. this.replacements = replacements;
  1686. }
  1687. dojo.extend(dojox.date.php.DateFormat, {
  1688. weekdays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  1689. weekdays_3: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  1690. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  1691. months_3: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  1692. monthdays: [31,28,31,30,31,30,31,31,30,31,30,31],
  1693. format: function(/*Date*/ date){
  1694. this.date = date;
  1695. for(var i = 0, replacement; replacement = this.replacements[i]; i++){
  1696. this.tokens[replacement[0]] = this[replacement[1]]();
  1697. }
  1698. return this.tokens.join("");
  1699. },
  1700. // Day
  1701. d: function(){
  1702. // summary: Day of the month, 2 digits with leading zeros
  1703. var j = this.j();
  1704. return (j.length == 1) ? "0" + j : j;
  1705. },
  1706. D: function(){
  1707. // summary: A textual representation of a day, three letters
  1708. return this.weekdays_3[this.date.getDay()];
  1709. },
  1710. j: function(){
  1711. // summary: Day of the month without leading zeros
  1712. return this.date.getDate() + "";
  1713. },
  1714. l: function(){
  1715. // summary: A full textual representation of the day of the week
  1716. return this.weekdays[this.date.getDay()];
  1717. },
  1718. N: function(){
  1719. // summary: ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)
  1720. var w = this.w();
  1721. return (!w) ? 7 : w;
  1722. },
  1723. S: function(){
  1724. // summary: English ordinal suffix for the day of the month, 2 characters
  1725. switch(this.date.getDate()){
  1726. case 11: case 12: case 13: return "th";
  1727. case 1: case 21: case 31: return "st";
  1728. case 2: case 22: return "nd";
  1729. case 3: case 23: return "rd";
  1730. default: return "th";
  1731. }
  1732. },
  1733. w: function(){
  1734. // summary: Numeric representation of the day of the week
  1735. return this.date.getDay() + "";
  1736. },
  1737. z: function(){
  1738. // summary: The day of the year (starting from 0)
  1739. var millis = this.date.getTime() - new Date(this.date.getFullYear(), 0, 1).getTime();
  1740. return Math.floor(millis/86400000) + "";
  1741. },
  1742. // Week
  1743. W: function(){
  1744. // summary: ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)
  1745. var week;
  1746. var jan1_w = new Date(this.date.getFullYear(), 0, 1).getDay() + 1;
  1747. var w = this.date.getDay() + 1;
  1748. var z = parseInt(this.z());
  1749. if(z <= (8 - jan1_w) && jan1_w > 4){
  1750. var last_year = new Date(this.date.getFullYear() - 1, this.date.getMonth(), this.date.getDate());
  1751. if(jan1_w == 5 || (jan1_w == 6 && dojo.date.isLeapYear(last_year))){
  1752. week = 53;
  1753. }else{
  1754. week = 52;
  1755. }
  1756. }else{
  1757. var i;
  1758. if(Boolean(this.L())){
  1759. i = 366;
  1760. }else{
  1761. i = 365;
  1762. }
  1763. if((i - z) < (4 - w)){
  1764. week = 1;
  1765. }else{
  1766. var j = z + (7 - w) + (jan1_w - 1);
  1767. week = Math.ceil(j / 7);
  1768. if(jan1_w > 4){
  1769. --week;
  1770. }
  1771. }
  1772. }
  1773. return week;
  1774. },
  1775. // Month
  1776. F: function(){
  1777. // summary: A full textual representation of a month, such as January or March
  1778. return this.months[this.date.getMonth()];
  1779. },
  1780. m: function(){
  1781. // summary: Numeric representation of a month, with leading zeros
  1782. var n = this.n();
  1783. return (n.length == 1) ? "0" + n : n;
  1784. },
  1785. M: function(){
  1786. // summary: A short textual representation of a month, three letters
  1787. return this.months_3[this.date.getMonth()];
  1788. },
  1789. n: function(){
  1790. // summary: Numeric representation of a month, without leading zeros
  1791. return this.date.getMonth() + 1 + "";
  1792. },
  1793. t: function(){
  1794. // summary: Number of days in the given month
  1795. return (Boolean(this.L()) && this.date.getMonth() == 1) ? 29 : this.monthdays[this.getMonth()];
  1796. },
  1797. // Year
  1798. L: function(){
  1799. // summary: Whether it's a leap year
  1800. return (dojo.date.isLeapYear(this.date)) ? "1" : "0";
  1801. },
  1802. o: function(){
  1803. // summary:
  1804. // ISO-8601 year number. This has the same value as Y, except that if
  1805. // the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)
  1806. // TODO: Figure out what this means
  1807. },
  1808. Y: function(){
  1809. // summary: A full numeric representation of a year, 4 digits
  1810. return this.date.getFullYear() + "";
  1811. },
  1812. y: function(){
  1813. // summary: A two digit representation of a year
  1814. return this.Y().slice(-2);
  1815. },
  1816. // Time
  1817. a: function(){
  1818. // summary: Lowercase Ante meridiem and Post meridiem
  1819. return this.date.getHours() >= 12 ? "pm" : "am";
  1820. },
  1821. b: function(){
  1822. // summary: Uppercase Ante meridiem and Post meridiem
  1823. return this.a().toUpperCase();
  1824. },
  1825. B: function(){
  1826. // summary:
  1827. // Swatch Internet time
  1828. // A day is 1,000 beats. All time is measured from GMT + 1
  1829. var off = this.date.getTimezoneOffset() + 60;
  1830. var secs = (this.date.getHours() * 3600) + (this.date.getMinutes() * 60) + this.getSeconds() + (off * 60);
  1831. var beat = Math.abs(Math.floor(secs / 86.4) % 1000) + "";
  1832. while(beat.length < 2) beat = "0" + beat;
  1833. return beat;
  1834. },
  1835. g: function(){
  1836. // summary: 12-hour format of an hour without leading zeros
  1837. return (this.date.getHours() > 12) ? this.date.getHours() - 12 + "" : this.date.getHours() + "";
  1838. },
  1839. G: function(){
  1840. // summary: 24-hour format of an hour without leading zeros
  1841. return this.date.getHours() + "";
  1842. },
  1843. h: function(){
  1844. // summary: 12-hour format of an hour with leading zeros
  1845. var g = this.g();
  1846. return (g.length == 1) ? "0" + g : g;
  1847. },
  1848. H: function(){
  1849. // summary: 24-hour format of an hour with leading zeros
  1850. var G = this.G();
  1851. return (G.length == 1) ? "0" + G : G;
  1852. },
  1853. i: function(){
  1854. // summary: Minutes with leading zeros
  1855. var mins = this.date.getMinutes() + "";
  1856. return (mins.length == 1) ? "0" + mins : mins;
  1857. },
  1858. s: function(){
  1859. // summary: Seconds, with leading zeros
  1860. var secs = this.date.getSeconds() + "";
  1861. return (secs.length == 1) ? "0" + secs : secs;
  1862. },
  1863. // Timezone
  1864. e: function(){
  1865. // summary: Timezone identifier (added in PHP 5.1.0)
  1866. return dojo.date.getTimezoneName(this.date);
  1867. },
  1868. I: function(){
  1869. // summary: Whether or not the date is in daylight saving time
  1870. // TODO: Can dojo.date do this?
  1871. },
  1872. O: function(){
  1873. // summary: Difference to Greenwich time (GMT) in hours
  1874. var off = Math.abs(this.date.getTimezoneOffset());
  1875. var hours = Math.floor(off / 60) + "";
  1876. var mins = (off % 60) + "";
  1877. if(hours.length == 1) hours = "0" + hours;
  1878. if(mins.length == 1) hours = "0" + mins;
  1879. return ((this.date.getTimezoneOffset() < 0) ? "+" : "-") + hours + mins;
  1880. },
  1881. P: function(){
  1882. // summary: Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)
  1883. var O = this.O();
  1884. return O.substring(0, 2) + ":" + O.substring(2, 4);
  1885. },
  1886. T: function(){
  1887. // summary: Timezone abbreviation
  1888. // Guess...
  1889. return this.e().substring(0, 3);
  1890. },
  1891. Z: function(){
  1892. // summary:
  1893. // Timezone offset in seconds. The offset for timezones west of UTC is always negative,
  1894. // and for those east of UTC is always positive.
  1895. return this.date.getTimezoneOffset() * -60;
  1896. },
  1897. // Full Date/Time
  1898. c: function(){
  1899. // summary: ISO 8601 date (added in PHP 5)
  1900. return this.Y() + "-" + this.m() + "-" + this.d() + "T" + this.h() + ":" + this.i() + ":" + this.s() + this.P();
  1901. },
  1902. r: function(){
  1903. // summary: RFC 2822 formatted date
  1904. return this.D() + ", " + this.d() + " " + this.M() + " " + this.Y() + " " + this.H() + ":" + this.i() + ":" + this.s() + " " + this.O();
  1905. },
  1906. U: function(){
  1907. // summary: Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
  1908. return Math.floor(this.date.getTime() / 1000);
  1909. }
  1910. });
  1911. }
  1912. if(!dojo._hasResource["dojox.dtl.utils.date"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1913. dojo._hasResource["dojox.dtl.utils.date"] = true;
  1914. dojo.provide("dojox.dtl.utils.date");
  1915. dojox.dtl.utils.date.DateFormat = function(/*String*/ format){
  1916. dojox.date.php.DateFormat.call(this, format);
  1917. }
  1918. dojo.extend(dojox.dtl.utils.date.DateFormat, dojox.date.php.DateFormat.prototype, {
  1919. f: function(){
  1920. // summary:
  1921. // Time, in 12-hour hours and minutes, with minutes left off if they're zero.
  1922. // description:
  1923. // Examples: '1', '1:30', '2:05', '2'
  1924. // Proprietary extension.
  1925. return (!this.date.getMinutes()) ? this.g() : this.g() + ":" + this.i();
  1926. },
  1927. N: function(){
  1928. // summary: Month abbreviation in Associated Press style. Proprietary extension.
  1929. return dojox.dtl.utils.date._months_ap[this.date.getMonth()];
  1930. },
  1931. P: function(){
  1932. // summary:
  1933. // Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off
  1934. // if they're zero and the strings 'midnight' and 'noon' if appropriate.
  1935. // description:
  1936. // Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.'
  1937. // Proprietary extension.
  1938. if(!this.date.getMinutes() && !this.date.getHours()){
  1939. return 'midnight';
  1940. }
  1941. if(!this.date.getMinutes() && this.date.getHours() == 12){
  1942. return 'noon';
  1943. }
  1944. return this.f() + " " + this.a();
  1945. }
  1946. });
  1947. dojo.mixin(dojox.dtl.utils.date, {
  1948. format: function(/*Date*/ date, /*String*/ format){
  1949. var df = new dojox.dtl.utils.date.DateFormat(format);
  1950. return df.format(date);
  1951. },
  1952. timesince: function(d, now){
  1953. // summary:
  1954. // Takes two datetime objects and returns the time between then and now
  1955. // as a nicely formatted string, e.g "10 minutes"
  1956. // description:
  1957. // Adapted from http://blog.natbat.co.uk/archive/2003/Jun/14/time_since
  1958. if(!(d instanceof Date)){
  1959. d = new Date(d.year, d.month, d.day);
  1960. }
  1961. if(!now){
  1962. now = new Date();
  1963. }
  1964. var delta = Math.abs(now.getTime() - d.getTime());
  1965. for(var i = 0, chunk; chunk = dojox.dtl.utils.date._chunks[i]; i++){
  1966. var count = Math.floor(delta / chunk[0]);
  1967. if(count) break;
  1968. }
  1969. return count + " " + chunk[1](count);
  1970. },
  1971. _chunks: [
  1972. [60 * 60 * 24 * 365 * 1000, function(n){ return (n == 1) ? 'year' : 'years'; }],
  1973. [60 * 60 * 24 * 30 * 1000, function(n){ return (n == 1) ? 'month' : 'months'; }],
  1974. [60 * 60 * 24 * 7 * 1000, function(n){ return (n == 1) ? 'week' : 'weeks'; }],
  1975. [60 * 60 * 24 * 1000, function(n){ return (n == 1) ? 'day' : 'days'; }],
  1976. [60 * 60 * 1000, function(n){ return (n == 1) ? 'hour' : 'hours'; }],
  1977. [60 * 1000, function(n){ return (n == 1) ? 'minute' : 'minutes'; }]
  1978. ],
  1979. _months_ap: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."]
  1980. });
  1981. }
  1982. if(!dojo._hasResource["dojox.dtl.tag.date"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1983. dojo._hasResource["dojox.dtl.tag.date"] = true;
  1984. dojo.provide("dojox.dtl.tag.date");
  1985. dojox.dtl.tag.date.NowNode = function(format, node){
  1986. this._format = format;
  1987. this.format = new dojox.dtl.utils.date.DateFormat(format);
  1988. this.contents = node;
  1989. }
  1990. dojo.extend(dojox.dtl.tag.date.NowNode, {
  1991. render: function(context, buffer){
  1992. this.contents.set(this.format.format(new Date()));
  1993. return this.contents.render(context, buffer);
  1994. },
  1995. unrender: function(context, buffer){
  1996. return this.contents.unrender(context, buffer);
  1997. },
  1998. clone: function(buffer){
  1999. return new this.constructor(this._format, this.contents.clone(buffer));
  2000. }
  2001. });
  2002. dojox.dtl.tag.date.now = function(parser, token){
  2003. // Split by either :" or :'
  2004. var parts = token.split_contents();
  2005. if(parts.length != 2){
  2006. throw new Error("'now' statement takes one argument");
  2007. }
  2008. return new dojox.dtl.tag.date.NowNode(parts[1].slice(1, -1), parser.create_text_node());
  2009. }
  2010. }
  2011. if(!dojo._hasResource["dojox.dtl.tag.loader"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2012. dojo._hasResource["dojox.dtl.tag.loader"] = true;
  2013. dojo.provide("dojox.dtl.tag.loader");
  2014. (function(){
  2015. var dd = dojox.dtl;
  2016. var ddtl = dd.tag.loader;
  2017. ddtl.BlockNode = dojo.extend(function(name, nodelist){
  2018. this.name = name;
  2019. this.nodelist = nodelist; // Can be overridden
  2020. },
  2021. {
  2022. "super": function(){
  2023. if(this.parent){
  2024. var html = this.parent.nodelist.dummyRender(this.context, null, true);
  2025. if(typeof html == "string"){
  2026. html = new String(html);
  2027. }
  2028. html.safe = true;
  2029. return html;
  2030. }
  2031. return '';
  2032. },
  2033. render: function(context, buffer){
  2034. var name = this.name;
  2035. var nodelist = this.nodelist;
  2036. var parent;
  2037. if(buffer.blocks){
  2038. var block = buffer.blocks[name];
  2039. if(block){
  2040. parent = block.parent;
  2041. nodelist = block.nodelist;
  2042. block.used = true;
  2043. }
  2044. }
  2045. this.rendered = nodelist;
  2046. context = context.push();
  2047. this.context = context;
  2048. this.parent = null;
  2049. if(nodelist != this.nodelist){
  2050. this.parent = this;
  2051. }
  2052. context.block = this;
  2053. if(buffer.getParent){
  2054. var bufferParent = buffer.getParent();
  2055. var setParent = dojo.connect(buffer, "onSetParent", function(node, up, root){
  2056. if(up && root){
  2057. buffer.setParent(bufferParent);
  2058. }
  2059. });
  2060. }
  2061. buffer = nodelist.render(context, buffer, this);
  2062. setParent && dojo.disconnect(setParent);
  2063. context = context.pop();
  2064. return buffer;
  2065. },
  2066. unrender: function(context, buffer){
  2067. return this.rendered.unrender(context, buffer);
  2068. },
  2069. clone: function(buffer){
  2070. return new this.constructor(this.name, this.nodelist.clone(buffer));
  2071. },
  2072. toString: function(){ return "dojox.dtl.tag.loader.BlockNode"; }
  2073. });
  2074. ddtl.ExtendsNode = dojo.extend(function(getTemplate, nodelist, shared, parent, key){
  2075. this.getTemplate = getTemplate;
  2076. this.nodelist = nodelist;
  2077. this.shared = shared;
  2078. this.parent = parent;
  2079. this.key = key;
  2080. },
  2081. {
  2082. parents: {},
  2083. getParent: function(context){
  2084. var parent = this.parent;
  2085. if(!parent){
  2086. var string;
  2087. parent = this.parent = context.get(this.key, false);
  2088. if(!parent){
  2089. throw new Error("extends tag used a variable that did not resolve");
  2090. }
  2091. if(typeof parent == "object"){
  2092. var url = parent.url || parent.templatePath;
  2093. if(parent.shared){
  2094. this.shared = true;
  2095. }
  2096. if(url){
  2097. parent = this.parent = url.toString();
  2098. }else if(parent.templateString){
  2099. // Allow the builder's string interning to work
  2100. string = parent.templateString;
  2101. parent = this.parent = " ";
  2102. }else{
  2103. parent = this.parent = this.parent.toString();
  2104. }
  2105. }
  2106. if(parent && parent.indexOf("shared:") === 0){
  2107. this.shared = true;
  2108. parent = this.parent = parent.substring(7, parent.length);
  2109. }
  2110. }
  2111. if(!parent){
  2112. throw new Error("Invalid template name in 'extends' tag.");
  2113. }
  2114. if(parent.render){
  2115. return parent;
  2116. }
  2117. if(this.parents[parent]){
  2118. return this.parents[parent];
  2119. }
  2120. this.parent = this.getTemplate(string || dojox.dtl.text.getTemplateString(parent));
  2121. if(this.shared){
  2122. this.parents[parent] = this.parent;
  2123. }
  2124. return this.parent;
  2125. },
  2126. render: function(context, buffer){
  2127. var parent = this.getParent(context);
  2128. parent.blocks = parent.blocks || {};
  2129. buffer.blocks = buffer.blocks || {};
  2130. for(var i = 0, node; node = this.nodelist.contents[i]; i++){
  2131. if(node instanceof dojox.dtl.tag.loader.BlockNode){
  2132. var old = parent.blocks[node.name];
  2133. if(old && old.nodelist != node.nodelist){
  2134. // In a shared template, the individual blocks might change
  2135. buffer = old.nodelist.unrender(context, buffer);
  2136. }
  2137. parent.blocks[node.name] = buffer.blocks[node.name] = {
  2138. shared: this.shared,
  2139. nodelist: node.nodelist,
  2140. used: false
  2141. }
  2142. }
  2143. }
  2144. this.rendered = parent;
  2145. return parent.nodelist.render(context, buffer, this);
  2146. },
  2147. unrender: function(context, buffer){
  2148. return this.rendered.unrender(context, buffer, this);
  2149. },
  2150. toString: function(){ return "dojox.dtl.block.ExtendsNode"; }
  2151. });
  2152. ddtl.IncludeNode = dojo.extend(function(path, constant, getTemplate, text, parsed){
  2153. this._path = path;
  2154. this.constant = constant;
  2155. this.path = (constant) ? path : new dd._Filter(path);
  2156. this.getTemplate = getTemplate;
  2157. this.text = text;
  2158. this.parsed = (arguments.length == 5) ? parsed : true;
  2159. },
  2160. {
  2161. _cache: [{}, {}],
  2162. render: function(context, buffer){
  2163. var location = ((this.constant) ? this.path : this.path.resolve(context)).toString();
  2164. var parsed = Number(this.parsed);
  2165. var dirty = false;
  2166. if(location != this.last){
  2167. dirty = true;
  2168. if(this.last){
  2169. buffer = this.unrender(context, buffer);
  2170. }
  2171. this.last = location;
  2172. }
  2173. var cache = this._cache[parsed];
  2174. if(parsed){
  2175. if(!cache[location]){
  2176. cache[location] = dd.text._resolveTemplateArg(location, true);
  2177. }
  2178. if(dirty){
  2179. var template = this.getTemplate(cache[location]);
  2180. this.rendered = template.nodelist;
  2181. }
  2182. return this.rendered.render(context, buffer, this);
  2183. }else{
  2184. if(this.text instanceof dd._TextNode){
  2185. if(dirty){
  2186. this.rendered = this.text;
  2187. this.rendered.set(dd.text._resolveTemplateArg(location, true));
  2188. }
  2189. return this.rendered.render(context, buffer);
  2190. }else{
  2191. if(!cache[location]){
  2192. var nodelist = [];
  2193. var div = document.createElement("div");
  2194. div.innerHTML = dd.text._resolveTemplateArg(location, true);
  2195. var children = div.childNodes;
  2196. while(children.length){
  2197. var removed = div.removeChild(children[0]);
  2198. nodelist.push(removed);
  2199. }
  2200. cache[location] = nodelist;
  2201. }
  2202. if(dirty){
  2203. this.nodelist = [];
  2204. var exists = true;
  2205. for(var i = 0, child; child = cache[location][i]; i++){
  2206. this.nodelist.push(child.cloneNode(true));
  2207. }
  2208. }
  2209. for(var i = 0, node; node = this.nodelist[i]; i++){
  2210. buffer = buffer.concat(node);
  2211. }
  2212. }
  2213. }
  2214. return buffer;
  2215. },
  2216. unrender: function(context, buffer){
  2217. if(this.rendered){
  2218. buffer = this.rendered.unrender(context, buffer);
  2219. }
  2220. if(this.nodelist){
  2221. for(var i = 0, node; node = this.nodelist[i]; i++){
  2222. buffer = buffer.remove(node);
  2223. }
  2224. }
  2225. return buffer;
  2226. },
  2227. clone: function(buffer){
  2228. return new this.constructor(this._path, this.constant, this.getTemplate, this.text.clone(buffer), this.parsed);
  2229. }
  2230. });
  2231. dojo.mixin(ddtl, {
  2232. block: function(parser, token){
  2233. var parts = token.contents.split();
  2234. var name = parts[1];
  2235. parser._blocks = parser._blocks || {};
  2236. parser._blocks[name] = parser._blocks[name] || [];
  2237. parser._blocks[name].push(name);
  2238. var nodelist = parser.parse(["endblock", "endblock " + name]).rtrim();
  2239. parser.next_token();
  2240. return new dojox.dtl.tag.loader.BlockNode(name, nodelist);
  2241. },
  2242. extends_: function(parser, token){
  2243. var parts = token.contents.split();
  2244. var shared = false;
  2245. var parent = null;
  2246. var key = null;
  2247. if(parts[1].charAt(0) == '"' || parts[1].charAt(0) == "'"){
  2248. parent = parts[1].substring(1, parts[1].length - 1);
  2249. }else{
  2250. key = parts[1];
  2251. }
  2252. if(parent && parent.indexOf("shared:") == 0){
  2253. shared = true;
  2254. parent = parent.substring(7, parent.length);
  2255. }
  2256. var nodelist = parser.parse();
  2257. return new dojox.dtl.tag.loader.ExtendsNode(parser.getTemplate, nodelist, shared, parent, key);
  2258. },
  2259. include: function(parser, token){
  2260. var parts = token.contents.split();
  2261. if(parts.length != 2){
  2262. throw new Error(parts[0] + " tag takes one argument: the name of the template to be included");
  2263. }
  2264. var path = parts[1];
  2265. var constant = false;
  2266. if((path.charAt(0) == '"' || path.slice(-1) == "'") && path.charAt(0) == path.slice(-1)){
  2267. path = path.slice(1, -1);
  2268. constant = true;
  2269. }
  2270. return new ddtl.IncludeNode(path, constant, parser.getTemplate, parser.create_text_node());
  2271. },
  2272. ssi: function(parser, token){
  2273. // We're going to treat things a little differently here.
  2274. // First of all, this tag is *not* portable, so I'm not
  2275. // concerned about it being a "drop in" replacement.
  2276. // Instead, we'll just replicate the include tag, but with that
  2277. // optional "parsed" parameter.
  2278. var parts = token.contents.split();
  2279. var parsed = false;
  2280. if(parts.length == 3){
  2281. parsed = (parts.pop() == "parsed");
  2282. if(!parsed){
  2283. throw new Error("Second (optional) argument to ssi tag must be 'parsed'");
  2284. }
  2285. }
  2286. var node = ddtl.include(parser, new dd.Token(token.token_type, parts.join(" ")));
  2287. node.parsed = parsed;
  2288. return node;
  2289. }
  2290. });
  2291. })();
  2292. }
  2293. if(!dojo._hasResource["dojox.dtl.tag.misc"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2294. dojo._hasResource["dojox.dtl.tag.misc"] = true;
  2295. dojo.provide("dojox.dtl.tag.misc");
  2296. (function(){
  2297. var dd = dojox.dtl;
  2298. var ddtm = dd.tag.misc;
  2299. ddtm.DebugNode = dojo.extend(function(text){
  2300. this.text = text;
  2301. },
  2302. {
  2303. render: function(context, buffer){
  2304. var keys = context.getKeys();
  2305. var debug = [];
  2306. var only = {};
  2307. for(var i = 0, key; key = keys[i]; i++){
  2308. only[key] = context[key];
  2309. debug += "[" + key + ": " + typeof context[key] + "]\n";
  2310. }
  2311. console.debug(only);
  2312. return this.text.set(debug).render(context, buffer, this);
  2313. },
  2314. unrender: function(context, buffer){
  2315. return buffer;
  2316. },
  2317. clone: function(buffer){
  2318. return new this.constructor(this.text.clone(buffer));
  2319. },
  2320. toString: function(){ return "ddtm.DebugNode"; }
  2321. });
  2322. ddtm.FilterNode = dojo.extend(function(varnode, nodelist){
  2323. this._varnode = varnode;
  2324. this._nodelist = nodelist;
  2325. },
  2326. {
  2327. render: function(context, buffer){
  2328. // Doing this in HTML requires a different buffer with a fake root node
  2329. var output = this._nodelist.render(context, new dojox.string.Builder());
  2330. context = context.update({ "var": output.toString() });
  2331. var filtered = this._varnode.render(context, buffer);
  2332. context = context.pop();
  2333. return buffer;
  2334. },
  2335. unrender: function(context, buffer){
  2336. return buffer;
  2337. },
  2338. clone: function(buffer){
  2339. return new this.constructor(this._expression, this._nodelist.clone(buffer));
  2340. }
  2341. });
  2342. ddtm.FirstOfNode = dojo.extend(function(vars, text){
  2343. this._vars = vars;
  2344. this.vars = dojo.map(vars, function(item){
  2345. return new dojox.dtl._Filter(item);
  2346. });
  2347. this.contents = text;
  2348. },
  2349. {
  2350. render: function(context, buffer){
  2351. for(var i = 0, item; item = this.vars[i]; i++){
  2352. var resolved = item.resolve(context);
  2353. if(typeof resolved != "undefined"){
  2354. if(resolved === null){
  2355. resolved = "null";
  2356. }
  2357. this.contents.set(resolved);
  2358. return this.contents.render(context, buffer);
  2359. }
  2360. }
  2361. return this.contents.unrender(context, buffer);
  2362. },
  2363. unrender: function(context, buffer){
  2364. return this.contents.unrender(context, buffer);
  2365. },
  2366. clone: function(buffer){
  2367. return new this.constructor(this._vars, this.contents.clone(buffer));
  2368. }
  2369. });
  2370. ddtm.SpacelessNode = dojo.extend(function(nodelist, text){
  2371. this.nodelist = nodelist;
  2372. this.contents = text;
  2373. },
  2374. {
  2375. render: function(context, buffer){
  2376. if(buffer.getParent){
  2377. // Unfortunately, we have to branch here
  2378. var watch = [
  2379. dojo.connect(buffer, "onAddNodeComplete", this, "_watch"),
  2380. dojo.connect(buffer, "onSetParent", this, "_watchParent")
  2381. ];
  2382. buffer = this.nodelist.render(context, buffer);
  2383. dojo.disconnect(watch[0]);
  2384. dojo.disconnect(watch[1]);
  2385. }else{
  2386. var value = this.nodelist.dummyRender(context);
  2387. this.contents.set(value.replace(/>\s+</g, '><'));
  2388. buffer = this.contents.render(context, buffer);
  2389. }
  2390. return buffer;
  2391. },
  2392. unrender: function(context, buffer){
  2393. return this.nodelist.unrender(context, buffer);
  2394. },
  2395. clone: function(buffer){
  2396. return new this.constructor(this.nodelist.clone(buffer), this.contents.clone(buffer));
  2397. },
  2398. _isEmpty: function(node){
  2399. return (node.nodeType == 3 && !node.data.match(/[^\s\n]/));
  2400. },
  2401. _watch: function(node){
  2402. if(this._isEmpty(node)){
  2403. var remove = false;
  2404. if(node.parentNode.firstChild == node){
  2405. node.parentNode.removeChild(node);
  2406. }
  2407. }else{
  2408. var children = node.parentNode.childNodes;
  2409. if(node.nodeType == 1 && children.length > 2){
  2410. for(var i = 2, child; child = children[i]; i++){
  2411. if(children[i - 2].nodeType == 1 && this._isEmpty(children[i - 1])){
  2412. node.parentNode.removeChild(children[i - 1]);
  2413. return;
  2414. }
  2415. }
  2416. }
  2417. }
  2418. },
  2419. _watchParent: function(node){
  2420. var children = node.childNodes;
  2421. if(children.length){
  2422. while(node.childNodes.length){
  2423. var last = node.childNodes[node.childNodes.length - 1];
  2424. if(!this._isEmpty(last)){
  2425. return;
  2426. }
  2427. node.removeChild(last);
  2428. }
  2429. }
  2430. }
  2431. });
  2432. ddtm.TemplateTagNode = dojo.extend(function(tag, text){
  2433. this.tag = tag;
  2434. this.contents = text;
  2435. },
  2436. {
  2437. mapping: {
  2438. openblock: "{%",
  2439. closeblock: "%}",
  2440. openvariable: "{{",
  2441. closevariable: "}}",
  2442. openbrace: "{",
  2443. closebrace: "}",
  2444. opencomment: "{#",
  2445. closecomment: "#}"
  2446. },
  2447. render: function(context, buffer){
  2448. this.contents.set(this.mapping[this.tag]);
  2449. return this.contents.render(context, buffer);
  2450. },
  2451. unrender: function(context, buffer){
  2452. return this.contents.unrender(context, buffer);
  2453. },
  2454. clone: function(buffer){
  2455. return new this.constructor(this.tag, this.contents.clone(buffer));
  2456. }
  2457. });
  2458. ddtm.WidthRatioNode = dojo.extend(function(current, max, width, text){
  2459. this.current = new dd._Filter(current);
  2460. this.max = new dd._Filter(max);
  2461. this.width = width;
  2462. this.contents = text;
  2463. },
  2464. {
  2465. render: function(context, buffer){
  2466. var current = +this.current.resolve(context);
  2467. var max = +this.max.resolve(context);
  2468. if(typeof current != "number" || typeof max != "number" || !max){
  2469. this.contents.set("");
  2470. }else{
  2471. this.contents.set("" + Math.round((current / max) * this.width));
  2472. }
  2473. return this.contents.render(context, buffer);
  2474. },
  2475. unrender: function(context, buffer){
  2476. return this.contents.unrender(context, buffer);
  2477. },
  2478. clone: function(buffer){
  2479. return new this.constructor(this.current.getExpression(), this.max.getExpression(), this.width, this.contents.clone(buffer));
  2480. }
  2481. });
  2482. ddtm.WithNode = dojo.extend(function(target, alias, nodelist){
  2483. this.target = new dd._Filter(target);
  2484. this.alias = alias;
  2485. this.nodelist = nodelist;
  2486. },
  2487. {
  2488. render: function(context, buffer){
  2489. var target = this.target.resolve(context);
  2490. context = context.push();
  2491. context[this.alias] = target;
  2492. buffer = this.nodelist.render(context, buffer);
  2493. context = context.pop();
  2494. return buffer;
  2495. },
  2496. unrender: function(context, buffer){
  2497. return buffer;
  2498. },
  2499. clone: function(buffer){
  2500. return new this.constructor(this.target.getExpression(), this.alias, this.nodelist.clone(buffer));
  2501. }
  2502. });
  2503. dojo.mixin(ddtm, {
  2504. comment: function(parser, token){
  2505. // summary: Ignore everything between {% comment %} and {% endcomment %}
  2506. parser.skip_past("endcomment");
  2507. return dd._noOpNode;
  2508. },
  2509. debug: function(parser, token){
  2510. // summary: Output the current context, maybe add more stuff later.
  2511. return new ddtm.DebugNode(parser.create_text_node());
  2512. },
  2513. filter: function(parser, token){
  2514. // summary: Filter the contents of the blog through variable filters.
  2515. var rest = token.contents.split(null, 1)[1];
  2516. var varnode = parser.create_variable_node("var|" + rest);
  2517. var nodelist = parser.parse(["endfilter"]);
  2518. parser.next_token();
  2519. return new ddtm.FilterNode(varnode, nodelist);
  2520. },
  2521. firstof: function(parser, token){
  2522. var parts = token.split_contents().slice(1);
  2523. if(!parts.length){
  2524. throw new Error("'firstof' statement requires at least one argument");
  2525. }
  2526. return new ddtm.FirstOfNode(parts, parser.create_text_node());
  2527. },
  2528. spaceless: function(parser, token){
  2529. var nodelist = parser.parse(["endspaceless"]);
  2530. parser.delete_first_token();
  2531. return new ddtm.SpacelessNode(nodelist, parser.create_text_node());
  2532. },
  2533. templatetag: function(parser, token){
  2534. var parts = token.contents.split();
  2535. if(parts.length != 2){
  2536. throw new Error("'templatetag' statement takes one argument");
  2537. }
  2538. var tag = parts[1];
  2539. var mapping = ddtm.TemplateTagNode.prototype.mapping;
  2540. if(!mapping[tag]){
  2541. var keys = [];
  2542. for(var key in mapping){
  2543. keys.push(key);
  2544. }
  2545. throw new Error("Invalid templatetag argument: '" + tag + "'. Must be one of: " + keys.join(", "));
  2546. }
  2547. return new ddtm.TemplateTagNode(tag, parser.create_text_node());
  2548. },
  2549. widthratio: function(parser, token){
  2550. var parts = token.contents.split();
  2551. if(parts.length != 4){
  2552. throw new Error("widthratio takes three arguments");
  2553. }
  2554. var width = +parts[3];
  2555. if(typeof width != "number"){
  2556. throw new Error("widthratio final argument must be an integer");
  2557. }
  2558. return new ddtm.WidthRatioNode(parts[1], parts[2], width, parser.create_text_node());
  2559. },
  2560. with_: function(parser, token){
  2561. var parts = token.split_contents();
  2562. if(parts.length != 4 || parts[2] != "as"){
  2563. throw new Error("do_width expected format as 'with value as name'");
  2564. }
  2565. var nodelist = parser.parse(["endwith"]);
  2566. parser.next_token();
  2567. return new ddtm.WithNode(parts[1], parts[3], nodelist);
  2568. }
  2569. });
  2570. })();
  2571. }
  2572. if(!dojo._hasResource["dojox.dtl.ext-dojo.NodeList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2573. dojo._hasResource["dojox.dtl.ext-dojo.NodeList"] = true;
  2574. dojo.provide("dojox.dtl.ext-dojo.NodeList");
  2575. dojo.extend(dojo.NodeList, {
  2576. dtl: function(template, context){
  2577. // template: dojox.dtl.__StringArgs|String
  2578. // The template string or location
  2579. // context: dojox.dtl.__ObjectArgs|Object
  2580. // The context object or location
  2581. var d = dojox.dtl;
  2582. var self = this;
  2583. var render = function(template, context){
  2584. var content = template.render(new d._Context(context));
  2585. self.forEach(function(node){
  2586. node.innerHTML = content;
  2587. });
  2588. }
  2589. d.text._resolveTemplateArg(template).addCallback(function(templateString){
  2590. template = new d.Template(templateString);
  2591. d.text._resolveContextArg(context).addCallback(function(context){
  2592. render(template, context);
  2593. });
  2594. });
  2595. return this;
  2596. }
  2597. });
  2598. }