dtl.js.uncompressed.js 80 KB

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