Commit | Line | Data |
---|---|---|
6a1aa64f DV |
1 | /*** |
2 | ||
3 | MochiKit.MochiKit 1.4 : PACKED VERSION | |
4 | ||
5 | THIS FILE IS AUTOMATICALLY GENERATED. If creating patches, please | |
6 | diff against the source tree, not this file. | |
7 | ||
8 | See <http://mochikit.com/> for documentation, downloads, license, etc. | |
9 | ||
10 | (c) 2005 Bob Ippolito. All rights Reserved. | |
11 | ||
12 | ***/ | |
13 | ||
14 | if(typeof (dojo)!="undefined"){ | |
15 | dojo.provide("MochiKit.Base"); | |
16 | } | |
17 | if(typeof (MochiKit)=="undefined"){ | |
18 | MochiKit={}; | |
19 | } | |
20 | if(typeof (MochiKit.Base)=="undefined"){ | |
21 | MochiKit.Base={}; | |
22 | } | |
23 | if(typeof (MochiKit.__export__)=="undefined"){ | |
24 | MochiKit.__export__=(MochiKit.__compat__||(typeof (JSAN)=="undefined"&&typeof (dojo)=="undefined")); | |
25 | } | |
26 | MochiKit.Base.VERSION="1.4"; | |
27 | MochiKit.Base.NAME="MochiKit.Base"; | |
28 | MochiKit.Base.update=function(_1,_2){ | |
29 | if(_1===null){ | |
30 | _1={}; | |
31 | } | |
32 | for(var i=1;i<arguments.length;i++){ | |
33 | var o=arguments[i]; | |
34 | if(typeof (o)!="undefined"&&o!==null){ | |
35 | for(var k in o){ | |
36 | _1[k]=o[k]; | |
37 | } | |
38 | } | |
39 | } | |
40 | return _1; | |
41 | }; | |
42 | MochiKit.Base.update(MochiKit.Base,{__repr__:function(){ | |
43 | return "["+this.NAME+" "+this.VERSION+"]"; | |
44 | },toString:function(){ | |
45 | return this.__repr__(); | |
46 | },camelize:function(_6){ | |
47 | var _7=_6.split("-"); | |
48 | var cc=_7[0]; | |
49 | for(var i=1;i<_7.length;i++){ | |
50 | cc+=_7[i].charAt(0).toUpperCase()+_7[i].substring(1); | |
51 | } | |
52 | return cc; | |
53 | },counter:function(n){ | |
54 | if(arguments.length===0){ | |
55 | n=1; | |
56 | } | |
57 | return function(){ | |
58 | return n++; | |
59 | }; | |
60 | },clone:function(_b){ | |
61 | var me=arguments.callee; | |
62 | if(arguments.length==1){ | |
63 | me.prototype=_b; | |
64 | return new me(); | |
65 | } | |
66 | },_flattenArray:function(_d,_e){ | |
67 | for(var i=0;i<_e.length;i++){ | |
68 | var o=_e[i]; | |
69 | if(o instanceof Array){ | |
70 | arguments.callee(_d,o); | |
71 | }else{ | |
72 | _d.push(o); | |
73 | } | |
74 | } | |
75 | return _d; | |
76 | },flattenArray:function(lst){ | |
77 | return MochiKit.Base._flattenArray([],lst); | |
78 | },flattenArguments:function(lst){ | |
79 | var res=[]; | |
80 | var m=MochiKit.Base; | |
81 | var _15=m.extend(null,arguments); | |
82 | while(_15.length){ | |
83 | var o=_15.shift(); | |
84 | if(o&&typeof (o)=="object"&&typeof (o.length)=="number"){ | |
85 | for(var i=o.length-1;i>=0;i--){ | |
86 | _15.unshift(o[i]); | |
87 | } | |
88 | }else{ | |
89 | res.push(o); | |
90 | } | |
91 | } | |
92 | return res; | |
93 | },extend:function(_18,obj,_1a){ | |
94 | if(!_1a){ | |
95 | _1a=0; | |
96 | } | |
97 | if(obj){ | |
98 | var l=obj.length; | |
99 | if(typeof (l)!="number"){ | |
100 | if(typeof (MochiKit.Iter)!="undefined"){ | |
101 | obj=MochiKit.Iter.list(obj); | |
102 | l=obj.length; | |
103 | }else{ | |
104 | throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); | |
105 | } | |
106 | } | |
107 | if(!_18){ | |
108 | _18=[]; | |
109 | } | |
110 | for(var i=_1a;i<l;i++){ | |
111 | _18.push(obj[i]); | |
112 | } | |
113 | } | |
114 | return _18; | |
115 | },updatetree:function(_1d,obj){ | |
116 | if(_1d===null){ | |
117 | _1d={}; | |
118 | } | |
119 | for(var i=1;i<arguments.length;i++){ | |
120 | var o=arguments[i]; | |
121 | if(typeof (o)!="undefined"&&o!==null){ | |
122 | for(var k in o){ | |
123 | var v=o[k]; | |
124 | if(typeof (_1d[k])=="object"&&typeof (v)=="object"){ | |
125 | arguments.callee(_1d[k],v); | |
126 | }else{ | |
127 | _1d[k]=v; | |
128 | } | |
129 | } | |
130 | } | |
131 | } | |
132 | return _1d; | |
133 | },setdefault:function(_23,obj){ | |
134 | if(_23===null){ | |
135 | _23={}; | |
136 | } | |
137 | for(var i=1;i<arguments.length;i++){ | |
138 | var o=arguments[i]; | |
139 | for(var k in o){ | |
140 | if(!(k in _23)){ | |
141 | _23[k]=o[k]; | |
142 | } | |
143 | } | |
144 | } | |
145 | return _23; | |
146 | },keys:function(obj){ | |
147 | var _29=[]; | |
148 | for(var _2a in obj){ | |
149 | _29.push(_2a); | |
150 | } | |
151 | return _29; | |
152 | },values:function(obj){ | |
153 | var _2c=[]; | |
154 | for(var _2d in obj){ | |
155 | _2c.push(obj[_2d]); | |
156 | } | |
157 | return _2c; | |
158 | },items:function(obj){ | |
159 | var _2f=[]; | |
160 | var e; | |
161 | for(var _31 in obj){ | |
162 | var v; | |
163 | try{ | |
164 | v=obj[_31]; | |
165 | } | |
166 | catch(e){ | |
167 | continue; | |
168 | } | |
169 | _2f.push([_31,v]); | |
170 | } | |
171 | return _2f; | |
172 | },_newNamedError:function(_33,_34,_35){ | |
173 | _35.prototype=new MochiKit.Base.NamedError(_33.NAME+"."+_34); | |
174 | _33[_34]=_35; | |
175 | },operator:{truth:function(a){ | |
176 | return !!a; | |
177 | },lognot:function(a){ | |
178 | return !a; | |
179 | },identity:function(a){ | |
180 | return a; | |
181 | },not:function(a){ | |
182 | return ~a; | |
183 | },neg:function(a){ | |
184 | return -a; | |
185 | },add:function(a,b){ | |
186 | return a+b; | |
187 | },sub:function(a,b){ | |
188 | return a-b; | |
189 | },div:function(a,b){ | |
190 | return a/b; | |
191 | },mod:function(a,b){ | |
192 | return a%b; | |
193 | },mul:function(a,b){ | |
194 | return a*b; | |
195 | },and:function(a,b){ | |
196 | return a&b; | |
197 | },or:function(a,b){ | |
198 | return a|b; | |
199 | },xor:function(a,b){ | |
200 | return a^b; | |
201 | },lshift:function(a,b){ | |
202 | return a<<b; | |
203 | },rshift:function(a,b){ | |
204 | return a>>b; | |
205 | },zrshift:function(a,b){ | |
206 | return a>>>b; | |
207 | },eq:function(a,b){ | |
208 | return a==b; | |
209 | },ne:function(a,b){ | |
210 | return a!=b; | |
211 | },gt:function(a,b){ | |
212 | return a>b; | |
213 | },ge:function(a,b){ | |
214 | return a>=b; | |
215 | },lt:function(a,b){ | |
216 | return a<b; | |
217 | },le:function(a,b){ | |
218 | return a<=b; | |
219 | },seq:function(a,b){ | |
220 | return a===b; | |
221 | },sne:function(a,b){ | |
222 | return a!==b; | |
223 | },ceq:function(a,b){ | |
224 | return MochiKit.Base.compare(a,b)===0; | |
225 | },cne:function(a,b){ | |
226 | return MochiKit.Base.compare(a,b)!==0; | |
227 | },cgt:function(a,b){ | |
228 | return MochiKit.Base.compare(a,b)==1; | |
229 | },cge:function(a,b){ | |
230 | return MochiKit.Base.compare(a,b)!=-1; | |
231 | },clt:function(a,b){ | |
232 | return MochiKit.Base.compare(a,b)==-1; | |
233 | },cle:function(a,b){ | |
234 | return MochiKit.Base.compare(a,b)!=1; | |
235 | },logand:function(a,b){ | |
236 | return a&&b; | |
237 | },logor:function(a,b){ | |
238 | return a||b; | |
239 | },contains:function(a,b){ | |
240 | return b in a; | |
241 | }},forwardCall:function(_73){ | |
242 | return function(){ | |
243 | return this[_73].apply(this,arguments); | |
244 | }; | |
245 | },itemgetter:function(_74){ | |
246 | return function(arg){ | |
247 | return arg[_74]; | |
248 | }; | |
249 | },typeMatcher:function(){ | |
250 | var _76={}; | |
251 | for(var i=0;i<arguments.length;i++){ | |
252 | var typ=arguments[i]; | |
253 | _76[typ]=typ; | |
254 | } | |
255 | return function(){ | |
256 | for(var i=0;i<arguments.length;i++){ | |
257 | if(!(typeof (arguments[i]) in _76)){ | |
258 | return false; | |
259 | } | |
260 | } | |
261 | return true; | |
262 | }; | |
263 | },isNull:function(){ | |
264 | for(var i=0;i<arguments.length;i++){ | |
265 | if(arguments[i]!==null){ | |
266 | return false; | |
267 | } | |
268 | } | |
269 | return true; | |
270 | },isUndefinedOrNull:function(){ | |
271 | for(var i=0;i<arguments.length;i++){ | |
272 | var o=arguments[i]; | |
273 | if(!(typeof (o)=="undefined"||o===null)){ | |
274 | return false; | |
275 | } | |
276 | } | |
277 | return true; | |
278 | },isEmpty:function(obj){ | |
279 | return !MochiKit.Base.isNotEmpty.apply(this,arguments); | |
280 | },isNotEmpty:function(obj){ | |
281 | for(var i=0;i<arguments.length;i++){ | |
282 | var o=arguments[i]; | |
283 | if(!(o&&o.length)){ | |
284 | return false; | |
285 | } | |
286 | } | |
287 | return true; | |
288 | },isArrayLike:function(){ | |
289 | for(var i=0;i<arguments.length;i++){ | |
290 | var o=arguments[i]; | |
291 | var typ=typeof (o); | |
292 | if((typ!="object"&&!(typ=="function"&&typeof (o.item)=="function"))||o===null||typeof (o.length)!="number"||o.nodeType===3){ | |
293 | return false; | |
294 | } | |
295 | } | |
296 | return true; | |
297 | },isDateLike:function(){ | |
298 | for(var i=0;i<arguments.length;i++){ | |
299 | var o=arguments[i]; | |
300 | if(typeof (o)!="object"||o===null||typeof (o.getTime)!="function"){ | |
301 | return false; | |
302 | } | |
303 | } | |
304 | return true; | |
305 | },xmap:function(fn){ | |
306 | if(fn===null){ | |
307 | return MochiKit.Base.extend(null,arguments,1); | |
308 | } | |
309 | var _87=[]; | |
310 | for(var i=1;i<arguments.length;i++){ | |
311 | _87.push(fn(arguments[i])); | |
312 | } | |
313 | return _87; | |
314 | },map:function(fn,lst){ | |
315 | var m=MochiKit.Base; | |
316 | var itr=MochiKit.Iter; | |
317 | var _8d=m.isArrayLike; | |
318 | if(arguments.length<=2){ | |
319 | if(!_8d(lst)){ | |
320 | if(itr){ | |
321 | lst=itr.list(lst); | |
322 | if(fn===null){ | |
323 | return lst; | |
324 | } | |
325 | }else{ | |
326 | throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); | |
327 | } | |
328 | } | |
329 | if(fn===null){ | |
330 | return m.extend(null,lst); | |
331 | } | |
332 | var _8e=[]; | |
333 | for(var i=0;i<lst.length;i++){ | |
334 | _8e.push(fn(lst[i])); | |
335 | } | |
336 | return _8e; | |
337 | }else{ | |
338 | if(fn===null){ | |
339 | fn=Array; | |
340 | } | |
341 | var _90=null; | |
342 | for(i=1;i<arguments.length;i++){ | |
343 | if(!_8d(arguments[i])){ | |
344 | if(itr){ | |
345 | return itr.list(itr.imap.apply(null,arguments)); | |
346 | }else{ | |
347 | throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); | |
348 | } | |
349 | } | |
350 | var l=arguments[i].length; | |
351 | if(_90===null||_90>l){ | |
352 | _90=l; | |
353 | } | |
354 | } | |
355 | _8e=[]; | |
356 | for(i=0;i<_90;i++){ | |
357 | var _92=[]; | |
358 | for(var j=1;j<arguments.length;j++){ | |
359 | _92.push(arguments[j][i]); | |
360 | } | |
361 | _8e.push(fn.apply(this,_92)); | |
362 | } | |
363 | return _8e; | |
364 | } | |
365 | },xfilter:function(fn){ | |
366 | var _95=[]; | |
367 | if(fn===null){ | |
368 | fn=MochiKit.Base.operator.truth; | |
369 | } | |
370 | for(var i=1;i<arguments.length;i++){ | |
371 | var o=arguments[i]; | |
372 | if(fn(o)){ | |
373 | _95.push(o); | |
374 | } | |
375 | } | |
376 | return _95; | |
377 | },filter:function(fn,lst,_9a){ | |
378 | var _9b=[]; | |
379 | var m=MochiKit.Base; | |
380 | if(!m.isArrayLike(lst)){ | |
381 | if(MochiKit.Iter){ | |
382 | lst=MochiKit.Iter.list(lst); | |
383 | }else{ | |
384 | throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); | |
385 | } | |
386 | } | |
387 | if(fn===null){ | |
388 | fn=m.operator.truth; | |
389 | } | |
390 | if(typeof (Array.prototype.filter)=="function"){ | |
391 | return Array.prototype.filter.call(lst,fn,_9a); | |
392 | }else{ | |
393 | if(typeof (_9a)=="undefined"||_9a===null){ | |
394 | for(var i=0;i<lst.length;i++){ | |
395 | var o=lst[i]; | |
396 | if(fn(o)){ | |
397 | _9b.push(o); | |
398 | } | |
399 | } | |
400 | }else{ | |
401 | for(i=0;i<lst.length;i++){ | |
402 | o=lst[i]; | |
403 | if(fn.call(_9a,o)){ | |
404 | _9b.push(o); | |
405 | } | |
406 | } | |
407 | } | |
408 | } | |
409 | return _9b; | |
410 | },_wrapDumbFunction:function(_9f){ | |
411 | return function(){ | |
412 | switch(arguments.length){ | |
413 | case 0: | |
414 | return _9f(); | |
415 | case 1: | |
416 | return _9f(arguments[0]); | |
417 | case 2: | |
418 | return _9f(arguments[0],arguments[1]); | |
419 | case 3: | |
420 | return _9f(arguments[0],arguments[1],arguments[2]); | |
421 | } | |
422 | var _a0=[]; | |
423 | for(var i=0;i<arguments.length;i++){ | |
424 | _a0.push("arguments["+i+"]"); | |
425 | } | |
426 | return eval("(func("+_a0.join(",")+"))"); | |
427 | }; | |
428 | },methodcaller:function(_a2){ | |
429 | var _a3=MochiKit.Base.extend(null,arguments,1); | |
430 | if(typeof (_a2)=="function"){ | |
431 | return function(obj){ | |
432 | return _a2.apply(obj,_a3); | |
433 | }; | |
434 | }else{ | |
435 | return function(obj){ | |
436 | return obj[_a2].apply(obj,_a3); | |
437 | }; | |
438 | } | |
439 | },method:function(_a6,_a7){ | |
440 | var m=MochiKit.Base; | |
441 | return m.bind.apply(this,m.extend([_a7,_a6],arguments,2)); | |
442 | },compose:function(f1,f2){ | |
443 | var _ab=[]; | |
444 | var m=MochiKit.Base; | |
445 | if(arguments.length===0){ | |
446 | throw new TypeError("compose() requires at least one argument"); | |
447 | } | |
448 | for(var i=0;i<arguments.length;i++){ | |
449 | var fn=arguments[i]; | |
450 | if(typeof (fn)!="function"){ | |
451 | throw new TypeError(m.repr(fn)+" is not a function"); | |
452 | } | |
453 | _ab.push(fn); | |
454 | } | |
455 | return function(){ | |
456 | var _af=arguments; | |
457 | for(var i=_ab.length-1;i>=0;i--){ | |
458 | _af=[_ab[i].apply(this,_af)]; | |
459 | } | |
460 | return _af[0]; | |
461 | }; | |
462 | },bind:function(_b1,_b2){ | |
463 | if(typeof (_b1)=="string"){ | |
464 | _b1=_b2[_b1]; | |
465 | } | |
466 | var _b3=_b1.im_func; | |
467 | var _b4=_b1.im_preargs; | |
468 | var _b5=_b1.im_self; | |
469 | var m=MochiKit.Base; | |
470 | if(typeof (_b1)=="function"&&typeof (_b1.apply)=="undefined"){ | |
471 | _b1=m._wrapDumbFunction(_b1); | |
472 | } | |
473 | if(typeof (_b3)!="function"){ | |
474 | _b3=_b1; | |
475 | } | |
476 | if(typeof (_b2)!="undefined"){ | |
477 | _b5=_b2; | |
478 | } | |
479 | if(typeof (_b4)=="undefined"){ | |
480 | _b4=[]; | |
481 | }else{ | |
482 | _b4=_b4.slice(); | |
483 | } | |
484 | m.extend(_b4,arguments,2); | |
485 | var _b7=function(){ | |
486 | var _b8=arguments; | |
487 | var me=arguments.callee; | |
488 | if(me.im_preargs.length>0){ | |
489 | _b8=m.concat(me.im_preargs,_b8); | |
490 | } | |
491 | var _ba=me.im_self; | |
492 | if(!_ba){ | |
493 | _ba=this; | |
494 | } | |
495 | return me.im_func.apply(_ba,_b8); | |
496 | }; | |
497 | _b7.im_self=_b5; | |
498 | _b7.im_func=_b3; | |
499 | _b7.im_preargs=_b4; | |
500 | return _b7; | |
501 | },bindMethods:function(_bb){ | |
502 | var _bc=MochiKit.Base.bind; | |
503 | for(var k in _bb){ | |
504 | var _be=_bb[k]; | |
505 | if(typeof (_be)=="function"){ | |
506 | _bb[k]=_bc(_be,_bb); | |
507 | } | |
508 | } | |
509 | },registerComparator:function(_bf,_c0,_c1,_c2){ | |
510 | MochiKit.Base.comparatorRegistry.register(_bf,_c0,_c1,_c2); | |
511 | },_primitives:{"boolean":true,"string":true,"number":true},compare:function(a,b){ | |
512 | if(a==b){ | |
513 | return 0; | |
514 | } | |
515 | var _c5=(typeof (a)=="undefined"||a===null); | |
516 | var _c6=(typeof (b)=="undefined"||b===null); | |
517 | if(_c5&&_c6){ | |
518 | return 0; | |
519 | }else{ | |
520 | if(_c5){ | |
521 | return -1; | |
522 | }else{ | |
523 | if(_c6){ | |
524 | return 1; | |
525 | } | |
526 | } | |
527 | } | |
528 | var m=MochiKit.Base; | |
529 | var _c8=m._primitives; | |
530 | if(!(typeof (a) in _c8&&typeof (b) in _c8)){ | |
531 | try{ | |
532 | return m.comparatorRegistry.match(a,b); | |
533 | } | |
534 | catch(e){ | |
535 | if(e!=m.NotFound){ | |
536 | throw e; | |
537 | } | |
538 | } | |
539 | } | |
540 | if(a<b){ | |
541 | return -1; | |
542 | }else{ | |
543 | if(a>b){ | |
544 | return 1; | |
545 | } | |
546 | } | |
547 | var _c9=m.repr; | |
548 | throw new TypeError(_c9(a)+" and "+_c9(b)+" can not be compared"); | |
549 | },compareDateLike:function(a,b){ | |
550 | return MochiKit.Base.compare(a.getTime(),b.getTime()); | |
551 | },compareArrayLike:function(a,b){ | |
552 | var _ce=MochiKit.Base.compare; | |
553 | var _cf=a.length; | |
554 | var _d0=0; | |
555 | if(_cf>b.length){ | |
556 | _d0=1; | |
557 | _cf=b.length; | |
558 | }else{ | |
559 | if(_cf<b.length){ | |
560 | _d0=-1; | |
561 | } | |
562 | } | |
563 | for(var i=0;i<_cf;i++){ | |
564 | var cmp=_ce(a[i],b[i]); | |
565 | if(cmp){ | |
566 | return cmp; | |
567 | } | |
568 | } | |
569 | return _d0; | |
570 | },registerRepr:function(_d3,_d4,_d5,_d6){ | |
571 | MochiKit.Base.reprRegistry.register(_d3,_d4,_d5,_d6); | |
572 | },repr:function(o){ | |
573 | if(typeof (o)=="undefined"){ | |
574 | return "undefined"; | |
575 | }else{ | |
576 | if(o===null){ | |
577 | return "null"; | |
578 | } | |
579 | } | |
580 | try{ | |
581 | if(typeof (o.__repr__)=="function"){ | |
582 | return o.__repr__(); | |
583 | }else{ | |
584 | if(typeof (o.repr)=="function"&&o.repr!=arguments.callee){ | |
585 | return o.repr(); | |
586 | } | |
587 | } | |
588 | return MochiKit.Base.reprRegistry.match(o); | |
589 | } | |
590 | catch(e){ | |
591 | if(typeof (o.NAME)=="string"&&(o.toString==Function.prototype.toString||o.toString==Object.prototype.toString)){ | |
592 | return o.NAME; | |
593 | } | |
594 | } | |
595 | try{ | |
596 | var _d8=(o+""); | |
597 | } | |
598 | catch(e){ | |
599 | return "["+typeof (o)+"]"; | |
600 | } | |
601 | if(typeof (o)=="function"){ | |
602 | o=_d8.replace(/^\s+/,""); | |
603 | var idx=o.indexOf("{"); | |
604 | if(idx!=-1){ | |
605 | o=o.substr(0,idx)+"{...}"; | |
606 | } | |
607 | } | |
608 | return _d8; | |
609 | },reprArrayLike:function(o){ | |
610 | var m=MochiKit.Base; | |
611 | return "["+m.map(m.repr,o).join(", ")+"]"; | |
612 | },reprString:function(o){ | |
613 | return ("\""+o.replace(/(["\\])/g,"\\$1")+"\"").replace(/[\f]/g,"\\f").replace(/[\b]/g,"\\b").replace(/[\n]/g,"\\n").replace(/[\t]/g,"\\t").replace(/[\r]/g,"\\r"); | |
614 | },reprNumber:function(o){ | |
615 | return o+""; | |
616 | },registerJSON:function(_de,_df,_e0,_e1){ | |
617 | MochiKit.Base.jsonRegistry.register(_de,_df,_e0,_e1); | |
618 | },evalJSON:function(){ | |
619 | return eval("("+arguments[0]+")"); | |
620 | },serializeJSON:function(o){ | |
621 | var _e3=typeof (o); | |
622 | if(_e3=="number"||_e3=="boolean"){ | |
623 | return o+""; | |
624 | }else{ | |
625 | if(o===null){ | |
626 | return "null"; | |
627 | } | |
628 | } | |
629 | var m=MochiKit.Base; | |
630 | var _e5=m.reprString; | |
631 | if(_e3=="string"){ | |
632 | return _e5(o); | |
633 | } | |
634 | var me=arguments.callee; | |
635 | var _e7; | |
636 | if(typeof (o.__json__)=="function"){ | |
637 | _e7=o.__json__(); | |
638 | if(o!==_e7){ | |
639 | return me(_e7); | |
640 | } | |
641 | } | |
642 | if(typeof (o.json)=="function"){ | |
643 | _e7=o.json(); | |
644 | if(o!==_e7){ | |
645 | return me(_e7); | |
646 | } | |
647 | } | |
648 | if(_e3!="function"&&typeof (o.length)=="number"){ | |
649 | var res=[]; | |
650 | for(var i=0;i<o.length;i++){ | |
651 | var val=me(o[i]); | |
652 | if(typeof (val)!="string"){ | |
653 | val="undefined"; | |
654 | } | |
655 | res.push(val); | |
656 | } | |
657 | return "["+res.join(", ")+"]"; | |
658 | } | |
659 | try{ | |
660 | _e7=m.jsonRegistry.match(o); | |
661 | if(o!==_e7){ | |
662 | return me(_e7); | |
663 | } | |
664 | } | |
665 | catch(e){ | |
666 | if(e!=m.NotFound){ | |
667 | throw e; | |
668 | } | |
669 | } | |
670 | if(_e3=="undefined"){ | |
671 | throw new TypeError("undefined can not be serialized as JSON"); | |
672 | } | |
673 | if(_e3=="function"){ | |
674 | return null; | |
675 | } | |
676 | res=[]; | |
677 | for(var k in o){ | |
678 | var _ec; | |
679 | if(typeof (k)=="number"){ | |
680 | _ec="\""+k+"\""; | |
681 | }else{ | |
682 | if(typeof (k)=="string"){ | |
683 | _ec=_e5(k); | |
684 | }else{ | |
685 | continue; | |
686 | } | |
687 | } | |
688 | val=me(o[k]); | |
689 | if(typeof (val)!="string"){ | |
690 | continue; | |
691 | } | |
692 | res.push(_ec+":"+val); | |
693 | } | |
694 | return "{"+res.join(", ")+"}"; | |
695 | },objEqual:function(a,b){ | |
696 | return (MochiKit.Base.compare(a,b)===0); | |
697 | },arrayEqual:function(_ef,arr){ | |
698 | if(_ef.length!=arr.length){ | |
699 | return false; | |
700 | } | |
701 | return (MochiKit.Base.compare(_ef,arr)===0); | |
702 | },concat:function(){ | |
703 | var _f1=[]; | |
704 | var _f2=MochiKit.Base.extend; | |
705 | for(var i=0;i<arguments.length;i++){ | |
706 | _f2(_f1,arguments[i]); | |
707 | } | |
708 | return _f1; | |
709 | },keyComparator:function(key){ | |
710 | var m=MochiKit.Base; | |
711 | var _f6=m.compare; | |
712 | if(arguments.length==1){ | |
713 | return function(a,b){ | |
714 | return _f6(a[key],b[key]); | |
715 | }; | |
716 | } | |
717 | var _f9=m.extend(null,arguments); | |
718 | return function(a,b){ | |
719 | var _fc=0; | |
720 | for(var i=0;(_fc===0)&&(i<_f9.length);i++){ | |
721 | var key=_f9[i]; | |
722 | _fc=_f6(a[key],b[key]); | |
723 | } | |
724 | return _fc; | |
725 | }; | |
726 | },reverseKeyComparator:function(key){ | |
727 | var _100=MochiKit.Base.keyComparator.apply(this,arguments); | |
728 | return function(a,b){ | |
729 | return _100(b,a); | |
730 | }; | |
731 | },partial:function(func){ | |
732 | var m=MochiKit.Base; | |
733 | return m.bind.apply(this,m.extend([func,undefined],arguments,1)); | |
734 | },listMinMax:function(_105,lst){ | |
735 | if(lst.length===0){ | |
736 | return null; | |
737 | } | |
738 | var cur=lst[0]; | |
739 | var _108=MochiKit.Base.compare; | |
740 | for(var i=1;i<lst.length;i++){ | |
741 | var o=lst[i]; | |
742 | if(_108(o,cur)==_105){ | |
743 | cur=o; | |
744 | } | |
745 | } | |
746 | return cur; | |
747 | },objMax:function(){ | |
748 | return MochiKit.Base.listMinMax(1,arguments); | |
749 | },objMin:function(){ | |
750 | return MochiKit.Base.listMinMax(-1,arguments); | |
751 | },findIdentical:function(lst,_10c,_10d,end){ | |
752 | if(typeof (end)=="undefined"||end===null){ | |
753 | end=lst.length; | |
754 | } | |
755 | if(typeof (_10d)=="undefined"||_10d===null){ | |
756 | _10d=0; | |
757 | } | |
758 | for(var i=_10d;i<end;i++){ | |
759 | if(lst[i]===_10c){ | |
760 | return i; | |
761 | } | |
762 | } | |
763 | return -1; | |
764 | },mean:function(){ | |
765 | var sum=0; | |
766 | var m=MochiKit.Base; | |
767 | var args=m.extend(null,arguments); | |
768 | var _113=args.length; | |
769 | while(args.length){ | |
770 | var o=args.shift(); | |
771 | if(o&&typeof (o)=="object"&&typeof (o.length)=="number"){ | |
772 | _113+=o.length-1; | |
773 | for(var i=o.length-1;i>=0;i--){ | |
774 | sum+=o[i]; | |
775 | } | |
776 | }else{ | |
777 | sum+=o; | |
778 | } | |
779 | } | |
780 | if(_113<=0){ | |
781 | throw new TypeError("mean() requires at least one argument"); | |
782 | } | |
783 | return sum/_113; | |
784 | },median:function(){ | |
785 | var data=MochiKit.Base.flattenArguments(arguments); | |
786 | if(data.length===0){ | |
787 | throw new TypeError("median() requires at least one argument"); | |
788 | } | |
789 | data.sort(compare); | |
790 | if(data.length%2==0){ | |
791 | var _117=data.length/2; | |
792 | return (data[_117]+data[_117-1])/2; | |
793 | }else{ | |
794 | return data[(data.length-1)/2]; | |
795 | } | |
796 | },findValue:function(lst,_119,_11a,end){ | |
797 | if(typeof (end)=="undefined"||end===null){ | |
798 | end=lst.length; | |
799 | } | |
800 | if(typeof (_11a)=="undefined"||_11a===null){ | |
801 | _11a=0; | |
802 | } | |
803 | var cmp=MochiKit.Base.compare; | |
804 | for(var i=_11a;i<end;i++){ | |
805 | if(cmp(lst[i],_119)===0){ | |
806 | return i; | |
807 | } | |
808 | } | |
809 | return -1; | |
810 | },nodeWalk:function(node,_11f){ | |
811 | var _120=[node]; | |
812 | var _121=MochiKit.Base.extend; | |
813 | while(_120.length){ | |
814 | var res=_11f(_120.shift()); | |
815 | if(res){ | |
816 | _121(_120,res); | |
817 | } | |
818 | } | |
819 | },nameFunctions:function(_123){ | |
820 | var base=_123.NAME; | |
821 | if(typeof (base)=="undefined"){ | |
822 | base=""; | |
823 | }else{ | |
824 | base=base+"."; | |
825 | } | |
826 | for(var name in _123){ | |
827 | var o=_123[name]; | |
828 | if(typeof (o)=="function"&&typeof (o.NAME)=="undefined"){ | |
829 | try{ | |
830 | o.NAME=base+name; | |
831 | } | |
832 | catch(e){ | |
833 | } | |
834 | } | |
835 | } | |
836 | },queryString:function(_127,_128){ | |
837 | if(typeof (MochiKit.DOM)!="undefined"&&arguments.length==1&&(typeof (_127)=="string"||(typeof (_127.nodeType)!="undefined"&&_127.nodeType>0))){ | |
838 | var kv=MochiKit.DOM.formContents(_127); | |
839 | _127=kv[0]; | |
840 | _128=kv[1]; | |
841 | }else{ | |
842 | if(arguments.length==1){ | |
843 | if(typeof (_127.length)=="number"&&_127.length==2){ | |
844 | return arguments.callee(_127[0],_127[1]); | |
845 | } | |
846 | var o=_127; | |
847 | _127=[]; | |
848 | _128=[]; | |
849 | for(var k in o){ | |
850 | var v=o[k]; | |
851 | if(typeof (v)=="function"){ | |
852 | continue; | |
853 | }else{ | |
854 | if(typeof (v)!="string"&&typeof (v.length)=="number"){ | |
855 | for(var i=0;i<v.length;i++){ | |
856 | _127.push(k); | |
857 | _128.push(v[i]); | |
858 | } | |
859 | }else{ | |
860 | _127.push(k); | |
861 | _128.push(v); | |
862 | } | |
863 | } | |
864 | } | |
865 | } | |
866 | } | |
867 | var rval=[]; | |
868 | var len=Math.min(_127.length,_128.length); | |
869 | var _130=MochiKit.Base.urlEncode; | |
870 | for(var i=0;i<len;i++){ | |
871 | v=_128[i]; | |
872 | if(typeof (v)!="undefined"&&v!==null){ | |
873 | rval.push(_130(_127[i])+"="+_130(v)); | |
874 | } | |
875 | } | |
876 | return rval.join("&"); | |
877 | },parseQueryString:function(_131,_132){ | |
878 | var qstr=(_131.charAt(0)=="?")?_131.substring(1):_131; | |
879 | var _134=qstr.replace(/\+/g,"%20").split(/(\&\;|\&\#38\;|\&|\&)/); | |
880 | var o={}; | |
881 | var _136; | |
882 | if(typeof (decodeURIComponent)!="undefined"){ | |
883 | _136=decodeURIComponent; | |
884 | }else{ | |
885 | _136=unescape; | |
886 | } | |
887 | if(_132){ | |
888 | for(var i=0;i<_134.length;i++){ | |
889 | var pair=_134[i].split("="); | |
890 | var name=_136(pair.shift()); | |
891 | if(!name){ | |
892 | continue; | |
893 | } | |
894 | var arr=o[name]; | |
895 | if(!(arr instanceof Array)){ | |
896 | arr=[]; | |
897 | o[name]=arr; | |
898 | } | |
899 | arr.push(_136(pair.join("="))); | |
900 | } | |
901 | }else{ | |
902 | for(i=0;i<_134.length;i++){ | |
903 | pair=_134[i].split("="); | |
904 | var name=pair.shift(); | |
905 | if(!name){ | |
906 | continue; | |
907 | } | |
908 | o[_136(name)]=_136(pair.join("=")); | |
909 | } | |
910 | } | |
911 | return o; | |
912 | }}); | |
913 | MochiKit.Base.AdapterRegistry=function(){ | |
914 | this.pairs=[]; | |
915 | }; | |
916 | MochiKit.Base.AdapterRegistry.prototype={register:function(name,_13c,wrap,_13e){ | |
917 | if(_13e){ | |
918 | this.pairs.unshift([name,_13c,wrap]); | |
919 | }else{ | |
920 | this.pairs.push([name,_13c,wrap]); | |
921 | } | |
922 | },match:function(){ | |
923 | for(var i=0;i<this.pairs.length;i++){ | |
924 | var pair=this.pairs[i]; | |
925 | if(pair[1].apply(this,arguments)){ | |
926 | return pair[2].apply(this,arguments); | |
927 | } | |
928 | } | |
929 | throw MochiKit.Base.NotFound; | |
930 | },unregister:function(name){ | |
931 | for(var i=0;i<this.pairs.length;i++){ | |
932 | var pair=this.pairs[i]; | |
933 | if(pair[0]==name){ | |
934 | this.pairs.splice(i,1); | |
935 | return true; | |
936 | } | |
937 | } | |
938 | return false; | |
939 | }}; | |
940 | MochiKit.Base.EXPORT=["flattenArray","noop","camelize","counter","clone","extend","update","updatetree","setdefault","keys","values","items","NamedError","operator","forwardCall","itemgetter","typeMatcher","isCallable","isUndefined","isUndefinedOrNull","isNull","isEmpty","isNotEmpty","isArrayLike","isDateLike","xmap","map","xfilter","filter","methodcaller","compose","bind","bindMethods","NotFound","AdapterRegistry","registerComparator","compare","registerRepr","repr","objEqual","arrayEqual","concat","keyComparator","reverseKeyComparator","partial","merge","listMinMax","listMax","listMin","objMax","objMin","nodeWalk","zip","urlEncode","queryString","serializeJSON","registerJSON","evalJSON","parseQueryString","findValue","findIdentical","flattenArguments","method","average","mean","median"]; | |
941 | MochiKit.Base.EXPORT_OK=["nameFunctions","comparatorRegistry","reprRegistry","jsonRegistry","compareDateLike","compareArrayLike","reprArrayLike","reprString","reprNumber"]; | |
942 | MochiKit.Base._exportSymbols=function(_144,_145){ | |
943 | if(!MochiKit.__export__){ | |
944 | return; | |
945 | } | |
946 | var all=_145.EXPORT_TAGS[":all"]; | |
947 | for(var i=0;i<all.length;i++){ | |
948 | _144[all[i]]=_145[all[i]]; | |
949 | } | |
950 | }; | |
951 | MochiKit.Base.__new__=function(){ | |
952 | var m=this; | |
953 | m.noop=m.operator.identity; | |
954 | m.forward=m.forwardCall; | |
955 | m.find=m.findValue; | |
956 | if(typeof (encodeURIComponent)!="undefined"){ | |
957 | m.urlEncode=function(_149){ | |
958 | return encodeURIComponent(_149).replace(/\'/g,"%27"); | |
959 | }; | |
960 | }else{ | |
961 | m.urlEncode=function(_14a){ | |
962 | return escape(_14a).replace(/\+/g,"%2B").replace(/\"/g,"%22").rval.replace(/\'/g,"%27"); | |
963 | }; | |
964 | } | |
965 | m.NamedError=function(name){ | |
966 | this.message=name; | |
967 | this.name=name; | |
968 | }; | |
969 | m.NamedError.prototype=new Error(); | |
970 | m.update(m.NamedError.prototype,{repr:function(){ | |
971 | if(this.message&&this.message!=this.name){ | |
972 | return this.name+"("+m.repr(this.message)+")"; | |
973 | }else{ | |
974 | return this.name+"()"; | |
975 | } | |
976 | },toString:m.forwardCall("repr")}); | |
977 | m.NotFound=new m.NamedError("MochiKit.Base.NotFound"); | |
978 | m.listMax=m.partial(m.listMinMax,1); | |
979 | m.listMin=m.partial(m.listMinMax,-1); | |
980 | m.isCallable=m.typeMatcher("function"); | |
981 | m.isUndefined=m.typeMatcher("undefined"); | |
982 | m.merge=m.partial(m.update,null); | |
983 | m.zip=m.partial(m.map,null); | |
984 | m.average=m.mean; | |
985 | m.comparatorRegistry=new m.AdapterRegistry(); | |
986 | m.registerComparator("dateLike",m.isDateLike,m.compareDateLike); | |
987 | m.registerComparator("arrayLike",m.isArrayLike,m.compareArrayLike); | |
988 | m.reprRegistry=new m.AdapterRegistry(); | |
989 | m.registerRepr("arrayLike",m.isArrayLike,m.reprArrayLike); | |
990 | m.registerRepr("string",m.typeMatcher("string"),m.reprString); | |
991 | m.registerRepr("numbers",m.typeMatcher("number","boolean"),m.reprNumber); | |
992 | m.jsonRegistry=new m.AdapterRegistry(); | |
993 | var all=m.concat(m.EXPORT,m.EXPORT_OK); | |
994 | m.EXPORT_TAGS={":common":m.concat(m.EXPORT_OK),":all":all}; | |
995 | m.nameFunctions(this); | |
996 | }; | |
997 | MochiKit.Base.__new__(); | |
998 | if(MochiKit.__export__){ | |
999 | compare=MochiKit.Base.compare; | |
1000 | compose=MochiKit.Base.compose; | |
1001 | serializeJSON=MochiKit.Base.serializeJSON; | |
1002 | } | |
1003 | MochiKit.Base._exportSymbols(this,MochiKit.Base); | |
1004 | if(typeof (dojo)!="undefined"){ | |
165759fa DV |
1005 | dojo.provide("MochiKit.Iter"); |
1006 | dojo.require("MochiKit.Base"); | |
1007 | } | |
1008 | if(typeof (JSAN)!="undefined"){ | |
1009 | JSAN.use("MochiKit.Base",[]); | |
1010 | } | |
1011 | try{ | |
1012 | if(typeof (MochiKit.Base)=="undefined"){ | |
1013 | throw ""; | |
1014 | } | |
1015 | } | |
1016 | catch(e){ | |
1017 | throw "MochiKit.Iter depends on MochiKit.Base!"; | |
1018 | } | |
1019 | if(typeof (MochiKit.Iter)=="undefined"){ | |
1020 | MochiKit.Iter={}; | |
1021 | } | |
1022 | MochiKit.Iter.NAME="MochiKit.Iter"; | |
1023 | MochiKit.Iter.VERSION="1.4"; | |
1024 | MochiKit.Base.update(MochiKit.Iter,{__repr__:function(){ | |
1025 | return "["+this.NAME+" "+this.VERSION+"]"; | |
1026 | },toString:function(){ | |
1027 | return this.__repr__(); | |
1028 | },registerIteratorFactory:function(name,_14e,_14f,_150){ | |
1029 | MochiKit.Iter.iteratorRegistry.register(name,_14e,_14f,_150); | |
1030 | },iter:function(_151,_152){ | |
1031 | var self=MochiKit.Iter; | |
1032 | if(arguments.length==2){ | |
1033 | return self.takewhile(function(a){ | |
1034 | return a!=_152; | |
1035 | },_151); | |
1036 | } | |
1037 | if(typeof (_151.next)=="function"){ | |
1038 | return _151; | |
1039 | }else{ | |
1040 | if(typeof (_151.iter)=="function"){ | |
1041 | return _151.iter(); | |
1042 | } | |
1043 | } | |
1044 | try{ | |
1045 | return self.iteratorRegistry.match(_151); | |
1046 | } | |
1047 | catch(e){ | |
1048 | var m=MochiKit.Base; | |
1049 | if(e==m.NotFound){ | |
1050 | e=new TypeError(typeof (_151)+": "+m.repr(_151)+" is not iterable"); | |
1051 | } | |
1052 | throw e; | |
1053 | } | |
1054 | },count:function(n){ | |
1055 | if(!n){ | |
1056 | n=0; | |
1057 | } | |
1058 | var m=MochiKit.Base; | |
1059 | return {repr:function(){ | |
1060 | return "count("+n+")"; | |
1061 | },toString:m.forwardCall("repr"),next:m.counter(n)}; | |
1062 | },cycle:function(p){ | |
1063 | var self=MochiKit.Iter; | |
1064 | var m=MochiKit.Base; | |
1065 | var lst=[]; | |
1066 | var _15c=self.iter(p); | |
1067 | return {repr:function(){ | |
1068 | return "cycle(...)"; | |
1069 | },toString:m.forwardCall("repr"),next:function(){ | |
1070 | try{ | |
1071 | var rval=_15c.next(); | |
1072 | lst.push(rval); | |
1073 | return rval; | |
1074 | } | |
1075 | catch(e){ | |
1076 | if(e!=self.StopIteration){ | |
1077 | throw e; | |
1078 | } | |
1079 | if(lst.length===0){ | |
1080 | this.next=function(){ | |
1081 | throw self.StopIteration; | |
1082 | }; | |
1083 | }else{ | |
1084 | var i=-1; | |
1085 | this.next=function(){ | |
1086 | i=(i+1)%lst.length; | |
1087 | return lst[i]; | |
1088 | }; | |
1089 | } | |
1090 | return this.next(); | |
1091 | } | |
1092 | }}; | |
1093 | },repeat:function(elem,n){ | |
1094 | var m=MochiKit.Base; | |
1095 | if(typeof (n)=="undefined"){ | |
1096 | return {repr:function(){ | |
1097 | return "repeat("+m.repr(elem)+")"; | |
1098 | },toString:m.forwardCall("repr"),next:function(){ | |
1099 | return elem; | |
1100 | }}; | |
1101 | } | |
1102 | return {repr:function(){ | |
1103 | return "repeat("+m.repr(elem)+", "+n+")"; | |
1104 | },toString:m.forwardCall("repr"),next:function(){ | |
1105 | if(n<=0){ | |
1106 | throw MochiKit.Iter.StopIteration; | |
1107 | } | |
1108 | n-=1; | |
1109 | return elem; | |
1110 | }}; | |
1111 | },next:function(_162){ | |
1112 | return _162.next(); | |
1113 | },izip:function(p,q){ | |
1114 | var m=MochiKit.Base; | |
1115 | var self=MochiKit.Iter; | |
1116 | var next=self.next; | |
1117 | var _168=m.map(self.iter,arguments); | |
1118 | return {repr:function(){ | |
1119 | return "izip(...)"; | |
1120 | },toString:m.forwardCall("repr"),next:function(){ | |
1121 | return m.map(next,_168); | |
1122 | }}; | |
1123 | },ifilter:function(pred,seq){ | |
1124 | var m=MochiKit.Base; | |
1125 | seq=MochiKit.Iter.iter(seq); | |
1126 | if(pred===null){ | |
1127 | pred=m.operator.truth; | |
1128 | } | |
1129 | return {repr:function(){ | |
1130 | return "ifilter(...)"; | |
1131 | },toString:m.forwardCall("repr"),next:function(){ | |
1132 | while(true){ | |
1133 | var rval=seq.next(); | |
1134 | if(pred(rval)){ | |
1135 | return rval; | |
1136 | } | |
1137 | } | |
1138 | return undefined; | |
1139 | }}; | |
1140 | },ifilterfalse:function(pred,seq){ | |
1141 | var m=MochiKit.Base; | |
1142 | seq=MochiKit.Iter.iter(seq); | |
1143 | if(pred===null){ | |
1144 | pred=m.operator.truth; | |
1145 | } | |
1146 | return {repr:function(){ | |
1147 | return "ifilterfalse(...)"; | |
1148 | },toString:m.forwardCall("repr"),next:function(){ | |
1149 | while(true){ | |
1150 | var rval=seq.next(); | |
1151 | if(!pred(rval)){ | |
1152 | return rval; | |
1153 | } | |
1154 | } | |
1155 | return undefined; | |
1156 | }}; | |
1157 | },islice:function(seq){ | |
1158 | var self=MochiKit.Iter; | |
1159 | var m=MochiKit.Base; | |
1160 | seq=self.iter(seq); | |
1161 | var _174=0; | |
1162 | var stop=0; | |
1163 | var step=1; | |
1164 | var i=-1; | |
1165 | if(arguments.length==2){ | |
1166 | stop=arguments[1]; | |
1167 | }else{ | |
1168 | if(arguments.length==3){ | |
1169 | _174=arguments[1]; | |
1170 | stop=arguments[2]; | |
1171 | }else{ | |
1172 | _174=arguments[1]; | |
1173 | stop=arguments[2]; | |
1174 | step=arguments[3]; | |
1175 | } | |
1176 | } | |
1177 | return {repr:function(){ | |
1178 | return "islice("+["...",_174,stop,step].join(", ")+")"; | |
1179 | },toString:m.forwardCall("repr"),next:function(){ | |
1180 | var rval; | |
1181 | while(i<_174){ | |
1182 | rval=seq.next(); | |
1183 | i++; | |
1184 | } | |
1185 | if(_174>=stop){ | |
1186 | throw self.StopIteration; | |
1187 | } | |
1188 | _174+=step; | |
1189 | return rval; | |
1190 | }}; | |
1191 | },imap:function(fun,p,q){ | |
1192 | var m=MochiKit.Base; | |
1193 | var self=MochiKit.Iter; | |
1194 | var _17e=m.map(self.iter,m.extend(null,arguments,1)); | |
1195 | var map=m.map; | |
1196 | var next=self.next; | |
1197 | return {repr:function(){ | |
1198 | return "imap(...)"; | |
1199 | },toString:m.forwardCall("repr"),next:function(){ | |
1200 | return fun.apply(this,map(next,_17e)); | |
1201 | }}; | |
1202 | },applymap:function(fun,seq,self){ | |
1203 | seq=MochiKit.Iter.iter(seq); | |
1204 | var m=MochiKit.Base; | |
1205 | return {repr:function(){ | |
1206 | return "applymap(...)"; | |
1207 | },toString:m.forwardCall("repr"),next:function(){ | |
1208 | return fun.apply(self,seq.next()); | |
1209 | }}; | |
1210 | },chain:function(p,q){ | |
1211 | var self=MochiKit.Iter; | |
1212 | var m=MochiKit.Base; | |
1213 | if(arguments.length==1){ | |
1214 | return self.iter(arguments[0]); | |
1215 | } | |
1216 | var _189=m.map(self.iter,arguments); | |
1217 | return {repr:function(){ | |
1218 | return "chain(...)"; | |
1219 | },toString:m.forwardCall("repr"),next:function(){ | |
1220 | while(_189.length>1){ | |
1221 | try{ | |
1222 | return _189[0].next(); | |
1223 | } | |
1224 | catch(e){ | |
1225 | if(e!=self.StopIteration){ | |
1226 | throw e; | |
1227 | } | |
1228 | _189.shift(); | |
1229 | } | |
1230 | } | |
1231 | if(_189.length==1){ | |
1232 | var arg=_189.shift(); | |
1233 | this.next=m.bind("next",arg); | |
1234 | return this.next(); | |
1235 | } | |
1236 | throw self.StopIteration; | |
1237 | }}; | |
1238 | },takewhile:function(pred,seq){ | |
1239 | var self=MochiKit.Iter; | |
1240 | seq=self.iter(seq); | |
1241 | return {repr:function(){ | |
1242 | return "takewhile(...)"; | |
1243 | },toString:MochiKit.Base.forwardCall("repr"),next:function(){ | |
1244 | var rval=seq.next(); | |
1245 | if(!pred(rval)){ | |
1246 | this.next=function(){ | |
1247 | throw self.StopIteration; | |
1248 | }; | |
1249 | this.next(); | |
1250 | } | |
1251 | return rval; | |
1252 | }}; | |
1253 | },dropwhile:function(pred,seq){ | |
1254 | seq=MochiKit.Iter.iter(seq); | |
1255 | var m=MochiKit.Base; | |
1256 | var bind=m.bind; | |
1257 | return {"repr":function(){ | |
1258 | return "dropwhile(...)"; | |
1259 | },"toString":m.forwardCall("repr"),"next":function(){ | |
1260 | while(true){ | |
1261 | var rval=seq.next(); | |
1262 | if(!pred(rval)){ | |
1263 | break; | |
1264 | } | |
1265 | } | |
1266 | this.next=bind("next",seq); | |
1267 | return rval; | |
1268 | }}; | |
1269 | },_tee:function(_194,sync,_196){ | |
1270 | sync.pos[_194]=-1; | |
1271 | var m=MochiKit.Base; | |
1272 | var _198=m.listMin; | |
1273 | return {repr:function(){ | |
1274 | return "tee("+_194+", ...)"; | |
1275 | },toString:m.forwardCall("repr"),next:function(){ | |
1276 | var rval; | |
1277 | var i=sync.pos[_194]; | |
1278 | if(i==sync.max){ | |
1279 | rval=_196.next(); | |
1280 | sync.deque.push(rval); | |
1281 | sync.max+=1; | |
1282 | sync.pos[_194]+=1; | |
1283 | }else{ | |
1284 | rval=sync.deque[i-sync.min]; | |
1285 | sync.pos[_194]+=1; | |
1286 | if(i==sync.min&&_198(sync.pos)!=sync.min){ | |
1287 | sync.min+=1; | |
1288 | sync.deque.shift(); | |
1289 | } | |
1290 | } | |
1291 | return rval; | |
1292 | }}; | |
1293 | },tee:function(_19b,n){ | |
1294 | var rval=[]; | |
1295 | var sync={"pos":[],"deque":[],"max":-1,"min":-1}; | |
1296 | if(arguments.length==1||typeof (n)=="undefined"||n===null){ | |
1297 | n=2; | |
1298 | } | |
1299 | var self=MochiKit.Iter; | |
1300 | _19b=self.iter(_19b); | |
1301 | var _tee=self._tee; | |
1302 | for(var i=0;i<n;i++){ | |
1303 | rval.push(_tee(i,sync,_19b)); | |
1304 | } | |
1305 | return rval; | |
1306 | },list:function(_1a2){ | |
1307 | var rval; | |
1308 | if(_1a2 instanceof Array){ | |
1309 | return _1a2.slice(); | |
1310 | } | |
1311 | if(typeof (_1a2)=="function"&&!(_1a2 instanceof Function)&&typeof (_1a2.length)=="number"){ | |
1312 | rval=[]; | |
1313 | for(var i=0;i<_1a2.length;i++){ | |
1314 | rval.push(_1a2[i]); | |
1315 | } | |
1316 | return rval; | |
1317 | } | |
1318 | var self=MochiKit.Iter; | |
1319 | _1a2=self.iter(_1a2); | |
1320 | var rval=[]; | |
1321 | try{ | |
1322 | while(true){ | |
1323 | rval.push(_1a2.next()); | |
1324 | } | |
1325 | } | |
1326 | catch(e){ | |
1327 | if(e!=self.StopIteration){ | |
1328 | throw e; | |
1329 | } | |
1330 | return rval; | |
1331 | } | |
1332 | return undefined; | |
1333 | },reduce:function(fn,_1a7,_1a8){ | |
1334 | var i=0; | |
1335 | var x=_1a8; | |
1336 | var self=MochiKit.Iter; | |
1337 | _1a7=self.iter(_1a7); | |
1338 | if(arguments.length<3){ | |
1339 | try{ | |
1340 | x=_1a7.next(); | |
1341 | } | |
1342 | catch(e){ | |
1343 | if(e==self.StopIteration){ | |
1344 | e=new TypeError("reduce() of empty sequence with no initial value"); | |
1345 | } | |
1346 | throw e; | |
1347 | } | |
1348 | i++; | |
1349 | } | |
1350 | try{ | |
1351 | while(true){ | |
1352 | x=fn(x,_1a7.next()); | |
1353 | } | |
1354 | } | |
1355 | catch(e){ | |
1356 | if(e!=self.StopIteration){ | |
1357 | throw e; | |
1358 | } | |
1359 | } | |
1360 | return x; | |
1361 | },range:function(){ | |
1362 | var _1ac=0; | |
1363 | var stop=0; | |
1364 | var step=1; | |
1365 | if(arguments.length==1){ | |
1366 | stop=arguments[0]; | |
1367 | }else{ | |
1368 | if(arguments.length==2){ | |
1369 | _1ac=arguments[0]; | |
1370 | stop=arguments[1]; | |
1371 | }else{ | |
1372 | if(arguments.length==3){ | |
1373 | _1ac=arguments[0]; | |
1374 | stop=arguments[1]; | |
1375 | step=arguments[2]; | |
1376 | }else{ | |
1377 | throw new TypeError("range() takes 1, 2, or 3 arguments!"); | |
1378 | } | |
1379 | } | |
1380 | } | |
1381 | if(step===0){ | |
1382 | throw new TypeError("range() step must not be 0"); | |
1383 | } | |
1384 | return {next:function(){ | |
1385 | if((step>0&&_1ac>=stop)||(step<0&&_1ac<=stop)){ | |
1386 | throw MochiKit.Iter.StopIteration; | |
1387 | } | |
1388 | var rval=_1ac; | |
1389 | _1ac+=step; | |
1390 | return rval; | |
1391 | },repr:function(){ | |
1392 | return "range("+[_1ac,stop,step].join(", ")+")"; | |
1393 | },toString:MochiKit.Base.forwardCall("repr")}; | |
1394 | },sum:function(_1b0,_1b1){ | |
1395 | if(typeof (_1b1)=="undefined"||_1b1===null){ | |
1396 | _1b1=0; | |
1397 | } | |
1398 | var x=_1b1; | |
1399 | var self=MochiKit.Iter; | |
1400 | _1b0=self.iter(_1b0); | |
1401 | try{ | |
1402 | while(true){ | |
1403 | x+=_1b0.next(); | |
1404 | } | |
1405 | } | |
1406 | catch(e){ | |
1407 | if(e!=self.StopIteration){ | |
1408 | throw e; | |
1409 | } | |
1410 | } | |
1411 | return x; | |
1412 | },exhaust:function(_1b4){ | |
1413 | var self=MochiKit.Iter; | |
1414 | _1b4=self.iter(_1b4); | |
1415 | try{ | |
1416 | while(true){ | |
1417 | _1b4.next(); | |
1418 | } | |
1419 | } | |
1420 | catch(e){ | |
1421 | if(e!=self.StopIteration){ | |
1422 | throw e; | |
1423 | } | |
1424 | } | |
1425 | },forEach:function(_1b6,func,self){ | |
1426 | var m=MochiKit.Base; | |
1427 | if(arguments.length>2){ | |
1428 | func=m.bind(func,self); | |
1429 | } | |
1430 | if(m.isArrayLike(_1b6)){ | |
1431 | try{ | |
1432 | for(var i=0;i<_1b6.length;i++){ | |
1433 | func(_1b6[i]); | |
1434 | } | |
1435 | } | |
1436 | catch(e){ | |
1437 | if(e!=MochiKit.Iter.StopIteration){ | |
1438 | throw e; | |
1439 | } | |
1440 | } | |
1441 | }else{ | |
1442 | self=MochiKit.Iter; | |
1443 | self.exhaust(self.imap(func,_1b6)); | |
1444 | } | |
1445 | },every:function(_1bb,func){ | |
1446 | var self=MochiKit.Iter; | |
1447 | try{ | |
1448 | self.ifilterfalse(func,_1bb).next(); | |
1449 | return false; | |
1450 | } | |
1451 | catch(e){ | |
1452 | if(e!=self.StopIteration){ | |
1453 | throw e; | |
1454 | } | |
1455 | return true; | |
1456 | } | |
1457 | },sorted:function(_1be,cmp){ | |
1458 | var rval=MochiKit.Iter.list(_1be); | |
1459 | if(arguments.length==1){ | |
1460 | cmp=MochiKit.Base.compare; | |
1461 | } | |
1462 | rval.sort(cmp); | |
1463 | return rval; | |
1464 | },reversed:function(_1c1){ | |
1465 | var rval=MochiKit.Iter.list(_1c1); | |
1466 | rval.reverse(); | |
1467 | return rval; | |
1468 | },some:function(_1c3,func){ | |
1469 | var self=MochiKit.Iter; | |
1470 | try{ | |
1471 | self.ifilter(func,_1c3).next(); | |
1472 | return true; | |
1473 | } | |
1474 | catch(e){ | |
1475 | if(e!=self.StopIteration){ | |
1476 | throw e; | |
1477 | } | |
1478 | return false; | |
1479 | } | |
1480 | },iextend:function(lst,_1c7){ | |
1481 | if(MochiKit.Base.isArrayLike(_1c7)){ | |
1482 | for(var i=0;i<_1c7.length;i++){ | |
1483 | lst.push(_1c7[i]); | |
1484 | } | |
1485 | }else{ | |
1486 | var self=MochiKit.Iter; | |
1487 | _1c7=self.iter(_1c7); | |
1488 | try{ | |
1489 | while(true){ | |
1490 | lst.push(_1c7.next()); | |
1491 | } | |
1492 | } | |
1493 | catch(e){ | |
1494 | if(e!=self.StopIteration){ | |
1495 | throw e; | |
1496 | } | |
1497 | } | |
1498 | } | |
1499 | return lst; | |
1500 | },groupby:function(_1ca,_1cb){ | |
1501 | var m=MochiKit.Base; | |
1502 | var self=MochiKit.Iter; | |
1503 | if(arguments.length<2){ | |
1504 | _1cb=m.operator.identity; | |
1505 | } | |
1506 | _1ca=self.iter(_1ca); | |
1507 | var pk=undefined; | |
1508 | var k=undefined; | |
1509 | var v; | |
1510 | function fetch(){ | |
1511 | v=_1ca.next(); | |
1512 | k=_1cb(v); | |
1513 | } | |
1514 | function eat(){ | |
1515 | var ret=v; | |
1516 | v=undefined; | |
1517 | return ret; | |
1518 | } | |
1519 | var _1d2=true; | |
1520 | var _1d3=m.compare; | |
1521 | return {repr:function(){ | |
1522 | return "groupby(...)"; | |
1523 | },next:function(){ | |
1524 | while(_1d3(k,pk)===0){ | |
1525 | fetch(); | |
1526 | if(_1d2){ | |
1527 | _1d2=false; | |
1528 | break; | |
1529 | } | |
1530 | } | |
1531 | pk=k; | |
1532 | return [k,{next:function(){ | |
1533 | if(v==undefined){ | |
1534 | fetch(); | |
1535 | } | |
1536 | if(_1d3(k,pk)!==0){ | |
1537 | throw self.StopIteration; | |
1538 | } | |
1539 | return eat(); | |
1540 | }}]; | |
1541 | }}; | |
1542 | },groupby_as_array:function(_1d4,_1d5){ | |
1543 | var m=MochiKit.Base; | |
1544 | var self=MochiKit.Iter; | |
1545 | if(arguments.length<2){ | |
1546 | _1d5=m.operator.identity; | |
1547 | } | |
1548 | _1d4=self.iter(_1d4); | |
1549 | var _1d8=[]; | |
1550 | var _1d9=true; | |
1551 | var _1da; | |
1552 | var _1db=m.compare; | |
1553 | while(true){ | |
1554 | try{ | |
1555 | var _1dc=_1d4.next(); | |
1556 | var key=_1d5(_1dc); | |
1557 | } | |
1558 | catch(e){ | |
1559 | if(e==self.StopIteration){ | |
1560 | break; | |
1561 | } | |
1562 | throw e; | |
1563 | } | |
1564 | if(_1d9||_1db(key,_1da)!==0){ | |
1565 | var _1de=[]; | |
1566 | _1d8.push([key,_1de]); | |
1567 | } | |
1568 | _1de.push(_1dc); | |
1569 | _1d9=false; | |
1570 | _1da=key; | |
1571 | } | |
1572 | return _1d8; | |
1573 | },arrayLikeIter:function(_1df){ | |
1574 | var i=0; | |
1575 | return {repr:function(){ | |
1576 | return "arrayLikeIter(...)"; | |
1577 | },toString:MochiKit.Base.forwardCall("repr"),next:function(){ | |
1578 | if(i>=_1df.length){ | |
1579 | throw MochiKit.Iter.StopIteration; | |
1580 | } | |
1581 | return _1df[i++]; | |
1582 | }}; | |
1583 | },hasIterateNext:function(_1e1){ | |
1584 | return (_1e1&&typeof (_1e1.iterateNext)=="function"); | |
1585 | },iterateNextIter:function(_1e2){ | |
1586 | return {repr:function(){ | |
1587 | return "iterateNextIter(...)"; | |
1588 | },toString:MochiKit.Base.forwardCall("repr"),next:function(){ | |
1589 | var rval=_1e2.iterateNext(); | |
1590 | if(rval===null||rval===undefined){ | |
1591 | throw MochiKit.Iter.StopIteration; | |
1592 | } | |
1593 | return rval; | |
1594 | }}; | |
1595 | }}); | |
285a6bda | 1596 | MochiKit.Iter.EXPORT_OK=["iteratorRegistry","arrayLikeIter","hasIterateNext","iterateNextIter"]; |
165759fa DV |
1597 | MochiKit.Iter.EXPORT=["StopIteration","registerIteratorFactory","iter","count","cycle","repeat","next","izip","ifilter","ifilterfalse","islice","imap","applymap","chain","takewhile","dropwhile","tee","list","reduce","range","sum","exhaust","forEach","every","sorted","reversed","some","iextend","groupby","groupby_as_array"]; |
1598 | MochiKit.Iter.__new__=function(){ | |
1599 | var m=MochiKit.Base; | |
1600 | if(typeof (StopIteration)!="undefined"){ | |
1601 | this.StopIteration=StopIteration; | |
1602 | }else{ | |
1603 | this.StopIteration=new m.NamedError("StopIteration"); | |
1604 | } | |
1605 | this.iteratorRegistry=new m.AdapterRegistry(); | |
1606 | this.registerIteratorFactory("arrayLike",m.isArrayLike,this.arrayLikeIter); | |
1607 | this.registerIteratorFactory("iterateNext",this.hasIterateNext,this.iterateNextIter); | |
1608 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
1609 | m.nameFunctions(this); | |
1610 | }; | |
1611 | MochiKit.Iter.__new__(); | |
1612 | if(MochiKit.__export__){ | |
1613 | reduce=MochiKit.Iter.reduce; | |
1614 | } | |
1615 | MochiKit.Base._exportSymbols(this,MochiKit.Iter); | |
1616 | if(typeof (dojo)!="undefined"){ | |
79f17b42 DV |
1617 | dojo.provide("MochiKit.DOM"); |
1618 | dojo.require("MochiKit.Base"); | |
6a1aa64f | 1619 | } |
79f17b42 DV |
1620 | if(typeof (JSAN)!="undefined"){ |
1621 | JSAN.use("MochiKit.Base",[]); | |
6a1aa64f | 1622 | } |
6a1aa64f | 1623 | try{ |
79f17b42 DV |
1624 | if(typeof (MochiKit.Base)=="undefined"){ |
1625 | throw ""; | |
6a1aa64f DV |
1626 | } |
1627 | } | |
1628 | catch(e){ | |
79f17b42 | 1629 | throw "MochiKit.DOM depends on MochiKit.Base!"; |
6a1aa64f | 1630 | } |
79f17b42 DV |
1631 | if(typeof (MochiKit.DOM)=="undefined"){ |
1632 | MochiKit.DOM={}; | |
6a1aa64f | 1633 | } |
79f17b42 DV |
1634 | MochiKit.DOM.NAME="MochiKit.DOM"; |
1635 | MochiKit.DOM.VERSION="1.4"; | |
1636 | MochiKit.DOM.__repr__=function(){ | |
1637 | return "["+this.NAME+" "+this.VERSION+"]"; | |
1638 | }; | |
1639 | MochiKit.DOM.toString=function(){ | |
1640 | return this.__repr__(); | |
1641 | }; | |
1642 | MochiKit.DOM.EXPORT=["removeEmptyTextNodes","formContents","currentWindow","currentDocument","withWindow","withDocument","registerDOMConverter","coerceToDOM","createDOM","createDOMFunc","isChildNode","getNodeAttribute","removeNodeAttribute","setNodeAttribute","updateNodeAttributes","appendChildNodes","insertSiblingNodesAfter","insertSiblingNodesBefore","replaceChildNodes","removeElement","swapDOM","BUTTON","TT","PRE","H1","H2","H3","BR","CANVAS","HR","LABEL","TEXTAREA","FORM","STRONG","SELECT","OPTION","OPTGROUP","LEGEND","FIELDSET","P","UL","OL","LI","TD","TR","THEAD","TBODY","TFOOT","TABLE","TH","INPUT","SPAN","A","DIV","IMG","getElement","$","getElementsByTagAndClassName","addToCallStack","addLoadEvent","focusOnLoad","setElementClass","toggleElementClass","addElementClass","removeElementClass","swapElementClass","hasElementClass","escapeHTML","toHTML","emitHTML","scrapeText","isParent","getFirstParentByTagAndClassName","makeClipping","undoClipping","makePositioned","undoPositioned","getFirstElementByTagAndClassName"]; | |
1643 | MochiKit.DOM.EXPORT_OK=["domConverters"]; | |
1644 | MochiKit.DOM.DEPRECATED=[["computedStyle","MochiKit.Style.getStyle","1.4"],["elementDimensions","MochiKit.Style.getElementDimensions","1.4"],["elementPosition","MochiKit.Style.getElementPosition","1.4"],["hideElement","MochiKit.Style.hideElement","1.4"],["setElementDimensions","MochiKit.Style.setElementDimensions","1.4"],["setElementPosition","MochiKit.Style.setElementPosition","1.4"],["setDisplayForElement","MochiKit.Style.setDisplayForElement","1.4"],["setOpacity","MochiKit.Style.setOpacity","1.4"],["showElement","MochiKit.Style.showElement","1.4"],["Coordinates","MochiKit.Style.Coordinates","1.4"],["Dimensions","MochiKit.Style.Dimensions","1.4"]]; | |
1645 | MochiKit.DOM.getViewportDimensions=new Function(""+"if (!MochiKit[\"Style\"]) {"+" throw new Error(\"This function has been deprecated and depends on MochiKit.Style.\");"+"}"+"return MochiKit.Style.getViewportDimensions.apply(this, arguments);"); | |
1646 | MochiKit.Base.update(MochiKit.DOM,{currentWindow:function(){ | |
1647 | return MochiKit.DOM._window; | |
1648 | },currentDocument:function(){ | |
1649 | return MochiKit.DOM._document; | |
1650 | },withWindow:function(win,func){ | |
1651 | var self=MochiKit.DOM; | |
223ddf66 DV |
1652 | var _1e8=self._document; |
1653 | var _1e9=self._window; | |
79f17b42 | 1654 | var rval; |
6a1aa64f | 1655 | try{ |
79f17b42 DV |
1656 | self._window=win; |
1657 | self._document=win.document; | |
1658 | rval=func(); | |
6a1aa64f DV |
1659 | } |
1660 | catch(e){ | |
223ddf66 DV |
1661 | self._window=_1e9; |
1662 | self._document=_1e8; | |
6a1aa64f DV |
1663 | throw e; |
1664 | } | |
223ddf66 DV |
1665 | self._window=_1e9; |
1666 | self._document=_1e8; | |
79f17b42 DV |
1667 | return rval; |
1668 | },formContents:function(elem){ | |
223ddf66 DV |
1669 | var _1ec=[]; |
1670 | var _1ed=[]; | |
6a1aa64f | 1671 | var m=MochiKit.Base; |
79f17b42 DV |
1672 | var self=MochiKit.DOM; |
1673 | if(typeof (elem)=="undefined"||elem===null){ | |
1674 | elem=self._document.body; | |
1675 | }else{ | |
1676 | elem=self.getElement(elem); | |
6a1aa64f | 1677 | } |
79f17b42 DV |
1678 | m.nodeWalk(elem,function(elem){ |
1679 | var name=elem.name; | |
1680 | if(m.isNotEmpty(name)){ | |
223ddf66 DV |
1681 | var _1f2=elem.tagName.toUpperCase(); |
1682 | if(_1f2==="INPUT"&&(elem.type=="radio"||elem.type=="checkbox")&&!elem.checked){ | |
79f17b42 | 1683 | return null; |
6a1aa64f | 1684 | } |
223ddf66 | 1685 | if(_1f2==="SELECT"){ |
79f17b42 DV |
1686 | if(elem.type=="select-one"){ |
1687 | if(elem.selectedIndex>=0){ | |
1688 | var opt=elem.options[elem.selectedIndex]; | |
1689 | var v=opt.value; | |
1690 | if(!v){ | |
1691 | var h=opt.outerHTML; | |
1692 | if(h&&!h.match(/^[^>]+\svalue\s*=/i)){ | |
1693 | v=opt.text; | |
6a1aa64f | 1694 | } |
6a1aa64f | 1695 | } |
223ddf66 DV |
1696 | _1ec.push(name); |
1697 | _1ed.push(v); | |
79f17b42 | 1698 | return null; |
6a1aa64f | 1699 | } |
223ddf66 DV |
1700 | _1ec.push(name); |
1701 | _1ed.push(""); | |
79f17b42 | 1702 | return null; |
6a1aa64f | 1703 | }else{ |
79f17b42 DV |
1704 | var opts=elem.options; |
1705 | if(!opts.length){ | |
223ddf66 DV |
1706 | _1ec.push(name); |
1707 | _1ed.push(""); | |
79f17b42 | 1708 | return null; |
6a1aa64f | 1709 | } |
79f17b42 DV |
1710 | for(var i=0;i<opts.length;i++){ |
1711 | var opt=opts[i]; | |
1712 | if(!opt.selected){ | |
1713 | continue; | |
6a1aa64f | 1714 | } |
79f17b42 DV |
1715 | var v=opt.value; |
1716 | if(!v){ | |
1717 | var h=opt.outerHTML; | |
1718 | if(h&&!h.match(/^[^>]+\svalue\s*=/i)){ | |
1719 | v=opt.text; | |
6a1aa64f | 1720 | } |
6a1aa64f | 1721 | } |
223ddf66 DV |
1722 | _1ec.push(name); |
1723 | _1ed.push(v); | |
6a1aa64f | 1724 | } |
79f17b42 | 1725 | return null; |
6a1aa64f | 1726 | } |
6a1aa64f | 1727 | } |
223ddf66 | 1728 | if(_1f2==="FORM"||_1f2==="P"||_1f2==="SPAN"||_1f2==="DIV"){ |
79f17b42 | 1729 | return elem.childNodes; |
6a1aa64f | 1730 | } |
223ddf66 DV |
1731 | _1ec.push(name); |
1732 | _1ed.push(elem.value||""); | |
79f17b42 | 1733 | return null; |
6a1aa64f | 1734 | } |
79f17b42 DV |
1735 | return elem.childNodes; |
1736 | }); | |
223ddf66 | 1737 | return [_1ec,_1ed]; |
79f17b42 DV |
1738 | },withDocument:function(doc,func){ |
1739 | var self=MochiKit.DOM; | |
223ddf66 | 1740 | var _1fb=self._document; |
79f17b42 | 1741 | var rval; |
6a1aa64f | 1742 | try{ |
79f17b42 DV |
1743 | self._document=doc; |
1744 | rval=func(); | |
6a1aa64f DV |
1745 | } |
1746 | catch(e){ | |
223ddf66 | 1747 | self._document=_1fb; |
6a1aa64f DV |
1748 | throw e; |
1749 | } | |
223ddf66 | 1750 | self._document=_1fb; |
79f17b42 | 1751 | return rval; |
223ddf66 DV |
1752 | },registerDOMConverter:function(name,_1fe,wrap,_200){ |
1753 | MochiKit.DOM.domConverters.register(name,_1fe,wrap,_200); | |
79f17b42 DV |
1754 | },coerceToDOM:function(node,ctx){ |
1755 | var m=MochiKit.Base; | |
1756 | var im=MochiKit.Iter; | |
1757 | var self=MochiKit.DOM; | |
1758 | if(im){ | |
1759 | var iter=im.iter; | |
223ddf66 | 1760 | var _207=im.repeat; |
79f17b42 DV |
1761 | var map=m.map; |
1762 | } | |
223ddf66 DV |
1763 | var _209=self.domConverters; |
1764 | var _20a=arguments.callee; | |
1765 | var _20b=m.NotFound; | |
79f17b42 DV |
1766 | while(true){ |
1767 | if(typeof (node)=="undefined"||node===null){ | |
1768 | return null; | |
6a1aa64f | 1769 | } |
79f17b42 DV |
1770 | if(typeof (node)=="function"&&typeof (node.length)=="number"&&!(node instanceof Function)){ |
1771 | node=im.list(node); | |
6a1aa64f | 1772 | } |
79f17b42 DV |
1773 | if(typeof (node.nodeType)!="undefined"&&node.nodeType>0){ |
1774 | return node; | |
6a1aa64f | 1775 | } |
79f17b42 DV |
1776 | if(typeof (node)=="number"||typeof (node)=="boolean"){ |
1777 | node=node.toString(); | |
6a1aa64f | 1778 | } |
79f17b42 DV |
1779 | if(typeof (node)=="string"){ |
1780 | return self._document.createTextNode(node); | |
6a1aa64f | 1781 | } |
79f17b42 DV |
1782 | if(typeof (node.__dom__)=="function"){ |
1783 | node=node.__dom__(ctx); | |
1784 | continue; | |
6a1aa64f | 1785 | } |
79f17b42 DV |
1786 | if(typeof (node.dom)=="function"){ |
1787 | node=node.dom(ctx); | |
1788 | continue; | |
6a1aa64f | 1789 | } |
79f17b42 DV |
1790 | if(typeof (node)=="function"){ |
1791 | node=node.apply(ctx,[ctx]); | |
1792 | continue; | |
6a1aa64f | 1793 | } |
79f17b42 | 1794 | if(im){ |
223ddf66 | 1795 | var _20c=null; |
6a1aa64f | 1796 | try{ |
223ddf66 | 1797 | _20c=iter(node); |
6a1aa64f DV |
1798 | } |
1799 | catch(e){ | |
6a1aa64f | 1800 | } |
223ddf66 DV |
1801 | if(_20c){ |
1802 | return map(_20a,_20c,_207(ctx)); | |
79f17b42 DV |
1803 | } |
1804 | } | |
1805 | try{ | |
223ddf66 | 1806 | node=_209.match(node,ctx); |
79f17b42 DV |
1807 | continue; |
1808 | } | |
1809 | catch(e){ | |
223ddf66 | 1810 | if(e!=_20b){ |
6a1aa64f DV |
1811 | throw e; |
1812 | } | |
6a1aa64f | 1813 | } |
79f17b42 | 1814 | return self._document.createTextNode(node.toString()); |
6a1aa64f | 1815 | } |
79f17b42 | 1816 | return undefined; |
223ddf66 | 1817 | },isChildNode:function(node,_20e){ |
79f17b42 DV |
1818 | var self=MochiKit.DOM; |
1819 | if(typeof (node)=="string"){ | |
1820 | node=self.getElement(node); | |
6a1aa64f | 1821 | } |
223ddf66 DV |
1822 | if(typeof (_20e)=="string"){ |
1823 | _20e=self.getElement(_20e); | |
6a1aa64f | 1824 | } |
223ddf66 | 1825 | if(node===_20e){ |
79f17b42 | 1826 | return true; |
6a1aa64f | 1827 | } |
79f17b42 DV |
1828 | while(node&&node.tagName.toUpperCase()!="BODY"){ |
1829 | node=node.parentNode; | |
223ddf66 | 1830 | if(node===_20e){ |
79f17b42 | 1831 | return true; |
6a1aa64f | 1832 | } |
6a1aa64f | 1833 | } |
79f17b42 | 1834 | return false; |
223ddf66 | 1835 | },setNodeAttribute:function(node,attr,_212){ |
79f17b42 | 1836 | var o={}; |
223ddf66 | 1837 | o[attr]=_212; |
79f17b42 DV |
1838 | try{ |
1839 | return MochiKit.DOM.updateNodeAttributes(node,o); | |
6a1aa64f | 1840 | } |
79f17b42 DV |
1841 | catch(e){ |
1842 | } | |
1843 | return null; | |
1844 | },getNodeAttribute:function(node,attr){ | |
1845 | var self=MochiKit.DOM; | |
223ddf66 | 1846 | var _217=self.attributeArray.renames[attr]; |
79f17b42 | 1847 | node=self.getElement(node); |
6a1aa64f | 1848 | try{ |
223ddf66 DV |
1849 | if(_217){ |
1850 | return node[_217]; | |
6a1aa64f | 1851 | } |
79f17b42 | 1852 | return node.getAttribute(attr); |
6a1aa64f DV |
1853 | } |
1854 | catch(e){ | |
6a1aa64f | 1855 | } |
79f17b42 DV |
1856 | return null; |
1857 | },removeNodeAttribute:function(node,attr){ | |
1858 | var self=MochiKit.DOM; | |
223ddf66 | 1859 | var _21b=self.attributeArray.renames[attr]; |
79f17b42 DV |
1860 | node=self.getElement(node); |
1861 | try{ | |
223ddf66 DV |
1862 | if(_21b){ |
1863 | return node[_21b]; | |
6a1aa64f | 1864 | } |
79f17b42 | 1865 | return node.removeAttribute(attr); |
6a1aa64f | 1866 | } |
79f17b42 | 1867 | catch(e){ |
6a1aa64f | 1868 | } |
79f17b42 | 1869 | return null; |
223ddf66 | 1870 | },updateNodeAttributes:function(node,_21d){ |
79f17b42 DV |
1871 | var elem=node; |
1872 | var self=MochiKit.DOM; | |
1873 | if(typeof (node)=="string"){ | |
1874 | elem=self.getElement(node); | |
1875 | } | |
223ddf66 DV |
1876 | if(_21d){ |
1877 | var _220=MochiKit.Base.updatetree; | |
79f17b42 | 1878 | if(self.attributeArray.compliant){ |
223ddf66 DV |
1879 | for(var k in _21d){ |
1880 | var v=_21d[k]; | |
79f17b42 DV |
1881 | if(typeof (v)=="object"&&typeof (elem[k])=="object"){ |
1882 | if(k=="style"&&MochiKit.Style){ | |
1883 | MochiKit.Style.setStyle(elem,v); | |
6a1aa64f | 1884 | }else{ |
223ddf66 | 1885 | _220(elem[k],v); |
79f17b42 | 1886 | } |
6a1aa64f | 1887 | }else{ |
79f17b42 DV |
1888 | if(k.substring(0,2)=="on"){ |
1889 | if(typeof (v)=="string"){ | |
1890 | v=new Function(v); | |
1891 | } | |
1892 | elem[k]=v; | |
6a1aa64f | 1893 | }else{ |
79f17b42 | 1894 | elem.setAttribute(k,v); |
6a1aa64f DV |
1895 | } |
1896 | } | |
1897 | } | |
79f17b42 | 1898 | }else{ |
223ddf66 DV |
1899 | var _223=self.attributeArray.renames; |
1900 | for(var k in _21d){ | |
1901 | v=_21d[k]; | |
1902 | var _224=_223[k]; | |
79f17b42 DV |
1903 | if(k=="style"&&typeof (v)=="string"){ |
1904 | elem.style.cssText=v; | |
1905 | }else{ | |
223ddf66 DV |
1906 | if(typeof (_224)=="string"){ |
1907 | elem[_224]=v; | |
79f17b42 DV |
1908 | }else{ |
1909 | if(typeof (elem[k])=="object"&&typeof (v)=="object"){ | |
1910 | if(k=="style"&&MochiKit.Style){ | |
1911 | MochiKit.Style.setStyle(elem,v); | |
1912 | }else{ | |
223ddf66 | 1913 | _220(elem[k],v); |
6a1aa64f | 1914 | } |
79f17b42 DV |
1915 | }else{ |
1916 | if(k.substring(0,2)=="on"){ | |
1917 | if(typeof (v)=="string"){ | |
1918 | v=new Function(v); | |
6a1aa64f | 1919 | } |
79f17b42 DV |
1920 | elem[k]=v; |
1921 | }else{ | |
1922 | elem.setAttribute(k,v); | |
6a1aa64f | 1923 | } |
6a1aa64f | 1924 | } |
6a1aa64f | 1925 | } |
6a1aa64f | 1926 | } |
6a1aa64f | 1927 | } |
6a1aa64f | 1928 | } |
6a1aa64f | 1929 | } |
79f17b42 DV |
1930 | return elem; |
1931 | },appendChildNodes:function(node){ | |
1932 | var elem=node; | |
1933 | var self=MochiKit.DOM; | |
1934 | if(typeof (node)=="string"){ | |
1935 | elem=self.getElement(node); | |
6a1aa64f | 1936 | } |
223ddf66 DV |
1937 | var _228=[self.coerceToDOM(MochiKit.Base.extend(null,arguments,1),elem)]; |
1938 | var _229=MochiKit.Base.concat; | |
1939 | while(_228.length){ | |
1940 | var n=_228.shift(); | |
79f17b42 DV |
1941 | if(typeof (n)=="undefined"||n===null){ |
1942 | }else{ | |
1943 | if(typeof (n.nodeType)=="number"){ | |
1944 | elem.appendChild(n); | |
1945 | }else{ | |
223ddf66 | 1946 | _228=_229(n,_228); |
6a1aa64f | 1947 | } |
6a1aa64f | 1948 | } |
6a1aa64f | 1949 | } |
79f17b42 DV |
1950 | return elem; |
1951 | },insertSiblingNodesBefore:function(node){ | |
1952 | var elem=node; | |
1953 | var self=MochiKit.DOM; | |
1954 | if(typeof (node)=="string"){ | |
1955 | elem=self.getElement(node); | |
6a1aa64f | 1956 | } |
223ddf66 DV |
1957 | var _22e=[self.coerceToDOM(MochiKit.Base.extend(null,arguments,1),elem)]; |
1958 | var _22f=elem.parentNode; | |
1959 | var _230=MochiKit.Base.concat; | |
1960 | while(_22e.length){ | |
1961 | var n=_22e.shift(); | |
79f17b42 | 1962 | if(typeof (n)=="undefined"||n===null){ |
6a1aa64f | 1963 | }else{ |
79f17b42 | 1964 | if(typeof (n.nodeType)=="number"){ |
223ddf66 | 1965 | _22f.insertBefore(n,elem); |
79f17b42 | 1966 | }else{ |
223ddf66 | 1967 | _22e=_230(n,_22e); |
6a1aa64f | 1968 | } |
6a1aa64f | 1969 | } |
6a1aa64f | 1970 | } |
223ddf66 | 1971 | return _22f; |
79f17b42 DV |
1972 | },insertSiblingNodesAfter:function(node){ |
1973 | var elem=node; | |
1974 | var self=MochiKit.DOM; | |
1975 | if(typeof (node)=="string"){ | |
1976 | elem=self.getElement(node); | |
6a1aa64f | 1977 | } |
223ddf66 | 1978 | var _235=[self.coerceToDOM(MochiKit.Base.extend(null,arguments,1),elem)]; |
79f17b42 | 1979 | if(elem.nextSibling){ |
223ddf66 | 1980 | return self.insertSiblingNodesBefore(elem.nextSibling,_235); |
6a1aa64f | 1981 | }else{ |
223ddf66 | 1982 | return self.appendChildNodes(elem.parentNode,_235); |
6a1aa64f | 1983 | } |
79f17b42 DV |
1984 | },replaceChildNodes:function(node){ |
1985 | var elem=node; | |
1986 | var self=MochiKit.DOM; | |
1987 | if(typeof (node)=="string"){ | |
1988 | elem=self.getElement(node); | |
1989 | arguments[0]=elem; | |
6a1aa64f | 1990 | } |
223ddf66 DV |
1991 | var _239; |
1992 | while((_239=elem.firstChild)){ | |
1993 | elem.removeChild(_239); | |
6a1aa64f | 1994 | } |
79f17b42 DV |
1995 | if(arguments.length<2){ |
1996 | return elem; | |
1997 | }else{ | |
1998 | return self.appendChildNodes.apply(this,arguments); | |
6a1aa64f | 1999 | } |
223ddf66 | 2000 | },createDOM:function(name,_23b){ |
79f17b42 DV |
2001 | var elem; |
2002 | var self=MochiKit.DOM; | |
2003 | var m=MochiKit.Base; | |
223ddf66 | 2004 | if(typeof (_23b)=="string"||typeof (_23b)=="number"){ |
79f17b42 DV |
2005 | var args=m.extend([name,null],arguments,1); |
2006 | return arguments.callee.apply(this,args); | |
6a1aa64f | 2007 | } |
79f17b42 | 2008 | if(typeof (name)=="string"){ |
223ddf66 DV |
2009 | var _240=self._xhtml; |
2010 | if(_23b&&!self.attributeArray.compliant){ | |
2011 | var _241=""; | |
2012 | if("name" in _23b){ | |
2013 | _241+=" name=\""+self.escapeHTML(_23b.name)+"\""; | |
6a1aa64f | 2014 | } |
223ddf66 DV |
2015 | if(name=="input"&&"type" in _23b){ |
2016 | _241+=" type=\""+self.escapeHTML(_23b.type)+"\""; | |
6a1aa64f | 2017 | } |
223ddf66 DV |
2018 | if(_241){ |
2019 | name="<"+name+_241+">"; | |
2020 | _240=false; | |
6a1aa64f | 2021 | } |
6a1aa64f | 2022 | } |
79f17b42 | 2023 | var d=self._document; |
223ddf66 | 2024 | if(_240&&d===document){ |
79f17b42 DV |
2025 | elem=d.createElementNS("http://www.w3.org/1999/xhtml",name); |
2026 | }else{ | |
2027 | elem=d.createElement(name); | |
6a1aa64f | 2028 | } |
79f17b42 DV |
2029 | }else{ |
2030 | elem=name; | |
6a1aa64f | 2031 | } |
223ddf66 DV |
2032 | if(_23b){ |
2033 | self.updateNodeAttributes(elem,_23b); | |
6a1aa64f | 2034 | } |
79f17b42 DV |
2035 | if(arguments.length<=2){ |
2036 | return elem; | |
6a1aa64f | 2037 | }else{ |
79f17b42 DV |
2038 | var args=m.extend([elem],arguments,2); |
2039 | return self.appendChildNodes.apply(this,args); | |
6a1aa64f | 2040 | } |
79f17b42 DV |
2041 | },createDOMFunc:function(){ |
2042 | var m=MochiKit.Base; | |
2043 | return m.partial.apply(this,m.extend([MochiKit.DOM.createDOM],arguments)); | |
2044 | },removeElement:function(elem){ | |
2045 | var e=MochiKit.DOM.getElement(elem); | |
2046 | e.parentNode.removeChild(e); | |
2047 | return e; | |
2048 | },swapDOM:function(dest,src){ | |
2049 | var self=MochiKit.DOM; | |
2050 | dest=self.getElement(dest); | |
223ddf66 | 2051 | var _249=dest.parentNode; |
79f17b42 DV |
2052 | if(src){ |
2053 | src=self.getElement(src); | |
223ddf66 | 2054 | _249.replaceChild(src,dest); |
79f17b42 | 2055 | }else{ |
223ddf66 | 2056 | _249.removeChild(dest); |
6a1aa64f | 2057 | } |
79f17b42 DV |
2058 | return src; |
2059 | },getElement:function(id){ | |
2060 | var self=MochiKit.DOM; | |
2061 | if(arguments.length==1){ | |
2062 | return ((typeof (id)=="string")?self._document.getElementById(id):id); | |
2063 | }else{ | |
2064 | return MochiKit.Base.map(self.getElement,arguments); | |
6a1aa64f | 2065 | } |
223ddf66 | 2066 | },getElementsByTagAndClassName:function(_24c,_24d,_24e){ |
79f17b42 | 2067 | var self=MochiKit.DOM; |
223ddf66 DV |
2068 | if(typeof (_24c)=="undefined"||_24c===null){ |
2069 | _24c="*"; | |
6a1aa64f | 2070 | } |
223ddf66 DV |
2071 | if(typeof (_24e)=="undefined"||_24e===null){ |
2072 | _24e=self._document; | |
6a1aa64f | 2073 | } |
223ddf66 DV |
2074 | _24e=self.getElement(_24e); |
2075 | var _250=(_24e.getElementsByTagName(_24c)||self._document.all); | |
2076 | if(typeof (_24d)=="undefined"||_24d===null){ | |
2077 | return MochiKit.Base.extend(null,_250); | |
6a1aa64f | 2078 | } |
223ddf66 DV |
2079 | var _251=[]; |
2080 | for(var i=0;i<_250.length;i++){ | |
2081 | var _253=_250[i]; | |
2082 | var cls=_253.className; | |
79f17b42 DV |
2083 | if(!cls){ |
2084 | continue; | |
6a1aa64f | 2085 | } |
223ddf66 DV |
2086 | var _255=cls.split(" "); |
2087 | for(var j=0;j<_255.length;j++){ | |
2088 | if(_255[j]==_24d){ | |
2089 | _251.push(_253); | |
79f17b42 | 2090 | break; |
6a1aa64f | 2091 | } |
6a1aa64f | 2092 | } |
6a1aa64f | 2093 | } |
223ddf66 | 2094 | return _251; |
79f17b42 DV |
2095 | },_newCallStack:function(path,once){ |
2096 | var rval=function(){ | |
223ddf66 DV |
2097 | var _25a=arguments.callee.callStack; |
2098 | for(var i=0;i<_25a.length;i++){ | |
2099 | if(_25a[i].apply(this,arguments)===false){ | |
79f17b42 | 2100 | break; |
6a1aa64f DV |
2101 | } |
2102 | } | |
79f17b42 DV |
2103 | if(once){ |
2104 | try{ | |
2105 | this[path]=null; | |
6a1aa64f | 2106 | } |
79f17b42 | 2107 | catch(e){ |
6a1aa64f | 2108 | } |
6a1aa64f | 2109 | } |
79f17b42 DV |
2110 | }; |
2111 | rval.callStack=[]; | |
2112 | return rval; | |
223ddf66 | 2113 | },addToCallStack:function(_25c,path,func,once){ |
79f17b42 | 2114 | var self=MochiKit.DOM; |
223ddf66 DV |
2115 | var _261=_25c[path]; |
2116 | var _262=_261; | |
2117 | if(!(typeof (_261)=="function"&&typeof (_261.callStack)=="object"&&_261.callStack!==null)){ | |
2118 | _262=self._newCallStack(path,once); | |
2119 | if(typeof (_261)=="function"){ | |
2120 | _262.callStack.push(_261); | |
6a1aa64f | 2121 | } |
223ddf66 | 2122 | _25c[path]=_262; |
6a1aa64f | 2123 | } |
223ddf66 | 2124 | _262.callStack.push(func); |
79f17b42 DV |
2125 | },addLoadEvent:function(func){ |
2126 | var self=MochiKit.DOM; | |
2127 | self.addToCallStack(self._window,"onload",func,true); | |
223ddf66 | 2128 | },focusOnLoad:function(_265){ |
79f17b42 DV |
2129 | var self=MochiKit.DOM; |
2130 | self.addLoadEvent(function(){ | |
223ddf66 DV |
2131 | _265=self.getElement(_265); |
2132 | if(_265){ | |
2133 | _265.focus(); | |
6a1aa64f | 2134 | } |
79f17b42 | 2135 | }); |
223ddf66 | 2136 | },setElementClass:function(_267,_268){ |
79f17b42 | 2137 | var self=MochiKit.DOM; |
223ddf66 | 2138 | var obj=self.getElement(_267); |
79f17b42 | 2139 | if(self.attributeArray.compliant){ |
223ddf66 | 2140 | obj.setAttribute("class",_268); |
6a1aa64f | 2141 | }else{ |
223ddf66 | 2142 | obj.setAttribute("className",_268); |
6a1aa64f | 2143 | } |
223ddf66 | 2144 | },toggleElementClass:function(_26b){ |
79f17b42 DV |
2145 | var self=MochiKit.DOM; |
2146 | for(var i=1;i<arguments.length;i++){ | |
2147 | var obj=self.getElement(arguments[i]); | |
223ddf66 DV |
2148 | if(!self.addElementClass(obj,_26b)){ |
2149 | self.removeElementClass(obj,_26b); | |
6a1aa64f | 2150 | } |
6a1aa64f | 2151 | } |
223ddf66 | 2152 | },addElementClass:function(_26f,_270){ |
79f17b42 | 2153 | var self=MochiKit.DOM; |
223ddf66 | 2154 | var obj=self.getElement(_26f); |
79f17b42 DV |
2155 | var cls=obj.className; |
2156 | if(cls==undefined||cls.length===0){ | |
223ddf66 | 2157 | self.setElementClass(obj,_270); |
79f17b42 | 2158 | return true; |
6a1aa64f | 2159 | } |
223ddf66 | 2160 | if(cls==_270){ |
79f17b42 | 2161 | return false; |
6a1aa64f | 2162 | } |
223ddf66 DV |
2163 | var _274=cls.split(" "); |
2164 | for(var i=0;i<_274.length;i++){ | |
2165 | if(_274[i]==_270){ | |
79f17b42 | 2166 | return false; |
6a1aa64f | 2167 | } |
6a1aa64f | 2168 | } |
223ddf66 | 2169 | self.setElementClass(obj,cls+" "+_270); |
79f17b42 | 2170 | return true; |
223ddf66 | 2171 | },removeElementClass:function(_276,_277){ |
79f17b42 | 2172 | var self=MochiKit.DOM; |
223ddf66 | 2173 | var obj=self.getElement(_276); |
79f17b42 DV |
2174 | var cls=obj.className; |
2175 | if(cls==undefined||cls.length===0){ | |
2176 | return false; | |
6a1aa64f | 2177 | } |
223ddf66 | 2178 | if(cls==_277){ |
79f17b42 DV |
2179 | self.setElementClass(obj,""); |
2180 | return true; | |
6a1aa64f | 2181 | } |
223ddf66 DV |
2182 | var _27b=cls.split(" "); |
2183 | for(var i=0;i<_27b.length;i++){ | |
2184 | if(_27b[i]==_277){ | |
2185 | _27b.splice(i,1); | |
2186 | self.setElementClass(obj,_27b.join(" ")); | |
79f17b42 | 2187 | return true; |
6a1aa64f DV |
2188 | } |
2189 | } | |
79f17b42 | 2190 | return false; |
223ddf66 DV |
2191 | },swapElementClass:function(_27d,_27e,_27f){ |
2192 | var obj=MochiKit.DOM.getElement(_27d); | |
2193 | var res=MochiKit.DOM.removeElementClass(obj,_27e); | |
79f17b42 | 2194 | if(res){ |
223ddf66 | 2195 | MochiKit.DOM.addElementClass(obj,_27f); |
6a1aa64f | 2196 | } |
79f17b42 | 2197 | return res; |
223ddf66 DV |
2198 | },hasElementClass:function(_282,_283){ |
2199 | var obj=MochiKit.DOM.getElement(_282); | |
79f17b42 DV |
2200 | var cls=obj.className; |
2201 | if(!cls){ | |
2202 | return false; | |
6a1aa64f | 2203 | } |
223ddf66 | 2204 | var _286=cls.split(" "); |
79f17b42 DV |
2205 | for(var i=1;i<arguments.length;i++){ |
2206 | var good=false; | |
223ddf66 DV |
2207 | for(var j=0;j<_286.length;j++){ |
2208 | if(_286[j]==arguments[i]){ | |
79f17b42 DV |
2209 | good=true; |
2210 | break; | |
6a1aa64f | 2211 | } |
6a1aa64f | 2212 | } |
79f17b42 DV |
2213 | if(!good){ |
2214 | return false; | |
6a1aa64f | 2215 | } |
6a1aa64f | 2216 | } |
79f17b42 DV |
2217 | return true; |
2218 | },escapeHTML:function(s){ | |
2219 | return s.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">"); | |
2220 | },toHTML:function(dom){ | |
2221 | return MochiKit.DOM.emitHTML(dom).join(""); | |
2222 | },emitHTML:function(dom,lst){ | |
2223 | if(typeof (lst)=="undefined"||lst===null){ | |
2224 | lst=[]; | |
6a1aa64f | 2225 | } |
223ddf66 | 2226 | var _28e=[dom]; |
79f17b42 | 2227 | var self=MochiKit.DOM; |
223ddf66 DV |
2228 | var _290=self.escapeHTML; |
2229 | var _291=self.attributeArray; | |
2230 | while(_28e.length){ | |
2231 | dom=_28e.pop(); | |
79f17b42 DV |
2232 | if(typeof (dom)=="string"){ |
2233 | lst.push(dom); | |
2234 | }else{ | |
2235 | if(dom.nodeType==1){ | |
2236 | lst.push("<"+dom.tagName.toLowerCase()); | |
223ddf66 DV |
2237 | var _292=[]; |
2238 | var _293=_291(dom); | |
2239 | for(var i=0;i<_293.length;i++){ | |
2240 | var a=_293[i]; | |
2241 | _292.push([" ",a.name,"=\"",_290(a.value),"\""]); | |
6a1aa64f | 2242 | } |
223ddf66 DV |
2243 | _292.sort(); |
2244 | for(i=0;i<_292.length;i++){ | |
2245 | var _296=_292[i]; | |
2246 | for(var j=0;j<_296.length;j++){ | |
2247 | lst.push(_296[j]); | |
6a1aa64f DV |
2248 | } |
2249 | } | |
79f17b42 DV |
2250 | if(dom.hasChildNodes()){ |
2251 | lst.push(">"); | |
223ddf66 DV |
2252 | _28e.push("</"+dom.tagName.toLowerCase()+">"); |
2253 | var _298=dom.childNodes; | |
2254 | for(i=_298.length-1;i>=0;i--){ | |
2255 | _28e.push(_298[i]); | |
6a1aa64f | 2256 | } |
6a1aa64f | 2257 | }else{ |
79f17b42 | 2258 | lst.push("/>"); |
6a1aa64f | 2259 | } |
79f17b42 DV |
2260 | }else{ |
2261 | if(dom.nodeType==3){ | |
223ddf66 | 2262 | lst.push(_290(dom.nodeValue)); |
6a1aa64f | 2263 | } |
6a1aa64f | 2264 | } |
6a1aa64f | 2265 | } |
6a1aa64f | 2266 | } |
79f17b42 | 2267 | return lst; |
223ddf66 | 2268 | },scrapeText:function(node,_29a){ |
79f17b42 DV |
2269 | var rval=[]; |
2270 | (function(node){ | |
2271 | var cn=node.childNodes; | |
2272 | if(cn){ | |
2273 | for(var i=0;i<cn.length;i++){ | |
2274 | arguments.callee.call(this,cn[i]); | |
6a1aa64f | 2275 | } |
6a1aa64f | 2276 | } |
223ddf66 DV |
2277 | var _29f=node.nodeValue; |
2278 | if(typeof (_29f)=="string"){ | |
2279 | rval.push(_29f); | |
6a1aa64f | 2280 | } |
79f17b42 | 2281 | })(MochiKit.DOM.getElement(node)); |
223ddf66 | 2282 | if(_29a){ |
79f17b42 | 2283 | return rval; |
6a1aa64f | 2284 | }else{ |
79f17b42 | 2285 | return rval.join(""); |
6a1aa64f | 2286 | } |
223ddf66 DV |
2287 | },removeEmptyTextNodes:function(_2a0){ |
2288 | _2a0=MochiKit.DOM.getElement(_2a0); | |
2289 | for(var i=0;i<_2a0.childNodes.length;i++){ | |
2290 | var node=_2a0.childNodes[i]; | |
79f17b42 DV |
2291 | if(node.nodeType==3&&!/\S/.test(node.nodeValue)){ |
2292 | node.parentNode.removeChild(node); | |
6a1aa64f | 2293 | } |
6a1aa64f | 2294 | } |
223ddf66 DV |
2295 | },makeClipping:function(_2a3){ |
2296 | _2a3=MochiKit.DOM.getElement(_2a3); | |
2297 | var _2a4=_2a3.style.overflow; | |
2298 | if((MochiKit.Style.getStyle(_2a3,"overflow")||"visible")!="hidden"){ | |
2299 | _2a3.style.overflow="hidden"; | |
6a1aa64f | 2300 | } |
223ddf66 DV |
2301 | return _2a4; |
2302 | },undoClipping:function(_2a5,_2a6){ | |
2303 | _2a5=MochiKit.DOM.getElement(_2a5); | |
2304 | if(!_2a6){ | |
79f17b42 | 2305 | return; |
6a1aa64f | 2306 | } |
223ddf66 DV |
2307 | _2a5.style.overflow=_2a6; |
2308 | },makePositioned:function(_2a7){ | |
2309 | _2a7=MochiKit.DOM.getElement(_2a7); | |
2310 | var pos=MochiKit.Style.getStyle(_2a7,"position"); | |
79f17b42 | 2311 | if(pos=="static"||!pos){ |
223ddf66 | 2312 | _2a7.style.position="relative"; |
79f17b42 | 2313 | if(/Opera/.test(navigator.userAgent)){ |
223ddf66 DV |
2314 | _2a7.style.top=0; |
2315 | _2a7.style.left=0; | |
6a1aa64f | 2316 | } |
6a1aa64f | 2317 | } |
223ddf66 DV |
2318 | },undoPositioned:function(_2a9){ |
2319 | _2a9=MochiKit.DOM.getElement(_2a9); | |
2320 | if(_2a9.style.position=="relative"){ | |
2321 | _2a9.style.position=_2a9.style.top=_2a9.style.left=_2a9.style.bottom=_2a9.style.right=""; | |
6a1aa64f | 2322 | } |
223ddf66 | 2323 | },getFirstElementByTagAndClassName:function(_2aa,_2ab,_2ac){ |
79f17b42 | 2324 | var self=MochiKit.DOM; |
223ddf66 DV |
2325 | if(typeof (_2aa)=="undefined"||_2aa===null){ |
2326 | _2aa="*"; | |
6a1aa64f | 2327 | } |
223ddf66 DV |
2328 | if(typeof (_2ac)=="undefined"||_2ac===null){ |
2329 | _2ac=self._document; | |
6a1aa64f | 2330 | } |
223ddf66 DV |
2331 | _2ac=self.getElement(_2ac); |
2332 | var _2ae=(_2ac.getElementsByTagName(_2aa)||self._document.all); | |
2333 | if(typeof (_2ab)=="undefined"||_2ab===null){ | |
2334 | return _2ae[0]; | |
6a1aa64f | 2335 | } |
223ddf66 DV |
2336 | for(var i=0;i<_2ae.length;i++){ |
2337 | var _2b0=_2ae[i]; | |
2338 | var _2b1=_2b0.className.split(" "); | |
2339 | for(var j=0;j<_2b1.length;j++){ | |
2340 | if(_2b1[j]==_2ab){ | |
2341 | return _2b0; | |
6a1aa64f | 2342 | } |
6a1aa64f | 2343 | } |
6a1aa64f | 2344 | } |
223ddf66 | 2345 | },getFirstParentByTagAndClassName:function(elem,_2b4,_2b5){ |
79f17b42 DV |
2346 | var self=MochiKit.DOM; |
2347 | elem=self.getElement(elem); | |
223ddf66 DV |
2348 | if(typeof (_2b4)=="undefined"||_2b4===null){ |
2349 | _2b4="*"; | |
79f17b42 | 2350 | }else{ |
223ddf66 | 2351 | _2b4=_2b4.toUpperCase(); |
6a1aa64f | 2352 | } |
223ddf66 DV |
2353 | if(typeof (_2b5)=="undefined"||_2b5===null){ |
2354 | _2b5=null; | |
6a1aa64f | 2355 | } |
223ddf66 DV |
2356 | var _2b7=""; |
2357 | var _2b8=""; | |
79f17b42 DV |
2358 | while(elem&&elem.tagName){ |
2359 | elem=elem.parentNode; | |
223ddf66 | 2360 | if(_2b4=="*"&&_2b5===null){ |
79f17b42 | 2361 | return elem; |
6a1aa64f | 2362 | } |
223ddf66 DV |
2363 | _2b7=elem.className.split(" "); |
2364 | _2b8=elem.tagName.toUpperCase(); | |
2365 | if(_2b5===null&&_2b4==_2b8){ | |
79f17b42 DV |
2366 | return elem; |
2367 | }else{ | |
223ddf66 DV |
2368 | if(_2b5!==null){ |
2369 | for(var i=0;i<_2b7.length;i++){ | |
2370 | if(_2b4=="*"&&_2b7[i]==_2b5){ | |
79f17b42 DV |
2371 | return elem; |
2372 | }else{ | |
223ddf66 | 2373 | if(_2b4==_2b8&&_2b7[i]==_2b5){ |
79f17b42 | 2374 | return elem; |
6a1aa64f | 2375 | } |
6a1aa64f DV |
2376 | } |
2377 | } | |
6a1aa64f | 2378 | } |
6a1aa64f | 2379 | } |
6a1aa64f | 2380 | } |
79f17b42 | 2381 | return elem; |
223ddf66 DV |
2382 | },isParent:function(_2ba,_2bb){ |
2383 | if(!_2ba.parentNode||_2ba==_2bb){ | |
79f17b42 | 2384 | return false; |
6a1aa64f | 2385 | } |
223ddf66 | 2386 | if(_2ba.parentNode==_2bb){ |
79f17b42 | 2387 | return true; |
6a1aa64f | 2388 | } |
223ddf66 | 2389 | return MochiKit.DOM.isParent(_2ba.parentNode,_2bb); |
79f17b42 | 2390 | },__new__:function(win){ |
6a1aa64f | 2391 | var m=MochiKit.Base; |
79f17b42 DV |
2392 | if(typeof (document)!="undefined"){ |
2393 | this._document=document; | |
223ddf66 DV |
2394 | var _2be="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; |
2395 | this._xhtml=(document.documentElement&&document.createElementNS&&document.documentElement.namespaceURI===_2be); | |
79f17b42 DV |
2396 | }else{ |
2397 | if(MochiKit.MockDOM){ | |
2398 | this._document=MochiKit.MockDOM.document; | |
2399 | } | |
2400 | } | |
2401 | this._window=win; | |
2402 | this.domConverters=new m.AdapterRegistry(); | |
223ddf66 DV |
2403 | var _2bf=this._document.createElement("span"); |
2404 | var _2c0; | |
2405 | if(_2bf&&_2bf.attributes&&_2bf.attributes.length>0){ | |
2406 | var _2c1=m.filter; | |
2407 | _2c0=function(node){ | |
2408 | return _2c1(_2c0.ignoreAttrFilter,node.attributes); | |
165759fa | 2409 | }; |
223ddf66 DV |
2410 | _2c0.ignoreAttr={}; |
2411 | var _2c3=_2bf.attributes; | |
2412 | var _2c4=_2c0.ignoreAttr; | |
2413 | for(var i=0;i<_2c3.length;i++){ | |
2414 | var a=_2c3[i]; | |
2415 | _2c4[a.name]=a.value; | |
2416 | } | |
2417 | _2c0.ignoreAttrFilter=function(a){ | |
2418 | return (_2c0.ignoreAttr[a.name]!=a.value); | |
165759fa | 2419 | }; |
223ddf66 DV |
2420 | _2c0.compliant=false; |
2421 | _2c0.renames={"class":"className","checked":"defaultChecked","usemap":"useMap","for":"htmlFor","readonly":"readOnly","colspan":"colSpan","bgcolor":"bgColor","cellspacing":"cellSpacing","cellpadding":"cellPadding"}; | |
165759fa | 2422 | }else{ |
223ddf66 | 2423 | _2c0=function(node){ |
79f17b42 DV |
2424 | return node.attributes; |
2425 | }; | |
223ddf66 DV |
2426 | _2c0.compliant=true; |
2427 | _2c0.renames={}; | |
79f17b42 | 2428 | } |
223ddf66 DV |
2429 | this.attributeArray=_2c0; |
2430 | var _2c9=function(_2ca,arr){ | |
2431 | var _2cc=arr[1].split("."); | |
79f17b42 DV |
2432 | var str=""; |
2433 | var obj={}; | |
223ddf66 | 2434 | str+="if (!MochiKit."+_2cc[1]+") { throw new Error(\""; |
79f17b42 | 2435 | str+="This function has been deprecated and depends on MochiKit."; |
223ddf66 DV |
2436 | str+=_2cc[1]+".\");}"; |
2437 | str+="return MochiKit."+_2cc[1]+"."+arr[0]; | |
79f17b42 | 2438 | str+=".apply(this, arguments);"; |
223ddf66 DV |
2439 | obj[_2cc[2]]=new Function(str); |
2440 | MochiKit.Base.update(MochiKit[_2ca],obj); | |
79f17b42 DV |
2441 | }; |
2442 | for(var i;i<MochiKit.DOM.DEPRECATED.length;i++){ | |
223ddf66 DV |
2443 | _2c9("DOM",MochiKit.DOM.DEPRECATED[i]); |
2444 | } | |
2445 | var _2cf=this.createDOMFunc; | |
2446 | this.UL=_2cf("ul"); | |
2447 | this.OL=_2cf("ol"); | |
2448 | this.LI=_2cf("li"); | |
2449 | this.TD=_2cf("td"); | |
2450 | this.TR=_2cf("tr"); | |
2451 | this.TBODY=_2cf("tbody"); | |
2452 | this.THEAD=_2cf("thead"); | |
2453 | this.TFOOT=_2cf("tfoot"); | |
2454 | this.TABLE=_2cf("table"); | |
2455 | this.TH=_2cf("th"); | |
2456 | this.INPUT=_2cf("input"); | |
2457 | this.SPAN=_2cf("span"); | |
2458 | this.A=_2cf("a"); | |
2459 | this.DIV=_2cf("div"); | |
2460 | this.IMG=_2cf("img"); | |
2461 | this.BUTTON=_2cf("button"); | |
2462 | this.TT=_2cf("tt"); | |
2463 | this.PRE=_2cf("pre"); | |
2464 | this.H1=_2cf("h1"); | |
2465 | this.H2=_2cf("h2"); | |
2466 | this.H3=_2cf("h3"); | |
2467 | this.BR=_2cf("br"); | |
2468 | this.HR=_2cf("hr"); | |
2469 | this.LABEL=_2cf("label"); | |
2470 | this.TEXTAREA=_2cf("textarea"); | |
2471 | this.FORM=_2cf("form"); | |
2472 | this.P=_2cf("p"); | |
2473 | this.SELECT=_2cf("select"); | |
2474 | this.OPTION=_2cf("option"); | |
2475 | this.OPTGROUP=_2cf("optgroup"); | |
2476 | this.LEGEND=_2cf("legend"); | |
2477 | this.FIELDSET=_2cf("fieldset"); | |
2478 | this.STRONG=_2cf("strong"); | |
2479 | this.CANVAS=_2cf("canvas"); | |
79f17b42 DV |
2480 | this.$=this.getElement; |
2481 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
2482 | m.nameFunctions(this); | |
2483 | }}); | |
2484 | MochiKit.DOM.__new__(((typeof (window)=="undefined")?this:window)); | |
2485 | if(MochiKit.__export__){ | |
2486 | withWindow=MochiKit.DOM.withWindow; | |
2487 | withDocument=MochiKit.DOM.withDocument; | |
2488 | } | |
2489 | MochiKit.Base._exportSymbols(this,MochiKit.DOM); | |
2490 | if(typeof (dojo)!="undefined"){ | |
2491 | dojo.provide("MochiKit.Style"); | |
2492 | dojo.require("MochiKit.Base"); | |
2493 | dojo.require("MochiKit.DOM"); | |
2494 | } | |
2495 | if(typeof (JSAN)!="undefined"){ | |
2496 | JSAN.use("MochiKit.Base",[]); | |
2497 | JSAN.use("MochiKit.DOM",[]); | |
2498 | } | |
6a1aa64f | 2499 | try{ |
79f17b42 DV |
2500 | if(typeof (MochiKit.Base)=="undefined"){ |
2501 | throw ""; | |
2502 | } | |
6a1aa64f DV |
2503 | } |
2504 | catch(e){ | |
79f17b42 DV |
2505 | throw "MochiKit.Style depends on MochiKit.Base!"; |
2506 | } | |
6a1aa64f | 2507 | try{ |
79f17b42 DV |
2508 | if(typeof (MochiKit.DOM)=="undefined"){ |
2509 | throw ""; | |
2510 | } | |
6a1aa64f DV |
2511 | } |
2512 | catch(e){ | |
79f17b42 | 2513 | throw "MochiKit.Style depends on MochiKit.DOM!"; |
6a1aa64f | 2514 | } |
79f17b42 DV |
2515 | if(typeof (MochiKit.Style)=="undefined"){ |
2516 | MochiKit.Style={}; | |
6a1aa64f | 2517 | } |
79f17b42 DV |
2518 | MochiKit.Style.NAME="MochiKit.Style"; |
2519 | MochiKit.Style.VERSION="1.4"; | |
2520 | MochiKit.Style.__repr__=function(){ | |
2521 | return "["+this.NAME+" "+this.VERSION+"]"; | |
2522 | }; | |
2523 | MochiKit.Style.toString=function(){ | |
2524 | return this.__repr__(); | |
2525 | }; | |
2526 | MochiKit.Style.EXPORT_OK=[]; | |
2527 | MochiKit.Style.EXPORT=["setStyle","setOpacity","getStyle","getElementDimensions","elementDimensions","setElementDimensions","getElementPosition","elementPosition","setElementPosition","setDisplayForElement","hideElement","showElement","getViewportDimensions","getViewportPosition","Dimensions","Coordinates"]; | |
2528 | MochiKit.Style.Dimensions=function(w,h){ | |
2529 | this.w=w; | |
2530 | this.h=h; | |
2531 | }; | |
2532 | MochiKit.Style.Dimensions.prototype.__repr__=function(){ | |
2533 | var repr=MochiKit.Base.repr; | |
2534 | return "{w: "+repr(this.w)+", h: "+repr(this.h)+"}"; | |
2535 | }; | |
2536 | MochiKit.Style.Dimensions.prototype.toString=function(){ | |
2537 | return this.__repr__(); | |
2538 | }; | |
2539 | MochiKit.Style.Coordinates=function(x,y){ | |
2540 | this.x=x; | |
2541 | this.y=y; | |
2542 | }; | |
2543 | MochiKit.Style.Coordinates.prototype.__repr__=function(){ | |
2544 | var repr=MochiKit.Base.repr; | |
2545 | return "{x: "+repr(this.x)+", y: "+repr(this.y)+"}"; | |
2546 | }; | |
2547 | MochiKit.Style.Coordinates.prototype.toString=function(){ | |
2548 | return this.__repr__(); | |
2549 | }; | |
223ddf66 | 2550 | MochiKit.Base.update(MochiKit.Style,{getStyle:function(elem,_2d7){ |
79f17b42 DV |
2551 | var dom=MochiKit.DOM; |
2552 | var d=dom._document; | |
2553 | elem=dom.getElement(elem); | |
223ddf66 | 2554 | _2d7=MochiKit.Base.camelize(_2d7); |
79f17b42 DV |
2555 | if(!elem||elem==d){ |
2556 | return undefined; | |
6a1aa64f | 2557 | } |
223ddf66 DV |
2558 | if(_2d7=="opacity"&&elem.filters){ |
2559 | var _2da=(MochiKit.Style.getStyle(elem,"filter")||"").match(/alpha\(opacity=(.*)\)/); | |
2560 | if(_2da&&_2da[1]){ | |
2561 | return parseFloat(_2da[1])/100; | |
6a1aa64f | 2562 | } |
79f17b42 | 2563 | return 1; |
6a1aa64f | 2564 | } |
223ddf66 DV |
2565 | var _2db=elem.style?elem.style[_2d7]:null; |
2566 | if(!_2db){ | |
79f17b42 DV |
2567 | if(d.defaultView&&d.defaultView.getComputedStyle){ |
2568 | var css=d.defaultView.getComputedStyle(elem,null); | |
223ddf66 DV |
2569 | _2d7=_2d7.replace(/([A-Z])/g,"-$1").toLowerCase(); |
2570 | _2db=css?css.getPropertyValue(_2d7):null; | |
6a1aa64f | 2571 | }else{ |
79f17b42 | 2572 | if(elem.currentStyle){ |
223ddf66 | 2573 | _2db=elem.currentStyle[_2d7]; |
6a1aa64f DV |
2574 | } |
2575 | } | |
6a1aa64f | 2576 | } |
223ddf66 DV |
2577 | if(_2d7=="opacity"){ |
2578 | _2db=parseFloat(_2db); | |
6a1aa64f | 2579 | } |
223ddf66 | 2580 | if(/Opera/.test(navigator.userAgent)&&(MochiKit.Base.find(["left","top","right","bottom"],_2d7)!=-1)){ |
79f17b42 | 2581 | if(MochiKit.Style.getStyle(elem,"position")=="static"){ |
223ddf66 | 2582 | _2db="auto"; |
6a1aa64f DV |
2583 | } |
2584 | } | |
223ddf66 DV |
2585 | return _2db=="auto"?null:_2db; |
2586 | },setStyle:function(elem,_2de){ | |
79f17b42 | 2587 | elem=MochiKit.DOM.getElement(elem); |
223ddf66 | 2588 | for(var name in _2de){ |
79f17b42 | 2589 | if(name=="opacity"){ |
223ddf66 | 2590 | MochiKit.Style.setOpacity(elem,_2de[name]); |
79f17b42 | 2591 | }else{ |
223ddf66 | 2592 | elem.style[MochiKit.Base.camelize(name)]=_2de[name]; |
6a1aa64f | 2593 | } |
6a1aa64f | 2594 | } |
79f17b42 DV |
2595 | },setOpacity:function(elem,o){ |
2596 | elem=MochiKit.DOM.getElement(elem); | |
2597 | var self=MochiKit.Style; | |
2598 | if(o==1){ | |
223ddf66 DV |
2599 | var _2e3=/Gecko/.test(navigator.userAgent)&&!(/Konqueror|AppleWebKit|KHTML/.test(navigator.userAgent)); |
2600 | elem.style["opacity"]=_2e3?0.999999:1; | |
79f17b42 DV |
2601 | if(/MSIE/.test(navigator.userAgent)){ |
2602 | elem.style["filter"]=self.getStyle(elem,"filter").replace(/alpha\([^\)]*\)/gi,""); | |
6a1aa64f | 2603 | } |
79f17b42 DV |
2604 | }else{ |
2605 | if(o<0.00001){ | |
2606 | o=0; | |
6a1aa64f | 2607 | } |
79f17b42 DV |
2608 | elem.style["opacity"]=o; |
2609 | if(/MSIE/.test(navigator.userAgent)){ | |
2610 | elem.style["filter"]=self.getStyle(elem,"filter").replace(/alpha\([^\)]*\)/gi,"")+"alpha(opacity="+o*100+")"; | |
6a1aa64f | 2611 | } |
6a1aa64f | 2612 | } |
223ddf66 | 2613 | },getElementPosition:function(elem,_2e5){ |
79f17b42 DV |
2614 | var self=MochiKit.Style; |
2615 | var dom=MochiKit.DOM; | |
2616 | elem=dom.getElement(elem); | |
2617 | if(!elem||(!(elem.x&&elem.y)&&(!elem.parentNode===null||self.getStyle(elem,"display")=="none"))){ | |
2618 | return undefined; | |
6a1aa64f | 2619 | } |
79f17b42 DV |
2620 | var c=new self.Coordinates(0,0); |
2621 | var box=null; | |
223ddf66 | 2622 | var _2ea=null; |
79f17b42 DV |
2623 | var d=MochiKit.DOM._document; |
2624 | var de=d.documentElement; | |
2625 | var b=d.body; | |
2626 | if(!elem.parentNode&&elem.x&&elem.y){ | |
2627 | c.x+=elem.x||0; | |
2628 | c.y+=elem.y||0; | |
2629 | }else{ | |
2630 | if(elem.getBoundingClientRect){ | |
2631 | box=elem.getBoundingClientRect(); | |
2632 | c.x+=box.left+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0); | |
2633 | c.y+=box.top+(de.scrollTop||b.scrollTop)-(de.clientTop||0); | |
6a1aa64f | 2634 | }else{ |
79f17b42 DV |
2635 | if(elem.offsetParent){ |
2636 | c.x+=elem.offsetLeft; | |
2637 | c.y+=elem.offsetTop; | |
223ddf66 DV |
2638 | _2ea=elem.offsetParent; |
2639 | if(_2ea!=elem){ | |
2640 | while(_2ea){ | |
2641 | c.x+=_2ea.offsetLeft; | |
2642 | c.y+=_2ea.offsetTop; | |
2643 | _2ea=_2ea.offsetParent; | |
6a1aa64f | 2644 | } |
6a1aa64f | 2645 | } |
79f17b42 DV |
2646 | var ua=navigator.userAgent.toLowerCase(); |
2647 | if((typeof (opera)!="undefined"&&parseFloat(opera.version())<9)||(ua.indexOf("AppleWebKit")!=-1&&self.getStyle(elem,"position")=="absolute")){ | |
2648 | c.x-=b.offsetLeft; | |
2649 | c.y-=b.offsetTop; | |
6a1aa64f | 2650 | } |
6a1aa64f DV |
2651 | } |
2652 | } | |
6a1aa64f | 2653 | } |
223ddf66 DV |
2654 | if(typeof (_2e5)!="undefined"){ |
2655 | _2e5=arguments.callee(_2e5); | |
2656 | if(_2e5){ | |
2657 | c.x-=(_2e5.x||0); | |
2658 | c.y-=(_2e5.y||0); | |
6a1aa64f | 2659 | } |
6a1aa64f | 2660 | } |
79f17b42 | 2661 | if(elem.parentNode){ |
223ddf66 | 2662 | _2ea=elem.parentNode; |
6a1aa64f | 2663 | }else{ |
223ddf66 | 2664 | _2ea=null; |
6a1aa64f | 2665 | } |
223ddf66 DV |
2666 | while(_2ea){ |
2667 | var _2ef=_2ea.tagName.toUpperCase(); | |
2668 | if(_2ef==="BODY"||_2ef==="HTML"){ | |
79f17b42 | 2669 | break; |
6a1aa64f | 2670 | } |
223ddf66 | 2671 | var disp=self.getStyle(_2ea,"display"); |
79f17b42 | 2672 | if(disp!="inline"&&disp!="table-row"){ |
223ddf66 DV |
2673 | c.x-=_2ea.scrollLeft; |
2674 | c.y-=_2ea.scrollTop; | |
6a1aa64f | 2675 | } |
223ddf66 DV |
2676 | if(_2ea.parentNode){ |
2677 | _2ea=_2ea.parentNode; | |
79f17b42 | 2678 | }else{ |
223ddf66 | 2679 | _2ea=null; |
6a1aa64f DV |
2680 | } |
2681 | } | |
79f17b42 | 2682 | return c; |
223ddf66 | 2683 | },setElementPosition:function(elem,_2f2,_2f3){ |
79f17b42 | 2684 | elem=MochiKit.DOM.getElement(elem); |
223ddf66 DV |
2685 | if(typeof (_2f3)=="undefined"){ |
2686 | _2f3="px"; | |
6a1aa64f | 2687 | } |
223ddf66 DV |
2688 | var _2f4={}; |
2689 | var _2f5=MochiKit.Base.isUndefinedOrNull; | |
2690 | if(!_2f5(_2f2.x)){ | |
2691 | _2f4["left"]=_2f2.x+_2f3; | |
6a1aa64f | 2692 | } |
223ddf66 DV |
2693 | if(!_2f5(_2f2.y)){ |
2694 | _2f4["top"]=_2f2.y+_2f3; | |
6a1aa64f | 2695 | } |
223ddf66 | 2696 | MochiKit.DOM.updateNodeAttributes(elem,{"style":_2f4}); |
79f17b42 DV |
2697 | },getElementDimensions:function(elem){ |
2698 | var self=MochiKit.Style; | |
2699 | var dom=MochiKit.DOM; | |
2700 | if(typeof (elem.w)=="number"||typeof (elem.h)=="number"){ | |
2701 | return new self.Dimensions(elem.w||0,elem.h||0); | |
6a1aa64f | 2702 | } |
79f17b42 DV |
2703 | elem=dom.getElement(elem); |
2704 | if(!elem){ | |
2705 | return undefined; | |
6a1aa64f | 2706 | } |
79f17b42 DV |
2707 | var disp=self.getStyle(elem,"display"); |
2708 | if(disp!="none"&&disp!==""&&typeof (disp)!="undefined"){ | |
2709 | return new self.Dimensions(elem.offsetWidth||0,elem.offsetHeight||0); | |
6a1aa64f | 2710 | } |
79f17b42 | 2711 | var s=elem.style; |
223ddf66 DV |
2712 | var _2fb=s.visibility; |
2713 | var _2fc=s.position; | |
79f17b42 DV |
2714 | s.visibility="hidden"; |
2715 | s.position="absolute"; | |
2716 | s.display=""; | |
223ddf66 DV |
2717 | var _2fd=elem.offsetWidth; |
2718 | var _2fe=elem.offsetHeight; | |
79f17b42 | 2719 | s.display="none"; |
223ddf66 DV |
2720 | s.position=_2fc; |
2721 | s.visibility=_2fb; | |
2722 | return new self.Dimensions(_2fd,_2fe); | |
2723 | },setElementDimensions:function(elem,_300,_301){ | |
79f17b42 | 2724 | elem=MochiKit.DOM.getElement(elem); |
223ddf66 DV |
2725 | if(typeof (_301)=="undefined"){ |
2726 | _301="px"; | |
6a1aa64f | 2727 | } |
223ddf66 DV |
2728 | var _302={}; |
2729 | var _303=MochiKit.Base.isUndefinedOrNull; | |
2730 | if(!_303(_300.w)){ | |
2731 | _302["width"]=_300.w+_301; | |
6a1aa64f | 2732 | } |
223ddf66 DV |
2733 | if(!_303(_300.h)){ |
2734 | _302["height"]=_300.h+_301; | |
6a1aa64f | 2735 | } |
223ddf66 DV |
2736 | MochiKit.DOM.updateNodeAttributes(elem,{"style":_302}); |
2737 | },setDisplayForElement:function(_304,_305){ | |
2738 | var _306=MochiKit.Base.extend(null,arguments,1); | |
2739 | var _307=MochiKit.DOM.getElement; | |
2740 | for(var i=0;i<_306.length;i++){ | |
2741 | _305=_307(_306[i]); | |
2742 | if(_305){ | |
2743 | _305.style.display=_304; | |
6a1aa64f | 2744 | } |
6a1aa64f | 2745 | } |
79f17b42 DV |
2746 | },getViewportDimensions:function(){ |
2747 | var d=new MochiKit.Style.Dimensions(); | |
2748 | var w=MochiKit.DOM._window; | |
2749 | var b=MochiKit.DOM._document.body; | |
2750 | if(w.innerWidth){ | |
2751 | d.w=w.innerWidth; | |
2752 | d.h=w.innerHeight; | |
2753 | }else{ | |
2754 | if(b.parentElement.clientWidth){ | |
2755 | d.w=b.parentElement.clientWidth; | |
2756 | d.h=b.parentElement.clientHeight; | |
2757 | }else{ | |
2758 | if(b&&b.clientWidth){ | |
2759 | d.w=b.clientWidth; | |
2760 | d.h=b.clientHeight; | |
6a1aa64f | 2761 | } |
6a1aa64f | 2762 | } |
6a1aa64f | 2763 | } |
79f17b42 DV |
2764 | return d; |
2765 | },getViewportPosition:function(){ | |
2766 | var c=new MochiKit.Style.Coordinates(0,0); | |
2767 | var d=MochiKit.DOM._document; | |
2768 | var de=d.documentElement; | |
2769 | var db=d.body; | |
2770 | if(de&&(de.scrollTop||de.scrollLeft)){ | |
2771 | c.x=de.scrollLeft; | |
2772 | c.y=de.scrollTop; | |
6a1aa64f | 2773 | }else{ |
79f17b42 DV |
2774 | if(db){ |
2775 | c.x=db.scrollLeft; | |
2776 | c.y=db.scrollTop; | |
6a1aa64f DV |
2777 | } |
2778 | } | |
79f17b42 DV |
2779 | return c; |
2780 | },__new__:function(){ | |
2781 | var m=MochiKit.Base; | |
2782 | this.elementPosition=this.getElementPosition; | |
2783 | this.elementDimensions=this.getElementDimensions; | |
2784 | this.hideElement=m.partial(this.setDisplayForElement,"none"); | |
2785 | this.showElement=m.partial(this.setDisplayForElement,"block"); | |
6a1aa64f | 2786 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; |
79f17b42 | 2787 | m.nameFunctions(this); |
6a1aa64f | 2788 | }}); |
79f17b42 DV |
2789 | MochiKit.Style.__new__(); |
2790 | MochiKit.Base._exportSymbols(this,MochiKit.Style); | |
6a1aa64f | 2791 | if(typeof (dojo)!="undefined"){ |
79f17b42 | 2792 | dojo.provide("MochiKit.Color"); |
6a1aa64f DV |
2793 | dojo.require("MochiKit.Base"); |
2794 | dojo.require("MochiKit.DOM"); | |
2795 | dojo.require("MochiKit.Style"); | |
2796 | } | |
2797 | if(typeof (JSAN)!="undefined"){ | |
2798 | JSAN.use("MochiKit.Base",[]); | |
2799 | JSAN.use("MochiKit.DOM",[]); | |
2800 | JSAN.use("MochiKit.Style",[]); | |
2801 | } | |
2802 | try{ | |
2803 | if(typeof (MochiKit.Base)=="undefined"){ | |
2804 | throw ""; | |
2805 | } | |
2806 | } | |
2807 | catch(e){ | |
79f17b42 | 2808 | throw "MochiKit.Color depends on MochiKit.Base"; |
6a1aa64f DV |
2809 | } |
2810 | try{ | |
2811 | if(typeof (MochiKit.DOM)=="undefined"){ | |
2812 | throw ""; | |
2813 | } | |
2814 | } | |
2815 | catch(e){ | |
79f17b42 | 2816 | throw "MochiKit.Color depends on MochiKit.DOM"; |
6a1aa64f DV |
2817 | } |
2818 | try{ | |
2819 | if(typeof (MochiKit.Style)=="undefined"){ | |
2820 | throw ""; | |
2821 | } | |
2822 | } | |
2823 | catch(e){ | |
79f17b42 | 2824 | throw "MochiKit.Color depends on MochiKit.Style"; |
6a1aa64f | 2825 | } |
79f17b42 DV |
2826 | if(typeof (MochiKit.Color)=="undefined"){ |
2827 | MochiKit.Color={}; | |
6a1aa64f | 2828 | } |
79f17b42 DV |
2829 | MochiKit.Color.NAME="MochiKit.Color"; |
2830 | MochiKit.Color.VERSION="1.4"; | |
2831 | MochiKit.Color.__repr__=function(){ | |
2832 | return "["+this.NAME+" "+this.VERSION+"]"; | |
6a1aa64f | 2833 | }; |
79f17b42 | 2834 | MochiKit.Color.toString=function(){ |
6a1aa64f | 2835 | return this.__repr__(); |
79f17b42 | 2836 | }; |
223ddf66 DV |
2837 | MochiKit.Color.Color=function(red,_312,blue,_314){ |
2838 | if(typeof (_314)=="undefined"||_314===null){ | |
2839 | _314=1; | |
6a1aa64f | 2840 | } |
223ddf66 | 2841 | this.rgb={r:red,g:_312,b:blue,a:_314}; |
79f17b42 | 2842 | }; |
223ddf66 | 2843 | MochiKit.Color.Color.prototype={__class__:MochiKit.Color.Color,colorWithAlpha:function(_315){ |
79f17b42 DV |
2844 | var rgb=this.rgb; |
2845 | var m=MochiKit.Color; | |
223ddf66 | 2846 | return m.Color.fromRGB(rgb.r,rgb.g,rgb.b,_315); |
79f17b42 DV |
2847 | },colorWithHue:function(hue){ |
2848 | var hsl=this.asHSL(); | |
2849 | hsl.h=hue; | |
2850 | var m=MochiKit.Color; | |
2851 | return m.Color.fromHSL(hsl); | |
223ddf66 | 2852 | },colorWithSaturation:function(_31b){ |
79f17b42 | 2853 | var hsl=this.asHSL(); |
223ddf66 | 2854 | hsl.s=_31b; |
79f17b42 DV |
2855 | var m=MochiKit.Color; |
2856 | return m.Color.fromHSL(hsl); | |
223ddf66 | 2857 | },colorWithLightness:function(_31e){ |
79f17b42 | 2858 | var hsl=this.asHSL(); |
223ddf66 | 2859 | hsl.l=_31e; |
79f17b42 DV |
2860 | var m=MochiKit.Color; |
2861 | return m.Color.fromHSL(hsl); | |
223ddf66 | 2862 | },darkerColorWithLevel:function(_321){ |
79f17b42 | 2863 | var hsl=this.asHSL(); |
223ddf66 | 2864 | hsl.l=Math.max(hsl.l-_321,0); |
79f17b42 DV |
2865 | var m=MochiKit.Color; |
2866 | return m.Color.fromHSL(hsl); | |
223ddf66 | 2867 | },lighterColorWithLevel:function(_324){ |
79f17b42 | 2868 | var hsl=this.asHSL(); |
223ddf66 | 2869 | hsl.l=Math.min(hsl.l+_324,1); |
79f17b42 DV |
2870 | var m=MochiKit.Color; |
2871 | return m.Color.fromHSL(hsl); | |
223ddf66 DV |
2872 | },blendedColor:function(_327,_328){ |
2873 | if(typeof (_328)=="undefined"||_328===null){ | |
2874 | _328=0.5; | |
6a1aa64f | 2875 | } |
223ddf66 | 2876 | var sf=1-_328; |
79f17b42 | 2877 | var s=this.rgb; |
223ddf66 DV |
2878 | var d=_327.rgb; |
2879 | var df=_328; | |
79f17b42 | 2880 | return MochiKit.Color.Color.fromRGB((s.r*sf)+(d.r*df),(s.g*sf)+(d.g*df),(s.b*sf)+(d.b*df),(s.a*sf)+(d.a*df)); |
223ddf66 | 2881 | },compareRGB:function(_32d){ |
79f17b42 | 2882 | var a=this.asRGB(); |
223ddf66 | 2883 | var b=_32d.asRGB(); |
79f17b42 DV |
2884 | return MochiKit.Base.compare([a.r,a.g,a.b,a.a],[b.r,b.g,b.b,b.a]); |
2885 | },isLight:function(){ | |
2886 | return this.asHSL().b>0.5; | |
2887 | },isDark:function(){ | |
2888 | return (!this.isLight()); | |
2889 | },toHSLString:function(){ | |
2890 | var c=this.asHSL(); | |
2891 | var ccc=MochiKit.Color.clampColorComponent; | |
2892 | var rval=this._hslString; | |
2893 | if(!rval){ | |
2894 | var mid=(ccc(c.h,360).toFixed(0)+","+ccc(c.s,100).toPrecision(4)+"%"+","+ccc(c.l,100).toPrecision(4)+"%"); | |
2895 | var a=c.a; | |
2896 | if(a>=1){ | |
2897 | a=1; | |
2898 | rval="hsl("+mid+")"; | |
6a1aa64f | 2899 | }else{ |
79f17b42 DV |
2900 | if(a<=0){ |
2901 | a=0; | |
6a1aa64f | 2902 | } |
79f17b42 | 2903 | rval="hsla("+mid+","+a+")"; |
6a1aa64f | 2904 | } |
79f17b42 | 2905 | this._hslString=rval; |
6a1aa64f | 2906 | } |
79f17b42 DV |
2907 | return rval; |
2908 | },toRGBString:function(){ | |
2909 | var c=this.rgb; | |
2910 | var ccc=MochiKit.Color.clampColorComponent; | |
2911 | var rval=this._rgbString; | |
2912 | if(!rval){ | |
2913 | var mid=(ccc(c.r,255).toFixed(0)+","+ccc(c.g,255).toFixed(0)+","+ccc(c.b,255).toFixed(0)); | |
2914 | if(c.a!=1){ | |
2915 | rval="rgba("+mid+","+c.a+")"; | |
6a1aa64f | 2916 | }else{ |
79f17b42 | 2917 | rval="rgb("+mid+")"; |
6a1aa64f | 2918 | } |
79f17b42 | 2919 | this._rgbString=rval; |
6a1aa64f | 2920 | } |
79f17b42 DV |
2921 | return rval; |
2922 | },asRGB:function(){ | |
2923 | return MochiKit.Base.clone(this.rgb); | |
2924 | },toHexString:function(){ | |
2925 | var m=MochiKit.Color; | |
2926 | var c=this.rgb; | |
2927 | var ccc=MochiKit.Color.clampColorComponent; | |
2928 | var rval=this._hexString; | |
2929 | if(!rval){ | |
2930 | rval=("#"+m.toColorPart(ccc(c.r,255))+m.toColorPart(ccc(c.g,255))+m.toColorPart(ccc(c.b,255))); | |
2931 | this._hexString=rval; | |
6a1aa64f | 2932 | } |
79f17b42 DV |
2933 | return rval; |
2934 | },asHSV:function(){ | |
2935 | var hsv=this.hsv; | |
2936 | var c=this.rgb; | |
2937 | if(typeof (hsv)=="undefined"||hsv===null){ | |
2938 | hsv=MochiKit.Color.rgbToHSV(this.rgb); | |
2939 | this.hsv=hsv; | |
6a1aa64f | 2940 | } |
79f17b42 DV |
2941 | return MochiKit.Base.clone(hsv); |
2942 | },asHSL:function(){ | |
2943 | var hsl=this.hsl; | |
2944 | var c=this.rgb; | |
2945 | if(typeof (hsl)=="undefined"||hsl===null){ | |
2946 | hsl=MochiKit.Color.rgbToHSL(this.rgb); | |
2947 | this.hsl=hsl; | |
6a1aa64f | 2948 | } |
79f17b42 | 2949 | return MochiKit.Base.clone(hsl); |
6a1aa64f | 2950 | },toString:function(){ |
79f17b42 DV |
2951 | return this.toRGBString(); |
2952 | },repr:function(){ | |
2953 | var c=this.rgb; | |
2954 | var col=[c.r,c.g,c.b,c.a]; | |
2955 | return this.__class__.NAME+"("+col.join(", ")+")"; | |
2956 | }}; | |
223ddf66 DV |
2957 | MochiKit.Base.update(MochiKit.Color.Color,{fromRGB:function(red,_344,blue,_346){ |
2958 | var _347=MochiKit.Color.Color; | |
79f17b42 DV |
2959 | if(arguments.length==1){ |
2960 | var rgb=red; | |
2961 | red=rgb.r; | |
223ddf66 | 2962 | _344=rgb.g; |
79f17b42 DV |
2963 | blue=rgb.b; |
2964 | if(typeof (rgb.a)=="undefined"){ | |
223ddf66 | 2965 | _346=undefined; |
79f17b42 | 2966 | }else{ |
223ddf66 | 2967 | _346=rgb.a; |
6a1aa64f DV |
2968 | } |
2969 | } | |
223ddf66 DV |
2970 | return new _347(red,_344,blue,_346); |
2971 | },fromHSL:function(hue,_34a,_34b,_34c){ | |
79f17b42 DV |
2972 | var m=MochiKit.Color; |
2973 | return m.Color.fromRGB(m.hslToRGB.apply(m,arguments)); | |
223ddf66 | 2974 | },fromHSV:function(hue,_34f,_350,_351){ |
79f17b42 DV |
2975 | var m=MochiKit.Color; |
2976 | return m.Color.fromRGB(m.hsvToRGB.apply(m,arguments)); | |
2977 | },fromName:function(name){ | |
223ddf66 | 2978 | var _354=MochiKit.Color.Color; |
79f17b42 DV |
2979 | if(name.charAt(0)=="\""){ |
2980 | name=name.substr(1,name.length-2); | |
6a1aa64f | 2981 | } |
223ddf66 DV |
2982 | var _355=_354._namedColors[name.toLowerCase()]; |
2983 | if(typeof (_355)=="string"){ | |
2984 | return _354.fromHexString(_355); | |
6a1aa64f | 2985 | }else{ |
79f17b42 | 2986 | if(name=="transparent"){ |
223ddf66 | 2987 | return _354.transparentColor(); |
6a1aa64f | 2988 | } |
79f17b42 DV |
2989 | } |
2990 | return null; | |
223ddf66 | 2991 | },fromString:function(_356){ |
79f17b42 | 2992 | var self=MochiKit.Color.Color; |
223ddf66 DV |
2993 | var _358=_356.substr(0,3); |
2994 | if(_358=="rgb"){ | |
2995 | return self.fromRGBString(_356); | |
6a1aa64f | 2996 | }else{ |
223ddf66 DV |
2997 | if(_358=="hsl"){ |
2998 | return self.fromHSLString(_356); | |
6a1aa64f | 2999 | }else{ |
223ddf66 DV |
3000 | if(_356.charAt(0)=="#"){ |
3001 | return self.fromHexString(_356); | |
6a1aa64f DV |
3002 | } |
3003 | } | |
6a1aa64f | 3004 | } |
223ddf66 DV |
3005 | return self.fromName(_356); |
3006 | },fromHexString:function(_359){ | |
3007 | if(_359.charAt(0)=="#"){ | |
3008 | _359=_359.substring(1); | |
6a1aa64f | 3009 | } |
223ddf66 | 3010 | var _35a=[]; |
79f17b42 | 3011 | var i,hex; |
223ddf66 | 3012 | if(_359.length==3){ |
79f17b42 | 3013 | for(i=0;i<3;i++){ |
223ddf66 DV |
3014 | hex=_359.substr(i,1); |
3015 | _35a.push(parseInt(hex+hex,16)/255); | |
6a1aa64f | 3016 | } |
6a1aa64f | 3017 | }else{ |
79f17b42 | 3018 | for(i=0;i<6;i+=2){ |
223ddf66 DV |
3019 | hex=_359.substr(i,2); |
3020 | _35a.push(parseInt(hex,16)/255); | |
6a1aa64f | 3021 | } |
6a1aa64f | 3022 | } |
223ddf66 DV |
3023 | var _35d=MochiKit.Color.Color; |
3024 | return _35d.fromRGB.apply(_35d,_35a); | |
3025 | },_fromColorString:function(pre,_35f,_360,_361){ | |
3026 | if(_361.indexOf(pre)===0){ | |
3027 | _361=_361.substring(_361.indexOf("(",3)+1,_361.length-1); | |
6a1aa64f | 3028 | } |
223ddf66 DV |
3029 | var _362=_361.split(/\s*,\s*/); |
3030 | var _363=[]; | |
3031 | for(var i=0;i<_362.length;i++){ | |
3032 | var c=_362[i]; | |
79f17b42 | 3033 | var val; |
223ddf66 | 3034 | var _367=c.substring(c.length-3); |
79f17b42 DV |
3035 | if(c.charAt(c.length-1)=="%"){ |
3036 | val=0.01*parseFloat(c.substring(0,c.length-1)); | |
6a1aa64f | 3037 | }else{ |
223ddf66 | 3038 | if(_367=="deg"){ |
79f17b42 | 3039 | val=parseFloat(c)/360; |
6a1aa64f | 3040 | }else{ |
223ddf66 | 3041 | if(_367=="rad"){ |
79f17b42 | 3042 | val=parseFloat(c)/(Math.PI*2); |
6a1aa64f | 3043 | }else{ |
223ddf66 | 3044 | val=_360[i]*parseFloat(c); |
6a1aa64f | 3045 | } |
6a1aa64f | 3046 | } |
6a1aa64f | 3047 | } |
223ddf66 | 3048 | _363.push(val); |
6a1aa64f | 3049 | } |
223ddf66 DV |
3050 | return this[_35f].apply(this,_363); |
3051 | },fromComputedStyle:function(elem,_369){ | |
79f17b42 DV |
3052 | var d=MochiKit.DOM; |
3053 | var cls=MochiKit.Color.Color; | |
3054 | for(elem=d.getElement(elem);elem;elem=elem.parentNode){ | |
223ddf66 DV |
3055 | var _36c=MochiKit.Style.getStyle.apply(d,arguments); |
3056 | if(!_36c){ | |
79f17b42 | 3057 | continue; |
6a1aa64f | 3058 | } |
223ddf66 DV |
3059 | var _36d=cls.fromString(_36c); |
3060 | if(!_36d){ | |
79f17b42 | 3061 | break; |
6a1aa64f | 3062 | } |
223ddf66 DV |
3063 | if(_36d.asRGB().a>0){ |
3064 | return _36d; | |
6a1aa64f | 3065 | } |
79f17b42 DV |
3066 | } |
3067 | return null; | |
3068 | },fromBackground:function(elem){ | |
3069 | var cls=MochiKit.Color.Color; | |
3070 | return cls.fromComputedStyle(elem,"backgroundColor","background-color")||cls.whiteColor(); | |
3071 | },fromText:function(elem){ | |
3072 | var cls=MochiKit.Color.Color; | |
3073 | return cls.fromComputedStyle(elem,"color","color")||cls.blackColor(); | |
3074 | },namedColors:function(){ | |
3075 | return MochiKit.Base.clone(MochiKit.Color.Color._namedColors); | |
3076 | }}); | |
223ddf66 DV |
3077 | MochiKit.Base.update(MochiKit.Color,{clampColorComponent:function(v,_373){ |
3078 | v*=_373; | |
79f17b42 DV |
3079 | if(v<0){ |
3080 | return 0; | |
6a1aa64f | 3081 | }else{ |
223ddf66 DV |
3082 | if(v>_373){ |
3083 | return _373; | |
6a1aa64f | 3084 | }else{ |
79f17b42 | 3085 | return v; |
6a1aa64f DV |
3086 | } |
3087 | } | |
79f17b42 DV |
3088 | },_hslValue:function(n1,n2,hue){ |
3089 | if(hue>6){ | |
3090 | hue-=6; | |
6a1aa64f | 3091 | }else{ |
79f17b42 DV |
3092 | if(hue<0){ |
3093 | hue+=6; | |
6a1aa64f DV |
3094 | } |
3095 | } | |
79f17b42 DV |
3096 | var val; |
3097 | if(hue<1){ | |
3098 | val=n1+(n2-n1)*hue; | |
6a1aa64f | 3099 | }else{ |
79f17b42 DV |
3100 | if(hue<3){ |
3101 | val=n2; | |
6a1aa64f | 3102 | }else{ |
79f17b42 DV |
3103 | if(hue<4){ |
3104 | val=n1+(n2-n1)*(4-hue); | |
3105 | }else{ | |
3106 | val=n1; | |
6a1aa64f | 3107 | } |
6a1aa64f DV |
3108 | } |
3109 | } | |
79f17b42 | 3110 | return val; |
223ddf66 | 3111 | },hsvToRGB:function(hue,_379,_37a,_37b){ |
79f17b42 DV |
3112 | if(arguments.length==1){ |
3113 | var hsv=hue; | |
3114 | hue=hsv.h; | |
223ddf66 DV |
3115 | _379=hsv.s; |
3116 | _37a=hsv.v; | |
3117 | _37b=hsv.a; | |
6a1aa64f | 3118 | } |
79f17b42 | 3119 | var red; |
223ddf66 | 3120 | var _37e; |
79f17b42 | 3121 | var blue; |
223ddf66 DV |
3122 | if(_379===0){ |
3123 | red=_37a; | |
3124 | _37e=_37a; | |
3125 | blue=_37a; | |
6a1aa64f | 3126 | }else{ |
79f17b42 DV |
3127 | var i=Math.floor(hue*6); |
3128 | var f=(hue*6)-i; | |
223ddf66 DV |
3129 | var p=_37a*(1-_379); |
3130 | var q=_37a*(1-(_379*f)); | |
3131 | var t=_37a*(1-(_379*(1-f))); | |
79f17b42 DV |
3132 | switch(i){ |
3133 | case 1: | |
3134 | red=q; | |
223ddf66 | 3135 | _37e=_37a; |
79f17b42 DV |
3136 | blue=p; |
3137 | break; | |
3138 | case 2: | |
3139 | red=p; | |
223ddf66 | 3140 | _37e=_37a; |
79f17b42 DV |
3141 | blue=t; |
3142 | break; | |
3143 | case 3: | |
3144 | red=p; | |
223ddf66 DV |
3145 | _37e=q; |
3146 | blue=_37a; | |
79f17b42 DV |
3147 | break; |
3148 | case 4: | |
3149 | red=t; | |
223ddf66 DV |
3150 | _37e=p; |
3151 | blue=_37a; | |
79f17b42 DV |
3152 | break; |
3153 | case 5: | |
223ddf66 DV |
3154 | red=_37a; |
3155 | _37e=p; | |
79f17b42 DV |
3156 | blue=q; |
3157 | break; | |
3158 | case 6: | |
3159 | case 0: | |
223ddf66 DV |
3160 | red=_37a; |
3161 | _37e=t; | |
79f17b42 DV |
3162 | blue=p; |
3163 | break; | |
6a1aa64f DV |
3164 | } |
3165 | } | |
223ddf66 DV |
3166 | return {r:red,g:_37e,b:blue,a:_37b}; |
3167 | },hslToRGB:function(hue,_386,_387,_388){ | |
79f17b42 DV |
3168 | if(arguments.length==1){ |
3169 | var hsl=hue; | |
3170 | hue=hsl.h; | |
223ddf66 DV |
3171 | _386=hsl.s; |
3172 | _387=hsl.l; | |
3173 | _388=hsl.a; | |
6a1aa64f | 3174 | } |
79f17b42 | 3175 | var red; |
223ddf66 | 3176 | var _38b; |
79f17b42 | 3177 | var blue; |
223ddf66 DV |
3178 | if(_386===0){ |
3179 | red=_387; | |
3180 | _38b=_387; | |
3181 | blue=_387; | |
79f17b42 DV |
3182 | }else{ |
3183 | var m2; | |
223ddf66 DV |
3184 | if(_387<=0.5){ |
3185 | m2=_387*(1+_386); | |
6a1aa64f | 3186 | }else{ |
223ddf66 | 3187 | m2=_387+_386-(_387*_386); |
6a1aa64f | 3188 | } |
223ddf66 | 3189 | var m1=(2*_387)-m2; |
79f17b42 DV |
3190 | var f=MochiKit.Color._hslValue; |
3191 | var h6=hue*6; | |
3192 | red=f(m1,m2,h6+2); | |
223ddf66 | 3193 | _38b=f(m1,m2,h6); |
79f17b42 | 3194 | blue=f(m1,m2,h6-2); |
6a1aa64f | 3195 | } |
223ddf66 DV |
3196 | return {r:red,g:_38b,b:blue,a:_388}; |
3197 | },rgbToHSV:function(red,_392,blue,_394){ | |
79f17b42 DV |
3198 | if(arguments.length==1){ |
3199 | var rgb=red; | |
3200 | red=rgb.r; | |
223ddf66 | 3201 | _392=rgb.g; |
79f17b42 | 3202 | blue=rgb.b; |
223ddf66 | 3203 | _394=rgb.a; |
6a1aa64f | 3204 | } |
223ddf66 DV |
3205 | var max=Math.max(Math.max(red,_392),blue); |
3206 | var min=Math.min(Math.min(red,_392),blue); | |
79f17b42 | 3207 | var hue; |
223ddf66 DV |
3208 | var _399; |
3209 | var _39a=max; | |
79f17b42 DV |
3210 | if(min==max){ |
3211 | hue=0; | |
223ddf66 | 3212 | _399=0; |
6a1aa64f | 3213 | }else{ |
223ddf66 DV |
3214 | var _39b=(max-min); |
3215 | _399=_39b/max; | |
79f17b42 | 3216 | if(red==max){ |
223ddf66 | 3217 | hue=(_392-blue)/_39b; |
79f17b42 | 3218 | }else{ |
223ddf66 DV |
3219 | if(_392==max){ |
3220 | hue=2+((blue-red)/_39b); | |
6a1aa64f | 3221 | }else{ |
223ddf66 | 3222 | hue=4+((red-_392)/_39b); |
6a1aa64f DV |
3223 | } |
3224 | } | |
79f17b42 DV |
3225 | hue/=6; |
3226 | if(hue<0){ | |
3227 | hue+=1; | |
6a1aa64f | 3228 | } |
79f17b42 DV |
3229 | if(hue>1){ |
3230 | hue-=1; | |
6a1aa64f | 3231 | } |
6a1aa64f | 3232 | } |
223ddf66 DV |
3233 | return {h:hue,s:_399,v:_39a,a:_394}; |
3234 | },rgbToHSL:function(red,_39d,blue,_39f){ | |
79f17b42 DV |
3235 | if(arguments.length==1){ |
3236 | var rgb=red; | |
3237 | red=rgb.r; | |
223ddf66 | 3238 | _39d=rgb.g; |
79f17b42 | 3239 | blue=rgb.b; |
223ddf66 | 3240 | _39f=rgb.a; |
6a1aa64f | 3241 | } |
223ddf66 DV |
3242 | var max=Math.max(red,Math.max(_39d,blue)); |
3243 | var min=Math.min(red,Math.min(_39d,blue)); | |
79f17b42 | 3244 | var hue; |
223ddf66 DV |
3245 | var _3a4; |
3246 | var _3a5=(max+min)/2; | |
3247 | var _3a6=max-min; | |
3248 | if(_3a6===0){ | |
79f17b42 | 3249 | hue=0; |
223ddf66 | 3250 | _3a4=0; |
79f17b42 | 3251 | }else{ |
223ddf66 DV |
3252 | if(_3a5<=0.5){ |
3253 | _3a4=_3a6/(max+min); | |
79f17b42 | 3254 | }else{ |
223ddf66 | 3255 | _3a4=_3a6/(2-max-min); |
6a1aa64f | 3256 | } |
79f17b42 | 3257 | if(red==max){ |
223ddf66 | 3258 | hue=(_39d-blue)/_3a6; |
79f17b42 | 3259 | }else{ |
223ddf66 DV |
3260 | if(_39d==max){ |
3261 | hue=2+((blue-red)/_3a6); | |
79f17b42 | 3262 | }else{ |
223ddf66 | 3263 | hue=4+((red-_39d)/_3a6); |
6a1aa64f | 3264 | } |
6a1aa64f | 3265 | } |
79f17b42 DV |
3266 | hue/=6; |
3267 | if(hue<0){ | |
3268 | hue+=1; | |
6a1aa64f | 3269 | } |
79f17b42 DV |
3270 | if(hue>1){ |
3271 | hue-=1; | |
6a1aa64f | 3272 | } |
6a1aa64f | 3273 | } |
223ddf66 | 3274 | return {h:hue,s:_3a4,l:_3a5,a:_39f}; |
79f17b42 DV |
3275 | },toColorPart:function(num){ |
3276 | num=Math.round(num); | |
223ddf66 | 3277 | var _3a8=num.toString(16); |
79f17b42 | 3278 | if(num<16){ |
223ddf66 | 3279 | return "0"+_3a8; |
6a1aa64f | 3280 | } |
223ddf66 | 3281 | return _3a8; |
79f17b42 | 3282 | },__new__:function(){ |
6a1aa64f | 3283 | var m=MochiKit.Base; |
79f17b42 DV |
3284 | this.Color.fromRGBString=m.bind(this.Color._fromColorString,this.Color,"rgb","fromRGB",[1/255,1/255,1/255,1]); |
3285 | this.Color.fromHSLString=m.bind(this.Color._fromColorString,this.Color,"hsl","fromHSL",[1/360,0.01,0.01,1]); | |
223ddf66 DV |
3286 | var _3aa=1/3; |
3287 | var _3ab={black:[0,0,0],blue:[0,0,1],brown:[0.6,0.4,0.2],cyan:[0,1,1],darkGray:[_3aa,_3aa,_3aa],gray:[0.5,0.5,0.5],green:[0,1,0],lightGray:[2*_3aa,2*_3aa,2*_3aa],magenta:[1,0,1],orange:[1,0.5,0],purple:[0.5,0,0.5],red:[1,0,0],transparent:[0,0,0,0],white:[1,1,1],yellow:[1,1,0]}; | |
3288 | var _3ac=function(name,r,g,b,a){ | |
79f17b42 DV |
3289 | var rval=this.fromRGB(r,g,b,a); |
3290 | this[name]=function(){ | |
3291 | return rval; | |
3292 | }; | |
3293 | return rval; | |
3294 | }; | |
223ddf66 | 3295 | for(var k in _3ab){ |
79f17b42 | 3296 | var name=k+"Color"; |
223ddf66 DV |
3297 | var _3b5=m.concat([_3ac,this.Color,name],_3ab[k]); |
3298 | this.Color[name]=m.bind.apply(null,_3b5); | |
6a1aa64f | 3299 | } |
223ddf66 | 3300 | var _3b6=function(){ |
79f17b42 DV |
3301 | for(var i=0;i<arguments.length;i++){ |
3302 | if(!(arguments[i] instanceof Color)){ | |
3303 | return false; | |
6a1aa64f | 3304 | } |
6a1aa64f | 3305 | } |
79f17b42 DV |
3306 | return true; |
3307 | }; | |
223ddf66 | 3308 | var _3b8=function(a,b){ |
79f17b42 DV |
3309 | return a.compareRGB(b); |
3310 | }; | |
3311 | m.nameFunctions(this); | |
223ddf66 | 3312 | m.registerComparator(this.Color.NAME,_3b6,_3b8); |
79f17b42 DV |
3313 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; |
3314 | }}); | |
3315 | MochiKit.Color.EXPORT=["Color"]; | |
3316 | MochiKit.Color.EXPORT_OK=["clampColorComponent","rgbToHSL","hslToRGB","rgbToHSV","hsvToRGB","toColorPart"]; | |
3317 | MochiKit.Color.__new__(); | |
3318 | MochiKit.Base._exportSymbols(this,MochiKit.Color); | |
3319 | MochiKit.Color.Color._namedColors={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"}; | |
6a1aa64f | 3320 | if(typeof (dojo)!="undefined"){ |
79f17b42 | 3321 | dojo.provide("MochiKit.Signal"); |
6a1aa64f DV |
3322 | dojo.require("MochiKit.Base"); |
3323 | dojo.require("MochiKit.DOM"); | |
3324 | dojo.require("MochiKit.Style"); | |
3325 | } | |
3326 | if(typeof (JSAN)!="undefined"){ | |
3327 | JSAN.use("MochiKit.Base",[]); | |
3328 | JSAN.use("MochiKit.DOM",[]); | |
3329 | JSAN.use("MochiKit.Style",[]); | |
3330 | } | |
3331 | try{ | |
79f17b42 | 3332 | if(typeof (MochiKit.Base)=="undefined"){ |
6a1aa64f DV |
3333 | throw ""; |
3334 | } | |
3335 | } | |
3336 | catch(e){ | |
79f17b42 | 3337 | throw "MochiKit.Signal depends on MochiKit.Base!"; |
6a1aa64f | 3338 | } |
79f17b42 DV |
3339 | try{ |
3340 | if(typeof (MochiKit.DOM)=="undefined"){ | |
3341 | throw ""; | |
6a1aa64f | 3342 | } |
6a1aa64f | 3343 | } |
79f17b42 DV |
3344 | catch(e){ |
3345 | throw "MochiKit.Signal depends on MochiKit.DOM!"; | |
6a1aa64f | 3346 | } |
79f17b42 DV |
3347 | try{ |
3348 | if(typeof (MochiKit.Style)=="undefined"){ | |
3349 | throw ""; | |
6a1aa64f DV |
3350 | } |
3351 | } | |
79f17b42 DV |
3352 | catch(e){ |
3353 | throw "MochiKit.Signal depends on MochiKit.Style!"; | |
6a1aa64f | 3354 | } |
79f17b42 DV |
3355 | if(typeof (MochiKit.Signal)=="undefined"){ |
3356 | MochiKit.Signal={}; | |
6a1aa64f | 3357 | } |
79f17b42 DV |
3358 | MochiKit.Signal.NAME="MochiKit.Signal"; |
3359 | MochiKit.Signal.VERSION="1.4"; | |
3360 | MochiKit.Signal._observers=[]; | |
3361 | MochiKit.Signal.Event=function(src,e){ | |
3362 | this._event=e||window.event; | |
3363 | this._src=src; | |
6a1aa64f | 3364 | }; |
79f17b42 DV |
3365 | MochiKit.Base.update(MochiKit.Signal.Event.prototype,{__repr__:function(){ |
3366 | var repr=MochiKit.Base.repr; | |
3367 | var str="{event(): "+repr(this.event())+", src(): "+repr(this.src())+", type(): "+repr(this.type())+", target(): "+repr(this.target()); | |
3368 | if(this.type()&&this.type().indexOf("key")===0||this.type().indexOf("mouse")===0||this.type().indexOf("click")!=-1||this.type()=="contextmenu"){ | |
3369 | str+=", modifier(): "+"{alt: "+repr(this.modifier().alt)+", ctrl: "+repr(this.modifier().ctrl)+", meta: "+repr(this.modifier().meta)+", shift: "+repr(this.modifier().shift)+", any: "+repr(this.modifier().any)+"}"; | |
6a1aa64f | 3370 | } |
79f17b42 DV |
3371 | if(this.type()&&this.type().indexOf("key")===0){ |
3372 | str+=", key(): {code: "+repr(this.key().code)+", string: "+repr(this.key().string)+"}"; | |
6a1aa64f | 3373 | } |
79f17b42 DV |
3374 | if(this.type()&&(this.type().indexOf("mouse")===0||this.type().indexOf("click")!=-1||this.type()=="contextmenu")){ |
3375 | str+=", mouse(): {page: "+repr(this.mouse().page)+", client: "+repr(this.mouse().client); | |
3376 | if(this.type()!="mousemove"){ | |
3377 | str+=", button: {left: "+repr(this.mouse().button.left)+", middle: "+repr(this.mouse().button.middle)+", right: "+repr(this.mouse().button.right)+"}}"; | |
3378 | }else{ | |
3379 | str+="}"; | |
6a1aa64f | 3380 | } |
6a1aa64f | 3381 | } |
79f17b42 DV |
3382 | if(this.type()=="mouseover"||this.type()=="mouseout"){ |
3383 | str+=", relatedTarget(): "+repr(this.relatedTarget()); | |
6a1aa64f | 3384 | } |
79f17b42 DV |
3385 | str+="}"; |
3386 | return str; | |
3387 | },toString:function(){ | |
6a1aa64f | 3388 | return this.__repr__(); |
79f17b42 DV |
3389 | },src:function(){ |
3390 | return this._src; | |
3391 | },event:function(){ | |
3392 | return this._event; | |
3393 | },type:function(){ | |
3394 | return this._event.type||undefined; | |
3395 | },target:function(){ | |
3396 | return this._event.target||this._event.srcElement; | |
3397 | },_relatedTarget:null,relatedTarget:function(){ | |
3398 | if(this._relatedTarget!==null){ | |
3399 | return this._relatedTarget; | |
6a1aa64f | 3400 | } |
79f17b42 DV |
3401 | var elem=null; |
3402 | if(this.type()=="mouseover"){ | |
3403 | elem=(this._event.relatedTarget||this._event.fromElement); | |
6a1aa64f | 3404 | }else{ |
79f17b42 DV |
3405 | if(this.type()=="mouseout"){ |
3406 | elem=(this._event.relatedTarget||this._event.toElement); | |
3407 | } | |
3408 | } | |
3409 | if(elem!==null){ | |
3410 | this._relatedTarget=elem; | |
3411 | return elem; | |
3412 | } | |
3413 | return undefined; | |
3414 | },_modifier:null,modifier:function(){ | |
3415 | if(this._modifier!==null){ | |
3416 | return this._modifier; | |
6a1aa64f | 3417 | } |
79f17b42 DV |
3418 | var m={}; |
3419 | m.alt=this._event.altKey; | |
3420 | m.ctrl=this._event.ctrlKey; | |
3421 | m.meta=this._event.metaKey||false; | |
3422 | m.shift=this._event.shiftKey; | |
3423 | m.any=m.alt||m.ctrl||m.shift||m.meta; | |
3424 | this._modifier=m; | |
3425 | return m; | |
3426 | },_key:null,key:function(){ | |
3427 | if(this._key!==null){ | |
3428 | return this._key; | |
6a1aa64f | 3429 | } |
79f17b42 DV |
3430 | var k={}; |
3431 | if(this.type()&&this.type().indexOf("key")===0){ | |
3432 | if(this.type()=="keydown"||this.type()=="keyup"){ | |
3433 | k.code=this._event.keyCode; | |
3434 | k.string=(MochiKit.Signal._specialKeys[k.code]||"KEY_UNKNOWN"); | |
3435 | this._key=k; | |
3436 | return k; | |
3437 | }else{ | |
3438 | if(this.type()=="keypress"){ | |
3439 | k.code=0; | |
3440 | k.string=""; | |
3441 | if(typeof (this._event.charCode)!="undefined"&&this._event.charCode!==0&&!MochiKit.Signal._specialMacKeys[this._event.charCode]){ | |
3442 | k.code=this._event.charCode; | |
3443 | k.string=String.fromCharCode(k.code); | |
6a1aa64f | 3444 | }else{ |
79f17b42 DV |
3445 | if(this._event.keyCode&&typeof (this._event.charCode)=="undefined"){ |
3446 | k.code=this._event.keyCode; | |
3447 | k.string=String.fromCharCode(k.code); | |
6a1aa64f DV |
3448 | } |
3449 | } | |
79f17b42 DV |
3450 | this._key=k; |
3451 | return k; | |
6a1aa64f | 3452 | } |
6a1aa64f DV |
3453 | } |
3454 | } | |
79f17b42 DV |
3455 | return undefined; |
3456 | },_mouse:null,mouse:function(){ | |
3457 | if(this._mouse!==null){ | |
3458 | return this._mouse; | |
6a1aa64f | 3459 | } |
79f17b42 DV |
3460 | var m={}; |
3461 | var e=this._event; | |
3462 | if(this.type()&&(this.type().indexOf("mouse")===0||this.type().indexOf("click")!=-1||this.type()=="contextmenu")){ | |
3463 | m.client=new MochiKit.Style.Coordinates(0,0); | |
3464 | if(e.clientX||e.clientY){ | |
3465 | m.client.x=(!e.clientX||e.clientX<0)?0:e.clientX; | |
3466 | m.client.y=(!e.clientY||e.clientY<0)?0:e.clientY; | |
3467 | } | |
3468 | m.page=new MochiKit.Style.Coordinates(0,0); | |
3469 | if(e.pageX||e.pageY){ | |
3470 | m.page.x=(!e.pageX||e.pageX<0)?0:e.pageX; | |
3471 | m.page.y=(!e.pageY||e.pageY<0)?0:e.pageY; | |
6a1aa64f | 3472 | }else{ |
79f17b42 DV |
3473 | var de=MochiKit.DOM._document.documentElement; |
3474 | var b=MochiKit.DOM._document.body; | |
3475 | m.page.x=e.clientX+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0); | |
3476 | m.page.y=e.clientY+(de.scrollTop||b.scrollTop)-(de.clientTop||0); | |
3477 | } | |
3478 | if(this.type()!="mousemove"){ | |
3479 | m.button={}; | |
3480 | m.button.left=false; | |
3481 | m.button.right=false; | |
3482 | m.button.middle=false; | |
3483 | if(e.which){ | |
3484 | m.button.left=(e.which==1); | |
3485 | m.button.middle=(e.which==2); | |
3486 | m.button.right=(e.which==3); | |
6a1aa64f | 3487 | }else{ |
79f17b42 DV |
3488 | m.button.left=!!(e.button&1); |
3489 | m.button.right=!!(e.button&2); | |
3490 | m.button.middle=!!(e.button&4); | |
6a1aa64f DV |
3491 | } |
3492 | } | |
79f17b42 DV |
3493 | this._mouse=m; |
3494 | return m; | |
6a1aa64f | 3495 | } |
79f17b42 DV |
3496 | return undefined; |
3497 | },stop:function(){ | |
3498 | this.stopPropagation(); | |
3499 | this.preventDefault(); | |
3500 | },stopPropagation:function(){ | |
3501 | if(this._event.stopPropagation){ | |
3502 | this._event.stopPropagation(); | |
6a1aa64f | 3503 | }else{ |
79f17b42 DV |
3504 | this._event.cancelBubble=true; |
3505 | } | |
3506 | },preventDefault:function(){ | |
3507 | if(this._event.preventDefault){ | |
3508 | this._event.preventDefault(); | |
6a1aa64f | 3509 | }else{ |
79f17b42 DV |
3510 | if(this._confirmUnload===null){ |
3511 | this._event.returnValue=false; | |
3512 | } | |
6a1aa64f | 3513 | } |
79f17b42 DV |
3514 | },_confirmUnload:null,confirmUnload:function(msg){ |
3515 | if(this.type()=="beforeunload"){ | |
3516 | this._confirmUnload=msg; | |
3517 | this._event.returnValue=msg; | |
6a1aa64f | 3518 | } |
79f17b42 DV |
3519 | }}); |
3520 | MochiKit.Signal._specialMacKeys={3:"KEY_ENTER",63289:"KEY_NUM_PAD_CLEAR",63276:"KEY_PAGE_UP",63277:"KEY_PAGE_DOWN",63275:"KEY_END",63273:"KEY_HOME",63234:"KEY_ARROW_LEFT",63232:"KEY_ARROW_UP",63235:"KEY_ARROW_RIGHT",63233:"KEY_ARROW_DOWN",63302:"KEY_INSERT",63272:"KEY_DELETE"}; | |
3521 | (function(){ | |
223ddf66 | 3522 | var _3c7=MochiKit.Signal._specialMacKeys; |
79f17b42 | 3523 | for(i=63236;i<=63242;i++){ |
223ddf66 | 3524 | _3c7[i]="KEY_F"+(i-63236+1); |
6a1aa64f | 3525 | } |
79f17b42 DV |
3526 | })(); |
3527 | MochiKit.Signal._specialKeys={8:"KEY_BACKSPACE",9:"KEY_TAB",12:"KEY_NUM_PAD_CLEAR",13:"KEY_ENTER",16:"KEY_SHIFT",17:"KEY_CTRL",18:"KEY_ALT",19:"KEY_PAUSE",20:"KEY_CAPS_LOCK",27:"KEY_ESCAPE",32:"KEY_SPACEBAR",33:"KEY_PAGE_UP",34:"KEY_PAGE_DOWN",35:"KEY_END",36:"KEY_HOME",37:"KEY_ARROW_LEFT",38:"KEY_ARROW_UP",39:"KEY_ARROW_RIGHT",40:"KEY_ARROW_DOWN",44:"KEY_PRINT_SCREEN",45:"KEY_INSERT",46:"KEY_DELETE",59:"KEY_SEMICOLON",91:"KEY_WINDOWS_LEFT",92:"KEY_WINDOWS_RIGHT",93:"KEY_SELECT",106:"KEY_NUM_PAD_ASTERISK",107:"KEY_NUM_PAD_PLUS_SIGN",109:"KEY_NUM_PAD_HYPHEN-MINUS",110:"KEY_NUM_PAD_FULL_STOP",111:"KEY_NUM_PAD_SOLIDUS",144:"KEY_NUM_LOCK",145:"KEY_SCROLL_LOCK",186:"KEY_SEMICOLON",187:"KEY_EQUALS_SIGN",188:"KEY_COMMA",189:"KEY_HYPHEN-MINUS",190:"KEY_FULL_STOP",191:"KEY_SOLIDUS",192:"KEY_GRAVE_ACCENT",219:"KEY_LEFT_SQUARE_BRACKET",220:"KEY_REVERSE_SOLIDUS",221:"KEY_RIGHT_SQUARE_BRACKET",222:"KEY_APOSTROPHE"}; | |
3528 | (function(){ | |
223ddf66 | 3529 | var _3c8=MochiKit.Signal._specialKeys; |
79f17b42 | 3530 | for(var i=48;i<=57;i++){ |
223ddf66 | 3531 | _3c8[i]="KEY_"+(i-48); |
6a1aa64f | 3532 | } |
79f17b42 | 3533 | for(i=65;i<=90;i++){ |
223ddf66 | 3534 | _3c8[i]="KEY_"+String.fromCharCode(i); |
6a1aa64f | 3535 | } |
79f17b42 | 3536 | for(i=96;i<=105;i++){ |
223ddf66 | 3537 | _3c8[i]="KEY_NUM_PAD_"+(i-96); |
6a1aa64f | 3538 | } |
79f17b42 | 3539 | for(i=112;i<=123;i++){ |
223ddf66 | 3540 | _3c8[i]="KEY_F"+(i-112+1); |
6a1aa64f | 3541 | } |
79f17b42 | 3542 | })(); |
223ddf66 DV |
3543 | MochiKit.Signal.Ident=function(_3ca){ |
3544 | this.source=_3ca.source; | |
3545 | this.signal=_3ca.signal; | |
3546 | this.listener=_3ca.listener; | |
3547 | this.isDOM=_3ca.isDOM; | |
3548 | this.objOrFunc=_3ca.objOrFunc; | |
3549 | this.funcOrStr=_3ca.funcOrStr; | |
3550 | this.connected=_3ca.connected; | |
6a1aa64f | 3551 | }; |
79f17b42 DV |
3552 | MochiKit.Signal.Ident.prototype={}; |
3553 | MochiKit.Base.update(MochiKit.Signal,{__repr__:function(){ | |
3554 | return "["+this.NAME+" "+this.VERSION+"]"; | |
3555 | },toString:function(){ | |
3556 | return this.__repr__(); | |
3557 | },_unloadCache:function(){ | |
3558 | var self=MochiKit.Signal; | |
223ddf66 DV |
3559 | var _3cc=self._observers; |
3560 | for(var i=0;i<_3cc.length;i++){ | |
3561 | if(_3cc[i].signal!=="onload"&&_3cc[i].signal!=="onunload"){ | |
3562 | self._disconnect(_3cc[i]); | |
6a1aa64f | 3563 | } |
6a1aa64f | 3564 | } |
223ddf66 | 3565 | },_listener:function(src,sig,func,obj,_3d2){ |
79f17b42 DV |
3566 | var self=MochiKit.Signal; |
3567 | var E=self.Event; | |
223ddf66 | 3568 | if(!_3d2){ |
79f17b42 | 3569 | return MochiKit.Base.bind(func,obj); |
6a1aa64f | 3570 | } |
79f17b42 DV |
3571 | obj=obj||src; |
3572 | if(typeof (func)=="string"){ | |
3573 | if(sig==="onload"||sig==="onunload"){ | |
223ddf66 DV |
3574 | return function(_3d5){ |
3575 | obj[func].apply(obj,[new E(src,_3d5)]); | |
3576 | var _3d6=new MochiKit.Signal.Ident({source:src,signal:sig,objOrFunc:obj,funcOrStr:func}); | |
3577 | MochiKit.Signal._disconnect(_3d6); | |
6a1aa64f | 3578 | }; |
79f17b42 | 3579 | }else{ |
223ddf66 DV |
3580 | return function(_3d7){ |
3581 | obj[func].apply(obj,[new E(src,_3d7)]); | |
6a1aa64f | 3582 | }; |
6a1aa64f | 3583 | } |
79f17b42 DV |
3584 | }else{ |
3585 | if(sig==="onload"||sig==="onunload"){ | |
223ddf66 DV |
3586 | return function(_3d8){ |
3587 | func.apply(obj,[new E(src,_3d8)]); | |
79f17b42 | 3588 | MochiKit.Signal.disconnect(src,sig,func); |
223ddf66 DV |
3589 | var _3d9=new MochiKit.Signal.Ident({source:src,signal:sig,objOrFunc:func}); |
3590 | MochiKit.Signal._disconnect(_3d9); | |
6a1aa64f | 3591 | }; |
79f17b42 | 3592 | }else{ |
223ddf66 DV |
3593 | return function(_3da){ |
3594 | func.apply(obj,[new E(src,_3da)]); | |
6a1aa64f | 3595 | }; |
6a1aa64f | 3596 | } |
6a1aa64f | 3597 | } |
79f17b42 DV |
3598 | },_browserAlreadyHasMouseEnterAndLeave:function(){ |
3599 | return /MSIE/.test(navigator.userAgent); | |
3600 | },_mouseEnterListener:function(src,sig,func,obj){ | |
3601 | var E=MochiKit.Signal.Event; | |
223ddf66 DV |
3602 | return function(_3e0){ |
3603 | var e=new E(src,_3e0); | |
79f17b42 DV |
3604 | try{ |
3605 | e.relatedTarget().nodeName; | |
6a1aa64f | 3606 | } |
79f17b42 DV |
3607 | catch(err){ |
3608 | return; | |
6a1aa64f | 3609 | } |
79f17b42 DV |
3610 | e.stop(); |
3611 | if(MochiKit.DOM.isChildNode(e.relatedTarget(),src)){ | |
3612 | return; | |
6a1aa64f | 3613 | } |
79f17b42 DV |
3614 | e.type=function(){ |
3615 | return sig; | |
6a1aa64f | 3616 | }; |
79f17b42 DV |
3617 | if(typeof (func)=="string"){ |
3618 | return obj[func].apply(obj,[e]); | |
3619 | }else{ | |
3620 | return func.apply(obj,[e]); | |
6a1aa64f | 3621 | } |
6a1aa64f | 3622 | }; |
223ddf66 | 3623 | },_getDestPair:function(_3e2,_3e3){ |
79f17b42 DV |
3624 | var obj=null; |
3625 | var func=null; | |
223ddf66 DV |
3626 | if(typeof (_3e3)!="undefined"){ |
3627 | obj=_3e2; | |
3628 | func=_3e3; | |
3629 | if(typeof (_3e3)=="string"){ | |
3630 | if(typeof (_3e2[_3e3])!="function"){ | |
79f17b42 | 3631 | throw new Error("'funcOrStr' must be a function on 'objOrFunc'"); |
6a1aa64f | 3632 | } |
79f17b42 | 3633 | }else{ |
223ddf66 | 3634 | if(typeof (_3e3)!="function"){ |
79f17b42 | 3635 | throw new Error("'funcOrStr' must be a function or string"); |
6a1aa64f | 3636 | } |
6a1aa64f | 3637 | } |
79f17b42 | 3638 | }else{ |
223ddf66 | 3639 | if(typeof (_3e2)!="function"){ |
79f17b42 DV |
3640 | throw new Error("'objOrFunc' must be a function if 'funcOrStr' is not given"); |
3641 | }else{ | |
223ddf66 | 3642 | func=_3e2; |
6a1aa64f | 3643 | } |
6a1aa64f | 3644 | } |
79f17b42 | 3645 | return [obj,func]; |
223ddf66 | 3646 | },connect:function(src,sig,_3e8,_3e9){ |
79f17b42 DV |
3647 | src=MochiKit.DOM.getElement(src); |
3648 | var self=MochiKit.Signal; | |
3649 | if(typeof (sig)!="string"){ | |
3650 | throw new Error("'sig' must be a string"); | |
6a1aa64f | 3651 | } |
223ddf66 DV |
3652 | var _3eb=self._getDestPair(_3e8,_3e9); |
3653 | var obj=_3eb[0]; | |
3654 | var func=_3eb[1]; | |
79f17b42 DV |
3655 | if(typeof (obj)=="undefined"||obj===null){ |
3656 | obj=src; | |
6a1aa64f | 3657 | } |
223ddf66 DV |
3658 | var _3ee=!!(src.addEventListener||src.attachEvent); |
3659 | if(_3ee&&(sig==="onmouseenter"||sig==="onmouseleave")&&!self._browserAlreadyHasMouseEnterAndLeave()){ | |
3660 | var _3ef=self._mouseEnterListener(src,sig.substr(2),func,obj); | |
79f17b42 DV |
3661 | if(sig==="onmouseenter"){ |
3662 | sig="onmouseover"; | |
3663 | }else{ | |
3664 | sig="onmouseout"; | |
6a1aa64f DV |
3665 | } |
3666 | }else{ | |
223ddf66 | 3667 | var _3ef=self._listener(src,sig,func,obj,_3ee); |
6a1aa64f | 3668 | } |
79f17b42 | 3669 | if(src.addEventListener){ |
223ddf66 | 3670 | src.addEventListener(sig.substr(2),_3ef,false); |
79f17b42 DV |
3671 | }else{ |
3672 | if(src.attachEvent){ | |
223ddf66 | 3673 | src.attachEvent(sig,_3ef); |
6a1aa64f DV |
3674 | } |
3675 | } | |
223ddf66 DV |
3676 | var _3f0=new MochiKit.Signal.Ident({source:src,signal:sig,listener:_3ef,isDOM:_3ee,objOrFunc:_3e8,funcOrStr:_3e9,connected:true}); |
3677 | self._observers.push(_3f0); | |
3678 | if(!_3ee&&typeof (src.__connect__)=="function"){ | |
3679 | var args=MochiKit.Base.extend([_3f0],arguments,1); | |
79f17b42 | 3680 | src.__connect__.apply(src,args); |
6a1aa64f | 3681 | } |
223ddf66 DV |
3682 | return _3f0; |
3683 | },_disconnect:function(_3f2){ | |
3684 | if(!_3f2.connected){ | |
79f17b42 | 3685 | return; |
6a1aa64f | 3686 | } |
223ddf66 DV |
3687 | _3f2.connected=false; |
3688 | if(!_3f2.isDOM){ | |
6a1aa64f DV |
3689 | return; |
3690 | } | |
223ddf66 DV |
3691 | var src=_3f2.source; |
3692 | var sig=_3f2.signal; | |
3693 | var _3f5=_3f2.listener; | |
79f17b42 | 3694 | if(src.removeEventListener){ |
223ddf66 | 3695 | src.removeEventListener(sig.substr(2),_3f5,false); |
79f17b42 DV |
3696 | }else{ |
3697 | if(src.detachEvent){ | |
223ddf66 | 3698 | src.detachEvent(sig,_3f5); |
79f17b42 DV |
3699 | }else{ |
3700 | throw new Error("'src' must be a DOM element"); | |
6a1aa64f | 3701 | } |
6a1aa64f | 3702 | } |
223ddf66 | 3703 | },disconnect:function(_3f6){ |
79f17b42 | 3704 | var self=MochiKit.Signal; |
223ddf66 | 3705 | var _3f8=self._observers; |
79f17b42 DV |
3706 | var m=MochiKit.Base; |
3707 | if(arguments.length>1){ | |
3708 | var src=MochiKit.DOM.getElement(arguments[0]); | |
3709 | var sig=arguments[1]; | |
3710 | var obj=arguments[2]; | |
3711 | var func=arguments[3]; | |
223ddf66 DV |
3712 | for(var i=_3f8.length-1;i>=0;i--){ |
3713 | var o=_3f8[i]; | |
79f17b42 DV |
3714 | if(o.source===src&&o.signal===sig&&o.objOrFunc===obj&&o.funcOrStr===func){ |
3715 | self._disconnect(o); | |
3716 | if(!self._lock){ | |
223ddf66 | 3717 | _3f8.splice(i,1); |
79f17b42 DV |
3718 | }else{ |
3719 | self._dirty=true; | |
6a1aa64f | 3720 | } |
79f17b42 | 3721 | return true; |
6a1aa64f | 3722 | } |
6a1aa64f | 3723 | } |
6a1aa64f | 3724 | }else{ |
223ddf66 | 3725 | var idx=m.findIdentical(_3f8,_3f6); |
79f17b42 | 3726 | if(idx>=0){ |
223ddf66 | 3727 | self._disconnect(_3f6); |
79f17b42 | 3728 | if(!self._lock){ |
223ddf66 | 3729 | _3f8.splice(idx,1); |
79f17b42 DV |
3730 | }else{ |
3731 | self._dirty=true; | |
6a1aa64f | 3732 | } |
79f17b42 | 3733 | return true; |
6a1aa64f | 3734 | } |
6a1aa64f | 3735 | } |
79f17b42 | 3736 | return false; |
223ddf66 | 3737 | },disconnectAllTo:function(_401,_402){ |
79f17b42 | 3738 | var self=MochiKit.Signal; |
223ddf66 DV |
3739 | var _404=self._observers; |
3740 | var _405=self._disconnect; | |
3741 | var _406=self._lock; | |
3742 | var _407=self._dirty; | |
3743 | if(typeof (_402)==="undefined"){ | |
3744 | _402=null; | |
79f17b42 | 3745 | } |
223ddf66 DV |
3746 | for(var i=_404.length-1;i>=0;i--){ |
3747 | var _409=_404[i]; | |
3748 | if(_409.objOrFunc===_401&&(_402===null||_409.funcOrStr===_402)){ | |
3749 | _405(_409); | |
3750 | if(_406){ | |
3751 | _407=true; | |
79f17b42 | 3752 | }else{ |
223ddf66 | 3753 | _404.splice(i,1); |
79f17b42 DV |
3754 | } |
3755 | } | |
3756 | } | |
223ddf66 | 3757 | self._dirty=_407; |
79f17b42 DV |
3758 | },disconnectAll:function(src,sig){ |
3759 | src=MochiKit.DOM.getElement(src); | |
6a1aa64f | 3760 | var m=MochiKit.Base; |
223ddf66 | 3761 | var _40d=m.flattenArguments(m.extend(null,arguments,1)); |
79f17b42 | 3762 | var self=MochiKit.Signal; |
223ddf66 DV |
3763 | var _40f=self._disconnect; |
3764 | var _410=self._observers; | |
3765 | var i,_412; | |
3766 | var _413=self._lock; | |
3767 | var _414=self._dirty; | |
3768 | if(_40d.length===0){ | |
3769 | for(i=_410.length-1;i>=0;i--){ | |
3770 | _412=_410[i]; | |
3771 | if(_412.source===src){ | |
3772 | _40f(_412); | |
3773 | if(!_413){ | |
3774 | _410.splice(i,1); | |
79f17b42 | 3775 | }else{ |
223ddf66 | 3776 | _414=true; |
6a1aa64f | 3777 | } |
6a1aa64f | 3778 | } |
6a1aa64f | 3779 | } |
79f17b42 DV |
3780 | }else{ |
3781 | var sigs={}; | |
223ddf66 DV |
3782 | for(i=0;i<_40d.length;i++){ |
3783 | sigs[_40d[i]]=true; | |
6a1aa64f | 3784 | } |
223ddf66 DV |
3785 | for(i=_410.length-1;i>=0;i--){ |
3786 | _412=_410[i]; | |
3787 | if(_412.source===src&&_412.signal in sigs){ | |
3788 | _40f(_412); | |
3789 | if(!_413){ | |
3790 | _410.splice(i,1); | |
79f17b42 | 3791 | }else{ |
223ddf66 | 3792 | _414=true; |
6a1aa64f | 3793 | } |
6a1aa64f | 3794 | } |
6a1aa64f | 3795 | } |
6a1aa64f | 3796 | } |
223ddf66 | 3797 | self._dirty=_414; |
79f17b42 DV |
3798 | },signal:function(src,sig){ |
3799 | var self=MochiKit.Signal; | |
223ddf66 | 3800 | var _419=self._observers; |
79f17b42 DV |
3801 | src=MochiKit.DOM.getElement(src); |
3802 | var args=MochiKit.Base.extend(null,arguments,2); | |
223ddf66 | 3803 | var _41b=[]; |
79f17b42 | 3804 | self._lock=true; |
223ddf66 DV |
3805 | for(var i=0;i<_419.length;i++){ |
3806 | var _41d=_419[i]; | |
3807 | if(_41d.source===src&&_41d.signal===sig){ | |
79f17b42 | 3808 | try{ |
223ddf66 | 3809 | _41d.listener.apply(src,args); |
6a1aa64f | 3810 | } |
79f17b42 | 3811 | catch(e){ |
223ddf66 | 3812 | _41b.push(e); |
6a1aa64f | 3813 | } |
6a1aa64f | 3814 | } |
6a1aa64f | 3815 | } |
79f17b42 DV |
3816 | self._lock=false; |
3817 | if(self._dirty){ | |
3818 | self._dirty=false; | |
223ddf66 DV |
3819 | for(var i=_419.length-1;i>=0;i--){ |
3820 | if(!_419[i].connected){ | |
3821 | _419.splice(i,1); | |
79f17b42 | 3822 | } |
6a1aa64f | 3823 | } |
79f17b42 | 3824 | } |
223ddf66 DV |
3825 | if(_41b.length==1){ |
3826 | throw _41b[0]; | |
6a1aa64f | 3827 | }else{ |
223ddf66 | 3828 | if(_41b.length>1){ |
79f17b42 | 3829 | var e=new Error("Multiple errors thrown in handling 'sig', see errors property"); |
223ddf66 | 3830 | e.errors=_41b; |
79f17b42 | 3831 | throw e; |
6a1aa64f DV |
3832 | } |
3833 | } | |
79f17b42 DV |
3834 | }}); |
3835 | MochiKit.Signal.EXPORT_OK=[]; | |
3836 | MochiKit.Signal.EXPORT=["connect","disconnect","signal","disconnectAll","disconnectAllTo"]; | |
3837 | MochiKit.Signal.__new__=function(win){ | |
3838 | var m=MochiKit.Base; | |
3839 | this._document=document; | |
3840 | this._window=win; | |
3841 | this._lock=false; | |
3842 | this._dirty=false; | |
3843 | try{ | |
3844 | this.connect(window,"onunload",this._unloadCache); | |
3845 | } | |
3846 | catch(e){ | |
3847 | } | |
3848 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
3849 | m.nameFunctions(this); | |
3850 | }; | |
3851 | MochiKit.Signal.__new__(this); | |
3852 | if(MochiKit.__export__){ | |
3853 | connect=MochiKit.Signal.connect; | |
3854 | disconnect=MochiKit.Signal.disconnect; | |
3855 | disconnectAll=MochiKit.Signal.disconnectAll; | |
3856 | signal=MochiKit.Signal.signal; | |
6a1aa64f | 3857 | } |
79f17b42 | 3858 | MochiKit.Base._exportSymbols(this,MochiKit.Signal); |
6a1aa64f DV |
3859 | |
3860 | ||
3861 | /*** | |
3862 | ||
3863 | PlotKit.PlotKit 0.9.1 : PACKED VERSION | |
3864 | ||
3865 | THIS FILE IS AUTOMATICALLY GENERATED. If creating patches, please | |
3866 | diff against the source tree, not this file. | |
3867 | ||
3868 | For more information, <http://www.liquidx.net/plotkit/>. | |
3869 | ||
3870 | Copyright (c) 2006. Alastair Tse. | |
3871 | ||
3872 | ***/ | |
3873 | ||
3874 | try{ | |
223ddf66 | 3875 | if(typeof (MochiKit.Base)=="undefined"||typeof (MochiKit.DOM)=="undefined"||typeof (MochiKit.Color)=="undefined"){ |
6a1aa64f DV |
3876 | throw ""; |
3877 | } | |
3878 | } | |
3879 | catch(e){ | |
223ddf66 | 3880 | throw "PlotKit depends on MochiKit.{Base,Color,DOM}"; |
6a1aa64f DV |
3881 | } |
3882 | MochiKit.Base.update(MochiKit.Color.Color.prototype,{asFillColor:function(){ | |
3883 | return this.lighterColorWithLevel(0.3); | |
3884 | },asStrokeColor:function(){ | |
3885 | return this.darkerColorWithLevel(0.1); | |
3886 | },asPointColor:function(){ | |
3887 | return this.lighterColorWithLevel(0.1); | |
3888 | }}); | |
3889 | if(typeof (PlotKit)=="undefined"){ | |
3890 | PlotKit={}; | |
3891 | } | |
3892 | PlotKit.NAME="PlotKit"; | |
3893 | PlotKit.VERSION="0.8"; | |
3894 | PlotKit.__repr__=function(){ | |
3895 | return "["+this.NAME+" "+this.VERSION+"]"; | |
3896 | }; | |
3897 | PlotKit.toString=function(){ | |
3898 | return this.__repr__(); | |
3899 | }; | |
3900 | if(typeof (PlotKit.Base)=="undefined"){ | |
3901 | PlotKit.Base={}; | |
3902 | } | |
3903 | PlotKit.Base.NAME="PlotKit.Base"; | |
3904 | PlotKit.Base.VERSION=PlotKit.VERSION; | |
3905 | PlotKit.Base.__repr__=function(){ | |
3906 | return "["+this.NAME+" "+this.VERSION+"]"; | |
3907 | }; | |
3908 | PlotKit.Base.toString=function(){ | |
3909 | return this.__repr__(); | |
3910 | }; | |
3911 | PlotKit.Base.usingPrototype=function(){ | |
3912 | try{ | |
3913 | return (typeof (Object.extend)=="function"); | |
3914 | } | |
3915 | catch(e){ | |
3916 | return false; | |
3917 | } | |
3918 | }; | |
223ddf66 | 3919 | MochiKit.Base.update(PlotKit.Base,{collapse:function(_1){ |
6a1aa64f | 3920 | var m=MochiKit.Base; |
223ddf66 DV |
3921 | var _3=new Array(); |
3922 | for(var i=0;i<_1.length;i++){ | |
3923 | _3=m.concat(_3,_1[i]); | |
6a1aa64f DV |
3924 | } |
3925 | if(PlotKit.Base.usingPrototype()){ | |
223ddf66 DV |
3926 | delete _3.extend; |
3927 | delete _3.from; | |
3928 | delete _3.inspect; | |
6a1aa64f | 3929 | } |
223ddf66 DV |
3930 | return _3; |
3931 | },uniq:function(_5){ | |
6a1aa64f | 3932 | var m=MochiKit.Base; |
223ddf66 | 3933 | if(!m.isArrayLike(_5)||(_5.length<1)){ |
6a1aa64f DV |
3934 | return new Array(); |
3935 | } | |
223ddf66 DV |
3936 | var _6=new Array(); |
3937 | var _7=_5[0]; | |
3938 | _6.push(_5[0]); | |
3939 | for(var i=1;i<_5.length;i++){ | |
3940 | if(m.compare(_5[i],_7)!=0){ | |
3941 | _7=_5[i]; | |
3942 | _6.push(_5[i]); | |
6a1aa64f DV |
3943 | } |
3944 | } | |
223ddf66 DV |
3945 | return _6; |
3946 | },palette:function(_8,_9,_10,_11){ | |
3947 | var _12=MochiKit.Base.isUndefinedOrNull; | |
3948 | var _13=new Array(); | |
3949 | if(_12(_11)){ | |
3950 | _11=0.1; | |
9148174b | 3951 | } |
223ddf66 DV |
3952 | if(_12(_10)){ |
3953 | _10=0.4; | |
9148174b | 3954 | } |
223ddf66 DV |
3955 | if(_12(_9)){ |
3956 | _9=-0.2; | |
9148174b | 3957 | } |
223ddf66 DV |
3958 | var _14=_9; |
3959 | while(_14<=_10){ | |
3960 | _13.push(_14); | |
3961 | _14+=_11; | |
9148174b | 3962 | } |
223ddf66 DV |
3963 | var _15=function(_16,_17){ |
3964 | return _16.lighterColorWithLevel(_17); | |
6a1aa64f | 3965 | }; |
223ddf66 | 3966 | return MochiKit.Base.map(partial(_15,_8),_13); |
6a1aa64f DV |
3967 | },excanvasSupported:function(){ |
3968 | if(/MSIE/.test(navigator.userAgent)&&!window.opera){ | |
3969 | return true; | |
3970 | } | |
3971 | return false; | |
3972 | },findPosX:function(obj){ | |
223ddf66 | 3973 | var _19=0; |
6a1aa64f DV |
3974 | if(obj.offsetParent){ |
3975 | while(obj.offsetParent){ | |
223ddf66 | 3976 | _19+=obj.offsetLeft; |
6a1aa64f DV |
3977 | obj=obj.offsetParent; |
3978 | } | |
3979 | }else{ | |
3980 | if(obj.x){ | |
223ddf66 | 3981 | _19+=obj.x; |
6a1aa64f DV |
3982 | } |
3983 | } | |
223ddf66 | 3984 | return _19; |
6a1aa64f | 3985 | },findPosY:function(obj){ |
223ddf66 | 3986 | var _20=0; |
6a1aa64f DV |
3987 | if(obj.offsetParent){ |
3988 | while(obj.offsetParent){ | |
223ddf66 | 3989 | _20+=obj.offsetTop; |
6a1aa64f DV |
3990 | obj=obj.offsetParent; |
3991 | } | |
3992 | }else{ | |
3993 | if(obj.y){ | |
223ddf66 | 3994 | _20+=obj.y; |
6a1aa64f DV |
3995 | } |
3996 | } | |
223ddf66 | 3997 | return _20; |
6a1aa64f DV |
3998 | },isFuncLike:function(obj){ |
3999 | return (typeof (obj)=="function"); | |
4000 | }}); | |
4001 | PlotKit.Base.map=function(fn,lst){ | |
4002 | if(PlotKit.Base.usingPrototype()){ | |
223ddf66 | 4003 | var _23=[]; |
6a1aa64f DV |
4004 | for(var x in lst){ |
4005 | if(typeof (lst[x])=="function"){ | |
4006 | continue; | |
4007 | } | |
223ddf66 | 4008 | _23.push(fn(lst[x])); |
6a1aa64f | 4009 | } |
223ddf66 | 4010 | return _23; |
6a1aa64f DV |
4011 | }else{ |
4012 | return MochiKit.Base.map(fn,lst); | |
4013 | } | |
4014 | }; | |
4015 | PlotKit.Base.items=function(lst){ | |
4016 | if(PlotKit.Base.usingPrototype()){ | |
223ddf66 | 4017 | var _25=[]; |
6a1aa64f DV |
4018 | for(var x in lst){ |
4019 | if(typeof (lst[x])=="function"){ | |
4020 | continue; | |
4021 | } | |
223ddf66 | 4022 | _25.push([x,lst[x]]); |
6a1aa64f | 4023 | } |
223ddf66 | 4024 | return _25; |
6a1aa64f DV |
4025 | }else{ |
4026 | return MochiKit.Base.items(lst); | |
4027 | } | |
4028 | }; | |
4029 | PlotKit.Base.keys=function(lst){ | |
4030 | if(PlotKit.Base.usingPrototype()){ | |
223ddf66 | 4031 | var _26=[]; |
6a1aa64f DV |
4032 | for(var x in lst){ |
4033 | if(typeof (lst[x])=="function"){ | |
4034 | continue; | |
4035 | } | |
223ddf66 | 4036 | _26.push(x); |
6a1aa64f | 4037 | } |
223ddf66 | 4038 | return _26; |
6a1aa64f DV |
4039 | }else{ |
4040 | return MochiKit.Base.keys(lst); | |
4041 | } | |
4042 | }; | |
4043 | PlotKit.Base.baseColors=function(){ | |
223ddf66 DV |
4044 | var _27=MochiKit.Color.Color.fromHexString; |
4045 | return [_27("#476fb2"),_27("#be2c2b"),_27("#85b730"),_27("#734a99"),_27("#26a1c5"),_27("#fb8707"),_27("#000000")]; | |
6a1aa64f | 4046 | }; |
223ddf66 | 4047 | PlotKit.Base.EXPORT=["baseColors","collapse","findPosX","findPosY","uniq","isFuncLike","excanvasSupported"]; |
6a1aa64f DV |
4048 | PlotKit.Base.EXPORT_OK=[]; |
4049 | PlotKit.Base.__new__=function(){ | |
4050 | var m=MochiKit.Base; | |
4051 | m.nameFunctions(this); | |
4052 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
4053 | }; | |
4054 | PlotKit.Base.__new__(); | |
4055 | MochiKit.Base._exportSymbols(this,PlotKit.Base); | |
4056 | try{ | |
4057 | if(typeof (PlotKit.Base)=="undefined"){ | |
4058 | throw ""; | |
4059 | } | |
4060 | } | |
4061 | catch(e){ | |
4062 | throw "PlotKit.Layout depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.Base"; | |
4063 | } | |
4064 | if(typeof (PlotKit.Layout)=="undefined"){ | |
4065 | PlotKit.Layout={}; | |
4066 | } | |
4067 | PlotKit.Layout.NAME="PlotKit.Layout"; | |
4068 | PlotKit.Layout.VERSION=PlotKit.VERSION; | |
4069 | PlotKit.Layout.__repr__=function(){ | |
4070 | return "["+this.NAME+" "+this.VERSION+"]"; | |
4071 | }; | |
4072 | PlotKit.Layout.toString=function(){ | |
4073 | return this.__repr__(); | |
4074 | }; | |
4075 | PlotKit.Layout.valid_styles=["bar","line","pie","point"]; | |
223ddf66 | 4076 | PlotKit.Layout=function(_28,_29){ |
6a1aa64f | 4077 | this.options={"barWidthFillFraction":0.75,"barOrientation":"vertical","xOriginIsZero":true,"yOriginIsZero":true,"xAxis":null,"yAxis":null,"xTicks":null,"yTicks":null,"xNumberOfTicks":10,"yNumberOfTicks":5,"xTickPrecision":1,"yTickPrecision":1,"pieRadius":0.4}; |
223ddf66 DV |
4078 | this.style=_28; |
4079 | MochiKit.Base.update(this.options,_29?_29:{}); | |
6a1aa64f DV |
4080 | if(!MochiKit.Base.isUndefinedOrNull(this.options.xAxis)){ |
4081 | this.minxval=this.options.xAxis[0]; | |
4082 | this.maxxval=this.options.xAxis[1]; | |
4083 | this.xscale=this.maxxval-this.minxval; | |
4084 | }else{ | |
4085 | this.minxval=0; | |
4086 | this.maxxval=null; | |
4087 | this.xscale=null; | |
4088 | } | |
4089 | if(!MochiKit.Base.isUndefinedOrNull(this.options.yAxis)){ | |
4090 | this.minyval=this.options.yAxis[0]; | |
4091 | this.maxyval=this.options.yAxis[1]; | |
4092 | this.yscale=this.maxyval-this.minyval; | |
4093 | }else{ | |
4094 | this.minyval=0; | |
4095 | this.maxyval=null; | |
4096 | this.yscale=null; | |
4097 | } | |
4098 | this.bars=new Array(); | |
4099 | this.points=new Array(); | |
4100 | this.slices=new Array(); | |
4101 | this.xticks=new Array(); | |
4102 | this.yticks=new Array(); | |
4103 | this.datasets=new Array(); | |
4104 | this.minxdelta=0; | |
4105 | this.xrange=1; | |
4106 | this.yrange=1; | |
4107 | this.hitTestCache={x2maxy:null}; | |
4108 | }; | |
223ddf66 DV |
4109 | PlotKit.Layout.prototype.addDataset=function(_30,_31){ |
4110 | this.datasets[_30]=_31; | |
6a1aa64f | 4111 | }; |
223ddf66 DV |
4112 | PlotKit.Layout.prototype.removeDataset=function(_32,_33){ |
4113 | delete this.datasets[_32]; | |
6a1aa64f DV |
4114 | }; |
4115 | PlotKit.Layout.prototype.evaluate=function(){ | |
4116 | this._evaluateLimits(); | |
4117 | this._evaluateScales(); | |
6a1aa64f DV |
4118 | if(this.style=="line"){ |
4119 | this._evaluateLineCharts(); | |
4120 | this._evaluateLineTicks(); | |
6a1aa64f DV |
4121 | } |
4122 | }; | |
6a1aa64f DV |
4123 | PlotKit.Layout.prototype._evaluateLimits=function(){ |
4124 | var map=PlotKit.Base.map; | |
223ddf66 DV |
4125 | var _35=PlotKit.Base.items; |
4126 | var _36=MochiKit.Base.itemgetter; | |
4127 | var _37=PlotKit.Base.collapse; | |
4128 | var _38=MochiKit.Base.listMin; | |
4129 | var _39=MochiKit.Base.listMax; | |
4130 | var _40=MochiKit.Base.isUndefinedOrNull; | |
4131 | var all=_37(map(_36(1),_35(this.datasets))); | |
4132 | if(_40(this.options.xAxis)){ | |
6a1aa64f DV |
4133 | if(this.options.xOriginIsZero){ |
4134 | this.minxval=0; | |
4135 | }else{ | |
223ddf66 | 4136 | this.minxval=_38(map(parseFloat,map(_36(0),all))); |
6a1aa64f | 4137 | } |
223ddf66 | 4138 | this.maxxval=_39(map(parseFloat,map(_36(0),all))); |
6a1aa64f DV |
4139 | }else{ |
4140 | this.minxval=this.options.xAxis[0]; | |
4141 | this.maxxval=this.options.xAxis[1]; | |
4142 | this.xscale=this.maxval-this.minxval; | |
4143 | } | |
223ddf66 | 4144 | if(_40(this.options.yAxis)){ |
6a1aa64f DV |
4145 | if(this.options.yOriginIsZero){ |
4146 | this.minyval=0; | |
4147 | }else{ | |
223ddf66 | 4148 | this.minyval=_38(map(parseFloat,map(_36(1),all))); |
6a1aa64f | 4149 | } |
223ddf66 | 4150 | this.maxyval=_39(map(parseFloat,map(_36(1),all))); |
6a1aa64f DV |
4151 | }else{ |
4152 | this.minyval=this.options.yAxis[0]; | |
4153 | this.maxyval=this.options.yAxis[1]; | |
4154 | this.yscale=this.maxyval-this.minyval; | |
4155 | } | |
4156 | }; | |
4157 | PlotKit.Layout.prototype._evaluateScales=function(){ | |
223ddf66 | 4158 | var _42=MochiKit.Base.isUndefinedOrNull; |
6a1aa64f DV |
4159 | this.xrange=this.maxxval-this.minxval; |
4160 | if(this.xrange==0){ | |
4161 | this.xscale=1; | |
4162 | }else{ | |
4163 | this.xscale=1/this.xrange; | |
4164 | } | |
4165 | this.yrange=this.maxyval-this.minyval; | |
4166 | if(this.yrange==0){ | |
4167 | this.yscale=1; | |
4168 | }else{ | |
4169 | this.yscale=1/this.yrange; | |
4170 | } | |
4171 | }; | |
4172 | PlotKit.Layout.prototype._uniqueXValues=function(){ | |
223ddf66 | 4173 | var _43=PlotKit.Base.collapse; |
6a1aa64f | 4174 | var map=PlotKit.Base.map; |
223ddf66 DV |
4175 | var _44=PlotKit.Base.uniq; |
4176 | var _45=MochiKit.Base.itemgetter; | |
4177 | var _46=PlotKit.Base.items; | |
4178 | var _47=map(parseFloat,map(_45(0),_43(map(_45(1),_46(this.datasets))))); | |
4179 | _47.sort(MochiKit.Base.compare); | |
4180 | return _44(_47); | |
6a1aa64f DV |
4181 | }; |
4182 | PlotKit.Layout.prototype._evaluateLineCharts=function(){ | |
223ddf66 DV |
4183 | var _48=PlotKit.Base.items; |
4184 | var _49=_48(this.datasets).length; | |
6a1aa64f DV |
4185 | this.points=new Array(); |
4186 | var i=0; | |
223ddf66 DV |
4187 | for(var _50 in this.datasets){ |
4188 | var _51=this.datasets[_50]; | |
4189 | if(PlotKit.Base.isFuncLike(_51)){ | |
6a1aa64f DV |
4190 | continue; |
4191 | } | |
223ddf66 | 4192 | _51.sort(function(a,b){ |
6a1aa64f DV |
4193 | return compare(parseFloat(a[0]),parseFloat(b[0])); |
4194 | }); | |
223ddf66 DV |
4195 | for(var j=0;j<_51.length;j++){ |
4196 | var _55=_51[j]; | |
4197 | var _56={x:((parseFloat(_55[0])-this.minxval)*this.xscale),y:1-((parseFloat(_55[1])-this.minyval)*this.yscale),xval:parseFloat(_55[0]),yval:parseFloat(_55[1]),name:_50}; | |
4198 | if(_56.y<=0){ | |
4199 | _56.y=0; | |
6a1aa64f | 4200 | } |
223ddf66 DV |
4201 | if(_56.y>=1){ |
4202 | _56.y=1; | |
6a1aa64f | 4203 | } |
223ddf66 DV |
4204 | if((_56.x>=0)&&(_56.x<=1)){ |
4205 | this.points.push(_56); | |
6a1aa64f DV |
4206 | } |
4207 | } | |
4208 | i++; | |
4209 | } | |
4210 | }; | |
6a1aa64f | 4211 | PlotKit.Layout.prototype._evaluateLineTicksForXAxis=function(){ |
223ddf66 | 4212 | var _57=MochiKit.Base.isUndefinedOrNull; |
6a1aa64f DV |
4213 | if(this.options.xTicks){ |
4214 | this.xticks=new Array(); | |
223ddf66 DV |
4215 | var _58=function(_59){ |
4216 | var _60=_59.label; | |
4217 | if(_57(_60)){ | |
4218 | _60=_59.v.toString(); | |
6a1aa64f | 4219 | } |
223ddf66 | 4220 | var pos=this.xscale*(_59.v-this.minxval); |
6a1aa64f | 4221 | if((pos>=0)&&(pos<=1)){ |
223ddf66 | 4222 | this.xticks.push([pos,_60]); |
6a1aa64f DV |
4223 | } |
4224 | }; | |
223ddf66 | 4225 | MochiKit.Iter.forEach(this.options.xTicks,bind(_58,this)); |
6a1aa64f DV |
4226 | }else{ |
4227 | if(this.options.xNumberOfTicks){ | |
223ddf66 DV |
4228 | var _62=this._uniqueXValues(); |
4229 | var _63=this.xrange/this.options.xNumberOfTicks; | |
4230 | var _64=0; | |
6a1aa64f | 4231 | this.xticks=new Array(); |
223ddf66 DV |
4232 | for(var i=0;i<=_62.length;i++){ |
4233 | if((_62[i]-this.minxval)>=(_64*_63)){ | |
4234 | var pos=this.xscale*(_62[i]-this.minxval); | |
6a1aa64f DV |
4235 | if((pos>1)||(pos<0)){ |
4236 | continue; | |
4237 | } | |
223ddf66 DV |
4238 | this.xticks.push([pos,_62[i]]); |
4239 | _64++; | |
6a1aa64f | 4240 | } |
223ddf66 | 4241 | if(_64>this.options.xNumberOfTicks){ |
6a1aa64f DV |
4242 | break; |
4243 | } | |
4244 | } | |
4245 | } | |
4246 | } | |
4247 | }; | |
4248 | PlotKit.Layout.prototype._evaluateLineTicksForYAxis=function(){ | |
223ddf66 | 4249 | var _65=MochiKit.Base.isUndefinedOrNull; |
6a1aa64f DV |
4250 | if(this.options.yTicks){ |
4251 | this.yticks=new Array(); | |
223ddf66 DV |
4252 | var _66=function(_67){ |
4253 | var _68=_67.label; | |
4254 | if(_65(_68)){ | |
4255 | _68=_67.v.toString(); | |
6a1aa64f | 4256 | } |
223ddf66 | 4257 | var pos=1-(this.yscale*(_67.v-this.minyval)); |
6a1aa64f | 4258 | if((pos>=0)&&(pos<=1)){ |
223ddf66 | 4259 | this.yticks.push([pos,_68]); |
6a1aa64f DV |
4260 | } |
4261 | }; | |
223ddf66 | 4262 | MochiKit.Iter.forEach(this.options.yTicks,bind(_66,this)); |
6a1aa64f DV |
4263 | } |
4264 | }; | |
4265 | PlotKit.Layout.prototype._evaluateLineTicks=function(){ | |
4266 | this._evaluateLineTicksForXAxis(); | |
4267 | this._evaluateLineTicksForYAxis(); | |
4268 | }; | |
6a1aa64f DV |
4269 | PlotKit.LayoutModule={}; |
4270 | PlotKit.LayoutModule.Layout=PlotKit.Layout; | |
4271 | PlotKit.LayoutModule.EXPORT=["Layout"]; | |
4272 | PlotKit.LayoutModule.EXPORT_OK=[]; | |
4273 | PlotKit.LayoutModule.__new__=function(){ | |
4274 | var m=MochiKit.Base; | |
4275 | m.nameFunctions(this); | |
4276 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
4277 | }; | |
4278 | PlotKit.LayoutModule.__new__(); | |
4279 | MochiKit.Base._exportSymbols(this,PlotKit.LayoutModule); | |
4280 | try{ | |
4281 | if((typeof (PlotKit.Base)=="undefined")||(typeof (PlotKit.Layout)=="undefined")){ | |
4282 | throw ""; | |
4283 | } | |
4284 | } | |
4285 | catch(e){ | |
4286 | throw "PlotKit.Layout depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.{Base,Layout}"; | |
4287 | } | |
4288 | if(typeof (PlotKit.CanvasRenderer)=="undefined"){ | |
4289 | PlotKit.CanvasRenderer={}; | |
4290 | } | |
4291 | PlotKit.CanvasRenderer.NAME="PlotKit.CanvasRenderer"; | |
4292 | PlotKit.CanvasRenderer.VERSION=PlotKit.VERSION; | |
4293 | PlotKit.CanvasRenderer.__repr__=function(){ | |
4294 | return "["+this.NAME+" "+this.VERSION+"]"; | |
4295 | }; | |
4296 | PlotKit.CanvasRenderer.toString=function(){ | |
4297 | return this.__repr__(); | |
4298 | }; | |
223ddf66 | 4299 | PlotKit.CanvasRenderer=function(_69,_70,_71){ |
6a1aa64f | 4300 | if(arguments.length>0){ |
223ddf66 | 4301 | this.__init__(_69,_70,_71); |
6a1aa64f DV |
4302 | } |
4303 | }; | |
223ddf66 DV |
4304 | PlotKit.CanvasRenderer.prototype.__init__=function(_72,_73,_74){ |
4305 | var _75=MochiKit.Base.isUndefinedOrNull; | |
4306 | var _76=MochiKit.Color.Color; | |
8846615a | 4307 | this.options={"drawBackground":true,"backgroundColor":_76.whiteColor(),"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[0]),"strokeColor":_76.whiteColor(),"strokeColorTransform":"asStrokeColor","strokeWidth":0.5,"shouldFill":true,"shouldStroke":true,"drawXAxis":true,"drawYAxis":true,"axisLineColor":_76.blackColor(),"axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":_76.blackColor(),"axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"pieRadius":0.4,"enableEvents":true}; |
223ddf66 DV |
4308 | MochiKit.Base.update(this.options,_74?_74:{}); |
4309 | this.layout=_73; | |
4310 | this.element=MochiKit.DOM.getElement(_72); | |
6a1aa64f DV |
4311 | this.container=this.element.parentNode; |
4312 | this.isIE=PlotKit.Base.excanvasSupported(); | |
223ddf66 | 4313 | if(this.isIE&&!_75(G_vmlCanvasManager)){ |
6a1aa64f DV |
4314 | this.IEDelay=0.5; |
4315 | this.maxTries=5; | |
4316 | this.renderDelay=null; | |
4317 | this.clearDelay=null; | |
4318 | this.element=G_vmlCanvasManager.initElement(this.element); | |
4319 | } | |
4320 | this.height=this.element.height; | |
4321 | this.width=this.element.width; | |
223ddf66 | 4322 | if(_75(this.element)){ |
6a1aa64f DV |
4323 | throw "CanvasRenderer() - passed canvas is not found"; |
4324 | } | |
4325 | if(!this.isIE&&!(PlotKit.CanvasRenderer.isSupported(this.element))){ | |
4326 | throw "CanvasRenderer() - Canvas is not supported."; | |
4327 | } | |
223ddf66 | 4328 | if(_75(this.container)||(this.container.nodeName.toLowerCase()!="div")){ |
6a1aa64f DV |
4329 | throw "CanvasRenderer() - <canvas> needs to be enclosed in <div>"; |
4330 | } | |
4331 | this.xlabels=new Array(); | |
4332 | this.ylabels=new Array(); | |
4333 | this.isFirstRender=true; | |
8846615a DV |
4334 | this.area={x:this.options.yAxisLabelWidth+2*this.options.axisTickSize,y:0}; |
4335 | this.area.w=this.width-this.area.x-this.options.rightGap; | |
4336 | this.area.h=this.height-this.options.axisLabelFontSize-2*this.options.axisTickSize; | |
6a1aa64f DV |
4337 | MochiKit.DOM.updateNodeAttributes(this.container,{"style":{"position":"relative","width":this.width+"px"}}); |
4338 | }; | |
4339 | PlotKit.CanvasRenderer.prototype.render=function(){ | |
4340 | if(this.isIE){ | |
4341 | try{ | |
4342 | if(this.renderDelay){ | |
4343 | this.renderDelay.cancel(); | |
4344 | this.renderDelay=null; | |
4345 | } | |
223ddf66 | 4346 | var _77=this.element.getContext("2d"); |
6a1aa64f DV |
4347 | } |
4348 | catch(e){ | |
4349 | this.isFirstRender=false; | |
4350 | if(this.maxTries-->0){ | |
4351 | this.renderDelay=MochiKit.Async.wait(this.IEDelay); | |
4352 | this.renderDelay.addCallback(bind(this.render,this)); | |
4353 | } | |
4354 | return; | |
4355 | } | |
4356 | } | |
4357 | if(this.options.drawBackground){ | |
4358 | this._renderBackground(); | |
4359 | } | |
6a1aa64f DV |
4360 | if(this.layout.style=="line"){ |
4361 | this._renderLineChart(); | |
4362 | this._renderLineAxis(); | |
4363 | } | |
6a1aa64f DV |
4364 | }; |
4365 | PlotKit.CanvasRenderer.prototype._renderLineChart=function(){ | |
223ddf66 DV |
4366 | var _78=this.element.getContext("2d"); |
4367 | var _79=this.options.colorScheme.length; | |
4368 | var _80=this.options.colorScheme; | |
4369 | var _81=MochiKit.Base.keys(this.layout.datasets); | |
4370 | var _82=_81.length; | |
4371 | var _83=MochiKit.Base.bind; | |
4372 | var _84=MochiKit.Base.partial; | |
4373 | for(var i=0;i<_82;i++){ | |
4374 | var _85=_81[i]; | |
4375 | var _86=_80[i%_79]; | |
4376 | var _87=this.options.strokeColorTransform; | |
4377 | _78.save(); | |
4378 | _78.fillStyle=_86.toRGBString(); | |
6a1aa64f | 4379 | if(this.options.strokeColor){ |
223ddf66 | 4380 | _78.strokeStyle=this.options.strokeColor.toRGBString(); |
6a1aa64f DV |
4381 | }else{ |
4382 | if(this.options.strokeColorTransform){ | |
223ddf66 | 4383 | _78.strokeStyle=_86[_87]().toRGBString(); |
6a1aa64f DV |
4384 | } |
4385 | } | |
223ddf66 DV |
4386 | _78.lineWidth=this.options.strokeWidth; |
4387 | var _88=function(ctx){ | |
6a1aa64f DV |
4388 | ctx.beginPath(); |
4389 | ctx.moveTo(this.area.x,this.area.y+this.area.h); | |
223ddf66 DV |
4390 | var _90=function(_91,_92){ |
4391 | if(_92.name==_85){ | |
4392 | _91.lineTo(this.area.w*_92.x+this.area.x,this.area.h*_92.y+this.area.y); | |
6a1aa64f DV |
4393 | } |
4394 | }; | |
223ddf66 | 4395 | MochiKit.Iter.forEach(this.layout.points,_84(_90,ctx),this); |
6a1aa64f DV |
4396 | ctx.lineTo(this.area.w+this.area.x,this.area.h+this.area.y); |
4397 | ctx.lineTo(this.area.x,this.area.y+this.area.h); | |
4398 | ctx.closePath(); | |
4399 | }; | |
4400 | if(this.options.shouldFill){ | |
223ddf66 DV |
4401 | _83(_88,this)(_78); |
4402 | _78.fill(); | |
6a1aa64f DV |
4403 | } |
4404 | if(this.options.shouldStroke){ | |
223ddf66 DV |
4405 | _83(_88,this)(_78); |
4406 | _78.stroke(); | |
6a1aa64f | 4407 | } |
223ddf66 | 4408 | _78.restore(); |
6a1aa64f DV |
4409 | } |
4410 | }; | |
6a1aa64f DV |
4411 | PlotKit.CanvasRenderer.prototype._renderLineAxis=function(){ |
4412 | this._renderAxis(); | |
4413 | }; | |
4414 | PlotKit.CanvasRenderer.prototype._renderAxis=function(){ | |
4415 | if(!this.options.drawXAxis&&!this.options.drawYAxis){ | |
4416 | return; | |
4417 | } | |
223ddf66 DV |
4418 | var _93=this.element.getContext("2d"); |
4419 | var _94={"style":{"position":"absolute","fontSize":this.options.axisLabelFontSize+"px","zIndex":10,"color":this.options.axisLabelColor.toRGBString(),"width":this.options.axisLabelWidth+"px","overflow":"hidden"}}; | |
4420 | _93.save(); | |
4421 | _93.strokeStyle=this.options.axisLineColor.toRGBString(); | |
4422 | _93.lineWidth=this.options.axisLineWidth; | |
6a1aa64f DV |
4423 | if(this.options.drawYAxis){ |
4424 | if(this.layout.yticks){ | |
223ddf66 DV |
4425 | var _95=function(_96){ |
4426 | if(typeof (_96)=="function"){ | |
6a1aa64f DV |
4427 | return; |
4428 | } | |
4429 | var x=this.area.x; | |
223ddf66 DV |
4430 | var y=this.area.y+_96[0]*this.area.h; |
4431 | _93.beginPath(); | |
4432 | _93.moveTo(x,y); | |
4433 | _93.lineTo(x-this.options.axisTickSize,y); | |
4434 | _93.closePath(); | |
4435 | _93.stroke(); | |
4436 | var _98=DIV(_94,_96[1]); | |
8846615a DV |
4437 | var top=(y-this.options.axisLabelFontSize/2); |
4438 | if(top<0){ | |
4439 | top=0; | |
4440 | } | |
4441 | if(top+this.options.axisLabelFontSize+3>this.height){ | |
4442 | _98.style.bottom="0px"; | |
4443 | }else{ | |
4444 | _98.style.top=top+"px"; | |
4445 | } | |
4446 | _98.style.left="0px"; | |
223ddf66 | 4447 | _98.style.textAlign="right"; |
8846615a | 4448 | _98.style.width=this.options.yAxisLabelWidth+"px"; |
223ddf66 DV |
4449 | MochiKit.DOM.appendChildNodes(this.container,_98); |
4450 | this.ylabels.push(_98); | |
9148174b | 4451 | }; |
223ddf66 | 4452 | MochiKit.Iter.forEach(this.layout.yticks,bind(_95,this)); |
8846615a DV |
4453 | var _100=this.ylabels[0]; |
4454 | var _101=this.options.axisLabelFontSize; | |
4455 | var _102=parseInt(_100.style.top)+_101; | |
4456 | if(_102>this.height-_101){ | |
4457 | _100.style.top=(parseInt(_100.style.top)-_101/2)+"px"; | |
4458 | } | |
9148174b | 4459 | } |
223ddf66 DV |
4460 | _93.beginPath(); |
4461 | _93.moveTo(this.area.x,this.area.y); | |
4462 | _93.lineTo(this.area.x,this.area.y+this.area.h); | |
4463 | _93.closePath(); | |
4464 | _93.stroke(); | |
6a1aa64f DV |
4465 | } |
4466 | if(this.options.drawXAxis){ | |
4467 | if(this.layout.xticks){ | |
8846615a | 4468 | var _95=function(tick){ |
6a1aa64f DV |
4469 | if(typeof (dataset)=="function"){ |
4470 | return; | |
4471 | } | |
8846615a | 4472 | var x=this.area.x+tick[0]*this.area.w; |
6a1aa64f | 4473 | var y=this.area.y+this.area.h; |
223ddf66 DV |
4474 | _93.beginPath(); |
4475 | _93.moveTo(x,y); | |
4476 | _93.lineTo(x,y+this.options.axisTickSize); | |
4477 | _93.closePath(); | |
4478 | _93.stroke(); | |
8846615a DV |
4479 | var _104=DIV(_94,tick[1]); |
4480 | _104.style.textAlign="center"; | |
4481 | _104.style.bottom="0px"; | |
4482 | var left=(x-this.options.axisLabelWidth/2); | |
4483 | if(left+this.options.axisLabelWidth>this.width){ | |
4484 | left=this.width-this.options.xAxisLabelWidth; | |
4485 | _104.style.textAlign="right"; | |
4486 | } | |
4487 | if(left<0){ | |
4488 | left=0; | |
4489 | _104.style.textAlign="left"; | |
4490 | } | |
4491 | _104.style.left=left+"px"; | |
8846615a DV |
4492 | _104.style.width=this.options.xAxisLabelWidth+"px"; |
4493 | MochiKit.DOM.appendChildNodes(this.container,_104); | |
4494 | this.xlabels.push(_104); | |
9148174b | 4495 | }; |
223ddf66 | 4496 | MochiKit.Iter.forEach(this.layout.xticks,bind(_95,this)); |
9148174b | 4497 | } |
223ddf66 DV |
4498 | _93.beginPath(); |
4499 | _93.moveTo(this.area.x,this.area.y+this.area.h); | |
4500 | _93.lineTo(this.area.x+this.area.w,this.area.y+this.area.h); | |
4501 | _93.closePath(); | |
4502 | _93.stroke(); | |
9148174b | 4503 | } |
223ddf66 | 4504 | _93.restore(); |
6a1aa64f DV |
4505 | }; |
4506 | PlotKit.CanvasRenderer.prototype._renderBackground=function(){ | |
8846615a DV |
4507 | var _106=this.element.getContext("2d"); |
4508 | _106.save(); | |
4509 | _106.fillStyle=this.options.backgroundColor.toRGBString(); | |
4510 | _106.fillRect(0,0,this.width,this.height); | |
4511 | _106.restore(); | |
6a1aa64f DV |
4512 | }; |
4513 | PlotKit.CanvasRenderer.prototype.clear=function(){ | |
4514 | if(this.isIE){ | |
4515 | try{ | |
4516 | if(this.clearDelay){ | |
4517 | this.clearDelay.cancel(); | |
4518 | this.clearDelay=null; | |
4519 | } | |
8846615a | 4520 | var _107=this.element.getContext("2d"); |
6a1aa64f DV |
4521 | } |
4522 | catch(e){ | |
4523 | this.isFirstRender=false; | |
4524 | this.clearDelay=MochiKit.Async.wait(this.IEDelay); | |
4525 | this.clearDelay.addCallback(bind(this.clear,this)); | |
4526 | return; | |
4527 | } | |
4528 | } | |
8846615a DV |
4529 | var _107=this.element.getContext("2d"); |
4530 | _107.clearRect(0,0,this.width,this.height); | |
6a1aa64f DV |
4531 | MochiKit.Iter.forEach(this.xlabels,MochiKit.DOM.removeElement); |
4532 | MochiKit.Iter.forEach(this.ylabels,MochiKit.DOM.removeElement); | |
4533 | this.xlabels=new Array(); | |
4534 | this.ylabels=new Array(); | |
4535 | }; | |
4536 | PlotKit.CanvasRenderer.prototype._initialiseEvents=function(){ | |
8846615a | 4537 | var _108=MochiKit.Signal.connect; |
6a1aa64f | 4538 | var bind=MochiKit.Base.bind; |
8846615a | 4539 | _108(this.element,"onclick",bind(this.onclick,this)); |
6a1aa64f DV |
4540 | }; |
4541 | PlotKit.CanvasRenderer.prototype._resolveObject=function(e){ | |
4542 | var x=(e.mouse().page.x-PlotKit.Base.findPosX(this.element)-this.area.x)/this.area.w; | |
4543 | var y=(e.mouse().page.y-PlotKit.Base.findPosY(this.element)-this.area.y)/this.area.h; | |
8846615a DV |
4544 | var _111=this.layout.hitTest(x,y); |
4545 | if(_111){ | |
4546 | return _111; | |
6a1aa64f DV |
4547 | } |
4548 | return null; | |
4549 | }; | |
8846615a DV |
4550 | PlotKit.CanvasRenderer.prototype._createEventObject=function(_112,e){ |
4551 | if(_112==null){ | |
6a1aa64f DV |
4552 | return null; |
4553 | } | |
8846615a | 4554 | e.chart=_112; |
6a1aa64f DV |
4555 | return e; |
4556 | }; | |
4557 | PlotKit.CanvasRenderer.prototype.onclick=function(e){ | |
8846615a DV |
4558 | var _113=this._resolveObject(e); |
4559 | var _114=this._createEventObject(_113,e); | |
4560 | if(_114!=null){ | |
4561 | MochiKit.Signal.signal(this,"onclick",_114); | |
6a1aa64f DV |
4562 | } |
4563 | }; | |
4564 | PlotKit.CanvasRenderer.prototype.onmouseover=function(e){ | |
8846615a DV |
4565 | var _115=this._resolveObject(e); |
4566 | var _116=this._createEventObject(_115,e); | |
4567 | if(_116!=null){ | |
4568 | signal(this,"onmouseover",_116); | |
6a1aa64f DV |
4569 | } |
4570 | }; | |
4571 | PlotKit.CanvasRenderer.prototype.onmouseout=function(e){ | |
8846615a DV |
4572 | var _117=this._resolveObject(e); |
4573 | var _118=this._createEventObject(_117,e); | |
4574 | if(_118==null){ | |
6a1aa64f DV |
4575 | signal(this,"onmouseout",e); |
4576 | }else{ | |
8846615a | 4577 | signal(this,"onmouseout",_118); |
6a1aa64f DV |
4578 | } |
4579 | }; | |
4580 | PlotKit.CanvasRenderer.prototype.onmousemove=function(e){ | |
8846615a DV |
4581 | var _119=this._resolveObject(e); |
4582 | var _120=this._createEventObject(_119,e); | |
4583 | if((_119==null)&&(this.event_isinside==null)){ | |
6a1aa64f DV |
4584 | return; |
4585 | } | |
8846615a DV |
4586 | if((_119!=null)&&(this.event_isinside==null)){ |
4587 | signal(this,"onmouseover",_120); | |
6a1aa64f | 4588 | } |
8846615a DV |
4589 | if((_119==null)&&(this.event_isinside!=null)){ |
4590 | signal(this,"onmouseout",_120); | |
6a1aa64f | 4591 | } |
8846615a DV |
4592 | if((_119!=null)&&(this.event_isinside!=null)){ |
4593 | signal(this,"onmousemove",_120); | |
6a1aa64f | 4594 | } |
8846615a | 4595 | this.event_isinside=_119; |
6a1aa64f | 4596 | }; |
8846615a DV |
4597 | PlotKit.CanvasRenderer.isSupported=function(_121){ |
4598 | var _122=null; | |
6a1aa64f | 4599 | try{ |
8846615a DV |
4600 | if(MochiKit.Base.isUndefinedOrNull(_121)){ |
4601 | _122=MochiKit.DOM.CANVAS({}); | |
6a1aa64f | 4602 | }else{ |
8846615a | 4603 | _122=MochiKit.DOM.getElement(_121); |
6a1aa64f | 4604 | } |
8846615a | 4605 | var _123=_122.getContext("2d"); |
6a1aa64f DV |
4606 | } |
4607 | catch(e){ | |
4608 | var ie=navigator.appVersion.match(/MSIE (\d\.\d)/); | |
8846615a DV |
4609 | var _125=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); |
4610 | if((!ie)||(ie[1]<6)||(_125)){ | |
6a1aa64f DV |
4611 | return false; |
4612 | } | |
4613 | return true; | |
4614 | } | |
4615 | return true; | |
4616 | }; | |
4617 | PlotKit.Canvas={}; | |
4618 | PlotKit.Canvas.CanvasRenderer=PlotKit.CanvasRenderer; | |
4619 | PlotKit.Canvas.EXPORT=["CanvasRenderer"]; | |
4620 | PlotKit.Canvas.EXPORT_OK=["CanvasRenderer"]; | |
4621 | PlotKit.Canvas.__new__=function(){ | |
4622 | var m=MochiKit.Base; | |
4623 | m.nameFunctions(this); | |
4624 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
4625 | }; | |
4626 | PlotKit.Canvas.__new__(); | |
4627 | MochiKit.Base._exportSymbols(this,PlotKit.Canvas); | |
6a1aa64f DV |
4628 | |
4629 | ||
6219c9d6 | 4630 | Date.ext={};Date.ext.util={};Date.ext.util.xPad=function(x,pad,r){if(typeof (r)=="undefined"){r=10}for(;parseInt(x,10)<r&&r>1;r/=10){x=pad.toString()+x}return x.toString()};Date.prototype.locale="en-GB";if(document.getElementsByTagName("html")&&document.getElementsByTagName("html")[0].lang){Date.prototype.locale=document.getElementsByTagName("html")[0].lang}Date.ext.locales={};Date.ext.locales.en={a:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],b:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],B:["January","February","March","April","May","June","July","August","September","October","November","December"],c:"%a %d %b %Y %T %Z",p:["AM","PM"],P:["am","pm"],x:"%d/%m/%y",X:"%T"};Date.ext.locales["en-US"]=Date.ext.locales.en;Date.ext.locales["en-US"].c="%a %d %b %Y %r %Z";Date.ext.locales["en-US"].x="%D";Date.ext.locales["en-US"].X="%r";Date.ext.locales["en-GB"]=Date.ext.locales.en;Date.ext.locales["en-AU"]=Date.ext.locales["en-GB"];Date.ext.formats={a:function(d){return Date.ext.locales[d.locale].a[d.getDay()]},A:function(d){return Date.ext.locales[d.locale].A[d.getDay()]},b:function(d){return Date.ext.locales[d.locale].b[d.getMonth()]},B:function(d){return Date.ext.locales[d.locale].B[d.getMonth()]},c:"toLocaleString",C:function(d){return Date.ext.util.xPad(parseInt(d.getFullYear()/100,10),0)},d:["getDate","0"],e:["getDate"," "],g:function(d){return Date.ext.util.xPad(parseInt(Date.ext.util.G(d)/100,10),0)},G:function(d){var y=d.getFullYear();var V=parseInt(Date.ext.formats.V(d),10);var W=parseInt(Date.ext.formats.W(d),10);if(W>V){y++}else{if(W===0&&V>=52){y--}}return y},H:["getHours","0"],I:function(d){var I=d.getHours()%12;return Date.ext.util.xPad(I===0?12:I,0)},j:function(d){var ms=d-new Date(""+d.getFullYear()+"/1/1 GMT");ms+=d.getTimezoneOffset()*60000;var doy=parseInt(ms/60000/60/24,10)+1;return Date.ext.util.xPad(doy,0,100)},m:function(d){return Date.ext.util.xPad(d.getMonth()+1,0)},M:["getMinutes","0"],p:function(d){return Date.ext.locales[d.locale].p[d.getHours()>=12?1:0]},P:function(d){return Date.ext.locales[d.locale].P[d.getHours()>=12?1:0]},S:["getSeconds","0"],u:function(d){var dow=d.getDay();return dow===0?7:dow},U:function(d){var doy=parseInt(Date.ext.formats.j(d),10);var rdow=6-d.getDay();var woy=parseInt((doy+rdow)/7,10);return Date.ext.util.xPad(woy,0)},V:function(d){var woy=parseInt(Date.ext.formats.W(d),10);var dow1_1=(new Date(""+d.getFullYear()+"/1/1")).getDay();var idow=woy+(dow1_1>4||dow1_1<=1?0:1);if(idow==53&&(new Date(""+d.getFullYear()+"/12/31")).getDay()<4){idow=1}else{if(idow===0){idow=Date.ext.formats.V(new Date(""+(d.getFullYear()-1)+"/12/31"))}}return Date.ext.util.xPad(idow,0)},w:"getDay",W:function(d){var doy=parseInt(Date.ext.formats.j(d),10);var rdow=7-Date.ext.formats.u(d);var woy=parseInt((doy+rdow)/7,10);return Date.ext.util.xPad(woy,0,10)},y:function(d){return Date.ext.util.xPad(d.getFullYear()%100,0)},Y:"getFullYear",z:function(d){var o=d.getTimezoneOffset();var H=Date.ext.util.xPad(parseInt(Math.abs(o/60),10),0);var M=Date.ext.util.xPad(o%60,0);return(o>0?"-":"+")+H+M},Z:function(d){return d.toString().replace(/^.*\(([^)]+)\)$/,"$1")},"%":function(d){return"%"}};Date.ext.aggregates={c:"locale",D:"%m/%d/%y",h:"%b",n:"\n",r:"%I:%M:%S %p",R:"%H:%M",t:"\t",T:"%H:%M:%S",x:"locale",X:"locale"};Date.ext.aggregates.z=Date.ext.formats.z(new Date());Date.ext.aggregates.Z=Date.ext.formats.Z(new Date());Date.ext.unsupported={};Date.prototype.strftime=function(fmt){if(!(this.locale in Date.ext.locales)){if(this.locale.replace(/-[a-zA-Z]+$/,"") in Date.ext.locales){this.locale=this.locale.replace(/-[a-zA-Z]+$/,"")}else{this.locale="en-GB"}}var d=this;while(fmt.match(/%[cDhnrRtTxXzZ]/)){fmt=fmt.replace(/%([cDhnrRtTxXzZ])/g,function(m0,m1){var f=Date.ext.aggregates[m1];return(f=="locale"?Date.ext.locales[d.locale][m1]:f)})}var str=fmt.replace(/%([aAbBCdegGHIjmMpPSuUVwWyY%])/g,function(m0,m1){var f=Date.ext.formats[m1];if(typeof (f)=="string"){return d[f]()}else{if(typeof (f)=="function"){return f.call(d,d)}else{if(typeof (f)=="object"&&typeof (f[0])=="string"){return Date.ext.util.xPad(d[f[0]](),f[1])}else{return m1}}}});d=null;return str}; |
285a6bda | 4631 | DygraphLayout=function(_1){ |
b2a516b8 | 4632 | PlotKit.Layout.call(this,"line",_1); |
6a1aa64f | 4633 | }; |
285a6bda DV |
4634 | DygraphLayout.prototype=new PlotKit.Layout(); |
4635 | DygraphLayout.prototype.evaluateWithError=function(){ | |
b2a516b8 DV |
4636 | this.evaluate(); |
4637 | if(!this.options.errorBars){ | |
4638 | return; | |
4639 | } | |
4640 | var i=0; | |
4641 | for(var _3 in this.datasets){ | |
4642 | var j=0; | |
4643 | var _5=this.datasets[_3]; | |
4644 | if(PlotKit.Base.isFuncLike(_5)){ | |
4645 | continue; | |
4646 | } | |
4647 | for(var j=0;j<_5.length;j++,i++){ | |
4648 | var _6=_5[j]; | |
4649 | var xv=parseFloat(_6[0]); | |
4650 | var yv=parseFloat(_6[1]); | |
4651 | if(xv==this.points[i].xval&&yv==this.points[i].yval){ | |
4652 | this.points[i].errorMinus=parseFloat(_6[2]); | |
4653 | this.points[i].errorPlus=parseFloat(_6[3]); | |
4654 | } | |
4655 | } | |
4656 | } | |
6a1aa64f | 4657 | }; |
285a6bda | 4658 | DygraphLayout.prototype.removeAllDatasets=function(){ |
b2a516b8 DV |
4659 | delete this.datasets; |
4660 | this.datasets=new Array(); | |
6a1aa64f | 4661 | }; |
285a6bda | 4662 | DygraphLayout.prototype.updateOptions=function(_9){ |
b2a516b8 DV |
4663 | MochiKit.Base.update(this.options,_9?_9:{}); |
4664 | }; | |
285a6bda | 4665 | DygraphCanvasRenderer=function(_10,_11,_12){ |
b2a516b8 DV |
4666 | PlotKit.CanvasRenderer.call(this,_10,_11,_12); |
4667 | this.options.shouldFill=false; | |
4668 | this.options.shouldStroke=true; | |
4669 | this.options.drawYGrid=true; | |
4670 | this.options.drawXGrid=true; | |
4671 | this.options.gridLineColor=MochiKit.Color.Color.grayColor(); | |
4672 | MochiKit.Base.update(this.options,_12); | |
4673 | this.options.drawBackground=false; | |
4674 | }; | |
285a6bda DV |
4675 | DygraphCanvasRenderer.prototype=new PlotKit.CanvasRenderer(); |
4676 | DygraphCanvasRenderer.prototype.render=function(){ | |
b2a516b8 DV |
4677 | var ctx=this.element.getContext("2d"); |
4678 | if(this.options.drawYGrid){ | |
4679 | var _14=this.layout.yticks; | |
4680 | ctx.save(); | |
4681 | ctx.strokeStyle=this.options.gridLineColor.toRGBString(); | |
4682 | ctx.lineWidth=this.options.axisLineWidth; | |
4683 | for(var i=0;i<_14.length;i++){ | |
4684 | var x=this.area.x; | |
4685 | var y=this.area.y+_14[i][0]*this.area.h; | |
4686 | ctx.beginPath(); | |
4687 | ctx.moveTo(x,y); | |
4688 | ctx.lineTo(x+this.area.w,y); | |
4689 | ctx.closePath(); | |
4690 | ctx.stroke(); | |
4691 | } | |
4692 | } | |
4693 | if(this.options.drawXGrid){ | |
4694 | var _14=this.layout.xticks; | |
4695 | ctx.save(); | |
4696 | ctx.strokeStyle=this.options.gridLineColor.toRGBString(); | |
4697 | ctx.lineWidth=this.options.axisLineWidth; | |
4698 | for(var i=0;i<_14.length;i++){ | |
4699 | var x=this.area.x+_14[i][0]*this.area.w; | |
4700 | var y=this.area.y+this.area.h; | |
4701 | ctx.beginPath(); | |
4702 | ctx.moveTo(x,y); | |
4703 | ctx.lineTo(x,this.area.y); | |
4704 | ctx.closePath(); | |
4705 | ctx.stroke(); | |
4706 | } | |
4707 | } | |
2ce09b19 DV |
4708 | this._renderLineChart(); |
4709 | this._renderLineAxis(); | |
b2a516b8 | 4710 | }; |
285a6bda | 4711 | DygraphCanvasRenderer.prototype._renderLineChart=function(){ |
b2a516b8 DV |
4712 | var _17=this.element.getContext("2d"); |
4713 | var _18=this.options.colorScheme.length; | |
4714 | var _19=this.options.colorScheme; | |
4715 | var _20=MochiKit.Base.keys(this.layout.datasets); | |
4716 | var _21=this.layout.options.errorBars; | |
4717 | var _22=_20.length; | |
4718 | var _23=MochiKit.Base.bind; | |
4719 | var _24=MochiKit.Base.partial; | |
4720 | var _25=function(_26){ | |
4721 | _26.canvasx=this.area.w*_26.x+this.area.x; | |
4722 | _26.canvasy=this.area.h*_26.y+this.area.y; | |
4723 | }; | |
4724 | MochiKit.Iter.forEach(this.layout.points,_25,this); | |
4725 | var _27=function(ctx){ | |
4726 | for(var i=0;i<_22;i++){ | |
4727 | var _28=_20[i]; | |
4728 | var _29=_19[i%_18]; | |
4729 | var _30=this.options.strokeColorTransform; | |
4730 | _17.save(); | |
4731 | _17.strokeStyle=_29.toRGBString(); | |
4732 | _17.lineWidth=this.options.strokeWidth; | |
4733 | ctx.beginPath(); | |
4734 | var _31=this.layout.points[0]; | |
4735 | var _32=true; | |
4736 | var _33=function(_34,_31){ | |
4737 | if(_31.name==_28){ | |
4738 | if(_32){ | |
4739 | _34.moveTo(_31.canvasx,_31.canvasy); | |
4740 | }else{ | |
4741 | _34.lineTo(_31.canvasx,_31.canvasy); | |
4742 | } | |
4743 | _32=false; | |
4744 | } | |
4745 | }; | |
4746 | MochiKit.Iter.forEach(this.layout.points,_24(_33,ctx),this); | |
4747 | ctx.stroke(); | |
4748 | } | |
4749 | }; | |
4750 | var _35=function(ctx){ | |
4751 | for(var i=0;i<_22;i++){ | |
4752 | var _36=_20[i]; | |
4753 | var _37=_19[i%_18]; | |
4754 | var _38=this.options.strokeColorTransform; | |
4755 | _17.save(); | |
4756 | _17.strokeStyle=_37.toRGBString(); | |
4757 | _17.lineWidth=this.options.strokeWidth; | |
4758 | var _39=-1; | |
4759 | var _40=[-1,-1]; | |
4760 | var _41=0; | |
4761 | var _42=this.layout.yscale; | |
4762 | var _43=function(_44,_45){ | |
4763 | _41++; | |
4764 | if(_45.name==_36){ | |
4765 | var _46=[_45.y-_45.errorPlus*_42,_45.y+_45.errorMinus*_42]; | |
4766 | _46[0]=this.area.h*_46[0]+this.area.y; | |
4767 | _46[1]=this.area.h*_46[1]+this.area.y; | |
4768 | if(_39>=0){ | |
4769 | _44.moveTo(_39,_40[0]); | |
4770 | _44.lineTo(_45.canvasx,_46[0]); | |
4771 | _44.lineTo(_45.canvasx,_46[1]); | |
4772 | _44.lineTo(_39,_40[1]); | |
4773 | _44.closePath(); | |
4774 | } | |
4775 | _40[0]=_46[0]; | |
4776 | _40[1]=_46[1]; | |
4777 | _39=_45.canvasx; | |
4778 | } | |
4779 | }; | |
4780 | var _47=_37.colorWithAlpha(0.15); | |
4781 | ctx.fillStyle=_47.toRGBString(); | |
4782 | ctx.beginPath(); | |
4783 | MochiKit.Iter.forEach(this.layout.points,_24(_43,ctx),this); | |
4784 | ctx.fill(); | |
4785 | } | |
6a1aa64f | 4786 | }; |
b2a516b8 DV |
4787 | if(_21){ |
4788 | _23(_35,this)(_17); | |
4789 | } | |
4790 | _23(_27,this)(_17); | |
4791 | _17.restore(); | |
6a1aa64f | 4792 | }; |
285a6bda | 4793 | Dygraph=function(div,_49,_50){ |
b2a516b8 | 4794 | if(arguments.length>0){ |
285a6bda DV |
4795 | if(arguments.length==4){ |
4796 | this.warn("Using deprecated four-argument dygraph constructor"); | |
4797 | this.__old_init__(div,_49,arguments[2],arguments[3]); | |
4798 | }else{ | |
4799 | this.__init__(div,_49,_50); | |
4800 | } | |
b2a516b8 | 4801 | } |
6a1aa64f | 4802 | }; |
285a6bda DV |
4803 | Dygraph.NAME="Dygraph"; |
4804 | Dygraph.VERSION="1.2"; | |
4805 | Dygraph.__repr__=function(){ | |
b2a516b8 | 4806 | return "["+this.NAME+" "+this.VERSION+"]"; |
6a1aa64f | 4807 | }; |
285a6bda | 4808 | Dygraph.toString=function(){ |
b2a516b8 | 4809 | return this.__repr__(); |
6a1aa64f | 4810 | }; |
285a6bda DV |
4811 | Dygraph.DEFAULT_ROLL_PERIOD=1; |
4812 | Dygraph.DEFAULT_WIDTH=480; | |
4813 | Dygraph.DEFAULT_HEIGHT=320; | |
4814 | Dygraph.AXIS_LINE_WIDTH=0.3; | |
8846615a | 4815 | Dygraph.DEFAULT_ATTRS={highlightCircleSize:3,pixelsPerXLabel:60,pixelsPerYLabel:30,labelsDivWidth:250,labelsDivStyles:{},labelsSeparateLines:false,labelsKMB:false,strokeWidth:1,axisTickSize:3,axisLabelFontSize:14,xAxisLabelWidth:50,yAxisLabelWidth:50,rightGap:5,showRoller:false,xValueFormatter:Dygraph.dateString_,xValueParser:Dygraph.dateParser,xTicker:Dygraph.dateTicker,sigma:2,errorBars:false,fractions:false,wilsonInterval:true,customBars:false}; |
285a6bda DV |
4816 | Dygraph.DEBUG=1; |
4817 | Dygraph.INFO=2; | |
4818 | Dygraph.WARNING=3; | |
4819 | Dygraph.ERROR=3; | |
4820 | Dygraph.prototype.__old_init__=function(div,_51,_52,_53){ | |
4821 | if(_52!=null){ | |
4822 | var _54=["Date"]; | |
4823 | for(var i=0;i<_52.length;i++){ | |
4824 | _54.push(_52[i]); | |
4825 | } | |
4826 | MochiKit.Base.update(_53,{"labels":_54}); | |
4827 | } | |
4828 | this.__init__(div,_51,_53); | |
4829 | }; | |
4830 | Dygraph.prototype.__init__=function(div,_55,_56){ | |
4831 | if(_56==null){ | |
4832 | _56={}; | |
4833 | } | |
b2a516b8 | 4834 | this.maindiv_=div; |
285a6bda DV |
4835 | this.file_=_55; |
4836 | this.rollPeriod_=_56.rollPeriod||Dygraph.DEFAULT_ROLL_PERIOD; | |
b2a516b8 | 4837 | this.previousVerticalX_=-1; |
285a6bda DV |
4838 | this.fractions_=_56.fractions||false; |
4839 | this.dateWindow_=_56.dateWindow||null; | |
4840 | this.valueRange_=_56.valueRange||null; | |
4841 | this.wilsonInterval_=_56.wilsonInterval||true; | |
4842 | this.customBars_=_56.customBars||false; | |
4843 | if(div.style.width==""){ | |
4844 | div.style.width=Dygraph.DEFAULT_WIDTH+"px"; | |
4845 | } | |
4846 | if(div.style.height==""){ | |
4847 | div.style.height=Dygraph.DEFAULT_HEIGHT+"px"; | |
4848 | } | |
b2a516b8 DV |
4849 | this.width_=parseInt(div.style.width,10); |
4850 | this.height_=parseInt(div.style.height,10); | |
285a6bda DV |
4851 | this.user_attrs_={}; |
4852 | MochiKit.Base.update(this.user_attrs_,_56); | |
b8339f6e | 4853 | this.attrs_={}; |
285a6bda DV |
4854 | MochiKit.Base.update(this.attrs_,Dygraph.DEFAULT_ATTRS); |
4855 | this.labelsFromCSV_=(this.attr_("labels")==null); | |
b2a516b8 | 4856 | this.createInterface_(); |
285a6bda DV |
4857 | this.layoutOptions_={"errorBars":(this.attr_("errorBars")||this.customBars_),"xOriginIsZero":false}; |
4858 | MochiKit.Base.update(this.layoutOptions_,this.attrs_); | |
4859 | MochiKit.Base.update(this.layoutOptions_,this.user_attrs_); | |
4860 | this.layout_=new DygraphLayout(this.layoutOptions_); | |
8846615a | 4861 | this.renderOptions_={colorScheme:this.colors_,strokeColor:null,axisLineWidth:Dygraph.AXIS_LINE_WIDTH}; |
285a6bda DV |
4862 | MochiKit.Base.update(this.renderOptions_,this.attrs_); |
4863 | MochiKit.Base.update(this.renderOptions_,this.user_attrs_); | |
4864 | this.plotter_=new DygraphCanvasRenderer(this.hidden_,this.layout_,this.renderOptions_); | |
b2a516b8 DV |
4865 | this.createStatusMessage_(); |
4866 | this.createRollInterface_(); | |
4867 | this.createDragInterface_(); | |
b2a516b8 | 4868 | this.start_(); |
6a1aa64f | 4869 | }; |
285a6bda DV |
4870 | Dygraph.prototype.attr_=function(_57){ |
4871 | if(typeof (this.user_attrs_[_57])!="undefined"){ | |
4872 | return this.user_attrs_[_57]; | |
4873 | }else{ | |
4874 | if(typeof (this.attrs_[_57])!="undefined"){ | |
4875 | return this.attrs_[_57]; | |
4876 | }else{ | |
4877 | return null; | |
4878 | } | |
4879 | } | |
4880 | }; | |
4881 | Dygraph.prototype.log=function(_58,_59){ | |
4882 | if(typeof (console)!="undefined"){ | |
4883 | switch(_58){ | |
4884 | case Dygraph.DEBUG: | |
4885 | console.debug("dygraphs: "+_59); | |
4886 | break; | |
4887 | case Dygraph.INFO: | |
4888 | console.info("dygraphs: "+_59); | |
4889 | break; | |
4890 | case Dygraph.WARNING: | |
4891 | console.warn("dygraphs: "+_59); | |
4892 | break; | |
4893 | case Dygraph.ERROR: | |
4894 | console.error("dygraphs: "+_59); | |
4895 | break; | |
4896 | } | |
4897 | } | |
4898 | }; | |
4899 | Dygraph.prototype.info=function(_60){ | |
4900 | this.log(Dygraph.INFO,_60); | |
4901 | }; | |
4902 | Dygraph.prototype.warn=function(_61){ | |
4903 | this.log(Dygraph.WARNING,_61); | |
4904 | }; | |
4905 | Dygraph.prototype.error=function(_62){ | |
4906 | this.log(Dygraph.ERROR,_62); | |
4907 | }; | |
4908 | Dygraph.prototype.rollPeriod=function(){ | |
b2a516b8 DV |
4909 | return this.rollPeriod_; |
4910 | }; | |
285a6bda DV |
4911 | Dygraph.prototype.createInterface_=function(){ |
4912 | var _63=this.maindiv_; | |
b2a516b8 | 4913 | this.graphDiv=MochiKit.DOM.DIV({style:{"width":this.width_+"px","height":this.height_+"px"}}); |
285a6bda DV |
4914 | appendChildNodes(_63,this.graphDiv); |
4915 | var _64=MochiKit.DOM.CANVAS; | |
4916 | this.canvas_=_64({style:{"position":"absolute"},width:this.width_,height:this.height_}); | |
b2a516b8 DV |
4917 | appendChildNodes(this.graphDiv,this.canvas_); |
4918 | this.hidden_=this.createPlotKitCanvas_(this.canvas_); | |
4919 | connect(this.hidden_,"onmousemove",this,function(e){ | |
4920 | this.mouseMove_(e); | |
4921 | }); | |
4922 | connect(this.hidden_,"onmouseout",this,function(e){ | |
4923 | this.mouseOut_(e); | |
4924 | }); | |
6a1aa64f | 4925 | }; |
285a6bda | 4926 | Dygraph.prototype.createPlotKitCanvas_=function(_66){ |
b2a516b8 DV |
4927 | var h=document.createElement("canvas"); |
4928 | h.style.position="absolute"; | |
285a6bda DV |
4929 | h.style.top=_66.style.top; |
4930 | h.style.left=_66.style.left; | |
b2a516b8 DV |
4931 | h.width=this.width_; |
4932 | h.height=this.height_; | |
4933 | MochiKit.DOM.appendChildNodes(this.graphDiv,h); | |
4934 | return h; | |
4935 | }; | |
285a6bda DV |
4936 | Dygraph.prototype.setColors_=function(){ |
4937 | var num=this.attr_("labels").length-1; | |
b2a516b8 | 4938 | this.colors_=[]; |
285a6bda DV |
4939 | var _69=this.attr_("colors"); |
4940 | if(!_69){ | |
4941 | var sat=this.attr_("colorSaturation")||1; | |
4942 | var val=this.attr_("colorValue")||0.5; | |
b2a516b8 DV |
4943 | for(var i=1;i<=num;i++){ |
4944 | var hue=(1*i/(1+num)); | |
4945 | this.colors_.push(MochiKit.Color.Color.fromHSV(hue,sat,val)); | |
4946 | } | |
4947 | }else{ | |
4948 | for(var i=0;i<num;i++){ | |
285a6bda DV |
4949 | var _73=_69[i%_69.length]; |
4950 | this.colors_.push(MochiKit.Color.Color.fromString(_73)); | |
b2a516b8 | 4951 | } |
b2a516b8 | 4952 | } |
285a6bda DV |
4953 | this.renderOptions_.colorScheme=this.colors_; |
4954 | MochiKit.Base.update(this.plotter_.options,this.renderOptions_); | |
4955 | MochiKit.Base.update(this.layoutOptions_,this.user_attrs_); | |
4956 | MochiKit.Base.update(this.layoutOptions_,this.attrs_); | |
b2a516b8 | 4957 | }; |
285a6bda DV |
4958 | Dygraph.prototype.createStatusMessage_=function(){ |
4959 | if(!this.attr_("labelsDiv")){ | |
4960 | var _74=this.attr_("labelsDivWidth"); | |
8846615a | 4961 | var _75={"style":{"position":"absolute","fontSize":"14px","zIndex":10,"width":_74+"px","top":"0px","left":(this.width_-_74-2)+"px","background":"white","textAlign":"left","overflow":"hidden"}}; |
285a6bda DV |
4962 | MochiKit.Base.update(_75["style"],this.attr_("labelsDivStyles")); |
4963 | var div=MochiKit.DOM.DIV(_75); | |
4964 | MochiKit.DOM.appendChildNodes(this.graphDiv,div); | |
4965 | this.attrs_.labelsDiv=div; | |
4966 | } | |
4967 | }; | |
4968 | Dygraph.prototype.createRollInterface_=function(){ | |
8846615a DV |
4969 | var _76=this.attr_("showRoller")?"block":"none"; |
4970 | var _77={"type":"text","size":"2","value":this.rollPeriod_,"style":{"position":"absolute","zIndex":10,"top":(this.plotter_.area.h-25)+"px","left":(this.plotter_.area.x+1)+"px","display":_76}}; | |
4971 | var _78=MochiKit.DOM.INPUT(_77); | |
b2a516b8 | 4972 | var pa=this.graphDiv; |
8846615a DV |
4973 | MochiKit.DOM.appendChildNodes(pa,_78); |
4974 | connect(_78,"onchange",this,function(){ | |
4975 | this.adjustRoll(_78.value); | |
b2a516b8 | 4976 | }); |
8846615a | 4977 | return _78; |
285a6bda DV |
4978 | }; |
4979 | Dygraph.prototype.createDragInterface_=function(){ | |
8846615a DV |
4980 | var _80=this; |
4981 | var _81=false; | |
4982 | var _82=null; | |
285a6bda DV |
4983 | var _83=null; |
4984 | var _84=null; | |
4985 | var _85=null; | |
4986 | var _86=null; | |
353a0294 DV |
4987 | var px=0; |
4988 | var py=0; | |
8846615a | 4989 | var _89=function(e){ |
b2a516b8 DV |
4990 | return e.mouse().page.x-px; |
4991 | }; | |
8846615a | 4992 | var _90=function(e){ |
b2a516b8 DV |
4993 | return e.mouse().page.y-py; |
4994 | }; | |
8846615a DV |
4995 | connect(this.hidden_,"onmousemove",function(_91){ |
4996 | if(_81){ | |
4997 | _84=_89(_91); | |
4998 | _85=_90(_91); | |
4999 | _80.drawZoomRect_(_82,_84,_86); | |
5000 | _86=_84; | |
6a1aa64f | 5001 | } |
b2a516b8 | 5002 | }); |
8846615a DV |
5003 | connect(this.hidden_,"onmousedown",function(_92){ |
5004 | _81=true; | |
5005 | px=PlotKit.Base.findPosX(_80.canvas_); | |
5006 | py=PlotKit.Base.findPosY(_80.canvas_); | |
5007 | _82=_89(_92); | |
5008 | _83=_90(_92); | |
b2a516b8 | 5009 | }); |
8846615a DV |
5010 | connect(document,"onmouseup",this,function(_93){ |
5011 | if(_81){ | |
5012 | _81=false; | |
5013 | _82=null; | |
285a6bda | 5014 | _83=null; |
6a1aa64f | 5015 | } |
b2a516b8 | 5016 | }); |
8846615a DV |
5017 | connect(this.hidden_,"onmouseout",this,function(_94){ |
5018 | if(_81){ | |
5019 | _84=null; | |
285a6bda | 5020 | _85=null; |
6a1aa64f | 5021 | } |
b2a516b8 | 5022 | }); |
8846615a DV |
5023 | connect(this.hidden_,"onmouseup",this,function(_95){ |
5024 | if(_81){ | |
5025 | _81=false; | |
5026 | _84=_89(_95); | |
5027 | _85=_90(_95); | |
5028 | var _96=Math.abs(_84-_82); | |
285a6bda | 5029 | var _97=Math.abs(_85-_83); |
8846615a DV |
5030 | if(_96<2&&_97<2&&_80.attr_("clickCallback")!=null&&_80.lastx_!=undefined){ |
5031 | _80.attr_("clickCallback")(_95,new Date(_80.lastx_)); | |
6a1aa64f | 5032 | } |
8846615a DV |
5033 | if(_96>=10){ |
5034 | _80.doZoom_(Math.min(_82,_84),Math.max(_82,_84)); | |
b2a516b8 | 5035 | }else{ |
8846615a | 5036 | _80.canvas_.getContext("2d").clearRect(0,0,_80.canvas_.width,_80.canvas_.height); |
b2a516b8 | 5037 | } |
8846615a | 5038 | _82=null; |
285a6bda | 5039 | _83=null; |
b2a516b8 DV |
5040 | } |
5041 | }); | |
8846615a DV |
5042 | connect(this.hidden_,"ondblclick",this,function(_98){ |
5043 | _80.dateWindow_=null; | |
5044 | _80.drawGraph_(_80.rawData_); | |
5045 | var _99=_80.rawData_[0][0]; | |
5046 | var _100=_80.rawData_[_80.rawData_.length-1][0]; | |
5047 | if(_80.attr_("zoomCallback")){ | |
5048 | _80.attr_("zoomCallback")(_99,_100); | |
67e650dc | 5049 | } |
b2a516b8 | 5050 | }); |
6a1aa64f | 5051 | }; |
8846615a | 5052 | Dygraph.prototype.drawZoomRect_=function(_101,endX,_103){ |
b2a516b8 | 5053 | var ctx=this.canvas_.getContext("2d"); |
8846615a DV |
5054 | if(_103){ |
5055 | ctx.clearRect(Math.min(_101,_103),0,Math.abs(_101-_103),this.height_); | |
b2a516b8 | 5056 | } |
8846615a | 5057 | if(endX&&_101){ |
b2a516b8 | 5058 | ctx.fillStyle="rgba(128,128,128,0.33)"; |
8846615a | 5059 | ctx.fillRect(Math.min(_101,endX),0,Math.abs(endX-_101),this.height_); |
b2a516b8 DV |
5060 | } |
5061 | }; | |
8846615a DV |
5062 | Dygraph.prototype.doZoom_=function(lowX,_105){ |
5063 | var _106=this.layout_.points; | |
5064 | var _107=null; | |
285a6bda | 5065 | var _108=null; |
8846615a DV |
5066 | for(var i=0;i<_106.length;i++){ |
5067 | var cx=_106[i].canvasx; | |
5068 | var x=_106[i].xval; | |
5069 | if(cx<lowX&&(_107==null||x>_107)){ | |
5070 | _107=x; | |
5071 | } | |
5072 | if(cx>_105&&(_108==null||x<_108)){ | |
285a6bda | 5073 | _108=x; |
b2a516b8 DV |
5074 | } |
5075 | } | |
8846615a DV |
5076 | if(_107==null){ |
5077 | _107=_106[0].xval; | |
b2a516b8 | 5078 | } |
285a6bda | 5079 | if(_108==null){ |
8846615a | 5080 | _108=_106[_106.length-1].xval; |
b2a516b8 | 5081 | } |
8846615a | 5082 | this.dateWindow_=[_107,_108]; |
b2a516b8 | 5083 | this.drawGraph_(this.rawData_); |
285a6bda | 5084 | if(this.attr_("zoomCallback")){ |
8846615a | 5085 | this.attr_("zoomCallback")(_107,_108); |
67e650dc | 5086 | } |
b2a516b8 | 5087 | }; |
8846615a DV |
5088 | Dygraph.prototype.mouseMove_=function(_110){ |
5089 | var _111=_110.mouse().page.x-PlotKit.Base.findPosX(this.hidden_); | |
5090 | var _112=this.layout_.points; | |
5091 | var _113=-1; | |
285a6bda | 5092 | var _114=-1; |
8846615a | 5093 | var _115=1e+100; |
b2a516b8 | 5094 | var idx=-1; |
8846615a DV |
5095 | for(var i=0;i<_112.length;i++){ |
5096 | var dist=Math.abs(_112[i].canvasx-_111); | |
5097 | if(dist>_115){ | |
b2a516b8 DV |
5098 | break; |
5099 | } | |
8846615a | 5100 | _115=dist; |
b2a516b8 DV |
5101 | idx=i; |
5102 | } | |
5103 | if(idx>=0){ | |
8846615a | 5104 | _113=_112[idx].xval; |
b2a516b8 | 5105 | } |
8846615a DV |
5106 | if(_111>_112[_112.length-1].canvasx){ |
5107 | _113=_112[_112.length-1].xval; | |
b2a516b8 | 5108 | } |
8846615a DV |
5109 | var _118=[]; |
5110 | for(var i=0;i<_112.length;i++){ | |
5111 | if(_112[i].xval==_113){ | |
5112 | _118.push(_112[i]); | |
b2a516b8 DV |
5113 | } |
5114 | } | |
8846615a | 5115 | var _119=this.attr_("highlightCircleSize"); |
b2a516b8 DV |
5116 | var ctx=this.canvas_.getContext("2d"); |
5117 | if(this.previousVerticalX_>=0){ | |
5118 | var px=this.previousVerticalX_; | |
8846615a | 5119 | ctx.clearRect(px-_119-1,0,2*_119+2,this.height_); |
b2a516b8 | 5120 | } |
8846615a DV |
5121 | if(_118.length>0){ |
5122 | var _111=_118[0].canvasx; | |
5123 | var _120=this.attr_("xValueFormatter")(_113,this)+":"; | |
b2a516b8 | 5124 | var clen=this.colors_.length; |
8846615a | 5125 | for(var i=0;i<_118.length;i++){ |
285a6bda | 5126 | if(this.attr_("labelsSeparateLines")){ |
8846615a | 5127 | _120+="<br/>"; |
b2a516b8 | 5128 | } |
8846615a DV |
5129 | var _122=_118[i]; |
5130 | _120+=" <b><font color='"+this.colors_[i%clen].toHexString()+"'>"+_122.name+"</font></b>:"+this.round_(_122.yval,2); | |
b2a516b8 | 5131 | } |
8846615a DV |
5132 | this.attr_("labelsDiv").innerHTML=_120; |
5133 | this.lastx_=_113; | |
b2a516b8 | 5134 | ctx.save(); |
8846615a | 5135 | for(var i=0;i<_118.length;i++){ |
b2a516b8 DV |
5136 | ctx.beginPath(); |
5137 | ctx.fillStyle=this.colors_[i%clen].toRGBString(); | |
8846615a | 5138 | ctx.arc(_111,_118[i%clen].canvasy,_119,0,360,false); |
b2a516b8 DV |
5139 | ctx.fill(); |
5140 | } | |
5141 | ctx.restore(); | |
8846615a | 5142 | this.previousVerticalX_=_111; |
b2a516b8 | 5143 | } |
6a1aa64f | 5144 | }; |
8846615a | 5145 | Dygraph.prototype.mouseOut_=function(_123){ |
b2a516b8 DV |
5146 | var ctx=this.canvas_.getContext("2d"); |
5147 | ctx.clearRect(0,0,this.width_,this.height_); | |
285a6bda | 5148 | this.attr_("labelsDiv").innerHTML=""; |
6a1aa64f | 5149 | }; |
285a6bda | 5150 | Dygraph.zeropad=function(x){ |
6372d433 DV |
5151 | if(x<10){ |
5152 | return "0"+x; | |
5153 | }else{ | |
5154 | return ""+x; | |
5155 | } | |
5156 | }; | |
285a6bda | 5157 | Dygraph.prototype.hmsString_=function(date){ |
8846615a | 5158 | var _125=Dygraph.zeropad; |
6372d433 DV |
5159 | var d=new Date(date); |
5160 | if(d.getSeconds()){ | |
8846615a | 5161 | return _125(d.getHours())+":"+_125(d.getMinutes())+":"+_125(d.getSeconds()); |
6372d433 DV |
5162 | }else{ |
5163 | if(d.getMinutes()){ | |
8846615a | 5164 | return _125(d.getHours())+":"+_125(d.getMinutes()); |
6372d433 | 5165 | }else{ |
8846615a | 5166 | return _125(d.getHours()); |
6372d433 DV |
5167 | } |
5168 | } | |
5169 | }; | |
285a6bda | 5170 | Dygraph.dateString_=function(date,self){ |
8846615a | 5171 | var _128=Dygraph.zeropad; |
b2a516b8 DV |
5172 | var d=new Date(date); |
5173 | var year=""+d.getFullYear(); | |
8846615a DV |
5174 | var _130=_128(d.getMonth()+1); |
5175 | var day=_128(d.getDate()); | |
6372d433 DV |
5176 | var ret=""; |
5177 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); | |
5178 | if(frac){ | |
285a6bda | 5179 | ret=" "+self.hmsString_(date); |
b2a516b8 | 5180 | } |
8846615a | 5181 | return year+"/"+_130+"/"+day+ret; |
6a1aa64f | 5182 | }; |
8846615a DV |
5183 | Dygraph.prototype.round_=function(num,_134){ |
5184 | var _135=Math.pow(10,_134); | |
5185 | return Math.round(num*_135)/_135; | |
6a1aa64f | 5186 | }; |
285a6bda | 5187 | Dygraph.prototype.loadedEvent_=function(data){ |
b2a516b8 DV |
5188 | this.rawData_=this.parseCSV_(data); |
5189 | this.drawGraph_(this.rawData_); | |
6a1aa64f | 5190 | }; |
285a6bda DV |
5191 | Dygraph.prototype.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; |
5192 | Dygraph.prototype.quarters=["Jan","Apr","Jul","Oct"]; | |
5193 | Dygraph.prototype.addXTicks_=function(){ | |
8846615a | 5194 | var _137,endDate; |
b2a516b8 | 5195 | if(this.dateWindow_){ |
8846615a | 5196 | _137=this.dateWindow_[0]; |
b2a516b8 DV |
5197 | endDate=this.dateWindow_[1]; |
5198 | }else{ | |
8846615a | 5199 | _137=this.rawData_[0][0]; |
b2a516b8 DV |
5200 | endDate=this.rawData_[this.rawData_.length-1][0]; |
5201 | } | |
8846615a DV |
5202 | var _138=this.attr_("xTicker")(_137,endDate,this); |
5203 | this.layout_.updateOptions({xTicks:_138}); | |
285a6bda DV |
5204 | }; |
5205 | Dygraph.SECONDLY=0; | |
5206 | Dygraph.TEN_SECONDLY=1; | |
5207 | Dygraph.THIRTY_SECONDLY=2; | |
5208 | Dygraph.MINUTELY=3; | |
5209 | Dygraph.TEN_MINUTELY=4; | |
5210 | Dygraph.THIRTY_MINUTELY=5; | |
5211 | Dygraph.HOURLY=6; | |
5212 | Dygraph.SIX_HOURLY=7; | |
5213 | Dygraph.DAILY=8; | |
5214 | Dygraph.WEEKLY=9; | |
5215 | Dygraph.MONTHLY=10; | |
5216 | Dygraph.QUARTERLY=11; | |
5217 | Dygraph.BIANNUAL=12; | |
5218 | Dygraph.ANNUAL=13; | |
5219 | Dygraph.DECADAL=14; | |
5220 | Dygraph.NUM_GRANULARITIES=15; | |
5221 | Dygraph.SHORT_SPACINGS=[]; | |
5222 | Dygraph.SHORT_SPACINGS[Dygraph.SECONDLY]=1000*1; | |
5223 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_SECONDLY]=1000*10; | |
5224 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_SECONDLY]=1000*30; | |
5225 | Dygraph.SHORT_SPACINGS[Dygraph.MINUTELY]=1000*60; | |
5226 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_MINUTELY]=1000*60*10; | |
5227 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_MINUTELY]=1000*60*30; | |
5228 | Dygraph.SHORT_SPACINGS[Dygraph.HOURLY]=1000*3600; | |
5229 | Dygraph.SHORT_SPACINGS[Dygraph.HOURLY]=1000*3600*6; | |
5230 | Dygraph.SHORT_SPACINGS[Dygraph.DAILY]=1000*86400; | |
5231 | Dygraph.SHORT_SPACINGS[Dygraph.WEEKLY]=1000*604800; | |
8846615a DV |
5232 | Dygraph.prototype.NumXTicks=function(_139,_140,_141){ |
5233 | if(_141<Dygraph.MONTHLY){ | |
5234 | var _142=Dygraph.SHORT_SPACINGS[_141]; | |
5235 | return Math.floor(0.5+1*(_140-_139)/_142); | |
285a6bda | 5236 | }else{ |
8846615a DV |
5237 | var _143=1; |
5238 | var _144=12; | |
5239 | if(_141==Dygraph.QUARTERLY){ | |
5240 | _144=3; | |
285a6bda | 5241 | } |
8846615a DV |
5242 | if(_141==Dygraph.BIANNUAL){ |
5243 | _144=2; | |
285a6bda | 5244 | } |
8846615a DV |
5245 | if(_141==Dygraph.ANNUAL){ |
5246 | _144=1; | |
285a6bda | 5247 | } |
8846615a DV |
5248 | if(_141==Dygraph.DECADAL){ |
5249 | _144=1; | |
5250 | _143=10; | |
285a6bda | 5251 | } |
8846615a DV |
5252 | var _145=365.2524*24*3600*1000; |
5253 | var _146=1*(_140-_139)/_145; | |
5254 | return Math.floor(0.5+1*_146*_144/_143); | |
285a6bda DV |
5255 | } |
5256 | }; | |
8846615a DV |
5257 | Dygraph.prototype.GetXAxis=function(_147,_148,_149){ |
5258 | var _150=[]; | |
5259 | if(_149<Dygraph.MONTHLY){ | |
5260 | var _151=Dygraph.SHORT_SPACINGS[_149]; | |
5261 | var _152="%d%b"; | |
5262 | if(_149<Dygraph.HOURLY){ | |
5263 | _147=_151*Math.floor(0.5+_147/_151); | |
285a6bda | 5264 | } |
8846615a | 5265 | for(var t=_147;t<=_148;t+=_151){ |
36615faf DV |
5266 | var d=new Date(t); |
5267 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); | |
8846615a DV |
5268 | if(frac==0||_149>=Dygraph.DAILY){ |
5269 | _150.push({v:t,label:new Date(t+3600*1000).strftime(_152)}); | |
b2a516b8 | 5270 | }else{ |
8846615a | 5271 | _150.push({v:t,label:this.hmsString_(t)}); |
36615faf DV |
5272 | } |
5273 | } | |
b2a516b8 | 5274 | }else{ |
8846615a DV |
5275 | var _154; |
5276 | var _155=1; | |
5277 | if(_149==Dygraph.MONTHLY){ | |
5278 | _154=[0,1,2,3,4,5,6,7,8,9,10,11,12]; | |
b2a516b8 | 5279 | }else{ |
8846615a DV |
5280 | if(_149==Dygraph.QUARTERLY){ |
5281 | _154=[0,3,6,9]; | |
b2a516b8 | 5282 | }else{ |
8846615a DV |
5283 | if(_149==Dygraph.BIANNUAL){ |
5284 | _154=[0,6]; | |
b2a516b8 | 5285 | }else{ |
8846615a DV |
5286 | if(_149==Dygraph.ANNUAL){ |
5287 | _154=[0]; | |
6372d433 | 5288 | }else{ |
8846615a DV |
5289 | if(_149==Dygraph.DECADAL){ |
5290 | _154=[0]; | |
5291 | _155=10; | |
b2a516b8 DV |
5292 | } |
5293 | } | |
5294 | } | |
5295 | } | |
6372d433 | 5296 | } |
8846615a | 5297 | var _156=new Date(_147).getFullYear(); |
285a6bda | 5298 | var _157=new Date(_148).getFullYear(); |
8846615a DV |
5299 | var _158=Dygraph.zeropad; |
5300 | for(var i=_156;i<=_157;i++){ | |
5301 | if(i%_155!=0){ | |
36615faf | 5302 | continue; |
6372d433 | 5303 | } |
8846615a DV |
5304 | for(var j=0;j<_154.length;j++){ |
5305 | var _159=i+"/"+_158(1+_154[j])+"/01"; | |
5306 | var t=Date.parse(_159); | |
5307 | if(t<_147||t>_148){ | |
b2a516b8 DV |
5308 | continue; |
5309 | } | |
8846615a | 5310 | _150.push({v:t,label:new Date(t).strftime("%b %y")}); |
b2a516b8 DV |
5311 | } |
5312 | } | |
b2a516b8 | 5313 | } |
8846615a | 5314 | return _150; |
36615faf | 5315 | }; |
8846615a DV |
5316 | Dygraph.dateTicker=function(_160,_161,self){ |
5317 | var _162=-1; | |
285a6bda | 5318 | for(var i=0;i<Dygraph.NUM_GRANULARITIES;i++){ |
8846615a DV |
5319 | var _163=self.NumXTicks(_160,_161,i); |
5320 | if(self.width_/_163>=self.attr_("pixelsPerXLabel")){ | |
5321 | _162=i; | |
36615faf DV |
5322 | break; |
5323 | } | |
b2a516b8 | 5324 | } |
8846615a DV |
5325 | if(_162>=0){ |
5326 | return self.GetXAxis(_160,_161,_162); | |
36615faf | 5327 | }else{ |
6372d433 | 5328 | } |
6a1aa64f | 5329 | }; |
285a6bda | 5330 | Dygraph.numericTicks=function(minV,maxV,self){ |
8846615a DV |
5331 | var _166=[1,2,5]; |
5332 | var _167,low_val,high_val,nTicks; | |
5333 | var _168=self.attr_("pixelsPerYLabel"); | |
2ce09b19 | 5334 | for(var i=-10;i<50;i++){ |
8846615a DV |
5335 | var _169=Math.pow(10,i); |
5336 | for(var j=0;j<_166.length;j++){ | |
5337 | _167=_169*_166[j]; | |
5338 | low_val=Math.floor(minV/_167)*_167; | |
5339 | high_val=Math.ceil(maxV/_167)*_167; | |
5340 | nTicks=(high_val-low_val)/_167; | |
5341 | var _170=self.height_/nTicks; | |
5342 | if(_170>_168){ | |
2ce09b19 | 5343 | break; |
6a1aa64f | 5344 | } |
b2a516b8 | 5345 | } |
8846615a | 5346 | if(_170>_168){ |
2ce09b19 | 5347 | break; |
b2a516b8 | 5348 | } |
2ce09b19 | 5349 | } |
8846615a | 5350 | var _171=[]; |
2ce09b19 | 5351 | for(var i=0;i<nTicks;i++){ |
8846615a DV |
5352 | var _172=low_val+i*_167; |
5353 | var _173=self.round_(_172,2); | |
285a6bda | 5354 | if(self.attr_("labelsKMB")){ |
b2a516b8 | 5355 | var k=1000; |
8846615a DV |
5356 | if(_172>=k*k*k){ |
5357 | _173=self.round_(_172/(k*k*k),1)+"B"; | |
b2a516b8 | 5358 | }else{ |
8846615a DV |
5359 | if(_172>=k*k){ |
5360 | _173=self.round_(_172/(k*k),1)+"M"; | |
b2a516b8 | 5361 | }else{ |
8846615a DV |
5362 | if(_172>=k){ |
5363 | _173=self.round_(_172/k,1)+"K"; | |
b2a516b8 DV |
5364 | } |
5365 | } | |
5366 | } | |
5367 | } | |
8846615a | 5368 | _171.push({label:_173,v:_172}); |
b2a516b8 | 5369 | } |
8846615a | 5370 | return _171; |
6a1aa64f | 5371 | }; |
285a6bda | 5372 | Dygraph.prototype.addYTicks_=function(minY,maxY){ |
8846615a DV |
5373 | var _177=Dygraph.numericTicks(minY,maxY,this); |
5374 | this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_177}); | |
6a1aa64f | 5375 | }; |
285a6bda | 5376 | Dygraph.prototype.drawGraph_=function(data){ |
b2a516b8 DV |
5377 | var maxY=null; |
5378 | this.layout_.removeAllDatasets(); | |
285a6bda | 5379 | this.setColors_(); |
b2a516b8 | 5380 | for(var i=1;i<data[0].length;i++){ |
8846615a | 5381 | var _178=[]; |
b2a516b8 DV |
5382 | for(var j=0;j<data.length;j++){ |
5383 | var date=data[j][0]; | |
8846615a | 5384 | _178[j]=[date,data[j][i]]; |
b2a516b8 | 5385 | } |
8846615a | 5386 | _178=this.rollingAverage(_178,this.rollPeriod_); |
285a6bda | 5387 | var bars=this.attr_("errorBars")||this.customBars_; |
b2a516b8 DV |
5388 | if(this.dateWindow_){ |
5389 | var low=this.dateWindow_[0]; | |
5390 | var high=this.dateWindow_[1]; | |
8846615a DV |
5391 | var _182=[]; |
5392 | for(var k=0;k<_178.length;k++){ | |
5393 | if(_178[k][0]>=low&&_178[k][0]<=high){ | |
5394 | _182.push(_178[k]); | |
5395 | var y=bars?_178[k][1][0]:_178[k][1]; | |
b2a516b8 DV |
5396 | if(maxY==null||y>maxY){ |
5397 | maxY=y; | |
5398 | } | |
5399 | } | |
5400 | } | |
8846615a | 5401 | _178=_182; |
285a6bda DV |
5402 | }else{ |
5403 | if(!this.customBars_){ | |
8846615a DV |
5404 | for(var j=0;j<_178.length;j++){ |
5405 | var y=bars?_178[j][1][0]:_178[j][1]; | |
285a6bda | 5406 | if(maxY==null||y>maxY){ |
8846615a | 5407 | maxY=bars?y+_178[j][1][1]:y; |
285a6bda DV |
5408 | } |
5409 | } | |
b2a516b8 | 5410 | }else{ |
8846615a DV |
5411 | for(var j=0;j<_178.length;j++){ |
5412 | var y=_178[j][1][0]; | |
5413 | var high=_178[j][1][2]; | |
285a6bda DV |
5414 | if(high>y){ |
5415 | y=high; | |
5416 | } | |
b2a516b8 | 5417 | if(maxY==null||y>maxY){ |
285a6bda DV |
5418 | maxY=y; |
5419 | } | |
b2a516b8 DV |
5420 | } |
5421 | } | |
5422 | } | |
5423 | if(bars){ | |
5424 | var vals=[]; | |
8846615a DV |
5425 | for(var j=0;j<_178.length;j++){ |
5426 | vals[j]=[_178[j][0],_178[j][1][0],_178[j][1][1],_178[j][1][2]]; | |
b2a516b8 | 5427 | } |
285a6bda | 5428 | this.layout_.addDataset(this.attr_("labels")[i],vals); |
b2a516b8 | 5429 | }else{ |
8846615a | 5430 | this.layout_.addDataset(this.attr_("labels")[i],_178); |
b2a516b8 DV |
5431 | } |
5432 | } | |
5433 | if(this.valueRange_!=null){ | |
5434 | this.addYTicks_(this.valueRange_[0],this.valueRange_[1]); | |
5435 | }else{ | |
5436 | maxY*=1.1; | |
5437 | if(maxY<=0){ | |
5438 | maxY=1; | |
b2a516b8 DV |
5439 | } |
5440 | this.addYTicks_(0,maxY); | |
5441 | } | |
5442 | this.addXTicks_(); | |
5443 | this.layout_.evaluateWithError(); | |
5444 | this.plotter_.clear(); | |
5445 | this.plotter_.render(); | |
5446 | this.canvas_.getContext("2d").clearRect(0,0,this.canvas_.width,this.canvas_.height); | |
6a1aa64f | 5447 | }; |
8846615a DV |
5448 | Dygraph.prototype.rollingAverage=function(_184,_185){ |
5449 | if(_184.length<2){ | |
5450 | return _184; | |
b2a516b8 | 5451 | } |
8846615a DV |
5452 | var _185=Math.min(_185,_184.length-1); |
5453 | var _186=[]; | |
5454 | var _187=this.attr_("sigma"); | |
b2a516b8 DV |
5455 | if(this.fractions_){ |
5456 | var num=0; | |
5457 | var den=0; | |
5458 | var mult=100; | |
8846615a DV |
5459 | for(var i=0;i<_184.length;i++){ |
5460 | num+=_184[i][1][0]; | |
5461 | den+=_184[i][1][1]; | |
5462 | if(i-_185>=0){ | |
5463 | num-=_184[i-_185][1][0]; | |
5464 | den-=_184[i-_185][1][1]; | |
5465 | } | |
5466 | var date=_184[i][0]; | |
5467 | var _190=den?num/den:0; | |
285a6bda | 5468 | if(this.attr_("errorBars")){ |
b2a516b8 DV |
5469 | if(this.wilsonInterval_){ |
5470 | if(den){ | |
8846615a DV |
5471 | var p=_190<0?0:_190,n=den; |
5472 | var pm=_187*Math.sqrt(p*(1-p)/n+_187*_187/(4*n*n)); | |
5473 | var _193=1+_187*_187/den; | |
5474 | var low=(p+_187*_187/(2*den)-pm)/_193; | |
5475 | var high=(p+_187*_187/(2*den)+pm)/_193; | |
5476 | _186[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; | |
b2a516b8 | 5477 | }else{ |
8846615a | 5478 | _186[i]=[date,[0,0,0]]; |
b2a516b8 DV |
5479 | } |
5480 | }else{ | |
8846615a DV |
5481 | var _194=den?_187*Math.sqrt(_190*(1-_190)/den):1; |
5482 | _186[i]=[date,[mult*_190,mult*_194,mult*_194]]; | |
b2a516b8 DV |
5483 | } |
5484 | }else{ | |
8846615a | 5485 | _186[i]=[date,mult*_190]; |
b2a516b8 DV |
5486 | } |
5487 | } | |
5488 | }else{ | |
5489 | if(this.customBars_){ | |
6372d433 DV |
5490 | var low=0; |
5491 | var mid=0; | |
5492 | var high=0; | |
8846615a DV |
5493 | var _196=0; |
5494 | for(var i=0;i<_184.length;i++){ | |
5495 | var data=_184[i][1]; | |
b2a516b8 | 5496 | var y=data[1]; |
8846615a | 5497 | _186[i]=[_184[i][0],[y,y-data[0],data[2]-y]]; |
6372d433 DV |
5498 | low+=data[0]; |
5499 | mid+=y; | |
5500 | high+=data[2]; | |
8846615a DV |
5501 | _196+=1; |
5502 | if(i-_185>=0){ | |
5503 | var prev=_184[i-_185]; | |
6372d433 DV |
5504 | low-=prev[1][0]; |
5505 | mid-=prev[1][1]; | |
5506 | high-=prev[1][2]; | |
8846615a | 5507 | _196-=1; |
6372d433 | 5508 | } |
8846615a | 5509 | _186[i]=[_184[i][0],[1*mid/_196,1*(mid-low)/_196,1*(high-mid)/_196]]; |
6372d433 DV |
5510 | } |
5511 | }else{ | |
8846615a | 5512 | var _198=Math.min(_185-1,_184.length-2); |
285a6bda | 5513 | if(!this.attr_("errorBars")){ |
8846615a | 5514 | for(var i=0;i<_198;i++){ |
b2a516b8 DV |
5515 | var sum=0; |
5516 | for(var j=0;j<i+1;j++){ | |
8846615a | 5517 | sum+=_184[j][1]; |
b2a516b8 | 5518 | } |
8846615a | 5519 | _186[i]=[_184[i][0],sum/(i+1)]; |
b2a516b8 | 5520 | } |
8846615a | 5521 | for(var i=Math.min(_185-1,_184.length-2);i<_184.length;i++){ |
b2a516b8 | 5522 | var sum=0; |
8846615a DV |
5523 | for(var j=i-_185+1;j<i+1;j++){ |
5524 | sum+=_184[j][1]; | |
b2a516b8 | 5525 | } |
8846615a | 5526 | _186[i]=[_184[i][0],sum/_185]; |
b2a516b8 DV |
5527 | } |
5528 | }else{ | |
8846615a | 5529 | for(var i=0;i<_198;i++){ |
b2a516b8 | 5530 | var sum=0; |
8846615a | 5531 | var _200=0; |
b2a516b8 | 5532 | for(var j=0;j<i+1;j++){ |
8846615a DV |
5533 | sum+=_184[j][1][0]; |
5534 | _200+=Math.pow(_184[j][1][1],2); | |
b2a516b8 | 5535 | } |
8846615a DV |
5536 | var _194=Math.sqrt(_200)/(i+1); |
5537 | _186[i]=[_184[i][0],[sum/(i+1),_187*_194,_187*_194]]; | |
b2a516b8 | 5538 | } |
8846615a | 5539 | for(var i=Math.min(_185-1,_184.length-2);i<_184.length;i++){ |
b2a516b8 | 5540 | var sum=0; |
8846615a DV |
5541 | var _200=0; |
5542 | for(var j=i-_185+1;j<i+1;j++){ | |
5543 | sum+=_184[j][1][0]; | |
5544 | _200+=Math.pow(_184[j][1][1],2); | |
b2a516b8 | 5545 | } |
8846615a DV |
5546 | var _194=Math.sqrt(_200)/_185; |
5547 | _186[i]=[_184[i][0],[sum/_185,_187*_194,_187*_194]]; | |
b2a516b8 DV |
5548 | } |
5549 | } | |
5550 | } | |
5551 | } | |
8846615a | 5552 | return _186; |
6a1aa64f | 5553 | }; |
8846615a DV |
5554 | Dygraph.dateParser=function(_201,self){ |
5555 | var _202; | |
285a6bda | 5556 | var d; |
8846615a DV |
5557 | if(_201.length==10&&_201.search("-")!=-1){ |
5558 | _202=_201.replace("-","/","g"); | |
5559 | while(_202.search("-")!=-1){ | |
5560 | _202=_202.replace("-","/"); | |
353a0294 | 5561 | } |
8846615a | 5562 | d=Date.parse(_202); |
b2a516b8 | 5563 | }else{ |
8846615a DV |
5564 | if(_201.length==8){ |
5565 | _202=_201.substr(0,4)+"/"+_201.substr(4,2)+"/"+_201.substr(6,2); | |
285a6bda | 5566 | d=Date.parse(_202); |
8846615a DV |
5567 | }else{ |
5568 | d=Date.parse(_201); | |
285a6bda | 5569 | } |
b2a516b8 | 5570 | } |
285a6bda | 5571 | if(!d||isNaN(d)){ |
8846615a | 5572 | self.error("Couldn't parse "+_201+" as a date"); |
b2a516b8 | 5573 | } |
285a6bda | 5574 | return d; |
6a1aa64f | 5575 | }; |
285a6bda | 5576 | Dygraph.prototype.detectTypeFromString_=function(str){ |
8846615a | 5577 | var _204=false; |
285a6bda | 5578 | if(str.indexOf("-")>=0||str.indexOf("/")>=0||isNaN(parseFloat(str))){ |
8846615a | 5579 | _204=true; |
285a6bda DV |
5580 | }else{ |
5581 | if(str.length==8&&str>"19700101"&&str<"20371231"){ | |
8846615a | 5582 | _204=true; |
285a6bda DV |
5583 | } |
5584 | } | |
8846615a | 5585 | if(_204){ |
285a6bda DV |
5586 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
5587 | this.attrs_.xValueParser=Dygraph.dateParser; | |
5588 | this.attrs_.xTicker=Dygraph.dateTicker; | |
5589 | }else{ | |
5590 | this.attrs_.xValueFormatter=function(x){ | |
5591 | return x; | |
5592 | }; | |
5593 | this.attrs_.xValueParser=function(x){ | |
5594 | return parseFloat(x); | |
5595 | }; | |
5596 | this.attrs_.xTicker=Dygraph.numericTicks; | |
5597 | } | |
5598 | }; | |
5599 | Dygraph.prototype.parseCSV_=function(data){ | |
b2a516b8 | 5600 | var ret=[]; |
8846615a DV |
5601 | var _205=data.split("\n"); |
5602 | var _206=0; | |
b2a516b8 | 5603 | if(this.labelsFromCSV_){ |
8846615a DV |
5604 | _206=1; |
5605 | this.attrs_.labels=_205[0].split(","); | |
5606 | } | |
5607 | var _207; | |
5608 | var _208=false; | |
5609 | var _209=this.attr_("labels").length; | |
5610 | for(var i=_206;i<_205.length;i++){ | |
5611 | var line=_205[i]; | |
b2a516b8 DV |
5612 | if(line.length==0){ |
5613 | continue; | |
5614 | } | |
8846615a DV |
5615 | var _211=line.split(","); |
5616 | if(_211.length<2){ | |
b2a516b8 DV |
5617 | continue; |
5618 | } | |
8846615a DV |
5619 | var _212=[]; |
5620 | if(!_208){ | |
5621 | this.detectTypeFromString_(_211[0]); | |
5622 | _207=this.attr_("xValueParser"); | |
5623 | _208=true; | |
285a6bda | 5624 | } |
8846615a | 5625 | _212[0]=_207(_211[0],this); |
b2a516b8 | 5626 | if(this.fractions_){ |
8846615a DV |
5627 | for(var j=1;j<_211.length;j++){ |
5628 | var vals=_211[j].split("/"); | |
5629 | _212[j]=[parseFloat(vals[0]),parseFloat(vals[1])]; | |
b2a516b8 DV |
5630 | } |
5631 | }else{ | |
285a6bda | 5632 | if(this.attr_("errorBars")){ |
8846615a DV |
5633 | for(var j=1;j<_211.length;j+=2){ |
5634 | _212[(j+1)/2]=[parseFloat(_211[j]),parseFloat(_211[j+1])]; | |
b2a516b8 DV |
5635 | } |
5636 | }else{ | |
5637 | if(this.customBars_){ | |
8846615a DV |
5638 | for(var j=1;j<_211.length;j++){ |
5639 | var vals=_211[j].split(";"); | |
5640 | _212[j]=[parseFloat(vals[0]),parseFloat(vals[1]),parseFloat(vals[2])]; | |
b2a516b8 DV |
5641 | } |
5642 | }else{ | |
8846615a DV |
5643 | for(var j=1;j<_211.length;j++){ |
5644 | _212[j]=parseFloat(_211[j]); | |
285a6bda | 5645 | } |
b2a516b8 DV |
5646 | } |
5647 | } | |
5648 | } | |
8846615a DV |
5649 | ret.push(_212); |
5650 | if(_212.length!=_209){ | |
5651 | this.error("Number of columns in line "+i+" ("+_212.length+") does not agree with number of labels ("+_209+") "+line); | |
b2a516b8 | 5652 | } |
b2a516b8 DV |
5653 | } |
5654 | return ret; | |
6a1aa64f | 5655 | }; |
285a6bda DV |
5656 | Dygraph.prototype.parseArray_=function(data){ |
5657 | if(data.length==0){ | |
5658 | this.error("Can't plot empty data set"); | |
5659 | return null; | |
5660 | } | |
5661 | if(data[0].length==0){ | |
5662 | this.error("Data set cannot contain an empty row"); | |
5663 | return null; | |
5664 | } | |
5665 | if(this.attr_("labels")==null){ | |
5666 | this.warn("Using default labels. Set labels explicitly via 'labels' "+"in the options parameter"); | |
5667 | this.attrs_.labels=["X"]; | |
5668 | for(var i=1;i<data[0].length;i++){ | |
5669 | this.attrs_.labels.push("Y"+i); | |
5670 | } | |
5671 | } | |
5672 | if(MochiKit.Base.isDateLike(data[0][0])){ | |
5673 | this.attrs_.xValueFormatter=Dygraph.dateString_; | |
5674 | this.attrs_.xTicker=Dygraph.dateTicker; | |
8846615a | 5675 | var _213=MochiKit.Base.clone(data); |
285a6bda | 5676 | for(var i=0;i<data.length;i++){ |
8846615a | 5677 | if(_213[i].length==0){ |
285a6bda DV |
5678 | this.error("Row "<<(1+i)<<" of data is empty"); |
5679 | return null; | |
5680 | } | |
8846615a | 5681 | if(_213[i][0]==null||typeof (_213[i][0].getTime)!="function"){ |
285a6bda DV |
5682 | this.error("x value in row "<<(1+i)<<" is not a Date"); |
5683 | return null; | |
5684 | } | |
8846615a | 5685 | _213[i][0]=_213[i][0].getTime(); |
285a6bda | 5686 | } |
8846615a | 5687 | return _213; |
285a6bda DV |
5688 | }else{ |
5689 | this.attrs_.xValueFormatter=function(x){ | |
5690 | return x; | |
5691 | }; | |
5692 | this.attrs_.xTicker=Dygraph.numericTicks; | |
5693 | return data; | |
5694 | } | |
5695 | }; | |
5696 | Dygraph.prototype.parseDataTable_=function(data){ | |
6219c9d6 DV |
5697 | var cols=data.getNumberOfColumns(); |
5698 | var rows=data.getNumberOfRows(); | |
8846615a | 5699 | var _216=[]; |
6219c9d6 | 5700 | for(var i=0;i<cols;i++){ |
8846615a | 5701 | _216.push(data.getColumnLabel(i)); |
6219c9d6 | 5702 | } |
8846615a DV |
5703 | this.attrs_.labels=_216; |
5704 | var _217=data.getColumnType(0); | |
5705 | if(_217=="date"){ | |
285a6bda DV |
5706 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
5707 | this.attrs_.xValueParser=Dygraph.dateParser; | |
5708 | this.attrs_.xTicker=Dygraph.dateTicker; | |
5709 | }else{ | |
33127159 | 5710 | if(_217=="number"){ |
285a6bda DV |
5711 | this.attrs_.xValueFormatter=function(x){ |
5712 | return x; | |
5713 | }; | |
5714 | this.attrs_.xValueParser=function(x){ | |
5715 | return parseFloat(x); | |
5716 | }; | |
5717 | this.attrs_.xTicker=Dygraph.numericTicks; | |
5718 | }else{ | |
33127159 | 5719 | this.error("only 'date' and 'number' types are supported for column 1 "+"of DataTable input (Got '"+_217+"')"); |
6219c9d6 DV |
5720 | return null; |
5721 | } | |
285a6bda | 5722 | } |
6219c9d6 DV |
5723 | var ret=[]; |
5724 | for(var i=0;i<rows;i++){ | |
5725 | var row=[]; | |
b3b20e24 DV |
5726 | if(!data.getValue(i,0)){ |
5727 | continue; | |
5728 | } | |
8846615a | 5729 | if(_217=="date"){ |
6219c9d6 | 5730 | row.push(data.getValue(i,0).getTime()); |
36615faf DV |
5731 | }else{ |
5732 | row.push(data.getValue(i,0)); | |
5733 | } | |
b3b20e24 | 5734 | var _219=false; |
6219c9d6 DV |
5735 | for(var j=1;j<cols;j++){ |
5736 | row.push(data.getValue(i,j)); | |
b3b20e24 DV |
5737 | if(data.getValue(i,j)){ |
5738 | _219=true; | |
6219c9d6 | 5739 | } |
b3b20e24 DV |
5740 | } |
5741 | if(_219){ | |
6219c9d6 DV |
5742 | ret.push(row); |
5743 | } | |
b3b20e24 | 5744 | } |
6219c9d6 DV |
5745 | return ret; |
5746 | }; | |
285a6bda | 5747 | Dygraph.prototype.start_=function(){ |
b2a516b8 DV |
5748 | if(typeof this.file_=="function"){ |
5749 | this.loadedEvent_(this.file_()); | |
5750 | }else{ | |
285a6bda DV |
5751 | if(MochiKit.Base.isArrayLike(this.file_)){ |
5752 | this.rawData_=this.parseArray_(this.file_); | |
5753 | this.drawGraph_(this.rawData_); | |
5754 | }else{ | |
6219c9d6 DV |
5755 | if(typeof this.file_=="object"&&typeof this.file_.getColumnRange=="function"){ |
5756 | this.rawData_=this.parseDataTable_(this.file_); | |
5757 | this.drawGraph_(this.rawData_); | |
5758 | }else{ | |
285a6bda DV |
5759 | if(typeof this.file_=="string"){ |
5760 | if(this.file_.indexOf("\n")>=0){ | |
5761 | this.loadedEvent_(this.file_); | |
5762 | }else{ | |
b2a516b8 | 5763 | var req=new XMLHttpRequest(); |
b3b20e24 | 5764 | var _221=this; |
b2a516b8 DV |
5765 | req.onreadystatechange=function(){ |
5766 | if(req.readyState==4){ | |
5767 | if(req.status==200){ | |
b3b20e24 | 5768 | _221.loadedEvent_(req.responseText); |
b2a516b8 DV |
5769 | } |
5770 | } | |
6a1aa64f | 5771 | }; |
b2a516b8 DV |
5772 | req.open("GET",this.file_,true); |
5773 | req.send(null); | |
5774 | } | |
285a6bda DV |
5775 | }else{ |
5776 | this.error("Unknown data format: "+(typeof this.file_)); | |
6219c9d6 | 5777 | } |
b2a516b8 | 5778 | } |
b2a516b8 | 5779 | } |
b2a516b8 | 5780 | } |
285a6bda | 5781 | }; |
b3b20e24 DV |
5782 | Dygraph.prototype.updateOptions=function(_222){ |
5783 | if(_222.customBars){ | |
5784 | this.customBars_=_222.customBars; | |
b2a516b8 | 5785 | } |
b3b20e24 DV |
5786 | if(_222.rollPeriod){ |
5787 | this.rollPeriod_=_222.rollPeriod; | |
b2a516b8 | 5788 | } |
b3b20e24 DV |
5789 | if(_222.dateWindow){ |
5790 | this.dateWindow_=_222.dateWindow; | |
b2a516b8 | 5791 | } |
b3b20e24 DV |
5792 | if(_222.valueRange){ |
5793 | this.valueRange_=_222.valueRange; | |
b2a516b8 | 5794 | } |
b3b20e24 | 5795 | MochiKit.Base.update(this.user_attrs_,_222); |
285a6bda DV |
5796 | this.labelsFromCSV_=(this.attr_("labels")==null); |
5797 | this.layout_.updateOptions({"errorBars":this.attr_("errorBars")}); | |
b3b20e24 DV |
5798 | if(_222["file"]&&_222["file"]!=this.file_){ |
5799 | this.file_=_222["file"]; | |
b2a516b8 DV |
5800 | this.start_(); |
5801 | }else{ | |
5802 | this.drawGraph_(this.rawData_); | |
5803 | } | |
6a1aa64f | 5804 | }; |
b3b20e24 DV |
5805 | Dygraph.prototype.adjustRoll=function(_223){ |
5806 | this.rollPeriod_=_223; | |
b2a516b8 | 5807 | this.drawGraph_(this.rawData_); |
6a1aa64f | 5808 | }; |
b3b20e24 DV |
5809 | Dygraph.GVizChart=function(_224){ |
5810 | this.container=_224; | |
6219c9d6 | 5811 | }; |
b3b20e24 | 5812 | Dygraph.GVizChart.prototype.draw=function(data,_225){ |
6219c9d6 | 5813 | this.container.innerHTML=""; |
b3b20e24 | 5814 | this.date_graph=new Dygraph(this.container,data,_225); |
6219c9d6 | 5815 | }; |
285a6bda | 5816 | DateGraph=Dygraph; |
b2a516b8 | 5817 |