Commit | Line | Data |
---|---|---|
078d1d29 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"){ | |
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 | }}); | |
1596 | MochiKit.Iter.EXPORT_OK=["iteratorRegistry","arrayLikeIter","hasIterateNext","iterateNextIter",]; | |
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"){ | |
1617 | dojo.provide("MochiKit.Logging"); | |
1618 | dojo.require("MochiKit.Base"); | |
1619 | } | |
1620 | if(typeof (JSAN)!="undefined"){ | |
1621 | JSAN.use("MochiKit.Base",[]); | |
1622 | } | |
1623 | try{ | |
1624 | if(typeof (MochiKit.Base)=="undefined"){ | |
1625 | throw ""; | |
1626 | } | |
1627 | } | |
1628 | catch(e){ | |
1629 | throw "MochiKit.Logging depends on MochiKit.Base!"; | |
1630 | } | |
1631 | if(typeof (MochiKit.Logging)=="undefined"){ | |
1632 | MochiKit.Logging={}; | |
1633 | } | |
1634 | MochiKit.Logging.NAME="MochiKit.Logging"; | |
1635 | MochiKit.Logging.VERSION="1.4"; | |
1636 | MochiKit.Logging.__repr__=function(){ | |
1637 | return "["+this.NAME+" "+this.VERSION+"]"; | |
1638 | }; | |
1639 | MochiKit.Logging.toString=function(){ | |
1640 | return this.__repr__(); | |
1641 | }; | |
1642 | MochiKit.Logging.EXPORT=["LogLevel","LogMessage","Logger","alertListener","logger","log","logError","logDebug","logFatal","logWarning"]; | |
1643 | MochiKit.Logging.EXPORT_OK=["logLevelAtLeast","isLogMessage","compareLogMessage"]; | |
1644 | MochiKit.Logging.LogMessage=function(num,_1e6,info){ | |
1645 | this.num=num; | |
1646 | this.level=_1e6; | |
1647 | this.info=info; | |
1648 | this.timestamp=new Date(); | |
1649 | }; | |
1650 | MochiKit.Logging.LogMessage.prototype={repr:function(){ | |
1651 | var m=MochiKit.Base; | |
1652 | return "LogMessage("+m.map(m.repr,[this.num,this.level,this.info]).join(", ")+")"; | |
1653 | },toString:MochiKit.Base.forwardCall("repr")}; | |
1654 | MochiKit.Base.update(MochiKit.Logging,{logLevelAtLeast:function(_1e9){ | |
1655 | var self=MochiKit.Logging; | |
1656 | if(typeof (_1e9)=="string"){ | |
1657 | _1e9=self.LogLevel[_1e9]; | |
1658 | } | |
1659 | return function(msg){ | |
1660 | var _1ec=msg.level; | |
1661 | if(typeof (_1ec)=="string"){ | |
1662 | _1ec=self.LogLevel[_1ec]; | |
1663 | } | |
1664 | return _1ec>=_1e9; | |
1665 | }; | |
1666 | },isLogMessage:function(){ | |
1667 | var _1ed=MochiKit.Logging.LogMessage; | |
1668 | for(var i=0;i<arguments.length;i++){ | |
1669 | if(!(arguments[i] instanceof _1ed)){ | |
1670 | return false; | |
1671 | } | |
1672 | } | |
1673 | return true; | |
1674 | },compareLogMessage:function(a,b){ | |
1675 | return MochiKit.Base.compare([a.level,a.info],[b.level,b.info]); | |
1676 | },alertListener:function(msg){ | |
1677 | alert("num: "+msg.num+"\nlevel: "+msg.level+"\ninfo: "+msg.info.join(" ")); | |
1678 | }}); | |
1679 | MochiKit.Logging.Logger=function(_1f2){ | |
1680 | this.counter=0; | |
1681 | if(typeof (_1f2)=="undefined"||_1f2===null){ | |
1682 | _1f2=-1; | |
1683 | } | |
1684 | this.maxSize=_1f2; | |
1685 | this._messages=[]; | |
1686 | this.listeners={}; | |
1687 | this.useNativeConsole=false; | |
1688 | }; | |
1689 | MochiKit.Logging.Logger.prototype={clear:function(){ | |
1690 | this._messages.splice(0,this._messages.length); | |
1691 | },logToConsole:function(msg){ | |
1692 | if(typeof (window)!="undefined"&&window.console&&window.console.log){ | |
1693 | window.console.log(msg.replace(/%/g,"\uff05")); | |
1694 | }else{ | |
1695 | if(typeof (opera)!="undefined"&&opera.postError){ | |
1696 | opera.postError(msg); | |
1697 | }else{ | |
1698 | if(typeof (printfire)=="function"){ | |
1699 | printfire(msg); | |
1700 | }else{ | |
1701 | if(typeof (Debug)!="undefined"&&Debug.writeln){ | |
1702 | Debug.writeln(msg); | |
1703 | }else{ | |
1704 | if(typeof (debug)!="undefined"&&debug.trace){ | |
1705 | debug.trace(msg); | |
1706 | } | |
1707 | } | |
1708 | } | |
1709 | } | |
1710 | } | |
1711 | },dispatchListeners:function(msg){ | |
1712 | for(var k in this.listeners){ | |
1713 | var pair=this.listeners[k]; | |
1714 | if(pair.ident!=k||(pair[0]&&!pair[0](msg))){ | |
1715 | continue; | |
1716 | } | |
1717 | pair[1](msg); | |
1718 | } | |
1719 | },addListener:function(_1f7,_1f8,_1f9){ | |
1720 | if(typeof (_1f8)=="string"){ | |
1721 | _1f8=MochiKit.Logging.logLevelAtLeast(_1f8); | |
1722 | } | |
1723 | var _1fa=[_1f8,_1f9]; | |
1724 | _1fa.ident=_1f7; | |
1725 | this.listeners[_1f7]=_1fa; | |
1726 | },removeListener:function(_1fb){ | |
1727 | delete this.listeners[_1fb]; | |
1728 | },baseLog:function(_1fc,_1fd){ | |
1729 | var msg=new MochiKit.Logging.LogMessage(this.counter,_1fc,MochiKit.Base.extend(null,arguments,1)); | |
1730 | this._messages.push(msg); | |
1731 | this.dispatchListeners(msg); | |
1732 | if(this.useNativeConsole){ | |
1733 | this.logToConsole(msg.level+": "+msg.info.join(" ")); | |
1734 | } | |
1735 | this.counter+=1; | |
1736 | while(this.maxSize>=0&&this._messages.length>this.maxSize){ | |
1737 | this._messages.shift(); | |
1738 | } | |
1739 | },getMessages:function(_1ff){ | |
1740 | var _200=0; | |
1741 | if(!(typeof (_1ff)=="undefined"||_1ff===null)){ | |
1742 | _200=Math.max(0,this._messages.length-_1ff); | |
1743 | } | |
1744 | return this._messages.slice(_200); | |
1745 | },getMessageText:function(_201){ | |
1746 | if(typeof (_201)=="undefined"||_201===null){ | |
1747 | _201=30; | |
1748 | } | |
1749 | var _202=this.getMessages(_201); | |
1750 | if(_202.length){ | |
1751 | var lst=map(function(m){ | |
1752 | return "\n ["+m.num+"] "+m.level+": "+m.info.join(" "); | |
1753 | },_202); | |
1754 | lst.unshift("LAST "+_202.length+" MESSAGES:"); | |
1755 | return lst.join(""); | |
1756 | } | |
1757 | return ""; | |
1758 | },debuggingBookmarklet:function(_205){ | |
1759 | if(typeof (MochiKit.LoggingPane)=="undefined"){ | |
1760 | alert(this.getMessageText()); | |
1761 | }else{ | |
1762 | MochiKit.LoggingPane.createLoggingPane(_205||false); | |
1763 | } | |
1764 | }}; | |
1765 | MochiKit.Logging.__new__=function(){ | |
1766 | this.LogLevel={ERROR:40,FATAL:50,WARNING:30,INFO:20,DEBUG:10}; | |
1767 | var m=MochiKit.Base; | |
1768 | m.registerComparator("LogMessage",this.isLogMessage,this.compareLogMessage); | |
1769 | var _207=m.partial; | |
1770 | var _208=this.Logger; | |
1771 | var _209=_208.prototype.baseLog; | |
1772 | m.update(this.Logger.prototype,{debug:_207(_209,"DEBUG"),log:_207(_209,"INFO"),error:_207(_209,"ERROR"),fatal:_207(_209,"FATAL"),warning:_207(_209,"WARNING")}); | |
1773 | var self=this; | |
1774 | var _20b=function(name){ | |
1775 | return function(){ | |
1776 | self.logger[name].apply(self.logger,arguments); | |
1777 | }; | |
1778 | }; | |
1779 | this.log=_20b("log"); | |
1780 | this.logError=_20b("error"); | |
1781 | this.logDebug=_20b("debug"); | |
1782 | this.logFatal=_20b("fatal"); | |
1783 | this.logWarning=_20b("warning"); | |
1784 | this.logger=new _208(); | |
1785 | this.logger.useNativeConsole=true; | |
1786 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
1787 | m.nameFunctions(this); | |
1788 | }; | |
1789 | if(typeof (printfire)=="undefined"&&typeof (document)!="undefined"&&document.createEvent&&typeof (dispatchEvent)!="undefined"){ | |
1790 | printfire=function(){ | |
1791 | printfire.args=arguments; | |
1792 | var ev=document.createEvent("Events"); | |
1793 | ev.initEvent("printfire",false,true); | |
1794 | dispatchEvent(ev); | |
1795 | }; | |
1796 | } | |
1797 | MochiKit.Logging.__new__(); | |
1798 | MochiKit.Base._exportSymbols(this,MochiKit.Logging); | |
1799 | if(typeof (dojo)!="undefined"){ | |
1800 | dojo.provide("MochiKit.DateTime"); | |
1801 | } | |
1802 | if(typeof (MochiKit)=="undefined"){ | |
1803 | MochiKit={}; | |
1804 | } | |
1805 | if(typeof (MochiKit.DateTime)=="undefined"){ | |
1806 | MochiKit.DateTime={}; | |
1807 | } | |
1808 | MochiKit.DateTime.NAME="MochiKit.DateTime"; | |
1809 | MochiKit.DateTime.VERSION="1.4"; | |
1810 | MochiKit.DateTime.__repr__=function(){ | |
1811 | return "["+this.NAME+" "+this.VERSION+"]"; | |
1812 | }; | |
1813 | MochiKit.DateTime.toString=function(){ | |
1814 | return this.__repr__(); | |
1815 | }; | |
1816 | MochiKit.DateTime.isoDate=function(str){ | |
1817 | str=str+""; | |
1818 | if(typeof (str)!="string"||str.length===0){ | |
1819 | return null; | |
1820 | } | |
1821 | var iso=str.split("-"); | |
1822 | if(iso.length===0){ | |
1823 | return null; | |
1824 | } | |
1825 | return new Date(iso[0],iso[1]-1,iso[2]); | |
1826 | }; | |
1827 | MochiKit.DateTime._isoRegexp=/(\d{4,})(?:-(\d{1,2})(?:-(\d{1,2})(?:[T ](\d{1,2}):(\d{1,2})(?::(\d{1,2})(?:\.(\d+))?)?(?:(Z)|([+-])(\d{1,2})(?::(\d{1,2}))?)?)?)?)?/; | |
1828 | MochiKit.DateTime.isoTimestamp=function(str){ | |
1829 | str=str+""; | |
1830 | if(typeof (str)!="string"||str.length===0){ | |
1831 | return null; | |
1832 | } | |
1833 | var res=str.match(MochiKit.DateTime._isoRegexp); | |
1834 | if(typeof (res)=="undefined"||res===null){ | |
1835 | return null; | |
1836 | } | |
1837 | var year,_213,day,hour,min,sec,msec; | |
1838 | year=parseInt(res[1],10); | |
1839 | if(typeof (res[2])=="undefined"||res[2]===""){ | |
1840 | return new Date(year); | |
1841 | } | |
1842 | _213=parseInt(res[2],10)-1; | |
1843 | day=parseInt(res[3],10); | |
1844 | if(typeof (res[4])=="undefined"||res[4]===""){ | |
1845 | return new Date(year,_213,day); | |
1846 | } | |
1847 | hour=parseInt(res[4],10); | |
1848 | min=parseInt(res[5],10); | |
1849 | sec=(typeof (res[6])!="undefined"&&res[6]!=="")?parseInt(res[6],10):0; | |
1850 | if(typeof (res[7])!="undefined"&&res[7]!==""){ | |
1851 | msec=Math.round(1000*parseFloat("0."+res[7])); | |
1852 | }else{ | |
1853 | msec=0; | |
1854 | } | |
1855 | if((typeof (res[8])=="undefined"||res[8]==="")&&(typeof (res[9])=="undefined"||res[9]==="")){ | |
1856 | return new Date(year,_213,day,hour,min,sec,msec); | |
1857 | } | |
1858 | var ofs; | |
1859 | if(typeof (res[9])!="undefined"&&res[9]!==""){ | |
1860 | ofs=parseInt(res[10],10)*3600000; | |
1861 | if(typeof (res[11])!="undefined"&&res[11]!==""){ | |
1862 | ofs+=parseInt(res[11],10)*60000; | |
1863 | } | |
1864 | if(res[9]=="-"){ | |
1865 | ofs=-ofs; | |
1866 | } | |
1867 | }else{ | |
1868 | ofs=0; | |
1869 | } | |
1870 | return new Date(Date.UTC(year,_213,day,hour,min,sec,msec)-ofs); | |
1871 | }; | |
1872 | MochiKit.DateTime.toISOTime=function(date,_21b){ | |
1873 | if(typeof (date)=="undefined"||date===null){ | |
1874 | return null; | |
1875 | } | |
1876 | var hh=date.getHours(); | |
1877 | var mm=date.getMinutes(); | |
1878 | var ss=date.getSeconds(); | |
1879 | var lst=[((_21b&&(hh<10))?"0"+hh:hh),((mm<10)?"0"+mm:mm),((ss<10)?"0"+ss:ss)]; | |
1880 | return lst.join(":"); | |
1881 | }; | |
1882 | MochiKit.DateTime.toISOTimestamp=function(date,_221){ | |
1883 | if(typeof (date)=="undefined"||date===null){ | |
1884 | return null; | |
1885 | } | |
1886 | var sep=_221?"T":" "; | |
1887 | var foot=_221?"Z":""; | |
1888 | if(_221){ | |
1889 | date=new Date(date.getTime()+(date.getTimezoneOffset()*60000)); | |
1890 | } | |
1891 | return MochiKit.DateTime.toISODate(date)+sep+MochiKit.DateTime.toISOTime(date,_221)+foot; | |
1892 | }; | |
1893 | MochiKit.DateTime.toISODate=function(date){ | |
1894 | if(typeof (date)=="undefined"||date===null){ | |
1895 | return null; | |
1896 | } | |
1897 | var _225=MochiKit.DateTime._padTwo; | |
1898 | return [date.getFullYear(),_225(date.getMonth()+1),_225(date.getDate())].join("-"); | |
1899 | }; | |
1900 | MochiKit.DateTime.americanDate=function(d){ | |
1901 | d=d+""; | |
1902 | if(typeof (d)!="string"||d.length===0){ | |
1903 | return null; | |
1904 | } | |
1905 | var a=d.split("/"); | |
1906 | return new Date(a[2],a[0]-1,a[1]); | |
1907 | }; | |
1908 | MochiKit.DateTime._padTwo=function(n){ | |
1909 | return (n>9)?n:"0"+n; | |
1910 | }; | |
1911 | MochiKit.DateTime.toPaddedAmericanDate=function(d){ | |
1912 | if(typeof (d)=="undefined"||d===null){ | |
1913 | return null; | |
1914 | } | |
1915 | var _22a=MochiKit.DateTime._padTwo; | |
1916 | return [_22a(d.getMonth()+1),_22a(d.getDate()),d.getFullYear()].join("/"); | |
1917 | }; | |
1918 | MochiKit.DateTime.toAmericanDate=function(d){ | |
1919 | if(typeof (d)=="undefined"||d===null){ | |
1920 | return null; | |
1921 | } | |
1922 | return [d.getMonth()+1,d.getDate(),d.getFullYear()].join("/"); | |
1923 | }; | |
1924 | MochiKit.DateTime.EXPORT=["isoDate","isoTimestamp","toISOTime","toISOTimestamp","toISODate","americanDate","toPaddedAmericanDate","toAmericanDate"]; | |
1925 | MochiKit.DateTime.EXPORT_OK=[]; | |
1926 | MochiKit.DateTime.EXPORT_TAGS={":common":MochiKit.DateTime.EXPORT,":all":MochiKit.DateTime.EXPORT}; | |
1927 | MochiKit.DateTime.__new__=function(){ | |
1928 | var base=this.NAME+"."; | |
1929 | for(var k in this){ | |
1930 | var o=this[k]; | |
1931 | if(typeof (o)=="function"&&typeof (o.NAME)=="undefined"){ | |
1932 | try{ | |
1933 | o.NAME=base+k; | |
1934 | } | |
1935 | catch(e){ | |
1936 | } | |
1937 | } | |
1938 | } | |
1939 | }; | |
1940 | MochiKit.DateTime.__new__(); | |
1941 | if(typeof (MochiKit.Base)!="undefined"){ | |
1942 | MochiKit.Base._exportSymbols(this,MochiKit.DateTime); | |
1943 | }else{ | |
1944 | (function(_22f,_230){ | |
1945 | if((typeof (JSAN)=="undefined"&&typeof (dojo)=="undefined")||(MochiKit.__export__===false)){ | |
1946 | var all=_230.EXPORT_TAGS[":all"]; | |
1947 | for(var i=0;i<all.length;i++){ | |
1948 | _22f[all[i]]=_230[all[i]]; | |
1949 | } | |
1950 | } | |
1951 | })(this,MochiKit.DateTime); | |
1952 | } | |
1953 | if(typeof (dojo)!="undefined"){ | |
1954 | dojo.provide("MochiKit.Format"); | |
1955 | } | |
1956 | if(typeof (MochiKit)=="undefined"){ | |
1957 | MochiKit={}; | |
1958 | } | |
1959 | if(typeof (MochiKit.Format)=="undefined"){ | |
1960 | MochiKit.Format={}; | |
1961 | } | |
1962 | MochiKit.Format.NAME="MochiKit.Format"; | |
1963 | MochiKit.Format.VERSION="1.4"; | |
1964 | MochiKit.Format.__repr__=function(){ | |
1965 | return "["+this.NAME+" "+this.VERSION+"]"; | |
1966 | }; | |
1967 | MochiKit.Format.toString=function(){ | |
1968 | return this.__repr__(); | |
1969 | }; | |
1970 | MochiKit.Format._numberFormatter=function(_233,_234,_235,_236,_237,_238,_239,_23a,_23b){ | |
1971 | return function(num){ | |
1972 | num=parseFloat(num); | |
1973 | if(typeof (num)=="undefined"||num===null||isNaN(num)){ | |
1974 | return _233; | |
1975 | } | |
1976 | var _23d=_234; | |
1977 | var _23e=_235; | |
1978 | if(num<0){ | |
1979 | num=-num; | |
1980 | }else{ | |
1981 | _23d=_23d.replace(/-/,""); | |
1982 | } | |
1983 | var me=arguments.callee; | |
1984 | var fmt=MochiKit.Format.formatLocale(_236); | |
1985 | if(_237){ | |
1986 | num=num*100; | |
1987 | _23e=fmt.percent+_23e; | |
1988 | } | |
1989 | num=MochiKit.Format.roundToFixed(num,_238); | |
1990 | var _241=num.split(/\./); | |
1991 | var _242=_241[0]; | |
1992 | var frac=(_241.length==1)?"":_241[1]; | |
1993 | var res=""; | |
1994 | while(_242.length<_239){ | |
1995 | _242="0"+_242; | |
1996 | } | |
1997 | if(_23a){ | |
1998 | while(_242.length>_23a){ | |
1999 | var i=_242.length-_23a; | |
2000 | res=fmt.separator+_242.substring(i,_242.length)+res; | |
2001 | _242=_242.substring(0,i); | |
2002 | } | |
2003 | } | |
2004 | res=_242+res; | |
2005 | if(_238>0){ | |
2006 | while(frac.length<_23b){ | |
2007 | frac=frac+"0"; | |
2008 | } | |
2009 | res=res+fmt.decimal+frac; | |
2010 | } | |
2011 | return _23d+res+_23e; | |
2012 | }; | |
2013 | }; | |
2014 | MochiKit.Format.numberFormatter=function(_246,_247,_248){ | |
2015 | if(typeof (_247)=="undefined"){ | |
2016 | _247=""; | |
2017 | } | |
2018 | var _249=_246.match(/((?:[0#]+,)?[0#]+)(?:\.([0#]+))?(%)?/); | |
2019 | if(!_249){ | |
2020 | throw TypeError("Invalid pattern"); | |
2021 | } | |
2022 | var _24a=_246.substr(0,_249.index); | |
2023 | var _24b=_246.substr(_249.index+_249[0].length); | |
2024 | if(_24a.search(/-/)==-1){ | |
2025 | _24a=_24a+"-"; | |
2026 | } | |
2027 | var _24c=_249[1]; | |
2028 | var frac=(typeof (_249[2])=="string"&&_249[2]!="")?_249[2]:""; | |
2029 | var _24e=(typeof (_249[3])=="string"&&_249[3]!=""); | |
2030 | var tmp=_24c.split(/,/); | |
2031 | var _250; | |
2032 | if(typeof (_248)=="undefined"){ | |
2033 | _248="default"; | |
2034 | } | |
2035 | if(tmp.length==1){ | |
2036 | _250=null; | |
2037 | }else{ | |
2038 | _250=tmp[1].length; | |
2039 | } | |
2040 | var _251=_24c.length-_24c.replace(/0/g,"").length; | |
2041 | var _252=frac.length-frac.replace(/0/g,"").length; | |
2042 | var _253=frac.length; | |
2043 | var rval=MochiKit.Format._numberFormatter(_247,_24a,_24b,_248,_24e,_253,_251,_250,_252); | |
2044 | var m=MochiKit.Base; | |
2045 | if(m){ | |
2046 | var fn=arguments.callee; | |
2047 | var args=m.concat(arguments); | |
2048 | rval.repr=function(){ | |
2049 | return [self.NAME,"(",map(m.repr,args).join(", "),")"].join(""); | |
2050 | }; | |
2051 | } | |
2052 | return rval; | |
2053 | }; | |
2054 | MochiKit.Format.formatLocale=function(_258){ | |
2055 | if(typeof (_258)=="undefined"||_258===null){ | |
2056 | _258="default"; | |
2057 | } | |
2058 | if(typeof (_258)=="string"){ | |
2059 | var rval=MochiKit.Format.LOCALE[_258]; | |
2060 | if(typeof (rval)=="string"){ | |
2061 | rval=arguments.callee(rval); | |
2062 | MochiKit.Format.LOCALE[_258]=rval; | |
2063 | } | |
2064 | return rval; | |
2065 | }else{ | |
2066 | return _258; | |
2067 | } | |
2068 | }; | |
2069 | MochiKit.Format.twoDigitAverage=function(_25a,_25b){ | |
2070 | if(_25b){ | |
2071 | var res=_25a/_25b; | |
2072 | if(!isNaN(res)){ | |
2073 | return MochiKit.Format.twoDigitFloat(_25a/_25b); | |
2074 | } | |
2075 | } | |
2076 | return "0"; | |
2077 | }; | |
2078 | MochiKit.Format.twoDigitFloat=function(_25d){ | |
2079 | var sign=(_25d<0?"-":""); | |
2080 | var s=Math.floor(Math.abs(_25d)*100).toString(); | |
2081 | if(s=="0"){ | |
2082 | return s; | |
2083 | } | |
2084 | if(s.length<3){ | |
2085 | while(s.charAt(s.length-1)=="0"){ | |
2086 | s=s.substring(0,s.length-1); | |
2087 | } | |
2088 | return sign+"0."+s; | |
2089 | } | |
2090 | var head=sign+s.substring(0,s.length-2); | |
2091 | var tail=s.substring(s.length-2,s.length); | |
2092 | if(tail=="00"){ | |
2093 | return head; | |
2094 | }else{ | |
2095 | if(tail.charAt(1)=="0"){ | |
2096 | return head+"."+tail.charAt(0); | |
2097 | }else{ | |
2098 | return head+"."+tail; | |
2099 | } | |
2100 | } | |
2101 | }; | |
2102 | MochiKit.Format.lstrip=function(str,_263){ | |
2103 | str=str+""; | |
2104 | if(typeof (str)!="string"){ | |
2105 | return null; | |
2106 | } | |
2107 | if(!_263){ | |
2108 | return str.replace(/^\s+/,""); | |
2109 | }else{ | |
2110 | return str.replace(new RegExp("^["+_263+"]+"),""); | |
2111 | } | |
2112 | }; | |
2113 | MochiKit.Format.rstrip=function(str,_265){ | |
2114 | str=str+""; | |
2115 | if(typeof (str)!="string"){ | |
2116 | return null; | |
2117 | } | |
2118 | if(!_265){ | |
2119 | return str.replace(/\s+$/,""); | |
2120 | }else{ | |
2121 | return str.replace(new RegExp("["+_265+"]+$"),""); | |
2122 | } | |
2123 | }; | |
2124 | MochiKit.Format.strip=function(str,_267){ | |
2125 | var self=MochiKit.Format; | |
2126 | return self.rstrip(self.lstrip(str,_267),_267); | |
2127 | }; | |
2128 | MochiKit.Format.truncToFixed=function(_269,_26a){ | |
2129 | _269=Math.floor(_269*Math.pow(10,_26a)); | |
2130 | var res=(_269*Math.pow(10,-_26a)).toFixed(_26a); | |
2131 | if(res.charAt(0)=="."){ | |
2132 | res="0"+res; | |
2133 | } | |
2134 | return res; | |
2135 | }; | |
2136 | MochiKit.Format.roundToFixed=function(_26c,_26d){ | |
2137 | return MochiKit.Format.truncToFixed(_26c+0.5*Math.pow(10,-_26d),_26d); | |
2138 | }; | |
2139 | MochiKit.Format.percentFormat=function(_26e){ | |
2140 | return MochiKit.Format.twoDigitFloat(100*_26e)+"%"; | |
2141 | }; | |
2142 | MochiKit.Format.EXPORT=["truncToFixed","roundToFixed","numberFormatter","formatLocale","twoDigitAverage","twoDigitFloat","percentFormat","lstrip","rstrip","strip"]; | |
2143 | MochiKit.Format.LOCALE={en_US:{separator:",",decimal:".",percent:"%"},de_DE:{separator:".",decimal:",",percent:"%"},fr_FR:{separator:" ",decimal:",",percent:"%"},"default":"en_US"}; | |
2144 | MochiKit.Format.EXPORT_OK=[]; | |
2145 | MochiKit.Format.EXPORT_TAGS={":all":MochiKit.Format.EXPORT,":common":MochiKit.Format.EXPORT}; | |
2146 | MochiKit.Format.__new__=function(){ | |
2147 | var base=this.NAME+"."; | |
2148 | var k,v,o; | |
2149 | for(k in this.LOCALE){ | |
2150 | o=this.LOCALE[k]; | |
2151 | if(typeof (o)=="object"){ | |
2152 | o.repr=function(){ | |
2153 | return this.NAME; | |
2154 | }; | |
2155 | o.NAME=base+"LOCALE."+k; | |
2156 | } | |
2157 | } | |
2158 | for(k in this){ | |
2159 | o=this[k]; | |
2160 | if(typeof (o)=="function"&&typeof (o.NAME)=="undefined"){ | |
2161 | try{ | |
2162 | o.NAME=base+k; | |
2163 | } | |
2164 | catch(e){ | |
2165 | } | |
2166 | } | |
2167 | } | |
2168 | }; | |
2169 | MochiKit.Format.__new__(); | |
2170 | if(typeof (MochiKit.Base)!="undefined"){ | |
2171 | MochiKit.Base._exportSymbols(this,MochiKit.Format); | |
2172 | }else{ | |
2173 | (function(_273,_274){ | |
2174 | if((typeof (JSAN)=="undefined"&&typeof (dojo)=="undefined")||(MochiKit.__export__===false)){ | |
2175 | var all=_274.EXPORT_TAGS[":all"]; | |
2176 | for(var i=0;i<all.length;i++){ | |
2177 | _273[all[i]]=_274[all[i]]; | |
2178 | } | |
2179 | } | |
2180 | })(this,MochiKit.Format); | |
2181 | } | |
2182 | if(typeof (dojo)!="undefined"){ | |
2183 | dojo.provide("MochiKit.Async"); | |
2184 | dojo.require("MochiKit.Base"); | |
2185 | } | |
2186 | if(typeof (JSAN)!="undefined"){ | |
2187 | JSAN.use("MochiKit.Base",[]); | |
2188 | } | |
2189 | try{ | |
2190 | if(typeof (MochiKit.Base)=="undefined"){ | |
2191 | throw ""; | |
2192 | } | |
2193 | } | |
2194 | catch(e){ | |
2195 | throw "MochiKit.Async depends on MochiKit.Base!"; | |
2196 | } | |
2197 | if(typeof (MochiKit.Async)=="undefined"){ | |
2198 | MochiKit.Async={}; | |
2199 | } | |
2200 | MochiKit.Async.NAME="MochiKit.Async"; | |
2201 | MochiKit.Async.VERSION="1.4"; | |
2202 | MochiKit.Async.__repr__=function(){ | |
2203 | return "["+this.NAME+" "+this.VERSION+"]"; | |
2204 | }; | |
2205 | MochiKit.Async.toString=function(){ | |
2206 | return this.__repr__(); | |
2207 | }; | |
2208 | MochiKit.Async.Deferred=function(_277){ | |
2209 | this.chain=[]; | |
2210 | this.id=this._nextId(); | |
2211 | this.fired=-1; | |
2212 | this.paused=0; | |
2213 | this.results=[null,null]; | |
2214 | this.canceller=_277; | |
2215 | this.silentlyCancelled=false; | |
2216 | this.chained=false; | |
2217 | }; | |
2218 | MochiKit.Async.Deferred.prototype={repr:function(){ | |
2219 | var _278; | |
2220 | if(this.fired==-1){ | |
2221 | _278="unfired"; | |
2222 | }else{ | |
2223 | if(this.fired===0){ | |
2224 | _278="success"; | |
2225 | }else{ | |
2226 | _278="error"; | |
2227 | } | |
2228 | } | |
2229 | return "Deferred("+this.id+", "+_278+")"; | |
2230 | },toString:MochiKit.Base.forwardCall("repr"),_nextId:MochiKit.Base.counter(),cancel:function(){ | |
2231 | var self=MochiKit.Async; | |
2232 | if(this.fired==-1){ | |
2233 | if(this.canceller){ | |
2234 | this.canceller(this); | |
2235 | }else{ | |
2236 | this.silentlyCancelled=true; | |
2237 | } | |
2238 | if(this.fired==-1){ | |
2239 | this.errback(new self.CancelledError(this)); | |
2240 | } | |
2241 | }else{ | |
2242 | if((this.fired===0)&&(this.results[0] instanceof self.Deferred)){ | |
2243 | this.results[0].cancel(); | |
2244 | } | |
2245 | } | |
2246 | },_resback:function(res){ | |
2247 | this.fired=((res instanceof Error)?1:0); | |
2248 | this.results[this.fired]=res; | |
2249 | this._fire(); | |
2250 | },_check:function(){ | |
2251 | if(this.fired!=-1){ | |
2252 | if(!this.silentlyCancelled){ | |
2253 | throw new MochiKit.Async.AlreadyCalledError(this); | |
2254 | } | |
2255 | this.silentlyCancelled=false; | |
2256 | return; | |
2257 | } | |
2258 | },callback:function(res){ | |
2259 | this._check(); | |
2260 | if(res instanceof MochiKit.Async.Deferred){ | |
2261 | throw new Error("Deferred instances can only be chained if they are the result of a callback"); | |
2262 | } | |
2263 | this._resback(res); | |
2264 | },errback:function(res){ | |
2265 | this._check(); | |
2266 | var self=MochiKit.Async; | |
2267 | if(res instanceof self.Deferred){ | |
2268 | throw new Error("Deferred instances can only be chained if they are the result of a callback"); | |
2269 | } | |
2270 | if(!(res instanceof Error)){ | |
2271 | res=new self.GenericError(res); | |
2272 | } | |
2273 | this._resback(res); | |
2274 | },addBoth:function(fn){ | |
2275 | if(arguments.length>1){ | |
2276 | fn=MochiKit.Base.partial.apply(null,arguments); | |
2277 | } | |
2278 | return this.addCallbacks(fn,fn); | |
2279 | },addCallback:function(fn){ | |
2280 | if(arguments.length>1){ | |
2281 | fn=MochiKit.Base.partial.apply(null,arguments); | |
2282 | } | |
2283 | return this.addCallbacks(fn,null); | |
2284 | },addErrback:function(fn){ | |
2285 | if(arguments.length>1){ | |
2286 | fn=MochiKit.Base.partial.apply(null,arguments); | |
2287 | } | |
2288 | return this.addCallbacks(null,fn); | |
2289 | },addCallbacks:function(cb,eb){ | |
2290 | if(this.chained){ | |
2291 | throw new Error("Chained Deferreds can not be re-used"); | |
2292 | } | |
2293 | this.chain.push([cb,eb]); | |
2294 | if(this.fired>=0){ | |
2295 | this._fire(); | |
2296 | } | |
2297 | return this; | |
2298 | },_fire:function(){ | |
2299 | var _283=this.chain; | |
2300 | var _284=this.fired; | |
2301 | var res=this.results[_284]; | |
2302 | var self=this; | |
2303 | var cb=null; | |
2304 | while(_283.length>0&&this.paused===0){ | |
2305 | var pair=_283.shift(); | |
2306 | var f=pair[_284]; | |
2307 | if(f===null){ | |
2308 | continue; | |
2309 | } | |
2310 | try{ | |
2311 | res=f(res); | |
2312 | _284=((res instanceof Error)?1:0); | |
2313 | if(res instanceof MochiKit.Async.Deferred){ | |
2314 | cb=function(res){ | |
2315 | self._resback(res); | |
2316 | self.paused--; | |
2317 | if((self.paused===0)&&(self.fired>=0)){ | |
2318 | self._fire(); | |
2319 | } | |
2320 | }; | |
2321 | this.paused++; | |
2322 | } | |
2323 | } | |
2324 | catch(err){ | |
2325 | _284=1; | |
2326 | if(!(err instanceof Error)){ | |
2327 | err=new MochiKit.Async.GenericError(err); | |
2328 | } | |
2329 | res=err; | |
2330 | } | |
2331 | } | |
2332 | this.fired=_284; | |
2333 | this.results[_284]=res; | |
2334 | if(cb&&this.paused){ | |
2335 | res.addBoth(cb); | |
2336 | res.chained=true; | |
2337 | } | |
2338 | }}; | |
2339 | MochiKit.Base.update(MochiKit.Async,{evalJSONRequest:function(){ | |
2340 | return eval("("+arguments[0].responseText+")"); | |
2341 | },succeed:function(_28b){ | |
2342 | var d=new MochiKit.Async.Deferred(); | |
2343 | d.callback.apply(d,arguments); | |
2344 | return d; | |
2345 | },fail:function(_28d){ | |
2346 | var d=new MochiKit.Async.Deferred(); | |
2347 | d.errback.apply(d,arguments); | |
2348 | return d; | |
2349 | },getXMLHttpRequest:function(){ | |
2350 | var self=arguments.callee; | |
2351 | if(!self.XMLHttpRequest){ | |
2352 | var _290=[function(){ | |
2353 | return new XMLHttpRequest(); | |
2354 | },function(){ | |
2355 | return new ActiveXObject("Msxml2.XMLHTTP"); | |
2356 | },function(){ | |
2357 | return new ActiveXObject("Microsoft.XMLHTTP"); | |
2358 | },function(){ | |
2359 | return new ActiveXObject("Msxml2.XMLHTTP.4.0"); | |
2360 | },function(){ | |
2361 | throw new MochiKit.Async.BrowserComplianceError("Browser does not support XMLHttpRequest"); | |
2362 | }]; | |
2363 | for(var i=0;i<_290.length;i++){ | |
2364 | var func=_290[i]; | |
2365 | try{ | |
2366 | self.XMLHttpRequest=func; | |
2367 | return func(); | |
2368 | } | |
2369 | catch(e){ | |
2370 | } | |
2371 | } | |
2372 | } | |
2373 | return self.XMLHttpRequest(); | |
2374 | },_xhr_onreadystatechange:function(d){ | |
2375 | var m=MochiKit.Base; | |
2376 | if(this.readyState==4){ | |
2377 | try{ | |
2378 | this.onreadystatechange=null; | |
2379 | } | |
2380 | catch(e){ | |
2381 | try{ | |
2382 | this.onreadystatechange=m.noop; | |
2383 | } | |
2384 | catch(e){ | |
2385 | } | |
2386 | } | |
2387 | var _295=null; | |
2388 | try{ | |
2389 | _295=this.status; | |
2390 | if(!_295&&m.isNotEmpty(this.responseText)){ | |
2391 | _295=304; | |
2392 | } | |
2393 | } | |
2394 | catch(e){ | |
2395 | } | |
2396 | if(_295==200||_295==201||_295==204||_295==304||_295==1223){ | |
2397 | d.callback(this); | |
2398 | }else{ | |
2399 | var err=new MochiKit.Async.XMLHttpRequestError(this,"Request failed"); | |
2400 | if(err.number){ | |
2401 | d.errback(err); | |
2402 | }else{ | |
2403 | d.errback(err); | |
2404 | } | |
2405 | } | |
2406 | } | |
2407 | },_xhr_canceller:function(req){ | |
2408 | try{ | |
2409 | req.onreadystatechange=null; | |
2410 | } | |
2411 | catch(e){ | |
2412 | try{ | |
2413 | req.onreadystatechange=MochiKit.Base.noop; | |
2414 | } | |
2415 | catch(e){ | |
2416 | } | |
2417 | } | |
2418 | req.abort(); | |
2419 | },sendXMLHttpRequest:function(req,_299){ | |
2420 | if(typeof (_299)=="undefined"||_299===null){ | |
2421 | _299=""; | |
2422 | } | |
2423 | var m=MochiKit.Base; | |
2424 | var self=MochiKit.Async; | |
2425 | var d=new self.Deferred(m.partial(self._xhr_canceller,req)); | |
2426 | try{ | |
2427 | req.onreadystatechange=m.bind(self._xhr_onreadystatechange,req,d); | |
2428 | req.send(_299); | |
2429 | } | |
2430 | catch(e){ | |
2431 | try{ | |
2432 | req.onreadystatechange=null; | |
2433 | } | |
2434 | catch(ignore){ | |
2435 | } | |
2436 | d.errback(e); | |
2437 | } | |
2438 | return d; | |
2439 | },doXHR:function(url,opts){ | |
2440 | var self=MochiKit.Async; | |
2441 | return self.callLater(0,self._doXHR,url,opts); | |
2442 | },_doXHR:function(url,opts){ | |
2443 | var m=MochiKit.Base; | |
2444 | opts=m.update({method:"GET",sendContent:""},opts); | |
2445 | var self=MochiKit.Async; | |
2446 | var req=self.getXMLHttpRequest(); | |
2447 | if(opts.queryString){ | |
2448 | var qs=m.queryString(opts.queryString); | |
2449 | if(qs){ | |
2450 | url+="?"+qs; | |
2451 | } | |
2452 | } | |
2453 | if("username" in opts){ | |
2454 | req.open(opts.method,url,true,opts.username,opts.password); | |
2455 | }else{ | |
2456 | req.open(opts.method,url,true); | |
2457 | } | |
2458 | if(req.overrideMimeType&&opts.mimeType){ | |
2459 | req.overrideMimeType(opts.mimeType); | |
2460 | } | |
2461 | if(opts.headers){ | |
2462 | var _2a6=opts.headers; | |
2463 | if(!m.isArrayLike(_2a6)){ | |
2464 | _2a6=m.items(_2a6); | |
2465 | } | |
2466 | for(var i=0;i<_2a6.length;i++){ | |
2467 | var _2a8=_2a6[i]; | |
2468 | var name=_2a8[0]; | |
2469 | var _2aa=_2a8[1]; | |
2470 | req.setRequestHeader(name,_2aa); | |
2471 | } | |
2472 | } | |
2473 | return self.sendXMLHttpRequest(req,opts.sendContent); | |
2474 | },_buildURL:function(url){ | |
2475 | if(arguments.length>1){ | |
2476 | var m=MochiKit.Base; | |
2477 | var qs=m.queryString.apply(null,m.extend(null,arguments,1)); | |
2478 | if(qs){ | |
2479 | return url+"?"+qs; | |
2480 | } | |
2481 | } | |
2482 | return url; | |
2483 | },doSimpleXMLHttpRequest:function(url){ | |
2484 | var self=MochiKit.Async; | |
2485 | url=self._buildURL.apply(self,arguments); | |
2486 | return self.doXHR(url); | |
2487 | },loadJSONDoc:function(url){ | |
2488 | var self=MochiKit.Async; | |
2489 | url=self._buildURL.apply(self,arguments); | |
2490 | var d=self.doXHR(url,{"mimeType":"text/plain","headers":[["Accept","application/json"]]}); | |
2491 | d=d.addCallback(self.evalJSONRequest); | |
2492 | return d; | |
2493 | },wait:function(_2b3,_2b4){ | |
2494 | var d=new MochiKit.Async.Deferred(); | |
2495 | var m=MochiKit.Base; | |
2496 | if(typeof (_2b4)!="undefined"){ | |
2497 | d.addCallback(function(){ | |
2498 | return _2b4; | |
2499 | }); | |
2500 | } | |
2501 | var _2b7=setTimeout(m.bind("callback",d),Math.floor(_2b3*1000)); | |
2502 | d.canceller=function(){ | |
2503 | try{ | |
2504 | clearTimeout(_2b7); | |
2505 | } | |
2506 | catch(e){ | |
2507 | } | |
2508 | }; | |
2509 | return d; | |
2510 | },callLater:function(_2b8,func){ | |
2511 | var m=MochiKit.Base; | |
2512 | var _2bb=m.partial.apply(m,m.extend(null,arguments,1)); | |
2513 | return MochiKit.Async.wait(_2b8).addCallback(function(res){ | |
2514 | return _2bb(); | |
2515 | }); | |
2516 | }}); | |
2517 | MochiKit.Async.DeferredLock=function(){ | |
2518 | this.waiting=[]; | |
2519 | this.locked=false; | |
2520 | this.id=this._nextId(); | |
2521 | }; | |
2522 | MochiKit.Async.DeferredLock.prototype={__class__:MochiKit.Async.DeferredLock,acquire:function(){ | |
2523 | var d=new MochiKit.Async.Deferred(); | |
2524 | if(this.locked){ | |
2525 | this.waiting.push(d); | |
2526 | }else{ | |
2527 | this.locked=true; | |
2528 | d.callback(this); | |
2529 | } | |
2530 | return d; | |
2531 | },release:function(){ | |
2532 | if(!this.locked){ | |
2533 | throw TypeError("Tried to release an unlocked DeferredLock"); | |
2534 | } | |
2535 | this.locked=false; | |
2536 | if(this.waiting.length>0){ | |
2537 | this.locked=true; | |
2538 | this.waiting.shift().callback(this); | |
2539 | } | |
2540 | },_nextId:MochiKit.Base.counter(),repr:function(){ | |
2541 | var _2be; | |
2542 | if(this.locked){ | |
2543 | _2be="locked, "+this.waiting.length+" waiting"; | |
2544 | }else{ | |
2545 | _2be="unlocked"; | |
2546 | } | |
2547 | return "DeferredLock("+this.id+", "+_2be+")"; | |
2548 | },toString:MochiKit.Base.forwardCall("repr")}; | |
2549 | MochiKit.Async.DeferredList=function(list,_2c0,_2c1,_2c2,_2c3){ | |
2550 | MochiKit.Async.Deferred.apply(this,[_2c3]); | |
2551 | this.list=list; | |
2552 | var _2c4=[]; | |
2553 | this.resultList=_2c4; | |
2554 | this.finishedCount=0; | |
2555 | this.fireOnOneCallback=_2c0; | |
2556 | this.fireOnOneErrback=_2c1; | |
2557 | this.consumeErrors=_2c2; | |
2558 | var cb=MochiKit.Base.bind(this._cbDeferred,this); | |
2559 | for(var i=0;i<list.length;i++){ | |
2560 | var d=list[i]; | |
2561 | _2c4.push(undefined); | |
2562 | d.addCallback(cb,i,true); | |
2563 | d.addErrback(cb,i,false); | |
2564 | } | |
2565 | if(list.length===0&&!_2c0){ | |
2566 | this.callback(this.resultList); | |
2567 | } | |
2568 | }; | |
2569 | MochiKit.Async.DeferredList.prototype=new MochiKit.Async.Deferred(); | |
2570 | MochiKit.Async.DeferredList.prototype._cbDeferred=function(_2c8,_2c9,_2ca){ | |
2571 | this.resultList[_2c8]=[_2c9,_2ca]; | |
2572 | this.finishedCount+=1; | |
2573 | if(this.fired==-1){ | |
2574 | if(_2c9&&this.fireOnOneCallback){ | |
2575 | this.callback([_2c8,_2ca]); | |
2576 | }else{ | |
2577 | if(!_2c9&&this.fireOnOneErrback){ | |
2578 | this.errback(_2ca); | |
2579 | }else{ | |
2580 | if(this.finishedCount==this.list.length){ | |
2581 | this.callback(this.resultList); | |
2582 | } | |
2583 | } | |
2584 | } | |
2585 | } | |
2586 | if(!_2c9&&this.consumeErrors){ | |
2587 | _2ca=null; | |
2588 | } | |
2589 | return _2ca; | |
2590 | }; | |
2591 | MochiKit.Async.gatherResults=function(_2cb){ | |
2592 | var d=new MochiKit.Async.DeferredList(_2cb,false,true,false); | |
2593 | d.addCallback(function(_2cd){ | |
2594 | var ret=[]; | |
2595 | for(var i=0;i<_2cd.length;i++){ | |
2596 | ret.push(_2cd[i][1]); | |
2597 | } | |
2598 | return ret; | |
2599 | }); | |
2600 | return d; | |
2601 | }; | |
2602 | MochiKit.Async.maybeDeferred=function(func){ | |
2603 | var self=MochiKit.Async; | |
2604 | var _2d2; | |
2605 | try{ | |
2606 | var r=func.apply(null,MochiKit.Base.extend([],arguments,1)); | |
2607 | if(r instanceof self.Deferred){ | |
2608 | _2d2=r; | |
2609 | }else{ | |
2610 | if(r instanceof Error){ | |
2611 | _2d2=self.fail(r); | |
2612 | }else{ | |
2613 | _2d2=self.succeed(r); | |
2614 | } | |
2615 | } | |
2616 | } | |
2617 | catch(e){ | |
2618 | _2d2=self.fail(e); | |
2619 | } | |
2620 | return _2d2; | |
2621 | }; | |
2622 | MochiKit.Async.EXPORT=["AlreadyCalledError","CancelledError","BrowserComplianceError","GenericError","XMLHttpRequestError","Deferred","succeed","fail","getXMLHttpRequest","doSimpleXMLHttpRequest","loadJSONDoc","wait","callLater","sendXMLHttpRequest","DeferredLock","DeferredList","gatherResults","maybeDeferred","doXHR"]; | |
2623 | MochiKit.Async.EXPORT_OK=["evalJSONRequest"]; | |
2624 | MochiKit.Async.__new__=function(){ | |
2625 | var m=MochiKit.Base; | |
2626 | var ne=m.partial(m._newNamedError,this); | |
2627 | ne("AlreadyCalledError",function(_2d6){ | |
2628 | this.deferred=_2d6; | |
2629 | }); | |
2630 | ne("CancelledError",function(_2d7){ | |
2631 | this.deferred=_2d7; | |
2632 | }); | |
2633 | ne("BrowserComplianceError",function(msg){ | |
2634 | this.message=msg; | |
2635 | }); | |
2636 | ne("GenericError",function(msg){ | |
2637 | this.message=msg; | |
2638 | }); | |
2639 | ne("XMLHttpRequestError",function(req,msg){ | |
2640 | this.req=req; | |
2641 | this.message=msg; | |
2642 | try{ | |
2643 | this.number=req.status; | |
2644 | } | |
2645 | catch(e){ | |
2646 | } | |
2647 | }); | |
2648 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
2649 | m.nameFunctions(this); | |
2650 | }; | |
2651 | MochiKit.Async.__new__(); | |
2652 | MochiKit.Base._exportSymbols(this,MochiKit.Async); | |
2653 | if(typeof (dojo)!="undefined"){ | |
2654 | dojo.provide("MochiKit.DOM"); | |
2655 | dojo.require("MochiKit.Base"); | |
2656 | } | |
2657 | if(typeof (JSAN)!="undefined"){ | |
2658 | JSAN.use("MochiKit.Base",[]); | |
2659 | } | |
2660 | try{ | |
2661 | if(typeof (MochiKit.Base)=="undefined"){ | |
2662 | throw ""; | |
2663 | } | |
2664 | } | |
2665 | catch(e){ | |
2666 | throw "MochiKit.DOM depends on MochiKit.Base!"; | |
2667 | } | |
2668 | if(typeof (MochiKit.DOM)=="undefined"){ | |
2669 | MochiKit.DOM={}; | |
2670 | } | |
2671 | MochiKit.DOM.NAME="MochiKit.DOM"; | |
2672 | MochiKit.DOM.VERSION="1.4"; | |
2673 | MochiKit.DOM.__repr__=function(){ | |
2674 | return "["+this.NAME+" "+this.VERSION+"]"; | |
2675 | }; | |
2676 | MochiKit.DOM.toString=function(){ | |
2677 | return this.__repr__(); | |
2678 | }; | |
2679 | 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"]; | |
2680 | MochiKit.DOM.EXPORT_OK=["domConverters"]; | |
2681 | 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"]]; | |
2682 | 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);"); | |
2683 | MochiKit.Base.update(MochiKit.DOM,{currentWindow:function(){ | |
2684 | return MochiKit.DOM._window; | |
2685 | },currentDocument:function(){ | |
2686 | return MochiKit.DOM._document; | |
2687 | },withWindow:function(win,func){ | |
2688 | var self=MochiKit.DOM; | |
2689 | var _2df=self._document; | |
2690 | var _2e0=self._window; | |
2691 | var rval; | |
2692 | try{ | |
2693 | self._window=win; | |
2694 | self._document=win.document; | |
2695 | rval=func(); | |
2696 | } | |
2697 | catch(e){ | |
2698 | self._window=_2e0; | |
2699 | self._document=_2df; | |
2700 | throw e; | |
2701 | } | |
2702 | self._window=_2e0; | |
2703 | self._document=_2df; | |
2704 | return rval; | |
2705 | },formContents:function(elem){ | |
2706 | var _2e3=[]; | |
2707 | var _2e4=[]; | |
2708 | var m=MochiKit.Base; | |
2709 | var self=MochiKit.DOM; | |
2710 | if(typeof (elem)=="undefined"||elem===null){ | |
2711 | elem=self._document.body; | |
2712 | }else{ | |
2713 | elem=self.getElement(elem); | |
2714 | } | |
2715 | m.nodeWalk(elem,function(elem){ | |
2716 | var name=elem.name; | |
2717 | if(m.isNotEmpty(name)){ | |
2718 | var _2e9=elem.tagName.toUpperCase(); | |
2719 | if(_2e9==="INPUT"&&(elem.type=="radio"||elem.type=="checkbox")&&!elem.checked){ | |
2720 | return null; | |
2721 | } | |
2722 | if(_2e9==="SELECT"){ | |
2723 | if(elem.type=="select-one"){ | |
2724 | if(elem.selectedIndex>=0){ | |
2725 | var opt=elem.options[elem.selectedIndex]; | |
2726 | var v=opt.value; | |
2727 | if(!v){ | |
2728 | var h=opt.outerHTML; | |
2729 | if(h&&!h.match(/^[^>]+\svalue\s*=/i)){ | |
2730 | v=opt.text; | |
2731 | } | |
2732 | } | |
2733 | _2e3.push(name); | |
2734 | _2e4.push(v); | |
2735 | return null; | |
2736 | } | |
2737 | _2e3.push(name); | |
2738 | _2e4.push(""); | |
2739 | return null; | |
2740 | }else{ | |
2741 | var opts=elem.options; | |
2742 | if(!opts.length){ | |
2743 | _2e3.push(name); | |
2744 | _2e4.push(""); | |
2745 | return null; | |
2746 | } | |
2747 | for(var i=0;i<opts.length;i++){ | |
2748 | var opt=opts[i]; | |
2749 | if(!opt.selected){ | |
2750 | continue; | |
2751 | } | |
2752 | var v=opt.value; | |
2753 | if(!v){ | |
2754 | var h=opt.outerHTML; | |
2755 | if(h&&!h.match(/^[^>]+\svalue\s*=/i)){ | |
2756 | v=opt.text; | |
2757 | } | |
2758 | } | |
2759 | _2e3.push(name); | |
2760 | _2e4.push(v); | |
2761 | } | |
2762 | return null; | |
2763 | } | |
2764 | } | |
2765 | if(_2e9==="FORM"||_2e9==="P"||_2e9==="SPAN"||_2e9==="DIV"){ | |
2766 | return elem.childNodes; | |
2767 | } | |
2768 | _2e3.push(name); | |
2769 | _2e4.push(elem.value||""); | |
2770 | return null; | |
2771 | } | |
2772 | return elem.childNodes; | |
2773 | }); | |
2774 | return [_2e3,_2e4]; | |
2775 | },withDocument:function(doc,func){ | |
2776 | var self=MochiKit.DOM; | |
2777 | var _2f2=self._document; | |
2778 | var rval; | |
2779 | try{ | |
2780 | self._document=doc; | |
2781 | rval=func(); | |
2782 | } | |
2783 | catch(e){ | |
2784 | self._document=_2f2; | |
2785 | throw e; | |
2786 | } | |
2787 | self._document=_2f2; | |
2788 | return rval; | |
2789 | },registerDOMConverter:function(name,_2f5,wrap,_2f7){ | |
2790 | MochiKit.DOM.domConverters.register(name,_2f5,wrap,_2f7); | |
2791 | },coerceToDOM:function(node,ctx){ | |
2792 | var m=MochiKit.Base; | |
2793 | var im=MochiKit.Iter; | |
2794 | var self=MochiKit.DOM; | |
2795 | if(im){ | |
2796 | var iter=im.iter; | |
2797 | var _2fe=im.repeat; | |
2798 | var map=m.map; | |
2799 | } | |
2800 | var _300=self.domConverters; | |
2801 | var _301=arguments.callee; | |
2802 | var _302=m.NotFound; | |
2803 | while(true){ | |
2804 | if(typeof (node)=="undefined"||node===null){ | |
2805 | return null; | |
2806 | } | |
2807 | if(typeof (node)=="function"&&typeof (node.length)=="number"&&!(node instanceof Function)){ | |
2808 | node=im.list(node); | |
2809 | } | |
2810 | if(typeof (node.nodeType)!="undefined"&&node.nodeType>0){ | |
2811 | return node; | |
2812 | } | |
2813 | if(typeof (node)=="number"||typeof (node)=="boolean"){ | |
2814 | node=node.toString(); | |
2815 | } | |
2816 | if(typeof (node)=="string"){ | |
2817 | return self._document.createTextNode(node); | |
2818 | } | |
2819 | if(typeof (node.__dom__)=="function"){ | |
2820 | node=node.__dom__(ctx); | |
2821 | continue; | |
2822 | } | |
2823 | if(typeof (node.dom)=="function"){ | |
2824 | node=node.dom(ctx); | |
2825 | continue; | |
2826 | } | |
2827 | if(typeof (node)=="function"){ | |
2828 | node=node.apply(ctx,[ctx]); | |
2829 | continue; | |
2830 | } | |
2831 | if(im){ | |
2832 | var _303=null; | |
2833 | try{ | |
2834 | _303=iter(node); | |
2835 | } | |
2836 | catch(e){ | |
2837 | } | |
2838 | if(_303){ | |
2839 | return map(_301,_303,_2fe(ctx)); | |
2840 | } | |
2841 | } | |
2842 | try{ | |
2843 | node=_300.match(node,ctx); | |
2844 | continue; | |
2845 | } | |
2846 | catch(e){ | |
2847 | if(e!=_302){ | |
2848 | throw e; | |
2849 | } | |
2850 | } | |
2851 | return self._document.createTextNode(node.toString()); | |
2852 | } | |
2853 | return undefined; | |
2854 | },isChildNode:function(node,_305){ | |
2855 | var self=MochiKit.DOM; | |
2856 | if(typeof (node)=="string"){ | |
2857 | node=self.getElement(node); | |
2858 | } | |
2859 | if(typeof (_305)=="string"){ | |
2860 | _305=self.getElement(_305); | |
2861 | } | |
2862 | if(node===_305){ | |
2863 | return true; | |
2864 | } | |
2865 | while(node&&node.tagName.toUpperCase()!="BODY"){ | |
2866 | node=node.parentNode; | |
2867 | if(node===_305){ | |
2868 | return true; | |
2869 | } | |
2870 | } | |
2871 | return false; | |
2872 | },setNodeAttribute:function(node,attr,_309){ | |
2873 | var o={}; | |
2874 | o[attr]=_309; | |
2875 | try{ | |
2876 | return MochiKit.DOM.updateNodeAttributes(node,o); | |
2877 | } | |
2878 | catch(e){ | |
2879 | } | |
2880 | return null; | |
2881 | },getNodeAttribute:function(node,attr){ | |
2882 | var self=MochiKit.DOM; | |
2883 | var _30e=self.attributeArray.renames[attr]; | |
2884 | node=self.getElement(node); | |
2885 | try{ | |
2886 | if(_30e){ | |
2887 | return node[_30e]; | |
2888 | } | |
2889 | return node.getAttribute(attr); | |
2890 | } | |
2891 | catch(e){ | |
2892 | } | |
2893 | return null; | |
2894 | },removeNodeAttribute:function(node,attr){ | |
2895 | var self=MochiKit.DOM; | |
2896 | var _312=self.attributeArray.renames[attr]; | |
2897 | node=self.getElement(node); | |
2898 | try{ | |
2899 | if(_312){ | |
2900 | return node[_312]; | |
2901 | } | |
2902 | return node.removeAttribute(attr); | |
2903 | } | |
2904 | catch(e){ | |
2905 | } | |
2906 | return null; | |
2907 | },updateNodeAttributes:function(node,_314){ | |
2908 | var elem=node; | |
2909 | var self=MochiKit.DOM; | |
2910 | if(typeof (node)=="string"){ | |
2911 | elem=self.getElement(node); | |
2912 | } | |
2913 | if(_314){ | |
2914 | var _317=MochiKit.Base.updatetree; | |
2915 | if(self.attributeArray.compliant){ | |
2916 | for(var k in _314){ | |
2917 | var v=_314[k]; | |
2918 | if(typeof (v)=="object"&&typeof (elem[k])=="object"){ | |
2919 | if(k=="style"&&MochiKit.Style){ | |
2920 | MochiKit.Style.setStyle(elem,v); | |
2921 | }else{ | |
2922 | _317(elem[k],v); | |
2923 | } | |
2924 | }else{ | |
2925 | if(k.substring(0,2)=="on"){ | |
2926 | if(typeof (v)=="string"){ | |
2927 | v=new Function(v); | |
2928 | } | |
2929 | elem[k]=v; | |
2930 | }else{ | |
2931 | elem.setAttribute(k,v); | |
2932 | } | |
2933 | } | |
2934 | } | |
2935 | }else{ | |
2936 | var _31a=self.attributeArray.renames; | |
2937 | for(var k in _314){ | |
2938 | v=_314[k]; | |
2939 | var _31b=_31a[k]; | |
2940 | if(k=="style"&&typeof (v)=="string"){ | |
2941 | elem.style.cssText=v; | |
2942 | }else{ | |
2943 | if(typeof (_31b)=="string"){ | |
2944 | elem[_31b]=v; | |
2945 | }else{ | |
2946 | if(typeof (elem[k])=="object"&&typeof (v)=="object"){ | |
2947 | if(k=="style"&&MochiKit.Style){ | |
2948 | MochiKit.Style.setStyle(elem,v); | |
2949 | }else{ | |
2950 | _317(elem[k],v); | |
2951 | } | |
2952 | }else{ | |
2953 | if(k.substring(0,2)=="on"){ | |
2954 | if(typeof (v)=="string"){ | |
2955 | v=new Function(v); | |
2956 | } | |
2957 | elem[k]=v; | |
2958 | }else{ | |
2959 | elem.setAttribute(k,v); | |
2960 | } | |
2961 | } | |
2962 | } | |
2963 | } | |
2964 | } | |
2965 | } | |
2966 | } | |
2967 | return elem; | |
2968 | },appendChildNodes:function(node){ | |
2969 | var elem=node; | |
2970 | var self=MochiKit.DOM; | |
2971 | if(typeof (node)=="string"){ | |
2972 | elem=self.getElement(node); | |
2973 | } | |
2974 | var _31f=[self.coerceToDOM(MochiKit.Base.extend(null,arguments,1),elem)]; | |
2975 | var _320=MochiKit.Base.concat; | |
2976 | while(_31f.length){ | |
2977 | var n=_31f.shift(); | |
2978 | if(typeof (n)=="undefined"||n===null){ | |
2979 | }else{ | |
2980 | if(typeof (n.nodeType)=="number"){ | |
2981 | elem.appendChild(n); | |
2982 | }else{ | |
2983 | _31f=_320(n,_31f); | |
2984 | } | |
2985 | } | |
2986 | } | |
2987 | return elem; | |
2988 | },insertSiblingNodesBefore:function(node){ | |
2989 | var elem=node; | |
2990 | var self=MochiKit.DOM; | |
2991 | if(typeof (node)=="string"){ | |
2992 | elem=self.getElement(node); | |
2993 | } | |
2994 | var _325=[self.coerceToDOM(MochiKit.Base.extend(null,arguments,1),elem)]; | |
2995 | var _326=elem.parentNode; | |
2996 | var _327=MochiKit.Base.concat; | |
2997 | while(_325.length){ | |
2998 | var n=_325.shift(); | |
2999 | if(typeof (n)=="undefined"||n===null){ | |
3000 | }else{ | |
3001 | if(typeof (n.nodeType)=="number"){ | |
3002 | _326.insertBefore(n,elem); | |
3003 | }else{ | |
3004 | _325=_327(n,_325); | |
3005 | } | |
3006 | } | |
3007 | } | |
3008 | return _326; | |
3009 | },insertSiblingNodesAfter:function(node){ | |
3010 | var elem=node; | |
3011 | var self=MochiKit.DOM; | |
3012 | if(typeof (node)=="string"){ | |
3013 | elem=self.getElement(node); | |
3014 | } | |
3015 | var _32c=[self.coerceToDOM(MochiKit.Base.extend(null,arguments,1),elem)]; | |
3016 | if(elem.nextSibling){ | |
3017 | return self.insertSiblingNodesBefore(elem.nextSibling,_32c); | |
3018 | }else{ | |
3019 | return self.appendChildNodes(elem.parentNode,_32c); | |
3020 | } | |
3021 | },replaceChildNodes:function(node){ | |
3022 | var elem=node; | |
3023 | var self=MochiKit.DOM; | |
3024 | if(typeof (node)=="string"){ | |
3025 | elem=self.getElement(node); | |
3026 | arguments[0]=elem; | |
3027 | } | |
3028 | var _330; | |
3029 | while((_330=elem.firstChild)){ | |
3030 | elem.removeChild(_330); | |
3031 | } | |
3032 | if(arguments.length<2){ | |
3033 | return elem; | |
3034 | }else{ | |
3035 | return self.appendChildNodes.apply(this,arguments); | |
3036 | } | |
3037 | },createDOM:function(name,_332){ | |
3038 | var elem; | |
3039 | var self=MochiKit.DOM; | |
3040 | var m=MochiKit.Base; | |
3041 | if(typeof (_332)=="string"||typeof (_332)=="number"){ | |
3042 | var args=m.extend([name,null],arguments,1); | |
3043 | return arguments.callee.apply(this,args); | |
3044 | } | |
3045 | if(typeof (name)=="string"){ | |
3046 | var _337=self._xhtml; | |
3047 | if(_332&&!self.attributeArray.compliant){ | |
3048 | var _338=""; | |
3049 | if("name" in _332){ | |
3050 | _338+=" name=\""+self.escapeHTML(_332.name)+"\""; | |
3051 | } | |
3052 | if(name=="input"&&"type" in _332){ | |
3053 | _338+=" type=\""+self.escapeHTML(_332.type)+"\""; | |
3054 | } | |
3055 | if(_338){ | |
3056 | name="<"+name+_338+">"; | |
3057 | _337=false; | |
3058 | } | |
3059 | } | |
3060 | var d=self._document; | |
3061 | if(_337&&d===document){ | |
3062 | elem=d.createElementNS("http://www.w3.org/1999/xhtml",name); | |
3063 | }else{ | |
3064 | elem=d.createElement(name); | |
3065 | } | |
3066 | }else{ | |
3067 | elem=name; | |
3068 | } | |
3069 | if(_332){ | |
3070 | self.updateNodeAttributes(elem,_332); | |
3071 | } | |
3072 | if(arguments.length<=2){ | |
3073 | return elem; | |
3074 | }else{ | |
3075 | var args=m.extend([elem],arguments,2); | |
3076 | return self.appendChildNodes.apply(this,args); | |
3077 | } | |
3078 | },createDOMFunc:function(){ | |
3079 | var m=MochiKit.Base; | |
3080 | return m.partial.apply(this,m.extend([MochiKit.DOM.createDOM],arguments)); | |
3081 | },removeElement:function(elem){ | |
3082 | var e=MochiKit.DOM.getElement(elem); | |
3083 | e.parentNode.removeChild(e); | |
3084 | return e; | |
3085 | },swapDOM:function(dest,src){ | |
3086 | var self=MochiKit.DOM; | |
3087 | dest=self.getElement(dest); | |
3088 | var _340=dest.parentNode; | |
3089 | if(src){ | |
3090 | src=self.getElement(src); | |
3091 | _340.replaceChild(src,dest); | |
3092 | }else{ | |
3093 | _340.removeChild(dest); | |
3094 | } | |
3095 | return src; | |
3096 | },getElement:function(id){ | |
3097 | var self=MochiKit.DOM; | |
3098 | if(arguments.length==1){ | |
3099 | return ((typeof (id)=="string")?self._document.getElementById(id):id); | |
3100 | }else{ | |
3101 | return MochiKit.Base.map(self.getElement,arguments); | |
3102 | } | |
3103 | },getElementsByTagAndClassName:function(_343,_344,_345){ | |
3104 | var self=MochiKit.DOM; | |
3105 | if(typeof (_343)=="undefined"||_343===null){ | |
3106 | _343="*"; | |
3107 | } | |
3108 | if(typeof (_345)=="undefined"||_345===null){ | |
3109 | _345=self._document; | |
3110 | } | |
3111 | _345=self.getElement(_345); | |
3112 | var _347=(_345.getElementsByTagName(_343)||self._document.all); | |
3113 | if(typeof (_344)=="undefined"||_344===null){ | |
3114 | return MochiKit.Base.extend(null,_347); | |
3115 | } | |
3116 | var _348=[]; | |
3117 | for(var i=0;i<_347.length;i++){ | |
3118 | var _34a=_347[i]; | |
3119 | var cls=_34a.className; | |
3120 | if(!cls){ | |
3121 | continue; | |
3122 | } | |
3123 | var _34c=cls.split(" "); | |
3124 | for(var j=0;j<_34c.length;j++){ | |
3125 | if(_34c[j]==_344){ | |
3126 | _348.push(_34a); | |
3127 | break; | |
3128 | } | |
3129 | } | |
3130 | } | |
3131 | return _348; | |
3132 | },_newCallStack:function(path,once){ | |
3133 | var rval=function(){ | |
3134 | var _351=arguments.callee.callStack; | |
3135 | for(var i=0;i<_351.length;i++){ | |
3136 | if(_351[i].apply(this,arguments)===false){ | |
3137 | break; | |
3138 | } | |
3139 | } | |
3140 | if(once){ | |
3141 | try{ | |
3142 | this[path]=null; | |
3143 | } | |
3144 | catch(e){ | |
3145 | } | |
3146 | } | |
3147 | }; | |
3148 | rval.callStack=[]; | |
3149 | return rval; | |
3150 | },addToCallStack:function(_353,path,func,once){ | |
3151 | var self=MochiKit.DOM; | |
3152 | var _358=_353[path]; | |
3153 | var _359=_358; | |
3154 | if(!(typeof (_358)=="function"&&typeof (_358.callStack)=="object"&&_358.callStack!==null)){ | |
3155 | _359=self._newCallStack(path,once); | |
3156 | if(typeof (_358)=="function"){ | |
3157 | _359.callStack.push(_358); | |
3158 | } | |
3159 | _353[path]=_359; | |
3160 | } | |
3161 | _359.callStack.push(func); | |
3162 | },addLoadEvent:function(func){ | |
3163 | var self=MochiKit.DOM; | |
3164 | self.addToCallStack(self._window,"onload",func,true); | |
3165 | },focusOnLoad:function(_35c){ | |
3166 | var self=MochiKit.DOM; | |
3167 | self.addLoadEvent(function(){ | |
3168 | _35c=self.getElement(_35c); | |
3169 | if(_35c){ | |
3170 | _35c.focus(); | |
3171 | } | |
3172 | }); | |
3173 | },setElementClass:function(_35e,_35f){ | |
3174 | var self=MochiKit.DOM; | |
3175 | var obj=self.getElement(_35e); | |
3176 | if(self.attributeArray.compliant){ | |
3177 | obj.setAttribute("class",_35f); | |
3178 | }else{ | |
3179 | obj.setAttribute("className",_35f); | |
3180 | } | |
3181 | },toggleElementClass:function(_362){ | |
3182 | var self=MochiKit.DOM; | |
3183 | for(var i=1;i<arguments.length;i++){ | |
3184 | var obj=self.getElement(arguments[i]); | |
3185 | if(!self.addElementClass(obj,_362)){ | |
3186 | self.removeElementClass(obj,_362); | |
3187 | } | |
3188 | } | |
3189 | },addElementClass:function(_366,_367){ | |
3190 | var self=MochiKit.DOM; | |
3191 | var obj=self.getElement(_366); | |
3192 | var cls=obj.className; | |
3193 | if(cls==undefined||cls.length===0){ | |
3194 | self.setElementClass(obj,_367); | |
3195 | return true; | |
3196 | } | |
3197 | if(cls==_367){ | |
3198 | return false; | |
3199 | } | |
3200 | var _36b=cls.split(" "); | |
3201 | for(var i=0;i<_36b.length;i++){ | |
3202 | if(_36b[i]==_367){ | |
3203 | return false; | |
3204 | } | |
3205 | } | |
3206 | self.setElementClass(obj,cls+" "+_367); | |
3207 | return true; | |
3208 | },removeElementClass:function(_36d,_36e){ | |
3209 | var self=MochiKit.DOM; | |
3210 | var obj=self.getElement(_36d); | |
3211 | var cls=obj.className; | |
3212 | if(cls==undefined||cls.length===0){ | |
3213 | return false; | |
3214 | } | |
3215 | if(cls==_36e){ | |
3216 | self.setElementClass(obj,""); | |
3217 | return true; | |
3218 | } | |
3219 | var _372=cls.split(" "); | |
3220 | for(var i=0;i<_372.length;i++){ | |
3221 | if(_372[i]==_36e){ | |
3222 | _372.splice(i,1); | |
3223 | self.setElementClass(obj,_372.join(" ")); | |
3224 | return true; | |
3225 | } | |
3226 | } | |
3227 | return false; | |
3228 | },swapElementClass:function(_374,_375,_376){ | |
3229 | var obj=MochiKit.DOM.getElement(_374); | |
3230 | var res=MochiKit.DOM.removeElementClass(obj,_375); | |
3231 | if(res){ | |
3232 | MochiKit.DOM.addElementClass(obj,_376); | |
3233 | } | |
3234 | return res; | |
3235 | },hasElementClass:function(_379,_37a){ | |
3236 | var obj=MochiKit.DOM.getElement(_379); | |
3237 | var cls=obj.className; | |
3238 | if(!cls){ | |
3239 | return false; | |
3240 | } | |
3241 | var _37d=cls.split(" "); | |
3242 | for(var i=1;i<arguments.length;i++){ | |
3243 | var good=false; | |
3244 | for(var j=0;j<_37d.length;j++){ | |
3245 | if(_37d[j]==arguments[i]){ | |
3246 | good=true; | |
3247 | break; | |
3248 | } | |
3249 | } | |
3250 | if(!good){ | |
3251 | return false; | |
3252 | } | |
3253 | } | |
3254 | return true; | |
3255 | },escapeHTML:function(s){ | |
3256 | return s.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">"); | |
3257 | },toHTML:function(dom){ | |
3258 | return MochiKit.DOM.emitHTML(dom).join(""); | |
3259 | },emitHTML:function(dom,lst){ | |
3260 | if(typeof (lst)=="undefined"||lst===null){ | |
3261 | lst=[]; | |
3262 | } | |
3263 | var _385=[dom]; | |
3264 | var self=MochiKit.DOM; | |
3265 | var _387=self.escapeHTML; | |
3266 | var _388=self.attributeArray; | |
3267 | while(_385.length){ | |
3268 | dom=_385.pop(); | |
3269 | if(typeof (dom)=="string"){ | |
3270 | lst.push(dom); | |
3271 | }else{ | |
3272 | if(dom.nodeType==1){ | |
3273 | lst.push("<"+dom.tagName.toLowerCase()); | |
3274 | var _389=[]; | |
3275 | var _38a=_388(dom); | |
3276 | for(var i=0;i<_38a.length;i++){ | |
3277 | var a=_38a[i]; | |
3278 | _389.push([" ",a.name,"=\"",_387(a.value),"\""]); | |
3279 | } | |
3280 | _389.sort(); | |
3281 | for(i=0;i<_389.length;i++){ | |
3282 | var _38d=_389[i]; | |
3283 | for(var j=0;j<_38d.length;j++){ | |
3284 | lst.push(_38d[j]); | |
3285 | } | |
3286 | } | |
3287 | if(dom.hasChildNodes()){ | |
3288 | lst.push(">"); | |
3289 | _385.push("</"+dom.tagName.toLowerCase()+">"); | |
3290 | var _38f=dom.childNodes; | |
3291 | for(i=_38f.length-1;i>=0;i--){ | |
3292 | _385.push(_38f[i]); | |
3293 | } | |
3294 | }else{ | |
3295 | lst.push("/>"); | |
3296 | } | |
3297 | }else{ | |
3298 | if(dom.nodeType==3){ | |
3299 | lst.push(_387(dom.nodeValue)); | |
3300 | } | |
3301 | } | |
3302 | } | |
3303 | } | |
3304 | return lst; | |
3305 | },scrapeText:function(node,_391){ | |
3306 | var rval=[]; | |
3307 | (function(node){ | |
3308 | var cn=node.childNodes; | |
3309 | if(cn){ | |
3310 | for(var i=0;i<cn.length;i++){ | |
3311 | arguments.callee.call(this,cn[i]); | |
3312 | } | |
3313 | } | |
3314 | var _396=node.nodeValue; | |
3315 | if(typeof (_396)=="string"){ | |
3316 | rval.push(_396); | |
3317 | } | |
3318 | })(MochiKit.DOM.getElement(node)); | |
3319 | if(_391){ | |
3320 | return rval; | |
3321 | }else{ | |
3322 | return rval.join(""); | |
3323 | } | |
3324 | },removeEmptyTextNodes:function(_397){ | |
3325 | _397=MochiKit.DOM.getElement(_397); | |
3326 | for(var i=0;i<_397.childNodes.length;i++){ | |
3327 | var node=_397.childNodes[i]; | |
3328 | if(node.nodeType==3&&!/\S/.test(node.nodeValue)){ | |
3329 | node.parentNode.removeChild(node); | |
3330 | } | |
3331 | } | |
3332 | },makeClipping:function(_39a){ | |
3333 | _39a=MochiKit.DOM.getElement(_39a); | |
3334 | var _39b=_39a.style.overflow; | |
3335 | if((MochiKit.Style.getStyle(_39a,"overflow")||"visible")!="hidden"){ | |
3336 | _39a.style.overflow="hidden"; | |
3337 | } | |
3338 | return _39b; | |
3339 | },undoClipping:function(_39c,_39d){ | |
3340 | _39c=MochiKit.DOM.getElement(_39c); | |
3341 | if(!_39d){ | |
3342 | return; | |
3343 | } | |
3344 | _39c.style.overflow=_39d; | |
3345 | },makePositioned:function(_39e){ | |
3346 | _39e=MochiKit.DOM.getElement(_39e); | |
3347 | var pos=MochiKit.Style.getStyle(_39e,"position"); | |
3348 | if(pos=="static"||!pos){ | |
3349 | _39e.style.position="relative"; | |
3350 | if(/Opera/.test(navigator.userAgent)){ | |
3351 | _39e.style.top=0; | |
3352 | _39e.style.left=0; | |
3353 | } | |
3354 | } | |
3355 | },undoPositioned:function(_3a0){ | |
3356 | _3a0=MochiKit.DOM.getElement(_3a0); | |
3357 | if(_3a0.style.position=="relative"){ | |
3358 | _3a0.style.position=_3a0.style.top=_3a0.style.left=_3a0.style.bottom=_3a0.style.right=""; | |
3359 | } | |
3360 | },getFirstElementByTagAndClassName:function(_3a1,_3a2,_3a3){ | |
3361 | var self=MochiKit.DOM; | |
3362 | if(typeof (_3a1)=="undefined"||_3a1===null){ | |
3363 | _3a1="*"; | |
3364 | } | |
3365 | if(typeof (_3a3)=="undefined"||_3a3===null){ | |
3366 | _3a3=self._document; | |
3367 | } | |
3368 | _3a3=self.getElement(_3a3); | |
3369 | var _3a5=(_3a3.getElementsByTagName(_3a1)||self._document.all); | |
3370 | if(typeof (_3a2)=="undefined"||_3a2===null){ | |
3371 | return _3a5[0]; | |
3372 | } | |
3373 | for(var i=0;i<_3a5.length;i++){ | |
3374 | var _3a7=_3a5[i]; | |
3375 | var _3a8=_3a7.className.split(" "); | |
3376 | for(var j=0;j<_3a8.length;j++){ | |
3377 | if(_3a8[j]==_3a2){ | |
3378 | return _3a7; | |
3379 | } | |
3380 | } | |
3381 | } | |
3382 | },getFirstParentByTagAndClassName:function(elem,_3ab,_3ac){ | |
3383 | var self=MochiKit.DOM; | |
3384 | elem=self.getElement(elem); | |
3385 | if(typeof (_3ab)=="undefined"||_3ab===null){ | |
3386 | _3ab="*"; | |
3387 | }else{ | |
3388 | _3ab=_3ab.toUpperCase(); | |
3389 | } | |
3390 | if(typeof (_3ac)=="undefined"||_3ac===null){ | |
3391 | _3ac=null; | |
3392 | } | |
3393 | var _3ae=""; | |
3394 | var _3af=""; | |
3395 | while(elem&&elem.tagName){ | |
3396 | elem=elem.parentNode; | |
3397 | if(_3ab=="*"&&_3ac===null){ | |
3398 | return elem; | |
3399 | } | |
3400 | _3ae=elem.className.split(" "); | |
3401 | _3af=elem.tagName.toUpperCase(); | |
3402 | if(_3ac===null&&_3ab==_3af){ | |
3403 | return elem; | |
3404 | }else{ | |
3405 | if(_3ac!==null){ | |
3406 | for(var i=0;i<_3ae.length;i++){ | |
3407 | if(_3ab=="*"&&_3ae[i]==_3ac){ | |
3408 | return elem; | |
3409 | }else{ | |
3410 | if(_3ab==_3af&&_3ae[i]==_3ac){ | |
3411 | return elem; | |
3412 | } | |
3413 | } | |
3414 | } | |
3415 | } | |
3416 | } | |
3417 | } | |
3418 | return elem; | |
3419 | },isParent:function(_3b1,_3b2){ | |
3420 | if(!_3b1.parentNode||_3b1==_3b2){ | |
3421 | return false; | |
3422 | } | |
3423 | if(_3b1.parentNode==_3b2){ | |
3424 | return true; | |
3425 | } | |
3426 | return MochiKit.DOM.isParent(_3b1.parentNode,_3b2); | |
3427 | },__new__:function(win){ | |
3428 | var m=MochiKit.Base; | |
3429 | if(typeof (document)!="undefined"){ | |
3430 | this._document=document; | |
3431 | var _3b5="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; | |
3432 | this._xhtml=(document.documentElement&&document.createElementNS&&document.documentElement.namespaceURI===_3b5); | |
3433 | }else{ | |
3434 | if(MochiKit.MockDOM){ | |
3435 | this._document=MochiKit.MockDOM.document; | |
3436 | } | |
3437 | } | |
3438 | this._window=win; | |
3439 | this.domConverters=new m.AdapterRegistry(); | |
3440 | var _3b6=this._document.createElement("span"); | |
3441 | var _3b7; | |
3442 | if(_3b6&&_3b6.attributes&&_3b6.attributes.length>0){ | |
3443 | var _3b8=m.filter; | |
3444 | _3b7=function(node){ | |
3445 | return _3b8(_3b7.ignoreAttrFilter,node.attributes); | |
3446 | }; | |
3447 | _3b7.ignoreAttr={}; | |
3448 | var _3ba=_3b6.attributes; | |
3449 | var _3bb=_3b7.ignoreAttr; | |
3450 | for(var i=0;i<_3ba.length;i++){ | |
3451 | var a=_3ba[i]; | |
3452 | _3bb[a.name]=a.value; | |
3453 | } | |
3454 | _3b7.ignoreAttrFilter=function(a){ | |
3455 | return (_3b7.ignoreAttr[a.name]!=a.value); | |
3456 | }; | |
3457 | _3b7.compliant=false; | |
3458 | _3b7.renames={"class":"className","checked":"defaultChecked","usemap":"useMap","for":"htmlFor","readonly":"readOnly","colspan":"colSpan","bgcolor":"bgColor","cellspacing":"cellSpacing","cellpadding":"cellPadding"}; | |
3459 | }else{ | |
3460 | _3b7=function(node){ | |
3461 | return node.attributes; | |
3462 | }; | |
3463 | _3b7.compliant=true; | |
3464 | _3b7.renames={}; | |
3465 | } | |
3466 | this.attributeArray=_3b7; | |
3467 | var _3c0=function(_3c1,arr){ | |
3468 | var _3c3=arr[1].split("."); | |
3469 | var str=""; | |
3470 | var obj={}; | |
3471 | str+="if (!MochiKit."+_3c3[1]+") { throw new Error(\""; | |
3472 | str+="This function has been deprecated and depends on MochiKit."; | |
3473 | str+=_3c3[1]+".\");}"; | |
3474 | str+="return MochiKit."+_3c3[1]+"."+arr[0]; | |
3475 | str+=".apply(this, arguments);"; | |
3476 | obj[_3c3[2]]=new Function(str); | |
3477 | MochiKit.Base.update(MochiKit[_3c1],obj); | |
3478 | }; | |
3479 | for(var i;i<MochiKit.DOM.DEPRECATED.length;i++){ | |
3480 | _3c0("DOM",MochiKit.DOM.DEPRECATED[i]); | |
3481 | } | |
3482 | var _3c6=this.createDOMFunc; | |
3483 | this.UL=_3c6("ul"); | |
3484 | this.OL=_3c6("ol"); | |
3485 | this.LI=_3c6("li"); | |
3486 | this.TD=_3c6("td"); | |
3487 | this.TR=_3c6("tr"); | |
3488 | this.TBODY=_3c6("tbody"); | |
3489 | this.THEAD=_3c6("thead"); | |
3490 | this.TFOOT=_3c6("tfoot"); | |
3491 | this.TABLE=_3c6("table"); | |
3492 | this.TH=_3c6("th"); | |
3493 | this.INPUT=_3c6("input"); | |
3494 | this.SPAN=_3c6("span"); | |
3495 | this.A=_3c6("a"); | |
3496 | this.DIV=_3c6("div"); | |
3497 | this.IMG=_3c6("img"); | |
3498 | this.BUTTON=_3c6("button"); | |
3499 | this.TT=_3c6("tt"); | |
3500 | this.PRE=_3c6("pre"); | |
3501 | this.H1=_3c6("h1"); | |
3502 | this.H2=_3c6("h2"); | |
3503 | this.H3=_3c6("h3"); | |
3504 | this.BR=_3c6("br"); | |
3505 | this.HR=_3c6("hr"); | |
3506 | this.LABEL=_3c6("label"); | |
3507 | this.TEXTAREA=_3c6("textarea"); | |
3508 | this.FORM=_3c6("form"); | |
3509 | this.P=_3c6("p"); | |
3510 | this.SELECT=_3c6("select"); | |
3511 | this.OPTION=_3c6("option"); | |
3512 | this.OPTGROUP=_3c6("optgroup"); | |
3513 | this.LEGEND=_3c6("legend"); | |
3514 | this.FIELDSET=_3c6("fieldset"); | |
3515 | this.STRONG=_3c6("strong"); | |
3516 | this.CANVAS=_3c6("canvas"); | |
3517 | this.$=this.getElement; | |
3518 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
3519 | m.nameFunctions(this); | |
3520 | }}); | |
3521 | MochiKit.DOM.__new__(((typeof (window)=="undefined")?this:window)); | |
3522 | if(MochiKit.__export__){ | |
3523 | withWindow=MochiKit.DOM.withWindow; | |
3524 | withDocument=MochiKit.DOM.withDocument; | |
3525 | } | |
3526 | MochiKit.Base._exportSymbols(this,MochiKit.DOM); | |
3527 | if(typeof (dojo)!="undefined"){ | |
3528 | dojo.provide("MochiKit.Selector"); | |
3529 | dojo.require("MochiKit.Base"); | |
3530 | dojo.require("MochiKit.DOM"); | |
3531 | dojo.require("MochiKit.Iter"); | |
3532 | } | |
3533 | if(typeof (JSAN)!="undefined"){ | |
3534 | JSAN.use("MochiKit.Base",[]); | |
3535 | JSAN.use("MochiKit.DOM",[]); | |
3536 | JSAN.use("MochiKit.Iter",[]); | |
3537 | } | |
3538 | try{ | |
3539 | if(typeof (MochiKit.Base)==="undefined"||typeof (MochiKit.DOM)==="undefined"||typeof (MochiKit.Iter)==="undefined"){ | |
3540 | throw ""; | |
3541 | } | |
3542 | } | |
3543 | catch(e){ | |
3544 | throw "MochiKit.Selector depends on MochiKit.Base, MochiKit.DOM and MochiKit.Iter!"; | |
3545 | } | |
3546 | if(typeof (MochiKit.Selector)=="undefined"){ | |
3547 | MochiKit.Selector={}; | |
3548 | } | |
3549 | MochiKit.Selector.NAME="MochiKit.Selector"; | |
3550 | MochiKit.Selector.VERSION="1.4"; | |
3551 | MochiKit.Selector.__repr__=function(){ | |
3552 | return "["+this.NAME+" "+this.VERSION+"]"; | |
3553 | }; | |
3554 | MochiKit.Selector.toString=function(){ | |
3555 | return this.__repr__(); | |
3556 | }; | |
3557 | MochiKit.Selector.EXPORT=["Selector","findChildElements","findDocElements","$$"]; | |
3558 | MochiKit.Selector.EXPORT_OK=[]; | |
3559 | MochiKit.Selector.Selector=function(_3c7){ | |
3560 | this.params={classNames:[],pseudoClassNames:[]}; | |
3561 | this.expression=_3c7.toString().replace(/(^\s+|\s+$)/g,""); | |
3562 | this.parseExpression(); | |
3563 | this.compileMatcher(); | |
3564 | }; | |
3565 | MochiKit.Selector.Selector.prototype={__class__:MochiKit.Selector.Selector,parseExpression:function(){ | |
3566 | function abort(_3c8){ | |
3567 | throw "Parse error in selector: "+_3c8; | |
3568 | } | |
3569 | if(this.expression==""){ | |
3570 | abort("empty expression"); | |
3571 | } | |
3572 | var repr=MochiKit.Base.repr; | |
3573 | var _3ca=this.params; | |
3574 | var expr=this.expression; | |
3575 | var _3cc,_3cd,_3ce,rest; | |
3576 | while(_3cc=expr.match(/^(.*)\[([a-z0-9_:-]+?)(?:([~\|!^$*]?=)(?:"([^"]*)"|([^\]\s]*)))?\]$/i)){ | |
3577 | _3ca.attributes=_3ca.attributes||[]; | |
3578 | _3ca.attributes.push({name:_3cc[2],operator:_3cc[3],value:_3cc[4]||_3cc[5]||""}); | |
3579 | expr=_3cc[1]; | |
3580 | } | |
3581 | if(expr=="*"){ | |
3582 | return this.params.wildcard=true; | |
3583 | } | |
3584 | while(_3cc=expr.match(/^([^a-z0-9_-])?([a-z0-9_-]+(?:\([^)]*\))?)(.*)/i)){ | |
3585 | _3cd=_3cc[1]; | |
3586 | _3ce=_3cc[2]; | |
3587 | rest=_3cc[3]; | |
3588 | switch(_3cd){ | |
3589 | case "#": | |
3590 | _3ca.id=_3ce; | |
3591 | break; | |
3592 | case ".": | |
3593 | _3ca.classNames.push(_3ce); | |
3594 | break; | |
3595 | case ":": | |
3596 | _3ca.pseudoClassNames.push(_3ce); | |
3597 | break; | |
3598 | case "": | |
3599 | case undefined: | |
3600 | _3ca.tagName=_3ce.toUpperCase(); | |
3601 | break; | |
3602 | default: | |
3603 | abort(repr(expr)); | |
3604 | } | |
3605 | expr=rest; | |
3606 | } | |
3607 | if(expr.length>0){ | |
3608 | abort(repr(expr)); | |
3609 | } | |
3610 | },buildMatchExpression:function(){ | |
3611 | var repr=MochiKit.Base.repr; | |
3612 | var _3d1=this.params; | |
3613 | var _3d2=[]; | |
3614 | var _3d3,i; | |
3615 | function childElements(_3d5){ | |
3616 | return "MochiKit.Base.filter(function (node) { return node.nodeType == 1; }, "+_3d5+".childNodes)"; | |
3617 | } | |
3618 | if(_3d1.wildcard){ | |
3619 | _3d2.push("true"); | |
3620 | } | |
3621 | if(_3d3=_3d1.id){ | |
3622 | _3d2.push("element.id == "+repr(_3d3)); | |
3623 | } | |
3624 | if(_3d3=_3d1.tagName){ | |
3625 | _3d2.push("element.tagName.toUpperCase() == "+repr(_3d3)); | |
3626 | } | |
3627 | if((_3d3=_3d1.classNames).length>0){ | |
3628 | for(i=0;i<_3d3.length;i++){ | |
3629 | _3d2.push("MochiKit.DOM.hasElementClass(element, "+repr(_3d3[i])+")"); | |
3630 | } | |
3631 | } | |
3632 | if((_3d3=_3d1.pseudoClassNames).length>0){ | |
3633 | for(i=0;i<_3d3.length;i++){ | |
3634 | var _3d6=_3d3[i].match(/^([^(]+)(?:\((.*)\))?$/); | |
3635 | var _3d7=_3d6[1]; | |
3636 | var _3d8=_3d6[2]; | |
3637 | switch(_3d7){ | |
3638 | case "root": | |
3639 | _3d2.push("element.nodeType == 9 || element === element.ownerDocument.documentElement"); | |
3640 | break; | |
3641 | case "nth-child": | |
3642 | case "nth-last-child": | |
3643 | case "nth-of-type": | |
3644 | case "nth-last-of-type": | |
3645 | _3d6=_3d8.match(/^((?:(\d+)n\+)?(\d+)|odd|even)$/); | |
3646 | if(!_3d6){ | |
3647 | throw "Invalid argument to pseudo element nth-child: "+_3d8; | |
3648 | } | |
3649 | var a,b; | |
3650 | if(_3d6[0]=="odd"){ | |
3651 | a=2; | |
3652 | b=1; | |
3653 | }else{ | |
3654 | if(_3d6[0]=="even"){ | |
3655 | a=2; | |
3656 | b=0; | |
3657 | }else{ | |
3658 | a=_3d6[2]&&parseInt(_3d6)||null; | |
3659 | b=parseInt(_3d6[3]); | |
3660 | } | |
3661 | } | |
3662 | _3d2.push("this.nthChild(element,"+a+","+b+","+!!_3d7.match("^nth-last")+","+!!_3d7.match("of-type$")+")"); | |
3663 | break; | |
3664 | case "first-child": | |
3665 | _3d2.push("this.nthChild(element, null, 1)"); | |
3666 | break; | |
3667 | case "last-child": | |
3668 | _3d2.push("this.nthChild(element, null, 1, true)"); | |
3669 | break; | |
3670 | case "first-of-type": | |
3671 | _3d2.push("this.nthChild(element, null, 1, false, true)"); | |
3672 | break; | |
3673 | case "last-of-type": | |
3674 | _3d2.push("this.nthChild(element, null, 1, true, true)"); | |
3675 | break; | |
3676 | case "only-child": | |
3677 | _3d2.push(childElements("element.parentNode")+".length == 1"); | |
3678 | break; | |
3679 | case "only-of-type": | |
3680 | _3d2.push("MochiKit.Base.filter(function (node) { return node.tagName == element.tagName; }, "+childElements("element.parentNode")+").length == 1"); | |
3681 | break; | |
3682 | case "empty": | |
3683 | _3d2.push("element.childNodes.length == 0"); | |
3684 | break; | |
3685 | case "enabled": | |
3686 | _3d2.push("(this.isUIElement(element) && element.disabled === false)"); | |
3687 | break; | |
3688 | case "disabled": | |
3689 | _3d2.push("(this.isUIElement(element) && element.disabled === true)"); | |
3690 | break; | |
3691 | case "checked": | |
3692 | _3d2.push("(this.isUIElement(element) && element.checked === true)"); | |
3693 | break; | |
3694 | case "not": | |
3695 | var _3db=new MochiKit.Selector.Selector(_3d8); | |
3696 | _3d2.push("!( "+_3db.buildMatchExpression()+")"); | |
3697 | break; | |
3698 | } | |
3699 | } | |
3700 | } | |
3701 | if(_3d3=_3d1.attributes){ | |
3702 | MochiKit.Base.map(function(_3dc){ | |
3703 | var _3dd="MochiKit.DOM.getNodeAttribute(element, "+repr(_3dc.name)+")"; | |
3704 | var _3de=function(_3df){ | |
3705 | return _3dd+".split("+repr(_3df)+")"; | |
3706 | }; | |
3707 | switch(_3dc.operator){ | |
3708 | case "=": | |
3709 | _3d2.push(_3dd+" == "+repr(_3dc.value)); | |
3710 | break; | |
3711 | case "~=": | |
3712 | _3d2.push(_3dd+" && MochiKit.Base.findValue("+_3de(" ")+", "+repr(_3dc.value)+") > -1"); | |
3713 | break; | |
3714 | case "^=": | |
3715 | _3d2.push(_3dd+".substring(0, "+_3dc.value.length+") == "+repr(_3dc.value)); | |
3716 | break; | |
3717 | case "$=": | |
3718 | _3d2.push(_3dd+".substring("+_3dd+".length - "+_3dc.value.length+") == "+repr(_3dc.value)); | |
3719 | break; | |
3720 | case "*=": | |
3721 | _3d2.push(_3dd+".match("+repr(_3dc.value)+")"); | |
3722 | break; | |
3723 | case "|=": | |
3724 | _3d2.push(_3dd+" && "+_3de("-")+"[0].toUpperCase() == "+repr(_3dc.value.toUpperCase())); | |
3725 | break; | |
3726 | case "!=": | |
3727 | _3d2.push(_3dd+" != "+repr(_3dc.value)); | |
3728 | break; | |
3729 | case "": | |
3730 | case undefined: | |
3731 | _3d2.push(_3dd+" != null"); | |
3732 | break; | |
3733 | default: | |
3734 | throw "Unknown operator "+_3dc.operator+" in selector"; | |
3735 | } | |
3736 | },_3d3); | |
3737 | } | |
3738 | return _3d2.join(" && "); | |
3739 | },compileMatcher:function(){ | |
3740 | this.match=new Function("element","if (!element.tagName) return false; return "+this.buildMatchExpression()); | |
3741 | },nthChild:function(_3e0,a,b,_3e3,_3e4){ | |
3742 | var _3e5=MochiKit.Base.filter(function(node){ | |
3743 | return node.nodeType==1; | |
3744 | },_3e0.parentNode.childNodes); | |
3745 | if(_3e4){ | |
3746 | _3e5=MochiKit.Base.filter(function(node){ | |
3747 | return node.tagName==_3e0.tagName; | |
3748 | },_3e5); | |
3749 | } | |
3750 | if(_3e3){ | |
3751 | _3e5=MochiKit.Iter.reversed(_3e5); | |
3752 | } | |
3753 | if(a){ | |
3754 | var _3e8=MochiKit.Base.findIdentical(_3e5,_3e0); | |
3755 | return ((_3e8+1-b)/a)%1==0; | |
3756 | }else{ | |
3757 | return b==MochiKit.Base.findIdentical(_3e5,_3e0)+1; | |
3758 | } | |
3759 | },isUIElement:function(_3e9){ | |
3760 | return MochiKit.Base.findValue(["input","button","select","option","textarea","object"],_3e9.tagName.toLowerCase())>-1; | |
3761 | },findElements:function(_3ea,axis){ | |
3762 | var _3ec; | |
3763 | if(axis==undefined){ | |
3764 | axis=""; | |
3765 | } | |
3766 | function inScope(_3ed,_3ee){ | |
3767 | if(axis==""){ | |
3768 | return MochiKit.DOM.isChildNode(_3ed,_3ee); | |
3769 | }else{ | |
3770 | if(axis==">"){ | |
3771 | return _3ed.parentNode==_3ee; | |
3772 | }else{ | |
3773 | if(axis=="+"){ | |
3774 | return _3ed==nextSiblingElement(_3ee); | |
3775 | }else{ | |
3776 | if(axis=="~"){ | |
3777 | var _3ef=_3ee; | |
3778 | while(_3ef=nextSiblingElement(_3ef)){ | |
3779 | if(_3ed==_3ef){ | |
3780 | return true; | |
3781 | } | |
3782 | } | |
3783 | return false; | |
3784 | }else{ | |
3785 | throw "Invalid axis: "+axis; | |
3786 | } | |
3787 | } | |
3788 | } | |
3789 | } | |
3790 | } | |
3791 | if(_3ec=MochiKit.DOM.getElement(this.params.id)){ | |
3792 | if(this.match(_3ec)){ | |
3793 | if(!_3ea||inScope(_3ec,_3ea)){ | |
3794 | return [_3ec]; | |
3795 | } | |
3796 | } | |
3797 | } | |
3798 | function nextSiblingElement(node){ | |
3799 | node=node.nextSibling; | |
3800 | while(node&&node.nodeType!=1){ | |
3801 | node=node.nextSibling; | |
3802 | } | |
3803 | return node; | |
3804 | } | |
3805 | if(axis==""){ | |
3806 | _3ea=(_3ea||MochiKit.DOM.currentDocument()).getElementsByTagName(this.params.tagName||"*"); | |
3807 | }else{ | |
3808 | if(axis==">"){ | |
3809 | if(!_3ea){ | |
3810 | throw "> combinator not allowed without preceeding expression"; | |
3811 | } | |
3812 | _3ea=MochiKit.Base.filter(function(node){ | |
3813 | return node.nodeType==1; | |
3814 | },_3ea.childNodes); | |
3815 | }else{ | |
3816 | if(axis=="+"){ | |
3817 | if(!_3ea){ | |
3818 | throw "+ combinator not allowed without preceeding expression"; | |
3819 | } | |
3820 | _3ea=nextSiblingElement(_3ea)&&[nextSiblingElement(_3ea)]; | |
3821 | }else{ | |
3822 | if(axis=="~"){ | |
3823 | if(!_3ea){ | |
3824 | throw "~ combinator not allowed without preceeding expression"; | |
3825 | } | |
3826 | var _3f2=[]; | |
3827 | while(nextSiblingElement(_3ea)){ | |
3828 | _3ea=nextSiblingElement(_3ea); | |
3829 | _3f2.push(_3ea); | |
3830 | } | |
3831 | _3ea=_3f2; | |
3832 | } | |
3833 | } | |
3834 | } | |
3835 | } | |
3836 | if(!_3ea){ | |
3837 | return []; | |
3838 | } | |
3839 | var _3f3=MochiKit.Base.filter(MochiKit.Base.bind(function(_3f4){ | |
3840 | return this.match(_3f4); | |
3841 | },this),_3ea); | |
3842 | return _3f3; | |
3843 | },repr:function(){ | |
3844 | return "Selector("+this.expression+")"; | |
3845 | },toString:MochiKit.Base.forwardCall("repr")}; | |
3846 | MochiKit.Base.update(MochiKit.Selector,{findChildElements:function(_3f5,_3f6){ | |
3847 | return MochiKit.Base.flattenArray(MochiKit.Base.map(function(_3f7){ | |
3848 | var _3f8=""; | |
3849 | return MochiKit.Iter.reduce(function(_3f9,expr){ | |
3850 | if(match=expr.match(/^[>+~]$/)){ | |
3851 | _3f8=match[0]; | |
3852 | return _3f9; | |
3853 | }else{ | |
3854 | var _3fb=new MochiKit.Selector.Selector(expr); | |
3855 | var _3fc=MochiKit.Iter.reduce(function(_3fd,_3fe){ | |
3856 | return MochiKit.Base.extend(_3fd,_3fb.findElements(_3fe||_3f5,_3f8)); | |
3857 | },_3f9,[]); | |
3858 | _3f8=""; | |
3859 | return _3fc; | |
3860 | } | |
3861 | },_3f7.replace(/(^\s+|\s+$)/g,"").split(/\s+/),[null]); | |
3862 | },_3f6)); | |
3863 | },findDocElements:function(){ | |
3864 | return MochiKit.Selector.findChildElements(MochiKit.DOM.currentDocument(),arguments); | |
3865 | },__new__:function(){ | |
3866 | var m=MochiKit.Base; | |
3867 | this.$$=this.findDocElements; | |
3868 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
3869 | m.nameFunctions(this); | |
3870 | }}); | |
3871 | MochiKit.Selector.__new__(); | |
3872 | MochiKit.Base._exportSymbols(this,MochiKit.Selector); | |
3873 | if(typeof (dojo)!="undefined"){ | |
3874 | dojo.provide("MochiKit.Style"); | |
3875 | dojo.require("MochiKit.Base"); | |
3876 | dojo.require("MochiKit.DOM"); | |
3877 | } | |
3878 | if(typeof (JSAN)!="undefined"){ | |
3879 | JSAN.use("MochiKit.Base",[]); | |
3880 | JSAN.use("MochiKit.DOM",[]); | |
3881 | } | |
3882 | try{ | |
3883 | if(typeof (MochiKit.Base)=="undefined"){ | |
3884 | throw ""; | |
3885 | } | |
3886 | } | |
3887 | catch(e){ | |
3888 | throw "MochiKit.Style depends on MochiKit.Base!"; | |
3889 | } | |
3890 | try{ | |
3891 | if(typeof (MochiKit.DOM)=="undefined"){ | |
3892 | throw ""; | |
3893 | } | |
3894 | } | |
3895 | catch(e){ | |
3896 | throw "MochiKit.Style depends on MochiKit.DOM!"; | |
3897 | } | |
3898 | if(typeof (MochiKit.Style)=="undefined"){ | |
3899 | MochiKit.Style={}; | |
3900 | } | |
3901 | MochiKit.Style.NAME="MochiKit.Style"; | |
3902 | MochiKit.Style.VERSION="1.4"; | |
3903 | MochiKit.Style.__repr__=function(){ | |
3904 | return "["+this.NAME+" "+this.VERSION+"]"; | |
3905 | }; | |
3906 | MochiKit.Style.toString=function(){ | |
3907 | return this.__repr__(); | |
3908 | }; | |
3909 | MochiKit.Style.EXPORT_OK=[]; | |
3910 | MochiKit.Style.EXPORT=["setStyle","setOpacity","getStyle","getElementDimensions","elementDimensions","setElementDimensions","getElementPosition","elementPosition","setElementPosition","setDisplayForElement","hideElement","showElement","getViewportDimensions","getViewportPosition","Dimensions","Coordinates"]; | |
3911 | MochiKit.Style.Dimensions=function(w,h){ | |
3912 | this.w=w; | |
3913 | this.h=h; | |
3914 | }; | |
3915 | MochiKit.Style.Dimensions.prototype.__repr__=function(){ | |
3916 | var repr=MochiKit.Base.repr; | |
3917 | return "{w: "+repr(this.w)+", h: "+repr(this.h)+"}"; | |
3918 | }; | |
3919 | MochiKit.Style.Dimensions.prototype.toString=function(){ | |
3920 | return this.__repr__(); | |
3921 | }; | |
3922 | MochiKit.Style.Coordinates=function(x,y){ | |
3923 | this.x=x; | |
3924 | this.y=y; | |
3925 | }; | |
3926 | MochiKit.Style.Coordinates.prototype.__repr__=function(){ | |
3927 | var repr=MochiKit.Base.repr; | |
3928 | return "{x: "+repr(this.x)+", y: "+repr(this.y)+"}"; | |
3929 | }; | |
3930 | MochiKit.Style.Coordinates.prototype.toString=function(){ | |
3931 | return this.__repr__(); | |
3932 | }; | |
3933 | MochiKit.Base.update(MochiKit.Style,{getStyle:function(elem,_407){ | |
3934 | var dom=MochiKit.DOM; | |
3935 | var d=dom._document; | |
3936 | elem=dom.getElement(elem); | |
3937 | _407=MochiKit.Base.camelize(_407); | |
3938 | if(!elem||elem==d){ | |
3939 | return undefined; | |
3940 | } | |
3941 | if(_407=="opacity"&&elem.filters){ | |
3942 | var _40a=(MochiKit.Style.getStyle(elem,"filter")||"").match(/alpha\(opacity=(.*)\)/); | |
3943 | if(_40a&&_40a[1]){ | |
3944 | return parseFloat(_40a[1])/100; | |
3945 | } | |
3946 | return 1; | |
3947 | } | |
3948 | var _40b=elem.style?elem.style[_407]:null; | |
3949 | if(!_40b){ | |
3950 | if(d.defaultView&&d.defaultView.getComputedStyle){ | |
3951 | var css=d.defaultView.getComputedStyle(elem,null); | |
3952 | _407=_407.replace(/([A-Z])/g,"-$1").toLowerCase(); | |
3953 | _40b=css?css.getPropertyValue(_407):null; | |
3954 | }else{ | |
3955 | if(elem.currentStyle){ | |
3956 | _40b=elem.currentStyle[_407]; | |
3957 | } | |
3958 | } | |
3959 | } | |
3960 | if(_407=="opacity"){ | |
3961 | _40b=parseFloat(_40b); | |
3962 | } | |
3963 | if(/Opera/.test(navigator.userAgent)&&(MochiKit.Base.find(["left","top","right","bottom"],_407)!=-1)){ | |
3964 | if(MochiKit.Style.getStyle(elem,"position")=="static"){ | |
3965 | _40b="auto"; | |
3966 | } | |
3967 | } | |
3968 | return _40b=="auto"?null:_40b; | |
3969 | },setStyle:function(elem,_40e){ | |
3970 | elem=MochiKit.DOM.getElement(elem); | |
3971 | for(var name in _40e){ | |
3972 | if(name=="opacity"){ | |
3973 | MochiKit.Style.setOpacity(elem,_40e[name]); | |
3974 | }else{ | |
3975 | elem.style[MochiKit.Base.camelize(name)]=_40e[name]; | |
3976 | } | |
3977 | } | |
3978 | },setOpacity:function(elem,o){ | |
3979 | elem=MochiKit.DOM.getElement(elem); | |
3980 | var self=MochiKit.Style; | |
3981 | if(o==1){ | |
3982 | var _413=/Gecko/.test(navigator.userAgent)&&!(/Konqueror|AppleWebKit|KHTML/.test(navigator.userAgent)); | |
3983 | elem.style["opacity"]=_413?0.999999:1; | |
3984 | if(/MSIE/.test(navigator.userAgent)){ | |
3985 | elem.style["filter"]=self.getStyle(elem,"filter").replace(/alpha\([^\)]*\)/gi,""); | |
3986 | } | |
3987 | }else{ | |
3988 | if(o<0.00001){ | |
3989 | o=0; | |
3990 | } | |
3991 | elem.style["opacity"]=o; | |
3992 | if(/MSIE/.test(navigator.userAgent)){ | |
3993 | elem.style["filter"]=self.getStyle(elem,"filter").replace(/alpha\([^\)]*\)/gi,"")+"alpha(opacity="+o*100+")"; | |
3994 | } | |
3995 | } | |
3996 | },getElementPosition:function(elem,_415){ | |
3997 | var self=MochiKit.Style; | |
3998 | var dom=MochiKit.DOM; | |
3999 | elem=dom.getElement(elem); | |
4000 | if(!elem||(!(elem.x&&elem.y)&&(!elem.parentNode===null||self.getStyle(elem,"display")=="none"))){ | |
4001 | return undefined; | |
4002 | } | |
4003 | var c=new self.Coordinates(0,0); | |
4004 | var box=null; | |
4005 | var _41a=null; | |
4006 | var d=MochiKit.DOM._document; | |
4007 | var de=d.documentElement; | |
4008 | var b=d.body; | |
4009 | if(!elem.parentNode&&elem.x&&elem.y){ | |
4010 | c.x+=elem.x||0; | |
4011 | c.y+=elem.y||0; | |
4012 | }else{ | |
4013 | if(elem.getBoundingClientRect){ | |
4014 | box=elem.getBoundingClientRect(); | |
4015 | c.x+=box.left+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0); | |
4016 | c.y+=box.top+(de.scrollTop||b.scrollTop)-(de.clientTop||0); | |
4017 | }else{ | |
4018 | if(elem.offsetParent){ | |
4019 | c.x+=elem.offsetLeft; | |
4020 | c.y+=elem.offsetTop; | |
4021 | _41a=elem.offsetParent; | |
4022 | if(_41a!=elem){ | |
4023 | while(_41a){ | |
4024 | c.x+=_41a.offsetLeft; | |
4025 | c.y+=_41a.offsetTop; | |
4026 | _41a=_41a.offsetParent; | |
4027 | } | |
4028 | } | |
4029 | var ua=navigator.userAgent.toLowerCase(); | |
4030 | if((typeof (opera)!="undefined"&&parseFloat(opera.version())<9)||(ua.indexOf("AppleWebKit")!=-1&&self.getStyle(elem,"position")=="absolute")){ | |
4031 | c.x-=b.offsetLeft; | |
4032 | c.y-=b.offsetTop; | |
4033 | } | |
4034 | } | |
4035 | } | |
4036 | } | |
4037 | if(typeof (_415)!="undefined"){ | |
4038 | _415=arguments.callee(_415); | |
4039 | if(_415){ | |
4040 | c.x-=(_415.x||0); | |
4041 | c.y-=(_415.y||0); | |
4042 | } | |
4043 | } | |
4044 | if(elem.parentNode){ | |
4045 | _41a=elem.parentNode; | |
4046 | }else{ | |
4047 | _41a=null; | |
4048 | } | |
4049 | while(_41a){ | |
4050 | var _41f=_41a.tagName.toUpperCase(); | |
4051 | if(_41f==="BODY"||_41f==="HTML"){ | |
4052 | break; | |
4053 | } | |
4054 | var disp=self.getStyle(_41a,"display"); | |
4055 | if(disp!="inline"&&disp!="table-row"){ | |
4056 | c.x-=_41a.scrollLeft; | |
4057 | c.y-=_41a.scrollTop; | |
4058 | } | |
4059 | if(_41a.parentNode){ | |
4060 | _41a=_41a.parentNode; | |
4061 | }else{ | |
4062 | _41a=null; | |
4063 | } | |
4064 | } | |
4065 | return c; | |
4066 | },setElementPosition:function(elem,_422,_423){ | |
4067 | elem=MochiKit.DOM.getElement(elem); | |
4068 | if(typeof (_423)=="undefined"){ | |
4069 | _423="px"; | |
4070 | } | |
4071 | var _424={}; | |
4072 | var _425=MochiKit.Base.isUndefinedOrNull; | |
4073 | if(!_425(_422.x)){ | |
4074 | _424["left"]=_422.x+_423; | |
4075 | } | |
4076 | if(!_425(_422.y)){ | |
4077 | _424["top"]=_422.y+_423; | |
4078 | } | |
4079 | MochiKit.DOM.updateNodeAttributes(elem,{"style":_424}); | |
4080 | },getElementDimensions:function(elem){ | |
4081 | var self=MochiKit.Style; | |
4082 | var dom=MochiKit.DOM; | |
4083 | if(typeof (elem.w)=="number"||typeof (elem.h)=="number"){ | |
4084 | return new self.Dimensions(elem.w||0,elem.h||0); | |
4085 | } | |
4086 | elem=dom.getElement(elem); | |
4087 | if(!elem){ | |
4088 | return undefined; | |
4089 | } | |
4090 | var disp=self.getStyle(elem,"display"); | |
4091 | if(disp!="none"&&disp!==""&&typeof (disp)!="undefined"){ | |
4092 | return new self.Dimensions(elem.offsetWidth||0,elem.offsetHeight||0); | |
4093 | } | |
4094 | var s=elem.style; | |
4095 | var _42b=s.visibility; | |
4096 | var _42c=s.position; | |
4097 | s.visibility="hidden"; | |
4098 | s.position="absolute"; | |
4099 | s.display=""; | |
4100 | var _42d=elem.offsetWidth; | |
4101 | var _42e=elem.offsetHeight; | |
4102 | s.display="none"; | |
4103 | s.position=_42c; | |
4104 | s.visibility=_42b; | |
4105 | return new self.Dimensions(_42d,_42e); | |
4106 | },setElementDimensions:function(elem,_430,_431){ | |
4107 | elem=MochiKit.DOM.getElement(elem); | |
4108 | if(typeof (_431)=="undefined"){ | |
4109 | _431="px"; | |
4110 | } | |
4111 | var _432={}; | |
4112 | var _433=MochiKit.Base.isUndefinedOrNull; | |
4113 | if(!_433(_430.w)){ | |
4114 | _432["width"]=_430.w+_431; | |
4115 | } | |
4116 | if(!_433(_430.h)){ | |
4117 | _432["height"]=_430.h+_431; | |
4118 | } | |
4119 | MochiKit.DOM.updateNodeAttributes(elem,{"style":_432}); | |
4120 | },setDisplayForElement:function(_434,_435){ | |
4121 | var _436=MochiKit.Base.extend(null,arguments,1); | |
4122 | var _437=MochiKit.DOM.getElement; | |
4123 | for(var i=0;i<_436.length;i++){ | |
4124 | _435=_437(_436[i]); | |
4125 | if(_435){ | |
4126 | _435.style.display=_434; | |
4127 | } | |
4128 | } | |
4129 | },getViewportDimensions:function(){ | |
4130 | var d=new MochiKit.Style.Dimensions(); | |
4131 | var w=MochiKit.DOM._window; | |
4132 | var b=MochiKit.DOM._document.body; | |
4133 | if(w.innerWidth){ | |
4134 | d.w=w.innerWidth; | |
4135 | d.h=w.innerHeight; | |
4136 | }else{ | |
4137 | if(b.parentElement.clientWidth){ | |
4138 | d.w=b.parentElement.clientWidth; | |
4139 | d.h=b.parentElement.clientHeight; | |
4140 | }else{ | |
4141 | if(b&&b.clientWidth){ | |
4142 | d.w=b.clientWidth; | |
4143 | d.h=b.clientHeight; | |
4144 | } | |
4145 | } | |
4146 | } | |
4147 | return d; | |
4148 | },getViewportPosition:function(){ | |
4149 | var c=new MochiKit.Style.Coordinates(0,0); | |
4150 | var d=MochiKit.DOM._document; | |
4151 | var de=d.documentElement; | |
4152 | var db=d.body; | |
4153 | if(de&&(de.scrollTop||de.scrollLeft)){ | |
4154 | c.x=de.scrollLeft; | |
4155 | c.y=de.scrollTop; | |
4156 | }else{ | |
4157 | if(db){ | |
4158 | c.x=db.scrollLeft; | |
4159 | c.y=db.scrollTop; | |
4160 | } | |
4161 | } | |
4162 | return c; | |
4163 | },__new__:function(){ | |
4164 | var m=MochiKit.Base; | |
4165 | this.elementPosition=this.getElementPosition; | |
4166 | this.elementDimensions=this.getElementDimensions; | |
4167 | this.hideElement=m.partial(this.setDisplayForElement,"none"); | |
4168 | this.showElement=m.partial(this.setDisplayForElement,"block"); | |
4169 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
4170 | m.nameFunctions(this); | |
4171 | }}); | |
4172 | MochiKit.Style.__new__(); | |
4173 | MochiKit.Base._exportSymbols(this,MochiKit.Style); | |
4174 | if(typeof (dojo)!="undefined"){ | |
4175 | dojo.provide("MochiKit.LoggingPane"); | |
4176 | dojo.require("MochiKit.Logging"); | |
4177 | dojo.require("MochiKit.Base"); | |
4178 | } | |
4179 | if(typeof (JSAN)!="undefined"){ | |
4180 | JSAN.use("MochiKit.Logging",[]); | |
4181 | JSAN.use("MochiKit.Base",[]); | |
4182 | } | |
4183 | try{ | |
4184 | if(typeof (MochiKit.Base)=="undefined"||typeof (MochiKit.Logging)=="undefined"){ | |
4185 | throw ""; | |
4186 | } | |
4187 | } | |
4188 | catch(e){ | |
4189 | throw "MochiKit.LoggingPane depends on MochiKit.Base and MochiKit.Logging!"; | |
4190 | } | |
4191 | if(typeof (MochiKit.LoggingPane)=="undefined"){ | |
4192 | MochiKit.LoggingPane={}; | |
4193 | } | |
4194 | MochiKit.LoggingPane.NAME="MochiKit.LoggingPane"; | |
4195 | MochiKit.LoggingPane.VERSION="1.4"; | |
4196 | MochiKit.LoggingPane.__repr__=function(){ | |
4197 | return "["+this.NAME+" "+this.VERSION+"]"; | |
4198 | }; | |
4199 | MochiKit.LoggingPane.toString=function(){ | |
4200 | return this.__repr__(); | |
4201 | }; | |
4202 | MochiKit.LoggingPane.createLoggingPane=function(_441){ | |
4203 | var m=MochiKit.LoggingPane; | |
4204 | _441=!(!_441); | |
4205 | if(m._loggingPane&&m._loggingPane.inline!=_441){ | |
4206 | m._loggingPane.closePane(); | |
4207 | m._loggingPane=null; | |
4208 | } | |
4209 | if(!m._loggingPane||m._loggingPane.closed){ | |
4210 | m._loggingPane=new m.LoggingPane(_441,MochiKit.Logging.logger); | |
4211 | } | |
4212 | return m._loggingPane; | |
4213 | }; | |
4214 | MochiKit.LoggingPane.LoggingPane=function(_443,_444){ | |
4215 | if(typeof (_444)=="undefined"||_444===null){ | |
4216 | _444=MochiKit.Logging.logger; | |
4217 | } | |
4218 | this.logger=_444; | |
4219 | var _445=MochiKit.Base.update; | |
4220 | var _446=MochiKit.Base.updatetree; | |
4221 | var bind=MochiKit.Base.bind; | |
4222 | var _448=MochiKit.Base.clone; | |
4223 | var win=window; | |
4224 | var uid="_MochiKit_LoggingPane"; | |
4225 | if(typeof (MochiKit.DOM)!="undefined"){ | |
4226 | win=MochiKit.DOM.currentWindow(); | |
4227 | } | |
4228 | if(!_443){ | |
4229 | var url=win.location.href.split("?")[0].replace(/[#:\/.><&-]/g,"_"); | |
4230 | var name=uid+"_"+url; | |
4231 | var nwin=win.open("",name,"dependent,resizable,height=200"); | |
4232 | if(!nwin){ | |
4233 | alert("Not able to open debugging window due to pop-up blocking."); | |
4234 | return undefined; | |
4235 | } | |
4236 | nwin.document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" "+"\"http://www.w3.org/TR/html4/loose.dtd\">"+"<html><head><title>[MochiKit.LoggingPane]</title></head>"+"<body></body></html>"); | |
4237 | nwin.document.close(); | |
4238 | nwin.document.title+=" "+win.document.title; | |
4239 | win=nwin; | |
4240 | } | |
4241 | var doc=win.document; | |
4242 | this.doc=doc; | |
4243 | var _44f=doc.getElementById(uid); | |
4244 | var _450=!!_44f; | |
4245 | if(_44f&&typeof (_44f.loggingPane)!="undefined"){ | |
4246 | _44f.loggingPane.logger=this.logger; | |
4247 | _44f.loggingPane.buildAndApplyFilter(); | |
4248 | return _44f.loggingPane; | |
4249 | } | |
4250 | if(_450){ | |
4251 | var _451; | |
4252 | while((_451=_44f.firstChild)){ | |
4253 | _44f.removeChild(_451); | |
4254 | } | |
4255 | }else{ | |
4256 | _44f=doc.createElement("div"); | |
4257 | _44f.id=uid; | |
4258 | } | |
4259 | _44f.loggingPane=this; | |
4260 | var _452=doc.createElement("input"); | |
4261 | var _453=doc.createElement("input"); | |
4262 | var _454=doc.createElement("button"); | |
4263 | var _455=doc.createElement("button"); | |
4264 | var _456=doc.createElement("button"); | |
4265 | var _457=doc.createElement("button"); | |
4266 | var _458=doc.createElement("div"); | |
4267 | var _459=doc.createElement("div"); | |
4268 | var _45a=uid+"_Listener"; | |
4269 | this.colorTable=_448(this.colorTable); | |
4270 | var _45b=[]; | |
4271 | var _45c=null; | |
4272 | var _45d=function(msg){ | |
4273 | var _45f=msg.level; | |
4274 | if(typeof (_45f)=="number"){ | |
4275 | _45f=MochiKit.Logging.LogLevel[_45f]; | |
4276 | } | |
4277 | return _45f; | |
4278 | }; | |
4279 | var _460=function(msg){ | |
4280 | return msg.info.join(" "); | |
4281 | }; | |
4282 | var _462=bind(function(msg){ | |
4283 | var _464=_45d(msg); | |
4284 | var text=_460(msg); | |
4285 | var c=this.colorTable[_464]; | |
4286 | var p=doc.createElement("span"); | |
4287 | p.className="MochiKit-LogMessage MochiKit-LogLevel-"+_464; | |
4288 | p.style.cssText="margin: 0px; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; white-space: pre-line; word-wrap: break-word; wrap-option: emergency; color: "+c; | |
4289 | p.appendChild(doc.createTextNode(_464+": "+text)); | |
4290 | _459.appendChild(p); | |
4291 | _459.appendChild(doc.createElement("br")); | |
4292 | if(_458.offsetHeight>_458.scrollHeight){ | |
4293 | _458.scrollTop=0; | |
4294 | }else{ | |
4295 | _458.scrollTop=_458.scrollHeight; | |
4296 | } | |
4297 | },this); | |
4298 | var _468=function(msg){ | |
4299 | _45b[_45b.length]=msg; | |
4300 | _462(msg); | |
4301 | }; | |
4302 | var _46a=function(){ | |
4303 | var _46b,_46c; | |
4304 | try{ | |
4305 | _46b=new RegExp(_452.value); | |
4306 | _46c=new RegExp(_453.value); | |
4307 | } | |
4308 | catch(e){ | |
4309 | logDebug("Error in filter regex: "+e.message); | |
4310 | return null; | |
4311 | } | |
4312 | return function(msg){ | |
4313 | return (_46b.test(_45d(msg))&&_46c.test(_460(msg))); | |
4314 | }; | |
4315 | }; | |
4316 | var _46e=function(){ | |
4317 | while(_459.firstChild){ | |
4318 | _459.removeChild(_459.firstChild); | |
4319 | } | |
4320 | }; | |
4321 | var _46f=function(){ | |
4322 | _45b=[]; | |
4323 | _46e(); | |
4324 | }; | |
4325 | var _470=bind(function(){ | |
4326 | if(this.closed){ | |
4327 | return; | |
4328 | } | |
4329 | this.closed=true; | |
4330 | if(MochiKit.LoggingPane._loggingPane==this){ | |
4331 | MochiKit.LoggingPane._loggingPane=null; | |
4332 | } | |
4333 | this.logger.removeListener(_45a); | |
4334 | try{ | |
4335 | try{ | |
4336 | _44f.loggingPane=null; | |
4337 | } | |
4338 | catch(e){ | |
4339 | logFatal("Bookmarklet was closed incorrectly."); | |
4340 | } | |
4341 | if(_443){ | |
4342 | _44f.parentNode.removeChild(_44f); | |
4343 | }else{ | |
4344 | this.win.close(); | |
4345 | } | |
4346 | } | |
4347 | catch(e){ | |
4348 | } | |
4349 | },this); | |
4350 | var _471=function(){ | |
4351 | _46e(); | |
4352 | for(var i=0;i<_45b.length;i++){ | |
4353 | var msg=_45b[i]; | |
4354 | if(_45c===null||_45c(msg)){ | |
4355 | _462(msg); | |
4356 | } | |
4357 | } | |
4358 | }; | |
4359 | this.buildAndApplyFilter=function(){ | |
4360 | _45c=_46a(); | |
4361 | _471(); | |
4362 | this.logger.removeListener(_45a); | |
4363 | this.logger.addListener(_45a,_45c,_468); | |
4364 | }; | |
4365 | var _474=bind(function(){ | |
4366 | _45b=this.logger.getMessages(); | |
4367 | _471(); | |
4368 | },this); | |
4369 | var _475=bind(function(_476){ | |
4370 | _476=_476||window.event; | |
4371 | key=_476.which||_476.keyCode; | |
4372 | if(key==13){ | |
4373 | this.buildAndApplyFilter(); | |
4374 | } | |
4375 | },this); | |
4376 | var _477="display: block; z-index: 1000; left: 0px; bottom: 0px; position: fixed; width: 100%; background-color: white; font: "+this.logFont; | |
4377 | if(_443){ | |
4378 | _477+="; height: 10em; border-top: 2px solid black"; | |
4379 | }else{ | |
4380 | _477+="; height: 100%;"; | |
4381 | } | |
4382 | _44f.style.cssText=_477; | |
4383 | if(!_450){ | |
4384 | doc.body.appendChild(_44f); | |
4385 | } | |
4386 | _477={"cssText":"width: 33%; display: inline; font: "+this.logFont}; | |
4387 | _446(_452,{"value":"FATAL|ERROR|WARNING|INFO|DEBUG","onkeypress":_475,"style":_477}); | |
4388 | _44f.appendChild(_452); | |
4389 | _446(_453,{"value":".*","onkeypress":_475,"style":_477}); | |
4390 | _44f.appendChild(_453); | |
4391 | _477="width: 8%; display:inline; font: "+this.logFont; | |
4392 | _454.appendChild(doc.createTextNode("Filter")); | |
4393 | _454.onclick=bind("buildAndApplyFilter",this); | |
4394 | _454.style.cssText=_477; | |
4395 | _44f.appendChild(_454); | |
4396 | _455.appendChild(doc.createTextNode("Load")); | |
4397 | _455.onclick=_474; | |
4398 | _455.style.cssText=_477; | |
4399 | _44f.appendChild(_455); | |
4400 | _456.appendChild(doc.createTextNode("Clear")); | |
4401 | _456.onclick=_46f; | |
4402 | _456.style.cssText=_477; | |
4403 | _44f.appendChild(_456); | |
4404 | _457.appendChild(doc.createTextNode("Close")); | |
4405 | _457.onclick=_470; | |
4406 | _457.style.cssText=_477; | |
4407 | _44f.appendChild(_457); | |
4408 | _458.style.cssText="overflow: auto; width: 100%"; | |
4409 | _459.style.cssText="width: 100%; height: "+(_443?"8em":"100%"); | |
4410 | _458.appendChild(_459); | |
4411 | _44f.appendChild(_458); | |
4412 | this.buildAndApplyFilter(); | |
4413 | _474(); | |
4414 | if(_443){ | |
4415 | this.win=undefined; | |
4416 | }else{ | |
4417 | this.win=win; | |
4418 | } | |
4419 | this.inline=_443; | |
4420 | this.closePane=_470; | |
4421 | this.closed=false; | |
4422 | return this; | |
4423 | }; | |
4424 | MochiKit.LoggingPane.LoggingPane.prototype={"logFont":"8pt Verdana,sans-serif","colorTable":{"ERROR":"red","FATAL":"darkred","WARNING":"blue","INFO":"black","DEBUG":"green"}}; | |
4425 | MochiKit.LoggingPane.EXPORT_OK=["LoggingPane"]; | |
4426 | MochiKit.LoggingPane.EXPORT=["createLoggingPane"]; | |
4427 | MochiKit.LoggingPane.__new__=function(){ | |
4428 | this.EXPORT_TAGS={":common":this.EXPORT,":all":MochiKit.Base.concat(this.EXPORT,this.EXPORT_OK)}; | |
4429 | MochiKit.Base.nameFunctions(this); | |
4430 | MochiKit.LoggingPane._loggingPane=null; | |
4431 | }; | |
4432 | MochiKit.LoggingPane.__new__(); | |
4433 | MochiKit.Base._exportSymbols(this,MochiKit.LoggingPane); | |
4434 | if(typeof (dojo)!="undefined"){ | |
4435 | dojo.provide("MochiKit.Color"); | |
4436 | dojo.require("MochiKit.Base"); | |
4437 | dojo.require("MochiKit.DOM"); | |
4438 | dojo.require("MochiKit.Style"); | |
4439 | } | |
4440 | if(typeof (JSAN)!="undefined"){ | |
4441 | JSAN.use("MochiKit.Base",[]); | |
4442 | JSAN.use("MochiKit.DOM",[]); | |
4443 | JSAN.use("MochiKit.Style",[]); | |
4444 | } | |
4445 | try{ | |
4446 | if(typeof (MochiKit.Base)=="undefined"){ | |
4447 | throw ""; | |
4448 | } | |
4449 | } | |
4450 | catch(e){ | |
4451 | throw "MochiKit.Color depends on MochiKit.Base"; | |
4452 | } | |
4453 | try{ | |
4454 | if(typeof (MochiKit.DOM)=="undefined"){ | |
4455 | throw ""; | |
4456 | } | |
4457 | } | |
4458 | catch(e){ | |
4459 | throw "MochiKit.Color depends on MochiKit.DOM"; | |
4460 | } | |
4461 | try{ | |
4462 | if(typeof (MochiKit.Style)=="undefined"){ | |
4463 | throw ""; | |
4464 | } | |
4465 | } | |
4466 | catch(e){ | |
4467 | throw "MochiKit.Color depends on MochiKit.Style"; | |
4468 | } | |
4469 | if(typeof (MochiKit.Color)=="undefined"){ | |
4470 | MochiKit.Color={}; | |
4471 | } | |
4472 | MochiKit.Color.NAME="MochiKit.Color"; | |
4473 | MochiKit.Color.VERSION="1.4"; | |
4474 | MochiKit.Color.__repr__=function(){ | |
4475 | return "["+this.NAME+" "+this.VERSION+"]"; | |
4476 | }; | |
4477 | MochiKit.Color.toString=function(){ | |
4478 | return this.__repr__(); | |
4479 | }; | |
4480 | MochiKit.Color.Color=function(red,_479,blue,_47b){ | |
4481 | if(typeof (_47b)=="undefined"||_47b===null){ | |
4482 | _47b=1; | |
4483 | } | |
4484 | this.rgb={r:red,g:_479,b:blue,a:_47b}; | |
4485 | }; | |
4486 | MochiKit.Color.Color.prototype={__class__:MochiKit.Color.Color,colorWithAlpha:function(_47c){ | |
4487 | var rgb=this.rgb; | |
4488 | var m=MochiKit.Color; | |
4489 | return m.Color.fromRGB(rgb.r,rgb.g,rgb.b,_47c); | |
4490 | },colorWithHue:function(hue){ | |
4491 | var hsl=this.asHSL(); | |
4492 | hsl.h=hue; | |
4493 | var m=MochiKit.Color; | |
4494 | return m.Color.fromHSL(hsl); | |
4495 | },colorWithSaturation:function(_482){ | |
4496 | var hsl=this.asHSL(); | |
4497 | hsl.s=_482; | |
4498 | var m=MochiKit.Color; | |
4499 | return m.Color.fromHSL(hsl); | |
4500 | },colorWithLightness:function(_485){ | |
4501 | var hsl=this.asHSL(); | |
4502 | hsl.l=_485; | |
4503 | var m=MochiKit.Color; | |
4504 | return m.Color.fromHSL(hsl); | |
4505 | },darkerColorWithLevel:function(_488){ | |
4506 | var hsl=this.asHSL(); | |
4507 | hsl.l=Math.max(hsl.l-_488,0); | |
4508 | var m=MochiKit.Color; | |
4509 | return m.Color.fromHSL(hsl); | |
4510 | },lighterColorWithLevel:function(_48b){ | |
4511 | var hsl=this.asHSL(); | |
4512 | hsl.l=Math.min(hsl.l+_48b,1); | |
4513 | var m=MochiKit.Color; | |
4514 | return m.Color.fromHSL(hsl); | |
4515 | },blendedColor:function(_48e,_48f){ | |
4516 | if(typeof (_48f)=="undefined"||_48f===null){ | |
4517 | _48f=0.5; | |
4518 | } | |
4519 | var sf=1-_48f; | |
4520 | var s=this.rgb; | |
4521 | var d=_48e.rgb; | |
4522 | var df=_48f; | |
4523 | 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)); | |
4524 | },compareRGB:function(_494){ | |
4525 | var a=this.asRGB(); | |
4526 | var b=_494.asRGB(); | |
4527 | return MochiKit.Base.compare([a.r,a.g,a.b,a.a],[b.r,b.g,b.b,b.a]); | |
4528 | },isLight:function(){ | |
4529 | return this.asHSL().b>0.5; | |
4530 | },isDark:function(){ | |
4531 | return (!this.isLight()); | |
4532 | },toHSLString:function(){ | |
4533 | var c=this.asHSL(); | |
4534 | var ccc=MochiKit.Color.clampColorComponent; | |
4535 | var rval=this._hslString; | |
4536 | if(!rval){ | |
4537 | var mid=(ccc(c.h,360).toFixed(0)+","+ccc(c.s,100).toPrecision(4)+"%"+","+ccc(c.l,100).toPrecision(4)+"%"); | |
4538 | var a=c.a; | |
4539 | if(a>=1){ | |
4540 | a=1; | |
4541 | rval="hsl("+mid+")"; | |
4542 | }else{ | |
4543 | if(a<=0){ | |
4544 | a=0; | |
4545 | } | |
4546 | rval="hsla("+mid+","+a+")"; | |
4547 | } | |
4548 | this._hslString=rval; | |
4549 | } | |
4550 | return rval; | |
4551 | },toRGBString:function(){ | |
4552 | var c=this.rgb; | |
4553 | var ccc=MochiKit.Color.clampColorComponent; | |
4554 | var rval=this._rgbString; | |
4555 | if(!rval){ | |
4556 | var mid=(ccc(c.r,255).toFixed(0)+","+ccc(c.g,255).toFixed(0)+","+ccc(c.b,255).toFixed(0)); | |
4557 | if(c.a!=1){ | |
4558 | rval="rgba("+mid+","+c.a+")"; | |
4559 | }else{ | |
4560 | rval="rgb("+mid+")"; | |
4561 | } | |
4562 | this._rgbString=rval; | |
4563 | } | |
4564 | return rval; | |
4565 | },asRGB:function(){ | |
4566 | return MochiKit.Base.clone(this.rgb); | |
4567 | },toHexString:function(){ | |
4568 | var m=MochiKit.Color; | |
4569 | var c=this.rgb; | |
4570 | var ccc=MochiKit.Color.clampColorComponent; | |
4571 | var rval=this._hexString; | |
4572 | if(!rval){ | |
4573 | rval=("#"+m.toColorPart(ccc(c.r,255))+m.toColorPart(ccc(c.g,255))+m.toColorPart(ccc(c.b,255))); | |
4574 | this._hexString=rval; | |
4575 | } | |
4576 | return rval; | |
4577 | },asHSV:function(){ | |
4578 | var hsv=this.hsv; | |
4579 | var c=this.rgb; | |
4580 | if(typeof (hsv)=="undefined"||hsv===null){ | |
4581 | hsv=MochiKit.Color.rgbToHSV(this.rgb); | |
4582 | this.hsv=hsv; | |
4583 | } | |
4584 | return MochiKit.Base.clone(hsv); | |
4585 | },asHSL:function(){ | |
4586 | var hsl=this.hsl; | |
4587 | var c=this.rgb; | |
4588 | if(typeof (hsl)=="undefined"||hsl===null){ | |
4589 | hsl=MochiKit.Color.rgbToHSL(this.rgb); | |
4590 | this.hsl=hsl; | |
4591 | } | |
4592 | return MochiKit.Base.clone(hsl); | |
4593 | },toString:function(){ | |
4594 | return this.toRGBString(); | |
4595 | },repr:function(){ | |
4596 | var c=this.rgb; | |
4597 | var col=[c.r,c.g,c.b,c.a]; | |
4598 | return this.__class__.NAME+"("+col.join(", ")+")"; | |
4599 | }}; | |
4600 | MochiKit.Base.update(MochiKit.Color.Color,{fromRGB:function(red,_4ab,blue,_4ad){ | |
4601 | var _4ae=MochiKit.Color.Color; | |
4602 | if(arguments.length==1){ | |
4603 | var rgb=red; | |
4604 | red=rgb.r; | |
4605 | _4ab=rgb.g; | |
4606 | blue=rgb.b; | |
4607 | if(typeof (rgb.a)=="undefined"){ | |
4608 | _4ad=undefined; | |
4609 | }else{ | |
4610 | _4ad=rgb.a; | |
4611 | } | |
4612 | } | |
4613 | return new _4ae(red,_4ab,blue,_4ad); | |
4614 | },fromHSL:function(hue,_4b1,_4b2,_4b3){ | |
4615 | var m=MochiKit.Color; | |
4616 | return m.Color.fromRGB(m.hslToRGB.apply(m,arguments)); | |
4617 | },fromHSV:function(hue,_4b6,_4b7,_4b8){ | |
4618 | var m=MochiKit.Color; | |
4619 | return m.Color.fromRGB(m.hsvToRGB.apply(m,arguments)); | |
4620 | },fromName:function(name){ | |
4621 | var _4bb=MochiKit.Color.Color; | |
4622 | if(name.charAt(0)=="\""){ | |
4623 | name=name.substr(1,name.length-2); | |
4624 | } | |
4625 | var _4bc=_4bb._namedColors[name.toLowerCase()]; | |
4626 | if(typeof (_4bc)=="string"){ | |
4627 | return _4bb.fromHexString(_4bc); | |
4628 | }else{ | |
4629 | if(name=="transparent"){ | |
4630 | return _4bb.transparentColor(); | |
4631 | } | |
4632 | } | |
4633 | return null; | |
4634 | },fromString:function(_4bd){ | |
4635 | var self=MochiKit.Color.Color; | |
4636 | var _4bf=_4bd.substr(0,3); | |
4637 | if(_4bf=="rgb"){ | |
4638 | return self.fromRGBString(_4bd); | |
4639 | }else{ | |
4640 | if(_4bf=="hsl"){ | |
4641 | return self.fromHSLString(_4bd); | |
4642 | }else{ | |
4643 | if(_4bd.charAt(0)=="#"){ | |
4644 | return self.fromHexString(_4bd); | |
4645 | } | |
4646 | } | |
4647 | } | |
4648 | return self.fromName(_4bd); | |
4649 | },fromHexString:function(_4c0){ | |
4650 | if(_4c0.charAt(0)=="#"){ | |
4651 | _4c0=_4c0.substring(1); | |
4652 | } | |
4653 | var _4c1=[]; | |
4654 | var i,hex; | |
4655 | if(_4c0.length==3){ | |
4656 | for(i=0;i<3;i++){ | |
4657 | hex=_4c0.substr(i,1); | |
4658 | _4c1.push(parseInt(hex+hex,16)/255); | |
4659 | } | |
4660 | }else{ | |
4661 | for(i=0;i<6;i+=2){ | |
4662 | hex=_4c0.substr(i,2); | |
4663 | _4c1.push(parseInt(hex,16)/255); | |
4664 | } | |
4665 | } | |
4666 | var _4c4=MochiKit.Color.Color; | |
4667 | return _4c4.fromRGB.apply(_4c4,_4c1); | |
4668 | },_fromColorString:function(pre,_4c6,_4c7,_4c8){ | |
4669 | if(_4c8.indexOf(pre)===0){ | |
4670 | _4c8=_4c8.substring(_4c8.indexOf("(",3)+1,_4c8.length-1); | |
4671 | } | |
4672 | var _4c9=_4c8.split(/\s*,\s*/); | |
4673 | var _4ca=[]; | |
4674 | for(var i=0;i<_4c9.length;i++){ | |
4675 | var c=_4c9[i]; | |
4676 | var val; | |
4677 | var _4ce=c.substring(c.length-3); | |
4678 | if(c.charAt(c.length-1)=="%"){ | |
4679 | val=0.01*parseFloat(c.substring(0,c.length-1)); | |
4680 | }else{ | |
4681 | if(_4ce=="deg"){ | |
4682 | val=parseFloat(c)/360; | |
4683 | }else{ | |
4684 | if(_4ce=="rad"){ | |
4685 | val=parseFloat(c)/(Math.PI*2); | |
4686 | }else{ | |
4687 | val=_4c7[i]*parseFloat(c); | |
4688 | } | |
4689 | } | |
4690 | } | |
4691 | _4ca.push(val); | |
4692 | } | |
4693 | return this[_4c6].apply(this,_4ca); | |
4694 | },fromComputedStyle:function(elem,_4d0){ | |
4695 | var d=MochiKit.DOM; | |
4696 | var cls=MochiKit.Color.Color; | |
4697 | for(elem=d.getElement(elem);elem;elem=elem.parentNode){ | |
4698 | var _4d3=MochiKit.Style.getStyle.apply(d,arguments); | |
4699 | if(!_4d3){ | |
4700 | continue; | |
4701 | } | |
4702 | var _4d4=cls.fromString(_4d3); | |
4703 | if(!_4d4){ | |
4704 | break; | |
4705 | } | |
4706 | if(_4d4.asRGB().a>0){ | |
4707 | return _4d4; | |
4708 | } | |
4709 | } | |
4710 | return null; | |
4711 | },fromBackground:function(elem){ | |
4712 | var cls=MochiKit.Color.Color; | |
4713 | return cls.fromComputedStyle(elem,"backgroundColor","background-color")||cls.whiteColor(); | |
4714 | },fromText:function(elem){ | |
4715 | var cls=MochiKit.Color.Color; | |
4716 | return cls.fromComputedStyle(elem,"color","color")||cls.blackColor(); | |
4717 | },namedColors:function(){ | |
4718 | return MochiKit.Base.clone(MochiKit.Color.Color._namedColors); | |
4719 | }}); | |
4720 | MochiKit.Base.update(MochiKit.Color,{clampColorComponent:function(v,_4da){ | |
4721 | v*=_4da; | |
4722 | if(v<0){ | |
4723 | return 0; | |
4724 | }else{ | |
4725 | if(v>_4da){ | |
4726 | return _4da; | |
4727 | }else{ | |
4728 | return v; | |
4729 | } | |
4730 | } | |
4731 | },_hslValue:function(n1,n2,hue){ | |
4732 | if(hue>6){ | |
4733 | hue-=6; | |
4734 | }else{ | |
4735 | if(hue<0){ | |
4736 | hue+=6; | |
4737 | } | |
4738 | } | |
4739 | var val; | |
4740 | if(hue<1){ | |
4741 | val=n1+(n2-n1)*hue; | |
4742 | }else{ | |
4743 | if(hue<3){ | |
4744 | val=n2; | |
4745 | }else{ | |
4746 | if(hue<4){ | |
4747 | val=n1+(n2-n1)*(4-hue); | |
4748 | }else{ | |
4749 | val=n1; | |
4750 | } | |
4751 | } | |
4752 | } | |
4753 | return val; | |
4754 | },hsvToRGB:function(hue,_4e0,_4e1,_4e2){ | |
4755 | if(arguments.length==1){ | |
4756 | var hsv=hue; | |
4757 | hue=hsv.h; | |
4758 | _4e0=hsv.s; | |
4759 | _4e1=hsv.v; | |
4760 | _4e2=hsv.a; | |
4761 | } | |
4762 | var red; | |
4763 | var _4e5; | |
4764 | var blue; | |
4765 | if(_4e0===0){ | |
4766 | red=_4e1; | |
4767 | _4e5=_4e1; | |
4768 | blue=_4e1; | |
4769 | }else{ | |
4770 | var i=Math.floor(hue*6); | |
4771 | var f=(hue*6)-i; | |
4772 | var p=_4e1*(1-_4e0); | |
4773 | var q=_4e1*(1-(_4e0*f)); | |
4774 | var t=_4e1*(1-(_4e0*(1-f))); | |
4775 | switch(i){ | |
4776 | case 1: | |
4777 | red=q; | |
4778 | _4e5=_4e1; | |
4779 | blue=p; | |
4780 | break; | |
4781 | case 2: | |
4782 | red=p; | |
4783 | _4e5=_4e1; | |
4784 | blue=t; | |
4785 | break; | |
4786 | case 3: | |
4787 | red=p; | |
4788 | _4e5=q; | |
4789 | blue=_4e1; | |
4790 | break; | |
4791 | case 4: | |
4792 | red=t; | |
4793 | _4e5=p; | |
4794 | blue=_4e1; | |
4795 | break; | |
4796 | case 5: | |
4797 | red=_4e1; | |
4798 | _4e5=p; | |
4799 | blue=q; | |
4800 | break; | |
4801 | case 6: | |
4802 | case 0: | |
4803 | red=_4e1; | |
4804 | _4e5=t; | |
4805 | blue=p; | |
4806 | break; | |
4807 | } | |
4808 | } | |
4809 | return {r:red,g:_4e5,b:blue,a:_4e2}; | |
4810 | },hslToRGB:function(hue,_4ed,_4ee,_4ef){ | |
4811 | if(arguments.length==1){ | |
4812 | var hsl=hue; | |
4813 | hue=hsl.h; | |
4814 | _4ed=hsl.s; | |
4815 | _4ee=hsl.l; | |
4816 | _4ef=hsl.a; | |
4817 | } | |
4818 | var red; | |
4819 | var _4f2; | |
4820 | var blue; | |
4821 | if(_4ed===0){ | |
4822 | red=_4ee; | |
4823 | _4f2=_4ee; | |
4824 | blue=_4ee; | |
4825 | }else{ | |
4826 | var m2; | |
4827 | if(_4ee<=0.5){ | |
4828 | m2=_4ee*(1+_4ed); | |
4829 | }else{ | |
4830 | m2=_4ee+_4ed-(_4ee*_4ed); | |
4831 | } | |
4832 | var m1=(2*_4ee)-m2; | |
4833 | var f=MochiKit.Color._hslValue; | |
4834 | var h6=hue*6; | |
4835 | red=f(m1,m2,h6+2); | |
4836 | _4f2=f(m1,m2,h6); | |
4837 | blue=f(m1,m2,h6-2); | |
4838 | } | |
4839 | return {r:red,g:_4f2,b:blue,a:_4ef}; | |
4840 | },rgbToHSV:function(red,_4f9,blue,_4fb){ | |
4841 | if(arguments.length==1){ | |
4842 | var rgb=red; | |
4843 | red=rgb.r; | |
4844 | _4f9=rgb.g; | |
4845 | blue=rgb.b; | |
4846 | _4fb=rgb.a; | |
4847 | } | |
4848 | var max=Math.max(Math.max(red,_4f9),blue); | |
4849 | var min=Math.min(Math.min(red,_4f9),blue); | |
4850 | var hue; | |
4851 | var _500; | |
4852 | var _501=max; | |
4853 | if(min==max){ | |
4854 | hue=0; | |
4855 | _500=0; | |
4856 | }else{ | |
4857 | var _502=(max-min); | |
4858 | _500=_502/max; | |
4859 | if(red==max){ | |
4860 | hue=(_4f9-blue)/_502; | |
4861 | }else{ | |
4862 | if(_4f9==max){ | |
4863 | hue=2+((blue-red)/_502); | |
4864 | }else{ | |
4865 | hue=4+((red-_4f9)/_502); | |
4866 | } | |
4867 | } | |
4868 | hue/=6; | |
4869 | if(hue<0){ | |
4870 | hue+=1; | |
4871 | } | |
4872 | if(hue>1){ | |
4873 | hue-=1; | |
4874 | } | |
4875 | } | |
4876 | return {h:hue,s:_500,v:_501,a:_4fb}; | |
4877 | },rgbToHSL:function(red,_504,blue,_506){ | |
4878 | if(arguments.length==1){ | |
4879 | var rgb=red; | |
4880 | red=rgb.r; | |
4881 | _504=rgb.g; | |
4882 | blue=rgb.b; | |
4883 | _506=rgb.a; | |
4884 | } | |
4885 | var max=Math.max(red,Math.max(_504,blue)); | |
4886 | var min=Math.min(red,Math.min(_504,blue)); | |
4887 | var hue; | |
4888 | var _50b; | |
4889 | var _50c=(max+min)/2; | |
4890 | var _50d=max-min; | |
4891 | if(_50d===0){ | |
4892 | hue=0; | |
4893 | _50b=0; | |
4894 | }else{ | |
4895 | if(_50c<=0.5){ | |
4896 | _50b=_50d/(max+min); | |
4897 | }else{ | |
4898 | _50b=_50d/(2-max-min); | |
4899 | } | |
4900 | if(red==max){ | |
4901 | hue=(_504-blue)/_50d; | |
4902 | }else{ | |
4903 | if(_504==max){ | |
4904 | hue=2+((blue-red)/_50d); | |
4905 | }else{ | |
4906 | hue=4+((red-_504)/_50d); | |
4907 | } | |
4908 | } | |
4909 | hue/=6; | |
4910 | if(hue<0){ | |
4911 | hue+=1; | |
4912 | } | |
4913 | if(hue>1){ | |
4914 | hue-=1; | |
4915 | } | |
4916 | } | |
4917 | return {h:hue,s:_50b,l:_50c,a:_506}; | |
4918 | },toColorPart:function(num){ | |
4919 | num=Math.round(num); | |
4920 | var _50f=num.toString(16); | |
4921 | if(num<16){ | |
4922 | return "0"+_50f; | |
4923 | } | |
4924 | return _50f; | |
4925 | },__new__:function(){ | |
4926 | var m=MochiKit.Base; | |
4927 | this.Color.fromRGBString=m.bind(this.Color._fromColorString,this.Color,"rgb","fromRGB",[1/255,1/255,1/255,1]); | |
4928 | this.Color.fromHSLString=m.bind(this.Color._fromColorString,this.Color,"hsl","fromHSL",[1/360,0.01,0.01,1]); | |
4929 | var _511=1/3; | |
4930 | var _512={black:[0,0,0],blue:[0,0,1],brown:[0.6,0.4,0.2],cyan:[0,1,1],darkGray:[_511,_511,_511],gray:[0.5,0.5,0.5],green:[0,1,0],lightGray:[2*_511,2*_511,2*_511],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]}; | |
4931 | var _513=function(name,r,g,b,a){ | |
4932 | var rval=this.fromRGB(r,g,b,a); | |
4933 | this[name]=function(){ | |
4934 | return rval; | |
4935 | }; | |
4936 | return rval; | |
4937 | }; | |
4938 | for(var k in _512){ | |
4939 | var name=k+"Color"; | |
4940 | var _51c=m.concat([_513,this.Color,name],_512[k]); | |
4941 | this.Color[name]=m.bind.apply(null,_51c); | |
4942 | } | |
4943 | var _51d=function(){ | |
4944 | for(var i=0;i<arguments.length;i++){ | |
4945 | if(!(arguments[i] instanceof Color)){ | |
4946 | return false; | |
4947 | } | |
4948 | } | |
4949 | return true; | |
4950 | }; | |
4951 | var _51f=function(a,b){ | |
4952 | return a.compareRGB(b); | |
4953 | }; | |
4954 | m.nameFunctions(this); | |
4955 | m.registerComparator(this.Color.NAME,_51d,_51f); | |
4956 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
4957 | }}); | |
4958 | MochiKit.Color.EXPORT=["Color"]; | |
4959 | MochiKit.Color.EXPORT_OK=["clampColorComponent","rgbToHSL","hslToRGB","rgbToHSV","hsvToRGB","toColorPart"]; | |
4960 | MochiKit.Color.__new__(); | |
4961 | MochiKit.Base._exportSymbols(this,MochiKit.Color); | |
4962 | 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"}; | |
4963 | if(typeof (dojo)!="undefined"){ | |
4964 | dojo.provide("MochiKit.Signal"); | |
4965 | dojo.require("MochiKit.Base"); | |
4966 | dojo.require("MochiKit.DOM"); | |
4967 | dojo.require("MochiKit.Style"); | |
4968 | } | |
4969 | if(typeof (JSAN)!="undefined"){ | |
4970 | JSAN.use("MochiKit.Base",[]); | |
4971 | JSAN.use("MochiKit.DOM",[]); | |
4972 | JSAN.use("MochiKit.Style",[]); | |
4973 | } | |
4974 | try{ | |
4975 | if(typeof (MochiKit.Base)=="undefined"){ | |
4976 | throw ""; | |
4977 | } | |
4978 | } | |
4979 | catch(e){ | |
4980 | throw "MochiKit.Signal depends on MochiKit.Base!"; | |
4981 | } | |
4982 | try{ | |
4983 | if(typeof (MochiKit.DOM)=="undefined"){ | |
4984 | throw ""; | |
4985 | } | |
4986 | } | |
4987 | catch(e){ | |
4988 | throw "MochiKit.Signal depends on MochiKit.DOM!"; | |
4989 | } | |
4990 | try{ | |
4991 | if(typeof (MochiKit.Style)=="undefined"){ | |
4992 | throw ""; | |
4993 | } | |
4994 | } | |
4995 | catch(e){ | |
4996 | throw "MochiKit.Signal depends on MochiKit.Style!"; | |
4997 | } | |
4998 | if(typeof (MochiKit.Signal)=="undefined"){ | |
4999 | MochiKit.Signal={}; | |
5000 | } | |
5001 | MochiKit.Signal.NAME="MochiKit.Signal"; | |
5002 | MochiKit.Signal.VERSION="1.4"; | |
5003 | MochiKit.Signal._observers=[]; | |
5004 | MochiKit.Signal.Event=function(src,e){ | |
5005 | this._event=e||window.event; | |
5006 | this._src=src; | |
5007 | }; | |
5008 | MochiKit.Base.update(MochiKit.Signal.Event.prototype,{__repr__:function(){ | |
5009 | var repr=MochiKit.Base.repr; | |
5010 | var str="{event(): "+repr(this.event())+", src(): "+repr(this.src())+", type(): "+repr(this.type())+", target(): "+repr(this.target()); | |
5011 | if(this.type()&&this.type().indexOf("key")===0||this.type().indexOf("mouse")===0||this.type().indexOf("click")!=-1||this.type()=="contextmenu"){ | |
5012 | 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)+"}"; | |
5013 | } | |
5014 | if(this.type()&&this.type().indexOf("key")===0){ | |
5015 | str+=", key(): {code: "+repr(this.key().code)+", string: "+repr(this.key().string)+"}"; | |
5016 | } | |
5017 | if(this.type()&&(this.type().indexOf("mouse")===0||this.type().indexOf("click")!=-1||this.type()=="contextmenu")){ | |
5018 | str+=", mouse(): {page: "+repr(this.mouse().page)+", client: "+repr(this.mouse().client); | |
5019 | if(this.type()!="mousemove"){ | |
5020 | str+=", button: {left: "+repr(this.mouse().button.left)+", middle: "+repr(this.mouse().button.middle)+", right: "+repr(this.mouse().button.right)+"}}"; | |
5021 | }else{ | |
5022 | str+="}"; | |
5023 | } | |
5024 | } | |
5025 | if(this.type()=="mouseover"||this.type()=="mouseout"){ | |
5026 | str+=", relatedTarget(): "+repr(this.relatedTarget()); | |
5027 | } | |
5028 | str+="}"; | |
5029 | return str; | |
5030 | },toString:function(){ | |
5031 | return this.__repr__(); | |
5032 | },src:function(){ | |
5033 | return this._src; | |
5034 | },event:function(){ | |
5035 | return this._event; | |
5036 | },type:function(){ | |
5037 | return this._event.type||undefined; | |
5038 | },target:function(){ | |
5039 | return this._event.target||this._event.srcElement; | |
5040 | },_relatedTarget:null,relatedTarget:function(){ | |
5041 | if(this._relatedTarget!==null){ | |
5042 | return this._relatedTarget; | |
5043 | } | |
5044 | var elem=null; | |
5045 | if(this.type()=="mouseover"){ | |
5046 | elem=(this._event.relatedTarget||this._event.fromElement); | |
5047 | }else{ | |
5048 | if(this.type()=="mouseout"){ | |
5049 | elem=(this._event.relatedTarget||this._event.toElement); | |
5050 | } | |
5051 | } | |
5052 | if(elem!==null){ | |
5053 | this._relatedTarget=elem; | |
5054 | return elem; | |
5055 | } | |
5056 | return undefined; | |
5057 | },_modifier:null,modifier:function(){ | |
5058 | if(this._modifier!==null){ | |
5059 | return this._modifier; | |
5060 | } | |
5061 | var m={}; | |
5062 | m.alt=this._event.altKey; | |
5063 | m.ctrl=this._event.ctrlKey; | |
5064 | m.meta=this._event.metaKey||false; | |
5065 | m.shift=this._event.shiftKey; | |
5066 | m.any=m.alt||m.ctrl||m.shift||m.meta; | |
5067 | this._modifier=m; | |
5068 | return m; | |
5069 | },_key:null,key:function(){ | |
5070 | if(this._key!==null){ | |
5071 | return this._key; | |
5072 | } | |
5073 | var k={}; | |
5074 | if(this.type()&&this.type().indexOf("key")===0){ | |
5075 | if(this.type()=="keydown"||this.type()=="keyup"){ | |
5076 | k.code=this._event.keyCode; | |
5077 | k.string=(MochiKit.Signal._specialKeys[k.code]||"KEY_UNKNOWN"); | |
5078 | this._key=k; | |
5079 | return k; | |
5080 | }else{ | |
5081 | if(this.type()=="keypress"){ | |
5082 | k.code=0; | |
5083 | k.string=""; | |
5084 | if(typeof (this._event.charCode)!="undefined"&&this._event.charCode!==0&&!MochiKit.Signal._specialMacKeys[this._event.charCode]){ | |
5085 | k.code=this._event.charCode; | |
5086 | k.string=String.fromCharCode(k.code); | |
5087 | }else{ | |
5088 | if(this._event.keyCode&&typeof (this._event.charCode)=="undefined"){ | |
5089 | k.code=this._event.keyCode; | |
5090 | k.string=String.fromCharCode(k.code); | |
5091 | } | |
5092 | } | |
5093 | this._key=k; | |
5094 | return k; | |
5095 | } | |
5096 | } | |
5097 | } | |
5098 | return undefined; | |
5099 | },_mouse:null,mouse:function(){ | |
5100 | if(this._mouse!==null){ | |
5101 | return this._mouse; | |
5102 | } | |
5103 | var m={}; | |
5104 | var e=this._event; | |
5105 | if(this.type()&&(this.type().indexOf("mouse")===0||this.type().indexOf("click")!=-1||this.type()=="contextmenu")){ | |
5106 | m.client=new MochiKit.Style.Coordinates(0,0); | |
5107 | if(e.clientX||e.clientY){ | |
5108 | m.client.x=(!e.clientX||e.clientX<0)?0:e.clientX; | |
5109 | m.client.y=(!e.clientY||e.clientY<0)?0:e.clientY; | |
5110 | } | |
5111 | m.page=new MochiKit.Style.Coordinates(0,0); | |
5112 | if(e.pageX||e.pageY){ | |
5113 | m.page.x=(!e.pageX||e.pageX<0)?0:e.pageX; | |
5114 | m.page.y=(!e.pageY||e.pageY<0)?0:e.pageY; | |
5115 | }else{ | |
5116 | var de=MochiKit.DOM._document.documentElement; | |
5117 | var b=MochiKit.DOM._document.body; | |
5118 | m.page.x=e.clientX+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0); | |
5119 | m.page.y=e.clientY+(de.scrollTop||b.scrollTop)-(de.clientTop||0); | |
5120 | } | |
5121 | if(this.type()!="mousemove"){ | |
5122 | m.button={}; | |
5123 | m.button.left=false; | |
5124 | m.button.right=false; | |
5125 | m.button.middle=false; | |
5126 | if(e.which){ | |
5127 | m.button.left=(e.which==1); | |
5128 | m.button.middle=(e.which==2); | |
5129 | m.button.right=(e.which==3); | |
5130 | }else{ | |
5131 | m.button.left=!!(e.button&1); | |
5132 | m.button.right=!!(e.button&2); | |
5133 | m.button.middle=!!(e.button&4); | |
5134 | } | |
5135 | } | |
5136 | this._mouse=m; | |
5137 | return m; | |
5138 | } | |
5139 | return undefined; | |
5140 | },stop:function(){ | |
5141 | this.stopPropagation(); | |
5142 | this.preventDefault(); | |
5143 | },stopPropagation:function(){ | |
5144 | if(this._event.stopPropagation){ | |
5145 | this._event.stopPropagation(); | |
5146 | }else{ | |
5147 | this._event.cancelBubble=true; | |
5148 | } | |
5149 | },preventDefault:function(){ | |
5150 | if(this._event.preventDefault){ | |
5151 | this._event.preventDefault(); | |
5152 | }else{ | |
5153 | if(this._confirmUnload===null){ | |
5154 | this._event.returnValue=false; | |
5155 | } | |
5156 | } | |
5157 | },_confirmUnload:null,confirmUnload:function(msg){ | |
5158 | if(this.type()=="beforeunload"){ | |
5159 | this._confirmUnload=msg; | |
5160 | this._event.returnValue=msg; | |
5161 | } | |
5162 | }}); | |
5163 | 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"}; | |
5164 | (function(){ | |
5165 | var _52e=MochiKit.Signal._specialMacKeys; | |
5166 | for(i=63236;i<=63242;i++){ | |
5167 | _52e[i]="KEY_F"+(i-63236+1); | |
5168 | } | |
5169 | })(); | |
5170 | 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"}; | |
5171 | (function(){ | |
5172 | var _52f=MochiKit.Signal._specialKeys; | |
5173 | for(var i=48;i<=57;i++){ | |
5174 | _52f[i]="KEY_"+(i-48); | |
5175 | } | |
5176 | for(i=65;i<=90;i++){ | |
5177 | _52f[i]="KEY_"+String.fromCharCode(i); | |
5178 | } | |
5179 | for(i=96;i<=105;i++){ | |
5180 | _52f[i]="KEY_NUM_PAD_"+(i-96); | |
5181 | } | |
5182 | for(i=112;i<=123;i++){ | |
5183 | _52f[i]="KEY_F"+(i-112+1); | |
5184 | } | |
5185 | })(); | |
5186 | MochiKit.Signal.Ident=function(_531){ | |
5187 | this.source=_531.source; | |
5188 | this.signal=_531.signal; | |
5189 | this.listener=_531.listener; | |
5190 | this.isDOM=_531.isDOM; | |
5191 | this.objOrFunc=_531.objOrFunc; | |
5192 | this.funcOrStr=_531.funcOrStr; | |
5193 | this.connected=_531.connected; | |
5194 | }; | |
5195 | MochiKit.Signal.Ident.prototype={}; | |
5196 | MochiKit.Base.update(MochiKit.Signal,{__repr__:function(){ | |
5197 | return "["+this.NAME+" "+this.VERSION+"]"; | |
5198 | },toString:function(){ | |
5199 | return this.__repr__(); | |
5200 | },_unloadCache:function(){ | |
5201 | var self=MochiKit.Signal; | |
5202 | var _533=self._observers; | |
5203 | for(var i=0;i<_533.length;i++){ | |
5204 | if(_533[i].signal!=="onload"&&_533[i].signal!=="onunload"){ | |
5205 | self._disconnect(_533[i]); | |
5206 | } | |
5207 | } | |
5208 | },_listener:function(src,sig,func,obj,_539){ | |
5209 | var self=MochiKit.Signal; | |
5210 | var E=self.Event; | |
5211 | if(!_539){ | |
5212 | return MochiKit.Base.bind(func,obj); | |
5213 | } | |
5214 | obj=obj||src; | |
5215 | if(typeof (func)=="string"){ | |
5216 | if(sig==="onload"||sig==="onunload"){ | |
5217 | return function(_53c){ | |
5218 | obj[func].apply(obj,[new E(src,_53c)]); | |
5219 | var _53d=new MochiKit.Signal.Ident({source:src,signal:sig,objOrFunc:obj,funcOrStr:func}); | |
5220 | MochiKit.Signal._disconnect(_53d); | |
5221 | }; | |
5222 | }else{ | |
5223 | return function(_53e){ | |
5224 | obj[func].apply(obj,[new E(src,_53e)]); | |
5225 | }; | |
5226 | } | |
5227 | }else{ | |
5228 | if(sig==="onload"||sig==="onunload"){ | |
5229 | return function(_53f){ | |
5230 | func.apply(obj,[new E(src,_53f)]); | |
5231 | MochiKit.Signal.disconnect(src,sig,func); | |
5232 | var _540=new MochiKit.Signal.Ident({source:src,signal:sig,objOrFunc:func}); | |
5233 | MochiKit.Signal._disconnect(_540); | |
5234 | }; | |
5235 | }else{ | |
5236 | return function(_541){ | |
5237 | func.apply(obj,[new E(src,_541)]); | |
5238 | }; | |
5239 | } | |
5240 | } | |
5241 | },_browserAlreadyHasMouseEnterAndLeave:function(){ | |
5242 | return /MSIE/.test(navigator.userAgent); | |
5243 | },_mouseEnterListener:function(src,sig,func,obj){ | |
5244 | var E=MochiKit.Signal.Event; | |
5245 | return function(_547){ | |
5246 | var e=new E(src,_547); | |
5247 | try{ | |
5248 | e.relatedTarget().nodeName; | |
5249 | } | |
5250 | catch(err){ | |
5251 | return; | |
5252 | } | |
5253 | e.stop(); | |
5254 | if(MochiKit.DOM.isChildNode(e.relatedTarget(),src)){ | |
5255 | return; | |
5256 | } | |
5257 | e.type=function(){ | |
5258 | return sig; | |
5259 | }; | |
5260 | if(typeof (func)=="string"){ | |
5261 | return obj[func].apply(obj,[e]); | |
5262 | }else{ | |
5263 | return func.apply(obj,[e]); | |
5264 | } | |
5265 | }; | |
5266 | },_getDestPair:function(_549,_54a){ | |
5267 | var obj=null; | |
5268 | var func=null; | |
5269 | if(typeof (_54a)!="undefined"){ | |
5270 | obj=_549; | |
5271 | func=_54a; | |
5272 | if(typeof (_54a)=="string"){ | |
5273 | if(typeof (_549[_54a])!="function"){ | |
5274 | throw new Error("'funcOrStr' must be a function on 'objOrFunc'"); | |
5275 | } | |
5276 | }else{ | |
5277 | if(typeof (_54a)!="function"){ | |
5278 | throw new Error("'funcOrStr' must be a function or string"); | |
5279 | } | |
5280 | } | |
5281 | }else{ | |
5282 | if(typeof (_549)!="function"){ | |
5283 | throw new Error("'objOrFunc' must be a function if 'funcOrStr' is not given"); | |
5284 | }else{ | |
5285 | func=_549; | |
5286 | } | |
5287 | } | |
5288 | return [obj,func]; | |
5289 | },connect:function(src,sig,_54f,_550){ | |
5290 | src=MochiKit.DOM.getElement(src); | |
5291 | var self=MochiKit.Signal; | |
5292 | if(typeof (sig)!="string"){ | |
5293 | throw new Error("'sig' must be a string"); | |
5294 | } | |
5295 | var _552=self._getDestPair(_54f,_550); | |
5296 | var obj=_552[0]; | |
5297 | var func=_552[1]; | |
5298 | if(typeof (obj)=="undefined"||obj===null){ | |
5299 | obj=src; | |
5300 | } | |
5301 | var _555=!!(src.addEventListener||src.attachEvent); | |
5302 | if(_555&&(sig==="onmouseenter"||sig==="onmouseleave")&&!self._browserAlreadyHasMouseEnterAndLeave()){ | |
5303 | var _556=self._mouseEnterListener(src,sig.substr(2),func,obj); | |
5304 | if(sig==="onmouseenter"){ | |
5305 | sig="onmouseover"; | |
5306 | }else{ | |
5307 | sig="onmouseout"; | |
5308 | } | |
5309 | }else{ | |
5310 | var _556=self._listener(src,sig,func,obj,_555); | |
5311 | } | |
5312 | if(src.addEventListener){ | |
5313 | src.addEventListener(sig.substr(2),_556,false); | |
5314 | }else{ | |
5315 | if(src.attachEvent){ | |
5316 | src.attachEvent(sig,_556); | |
5317 | } | |
5318 | } | |
5319 | var _557=new MochiKit.Signal.Ident({source:src,signal:sig,listener:_556,isDOM:_555,objOrFunc:_54f,funcOrStr:_550,connected:true}); | |
5320 | self._observers.push(_557); | |
5321 | if(!_555&&typeof (src.__connect__)=="function"){ | |
5322 | var args=MochiKit.Base.extend([_557],arguments,1); | |
5323 | src.__connect__.apply(src,args); | |
5324 | } | |
5325 | return _557; | |
5326 | },_disconnect:function(_559){ | |
5327 | if(!_559.connected){ | |
5328 | return; | |
5329 | } | |
5330 | _559.connected=false; | |
5331 | if(!_559.isDOM){ | |
5332 | return; | |
5333 | } | |
5334 | var src=_559.source; | |
5335 | var sig=_559.signal; | |
5336 | var _55c=_559.listener; | |
5337 | if(src.removeEventListener){ | |
5338 | src.removeEventListener(sig.substr(2),_55c,false); | |
5339 | }else{ | |
5340 | if(src.detachEvent){ | |
5341 | src.detachEvent(sig,_55c); | |
5342 | }else{ | |
5343 | throw new Error("'src' must be a DOM element"); | |
5344 | } | |
5345 | } | |
5346 | },disconnect:function(_55d){ | |
5347 | var self=MochiKit.Signal; | |
5348 | var _55f=self._observers; | |
5349 | var m=MochiKit.Base; | |
5350 | if(arguments.length>1){ | |
5351 | var src=MochiKit.DOM.getElement(arguments[0]); | |
5352 | var sig=arguments[1]; | |
5353 | var obj=arguments[2]; | |
5354 | var func=arguments[3]; | |
5355 | for(var i=_55f.length-1;i>=0;i--){ | |
5356 | var o=_55f[i]; | |
5357 | if(o.source===src&&o.signal===sig&&o.objOrFunc===obj&&o.funcOrStr===func){ | |
5358 | self._disconnect(o); | |
5359 | if(!self._lock){ | |
5360 | _55f.splice(i,1); | |
5361 | }else{ | |
5362 | self._dirty=true; | |
5363 | } | |
5364 | return true; | |
5365 | } | |
5366 | } | |
5367 | }else{ | |
5368 | var idx=m.findIdentical(_55f,_55d); | |
5369 | if(idx>=0){ | |
5370 | self._disconnect(_55d); | |
5371 | if(!self._lock){ | |
5372 | _55f.splice(idx,1); | |
5373 | }else{ | |
5374 | self._dirty=true; | |
5375 | } | |
5376 | return true; | |
5377 | } | |
5378 | } | |
5379 | return false; | |
5380 | },disconnectAllTo:function(_568,_569){ | |
5381 | var self=MochiKit.Signal; | |
5382 | var _56b=self._observers; | |
5383 | var _56c=self._disconnect; | |
5384 | var _56d=self._lock; | |
5385 | var _56e=self._dirty; | |
5386 | if(typeof (_569)==="undefined"){ | |
5387 | _569=null; | |
5388 | } | |
5389 | for(var i=_56b.length-1;i>=0;i--){ | |
5390 | var _570=_56b[i]; | |
5391 | if(_570.objOrFunc===_568&&(_569===null||_570.funcOrStr===_569)){ | |
5392 | _56c(_570); | |
5393 | if(_56d){ | |
5394 | _56e=true; | |
5395 | }else{ | |
5396 | _56b.splice(i,1); | |
5397 | } | |
5398 | } | |
5399 | } | |
5400 | self._dirty=_56e; | |
5401 | },disconnectAll:function(src,sig){ | |
5402 | src=MochiKit.DOM.getElement(src); | |
5403 | var m=MochiKit.Base; | |
5404 | var _574=m.flattenArguments(m.extend(null,arguments,1)); | |
5405 | var self=MochiKit.Signal; | |
5406 | var _576=self._disconnect; | |
5407 | var _577=self._observers; | |
5408 | var i,_579; | |
5409 | var _57a=self._lock; | |
5410 | var _57b=self._dirty; | |
5411 | if(_574.length===0){ | |
5412 | for(i=_577.length-1;i>=0;i--){ | |
5413 | _579=_577[i]; | |
5414 | if(_579.source===src){ | |
5415 | _576(_579); | |
5416 | if(!_57a){ | |
5417 | _577.splice(i,1); | |
5418 | }else{ | |
5419 | _57b=true; | |
5420 | } | |
5421 | } | |
5422 | } | |
5423 | }else{ | |
5424 | var sigs={}; | |
5425 | for(i=0;i<_574.length;i++){ | |
5426 | sigs[_574[i]]=true; | |
5427 | } | |
5428 | for(i=_577.length-1;i>=0;i--){ | |
5429 | _579=_577[i]; | |
5430 | if(_579.source===src&&_579.signal in sigs){ | |
5431 | _576(_579); | |
5432 | if(!_57a){ | |
5433 | _577.splice(i,1); | |
5434 | }else{ | |
5435 | _57b=true; | |
5436 | } | |
5437 | } | |
5438 | } | |
5439 | } | |
5440 | self._dirty=_57b; | |
5441 | },signal:function(src,sig){ | |
5442 | var self=MochiKit.Signal; | |
5443 | var _580=self._observers; | |
5444 | src=MochiKit.DOM.getElement(src); | |
5445 | var args=MochiKit.Base.extend(null,arguments,2); | |
5446 | var _582=[]; | |
5447 | self._lock=true; | |
5448 | for(var i=0;i<_580.length;i++){ | |
5449 | var _584=_580[i]; | |
5450 | if(_584.source===src&&_584.signal===sig){ | |
5451 | try{ | |
5452 | _584.listener.apply(src,args); | |
5453 | } | |
5454 | catch(e){ | |
5455 | _582.push(e); | |
5456 | } | |
5457 | } | |
5458 | } | |
5459 | self._lock=false; | |
5460 | if(self._dirty){ | |
5461 | self._dirty=false; | |
5462 | for(var i=_580.length-1;i>=0;i--){ | |
5463 | if(!_580[i].connected){ | |
5464 | _580.splice(i,1); | |
5465 | } | |
5466 | } | |
5467 | } | |
5468 | if(_582.length==1){ | |
5469 | throw _582[0]; | |
5470 | }else{ | |
5471 | if(_582.length>1){ | |
5472 | var e=new Error("Multiple errors thrown in handling 'sig', see errors property"); | |
5473 | e.errors=_582; | |
5474 | throw e; | |
5475 | } | |
5476 | } | |
5477 | }}); | |
5478 | MochiKit.Signal.EXPORT_OK=[]; | |
5479 | MochiKit.Signal.EXPORT=["connect","disconnect","signal","disconnectAll","disconnectAllTo"]; | |
5480 | MochiKit.Signal.__new__=function(win){ | |
5481 | var m=MochiKit.Base; | |
5482 | this._document=document; | |
5483 | this._window=win; | |
5484 | this._lock=false; | |
5485 | this._dirty=false; | |
5486 | try{ | |
5487 | this.connect(window,"onunload",this._unloadCache); | |
5488 | } | |
5489 | catch(e){ | |
5490 | } | |
5491 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
5492 | m.nameFunctions(this); | |
5493 | }; | |
5494 | MochiKit.Signal.__new__(this); | |
5495 | if(MochiKit.__export__){ | |
5496 | connect=MochiKit.Signal.connect; | |
5497 | disconnect=MochiKit.Signal.disconnect; | |
5498 | disconnectAll=MochiKit.Signal.disconnectAll; | |
5499 | signal=MochiKit.Signal.signal; | |
5500 | } | |
5501 | MochiKit.Base._exportSymbols(this,MochiKit.Signal); | |
5502 | if(typeof (dojo)!="undefined"){ | |
5503 | dojo.provide("MochiKit.Position"); | |
5504 | dojo.require("MochiKit.Base"); | |
5505 | dojo.require("MochiKit.DOM"); | |
5506 | dojo.require("MochiKit.Style"); | |
5507 | } | |
5508 | if(typeof (JSAN)!="undefined"){ | |
5509 | JSAN.use("MochiKit.Base",[]); | |
5510 | JSAN.use("MochiKit.DOM",[]); | |
5511 | JSAN.use("MochiKit.Style",[]); | |
5512 | } | |
5513 | try{ | |
5514 | if(typeof (MochiKit.Base)=="undefined"||typeof (MochiKit.Style)=="undefined"||typeof (MochiKit.DOM)=="undefined"){ | |
5515 | throw ""; | |
5516 | } | |
5517 | } | |
5518 | catch(e){ | |
5519 | throw "MochiKit.Style depends on MochiKit.Base, MochiKit.DOM, and MochiKit.Style!"; | |
5520 | } | |
5521 | if(typeof (MochiKit.Position)=="undefined"){ | |
5522 | MochiKit.Position={}; | |
5523 | } | |
5524 | MochiKit.Position.NAME="MochiKit.Position"; | |
5525 | MochiKit.Position.VERSION="1.4"; | |
5526 | MochiKit.Position.__repr__=function(){ | |
5527 | return "["+this.NAME+" "+this.VERSION+"]"; | |
5528 | }; | |
5529 | MochiKit.Position.toString=function(){ | |
5530 | return this.__repr__(); | |
5531 | }; | |
5532 | MochiKit.Position.EXPORT_OK=[]; | |
5533 | MochiKit.Position.EXPORT=[]; | |
5534 | MochiKit.Base.update(MochiKit.Position,{includeScrollOffsets:false,prepare:function(){ | |
5535 | var _588=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0; | |
5536 | var _589=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0; | |
5537 | this.windowOffset=new MochiKit.Style.Coordinates(_588,_589); | |
5538 | },cumulativeOffset:function(_58a){ | |
5539 | var _58b=0; | |
5540 | var _58c=0; | |
5541 | do{ | |
5542 | _58b+=_58a.offsetTop||0; | |
5543 | _58c+=_58a.offsetLeft||0; | |
5544 | _58a=_58a.offsetParent; | |
5545 | }while(_58a); | |
5546 | return new MochiKit.Style.Coordinates(_58c,_58b); | |
5547 | },realOffset:function(_58d){ | |
5548 | var _58e=0; | |
5549 | var _58f=0; | |
5550 | do{ | |
5551 | _58e+=_58d.scrollTop||0; | |
5552 | _58f+=_58d.scrollLeft||0; | |
5553 | _58d=_58d.parentNode; | |
5554 | }while(_58d); | |
5555 | return new MochiKit.Style.Coordinates(_58f,_58e); | |
5556 | },within:function(_590,x,y){ | |
5557 | if(this.includeScrollOffsets){ | |
5558 | return this.withinIncludingScrolloffsets(_590,x,y); | |
5559 | } | |
5560 | this.xcomp=x; | |
5561 | this.ycomp=y; | |
5562 | this.offset=this.cumulativeOffset(_590); | |
5563 | if(_590.style.position=="fixed"){ | |
5564 | this.offset.x+=this.windowOffset.x; | |
5565 | this.offset.y+=this.windowOffset.y; | |
5566 | } | |
5567 | return (y>=this.offset.y&&y<this.offset.y+_590.offsetHeight&&x>=this.offset.x&&x<this.offset.x+_590.offsetWidth); | |
5568 | },withinIncludingScrolloffsets:function(_593,x,y){ | |
5569 | var _596=this.realOffset(_593); | |
5570 | this.xcomp=x+_596.x-this.windowOffset.x; | |
5571 | this.ycomp=y+_596.y-this.windowOffset.y; | |
5572 | this.offset=this.cumulativeOffset(_593); | |
5573 | return (this.ycomp>=this.offset.y&&this.ycomp<this.offset.y+_593.offsetHeight&&this.xcomp>=this.offset.x&&this.xcomp<this.offset.x+_593.offsetWidth); | |
5574 | },overlap:function(mode,_598){ | |
5575 | if(!mode){ | |
5576 | return 0; | |
5577 | } | |
5578 | if(mode=="vertical"){ | |
5579 | return ((this.offset.y+_598.offsetHeight)-this.ycomp)/_598.offsetHeight; | |
5580 | } | |
5581 | if(mode=="horizontal"){ | |
5582 | return ((this.offset.x+_598.offsetWidth)-this.xcomp)/_598.offsetWidth; | |
5583 | } | |
5584 | },absolutize:function(_599){ | |
5585 | _599=MochiKit.DOM.getElement(_599); | |
5586 | if(_599.style.position=="absolute"){ | |
5587 | return; | |
5588 | } | |
5589 | MochiKit.Position.prepare(); | |
5590 | var _59a=MochiKit.Position.positionedOffset(_599); | |
5591 | var _59b=_599.clientWidth; | |
5592 | var _59c=_599.clientHeight; | |
5593 | var _59d={"position":_599.style.position,"left":_59a.x-parseFloat(_599.style.left||0),"top":_59a.y-parseFloat(_599.style.top||0),"width":_599.style.width,"height":_599.style.height}; | |
5594 | _599.style.position="absolute"; | |
5595 | _599.style.top=_59a.y+"px"; | |
5596 | _599.style.left=_59a.x+"px"; | |
5597 | _599.style.width=_59b+"px"; | |
5598 | _599.style.height=_59c+"px"; | |
5599 | return _59d; | |
5600 | },positionedOffset:function(_59e){ | |
5601 | var _59f=0,_5a0=0; | |
5602 | do{ | |
5603 | _59f+=_59e.offsetTop||0; | |
5604 | _5a0+=_59e.offsetLeft||0; | |
5605 | _59e=_59e.offsetParent; | |
5606 | if(_59e){ | |
5607 | p=MochiKit.Style.getStyle(_59e,"position"); | |
5608 | if(p=="relative"||p=="absolute"){ | |
5609 | break; | |
5610 | } | |
5611 | } | |
5612 | }while(_59e); | |
5613 | return new MochiKit.Style.Coordinates(_5a0,_59f); | |
5614 | },relativize:function(_5a1,_5a2){ | |
5615 | _5a1=MochiKit.DOM.getElement(_5a1); | |
5616 | if(_5a1.style.position=="relative"){ | |
5617 | return; | |
5618 | } | |
5619 | MochiKit.Position.prepare(); | |
5620 | var top=parseFloat(_5a1.style.top||0)-(_5a2["top"]||0); | |
5621 | var left=parseFloat(_5a1.style.left||0)-(_5a2["left"]||0); | |
5622 | _5a1.style.position=_5a2["position"]; | |
5623 | _5a1.style.top=top+"px"; | |
5624 | _5a1.style.left=left+"px"; | |
5625 | _5a1.style.width=_5a2["width"]; | |
5626 | _5a1.style.height=_5a2["height"]; | |
5627 | },clone:function(_5a5,_5a6){ | |
5628 | _5a5=MochiKit.DOM.getElement(_5a5); | |
5629 | _5a6=MochiKit.DOM.getElement(_5a6); | |
5630 | _5a6.style.position="absolute"; | |
5631 | var _5a7=this.cumulativeOffset(_5a5); | |
5632 | _5a6.style.top=_5a7.y+"px"; | |
5633 | _5a6.style.left=_5a7.x+"px"; | |
5634 | _5a6.style.width=_5a5.offsetWidth+"px"; | |
5635 | _5a6.style.height=_5a5.offsetHeight+"px"; | |
5636 | },page:function(_5a8){ | |
5637 | var _5a9=0; | |
5638 | var _5aa=0; | |
5639 | var _5ab=_5a8; | |
5640 | do{ | |
5641 | _5a9+=_5ab.offsetTop||0; | |
5642 | _5aa+=_5ab.offsetLeft||0; | |
5643 | if(_5ab.offsetParent==document.body&&MochiKit.Style.getStyle(_5ab,"position")=="absolute"){ | |
5644 | break; | |
5645 | } | |
5646 | }while(_5ab=_5ab.offsetParent); | |
5647 | _5ab=_5a8; | |
5648 | do{ | |
5649 | _5a9-=_5ab.scrollTop||0; | |
5650 | _5aa-=_5ab.scrollLeft||0; | |
5651 | }while(_5ab=_5ab.parentNode); | |
5652 | return new MochiKit.Style.Coordinates(_5aa,_5a9); | |
5653 | }}); | |
5654 | MochiKit.Position.__new__=function(win){ | |
5655 | var m=MochiKit.Base; | |
5656 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
5657 | m.nameFunctions(this); | |
5658 | }; | |
5659 | MochiKit.Position.__new__(this); | |
5660 | if(typeof (dojo)!="undefined"){ | |
5661 | dojo.provide("MochiKit.Visual"); | |
5662 | dojo.require("MochiKit.Base"); | |
5663 | dojo.require("MochiKit.DOM"); | |
5664 | dojo.require("MochiKit.Style"); | |
5665 | dojo.require("MochiKit.Color"); | |
5666 | dojo.require("MochiKit.Position"); | |
5667 | } | |
5668 | if(typeof (JSAN)!="undefined"){ | |
5669 | JSAN.use("MochiKit.Base",[]); | |
5670 | JSAN.use("MochiKit.DOM",[]); | |
5671 | JSAN.use("MochiKit.Style",[]); | |
5672 | JSAN.use("MochiKit.Color",[]); | |
5673 | JSAN.use("MochiKit.Position",[]); | |
5674 | } | |
5675 | try{ | |
5676 | if(typeof (MochiKit.Base)==="undefined"||typeof (MochiKit.DOM)==="undefined"||typeof (MochiKit.Style)==="undefined"||typeof (MochiKit.Position)==="undefined"||typeof (MochiKit.Color)==="undefined"){ | |
5677 | throw ""; | |
5678 | } | |
5679 | } | |
5680 | catch(e){ | |
5681 | throw "MochiKit.Visual depends on MochiKit.Base, MochiKit.DOM, MochiKit.Style, MochiKit.Position and MochiKit.Color!"; | |
5682 | } | |
5683 | if(typeof (MochiKit.Visual)=="undefined"){ | |
5684 | MochiKit.Visual={}; | |
5685 | } | |
5686 | MochiKit.Visual.NAME="MochiKit.Visual"; | |
5687 | MochiKit.Visual.VERSION="1.4"; | |
5688 | MochiKit.Visual.__repr__=function(){ | |
5689 | return "["+this.NAME+" "+this.VERSION+"]"; | |
5690 | }; | |
5691 | MochiKit.Visual.toString=function(){ | |
5692 | return this.__repr__(); | |
5693 | }; | |
5694 | MochiKit.Visual._RoundCorners=function(e,_5af){ | |
5695 | e=MochiKit.DOM.getElement(e); | |
5696 | this._setOptions(_5af); | |
5697 | if(this.options.__unstable__wrapElement){ | |
5698 | e=this._doWrap(e); | |
5699 | } | |
5700 | var _5b0=this.options.color; | |
5701 | var C=MochiKit.Color.Color; | |
5702 | if(this.options.color==="fromElement"){ | |
5703 | _5b0=C.fromBackground(e); | |
5704 | }else{ | |
5705 | if(!(_5b0 instanceof C)){ | |
5706 | _5b0=C.fromString(_5b0); | |
5707 | } | |
5708 | } | |
5709 | this.isTransparent=(_5b0.asRGB().a<=0); | |
5710 | var _5b2=this.options.bgColor; | |
5711 | if(this.options.bgColor==="fromParent"){ | |
5712 | _5b2=C.fromBackground(e.offsetParent); | |
5713 | }else{ | |
5714 | if(!(_5b2 instanceof C)){ | |
5715 | _5b2=C.fromString(_5b2); | |
5716 | } | |
5717 | } | |
5718 | this._roundCornersImpl(e,_5b0,_5b2); | |
5719 | }; | |
5720 | MochiKit.Visual._RoundCorners.prototype={_doWrap:function(e){ | |
5721 | var _5b4=e.parentNode; | |
5722 | var doc=MochiKit.DOM.currentDocument(); | |
5723 | if(typeof (doc.defaultView)==="undefined"||doc.defaultView===null){ | |
5724 | return e; | |
5725 | } | |
5726 | var _5b6=doc.defaultView.getComputedStyle(e,null); | |
5727 | if(typeof (_5b6)==="undefined"||_5b6===null){ | |
5728 | return e; | |
5729 | } | |
5730 | var _5b7=MochiKit.DOM.DIV({"style":{display:"block",marginTop:_5b6.getPropertyValue("padding-top"),marginRight:_5b6.getPropertyValue("padding-right"),marginBottom:_5b6.getPropertyValue("padding-bottom"),marginLeft:_5b6.getPropertyValue("padding-left"),padding:"0px"}}); | |
5731 | _5b7.innerHTML=e.innerHTML; | |
5732 | e.innerHTML=""; | |
5733 | e.appendChild(_5b7); | |
5734 | return e; | |
5735 | },_roundCornersImpl:function(e,_5b9,_5ba){ | |
5736 | if(this.options.border){ | |
5737 | this._renderBorder(e,_5ba); | |
5738 | } | |
5739 | if(this._isTopRounded()){ | |
5740 | this._roundTopCorners(e,_5b9,_5ba); | |
5741 | } | |
5742 | if(this._isBottomRounded()){ | |
5743 | this._roundBottomCorners(e,_5b9,_5ba); | |
5744 | } | |
5745 | },_renderBorder:function(el,_5bc){ | |
5746 | var _5bd="1px solid "+this._borderColor(_5bc); | |
5747 | var _5be="border-left: "+_5bd; | |
5748 | var _5bf="border-right: "+_5bd; | |
5749 | var _5c0="style='"+_5be+";"+_5bf+"'"; | |
5750 | el.innerHTML="<div "+_5c0+">"+el.innerHTML+"</div>"; | |
5751 | },_roundTopCorners:function(el,_5c2,_5c3){ | |
5752 | var _5c4=this._createCorner(_5c3); | |
5753 | for(var i=0;i<this.options.numSlices;i++){ | |
5754 | _5c4.appendChild(this._createCornerSlice(_5c2,_5c3,i,"top")); | |
5755 | } | |
5756 | el.style.paddingTop=0; | |
5757 | el.insertBefore(_5c4,el.firstChild); | |
5758 | },_roundBottomCorners:function(el,_5c7,_5c8){ | |
5759 | var _5c9=this._createCorner(_5c8); | |
5760 | for(var i=(this.options.numSlices-1);i>=0;i--){ | |
5761 | _5c9.appendChild(this._createCornerSlice(_5c7,_5c8,i,"bottom")); | |
5762 | } | |
5763 | el.style.paddingBottom=0; | |
5764 | el.appendChild(_5c9); | |
5765 | },_createCorner:function(_5cb){ | |
5766 | var dom=MochiKit.DOM; | |
5767 | return dom.DIV({style:{backgroundColor:_5cb.toString()}}); | |
5768 | },_createCornerSlice:function(_5cd,_5ce,n,_5d0){ | |
5769 | var _5d1=MochiKit.DOM.SPAN(); | |
5770 | var _5d2=_5d1.style; | |
5771 | _5d2.backgroundColor=_5cd.toString(); | |
5772 | _5d2.display="block"; | |
5773 | _5d2.height="1px"; | |
5774 | _5d2.overflow="hidden"; | |
5775 | _5d2.fontSize="1px"; | |
5776 | var _5d3=this._borderColor(_5cd,_5ce); | |
5777 | if(this.options.border&&n===0){ | |
5778 | _5d2.borderTopStyle="solid"; | |
5779 | _5d2.borderTopWidth="1px"; | |
5780 | _5d2.borderLeftWidth="0px"; | |
5781 | _5d2.borderRightWidth="0px"; | |
5782 | _5d2.borderBottomWidth="0px"; | |
5783 | _5d2.height="0px"; | |
5784 | _5d2.borderColor=_5d3.toString(); | |
5785 | }else{ | |
5786 | if(_5d3){ | |
5787 | _5d2.borderColor=_5d3.toString(); | |
5788 | _5d2.borderStyle="solid"; | |
5789 | _5d2.borderWidth="0px 1px"; | |
5790 | } | |
5791 | } | |
5792 | if(!this.options.compact&&(n==(this.options.numSlices-1))){ | |
5793 | _5d2.height="2px"; | |
5794 | } | |
5795 | this._setMargin(_5d1,n,_5d0); | |
5796 | this._setBorder(_5d1,n,_5d0); | |
5797 | return _5d1; | |
5798 | },_setOptions:function(_5d4){ | |
5799 | this.options={corners:"all",color:"fromElement",bgColor:"fromParent",blend:true,border:false,compact:false,__unstable__wrapElement:false}; | |
5800 | MochiKit.Base.update(this.options,_5d4); | |
5801 | this.options.numSlices=(this.options.compact?2:4); | |
5802 | },_whichSideTop:function(){ | |
5803 | var _5d5=this.options.corners; | |
5804 | if(this._hasString(_5d5,"all","top")){ | |
5805 | return ""; | |
5806 | } | |
5807 | var _5d6=(_5d5.indexOf("tl")!=-1); | |
5808 | var _5d7=(_5d5.indexOf("tr")!=-1); | |
5809 | if(_5d6&&_5d7){ | |
5810 | return ""; | |
5811 | } | |
5812 | if(_5d6){ | |
5813 | return "left"; | |
5814 | } | |
5815 | if(_5d7){ | |
5816 | return "right"; | |
5817 | } | |
5818 | return ""; | |
5819 | },_whichSideBottom:function(){ | |
5820 | var _5d8=this.options.corners; | |
5821 | if(this._hasString(_5d8,"all","bottom")){ | |
5822 | return ""; | |
5823 | } | |
5824 | var _5d9=(_5d8.indexOf("bl")!=-1); | |
5825 | var _5da=(_5d8.indexOf("br")!=-1); | |
5826 | if(_5d9&&_5da){ | |
5827 | return ""; | |
5828 | } | |
5829 | if(_5d9){ | |
5830 | return "left"; | |
5831 | } | |
5832 | if(_5da){ | |
5833 | return "right"; | |
5834 | } | |
5835 | return ""; | |
5836 | },_borderColor:function(_5db,_5dc){ | |
5837 | if(_5db=="transparent"){ | |
5838 | return _5dc; | |
5839 | }else{ | |
5840 | if(this.options.border){ | |
5841 | return this.options.border; | |
5842 | }else{ | |
5843 | if(this.options.blend){ | |
5844 | return _5dc.blendedColor(_5db); | |
5845 | } | |
5846 | } | |
5847 | } | |
5848 | return ""; | |
5849 | },_setMargin:function(el,n,_5df){ | |
5850 | var _5e0=this._marginSize(n)+"px"; | |
5851 | var _5e1=(_5df=="top"?this._whichSideTop():this._whichSideBottom()); | |
5852 | var _5e2=el.style; | |
5853 | if(_5e1=="left"){ | |
5854 | _5e2.marginLeft=_5e0; | |
5855 | _5e2.marginRight="0px"; | |
5856 | }else{ | |
5857 | if(_5e1=="right"){ | |
5858 | _5e2.marginRight=_5e0; | |
5859 | _5e2.marginLeft="0px"; | |
5860 | }else{ | |
5861 | _5e2.marginLeft=_5e0; | |
5862 | _5e2.marginRight=_5e0; | |
5863 | } | |
5864 | } | |
5865 | },_setBorder:function(el,n,_5e5){ | |
5866 | var _5e6=this._borderSize(n)+"px"; | |
5867 | var _5e7=(_5e5=="top"?this._whichSideTop():this._whichSideBottom()); | |
5868 | var _5e8=el.style; | |
5869 | if(_5e7=="left"){ | |
5870 | _5e8.borderLeftWidth=_5e6; | |
5871 | _5e8.borderRightWidth="0px"; | |
5872 | }else{ | |
5873 | if(_5e7=="right"){ | |
5874 | _5e8.borderRightWidth=_5e6; | |
5875 | _5e8.borderLeftWidth="0px"; | |
5876 | }else{ | |
5877 | _5e8.borderLeftWidth=_5e6; | |
5878 | _5e8.borderRightWidth=_5e6; | |
5879 | } | |
5880 | } | |
5881 | },_marginSize:function(n){ | |
5882 | if(this.isTransparent){ | |
5883 | return 0; | |
5884 | } | |
5885 | var o=this.options; | |
5886 | if(o.compact&&o.blend){ | |
5887 | var _5eb=[1,0]; | |
5888 | return _5eb[n]; | |
5889 | }else{ | |
5890 | if(o.compact){ | |
5891 | var _5ec=[2,1]; | |
5892 | return _5ec[n]; | |
5893 | }else{ | |
5894 | if(o.blend){ | |
5895 | var _5ed=[3,2,1,0]; | |
5896 | return _5ed[n]; | |
5897 | }else{ | |
5898 | var _5ee=[5,3,2,1]; | |
5899 | return _5ee[n]; | |
5900 | } | |
5901 | } | |
5902 | } | |
5903 | },_borderSize:function(n){ | |
5904 | var o=this.options; | |
5905 | var _5f1; | |
5906 | if(o.compact&&(o.blend||this.isTransparent)){ | |
5907 | return 1; | |
5908 | }else{ | |
5909 | if(o.compact){ | |
5910 | _5f1=[1,0]; | |
5911 | }else{ | |
5912 | if(o.blend){ | |
5913 | _5f1=[2,1,1,1]; | |
5914 | }else{ | |
5915 | if(o.border){ | |
5916 | _5f1=[0,2,0,0]; | |
5917 | }else{ | |
5918 | if(this.isTransparent){ | |
5919 | _5f1=[5,3,2,1]; | |
5920 | }else{ | |
5921 | return 0; | |
5922 | } | |
5923 | } | |
5924 | } | |
5925 | } | |
5926 | } | |
5927 | return _5f1[n]; | |
5928 | },_hasString:function(str){ | |
5929 | for(var i=1;i<arguments.length;i++){ | |
5930 | if(str.indexOf(arguments[i])!=-1){ | |
5931 | return true; | |
5932 | } | |
5933 | } | |
5934 | return false; | |
5935 | },_isTopRounded:function(){ | |
5936 | return this._hasString(this.options.corners,"all","top","tl","tr"); | |
5937 | },_isBottomRounded:function(){ | |
5938 | return this._hasString(this.options.corners,"all","bottom","bl","br"); | |
5939 | },_hasSingleTextChild:function(el){ | |
5940 | return (el.childNodes.length==1&&el.childNodes[0].nodeType==3); | |
5941 | }}; | |
5942 | MochiKit.Visual.roundElement=function(e,_5f6){ | |
5943 | new MochiKit.Visual._RoundCorners(e,_5f6); | |
5944 | }; | |
5945 | MochiKit.Visual.roundClass=function(_5f7,_5f8,_5f9){ | |
5946 | var _5fa=MochiKit.DOM.getElementsByTagAndClassName(_5f7,_5f8); | |
5947 | for(var i=0;i<_5fa.length;i++){ | |
5948 | MochiKit.Visual.roundElement(_5fa[i],_5f9); | |
5949 | } | |
5950 | }; | |
5951 | MochiKit.Visual.tagifyText=function(_5fc,_5fd){ | |
5952 | _5fd=_5fd||"position:relative"; | |
5953 | if(/MSIE/.test(navigator.userAgent)){ | |
5954 | _5fd+=";zoom:1"; | |
5955 | } | |
5956 | _5fc=MochiKit.DOM.getElement(_5fc); | |
5957 | var ma=MochiKit.Base.map; | |
5958 | ma(function(_5ff){ | |
5959 | if(_5ff.nodeType==3){ | |
5960 | ma(function(_600){ | |
5961 | _5fc.insertBefore(MochiKit.DOM.SPAN({style:_5fd},_600==" "?String.fromCharCode(160):_600),_5ff); | |
5962 | },_5ff.nodeValue.split("")); | |
5963 | MochiKit.DOM.removeElement(_5ff); | |
5964 | } | |
5965 | },_5fc.childNodes); | |
5966 | }; | |
5967 | MochiKit.Visual.forceRerendering=function(_601){ | |
5968 | try{ | |
5969 | _601=MochiKit.DOM.getElement(_601); | |
5970 | var n=document.createTextNode(" "); | |
5971 | _601.appendChild(n); | |
5972 | _601.removeChild(n); | |
5973 | } | |
5974 | catch(e){ | |
5975 | } | |
5976 | }; | |
5977 | MochiKit.Visual.multiple=function(_603,_604,_605){ | |
5978 | _605=MochiKit.Base.update({speed:0.1,delay:0},_605||{}); | |
5979 | var _606=_605.delay; | |
5980 | var _607=0; | |
5981 | MochiKit.Base.map(function(_608){ | |
5982 | _605.delay=_607*_605.speed+_606; | |
5983 | new _604(_608,_605); | |
5984 | _607+=1; | |
5985 | },_603); | |
5986 | }; | |
5987 | MochiKit.Visual.PAIRS={"slide":["slideDown","slideUp"],"blind":["blindDown","blindUp"],"appear":["appear","fade"],"size":["grow","shrink"]}; | |
5988 | MochiKit.Visual.toggle=function(_609,_60a,_60b){ | |
5989 | _609=MochiKit.DOM.getElement(_609); | |
5990 | _60a=(_60a||"appear").toLowerCase(); | |
5991 | _60b=MochiKit.Base.update({queue:{position:"end",scope:(_609.id||"global"),limit:1}},_60b||{}); | |
5992 | var v=MochiKit.Visual; | |
5993 | v[_609.style.display!="none"?v.PAIRS[_60a][1]:v.PAIRS[_60a][0]](_609,_60b); | |
5994 | }; | |
5995 | MochiKit.Visual.Transitions={}; | |
5996 | MochiKit.Visual.Transitions.linear=function(pos){ | |
5997 | return pos; | |
5998 | }; | |
5999 | MochiKit.Visual.Transitions.sinoidal=function(pos){ | |
6000 | return (-Math.cos(pos*Math.PI)/2)+0.5; | |
6001 | }; | |
6002 | MochiKit.Visual.Transitions.reverse=function(pos){ | |
6003 | return 1-pos; | |
6004 | }; | |
6005 | MochiKit.Visual.Transitions.flicker=function(pos){ | |
6006 | return ((-Math.cos(pos*Math.PI)/4)+0.75)+Math.random()/4; | |
6007 | }; | |
6008 | MochiKit.Visual.Transitions.wobble=function(pos){ | |
6009 | return (-Math.cos(pos*Math.PI*(9*pos))/2)+0.5; | |
6010 | }; | |
6011 | MochiKit.Visual.Transitions.pulse=function(pos,_613){ | |
6012 | if(!_613){ | |
6013 | return (Math.floor(pos*10)%2===0?(pos*10-Math.floor(pos*10)):1-(pos*10-Math.floor(pos*10))); | |
6014 | } | |
6015 | return (Math.round((pos%(1/_613))*_613)==0?((pos*_613*2)-Math.floor(pos*_613*2)):1-((pos*_613*2)-Math.floor(pos*_613*2))); | |
6016 | }; | |
6017 | MochiKit.Visual.Transitions.none=function(pos){ | |
6018 | return 0; | |
6019 | }; | |
6020 | MochiKit.Visual.Transitions.full=function(pos){ | |
6021 | return 1; | |
6022 | }; | |
6023 | MochiKit.Visual.ScopedQueue=function(){ | |
6024 | var cls=arguments.callee; | |
6025 | if(!(this instanceof cls)){ | |
6026 | return new cls(); | |
6027 | } | |
6028 | this.__init__(); | |
6029 | }; | |
6030 | MochiKit.Base.update(MochiKit.Visual.ScopedQueue.prototype,{__init__:function(){ | |
6031 | this.effects=[]; | |
6032 | this.interval=null; | |
6033 | },add:function(_617){ | |
6034 | var _618=new Date().getTime(); | |
6035 | var _619=(typeof (_617.options.queue)=="string")?_617.options.queue:_617.options.queue.position; | |
6036 | var ma=MochiKit.Base.map; | |
6037 | switch(_619){ | |
6038 | case "front": | |
6039 | ma(function(e){ | |
6040 | if(e.state=="idle"){ | |
6041 | e.startOn+=_617.finishOn; | |
6042 | e.finishOn+=_617.finishOn; | |
6043 | } | |
6044 | },this.effects); | |
6045 | break; | |
6046 | case "end": | |
6047 | var _61c; | |
6048 | ma(function(e){ | |
6049 | var i=e.finishOn; | |
6050 | if(i>=(_61c||i)){ | |
6051 | _61c=i; | |
6052 | } | |
6053 | },this.effects); | |
6054 | _618=_61c||_618; | |
6055 | break; | |
6056 | case "break": | |
6057 | ma(function(e){ | |
6058 | e.finalize(); | |
6059 | },this.effects); | |
6060 | break; | |
6061 | } | |
6062 | _617.startOn+=_618; | |
6063 | _617.finishOn+=_618; | |
6064 | if(!_617.options.queue.limit||this.effects.length<_617.options.queue.limit){ | |
6065 | this.effects.push(_617); | |
6066 | } | |
6067 | if(!this.interval){ | |
6068 | this.interval=this.startLoop(MochiKit.Base.bind(this.loop,this),40); | |
6069 | } | |
6070 | },startLoop:function(func,_621){ | |
6071 | return setInterval(func,_621); | |
6072 | },remove:function(_622){ | |
6073 | this.effects=MochiKit.Base.filter(function(e){ | |
6074 | return e!=_622; | |
6075 | },this.effects); | |
6076 | if(!this.effects.length){ | |
6077 | this.stopLoop(this.interval); | |
6078 | this.interval=null; | |
6079 | } | |
6080 | },stopLoop:function(_624){ | |
6081 | clearInterval(_624); | |
6082 | },loop:function(){ | |
6083 | var _625=new Date().getTime(); | |
6084 | MochiKit.Base.map(function(_626){ | |
6085 | _626.loop(_625); | |
6086 | },this.effects); | |
6087 | }}); | |
6088 | MochiKit.Visual.Queues={instances:{},get:function(_627){ | |
6089 | if(typeof (_627)!="string"){ | |
6090 | return _627; | |
6091 | } | |
6092 | if(!this.instances[_627]){ | |
6093 | this.instances[_627]=new MochiKit.Visual.ScopedQueue(); | |
6094 | } | |
6095 | return this.instances[_627]; | |
6096 | }}; | |
6097 | MochiKit.Visual.Queue=MochiKit.Visual.Queues.get("global"); | |
6098 | MochiKit.Visual.DefaultOptions={transition:MochiKit.Visual.Transitions.sinoidal,duration:1,fps:25,sync:false,from:0,to:1,delay:0,queue:"parallel"}; | |
6099 | MochiKit.Visual.Base=function(){ | |
6100 | }; | |
6101 | MochiKit.Visual.Base.prototype={__class__:MochiKit.Visual.Base,start:function(_628){ | |
6102 | var v=MochiKit.Visual; | |
6103 | this.options=MochiKit.Base.setdefault(_628||{},v.DefaultOptions); | |
6104 | this.currentFrame=0; | |
6105 | this.state="idle"; | |
6106 | this.startOn=this.options.delay*1000; | |
6107 | this.finishOn=this.startOn+(this.options.duration*1000); | |
6108 | this.event("beforeStart"); | |
6109 | if(!this.options.sync){ | |
6110 | v.Queues.get(typeof (this.options.queue)=="string"?"global":this.options.queue.scope).add(this); | |
6111 | } | |
6112 | },loop:function(_62a){ | |
6113 | if(_62a>=this.startOn){ | |
6114 | if(_62a>=this.finishOn){ | |
6115 | return this.finalize(); | |
6116 | } | |
6117 | var pos=(_62a-this.startOn)/(this.finishOn-this.startOn); | |
6118 | var _62c=Math.round(pos*this.options.fps*this.options.duration); | |
6119 | if(_62c>this.currentFrame){ | |
6120 | this.render(pos); | |
6121 | this.currentFrame=_62c; | |
6122 | } | |
6123 | } | |
6124 | },render:function(pos){ | |
6125 | if(this.state=="idle"){ | |
6126 | this.state="running"; | |
6127 | this.event("beforeSetup"); | |
6128 | this.setup(); | |
6129 | this.event("afterSetup"); | |
6130 | } | |
6131 | if(this.state=="running"){ | |
6132 | if(this.options.transition){ | |
6133 | pos=this.options.transition(pos); | |
6134 | } | |
6135 | pos*=(this.options.to-this.options.from); | |
6136 | pos+=this.options.from; | |
6137 | this.event("beforeUpdate"); | |
6138 | this.update(pos); | |
6139 | this.event("afterUpdate"); | |
6140 | } | |
6141 | },cancel:function(){ | |
6142 | if(!this.options.sync){ | |
6143 | MochiKit.Visual.Queues.get(typeof (this.options.queue)=="string"?"global":this.options.queue.scope).remove(this); | |
6144 | } | |
6145 | this.state="finished"; | |
6146 | },finalize:function(){ | |
6147 | this.render(1); | |
6148 | this.cancel(); | |
6149 | this.event("beforeFinish"); | |
6150 | this.finish(); | |
6151 | this.event("afterFinish"); | |
6152 | },setup:function(){ | |
6153 | },finish:function(){ | |
6154 | },update:function(_62e){ | |
6155 | },event:function(_62f){ | |
6156 | if(this.options[_62f+"Internal"]){ | |
6157 | this.options[_62f+"Internal"](this); | |
6158 | } | |
6159 | if(this.options[_62f]){ | |
6160 | this.options[_62f](this); | |
6161 | } | |
6162 | },repr:function(){ | |
6163 | return "["+this.__class__.NAME+", options:"+MochiKit.Base.repr(this.options)+"]"; | |
6164 | }}; | |
6165 | MochiKit.Visual.Parallel=function(_630,_631){ | |
6166 | var cls=arguments.callee; | |
6167 | if(!(this instanceof cls)){ | |
6168 | return new cls(_630,_631); | |
6169 | } | |
6170 | this.__init__(_630,_631); | |
6171 | }; | |
6172 | MochiKit.Visual.Parallel.prototype=new MochiKit.Visual.Base(); | |
6173 | MochiKit.Base.update(MochiKit.Visual.Parallel.prototype,{__class__:MochiKit.Visual.Parallel,__init__:function(_633,_634){ | |
6174 | this.effects=_633||[]; | |
6175 | this.start(_634); | |
6176 | },update:function(_635){ | |
6177 | MochiKit.Base.map(function(_636){ | |
6178 | _636.render(_635); | |
6179 | },this.effects); | |
6180 | },finish:function(){ | |
6181 | MochiKit.Base.map(function(_637){ | |
6182 | _637.finalize(); | |
6183 | },this.effects); | |
6184 | }}); | |
6185 | MochiKit.Visual.Opacity=function(_638,_639){ | |
6186 | var cls=arguments.callee; | |
6187 | if(!(this instanceof cls)){ | |
6188 | return new cls(_638,_639); | |
6189 | } | |
6190 | this.__init__(_638,_639); | |
6191 | }; | |
6192 | MochiKit.Visual.Opacity.prototype=new MochiKit.Visual.Base(); | |
6193 | MochiKit.Base.update(MochiKit.Visual.Opacity.prototype,{__class__:MochiKit.Visual.Opacity,__init__:function(_63b,_63c){ | |
6194 | var b=MochiKit.Base; | |
6195 | var s=MochiKit.Style; | |
6196 | this.element=MochiKit.DOM.getElement(_63b); | |
6197 | if(this.element.currentStyle&&(!this.element.currentStyle.hasLayout)){ | |
6198 | s.setStyle(this.element,{zoom:1}); | |
6199 | } | |
6200 | _63c=b.update({from:s.getStyle(this.element,"opacity")||0,to:1},_63c||{}); | |
6201 | this.start(_63c); | |
6202 | },update:function(_63f){ | |
6203 | MochiKit.Style.setStyle(this.element,{"opacity":_63f}); | |
6204 | }}); | |
6205 | MochiKit.Visual.Move=function(_640,_641){ | |
6206 | var cls=arguments.callee; | |
6207 | if(!(this instanceof cls)){ | |
6208 | return new cls(_640,_641); | |
6209 | } | |
6210 | this.__init__(_640,_641); | |
6211 | }; | |
6212 | MochiKit.Visual.Move.prototype=new MochiKit.Visual.Base(); | |
6213 | MochiKit.Base.update(MochiKit.Visual.Move.prototype,{__class__:MochiKit.Visual.Move,__init__:function(_643,_644){ | |
6214 | this.element=MochiKit.DOM.getElement(_643); | |
6215 | _644=MochiKit.Base.update({x:0,y:0,mode:"relative"},_644||{}); | |
6216 | this.start(_644); | |
6217 | },setup:function(){ | |
6218 | MochiKit.DOM.makePositioned(this.element); | |
6219 | var s=this.element.style; | |
6220 | var _646=s.visibility; | |
6221 | var _647=s.display; | |
6222 | if(_647=="none"){ | |
6223 | s.visibility="hidden"; | |
6224 | s.display=""; | |
6225 | } | |
6226 | this.originalLeft=parseFloat(MochiKit.Style.getStyle(this.element,"left")||"0"); | |
6227 | this.originalTop=parseFloat(MochiKit.Style.getStyle(this.element,"top")||"0"); | |
6228 | if(this.options.mode=="absolute"){ | |
6229 | this.options.x-=this.originalLeft; | |
6230 | this.options.y-=this.originalTop; | |
6231 | } | |
6232 | if(_647=="none"){ | |
6233 | s.visibility=_646; | |
6234 | s.display=_647; | |
6235 | } | |
6236 | },update:function(_648){ | |
6237 | MochiKit.Style.setStyle(this.element,{left:Math.round(this.options.x*_648+this.originalLeft)+"px",top:Math.round(this.options.y*_648+this.originalTop)+"px"}); | |
6238 | }}); | |
6239 | MochiKit.Visual.Scale=function(_649,_64a,_64b){ | |
6240 | var cls=arguments.callee; | |
6241 | if(!(this instanceof cls)){ | |
6242 | return new cls(_649,_64a,_64b); | |
6243 | } | |
6244 | this.__init__(_649,_64a,_64b); | |
6245 | }; | |
6246 | MochiKit.Visual.Scale.prototype=new MochiKit.Visual.Base(); | |
6247 | MochiKit.Base.update(MochiKit.Visual.Scale.prototype,{__class__:MochiKit.Visual.Scale,__init__:function(_64d,_64e,_64f){ | |
6248 | this.element=MochiKit.DOM.getElement(_64d); | |
6249 | _64f=MochiKit.Base.update({scaleX:true,scaleY:true,scaleContent:true,scaleFromCenter:false,scaleMode:"box",scaleFrom:100,scaleTo:_64e},_64f||{}); | |
6250 | this.start(_64f); | |
6251 | },setup:function(){ | |
6252 | this.restoreAfterFinish=this.options.restoreAfterFinish||false; | |
6253 | this.elementPositioning=MochiKit.Style.getStyle(this.element,"position"); | |
6254 | var ma=MochiKit.Base.map; | |
6255 | var b=MochiKit.Base.bind; | |
6256 | this.originalStyle={}; | |
6257 | ma(b(function(k){ | |
6258 | this.originalStyle[k]=this.element.style[k]; | |
6259 | },this),["top","left","width","height","fontSize"]); | |
6260 | this.originalTop=this.element.offsetTop; | |
6261 | this.originalLeft=this.element.offsetLeft; | |
6262 | var _653=MochiKit.Style.getStyle(this.element,"font-size")||"100%"; | |
6263 | ma(b(function(_654){ | |
6264 | if(_653.indexOf(_654)>0){ | |
6265 | this.fontSize=parseFloat(_653); | |
6266 | this.fontSizeType=_654; | |
6267 | } | |
6268 | },this),["em","px","%"]); | |
6269 | this.factor=(this.options.scaleTo-this.options.scaleFrom)/100; | |
6270 | if(/^content/.test(this.options.scaleMode)){ | |
6271 | this.dims=[this.element.scrollHeight,this.element.scrollWidth]; | |
6272 | }else{ | |
6273 | if(this.options.scaleMode=="box"){ | |
6274 | this.dims=[this.element.offsetHeight,this.element.offsetWidth]; | |
6275 | }else{ | |
6276 | this.dims=[this.options.scaleMode.originalHeight,this.options.scaleMode.originalWidth]; | |
6277 | } | |
6278 | } | |
6279 | },update:function(_655){ | |
6280 | var _656=(this.options.scaleFrom/100)+(this.factor*_655); | |
6281 | if(this.options.scaleContent&&this.fontSize){ | |
6282 | MochiKit.Style.setStyle(this.element,{fontSize:this.fontSize*_656+this.fontSizeType}); | |
6283 | } | |
6284 | this.setDimensions(this.dims[0]*_656,this.dims[1]*_656); | |
6285 | },finish:function(){ | |
6286 | if(this.restoreAfterFinish){ | |
6287 | MochiKit.Style.setStyle(this.element,this.originalStyle); | |
6288 | } | |
6289 | },setDimensions:function(_657,_658){ | |
6290 | var d={}; | |
6291 | var r=Math.round; | |
6292 | if(/MSIE/.test(navigator.userAgent)){ | |
6293 | r=Math.ceil; | |
6294 | } | |
6295 | if(this.options.scaleX){ | |
6296 | d.width=r(_658)+"px"; | |
6297 | } | |
6298 | if(this.options.scaleY){ | |
6299 | d.height=r(_657)+"px"; | |
6300 | } | |
6301 | if(this.options.scaleFromCenter){ | |
6302 | var topd=(_657-this.dims[0])/2; | |
6303 | var _65c=(_658-this.dims[1])/2; | |
6304 | if(this.elementPositioning=="absolute"){ | |
6305 | if(this.options.scaleY){ | |
6306 | d.top=this.originalTop-topd+"px"; | |
6307 | } | |
6308 | if(this.options.scaleX){ | |
6309 | d.left=this.originalLeft-_65c+"px"; | |
6310 | } | |
6311 | }else{ | |
6312 | if(this.options.scaleY){ | |
6313 | d.top=-topd+"px"; | |
6314 | } | |
6315 | if(this.options.scaleX){ | |
6316 | d.left=-_65c+"px"; | |
6317 | } | |
6318 | } | |
6319 | } | |
6320 | MochiKit.Style.setStyle(this.element,d); | |
6321 | }}); | |
6322 | MochiKit.Visual.Highlight=function(_65d,_65e){ | |
6323 | var cls=arguments.callee; | |
6324 | if(!(this instanceof cls)){ | |
6325 | return new cls(_65d,_65e); | |
6326 | } | |
6327 | this.__init__(_65d,_65e); | |
6328 | }; | |
6329 | MochiKit.Visual.Highlight.prototype=new MochiKit.Visual.Base(); | |
6330 | MochiKit.Base.update(MochiKit.Visual.Highlight.prototype,{__class__:MochiKit.Visual.Highlight,__init__:function(_660,_661){ | |
6331 | this.element=MochiKit.DOM.getElement(_660); | |
6332 | _661=MochiKit.Base.update({startcolor:"#ffff99"},_661||{}); | |
6333 | this.start(_661); | |
6334 | },setup:function(){ | |
6335 | var b=MochiKit.Base; | |
6336 | var s=MochiKit.Style; | |
6337 | if(s.getStyle(this.element,"display")=="none"){ | |
6338 | this.cancel(); | |
6339 | return; | |
6340 | } | |
6341 | this.oldStyle={backgroundImage:s.getStyle(this.element,"background-image")}; | |
6342 | s.setStyle(this.element,{backgroundImage:"none"}); | |
6343 | if(!this.options.endcolor){ | |
6344 | this.options.endcolor=MochiKit.Color.Color.fromBackground(this.element).toHexString(); | |
6345 | } | |
6346 | if(b.isUndefinedOrNull(this.options.restorecolor)){ | |
6347 | this.options.restorecolor=s.getStyle(this.element,"background-color"); | |
6348 | } | |
6349 | this._base=b.map(b.bind(function(i){ | |
6350 | return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16); | |
6351 | },this),[0,1,2]); | |
6352 | this._delta=b.map(b.bind(function(i){ | |
6353 | return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i]; | |
6354 | },this),[0,1,2]); | |
6355 | },update:function(_666){ | |
6356 | var m="#"; | |
6357 | MochiKit.Base.map(MochiKit.Base.bind(function(i){ | |
6358 | m+=MochiKit.Color.toColorPart(Math.round(this._base[i]+this._delta[i]*_666)); | |
6359 | },this),[0,1,2]); | |
6360 | MochiKit.Style.setStyle(this.element,{backgroundColor:m}); | |
6361 | },finish:function(){ | |
6362 | MochiKit.Style.setStyle(this.element,MochiKit.Base.update(this.oldStyle,{backgroundColor:this.options.restorecolor})); | |
6363 | }}); | |
6364 | MochiKit.Visual.ScrollTo=function(_669,_66a){ | |
6365 | var cls=arguments.callee; | |
6366 | if(!(this instanceof cls)){ | |
6367 | return new cls(_669,_66a); | |
6368 | } | |
6369 | this.__init__(_669,_66a); | |
6370 | }; | |
6371 | MochiKit.Visual.ScrollTo.prototype=new MochiKit.Visual.Base(); | |
6372 | MochiKit.Base.update(MochiKit.Visual.ScrollTo.prototype,{__class__:MochiKit.Visual.ScrollTo,__init__:function(_66c,_66d){ | |
6373 | this.element=MochiKit.DOM.getElement(_66c); | |
6374 | this.start(_66d||{}); | |
6375 | },setup:function(){ | |
6376 | var p=MochiKit.Position; | |
6377 | p.prepare(); | |
6378 | var _66f=p.cumulativeOffset(this.element); | |
6379 | if(this.options.offset){ | |
6380 | _66f.y+=this.options.offset; | |
6381 | } | |
6382 | var max; | |
6383 | if(window.innerHeight){ | |
6384 | max=window.innerHeight-window.height; | |
6385 | }else{ | |
6386 | if(document.documentElement&&document.documentElement.clientHeight){ | |
6387 | max=document.documentElement.clientHeight-document.body.scrollHeight; | |
6388 | }else{ | |
6389 | if(document.body){ | |
6390 | max=document.body.clientHeight-document.body.scrollHeight; | |
6391 | } | |
6392 | } | |
6393 | } | |
6394 | this.scrollStart=p.windowOffset.y; | |
6395 | this.delta=(_66f.y>max?max:_66f.y)-this.scrollStart; | |
6396 | },update:function(_671){ | |
6397 | var p=MochiKit.Position; | |
6398 | p.prepare(); | |
6399 | window.scrollTo(p.windowOffset.x,this.scrollStart+(_671*this.delta)); | |
6400 | }}); | |
6401 | MochiKit.Visual.CSS_LENGTH=/^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/; | |
6402 | MochiKit.Visual.Morph=function(_673,_674){ | |
6403 | var cls=arguments.callee; | |
6404 | if(!(this instanceof cls)){ | |
6405 | return new cls(_673,_674); | |
6406 | } | |
6407 | this.__init__(_673,_674); | |
6408 | }; | |
6409 | MochiKit.Visual.Morph.prototype=new MochiKit.Visual.Base(); | |
6410 | MochiKit.Base.update(MochiKit.Visual.Morph.prototype,{__class__:MochiKit.Visual.Morph,__init__:function(_676,_677){ | |
6411 | this.element=MochiKit.DOM.getElement(_676); | |
6412 | this.start(_677||{}); | |
6413 | },setup:function(){ | |
6414 | var b=MochiKit.Base; | |
6415 | var _679=this.options.style; | |
6416 | this.styleStart={}; | |
6417 | this.styleEnd={}; | |
6418 | this.units={}; | |
6419 | var _67a,unit; | |
6420 | for(var s in _679){ | |
6421 | _67a=_679[s]; | |
6422 | s=b.camelize(s); | |
6423 | if(MochiKit.Visual.CSS_LENGTH.test(_67a)){ | |
6424 | var _67d=_67a.match(/^([\+\-]?[0-9\.]+)(.*)$/); | |
6425 | _67a=parseFloat(_67d[1]); | |
6426 | unit=(_67d.length==3)?_67d[2]:null; | |
6427 | this.styleEnd[s]=_67a; | |
6428 | this.units[s]=unit; | |
6429 | _67a=MochiKit.Style.getStyle(this.element,s); | |
6430 | _67d=_67a.match(/^([\+\-]?[0-9\.]+)(.*)$/); | |
6431 | _67a=parseFloat(_67d[1]); | |
6432 | this.styleStart[s]=_67a; | |
6433 | }else{ | |
6434 | var c=MochiKit.Color.Color; | |
6435 | _67a=c.fromString(_67a); | |
6436 | if(_67a){ | |
6437 | this.units[s]="color"; | |
6438 | this.styleEnd[s]=_67a.toHexString(); | |
6439 | _67a=MochiKit.Style.getStyle(this.element,s); | |
6440 | this.styleStart[s]=c.fromString(_67a).toHexString(); | |
6441 | this.styleStart[s]=b.map(b.bind(function(i){ | |
6442 | return parseInt(this.styleStart[s].slice(i*2+1,i*2+3),16); | |
6443 | },this),[0,1,2]); | |
6444 | this.styleEnd[s]=b.map(b.bind(function(i){ | |
6445 | return parseInt(this.styleEnd[s].slice(i*2+1,i*2+3),16); | |
6446 | },this),[0,1,2]); | |
6447 | } | |
6448 | } | |
6449 | } | |
6450 | },update:function(_681){ | |
6451 | var _682; | |
6452 | for(var s in this.styleStart){ | |
6453 | if(this.units[s]=="color"){ | |
6454 | var m="#"; | |
6455 | var _685=this.styleStart[s]; | |
6456 | var end=this.styleEnd[s]; | |
6457 | MochiKit.Base.map(MochiKit.Base.bind(function(i){ | |
6458 | m+=MochiKit.Color.toColorPart(Math.round(_685[i]+(end[i]-_685[i])*_681)); | |
6459 | },this),[0,1,2]); | |
6460 | this.element.style[s]=m; | |
6461 | }else{ | |
6462 | _682=this.styleStart[s]+Math.round((this.styleEnd[s]-this.styleStart[s])*_681*1000)/1000+this.units[s]; | |
6463 | this.element.style[s]=_682; | |
6464 | } | |
6465 | } | |
6466 | }}); | |
6467 | MochiKit.Visual.fade=function(_688,_689){ | |
6468 | var s=MochiKit.Style; | |
6469 | var _68b=s.getStyle(_688,"opacity"); | |
6470 | _689=MochiKit.Base.update({from:s.getStyle(_688,"opacity")||1,to:0,afterFinishInternal:function(_68c){ | |
6471 | if(_68c.options.to!==0){ | |
6472 | return; | |
6473 | } | |
6474 | s.hideElement(_68c.element); | |
6475 | s.setStyle(_68c.element,{"opacity":_68b}); | |
6476 | }},_689||{}); | |
6477 | return new MochiKit.Visual.Opacity(_688,_689); | |
6478 | }; | |
6479 | MochiKit.Visual.appear=function(_68d,_68e){ | |
6480 | var s=MochiKit.Style; | |
6481 | var v=MochiKit.Visual; | |
6482 | _68e=MochiKit.Base.update({from:(s.getStyle(_68d,"display")=="none"?0:s.getStyle(_68d,"opacity")||0),to:1,afterFinishInternal:function(_691){ | |
6483 | v.forceRerendering(_691.element); | |
6484 | },beforeSetupInternal:function(_692){ | |
6485 | s.setStyle(_692.element,{"opacity":_692.options.from}); | |
6486 | s.showElement(_692.element); | |
6487 | }},_68e||{}); | |
6488 | return new v.Opacity(_68d,_68e); | |
6489 | }; | |
6490 | MochiKit.Visual.puff=function(_693,_694){ | |
6491 | var s=MochiKit.Style; | |
6492 | var v=MochiKit.Visual; | |
6493 | _693=MochiKit.DOM.getElement(_693); | |
6494 | var _697={position:s.getStyle(_693,"position"),top:_693.style.top,left:_693.style.left,width:_693.style.width,height:_693.style.height,opacity:s.getStyle(_693,"opacity")}; | |
6495 | _694=MochiKit.Base.update({beforeSetupInternal:function(_698){ | |
6496 | MochiKit.Position.absolutize(_698.effects[0].element); | |
6497 | },afterFinishInternal:function(_699){ | |
6498 | s.hideElement(_699.effects[0].element); | |
6499 | s.setStyle(_699.effects[0].element,_697); | |
6500 | },scaleContent:true,scaleFromCenter:true},_694||{}); | |
6501 | return new v.Parallel([new v.Scale(_693,200,{sync:true,scaleFromCenter:_694.scaleFromCenter,scaleContent:_694.scaleContent,restoreAfterFinish:true}),new v.Opacity(_693,{sync:true,to:0})],_694); | |
6502 | }; | |
6503 | MochiKit.Visual.blindUp=function(_69a,_69b){ | |
6504 | var d=MochiKit.DOM; | |
6505 | _69a=d.getElement(_69a); | |
6506 | var _69d=d.makeClipping(_69a); | |
6507 | _69b=MochiKit.Base.update({scaleContent:false,scaleX:false,restoreAfterFinish:true,afterFinishInternal:function(_69e){ | |
6508 | MochiKit.Style.hideElement(_69e.element); | |
6509 | d.undoClipping(_69e.element,_69d); | |
6510 | }},_69b||{}); | |
6511 | return new MochiKit.Visual.Scale(_69a,0,_69b); | |
6512 | }; | |
6513 | MochiKit.Visual.blindDown=function(_69f,_6a0){ | |
6514 | var d=MochiKit.DOM; | |
6515 | var s=MochiKit.Style; | |
6516 | _69f=d.getElement(_69f); | |
6517 | var _6a3=s.getElementDimensions(_69f); | |
6518 | var _6a4; | |
6519 | _6a0=MochiKit.Base.update({scaleContent:false,scaleX:false,scaleFrom:0,scaleMode:{originalHeight:_6a3.h,originalWidth:_6a3.w},restoreAfterFinish:true,afterSetupInternal:function(_6a5){ | |
6520 | _6a4=d.makeClipping(_6a5.element); | |
6521 | s.setStyle(_6a5.element,{height:"0px"}); | |
6522 | s.showElement(_6a5.element); | |
6523 | },afterFinishInternal:function(_6a6){ | |
6524 | d.undoClipping(_6a6.element,_6a4); | |
6525 | }},_6a0||{}); | |
6526 | return new MochiKit.Visual.Scale(_69f,100,_6a0); | |
6527 | }; | |
6528 | MochiKit.Visual.switchOff=function(_6a7,_6a8){ | |
6529 | var d=MochiKit.DOM; | |
6530 | _6a7=d.getElement(_6a7); | |
6531 | var _6aa=MochiKit.Style.getStyle(_6a7,"opacity"); | |
6532 | var _6ab; | |
6533 | _6a8=MochiKit.Base.update({duration:0.3,scaleFromCenter:true,scaleX:false,scaleContent:false,restoreAfterFinish:true,beforeSetupInternal:function(_6ac){ | |
6534 | d.makePositioned(_6ac.element); | |
6535 | _6ab=d.makeClipping(_6ac.element); | |
6536 | },afterFinishInternal:function(_6ad){ | |
6537 | MochiKit.Style.hideElement(_6ad.element); | |
6538 | d.undoClipping(_6ad.element,_6ab); | |
6539 | d.undoPositioned(_6ad.element); | |
6540 | MochiKit.Style.setStyle(_6ad.element,{"opacity":_6aa}); | |
6541 | }},_6a8||{}); | |
6542 | var v=MochiKit.Visual; | |
6543 | return new v.appear(_6a7,{duration:0.4,from:0,transition:v.Transitions.flicker,afterFinishInternal:function(_6af){ | |
6544 | new v.Scale(_6af.element,1,_6a8); | |
6545 | }}); | |
6546 | }; | |
6547 | MochiKit.Visual.dropOut=function(_6b0,_6b1){ | |
6548 | var d=MochiKit.DOM; | |
6549 | var s=MochiKit.Style; | |
6550 | _6b0=d.getElement(_6b0); | |
6551 | var _6b4={top:s.getStyle(_6b0,"top"),left:s.getStyle(_6b0,"left"),opacity:s.getStyle(_6b0,"opacity")}; | |
6552 | _6b1=MochiKit.Base.update({duration:0.5,distance:100,beforeSetupInternal:function(_6b5){ | |
6553 | d.makePositioned(_6b5.effects[0].element); | |
6554 | },afterFinishInternal:function(_6b6){ | |
6555 | s.hideElement(_6b6.effects[0].element); | |
6556 | d.undoPositioned(_6b6.effects[0].element); | |
6557 | s.setStyle(_6b6.effects[0].element,_6b4); | |
6558 | }},_6b1||{}); | |
6559 | var v=MochiKit.Visual; | |
6560 | return new v.Parallel([new v.Move(_6b0,{x:0,y:_6b1.distance,sync:true}),new v.Opacity(_6b0,{sync:true,to:0})],_6b1); | |
6561 | }; | |
6562 | MochiKit.Visual.shake=function(_6b8,_6b9){ | |
6563 | var d=MochiKit.DOM; | |
6564 | var v=MochiKit.Visual; | |
6565 | var s=MochiKit.Style; | |
6566 | _6b8=d.getElement(_6b8); | |
6567 | _6b9=MochiKit.Base.update({x:-20,y:0,duration:0.05,afterFinishInternal:function(_6bd){ | |
6568 | d.undoPositioned(_6bd.element); | |
6569 | s.setStyle(_6bd.element,_6be); | |
6570 | }},_6b9||{}); | |
6571 | var _6be={top:s.getStyle(_6b8,"top"),left:s.getStyle(_6b8,"left")}; | |
6572 | return new v.Move(_6b8,{x:20,y:0,duration:0.05,afterFinishInternal:function(_6bf){ | |
6573 | new v.Move(_6bf.element,{x:-40,y:0,duration:0.1,afterFinishInternal:function(_6c0){ | |
6574 | new v.Move(_6c0.element,{x:40,y:0,duration:0.1,afterFinishInternal:function(_6c1){ | |
6575 | new v.Move(_6c1.element,{x:-40,y:0,duration:0.1,afterFinishInternal:function(_6c2){ | |
6576 | new v.Move(_6c2.element,{x:40,y:0,duration:0.1,afterFinishInternal:function(_6c3){ | |
6577 | new v.Move(_6c3.element,_6b9); | |
6578 | }}); | |
6579 | }}); | |
6580 | }}); | |
6581 | }}); | |
6582 | }}); | |
6583 | }; | |
6584 | MochiKit.Visual.slideDown=function(_6c4,_6c5){ | |
6585 | var d=MochiKit.DOM; | |
6586 | var b=MochiKit.Base; | |
6587 | var s=MochiKit.Style; | |
6588 | _6c4=d.getElement(_6c4); | |
6589 | if(!_6c4.firstChild){ | |
6590 | throw "MochiKit.Visual.slideDown must be used on a element with a child"; | |
6591 | } | |
6592 | d.removeEmptyTextNodes(_6c4); | |
6593 | var _6c9=s.getStyle(_6c4.firstChild,"bottom")||0; | |
6594 | var _6ca=s.getElementDimensions(_6c4); | |
6595 | var _6cb; | |
6596 | _6c5=b.update({scaleContent:false,scaleX:false,scaleFrom:0,scaleMode:{originalHeight:_6ca.h,originalWidth:_6ca.w},restoreAfterFinish:true,afterSetupInternal:function(_6cc){ | |
6597 | d.makePositioned(_6cc.element); | |
6598 | d.makePositioned(_6cc.element.firstChild); | |
6599 | if(/Opera/.test(navigator.userAgent)){ | |
6600 | s.setStyle(_6cc.element,{top:""}); | |
6601 | } | |
6602 | _6cb=d.makeClipping(_6cc.element); | |
6603 | s.setStyle(_6cc.element,{height:"0px"}); | |
6604 | s.showElement(_6cc.element); | |
6605 | },afterUpdateInternal:function(_6cd){ | |
6606 | s.setStyle(_6cd.element.firstChild,{bottom:(_6cd.dims[0]-_6cd.element.clientHeight)+"px"}); | |
6607 | },afterFinishInternal:function(_6ce){ | |
6608 | d.undoClipping(_6ce.element,_6cb); | |
6609 | if(/MSIE/.test(navigator.userAgent)){ | |
6610 | d.undoPositioned(_6ce.element); | |
6611 | d.undoPositioned(_6ce.element.firstChild); | |
6612 | }else{ | |
6613 | d.undoPositioned(_6ce.element.firstChild); | |
6614 | d.undoPositioned(_6ce.element); | |
6615 | } | |
6616 | s.setStyle(_6ce.element.firstChild,{bottom:_6c9}); | |
6617 | }},_6c5||{}); | |
6618 | return new MochiKit.Visual.Scale(_6c4,100,_6c5); | |
6619 | }; | |
6620 | MochiKit.Visual.slideUp=function(_6cf,_6d0){ | |
6621 | var d=MochiKit.DOM; | |
6622 | var b=MochiKit.Base; | |
6623 | var s=MochiKit.Style; | |
6624 | _6cf=d.getElement(_6cf); | |
6625 | if(!_6cf.firstChild){ | |
6626 | throw "MochiKit.Visual.slideUp must be used on a element with a child"; | |
6627 | } | |
6628 | d.removeEmptyTextNodes(_6cf); | |
6629 | var _6d4=s.getStyle(_6cf.firstChild,"bottom"); | |
6630 | var _6d5; | |
6631 | _6d0=b.update({scaleContent:false,scaleX:false,scaleMode:"box",scaleFrom:100,restoreAfterFinish:true,beforeStartInternal:function(_6d6){ | |
6632 | d.makePositioned(_6d6.element); | |
6633 | d.makePositioned(_6d6.element.firstChild); | |
6634 | if(/Opera/.test(navigator.userAgent)){ | |
6635 | s.setStyle(_6d6.element,{top:""}); | |
6636 | } | |
6637 | _6d5=d.makeClipping(_6d6.element); | |
6638 | s.showElement(_6d6.element); | |
6639 | },afterUpdateInternal:function(_6d7){ | |
6640 | s.setStyle(_6d7.element.firstChild,{bottom:(_6d7.dims[0]-_6d7.element.clientHeight)+"px"}); | |
6641 | },afterFinishInternal:function(_6d8){ | |
6642 | s.hideElement(_6d8.element); | |
6643 | d.undoClipping(_6d8.element,_6d5); | |
6644 | d.undoPositioned(_6d8.element.firstChild); | |
6645 | d.undoPositioned(_6d8.element); | |
6646 | s.setStyle(_6d8.element.firstChild,{bottom:_6d4}); | |
6647 | }},_6d0||{}); | |
6648 | return new MochiKit.Visual.Scale(_6cf,0,_6d0); | |
6649 | }; | |
6650 | MochiKit.Visual.squish=function(_6d9,_6da){ | |
6651 | var d=MochiKit.DOM; | |
6652 | var b=MochiKit.Base; | |
6653 | var _6dd; | |
6654 | _6da=b.update({restoreAfterFinish:true,beforeSetupInternal:function(_6de){ | |
6655 | _6dd=d.makeClipping(_6de.element); | |
6656 | },afterFinishInternal:function(_6df){ | |
6657 | MochiKit.Style.hideElement(_6df.element); | |
6658 | d.undoClipping(_6df.element,_6dd); | |
6659 | }},_6da||{}); | |
6660 | return new MochiKit.Visual.Scale(_6d9,/Opera/.test(navigator.userAgent)?1:0,_6da); | |
6661 | }; | |
6662 | MochiKit.Visual.grow=function(_6e0,_6e1){ | |
6663 | var d=MochiKit.DOM; | |
6664 | var v=MochiKit.Visual; | |
6665 | var s=MochiKit.Style; | |
6666 | _6e0=d.getElement(_6e0); | |
6667 | _6e1=MochiKit.Base.update({direction:"center",moveTransition:v.Transitions.sinoidal,scaleTransition:v.Transitions.sinoidal,opacityTransition:v.Transitions.full,scaleContent:true,scaleFromCenter:false},_6e1||{}); | |
6668 | var _6e5={top:_6e0.style.top,left:_6e0.style.left,height:_6e0.style.height,width:_6e0.style.width,opacity:s.getStyle(_6e0,"opacity")}; | |
6669 | var dims=s.getElementDimensions(_6e0); | |
6670 | var _6e7,_6e8; | |
6671 | var _6e9,_6ea; | |
6672 | switch(_6e1.direction){ | |
6673 | case "top-left": | |
6674 | _6e7=_6e8=_6e9=_6ea=0; | |
6675 | break; | |
6676 | case "top-right": | |
6677 | _6e7=dims.w; | |
6678 | _6e8=_6ea=0; | |
6679 | _6e9=-dims.w; | |
6680 | break; | |
6681 | case "bottom-left": | |
6682 | _6e7=_6e9=0; | |
6683 | _6e8=dims.h; | |
6684 | _6ea=-dims.h; | |
6685 | break; | |
6686 | case "bottom-right": | |
6687 | _6e7=dims.w; | |
6688 | _6e8=dims.h; | |
6689 | _6e9=-dims.w; | |
6690 | _6ea=-dims.h; | |
6691 | break; | |
6692 | case "center": | |
6693 | _6e7=dims.w/2; | |
6694 | _6e8=dims.h/2; | |
6695 | _6e9=-dims.w/2; | |
6696 | _6ea=-dims.h/2; | |
6697 | break; | |
6698 | } | |
6699 | var _6eb=MochiKit.Base.update({beforeSetupInternal:function(_6ec){ | |
6700 | s.setStyle(_6ec.effects[0].element,{height:"0px"}); | |
6701 | s.showElement(_6ec.effects[0].element); | |
6702 | },afterFinishInternal:function(_6ed){ | |
6703 | d.undoClipping(_6ed.effects[0].element); | |
6704 | d.undoPositioned(_6ed.effects[0].element); | |
6705 | s.setStyle(_6ed.effects[0].element,_6e5); | |
6706 | }},_6e1||{}); | |
6707 | return new v.Move(_6e0,{x:_6e7,y:_6e8,duration:0.01,beforeSetupInternal:function(_6ee){ | |
6708 | s.hideElement(_6ee.element); | |
6709 | d.makeClipping(_6ee.element); | |
6710 | d.makePositioned(_6ee.element); | |
6711 | },afterFinishInternal:function(_6ef){ | |
6712 | new v.Parallel([new v.Opacity(_6ef.element,{sync:true,to:1,from:0,transition:_6e1.opacityTransition}),new v.Move(_6ef.element,{x:_6e9,y:_6ea,sync:true,transition:_6e1.moveTransition}),new v.Scale(_6ef.element,100,{scaleMode:{originalHeight:dims.h,originalWidth:dims.w},sync:true,scaleFrom:/Opera/.test(navigator.userAgent)?1:0,transition:_6e1.scaleTransition,scaleContent:_6e1.scaleContent,scaleFromCenter:_6e1.scaleFromCenter,restoreAfterFinish:true})],_6eb); | |
6713 | }}); | |
6714 | }; | |
6715 | MochiKit.Visual.shrink=function(_6f0,_6f1){ | |
6716 | var d=MochiKit.DOM; | |
6717 | var v=MochiKit.Visual; | |
6718 | var s=MochiKit.Style; | |
6719 | _6f0=d.getElement(_6f0); | |
6720 | _6f1=MochiKit.Base.update({direction:"center",moveTransition:v.Transitions.sinoidal,scaleTransition:v.Transitions.sinoidal,opacityTransition:v.Transitions.none,scaleContent:true,scaleFromCenter:false},_6f1||{}); | |
6721 | var _6f5={top:_6f0.style.top,left:_6f0.style.left,height:_6f0.style.height,width:_6f0.style.width,opacity:s.getStyle(_6f0,"opacity")}; | |
6722 | var dims=s.getElementDimensions(_6f0); | |
6723 | var _6f7,_6f8; | |
6724 | switch(_6f1.direction){ | |
6725 | case "top-left": | |
6726 | _6f7=_6f8=0; | |
6727 | break; | |
6728 | case "top-right": | |
6729 | _6f7=dims.w; | |
6730 | _6f8=0; | |
6731 | break; | |
6732 | case "bottom-left": | |
6733 | _6f7=0; | |
6734 | _6f8=dims.h; | |
6735 | break; | |
6736 | case "bottom-right": | |
6737 | _6f7=dims.w; | |
6738 | _6f8=dims.h; | |
6739 | break; | |
6740 | case "center": | |
6741 | _6f7=dims.w/2; | |
6742 | _6f8=dims.h/2; | |
6743 | break; | |
6744 | } | |
6745 | var _6f9; | |
6746 | var _6fa=MochiKit.Base.update({beforeStartInternal:function(_6fb){ | |
6747 | _6f9=d.makePositioned(_6fb.effects[0].element); | |
6748 | d.makeClipping(_6fb.effects[0].element); | |
6749 | },afterFinishInternal:function(_6fc){ | |
6750 | s.hideElement(_6fc.effects[0].element); | |
6751 | d.undoClipping(_6fc.effects[0].element,_6f9); | |
6752 | d.undoPositioned(_6fc.effects[0].element); | |
6753 | s.setStyle(_6fc.effects[0].element,_6f5); | |
6754 | }},_6f1||{}); | |
6755 | return new v.Parallel([new v.Opacity(_6f0,{sync:true,to:0,from:1,transition:_6f1.opacityTransition}),new v.Scale(_6f0,/Opera/.test(navigator.userAgent)?1:0,{sync:true,transition:_6f1.scaleTransition,scaleContent:_6f1.scaleContent,scaleFromCenter:_6f1.scaleFromCenter,restoreAfterFinish:true}),new v.Move(_6f0,{x:_6f7,y:_6f8,sync:true,transition:_6f1.moveTransition})],_6fa); | |
6756 | }; | |
6757 | MochiKit.Visual.pulsate=function(_6fd,_6fe){ | |
6758 | var d=MochiKit.DOM; | |
6759 | var v=MochiKit.Visual; | |
6760 | var b=MochiKit.Base; | |
6761 | var _702=MochiKit.Style.getStyle(_6fd,"opacity"); | |
6762 | _6fe=b.update({duration:3,from:0,afterFinishInternal:function(_703){ | |
6763 | MochiKit.Style.setStyle(_703.element,{"opacity":_702}); | |
6764 | }},_6fe||{}); | |
6765 | var _704=_6fe.transition||v.Transitions.sinoidal; | |
6766 | var _705=b.bind(function(pos){ | |
6767 | return _704(1-v.Transitions.pulse(pos,_6fe.pulses)); | |
6768 | },_704); | |
6769 | b.bind(_705,_704); | |
6770 | return new v.Opacity(_6fd,b.update({transition:_705},_6fe)); | |
6771 | }; | |
6772 | MochiKit.Visual.fold=function(_707,_708){ | |
6773 | var d=MochiKit.DOM; | |
6774 | var v=MochiKit.Visual; | |
6775 | var s=MochiKit.Style; | |
6776 | _707=d.getElement(_707); | |
6777 | var _70c={top:_707.style.top,left:_707.style.left,width:_707.style.width,height:_707.style.height}; | |
6778 | var _70d=d.makeClipping(_707); | |
6779 | _708=MochiKit.Base.update({scaleContent:false,scaleX:false,afterFinishInternal:function(_70e){ | |
6780 | new v.Scale(_707,1,{scaleContent:false,scaleY:false,afterFinishInternal:function(_70f){ | |
6781 | s.hideElement(_70f.element); | |
6782 | d.undoClipping(_70f.element,_70d); | |
6783 | s.setStyle(_70f.element,_70c); | |
6784 | }}); | |
6785 | }},_708||{}); | |
6786 | return new v.Scale(_707,5,_708); | |
6787 | }; | |
6788 | MochiKit.Visual.Color=MochiKit.Color.Color; | |
6789 | MochiKit.Visual.getElementsComputedStyle=MochiKit.DOM.computedStyle; | |
6790 | MochiKit.Visual.__new__=function(){ | |
6791 | var m=MochiKit.Base; | |
6792 | m.nameFunctions(this); | |
6793 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
6794 | }; | |
6795 | MochiKit.Visual.EXPORT=["roundElement","roundClass","tagifyText","multiple","toggle","Parallel","Opacity","Move","Scale","Highlight","ScrollTo","Morph","fade","appear","puff","blindUp","blindDown","switchOff","dropOut","shake","slideDown","slideUp","squish","grow","shrink","pulsate","fold"]; | |
6796 | MochiKit.Visual.EXPORT_OK=["Base","PAIRS"]; | |
6797 | MochiKit.Visual.__new__(); | |
6798 | MochiKit.Base._exportSymbols(this,MochiKit.Visual); | |
6799 | if(typeof (MochiKit)=="undefined"){ | |
6800 | MochiKit={}; | |
6801 | } | |
6802 | if(typeof (MochiKit.MochiKit)=="undefined"){ | |
6803 | MochiKit.MochiKit={}; | |
6804 | } | |
6805 | MochiKit.MochiKit.NAME="MochiKit.MochiKit"; | |
6806 | MochiKit.MochiKit.VERSION="1.4"; | |
6807 | MochiKit.MochiKit.__repr__=function(){ | |
6808 | return "["+this.NAME+" "+this.VERSION+"]"; | |
6809 | }; | |
6810 | MochiKit.MochiKit.toString=function(){ | |
6811 | return this.__repr__(); | |
6812 | }; | |
6813 | MochiKit.MochiKit.SUBMODULES=["Base","Iter","Logging","DateTime","Format","Async","DOM","Selector","Style","LoggingPane","Color","Signal","Position","Visual"]; | |
6814 | if(typeof (JSAN)!="undefined"||typeof (dojo)!="undefined"){ | |
6815 | if(typeof (dojo)!="undefined"){ | |
6816 | dojo.provide("MochiKit.MochiKit"); | |
6817 | dojo.require("MochiKit.*"); | |
6818 | } | |
6819 | if(typeof (JSAN)!="undefined"){ | |
6820 | (function(lst){ | |
6821 | for(var i=0;i<lst.length;i++){ | |
6822 | JSAN.use("MochiKit."+lst[i],[]); | |
6823 | } | |
6824 | })(MochiKit.MochiKit.SUBMODULES); | |
6825 | } | |
6826 | (function(){ | |
6827 | var _713=MochiKit.Base.extend; | |
6828 | var self=MochiKit.MochiKit; | |
6829 | var _715=self.SUBMODULES; | |
6830 | var _716=[]; | |
6831 | var _717=[]; | |
6832 | var _718={}; | |
6833 | var i,k,m,all; | |
6834 | for(i=0;i<_715.length;i++){ | |
6835 | m=MochiKit[_715[i]]; | |
6836 | _713(_716,m.EXPORT); | |
6837 | _713(_717,m.EXPORT_OK); | |
6838 | for(k in m.EXPORT_TAGS){ | |
6839 | _718[k]=_713(_718[k],m.EXPORT_TAGS[k]); | |
6840 | } | |
6841 | all=m.EXPORT_TAGS[":all"]; | |
6842 | if(!all){ | |
6843 | all=_713(null,m.EXPORT,m.EXPORT_OK); | |
6844 | } | |
6845 | var j; | |
6846 | for(j=0;j<all.length;j++){ | |
6847 | k=all[j]; | |
6848 | self[k]=m[k]; | |
6849 | } | |
6850 | } | |
6851 | self.EXPORT=_716; | |
6852 | self.EXPORT_OK=_717; | |
6853 | self.EXPORT_TAGS=_718; | |
6854 | }()); | |
6855 | }else{ | |
6856 | if(typeof (MochiKit.__compat__)=="undefined"){ | |
6857 | MochiKit.__compat__=true; | |
6858 | } | |
6859 | (function(){ | |
6860 | if(typeof (document)=="undefined"){ | |
6861 | return; | |
6862 | } | |
6863 | var _71e=document.getElementsByTagName("script"); | |
6864 | var _71f="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; | |
6865 | var base=null; | |
6866 | var _721=null; | |
6867 | var _722={}; | |
6868 | var i; | |
6869 | for(i=0;i<_71e.length;i++){ | |
6870 | var src=_71e[i].getAttribute("src"); | |
6871 | if(!src){ | |
6872 | continue; | |
6873 | } | |
6874 | _722[src]=true; | |
6875 | if(src.match(/MochiKit.js$/)){ | |
6876 | base=src.substring(0,src.lastIndexOf("MochiKit.js")); | |
6877 | _721=_71e[i]; | |
6878 | } | |
6879 | } | |
6880 | if(base===null){ | |
6881 | return; | |
6882 | } | |
6883 | var _725=MochiKit.MochiKit.SUBMODULES; | |
6884 | for(var i=0;i<_725.length;i++){ | |
6885 | if(MochiKit[_725[i]]){ | |
6886 | continue; | |
6887 | } | |
6888 | var uri=base+_725[i]+".js"; | |
6889 | if(uri in _722){ | |
6890 | continue; | |
6891 | } | |
6892 | if(document.documentElement&&document.documentElement.namespaceURI==_71f){ | |
6893 | var s=document.createElementNS(_71f,"script"); | |
6894 | s.setAttribute("id","MochiKit_"+base+_725[i]); | |
6895 | s.setAttribute("src",uri); | |
6896 | s.setAttribute("type","application/x-javascript"); | |
6897 | _721.parentNode.appendChild(s); | |
6898 | }else{ | |
6899 | document.write("<script src=\""+uri+"\" type=\"text/javascript\"></script>"); | |
6900 | } | |
6901 | } | |
6902 | })(); | |
6903 | } | |
6904 | ||
6905 | ||
6906 | /*** | |
6907 | ||
6908 | PlotKit.PlotKit 0.9.1 : PACKED VERSION | |
6909 | ||
6910 | THIS FILE IS AUTOMATICALLY GENERATED. If creating patches, please | |
6911 | diff against the source tree, not this file. | |
6912 | ||
6913 | For more information, <http://www.liquidx.net/plotkit/>. | |
6914 | ||
6915 | Copyright (c) 2006. Alastair Tse. | |
6916 | ||
6917 | ***/ | |
6918 | ||
6919 | try{ | |
6920 | if(typeof (MochiKit.Base)=="undefined"||typeof (MochiKit.DOM)=="undefined"||typeof (MochiKit.Color)=="undefined"||typeof (MochiKit.Format)=="undefined"){ | |
6921 | throw ""; | |
6922 | } | |
6923 | } | |
6924 | catch(e){ | |
6925 | throw "PlotKit depends on MochiKit.{Base,Color,DOM,Format}"; | |
6926 | } | |
6927 | MochiKit.Base.update(MochiKit.Color.Color.prototype,{asFillColor:function(){ | |
6928 | return this.lighterColorWithLevel(0.3); | |
6929 | },asStrokeColor:function(){ | |
6930 | return this.darkerColorWithLevel(0.1); | |
6931 | },asPointColor:function(){ | |
6932 | return this.lighterColorWithLevel(0.1); | |
6933 | }}); | |
6934 | if(typeof (PlotKit)=="undefined"){ | |
6935 | PlotKit={}; | |
6936 | } | |
6937 | PlotKit.NAME="PlotKit"; | |
6938 | PlotKit.VERSION="0.8"; | |
6939 | PlotKit.__repr__=function(){ | |
6940 | return "["+this.NAME+" "+this.VERSION+"]"; | |
6941 | }; | |
6942 | PlotKit.toString=function(){ | |
6943 | return this.__repr__(); | |
6944 | }; | |
6945 | if(typeof (PlotKit.Base)=="undefined"){ | |
6946 | PlotKit.Base={}; | |
6947 | } | |
6948 | PlotKit.Base.NAME="PlotKit.Base"; | |
6949 | PlotKit.Base.VERSION=PlotKit.VERSION; | |
6950 | PlotKit.Base.__repr__=function(){ | |
6951 | return "["+this.NAME+" "+this.VERSION+"]"; | |
6952 | }; | |
6953 | PlotKit.Base.toString=function(){ | |
6954 | return this.__repr__(); | |
6955 | }; | |
6956 | PlotKit.Base.usingPrototype=function(){ | |
6957 | try{ | |
6958 | return (typeof (Object.extend)=="function"); | |
6959 | } | |
6960 | catch(e){ | |
6961 | return false; | |
6962 | } | |
6963 | }; | |
6964 | MochiKit.Base.update(PlotKit.Base,{roundInterval:function(_1,_2,_3){ | |
6965 | var _4=MochiKit.Format.roundToFixed; | |
6966 | var _5=_1/_2; | |
6967 | return parseFloat(_4(_5,_3)); | |
6968 | },collapse:function(_6){ | |
6969 | var m=MochiKit.Base; | |
6970 | var _8=new Array(); | |
6971 | for(var i=0;i<_6.length;i++){ | |
6972 | _8=m.concat(_8,_6[i]); | |
6973 | } | |
6974 | if(PlotKit.Base.usingPrototype()){ | |
6975 | delete _8.extend; | |
6976 | delete _8.from; | |
6977 | delete _8.inspect; | |
6978 | } | |
6979 | return _8; | |
6980 | },uniq:function(_10){ | |
6981 | var m=MochiKit.Base; | |
6982 | if(!m.isArrayLike(_10)||(_10.length<1)){ | |
6983 | return new Array(); | |
6984 | } | |
6985 | var _11=new Array(); | |
6986 | var _12=_10[0]; | |
6987 | _11.push(_10[0]); | |
6988 | for(var i=1;i<_10.length;i++){ | |
6989 | if(m.compare(_10[i],_12)!=0){ | |
6990 | _12=_10[i]; | |
6991 | _11.push(_10[i]); | |
6992 | } | |
6993 | } | |
6994 | return _11; | |
6995 | },colorScheme:function(){ | |
6996 | var mb=MochiKit.Base; | |
6997 | var mc=MochiKit.Color; | |
6998 | var _15=["red","orange","yellow","green","cyan","blue","purple","magenta"]; | |
6999 | var _16=function(_17){ | |
7000 | return mc.Color[_17+"Color"](); | |
7001 | }; | |
7002 | return mb.map(_16,_15); | |
7003 | },baseDarkPrimaryColors:function(){ | |
7004 | var _18=MochiKit.Color.Color.fromHexString; | |
7005 | return [_18("#ad3f40"),_18("#ddac2c"),_18("#dfdd0c"),_18("#5276c4"),_18("#739c5a")]; | |
7006 | },basePrimaryColors:function(){ | |
7007 | var _19=MochiKit.Color.Color.fromHexString; | |
7008 | return [_19("#d24c4d"),_19("#f2b32f"),_19("#ece90e"),_19("#5d83da"),_19("#78a15d")]; | |
7009 | },baseBlueColors:function(){ | |
7010 | var _20=MochiKit.Color.Color.fromHexString; | |
7011 | return [_20("#4b6b94"),_20("#5d81b4"),_20("#acbad2")]; | |
7012 | },palette:function(_21,_22,_23,_24){ | |
7013 | var _25=MochiKit.Base.isUndefinedOrNull; | |
7014 | var _26=new Array(); | |
7015 | if(_25(_24)){ | |
7016 | _24=0.1; | |
7017 | } | |
7018 | if(_25(_23)){ | |
7019 | _23=0.4; | |
7020 | } | |
7021 | if(_25(_22)){ | |
7022 | _22=-0.2; | |
7023 | } | |
7024 | var _27=_22; | |
7025 | while(_27<=_23){ | |
7026 | _26.push(_27); | |
7027 | _27+=_24; | |
7028 | } | |
7029 | var _28=function(_29,_30){ | |
7030 | return _29.lighterColorWithLevel(_30); | |
7031 | }; | |
7032 | return MochiKit.Base.map(partial(_28,_21),_26); | |
7033 | },excanvasSupported:function(){ | |
7034 | if(/MSIE/.test(navigator.userAgent)&&!window.opera){ | |
7035 | return true; | |
7036 | } | |
7037 | return false; | |
7038 | },findPosX:function(obj){ | |
7039 | var _32=0; | |
7040 | if(obj.offsetParent){ | |
7041 | while(obj.offsetParent){ | |
7042 | _32+=obj.offsetLeft; | |
7043 | obj=obj.offsetParent; | |
7044 | } | |
7045 | }else{ | |
7046 | if(obj.x){ | |
7047 | _32+=obj.x; | |
7048 | } | |
7049 | } | |
7050 | return _32; | |
7051 | },findPosY:function(obj){ | |
7052 | var _33=0; | |
7053 | if(obj.offsetParent){ | |
7054 | while(obj.offsetParent){ | |
7055 | _33+=obj.offsetTop; | |
7056 | obj=obj.offsetParent; | |
7057 | } | |
7058 | }else{ | |
7059 | if(obj.y){ | |
7060 | _33+=obj.y; | |
7061 | } | |
7062 | } | |
7063 | return _33; | |
7064 | },isFuncLike:function(obj){ | |
7065 | return (typeof (obj)=="function"); | |
7066 | }}); | |
7067 | PlotKit.Base.map=function(fn,lst){ | |
7068 | if(PlotKit.Base.usingPrototype()){ | |
7069 | var _36=[]; | |
7070 | for(var x in lst){ | |
7071 | if(typeof (lst[x])=="function"){ | |
7072 | continue; | |
7073 | } | |
7074 | _36.push(fn(lst[x])); | |
7075 | } | |
7076 | return _36; | |
7077 | }else{ | |
7078 | return MochiKit.Base.map(fn,lst); | |
7079 | } | |
7080 | }; | |
7081 | PlotKit.Base.items=function(lst){ | |
7082 | if(PlotKit.Base.usingPrototype()){ | |
7083 | var _38=[]; | |
7084 | for(var x in lst){ | |
7085 | if(typeof (lst[x])=="function"){ | |
7086 | continue; | |
7087 | } | |
7088 | _38.push([x,lst[x]]); | |
7089 | } | |
7090 | return _38; | |
7091 | }else{ | |
7092 | return MochiKit.Base.items(lst); | |
7093 | } | |
7094 | }; | |
7095 | PlotKit.Base.keys=function(lst){ | |
7096 | if(PlotKit.Base.usingPrototype()){ | |
7097 | var _39=[]; | |
7098 | for(var x in lst){ | |
7099 | if(typeof (lst[x])=="function"){ | |
7100 | continue; | |
7101 | } | |
7102 | _39.push(x); | |
7103 | } | |
7104 | return _39; | |
7105 | }else{ | |
7106 | return MochiKit.Base.keys(lst); | |
7107 | } | |
7108 | }; | |
7109 | PlotKit.Base.baseColors=function(){ | |
7110 | var _40=MochiKit.Color.Color.fromHexString; | |
7111 | return [_40("#476fb2"),_40("#be2c2b"),_40("#85b730"),_40("#734a99"),_40("#26a1c5"),_40("#fb8707"),_40("#000000")]; | |
7112 | }; | |
7113 | PlotKit.Base.officeBaseStyle={"axisLineWidth":2,"axisLabelColor":Color.grayColor(),"axisLineColor":Color.whiteColor(),"padding":{top:5,bottom:10,left:30,right:30}}; | |
7114 | MochiKit.Base.update(PlotKit.Base,{officeBlue:function(){ | |
7115 | var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[0]),"backgroundColor":PlotKit.Base.baseColors()[0].lighterColorWithLevel(0.45)}; | |
7116 | MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); | |
7117 | return r; | |
7118 | },officeRed:function(){ | |
7119 | var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[1]),"backgroundColor":PlotKit.Base.baseColors()[1].lighterColorWithLevel(0.5)}; | |
7120 | MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); | |
7121 | return r; | |
7122 | },officeGreen:function(){ | |
7123 | var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[2]),"backgroundColor":PlotKit.Base.baseColors()[2].lighterColorWithLevel(0.5)}; | |
7124 | MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); | |
7125 | return r; | |
7126 | },officePurple:function(){ | |
7127 | var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[3]),"backgroundColor":PlotKit.Base.baseColors()[3].lighterColorWithLevel(0.5)}; | |
7128 | MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); | |
7129 | return r; | |
7130 | },officeCyan:function(){ | |
7131 | var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[4]),"backgroundColor":PlotKit.Base.baseColors()[4].lighterColorWithLevel(0.5)}; | |
7132 | MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); | |
7133 | return r; | |
7134 | },officeOrange:function(){ | |
7135 | var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[5]),"backgroundColor":PlotKit.Base.baseColors()[5].lighterColorWithLevel(0.4)}; | |
7136 | MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); | |
7137 | return r; | |
7138 | },officeBlack:function(){ | |
7139 | var r={"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[6],0,0.6),"backgroundColor":PlotKit.Base.baseColors()[6].lighterColorWithLevel(0.9)}; | |
7140 | MochiKit.Base.update(r,PlotKit.Base.officeBaseStyle); | |
7141 | return r; | |
7142 | }}); | |
7143 | PlotKit.Base.EXPORT=["baseColors","collapse","colorScheme","findPosX","findPosY","officeBaseStyle","officeBlue","officeRed","officeGreen","officePurple","officeCyan","officeOrange","officeBlack","roundInterval","uniq","isFuncLike","excanvasSupported"]; | |
7144 | PlotKit.Base.EXPORT_OK=[]; | |
7145 | PlotKit.Base.__new__=function(){ | |
7146 | var m=MochiKit.Base; | |
7147 | m.nameFunctions(this); | |
7148 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
7149 | }; | |
7150 | PlotKit.Base.__new__(); | |
7151 | MochiKit.Base._exportSymbols(this,PlotKit.Base); | |
7152 | try{ | |
7153 | if(typeof (PlotKit.Base)=="undefined"){ | |
7154 | throw ""; | |
7155 | } | |
7156 | } | |
7157 | catch(e){ | |
7158 | throw "PlotKit.Layout depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.Base"; | |
7159 | } | |
7160 | if(typeof (PlotKit.Layout)=="undefined"){ | |
7161 | PlotKit.Layout={}; | |
7162 | } | |
7163 | PlotKit.Layout.NAME="PlotKit.Layout"; | |
7164 | PlotKit.Layout.VERSION=PlotKit.VERSION; | |
7165 | PlotKit.Layout.__repr__=function(){ | |
7166 | return "["+this.NAME+" "+this.VERSION+"]"; | |
7167 | }; | |
7168 | PlotKit.Layout.toString=function(){ | |
7169 | return this.__repr__(); | |
7170 | }; | |
7171 | PlotKit.Layout.valid_styles=["bar","line","pie","point"]; | |
7172 | PlotKit.Layout=function(_42,_43){ | |
7173 | 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}; | |
7174 | this.style=_42; | |
7175 | MochiKit.Base.update(this.options,_43?_43:{}); | |
7176 | if(!MochiKit.Base.isUndefinedOrNull(this.options.xAxis)){ | |
7177 | this.minxval=this.options.xAxis[0]; | |
7178 | this.maxxval=this.options.xAxis[1]; | |
7179 | this.xscale=this.maxxval-this.minxval; | |
7180 | }else{ | |
7181 | this.minxval=0; | |
7182 | this.maxxval=null; | |
7183 | this.xscale=null; | |
7184 | } | |
7185 | if(!MochiKit.Base.isUndefinedOrNull(this.options.yAxis)){ | |
7186 | this.minyval=this.options.yAxis[0]; | |
7187 | this.maxyval=this.options.yAxis[1]; | |
7188 | this.yscale=this.maxyval-this.minyval; | |
7189 | }else{ | |
7190 | this.minyval=0; | |
7191 | this.maxyval=null; | |
7192 | this.yscale=null; | |
7193 | } | |
7194 | this.bars=new Array(); | |
7195 | this.points=new Array(); | |
7196 | this.slices=new Array(); | |
7197 | this.xticks=new Array(); | |
7198 | this.yticks=new Array(); | |
7199 | this.datasets=new Array(); | |
7200 | this.minxdelta=0; | |
7201 | this.xrange=1; | |
7202 | this.yrange=1; | |
7203 | this.hitTestCache={x2maxy:null}; | |
7204 | }; | |
7205 | PlotKit.Layout.prototype.addDataset=function(_44,_45){ | |
7206 | this.datasets[_44]=_45; | |
7207 | }; | |
7208 | PlotKit.Layout.prototype.removeDataset=function(_46,_47){ | |
7209 | delete this.datasets[_46]; | |
7210 | }; | |
7211 | PlotKit.Layout.prototype.addDatasetFromTable=function(_48,_49,_50,_51,_52){ | |
7212 | var _53=MochiKit.Base.isUndefinedOrNull; | |
7213 | var _54=MochiKit.DOM.scrapeText; | |
7214 | var _55=MochiKit.Format.strip; | |
7215 | if(_53(_50)){ | |
7216 | _50=0; | |
7217 | } | |
7218 | if(_53(_51)){ | |
7219 | _51=1; | |
7220 | } | |
7221 | if(_53(_52)){ | |
7222 | _52=-1; | |
7223 | } | |
7224 | var _56=_49.tBodies[0].rows; | |
7225 | var _57=new Array(); | |
7226 | var _58=new Array(); | |
7227 | if(!_53(_56)){ | |
7228 | for(var i=0;i<_56.length;i++){ | |
7229 | _57.push([parseFloat(_55(_54(_56[i].cells[_50]))),parseFloat(_55(_54(_56[i].cells[_51])))]); | |
7230 | if(_52>=0){ | |
7231 | _58.push({v:parseFloat(_55(_54(_56[i].cells[_50]))),label:_55(_54(_56[i].cells[_52]))}); | |
7232 | } | |
7233 | } | |
7234 | this.addDataset(_48,_57); | |
7235 | if(_52>=0){ | |
7236 | this.options.xTicks=_58; | |
7237 | } | |
7238 | return true; | |
7239 | } | |
7240 | return false; | |
7241 | }; | |
7242 | PlotKit.Layout.prototype.evaluate=function(){ | |
7243 | this._evaluateLimits(); | |
7244 | this._evaluateScales(); | |
7245 | if(this.style=="bar"){ | |
7246 | if(this.options.barOrientation=="horizontal"){ | |
7247 | this._evaluateHorizBarCharts(); | |
7248 | }else{ | |
7249 | this._evaluateBarCharts(); | |
7250 | } | |
7251 | this._evaluateBarTicks(); | |
7252 | }else{ | |
7253 | if(this.style=="line"){ | |
7254 | this._evaluateLineCharts(); | |
7255 | this._evaluateLineTicks(); | |
7256 | }else{ | |
7257 | if(this.style=="pie"){ | |
7258 | this._evaluatePieCharts(); | |
7259 | this._evaluatePieTicks(); | |
7260 | } | |
7261 | } | |
7262 | } | |
7263 | }; | |
7264 | PlotKit.Layout.prototype.hitTest=function(x,y){ | |
7265 | var f=MochiKit.Format.twoDigitFloat; | |
7266 | if((this.style=="bar")&&this.bars&&(this.bars.length>0)){ | |
7267 | for(var i=0;i<this.bars.length;i++){ | |
7268 | var bar=this.bars[i]; | |
7269 | if((x>=bar.x)&&(x<=bar.x+bar.w)&&(y>=bar.y)&&(y-bar.y<=bar.h)){ | |
7270 | return bar; | |
7271 | } | |
7272 | } | |
7273 | }else{ | |
7274 | if(this.style=="line"){ | |
7275 | if(this.hitTestCache.x2maxy==null){ | |
7276 | this._regenerateHitTestCache(); | |
7277 | } | |
7278 | var _62=x/this.xscale; | |
7279 | var _63=this.hitTestCache.xvalues; | |
7280 | var _64=null; | |
7281 | var _65=null; | |
7282 | for(var i=1;i<_63.length;i++){ | |
7283 | if(_63[i]>_62){ | |
7284 | _64=_63[i-1]; | |
7285 | _65=_63[i]; | |
7286 | break; | |
7287 | } | |
7288 | } | |
7289 | if((_64!=null)){ | |
7290 | var _66=this.hitTestCache.x2maxy[_64]; | |
7291 | var _67=this.hitTestCache.x2maxy[_65]; | |
7292 | var _68=(1-y)/this.yscale; | |
7293 | var _69=(_67-_66)/(_65-_64); | |
7294 | var _70=_66+_69*(_62-_64); | |
7295 | if(_70>=_68){ | |
7296 | var obj={xval:_62,yval:_68,xafter:_65,yafter:_67,xbefore:_64,ybefore:_66,yprojected:_70}; | |
7297 | return obj; | |
7298 | } | |
7299 | } | |
7300 | }else{ | |
7301 | if(this.style=="pie"){ | |
7302 | var _71=Math.sqrt((y-0.5)*(y-0.5)+(x-0.5)*(x-0.5)); | |
7303 | if(_71>this.options.pieRadius){ | |
7304 | return null; | |
7305 | } | |
7306 | var _72=Math.atan2(y-0.5,x-0.5)-Math.PI/2; | |
7307 | for(var i=0;i<this.slices.length;i++){ | |
7308 | var _73=this.slices[i]; | |
7309 | if(_73.startAngle<_72&&_73.endAngle>=_72){ | |
7310 | return _73; | |
7311 | } | |
7312 | } | |
7313 | } | |
7314 | } | |
7315 | } | |
7316 | return null; | |
7317 | }; | |
7318 | PlotKit.Layout.prototype.rectForX=function(x){ | |
7319 | return null; | |
7320 | }; | |
7321 | PlotKit.Layout.prototype.angleRangeForX=function(x){ | |
7322 | return null; | |
7323 | }; | |
7324 | PlotKit.Layout.prototype._evaluateLimits=function(){ | |
7325 | var map=PlotKit.Base.map; | |
7326 | var _75=PlotKit.Base.items; | |
7327 | var _76=MochiKit.Base.itemgetter; | |
7328 | var _77=PlotKit.Base.collapse; | |
7329 | var _78=MochiKit.Base.listMin; | |
7330 | var _79=MochiKit.Base.listMax; | |
7331 | var _80=MochiKit.Base.isUndefinedOrNull; | |
7332 | var all=_77(map(_76(1),_75(this.datasets))); | |
7333 | if(_80(this.options.xAxis)){ | |
7334 | if(this.options.xOriginIsZero){ | |
7335 | this.minxval=0; | |
7336 | }else{ | |
7337 | this.minxval=_78(map(parseFloat,map(_76(0),all))); | |
7338 | } | |
7339 | this.maxxval=_79(map(parseFloat,map(_76(0),all))); | |
7340 | }else{ | |
7341 | this.minxval=this.options.xAxis[0]; | |
7342 | this.maxxval=this.options.xAxis[1]; | |
7343 | this.xscale=this.maxval-this.minxval; | |
7344 | } | |
7345 | if(_80(this.options.yAxis)){ | |
7346 | if(this.options.yOriginIsZero){ | |
7347 | this.minyval=0; | |
7348 | }else{ | |
7349 | this.minyval=_78(map(parseFloat,map(_76(1),all))); | |
7350 | } | |
7351 | this.maxyval=_79(map(parseFloat,map(_76(1),all))); | |
7352 | }else{ | |
7353 | this.minyval=this.options.yAxis[0]; | |
7354 | this.maxyval=this.options.yAxis[1]; | |
7355 | this.yscale=this.maxyval-this.minyval; | |
7356 | } | |
7357 | }; | |
7358 | PlotKit.Layout.prototype._evaluateScales=function(){ | |
7359 | var _82=MochiKit.Base.isUndefinedOrNull; | |
7360 | this.xrange=this.maxxval-this.minxval; | |
7361 | if(this.xrange==0){ | |
7362 | this.xscale=1; | |
7363 | }else{ | |
7364 | this.xscale=1/this.xrange; | |
7365 | } | |
7366 | this.yrange=this.maxyval-this.minyval; | |
7367 | if(this.yrange==0){ | |
7368 | this.yscale=1; | |
7369 | }else{ | |
7370 | this.yscale=1/this.yrange; | |
7371 | } | |
7372 | }; | |
7373 | PlotKit.Layout.prototype._uniqueXValues=function(){ | |
7374 | var _83=PlotKit.Base.collapse; | |
7375 | var map=PlotKit.Base.map; | |
7376 | var _84=PlotKit.Base.uniq; | |
7377 | var _85=MochiKit.Base.itemgetter; | |
7378 | var _86=PlotKit.Base.items; | |
7379 | var _87=map(parseFloat,map(_85(0),_83(map(_85(1),_86(this.datasets))))); | |
7380 | _87.sort(MochiKit.Base.compare); | |
7381 | return _84(_87); | |
7382 | }; | |
7383 | PlotKit.Layout.prototype._evaluateBarCharts=function(){ | |
7384 | var _88=PlotKit.Base.items; | |
7385 | var _89=_88(this.datasets).length; | |
7386 | var _90=10000000; | |
7387 | var _91=this._uniqueXValues(); | |
7388 | for(var i=1;i<_91.length;i++){ | |
7389 | _90=Math.min(Math.abs(_91[i]-_91[i-1]),_90); | |
7390 | } | |
7391 | var _92=0; | |
7392 | var _93=0; | |
7393 | var _94=0; | |
7394 | if(_91.length==1){ | |
7395 | _90=1; | |
7396 | this.xscale=1; | |
7397 | this.minxval=_91[0]; | |
7398 | _92=1*this.options.barWidthFillFraction; | |
7399 | _93=_92/_89; | |
7400 | _94=(1-this.options.barWidthFillFraction)/2; | |
7401 | }else{ | |
7402 | if(this.xrange==1){ | |
7403 | this.xscale=0.5; | |
7404 | }else{ | |
7405 | if(this.xrange==2){ | |
7406 | this.xscale=1/3; | |
7407 | }else{ | |
7408 | this.xscale=(1-_90/this.xrange)/this.xrange; | |
7409 | } | |
7410 | } | |
7411 | _92=_90*this.xscale*this.options.barWidthFillFraction; | |
7412 | _93=_92/_89; | |
7413 | _94=_90*this.xscale*(1-this.options.barWidthFillFraction)/2; | |
7414 | } | |
7415 | this.minxdelta=_90; | |
7416 | this.bars=new Array(); | |
7417 | var i=0; | |
7418 | for(var _95 in this.datasets){ | |
7419 | var _96=this.datasets[_95]; | |
7420 | if(PlotKit.Base.isFuncLike(_96)){ | |
7421 | continue; | |
7422 | } | |
7423 | for(var j=0;j<_96.length;j++){ | |
7424 | var _98=_96[j]; | |
7425 | var _99={x:((parseFloat(_98[0])-this.minxval)*this.xscale)+(i*_93)+_94,y:1-((parseFloat(_98[1])-this.minyval)*this.yscale),w:_93,h:((parseFloat(_98[1])-this.minyval)*this.yscale),xval:parseFloat(_98[0]),yval:parseFloat(_98[1]),name:_95}; | |
7426 | if((_99.x>=0)&&(_99.x<=1)&&(_99.y>=0)&&(_99.y<=1)){ | |
7427 | this.bars.push(_99); | |
7428 | } | |
7429 | } | |
7430 | i++; | |
7431 | } | |
7432 | }; | |
7433 | PlotKit.Layout.prototype._evaluateHorizBarCharts=function(){ | |
7434 | var _100=PlotKit.Base.items; | |
7435 | var _101=_100(this.datasets).length; | |
7436 | var _102=10000000; | |
7437 | var _103=this._uniqueXValues(); | |
7438 | for(var i=1;i<_103.length;i++){ | |
7439 | _102=Math.min(Math.abs(_103[i]-_103[i-1]),_102); | |
7440 | } | |
7441 | var _104=0; | |
7442 | var _105=0; | |
7443 | var _106=0; | |
7444 | if(_103.length==1){ | |
7445 | _102=1; | |
7446 | this.xscale=1; | |
7447 | this.minxval=_103[0]; | |
7448 | _104=1*this.options.barWidthFillFraction; | |
7449 | _105=_104/_101; | |
7450 | _106=(1-this.options.barWidthFillFraction)/2; | |
7451 | }else{ | |
7452 | this.xscale=(1-_102/this.xrange)/this.xrange; | |
7453 | _104=_102*this.xscale*this.options.barWidthFillFraction; | |
7454 | _105=_104/_101; | |
7455 | _106=_102*this.xscale*(1-this.options.barWidthFillFraction)/2; | |
7456 | } | |
7457 | this.minxdelta=_102; | |
7458 | this.bars=new Array(); | |
7459 | var i=0; | |
7460 | for(var _107 in this.datasets){ | |
7461 | var _108=this.datasets[_107]; | |
7462 | if(PlotKit.Base.isFuncLike(_108)){ | |
7463 | continue; | |
7464 | } | |
7465 | for(var j=0;j<_108.length;j++){ | |
7466 | var item=_108[j]; | |
7467 | var rect={y:((parseFloat(item[0])-this.minxval)*this.xscale)+(i*_105)+_106,x:0,h:_105,w:((parseFloat(item[1])-this.minyval)*this.yscale),xval:parseFloat(item[0]),yval:parseFloat(item[1]),name:_107}; | |
7468 | if(rect.y<=0){ | |
7469 | rect.y=0; | |
7470 | } | |
7471 | if(rect.y>=1){ | |
7472 | rect.y=1; | |
7473 | } | |
7474 | if((rect.x>=0)&&(rect.x<=1)){ | |
7475 | this.bars.push(rect); | |
7476 | } | |
7477 | } | |
7478 | i++; | |
7479 | } | |
7480 | }; | |
7481 | PlotKit.Layout.prototype._evaluateLineCharts=function(){ | |
7482 | var _111=PlotKit.Base.items; | |
7483 | var _112=_111(this.datasets).length; | |
7484 | this.points=new Array(); | |
7485 | var i=0; | |
7486 | for(var _113 in this.datasets){ | |
7487 | var _114=this.datasets[_113]; | |
7488 | if(PlotKit.Base.isFuncLike(_114)){ | |
7489 | continue; | |
7490 | } | |
7491 | _114.sort(function(a,b){ | |
7492 | return compare(parseFloat(a[0]),parseFloat(b[0])); | |
7493 | }); | |
7494 | for(var j=0;j<_114.length;j++){ | |
7495 | var item=_114[j]; | |
7496 | var _117={x:((parseFloat(item[0])-this.minxval)*this.xscale),y:1-((parseFloat(item[1])-this.minyval)*this.yscale),xval:parseFloat(item[0]),yval:parseFloat(item[1]),name:_113}; | |
7497 | if(_117.y<=0){ | |
7498 | _117.y=0; | |
7499 | } | |
7500 | if(_117.y>=1){ | |
7501 | _117.y=1; | |
7502 | } | |
7503 | if((_117.x>=0)&&(_117.x<=1)){ | |
7504 | this.points.push(_117); | |
7505 | } | |
7506 | } | |
7507 | i++; | |
7508 | } | |
7509 | }; | |
7510 | PlotKit.Layout.prototype._evaluatePieCharts=function(){ | |
7511 | var _118=PlotKit.Base.items; | |
7512 | var sum=MochiKit.Iter.sum; | |
7513 | var _120=MochiKit.Base.itemgetter; | |
7514 | var _121=_118(this.datasets).length; | |
7515 | var _122=_118(this.datasets)[0][1]; | |
7516 | var _123=sum(map(_120(1),_122)); | |
7517 | this.slices=new Array(); | |
7518 | var _124=0; | |
7519 | for(var i=0;i<_122.length;i++){ | |
7520 | var _125=_122[i][1]/_123; | |
7521 | var _126=_124*Math.PI*2; | |
7522 | var _127=(_124+_125)*Math.PI*2; | |
7523 | var _128={fraction:_125,xval:_122[i][0],yval:_122[i][1],startAngle:_126,endAngle:_127}; | |
7524 | if(_122[i][1]!=0){ | |
7525 | this.slices.push(_128); | |
7526 | } | |
7527 | _124+=_125; | |
7528 | } | |
7529 | }; | |
7530 | PlotKit.Layout.prototype._evaluateLineTicksForXAxis=function(){ | |
7531 | var _129=MochiKit.Base.isUndefinedOrNull; | |
7532 | if(this.options.xTicks){ | |
7533 | this.xticks=new Array(); | |
7534 | var _130=function(tick){ | |
7535 | var _132=tick.label; | |
7536 | if(_129(_132)){ | |
7537 | _132=tick.v.toString(); | |
7538 | } | |
7539 | var pos=this.xscale*(tick.v-this.minxval); | |
7540 | if((pos>=0)&&(pos<=1)){ | |
7541 | this.xticks.push([pos,_132]); | |
7542 | } | |
7543 | }; | |
7544 | MochiKit.Iter.forEach(this.options.xTicks,bind(_130,this)); | |
7545 | }else{ | |
7546 | if(this.options.xNumberOfTicks){ | |
7547 | var _134=this._uniqueXValues(); | |
7548 | var _135=this.xrange/this.options.xNumberOfTicks; | |
7549 | var _136=0; | |
7550 | this.xticks=new Array(); | |
7551 | for(var i=0;i<=_134.length;i++){ | |
7552 | if((_134[i]-this.minxval)>=(_136*_135)){ | |
7553 | var pos=this.xscale*(_134[i]-this.minxval); | |
7554 | if((pos>1)||(pos<0)){ | |
7555 | continue; | |
7556 | } | |
7557 | this.xticks.push([pos,_134[i]]); | |
7558 | _136++; | |
7559 | } | |
7560 | if(_136>this.options.xNumberOfTicks){ | |
7561 | break; | |
7562 | } | |
7563 | } | |
7564 | } | |
7565 | } | |
7566 | }; | |
7567 | PlotKit.Layout.prototype._evaluateLineTicksForYAxis=function(){ | |
7568 | var _137=MochiKit.Base.isUndefinedOrNull; | |
7569 | if(this.options.yTicks){ | |
7570 | this.yticks=new Array(); | |
7571 | var _138=function(tick){ | |
7572 | var _139=tick.label; | |
7573 | if(_137(_139)){ | |
7574 | _139=tick.v.toString(); | |
7575 | } | |
7576 | var pos=1-(this.yscale*(tick.v-this.minyval)); | |
7577 | if((pos>=0)&&(pos<=1)){ | |
7578 | this.yticks.push([pos,_139]); | |
7579 | } | |
7580 | }; | |
7581 | MochiKit.Iter.forEach(this.options.yTicks,bind(_138,this)); | |
7582 | }else{ | |
7583 | if(this.options.yNumberOfTicks){ | |
7584 | this.yticks=new Array(); | |
7585 | var _140=PlotKit.Base.roundInterval; | |
7586 | var prec=this.options.yTickPrecision; | |
7587 | var _142=_140(this.yrange,this.options.yNumberOfTicks,prec); | |
7588 | for(var i=0;i<=this.options.yNumberOfTicks;i++){ | |
7589 | var yval=this.minyval+(i*_142); | |
7590 | var pos=1-((yval-this.minyval)*this.yscale); | |
7591 | if((pos>1)||(pos<0)){ | |
7592 | continue; | |
7593 | } | |
7594 | this.yticks.push([pos,MochiKit.Format.roundToFixed(yval,prec)]); | |
7595 | } | |
7596 | } | |
7597 | } | |
7598 | }; | |
7599 | PlotKit.Layout.prototype._evaluateLineTicks=function(){ | |
7600 | this._evaluateLineTicksForXAxis(); | |
7601 | this._evaluateLineTicksForYAxis(); | |
7602 | }; | |
7603 | PlotKit.Layout.prototype._evaluateBarTicks=function(){ | |
7604 | this._evaluateLineTicks(); | |
7605 | var _144=function(tick){ | |
7606 | return [tick[0]+(this.minxdelta*this.xscale)/2,tick[1]]; | |
7607 | }; | |
7608 | this.xticks=MochiKit.Base.map(bind(_144,this),this.xticks); | |
7609 | if(this.options.barOrientation=="horizontal"){ | |
7610 | var _145=this.xticks; | |
7611 | this.xticks=this.yticks; | |
7612 | this.yticks=_145; | |
7613 | var _146=function(tick){ | |
7614 | return [1-tick[0],tick[1]]; | |
7615 | }; | |
7616 | this.xticks=MochiKit.Base.map(_146,this.xticks); | |
7617 | } | |
7618 | }; | |
7619 | PlotKit.Layout.prototype._evaluatePieTicks=function(){ | |
7620 | var _147=MochiKit.Base.isUndefinedOrNull; | |
7621 | var _148=MochiKit.Format.numberFormatter("#%"); | |
7622 | this.xticks=new Array(); | |
7623 | if(this.options.xTicks){ | |
7624 | var _149=new Array(); | |
7625 | for(var i=0;i<this.slices.length;i++){ | |
7626 | _149[this.slices[i].xval]=this.slices[i]; | |
7627 | } | |
7628 | for(var i=0;i<this.options.xTicks.length;i++){ | |
7629 | var tick=this.options.xTicks[i]; | |
7630 | var _150=_149[tick.v]; | |
7631 | var _151=tick.label; | |
7632 | if(_150){ | |
7633 | if(_147(_151)){ | |
7634 | _151=tick.v.toString(); | |
7635 | } | |
7636 | _151+=" ("+_148(_150.fraction)+")"; | |
7637 | this.xticks.push([tick.v,_151]); | |
7638 | } | |
7639 | } | |
7640 | }else{ | |
7641 | for(var i=0;i<this.slices.length;i++){ | |
7642 | var _150=this.slices[i]; | |
7643 | var _151=_150.xval+" ("+_148(_150.fraction)+")"; | |
7644 | this.xticks.push([_150.xval,_151]); | |
7645 | } | |
7646 | } | |
7647 | }; | |
7648 | PlotKit.Layout.prototype._regenerateHitTestCache=function(){ | |
7649 | this.hitTestCache.xvalues=this._uniqueXValues(); | |
7650 | this.hitTestCache.xlookup=new Array(); | |
7651 | this.hitTestCache.x2maxy=new Array(); | |
7652 | var _152=MochiKit.Base.listMax; | |
7653 | var _153=MochiKit.Base.itemgetter; | |
7654 | var map=MochiKit.Base.map; | |
7655 | var _154=keys(this.datasets); | |
7656 | for(var i=0;i<_154.length;i++){ | |
7657 | var _155=this.datasets[_154[i]]; | |
7658 | for(var j=0;j<_155.length;j++){ | |
7659 | var xval=_155[j][0]; | |
7660 | var yval=_155[j][1]; | |
7661 | if(this.hitTestCache.xlookup[xval]){ | |
7662 | this.hitTestCache.xlookup[xval].push([yval,_154[i]]); | |
7663 | }else{ | |
7664 | this.hitTestCache.xlookup[xval]=[[yval,_154[i]]]; | |
7665 | } | |
7666 | } | |
7667 | } | |
7668 | for(var x in this.hitTestCache.xlookup){ | |
7669 | var _157=this.hitTestCache.xlookup[x]; | |
7670 | this.hitTestCache.x2maxy[x]=_152(map(_153(0),_157)); | |
7671 | } | |
7672 | }; | |
7673 | PlotKit.LayoutModule={}; | |
7674 | PlotKit.LayoutModule.Layout=PlotKit.Layout; | |
7675 | PlotKit.LayoutModule.EXPORT=["Layout"]; | |
7676 | PlotKit.LayoutModule.EXPORT_OK=[]; | |
7677 | PlotKit.LayoutModule.__new__=function(){ | |
7678 | var m=MochiKit.Base; | |
7679 | m.nameFunctions(this); | |
7680 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
7681 | }; | |
7682 | PlotKit.LayoutModule.__new__(); | |
7683 | MochiKit.Base._exportSymbols(this,PlotKit.LayoutModule); | |
7684 | try{ | |
7685 | if((typeof (PlotKit.Base)=="undefined")||(typeof (PlotKit.Layout)=="undefined")){ | |
7686 | throw ""; | |
7687 | } | |
7688 | } | |
7689 | catch(e){ | |
7690 | throw "PlotKit.Layout depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.{Base,Layout}"; | |
7691 | } | |
7692 | if(typeof (PlotKit.CanvasRenderer)=="undefined"){ | |
7693 | PlotKit.CanvasRenderer={}; | |
7694 | } | |
7695 | PlotKit.CanvasRenderer.NAME="PlotKit.CanvasRenderer"; | |
7696 | PlotKit.CanvasRenderer.VERSION=PlotKit.VERSION; | |
7697 | PlotKit.CanvasRenderer.__repr__=function(){ | |
7698 | return "["+this.NAME+" "+this.VERSION+"]"; | |
7699 | }; | |
7700 | PlotKit.CanvasRenderer.toString=function(){ | |
7701 | return this.__repr__(); | |
7702 | }; | |
7703 | PlotKit.CanvasRenderer=function(_158,_159,_160){ | |
7704 | if(arguments.length>0){ | |
7705 | this.__init__(_158,_159,_160); | |
7706 | } | |
7707 | }; | |
7708 | PlotKit.CanvasRenderer.prototype.__init__=function(_161,_162,_163){ | |
7709 | var _164=MochiKit.Base.isUndefinedOrNull; | |
7710 | var _165=MochiKit.Color.Color; | |
7711 | this.options={"drawBackground":true,"backgroundColor":_165.whiteColor(),"padding":{left:30,right:30,top:5,bottom:10},"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[0]),"strokeColor":_165.whiteColor(),"strokeColorTransform":"asStrokeColor","strokeWidth":0.5,"shouldFill":true,"shouldStroke":true,"drawXAxis":true,"drawYAxis":true,"axisLineColor":_165.blackColor(),"axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":_165.blackColor(),"axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"pieRadius":0.4,"enableEvents":true}; | |
7712 | MochiKit.Base.update(this.options,_163?_163:{}); | |
7713 | this.layout=_162; | |
7714 | this.element=MochiKit.DOM.getElement(_161); | |
7715 | this.container=this.element.parentNode; | |
7716 | this.isIE=PlotKit.Base.excanvasSupported(); | |
7717 | if(this.isIE&&!_164(G_vmlCanvasManager)){ | |
7718 | this.IEDelay=0.5; | |
7719 | this.maxTries=5; | |
7720 | this.renderDelay=null; | |
7721 | this.clearDelay=null; | |
7722 | this.element=G_vmlCanvasManager.initElement(this.element); | |
7723 | } | |
7724 | this.height=this.element.height; | |
7725 | this.width=this.element.width; | |
7726 | if(_164(this.element)){ | |
7727 | throw "CanvasRenderer() - passed canvas is not found"; | |
7728 | } | |
7729 | if(!this.isIE&&!(PlotKit.CanvasRenderer.isSupported(this.element))){ | |
7730 | throw "CanvasRenderer() - Canvas is not supported."; | |
7731 | } | |
7732 | if(_164(this.container)||(this.container.nodeName.toLowerCase()!="div")){ | |
7733 | throw "CanvasRenderer() - <canvas> needs to be enclosed in <div>"; | |
7734 | } | |
7735 | this.xlabels=new Array(); | |
7736 | this.ylabels=new Array(); | |
7737 | this.isFirstRender=true; | |
7738 | this.area={x:this.options.padding.left,y:this.options.padding.top,w:this.width-this.options.padding.left-this.options.padding.right,h:this.height-this.options.padding.top-this.options.padding.bottom}; | |
7739 | MochiKit.DOM.updateNodeAttributes(this.container,{"style":{"position":"relative","width":this.width+"px"}}); | |
7740 | }; | |
7741 | PlotKit.CanvasRenderer.prototype.render=function(){ | |
7742 | if(this.isIE){ | |
7743 | try{ | |
7744 | if(this.renderDelay){ | |
7745 | this.renderDelay.cancel(); | |
7746 | this.renderDelay=null; | |
7747 | } | |
7748 | var _166=this.element.getContext("2d"); | |
7749 | } | |
7750 | catch(e){ | |
7751 | this.isFirstRender=false; | |
7752 | if(this.maxTries-->0){ | |
7753 | this.renderDelay=MochiKit.Async.wait(this.IEDelay); | |
7754 | this.renderDelay.addCallback(bind(this.render,this)); | |
7755 | } | |
7756 | return; | |
7757 | } | |
7758 | } | |
7759 | if(this.options.drawBackground){ | |
7760 | this._renderBackground(); | |
7761 | } | |
7762 | if(this.layout.style=="bar"){ | |
7763 | this._renderBarChart(); | |
7764 | this._renderBarAxis(); | |
7765 | }else{ | |
7766 | if(this.layout.style=="pie"){ | |
7767 | this._renderPieChart(); | |
7768 | this._renderPieAxis(); | |
7769 | }else{ | |
7770 | if(this.layout.style=="line"){ | |
7771 | this._renderLineChart(); | |
7772 | this._renderLineAxis(); | |
7773 | } | |
7774 | } | |
7775 | } | |
7776 | }; | |
7777 | PlotKit.CanvasRenderer.prototype._renderBarChartWrap=function(data,_168){ | |
7778 | var _169=this.element.getContext("2d"); | |
7779 | var _170=this.options.colorScheme.length; | |
7780 | var _171=this.options.colorScheme; | |
7781 | var _172=MochiKit.Base.keys(this.layout.datasets); | |
7782 | var _173=_172.length; | |
7783 | for(var i=0;i<_173;i++){ | |
7784 | var _174=_172[i]; | |
7785 | var _175=_171[i%_170]; | |
7786 | _169.save(); | |
7787 | _169.fillStyle=_175.toRGBString(); | |
7788 | if(this.options.strokeColor){ | |
7789 | _169.strokeStyle=this.options.strokeColor.toRGBString(); | |
7790 | }else{ | |
7791 | if(this.options.strokeColorTransform){ | |
7792 | _169.strokeStyle=_175[this.options.strokeColorTransform]().toRGBString(); | |
7793 | } | |
7794 | } | |
7795 | _169.lineWidth=this.options.strokeWidth; | |
7796 | var _176=function(obj){ | |
7797 | if(obj.name==_174){ | |
7798 | _168(_169,obj); | |
7799 | } | |
7800 | }; | |
7801 | MochiKit.Iter.forEach(data,bind(_176,this)); | |
7802 | _169.restore(); | |
7803 | } | |
7804 | }; | |
7805 | PlotKit.CanvasRenderer.prototype._renderBarChart=function(){ | |
7806 | var bind=MochiKit.Base.bind; | |
7807 | var _178=function(_179,bar){ | |
7808 | var x=this.area.w*bar.x+this.area.x; | |
7809 | var y=this.area.h*bar.y+this.area.y; | |
7810 | var w=this.area.w*bar.w; | |
7811 | var h=this.area.h*bar.h; | |
7812 | if((w<1)||(h<1)){ | |
7813 | return; | |
7814 | } | |
7815 | if(this.options.shouldFill){ | |
7816 | _179.fillRect(x,y,w,h); | |
7817 | } | |
7818 | if(this.options.shouldStroke){ | |
7819 | _179.strokeRect(x,y,w,h); | |
7820 | } | |
7821 | }; | |
7822 | this._renderBarChartWrap(this.layout.bars,bind(_178,this)); | |
7823 | }; | |
7824 | PlotKit.CanvasRenderer.prototype._renderLineChart=function(){ | |
7825 | var _182=this.element.getContext("2d"); | |
7826 | var _183=this.options.colorScheme.length; | |
7827 | var _184=this.options.colorScheme; | |
7828 | var _185=MochiKit.Base.keys(this.layout.datasets); | |
7829 | var _186=_185.length; | |
7830 | var bind=MochiKit.Base.bind; | |
7831 | var _187=MochiKit.Base.partial; | |
7832 | for(var i=0;i<_186;i++){ | |
7833 | var _188=_185[i]; | |
7834 | var _189=_184[i%_183]; | |
7835 | var _190=this.options.strokeColorTransform; | |
7836 | _182.save(); | |
7837 | _182.fillStyle=_189.toRGBString(); | |
7838 | if(this.options.strokeColor){ | |
7839 | _182.strokeStyle=this.options.strokeColor.toRGBString(); | |
7840 | }else{ | |
7841 | if(this.options.strokeColorTransform){ | |
7842 | _182.strokeStyle=_189[_190]().toRGBString(); | |
7843 | } | |
7844 | } | |
7845 | _182.lineWidth=this.options.strokeWidth; | |
7846 | var _191=function(ctx){ | |
7847 | ctx.beginPath(); | |
7848 | ctx.moveTo(this.area.x,this.area.y+this.area.h); | |
7849 | var _193=function(ctx_,_195){ | |
7850 | if(_195.name==_188){ | |
7851 | ctx_.lineTo(this.area.w*_195.x+this.area.x,this.area.h*_195.y+this.area.y); | |
7852 | } | |
7853 | }; | |
7854 | MochiKit.Iter.forEach(this.layout.points,_187(_193,ctx),this); | |
7855 | ctx.lineTo(this.area.w+this.area.x,this.area.h+this.area.y); | |
7856 | ctx.lineTo(this.area.x,this.area.y+this.area.h); | |
7857 | ctx.closePath(); | |
7858 | }; | |
7859 | if(this.options.shouldFill){ | |
7860 | bind(_191,this)(_182); | |
7861 | _182.fill(); | |
7862 | } | |
7863 | if(this.options.shouldStroke){ | |
7864 | bind(_191,this)(_182); | |
7865 | _182.stroke(); | |
7866 | } | |
7867 | _182.restore(); | |
7868 | } | |
7869 | }; | |
7870 | PlotKit.CanvasRenderer.prototype._renderPieChart=function(){ | |
7871 | var _196=this.element.getContext("2d"); | |
7872 | var _197=this.options.colorScheme.length; | |
7873 | var _198=this.layout.slices; | |
7874 | var _199=this.area.x+this.area.w*0.5; | |
7875 | var _200=this.area.y+this.area.h*0.5; | |
7876 | var _201=Math.min(this.area.w*this.options.pieRadius,this.area.h*this.options.pieRadius); | |
7877 | if(this.isIE){ | |
7878 | _199=parseInt(_199); | |
7879 | _200=parseInt(_200); | |
7880 | _201=parseInt(_201); | |
7881 | } | |
7882 | for(var i=0;i<_198.length;i++){ | |
7883 | var _202=this.options.colorScheme[i%_197]; | |
7884 | _196.save(); | |
7885 | _196.fillStyle=_202.toRGBString(); | |
7886 | var _203=function(){ | |
7887 | _196.beginPath(); | |
7888 | _196.moveTo(_199,_200); | |
7889 | _196.arc(_199,_200,_201,_198[i].startAngle-Math.PI/2,_198[i].endAngle-Math.PI/2,false); | |
7890 | _196.lineTo(_199,_200); | |
7891 | _196.closePath(); | |
7892 | }; | |
7893 | if(Math.abs(_198[i].startAngle-_198[i].endAngle)>0.001){ | |
7894 | if(this.options.shouldFill){ | |
7895 | _203(); | |
7896 | _196.fill(); | |
7897 | } | |
7898 | if(this.options.shouldStroke){ | |
7899 | _203(); | |
7900 | _196.lineWidth=this.options.strokeWidth; | |
7901 | if(this.options.strokeColor){ | |
7902 | _196.strokeStyle=this.options.strokeColor.toRGBString(); | |
7903 | }else{ | |
7904 | if(this.options.strokeColorTransform){ | |
7905 | _196.strokeStyle=_202[this.options.strokeColorTransform]().toRGBString(); | |
7906 | } | |
7907 | } | |
7908 | _196.stroke(); | |
7909 | } | |
7910 | } | |
7911 | _196.restore(); | |
7912 | } | |
7913 | }; | |
7914 | PlotKit.CanvasRenderer.prototype._renderBarAxis=function(){ | |
7915 | this._renderAxis(); | |
7916 | }; | |
7917 | PlotKit.CanvasRenderer.prototype._renderLineAxis=function(){ | |
7918 | this._renderAxis(); | |
7919 | }; | |
7920 | PlotKit.CanvasRenderer.prototype._renderAxis=function(){ | |
7921 | if(!this.options.drawXAxis&&!this.options.drawYAxis){ | |
7922 | return; | |
7923 | } | |
7924 | var _204=this.element.getContext("2d"); | |
7925 | var _205={"style":{"position":"absolute","fontSize":this.options.axisLabelFontSize+"px","zIndex":10,"color":this.options.axisLabelColor.toRGBString(),"width":this.options.axisLabelWidth+"px","overflow":"hidden"}}; | |
7926 | _204.save(); | |
7927 | _204.strokeStyle=this.options.axisLineColor.toRGBString(); | |
7928 | _204.lineWidth=this.options.axisLineWidth; | |
7929 | if(this.options.drawYAxis){ | |
7930 | if(this.layout.yticks){ | |
7931 | var _206=function(tick){ | |
7932 | if(typeof (tick)=="function"){ | |
7933 | return; | |
7934 | } | |
7935 | var x=this.area.x; | |
7936 | var y=this.area.y+tick[0]*this.area.h; | |
7937 | _204.beginPath(); | |
7938 | _204.moveTo(x,y); | |
7939 | _204.lineTo(x-this.options.axisTickSize,y); | |
7940 | _204.closePath(); | |
7941 | _204.stroke(); | |
7942 | var _207=DIV(_205,tick[1]); | |
7943 | _207.style.top=(y-this.options.axisLabelFontSize)+"px"; | |
7944 | _207.style.left=(x-this.options.padding.left-this.options.axisTickSize)+"px"; | |
7945 | _207.style.textAlign="right"; | |
7946 | _207.style.width=(this.options.padding.left-this.options.axisTickSize*2)+"px"; | |
7947 | MochiKit.DOM.appendChildNodes(this.container,_207); | |
7948 | this.ylabels.push(_207); | |
7949 | }; | |
7950 | MochiKit.Iter.forEach(this.layout.yticks,bind(_206,this)); | |
7951 | } | |
7952 | _204.beginPath(); | |
7953 | _204.moveTo(this.area.x,this.area.y); | |
7954 | _204.lineTo(this.area.x,this.area.y+this.area.h); | |
7955 | _204.closePath(); | |
7956 | _204.stroke(); | |
7957 | } | |
7958 | if(this.options.drawXAxis){ | |
7959 | if(this.layout.xticks){ | |
7960 | var _206=function(tick){ | |
7961 | if(typeof (dataset)=="function"){ | |
7962 | return; | |
7963 | } | |
7964 | var x=this.area.x+tick[0]*this.area.w; | |
7965 | var y=this.area.y+this.area.h; | |
7966 | _204.beginPath(); | |
7967 | _204.moveTo(x,y); | |
7968 | _204.lineTo(x,y+this.options.axisTickSize); | |
7969 | _204.closePath(); | |
7970 | _204.stroke(); | |
7971 | var _208=DIV(_205,tick[1]); | |
7972 | _208.style.top=(y+this.options.axisTickSize)+"px"; | |
7973 | _208.style.left=(x-this.options.axisLabelWidth/2)+"px"; | |
7974 | _208.style.textAlign="center"; | |
7975 | _208.style.width=this.options.axisLabelWidth+"px"; | |
7976 | MochiKit.DOM.appendChildNodes(this.container,_208); | |
7977 | this.xlabels.push(_208); | |
7978 | }; | |
7979 | MochiKit.Iter.forEach(this.layout.xticks,bind(_206,this)); | |
7980 | } | |
7981 | _204.beginPath(); | |
7982 | _204.moveTo(this.area.x,this.area.y+this.area.h); | |
7983 | _204.lineTo(this.area.x+this.area.w,this.area.y+this.area.h); | |
7984 | _204.closePath(); | |
7985 | _204.stroke(); | |
7986 | } | |
7987 | _204.restore(); | |
7988 | }; | |
7989 | PlotKit.CanvasRenderer.prototype._renderPieAxis=function(){ | |
7990 | if(!this.options.drawXAxis){ | |
7991 | return; | |
7992 | } | |
7993 | if(this.layout.xticks){ | |
7994 | var _209=new Array(); | |
7995 | for(var i=0;i<this.layout.slices.length;i++){ | |
7996 | _209[this.layout.slices[i].xval]=this.layout.slices[i]; | |
7997 | } | |
7998 | var _210=this.area.x+this.area.w*0.5; | |
7999 | var _211=this.area.y+this.area.h*0.5; | |
8000 | var _212=Math.min(this.area.w*this.options.pieRadius,this.area.h*this.options.pieRadius); | |
8001 | var _213=this.options.axisLabelWidth; | |
8002 | for(var i=0;i<this.layout.xticks.length;i++){ | |
8003 | var _214=_209[this.layout.xticks[i][0]]; | |
8004 | if(MochiKit.Base.isUndefinedOrNull(_214)){ | |
8005 | continue; | |
8006 | } | |
8007 | var _215=(_214.startAngle+_214.endAngle)/2; | |
8008 | var _216=_215; | |
8009 | if(_216>Math.PI*2){ | |
8010 | _216=_216-Math.PI*2; | |
8011 | }else{ | |
8012 | if(_216<0){ | |
8013 | _216=_216+Math.PI*2; | |
8014 | } | |
8015 | } | |
8016 | var _217=_210+Math.sin(_216)*(_212+10); | |
8017 | var _218=_211-Math.cos(_216)*(_212+10); | |
8018 | var _219={"position":"absolute","zIndex":11,"width":_213+"px","fontSize":this.options.axisLabelFontSize+"px","overflow":"hidden","color":this.options.axisLabelColor.toHexString()}; | |
8019 | if(_216<=Math.PI*0.5){ | |
8020 | _219["textAlign"]="left"; | |
8021 | _219["verticalAlign"]="top"; | |
8022 | _219["left"]=_217+"px"; | |
8023 | _219["top"]=(_218-this.options.axisLabelFontSize)+"px"; | |
8024 | }else{ | |
8025 | if((_216>Math.PI*0.5)&&(_216<=Math.PI)){ | |
8026 | _219["textAlign"]="left"; | |
8027 | _219["verticalAlign"]="bottom"; | |
8028 | _219["left"]=_217+"px"; | |
8029 | _219["top"]=_218+"px"; | |
8030 | }else{ | |
8031 | if((_216>Math.PI)&&(_216<=Math.PI*1.5)){ | |
8032 | _219["textAlign"]="right"; | |
8033 | _219["verticalAlign"]="bottom"; | |
8034 | _219["left"]=(_217-_213)+"px"; | |
8035 | _219["top"]=_218+"px"; | |
8036 | }else{ | |
8037 | _219["textAlign"]="right"; | |
8038 | _219["verticalAlign"]="bottom"; | |
8039 | _219["left"]=(_217-_213)+"px"; | |
8040 | _219["top"]=(_218-this.options.axisLabelFontSize)+"px"; | |
8041 | } | |
8042 | } | |
8043 | } | |
8044 | var _220=DIV({"style":_219},this.layout.xticks[i][1]); | |
8045 | this.xlabels.push(_220); | |
8046 | MochiKit.DOM.appendChildNodes(this.container,_220); | |
8047 | } | |
8048 | } | |
8049 | }; | |
8050 | PlotKit.CanvasRenderer.prototype._renderBackground=function(){ | |
8051 | var _221=this.element.getContext("2d"); | |
8052 | _221.save(); | |
8053 | _221.fillStyle=this.options.backgroundColor.toRGBString(); | |
8054 | _221.fillRect(0,0,this.width,this.height); | |
8055 | _221.restore(); | |
8056 | }; | |
8057 | PlotKit.CanvasRenderer.prototype.clear=function(){ | |
8058 | if(this.isIE){ | |
8059 | try{ | |
8060 | if(this.clearDelay){ | |
8061 | this.clearDelay.cancel(); | |
8062 | this.clearDelay=null; | |
8063 | } | |
8064 | var _222=this.element.getContext("2d"); | |
8065 | } | |
8066 | catch(e){ | |
8067 | this.isFirstRender=false; | |
8068 | this.clearDelay=MochiKit.Async.wait(this.IEDelay); | |
8069 | this.clearDelay.addCallback(bind(this.clear,this)); | |
8070 | return; | |
8071 | } | |
8072 | } | |
8073 | var _222=this.element.getContext("2d"); | |
8074 | _222.clearRect(0,0,this.width,this.height); | |
8075 | MochiKit.Iter.forEach(this.xlabels,MochiKit.DOM.removeElement); | |
8076 | MochiKit.Iter.forEach(this.ylabels,MochiKit.DOM.removeElement); | |
8077 | this.xlabels=new Array(); | |
8078 | this.ylabels=new Array(); | |
8079 | }; | |
8080 | PlotKit.CanvasRenderer.prototype._initialiseEvents=function(){ | |
8081 | var _223=MochiKit.Signal.connect; | |
8082 | var bind=MochiKit.Base.bind; | |
8083 | _223(this.element,"onclick",bind(this.onclick,this)); | |
8084 | }; | |
8085 | PlotKit.CanvasRenderer.prototype._resolveObject=function(e){ | |
8086 | var x=(e.mouse().page.x-PlotKit.Base.findPosX(this.element)-this.area.x)/this.area.w; | |
8087 | var y=(e.mouse().page.y-PlotKit.Base.findPosY(this.element)-this.area.y)/this.area.h; | |
8088 | var _225=this.layout.hitTest(x,y); | |
8089 | if(_225){ | |
8090 | return _225; | |
8091 | } | |
8092 | return null; | |
8093 | }; | |
8094 | PlotKit.CanvasRenderer.prototype._createEventObject=function(_226,e){ | |
8095 | if(_226==null){ | |
8096 | return null; | |
8097 | } | |
8098 | e.chart=_226; | |
8099 | return e; | |
8100 | }; | |
8101 | PlotKit.CanvasRenderer.prototype.onclick=function(e){ | |
8102 | var _227=this._resolveObject(e); | |
8103 | var _228=this._createEventObject(_227,e); | |
8104 | if(_228!=null){ | |
8105 | MochiKit.Signal.signal(this,"onclick",_228); | |
8106 | } | |
8107 | }; | |
8108 | PlotKit.CanvasRenderer.prototype.onmouseover=function(e){ | |
8109 | var _229=this._resolveObject(e); | |
8110 | var _230=this._createEventObject(_229,e); | |
8111 | if(_230!=null){ | |
8112 | signal(this,"onmouseover",_230); | |
8113 | } | |
8114 | }; | |
8115 | PlotKit.CanvasRenderer.prototype.onmouseout=function(e){ | |
8116 | var _231=this._resolveObject(e); | |
8117 | var _232=this._createEventObject(_231,e); | |
8118 | if(_232==null){ | |
8119 | signal(this,"onmouseout",e); | |
8120 | }else{ | |
8121 | signal(this,"onmouseout",_232); | |
8122 | } | |
8123 | }; | |
8124 | PlotKit.CanvasRenderer.prototype.onmousemove=function(e){ | |
8125 | var _233=this._resolveObject(e); | |
8126 | var _234=this._createEventObject(_233,e); | |
8127 | if((_233==null)&&(this.event_isinside==null)){ | |
8128 | return; | |
8129 | } | |
8130 | if((_233!=null)&&(this.event_isinside==null)){ | |
8131 | signal(this,"onmouseover",_234); | |
8132 | } | |
8133 | if((_233==null)&&(this.event_isinside!=null)){ | |
8134 | signal(this,"onmouseout",_234); | |
8135 | } | |
8136 | if((_233!=null)&&(this.event_isinside!=null)){ | |
8137 | signal(this,"onmousemove",_234); | |
8138 | } | |
8139 | this.event_isinside=_233; | |
8140 | }; | |
8141 | PlotKit.CanvasRenderer.isSupported=function(_235){ | |
8142 | var _236=null; | |
8143 | try{ | |
8144 | if(MochiKit.Base.isUndefinedOrNull(_235)){ | |
8145 | _236=MochiKit.DOM.CANVAS({}); | |
8146 | }else{ | |
8147 | _236=MochiKit.DOM.getElement(_235); | |
8148 | } | |
8149 | var _237=_236.getContext("2d"); | |
8150 | } | |
8151 | catch(e){ | |
8152 | var ie=navigator.appVersion.match(/MSIE (\d\.\d)/); | |
8153 | var _239=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); | |
8154 | if((!ie)||(ie[1]<6)||(_239)){ | |
8155 | return false; | |
8156 | } | |
8157 | return true; | |
8158 | } | |
8159 | return true; | |
8160 | }; | |
8161 | PlotKit.Canvas={}; | |
8162 | PlotKit.Canvas.CanvasRenderer=PlotKit.CanvasRenderer; | |
8163 | PlotKit.Canvas.EXPORT=["CanvasRenderer"]; | |
8164 | PlotKit.Canvas.EXPORT_OK=["CanvasRenderer"]; | |
8165 | PlotKit.Canvas.__new__=function(){ | |
8166 | var m=MochiKit.Base; | |
8167 | m.nameFunctions(this); | |
8168 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
8169 | }; | |
8170 | PlotKit.Canvas.__new__(); | |
8171 | MochiKit.Base._exportSymbols(this,PlotKit.Canvas); | |
8172 | try{ | |
8173 | if(typeof (PlotKit.Layout)=="undefined"){ | |
8174 | throw ""; | |
8175 | } | |
8176 | } | |
8177 | catch(e){ | |
8178 | throw "PlotKit depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.Layout"; | |
8179 | } | |
8180 | PlotKit.SVGRenderer=function(_240,_241,_242){ | |
8181 | if(arguments.length>0){ | |
8182 | this.__init__(_240,_241,_242); | |
8183 | } | |
8184 | }; | |
8185 | PlotKit.SVGRenderer.NAME="PlotKit.SVGRenderer"; | |
8186 | PlotKit.SVGRenderer.VERSION=PlotKit.VERSION; | |
8187 | PlotKit.SVGRenderer.__repr__=function(){ | |
8188 | return "["+this.NAME+" "+this.VERSION+"]"; | |
8189 | }; | |
8190 | PlotKit.SVGRenderer.toString=function(){ | |
8191 | return this.__repr__(); | |
8192 | }; | |
8193 | PlotKit.SVGRenderer.SVGNS="http://www.w3.org/2000/svg"; | |
8194 | PlotKit.SVGRenderer.prototype.__init__=function(_243,_244,_245){ | |
8195 | var _246=MochiKit.Base.isUndefinedOrNull; | |
8196 | this.options={"drawBackground":true,"backgroundColor":Color.whiteColor(),"padding":{left:30,right:30,top:5,bottom:10},"colorScheme":PlotKit.Base.palette(PlotKit.Base.baseColors()[1]),"strokeColor":Color.whiteColor(),"strokeColorTransform":"asStrokeColor","strokeWidth":0.5,"shouldFill":true,"shouldStroke":true,"drawXAxis":true,"drawYAxis":true,"axisLineColor":Color.blackColor(),"axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":Color.blackColor(),"axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"axisLabelUseDiv":true,"pieRadius":0.4,"enableEvents":true}; | |
8197 | MochiKit.Base.update(this.options,_245?_245:{}); | |
8198 | this.layout=_244; | |
8199 | this.element=MochiKit.DOM.getElement(_243); | |
8200 | this.container=this.element.parentNode; | |
8201 | this.height=parseInt(this.element.getAttribute("height")); | |
8202 | this.width=parseInt(this.element.getAttribute("width")); | |
8203 | this.document=document; | |
8204 | this.root=this.element; | |
8205 | try{ | |
8206 | this.document=this.element.getSVGDocument(); | |
8207 | this.root=_246(this.document.documentElement)?this.element:this.document.documentElement; | |
8208 | } | |
8209 | catch(e){ | |
8210 | } | |
8211 | this.element.style.zIndex=1; | |
8212 | if(_246(this.element)){ | |
8213 | throw "SVGRenderer() - passed SVG object is not found"; | |
8214 | } | |
8215 | if(_246(this.container)||this.container.nodeName.toLowerCase()!="div"){ | |
8216 | throw "SVGRenderer() - No DIV's around the SVG."; | |
8217 | } | |
8218 | this.xlabels=new Array(); | |
8219 | this.ylabels=new Array(); | |
8220 | this.defs=this.createSVGElement("defs"); | |
8221 | this.area={x:this.options.padding.left,y:this.options.padding.top,w:this.width-this.options.padding.left-this.options.padding.right,h:this.height-this.options.padding.top-this.options.padding.bottom}; | |
8222 | MochiKit.DOM.updateNodeAttributes(this.container,{"style":{"position":"relative","width":this.width+"px"}}); | |
8223 | }; | |
8224 | PlotKit.SVGRenderer.prototype.render=function(){ | |
8225 | if(this.options.drawBackground){ | |
8226 | this._renderBackground(); | |
8227 | } | |
8228 | if(this.layout.style=="bar"){ | |
8229 | this._renderBarChart(); | |
8230 | this._renderBarAxis(); | |
8231 | }else{ | |
8232 | if(this.layout.style=="pie"){ | |
8233 | this._renderPieChart(); | |
8234 | this._renderPieAxis(); | |
8235 | }else{ | |
8236 | if(this.layout.style=="line"){ | |
8237 | this._renderLineChart(); | |
8238 | this._renderLineAxis(); | |
8239 | } | |
8240 | } | |
8241 | } | |
8242 | }; | |
8243 | PlotKit.SVGRenderer.prototype._renderBarOrLine=function(data,_247,_248,_249){ | |
8244 | var _250=this.options.colorScheme.length; | |
8245 | var _251=this.options.colorScheme; | |
8246 | var _252=MochiKit.Base.keys(this.layout.datasets); | |
8247 | var _253=_252.length; | |
8248 | for(var i=0;i<_253;i++){ | |
8249 | var _254=_252[i]; | |
8250 | var _255=new Array(); | |
8251 | var _256=_251[i%_250]; | |
8252 | if(this.options.shouldFill){ | |
8253 | _255["fill"]=_256.toRGBString(); | |
8254 | }else{ | |
8255 | _255["fill"]="none"; | |
8256 | } | |
8257 | if(this.options.shouldStroke&&(this.options.strokeColor||this.options.strokeColorTransform)){ | |
8258 | if(this.options.strokeColor){ | |
8259 | _255["stroke"]=this.options.strokeColor.toRGBString(); | |
8260 | }else{ | |
8261 | if(this.options.strokeColorTransform){ | |
8262 | _255["stroke"]=_256[this.options.strokeColorTransform]().toRGBString(); | |
8263 | } | |
8264 | } | |
8265 | _255["strokeWidth"]=this.options.strokeWidth; | |
8266 | } | |
8267 | if(_248){ | |
8268 | _248(_255); | |
8269 | } | |
8270 | var _257=function(obj){ | |
8271 | if(obj.name==_254){ | |
8272 | _247(_255,obj); | |
8273 | } | |
8274 | }; | |
8275 | MochiKit.Iter.forEach(data,bind(_257,this)); | |
8276 | if(_249){ | |
8277 | _249(_255); | |
8278 | } | |
8279 | } | |
8280 | }; | |
8281 | PlotKit.SVGRenderer.prototype._renderBarChart=function(){ | |
8282 | var bind=MochiKit.Base.bind; | |
8283 | var _258=function(_259,bar){ | |
8284 | var x=this.area.w*bar.x+this.area.x; | |
8285 | var y=this.area.h*bar.y+this.area.y; | |
8286 | var w=this.area.w*bar.w; | |
8287 | var h=this.area.h*bar.h; | |
8288 | this._drawRect(x,y,w,h,_259); | |
8289 | }; | |
8290 | this._renderBarOrLine(this.layout.bars,bind(_258,this)); | |
8291 | }; | |
8292 | PlotKit.SVGRenderer.prototype._renderLineChart=function(){ | |
8293 | var bind=MochiKit.Base.bind; | |
8294 | var _260=function(_261,_262){ | |
8295 | this._tempPointsBuffer+=(this.area.w*_262.x+this.area.x)+","+(this.area.h*_262.y+this.area.y)+" "; | |
8296 | }; | |
8297 | var _263=function(_264){ | |
8298 | this._tempPointsBuffer=""; | |
8299 | this._tempPointsBuffer+=(this.area.x)+","+(this.area.y+this.area.h)+" "; | |
8300 | }; | |
8301 | var _265=function(_266){ | |
8302 | this._tempPointsBuffer+=(this.area.w+this.area.x)+","+(this.area.h+this.area.y); | |
8303 | _266["points"]=this._tempPointsBuffer; | |
8304 | var elem=this.createSVGElement("polygon",_266); | |
8305 | this.root.appendChild(elem); | |
8306 | }; | |
8307 | this._renderBarOrLine(this.layout.points,bind(_260,this),bind(_263,this),bind(_265,this)); | |
8308 | }; | |
8309 | PlotKit.SVGRenderer.prototype._renderPieChart=function(){ | |
8310 | var _268=this.options.colorScheme.length; | |
8311 | var _269=this.layout.slices; | |
8312 | var _270=this.area.x+this.area.w*0.5; | |
8313 | var _271=this.area.y+this.area.h*0.5; | |
8314 | var _272=Math.min(this.area.w*this.options.pieRadius,this.area.h*this.options.pieRadius); | |
8315 | if(_269.length==1&&(Math.abs(_269[0].startAngle)-Math.abs(_269[0].endAngle)<0.1)){ | |
8316 | var _273={"cx":_270,"cy":_271,"r":_272}; | |
8317 | var _274=this.options.colorScheme[0]; | |
8318 | if(this.options.shouldFill){ | |
8319 | _273["fill"]=_274.toRGBString(); | |
8320 | }else{ | |
8321 | _273["fill"]="none"; | |
8322 | } | |
8323 | if(this.options.shouldStroke&&(this.options.strokeColor||this.options.strokeColorTransform)){ | |
8324 | if(this.options.strokeColor){ | |
8325 | _273["stroke"]=this.options.strokeColor.toRGBString(); | |
8326 | }else{ | |
8327 | if(this.options.strokeColorTransform){ | |
8328 | _273["stroke"]=_274[this.options.strokeColorTransform]().toRGBString(); | |
8329 | } | |
8330 | } | |
8331 | _273["style"]="stroke-width: "+this.options.strokeWidth; | |
8332 | } | |
8333 | this.root.appendChild(this.createSVGElement("circle",_273)); | |
8334 | return; | |
8335 | } | |
8336 | for(var i=0;i<_269.length;i++){ | |
8337 | var _273=new Array(); | |
8338 | var _274=this.options.colorScheme[i%_268]; | |
8339 | if(this.options.shouldFill){ | |
8340 | _273["fill"]=_274.toRGBString(); | |
8341 | }else{ | |
8342 | _273["fill"]="none"; | |
8343 | } | |
8344 | if(this.options.shouldStroke&&(this.options.strokeColor||this.options.strokeColorTransform)){ | |
8345 | if(this.options.strokeColor){ | |
8346 | _273["stroke"]=this.options.strokeColor.toRGBString(); | |
8347 | }else{ | |
8348 | if(this.options.strokeColorTransform){ | |
8349 | _273["stroke"]=_274[this.options.strokeColorTransform]().toRGBString(); | |
8350 | } | |
8351 | } | |
8352 | _273["style"]="stroke-width:"+this.options.strokeWidth; | |
8353 | } | |
8354 | var _275=0; | |
8355 | if(Math.abs(_269[i].endAngle-_269[i].startAngle)>Math.PI){ | |
8356 | _275=1; | |
8357 | } | |
8358 | var x1=Math.cos(_269[i].startAngle-Math.PI/2)*_272; | |
8359 | var y1=Math.sin(_269[i].startAngle-Math.PI/2)*_272; | |
8360 | var x2=Math.cos(_269[i].endAngle-Math.PI/2)*_272; | |
8361 | var y2=Math.sin(_269[i].endAngle-Math.PI/2)*_272; | |
8362 | var rx=x2-x1; | |
8363 | var ry=y2-y1; | |
8364 | var _282="M"+_270+","+_271+" "; | |
8365 | _282+="l"+x1+","+y1+" "; | |
8366 | _282+="a"+_272+","+_272+" 0 "+_275+",1 "+rx+","+ry+" z"; | |
8367 | _273["d"]=_282; | |
8368 | var elem=this.createSVGElement("path",_273); | |
8369 | this.root.appendChild(elem); | |
8370 | } | |
8371 | }; | |
8372 | PlotKit.SVGRenderer.prototype._renderBarAxis=function(){ | |
8373 | this._renderAxis(); | |
8374 | }; | |
8375 | PlotKit.SVGRenderer.prototype._renderLineAxis=function(){ | |
8376 | this._renderAxis(); | |
8377 | }; | |
8378 | PlotKit.SVGRenderer.prototype._renderAxis=function(){ | |
8379 | if(!this.options.drawXAxis&&!this.options.drawYAxis){ | |
8380 | return; | |
8381 | } | |
8382 | var _283={"style":{"position":"absolute","textAlign":"center","fontSize":this.options.axisLabelFontSize+"px","zIndex":10,"color":this.options.axisLabelColor.toRGBString(),"width":this.options.axisLabelWidth+"px","overflow":"hidden"}}; | |
8383 | var _284={"stroke":this.options.axisLineColor.toRGBString(),"strokeWidth":this.options.axisLineWidth}; | |
8384 | if(this.options.drawYAxis){ | |
8385 | if(this.layout.yticks){ | |
8386 | var _285=function(tick){ | |
8387 | var x=this.area.x; | |
8388 | var y=this.area.y+tick[0]*this.area.h; | |
8389 | this._drawLine(x,y,x-3,y,_284); | |
8390 | if(this.options.axisLabelUseDiv){ | |
8391 | var _286=DIV(_283,tick[1]); | |
8392 | _286.style.top=(y-this.options.axisLabelFontSize)+"px"; | |
8393 | _286.style.left=(x-this.options.padding.left+this.options.axisTickSize)+"px"; | |
8394 | _286.style.textAlign="left"; | |
8395 | _286.style.width=(this.options.padding.left-3)+"px"; | |
8396 | MochiKit.DOM.appendChildNodes(this.container,_286); | |
8397 | this.ylabels.push(_286); | |
8398 | }else{ | |
8399 | var _287={y:y+3,x:(x-this.options.padding.left+3),width:(this.options.padding.left-this.options.axisTickSize)+"px",height:(this.options.axisLabelFontSize+3)+"px",fontFamily:"Arial",fontSize:this.options.axisLabelFontSize+"px",fill:this.options.axisLabelColor.toRGBString()}; | |
8400 | var _286=this.createSVGElement("text",_287); | |
8401 | _286.appendChild(this.document.createTextNode(tick[1])); | |
8402 | this.root.appendChild(_286); | |
8403 | } | |
8404 | }; | |
8405 | MochiKit.Iter.forEach(this.layout.yticks,bind(_285,this)); | |
8406 | } | |
8407 | this._drawLine(this.area.x,this.area.y,this.area.x,this.area.y+this.area.h,_284); | |
8408 | } | |
8409 | if(this.options.drawXAxis){ | |
8410 | if(this.layout.xticks){ | |
8411 | var _285=function(tick){ | |
8412 | var x=this.area.x+tick[0]*this.area.w; | |
8413 | var y=this.area.y+this.area.h; | |
8414 | this._drawLine(x,y,x,y+this.options.axisTickSize,_284); | |
8415 | if(this.options.axisLabelUseDiv){ | |
8416 | var _288=DIV(_283,tick[1]); | |
8417 | _288.style.top=(y+this.options.axisTickSize)+"px"; | |
8418 | _288.style.left=(x-this.options.axisLabelWidth/2)+"px"; | |
8419 | _288.style.textAlign="center"; | |
8420 | _288.style.width=this.options.axisLabelWidth+"px"; | |
8421 | MochiKit.DOM.appendChildNodes(this.container,_288); | |
8422 | this.xlabels.push(_288); | |
8423 | }else{ | |
8424 | var _289={y:(y+this.options.axisTickSize+this.options.axisLabelFontSize),x:x-3,width:this.options.axisLabelWidth+"px",height:(this.options.axisLabelFontSize+3)+"px",fontFamily:"Arial",fontSize:this.options.axisLabelFontSize+"px",fill:this.options.axisLabelColor.toRGBString(),textAnchor:"middle"}; | |
8425 | var _288=this.createSVGElement("text",_289); | |
8426 | _288.appendChild(this.document.createTextNode(tick[1])); | |
8427 | this.root.appendChild(_288); | |
8428 | } | |
8429 | }; | |
8430 | MochiKit.Iter.forEach(this.layout.xticks,bind(_285,this)); | |
8431 | } | |
8432 | this._drawLine(this.area.x,this.area.y+this.area.h,this.area.x+this.area.w,this.area.y+this.area.h,_284); | |
8433 | } | |
8434 | }; | |
8435 | PlotKit.SVGRenderer.prototype._renderPieAxis=function(){ | |
8436 | if(this.layout.xticks){ | |
8437 | var _290=new Array(); | |
8438 | for(var i=0;i<this.layout.slices.length;i++){ | |
8439 | _290[this.layout.slices[i].xval]=this.layout.slices[i]; | |
8440 | } | |
8441 | var _291=this.area.x+this.area.w*0.5; | |
8442 | var _292=this.area.y+this.area.h*0.5; | |
8443 | var _293=Math.min(this.area.w*this.options.pieRadius+10,this.area.h*this.options.pieRadius+10); | |
8444 | var _294=this.options.axisLabelWidth; | |
8445 | for(var i=0;i<this.layout.xticks.length;i++){ | |
8446 | var _295=_290[this.layout.xticks[i][0]]; | |
8447 | if(MochiKit.Base.isUndefinedOrNull(_295)){ | |
8448 | continue; | |
8449 | } | |
8450 | var _296=(_295.startAngle+_295.endAngle)/2; | |
8451 | var _297=_296; | |
8452 | if(_297>Math.PI*2){ | |
8453 | _297=_297-Math.PI*2; | |
8454 | }else{ | |
8455 | if(_297<0){ | |
8456 | _297=_297+Math.PI*2; | |
8457 | } | |
8458 | } | |
8459 | var _298=_291+Math.sin(_297)*(_293+10); | |
8460 | var _299=_292-Math.cos(_297)*(_293+10); | |
8461 | var _300={"position":"absolute","zIndex":11,"width":_294+"px","fontSize":this.options.axisLabelFontSize+"px","overflow":"hidden","color":this.options.axisLabelColor.toHexString()}; | |
8462 | var _301={"width":_294+"px","fontSize":this.options.axisLabelFontSize+"px","height":(this.options.axisLabelFontSize+3)+"px","fill":this.options.axisLabelColor.toRGBString()}; | |
8463 | if(_297<=Math.PI*0.5){ | |
8464 | MochiKit.Base.update(_300,{"textAlign":"left","verticalAlign":"top","left":_298+"px","top":(_299-this.options.axisLabelFontSize)+"px"}); | |
8465 | MochiKit.Base.update(_301,{"x":_298,"y":(_299-this.options.axisLabelFontSize),"textAnchor":"left"}); | |
8466 | }else{ | |
8467 | if((_297>Math.PI*0.5)&&(_297<=Math.PI)){ | |
8468 | MochiKit.Base.update(_300,{"textAlign":"left","verticalAlign":"bottom","left":_298+"px","top":_299+"px"}); | |
8469 | MochiKit.Base.update(_301,{"textAnchor":"left","x":_298,"y":_299}); | |
8470 | }else{ | |
8471 | if((_297>Math.PI)&&(_297<=Math.PI*1.5)){ | |
8472 | MochiKit.Base.update(_300,{"textAlign":"right","verticalAlign":"bottom","left":_298+"px","top":_299+"px"}); | |
8473 | MochiKit.Base.update(_301,{"textAnchor":"right","x":_298-_294,"y":_299}); | |
8474 | }else{ | |
8475 | MochiKit.Base.update(_300,{"textAlign":"left","verticalAlign":"bottom","left":_298+"px","top":_299+"px"}); | |
8476 | MochiKit.Base.update(_301,{"textAnchor":"left","x":_298-_294,"y":_299-this.options.axisLabelFontSize}); | |
8477 | } | |
8478 | } | |
8479 | } | |
8480 | if(this.options.axisLabelUseDiv){ | |
8481 | var _302=DIV({"style":_300},this.layout.xticks[i][1]); | |
8482 | this.xlabels.push(_302); | |
8483 | MochiKit.DOM.appendChildNodes(this.container,_302); | |
8484 | }else{ | |
8485 | var _302=this.createSVGElement("text",_301); | |
8486 | _302.appendChild(this.document.createTextNode(this.layout.xticks[i][1])); | |
8487 | this.root.appendChild(_302); | |
8488 | } | |
8489 | } | |
8490 | } | |
8491 | }; | |
8492 | PlotKit.SVGRenderer.prototype._renderBackground=function(){ | |
8493 | var opts={"stroke":"none","fill":this.options.backgroundColor.toRGBString()}; | |
8494 | this._drawRect(0,0,this.width,this.height,opts); | |
8495 | }; | |
8496 | PlotKit.SVGRenderer.prototype._drawRect=function(x,y,w,h,_304){ | |
8497 | var _305={x:x+"px",y:y+"px",width:w+"px",height:h+"px"}; | |
8498 | if(_304){ | |
8499 | MochiKit.Base.update(_305,_304); | |
8500 | } | |
8501 | var elem=this.createSVGElement("rect",_305); | |
8502 | this.root.appendChild(elem); | |
8503 | }; | |
8504 | PlotKit.SVGRenderer.prototype._drawLine=function(x1,y1,x2,y2,_306){ | |
8505 | var _307={x1:x1+"px",y1:y1+"px",x2:x2+"px",y2:y2+"px"}; | |
8506 | if(_306){ | |
8507 | MochiKit.Base.update(_307,_306); | |
8508 | } | |
8509 | var elem=this.createSVGElement("line",_307); | |
8510 | this.root.appendChild(elem); | |
8511 | }; | |
8512 | PlotKit.SVGRenderer.prototype.clear=function(){ | |
8513 | while(this.element.firstChild){ | |
8514 | this.element.removeChild(this.element.firstChild); | |
8515 | } | |
8516 | if(this.options.axisLabelUseDiv){ | |
8517 | for(var i=0;i<this.xlabels.length;i++){ | |
8518 | MochiKit.DOM.removeElement(this.xlabels[i]); | |
8519 | } | |
8520 | for(var i=0;i<this.ylabels.length;i++){ | |
8521 | MochiKit.DOM.removeElement(this.ylabels[i]); | |
8522 | } | |
8523 | } | |
8524 | this.xlabels=new Array(); | |
8525 | this.ylabels=new Array(); | |
8526 | }; | |
8527 | PlotKit.SVGRenderer.prototype.createSVGElement=function(name,_309){ | |
8528 | var _310=MochiKit.Base.isUndefinedOrNull; | |
8529 | var elem; | |
8530 | var doc=_310(this.document)?document:this.document; | |
8531 | try{ | |
8532 | elem=doc.createElementNS(PlotKit.SVGRenderer.SVGNS,name); | |
8533 | } | |
8534 | catch(e){ | |
8535 | elem=doc.createElement(name); | |
8536 | elem.setAttribute("xmlns",PlotKit.SVGRenderer.SVGNS); | |
8537 | } | |
8538 | if(_309){ | |
8539 | MochiKit.DOM.updateNodeAttributes(elem,_309); | |
8540 | } | |
8541 | return elem; | |
8542 | }; | |
8543 | PlotKit.SVGRenderer.SVG=function(_312){ | |
8544 | var ie=navigator.appVersion.match(/MSIE (\d\.\d)/); | |
8545 | var _313=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); | |
8546 | if(ie&&(ie[1]>=6)&&(!_313)){ | |
8547 | var _314=_312["width"]?_312["width"]:"100"; | |
8548 | var _315=_312["height"]?_312["height"]:"100"; | |
8549 | var eid=_312["id"]?_312["id"]:"notunique"; | |
8550 | var html="<svg:svg width=\""+_314+"\" height=\""+_315+"\" "; | |
8551 | html+="id=\""+eid+"\" version=\"1.1\" baseProfile=\"full\" />"; | |
8552 | var _318=document.createElement(html); | |
8553 | var _319=_318.getSVGDocument().createElementNS(PlotKit.SVGRenderer.SVGNS,"svg"); | |
8554 | _319.setAttribute("width",_314); | |
8555 | _319.setAttribute("height",_315); | |
8556 | _318.getSVGDocument().appendChild(_319); | |
8557 | return _318; | |
8558 | }else{ | |
8559 | return PlotKit.SVGRenderer.prototype.createSVGElement("svg",_312); | |
8560 | } | |
8561 | }; | |
8562 | PlotKit.SVGRenderer.isSupported=function(){ | |
8563 | var _320=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); | |
8564 | var _321=navigator.appVersion.match(/MSIE (\d\.\d)/); | |
8565 | var _322=navigator.userAgent.match(/AppleWebKit\/(\d+)/); | |
8566 | var _323=navigator.userAgent.match(/Opera\/(\d*\.\d*)/); | |
8567 | var _324=navigator.userAgent.match(/rv:(\d*\.\d*).*Gecko/); | |
8568 | var _325="http://www.w3.org/TR/SVG11/feature#SVG"; | |
8569 | if(_321&&(_321[1]>=6)&&!_320){ | |
8570 | return document.implementation.hasFeature(_325,"1.1"); | |
8571 | } | |
8572 | if(_323&&(_323[1]>8.9)){ | |
8573 | return true; | |
8574 | } | |
8575 | if(_324&&(_324>1.7)){ | |
8576 | return true; | |
8577 | } | |
8578 | return false; | |
8579 | }; | |
8580 | PlotKit.SVG={}; | |
8581 | PlotKit.SVG.SVGRenderer=PlotKit.SVGRenderer; | |
8582 | PlotKit.SVG.EXPORT=["SVGRenderer"]; | |
8583 | PlotKit.SVG.EXPORT_OK=["SVGRenderer"]; | |
8584 | PlotKit.SVG.__new__=function(){ | |
8585 | var m=MochiKit.Base; | |
8586 | m.nameFunctions(this); | |
8587 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
8588 | }; | |
8589 | PlotKit.SVG.__new__(); | |
8590 | MochiKit.Base._exportSymbols(this,PlotKit.SVG); | |
8591 | try{ | |
8592 | if(typeof (PlotKit.CanvasRenderer)=="undefined"){ | |
8593 | throw ""; | |
8594 | } | |
8595 | } | |
8596 | catch(e){ | |
8597 | throw "SweetCanvas depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.{Layout, Canvas}"; | |
8598 | } | |
8599 | if(typeof (PlotKit.SweetCanvasRenderer)=="undefined"){ | |
8600 | PlotKit.SweetCanvasRenderer={}; | |
8601 | } | |
8602 | PlotKit.SweetCanvasRenderer=function(_326,_327,_328){ | |
8603 | if(arguments.length>0){ | |
8604 | this.__init__(_326,_327,_328); | |
8605 | } | |
8606 | }; | |
8607 | PlotKit.SweetCanvasRenderer.NAME="PlotKit.SweetCanvasRenderer"; | |
8608 | PlotKit.SweetCanvasRenderer.VERSION=PlotKit.VERSION; | |
8609 | PlotKit.SweetCanvasRenderer.__repr__=function(){ | |
8610 | return "["+this.NAME+" "+this.VERSION+"]"; | |
8611 | }; | |
8612 | PlotKit.SweetCanvasRenderer.toString=function(){ | |
8613 | return this.__repr__(); | |
8614 | }; | |
8615 | PlotKit.SweetCanvasRenderer.prototype=new PlotKit.CanvasRenderer(); | |
8616 | PlotKit.SweetCanvasRenderer.prototype.constructor=PlotKit.SweetCanvasRenderer; | |
8617 | PlotKit.SweetCanvasRenderer.__super__=PlotKit.CanvasRenderer.prototype; | |
8618 | PlotKit.SweetCanvasRenderer.prototype.__init__=function(el,_330,opts){ | |
8619 | var _331=PlotKit.Base.officeBlue(); | |
8620 | MochiKit.Base.update(_331,opts); | |
8621 | PlotKit.SweetCanvasRenderer.__super__.__init__.call(this,el,_330,_331); | |
8622 | }; | |
8623 | PlotKit.SweetCanvasRenderer.prototype._renderBarChart=function(){ | |
8624 | var bind=MochiKit.Base.bind; | |
8625 | var _332=Color.blackColor().colorWithAlpha(0.1).toRGBString(); | |
8626 | var _333=function(_334,x,y,w,h){ | |
8627 | _334.fillStyle=_332; | |
8628 | _334.fillRect(x-2,y-2,w+4,h+2); | |
8629 | _334.fillStyle=_332; | |
8630 | _334.fillRect(x-1,y-1,w+2,h+1); | |
8631 | }; | |
8632 | var _335=this.options.colorScheme.length; | |
8633 | var _336=this.options.colorScheme; | |
8634 | var _337=PlotKit.Base.keys(this.layout.datasets); | |
8635 | var _338=_337.length; | |
8636 | var _339=function(name){ | |
8637 | for(var i=0;i<_338;i++){ | |
8638 | if(name==_337[i]){ | |
8639 | return _336[i%_335]; | |
8640 | } | |
8641 | } | |
8642 | return _336[0]; | |
8643 | }; | |
8644 | var _340=function(_341,bar){ | |
8645 | var x=this.area.w*bar.x+this.area.x; | |
8646 | var y=this.area.h*bar.y+this.area.y; | |
8647 | var w=this.area.w*bar.w; | |
8648 | var h=this.area.h*bar.h; | |
8649 | if((w<1)||(h<1)){ | |
8650 | return; | |
8651 | } | |
8652 | _341.save(); | |
8653 | _341.shadowBlur=5; | |
8654 | _341.shadowColor=Color.fromHexString("#888888").toRGBString(); | |
8655 | if(this.isIE){ | |
8656 | _341.save(); | |
8657 | _341.fillStyle="#cccccc"; | |
8658 | _341.fillRect(x-2,y-2,w+4,h+2); | |
8659 | _341.restore(); | |
8660 | }else{ | |
8661 | _333(_341,x,y,w,h); | |
8662 | } | |
8663 | if(this.options.shouldFill){ | |
8664 | _341.fillStyle=_339(bar.name).toRGBString(); | |
8665 | _341.fillRect(x,y,w,h); | |
8666 | } | |
8667 | _341.shadowBlur=0; | |
8668 | _341.strokeStyle=Color.whiteColor().toRGBString(); | |
8669 | _341.lineWidth=2; | |
8670 | if(this.options.shouldStroke){ | |
8671 | _341.strokeRect(x,y,w,h); | |
8672 | } | |
8673 | _341.restore(); | |
8674 | }; | |
8675 | this._renderBarChartWrap(this.layout.bars,bind(_340,this)); | |
8676 | }; | |
8677 | PlotKit.SweetCanvasRenderer.prototype._renderLineChart=function(){ | |
8678 | var _342=this.element.getContext("2d"); | |
8679 | var _343=this.options.colorScheme.length; | |
8680 | var _344=this.options.colorScheme; | |
8681 | var _345=PlotKit.Base.keys(this.layout.datasets); | |
8682 | var _346=_345.length; | |
8683 | var bind=MochiKit.Base.bind; | |
8684 | for(var i=0;i<_346;i++){ | |
8685 | var _347=_345[i]; | |
8686 | var _348=_344[i%_343]; | |
8687 | var _349=this.options.strokeColorTransform; | |
8688 | _342.save(); | |
8689 | var _350=function(ctx){ | |
8690 | ctx.beginPath(); | |
8691 | ctx.moveTo(this.area.x,this.area.y+this.area.h); | |
8692 | var _351=function(ctx_,_352){ | |
8693 | if(_352.name==_347){ | |
8694 | ctx_.lineTo(this.area.w*_352.x+this.area.x,this.area.h*_352.y+this.area.y); | |
8695 | } | |
8696 | }; | |
8697 | MochiKit.Iter.forEach(this.layout.points,partial(_351,ctx),this); | |
8698 | ctx.lineTo(this.area.w+this.area.x,this.area.h+this.area.y); | |
8699 | ctx.lineTo(this.area.x,this.area.y+this.area.h); | |
8700 | ctx.closePath(); | |
8701 | }; | |
8702 | if(this.options.shouldFill){ | |
8703 | _342.save(); | |
8704 | if(this.isIE){ | |
8705 | _342.fillStyle="#cccccc"; | |
8706 | }else{ | |
8707 | _342.fillStyle=Color.blackColor().colorWithAlpha(0.2).toRGBString(); | |
8708 | } | |
8709 | _342.translate(-1,-2); | |
8710 | bind(_350,this)(_342); | |
8711 | if(this.options.shouldFill){ | |
8712 | _342.fill(); | |
8713 | } | |
8714 | _342.restore(); | |
8715 | } | |
8716 | _342.shadowBlur=5; | |
8717 | _342.shadowColor=Color.fromHexString("#888888").toRGBString(); | |
8718 | _342.fillStyle=_348.toRGBString(); | |
8719 | _342.lineWidth=2; | |
8720 | _342.strokeStyle=Color.whiteColor().toRGBString(); | |
8721 | if(this.options.shouldFill){ | |
8722 | bind(_350,this)(_342); | |
8723 | _342.fill(); | |
8724 | } | |
8725 | if(this.options.shouldStroke){ | |
8726 | bind(_350,this)(_342); | |
8727 | _342.stroke(); | |
8728 | } | |
8729 | _342.restore(); | |
8730 | } | |
8731 | }; | |
8732 | PlotKit.SweetCanvasRenderer.prototype._renderPieChart=function(){ | |
8733 | var _353=this.element.getContext("2d"); | |
8734 | var _354=this.options.colorScheme.length; | |
8735 | var _355=this.layout.slices; | |
8736 | var _356=this.area.x+this.area.w*0.5; | |
8737 | var _357=this.area.y+this.area.h*0.5; | |
8738 | var _358=Math.min(this.area.w*this.options.pieRadius,this.area.h*this.options.pieRadius); | |
8739 | if(this.isIE){ | |
8740 | _356=parseInt(_356); | |
8741 | _357=parseInt(_357); | |
8742 | _358=parseInt(_358); | |
8743 | } | |
8744 | if(!this.isIE){ | |
8745 | _353.save(); | |
8746 | var _359=Color.blackColor().colorWithAlpha(0.2); | |
8747 | _353.fillStyle=_359.toRGBString(); | |
8748 | _353.shadowBlur=5; | |
8749 | _353.shadowColor=Color.fromHexString("#888888").toRGBString(); | |
8750 | _353.translate(1,1); | |
8751 | _353.beginPath(); | |
8752 | _353.moveTo(_356,_357); | |
8753 | _353.arc(_356,_357,_358+2,0,Math.PI*2,false); | |
8754 | _353.closePath(); | |
8755 | _353.fill(); | |
8756 | _353.restore(); | |
8757 | } | |
8758 | _353.save(); | |
8759 | _353.strokeStyle=Color.whiteColor().toRGBString(); | |
8760 | _353.lineWidth=2; | |
8761 | for(var i=0;i<_355.length;i++){ | |
8762 | var _360=this.options.colorScheme[i%_354]; | |
8763 | _353.fillStyle=_360.toRGBString(); | |
8764 | var _361=function(){ | |
8765 | _353.beginPath(); | |
8766 | _353.moveTo(_356,_357); | |
8767 | _353.arc(_356,_357,_358,_355[i].startAngle-Math.PI/2,_355[i].endAngle-Math.PI/2,false); | |
8768 | _353.lineTo(_356,_357); | |
8769 | _353.closePath(); | |
8770 | }; | |
8771 | if(Math.abs(_355[i].startAngle-_355[i].endAngle)>0.0001){ | |
8772 | if(this.options.shouldFill){ | |
8773 | _361(); | |
8774 | _353.fill(); | |
8775 | } | |
8776 | if(this.options.shouldStroke){ | |
8777 | _361(); | |
8778 | _353.stroke(); | |
8779 | } | |
8780 | } | |
8781 | } | |
8782 | _353.restore(); | |
8783 | }; | |
8784 | PlotKit.SweetCanvasRenderer.prototype._renderBackground=function(){ | |
8785 | var _362=this.element.getContext("2d"); | |
8786 | if(this.layout.style=="bar"||this.layout.style=="line"){ | |
8787 | _362.save(); | |
8788 | _362.fillStyle=this.options.backgroundColor.toRGBString(); | |
8789 | _362.fillRect(this.area.x,this.area.y,this.area.w,this.area.h); | |
8790 | _362.strokeStyle=this.options.axisLineColor.toRGBString(); | |
8791 | _362.lineWidth=1; | |
8792 | var _363=this.layout.yticks; | |
8793 | var _364=false; | |
8794 | if(this.layout.style=="bar"&&this.layout.options.barOrientation=="horizontal"){ | |
8795 | _363=this.layout.xticks; | |
8796 | _364=true; | |
8797 | } | |
8798 | for(var i=0;i<_363.length;i++){ | |
8799 | var x1=0; | |
8800 | var y1=0; | |
8801 | var x2=0; | |
8802 | var y2=0; | |
8803 | if(_364){ | |
8804 | x1=_363[i][0]*this.area.w+this.area.x; | |
8805 | y1=this.area.y; | |
8806 | x2=x1; | |
8807 | y2=y1+this.area.h; | |
8808 | }else{ | |
8809 | x1=this.area.x; | |
8810 | y1=_363[i][0]*this.area.h+this.area.y; | |
8811 | x2=x1+this.area.w; | |
8812 | y2=y1; | |
8813 | } | |
8814 | _362.beginPath(); | |
8815 | _362.moveTo(x1,y1); | |
8816 | _362.lineTo(x2,y2); | |
8817 | _362.closePath(); | |
8818 | _362.stroke(); | |
8819 | } | |
8820 | _362.restore(); | |
8821 | }else{ | |
8822 | PlotKit.SweetCanvasRenderer.__super__._renderBackground.call(this); | |
8823 | } | |
8824 | }; | |
8825 | PlotKit.SweetCanvas={}; | |
8826 | PlotKit.SweetCanvas.SweetCanvasRenderer=PlotKit.SweetCanvasRenderer; | |
8827 | PlotKit.SweetCanvas.EXPORT=["SweetCanvasRenderer"]; | |
8828 | PlotKit.SweetCanvas.EXPORT_OK=["SweetCanvasRenderer"]; | |
8829 | PlotKit.SweetCanvas.__new__=function(){ | |
8830 | var m=MochiKit.Base; | |
8831 | m.nameFunctions(this); | |
8832 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
8833 | }; | |
8834 | PlotKit.SweetCanvas.__new__(); | |
8835 | MochiKit.Base._exportSymbols(this,PlotKit.SweetCanvas); | |
8836 | try{ | |
8837 | if(typeof (PlotKit.SVGRenderer)=="undefined"){ | |
8838 | throw ""; | |
8839 | } | |
8840 | } | |
8841 | catch(e){ | |
8842 | throw "SweetSVG depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.{Layout, SVG}"; | |
8843 | } | |
8844 | if(typeof (PlotKit.SweetSVGRenderer)=="undefined"){ | |
8845 | PlotKit.SweetSVGRenderer={}; | |
8846 | } | |
8847 | PlotKit.SweetSVGRenderer=function(_365,_366,_367){ | |
8848 | if(arguments.length>0){ | |
8849 | this.__init__(_365,_366,_367); | |
8850 | } | |
8851 | }; | |
8852 | PlotKit.SweetSVGRenderer.NAME="PlotKit.SweetSVGRenderer"; | |
8853 | PlotKit.SweetSVGRenderer.VERSION=PlotKit.VERSION; | |
8854 | PlotKit.SweetSVGRenderer.__repr__=function(){ | |
8855 | return "["+this.NAME+" "+this.VERSION+"]"; | |
8856 | }; | |
8857 | PlotKit.SweetSVGRenderer.toString=function(){ | |
8858 | return this.__repr__(); | |
8859 | }; | |
8860 | PlotKit.SweetSVGRenderer.prototype=new PlotKit.SVGRenderer(); | |
8861 | PlotKit.SweetSVGRenderer.prototype.constructor=PlotKit.SweetSVGRenderer; | |
8862 | PlotKit.SweetSVGRenderer.__super__=PlotKit.SVGRenderer.prototype; | |
8863 | PlotKit.SweetSVGRenderer.prototype.__init__=function(_368,_369,_370){ | |
8864 | var _371=PlotKit.Base.officeBlue(); | |
8865 | MochiKit.Base.update(_371,_370); | |
8866 | PlotKit.SweetSVGRenderer.__super__.__init__.call(this,_368,_369,_371); | |
8867 | }; | |
8868 | PlotKit.SweetSVGRenderer.prototype._addDropShadowFilter=function(){ | |
8869 | var _372=this.createSVGElement("filter",{x:0,y:0,"id":"dropShadow"}); | |
8870 | var _373=this.createSVGElement("feOffset",{"in":"SourceGraphic","dx":0,"dy":0,"result":"topCopy"}); | |
8871 | var blur=this.createSVGElement("feGaussianBlur",{"in":"SourceAlpha","StdDeviation":2,"result":"shadow"}); | |
8872 | var _375=this.createSVGElement("feOffset",{"in":"shadow","dx":-1,"dy":-2,"result":"movedShadow"}); | |
8873 | var _376=this.createSVGElement("feMerge"); | |
8874 | var _377=this.createSVGElement("feMergeNode",{"in":"topCopy"}); | |
8875 | var _378=this.createSVGElement("feMergeNode",{"in":"movedShadow"}); | |
8876 | _376.appendChild(_377); | |
8877 | _376.appendChild(_378); | |
8878 | _372.appendChild(_373); | |
8879 | _372.appendChild(blur); | |
8880 | _372.appendChild(_375); | |
8881 | _372.appendChild(_376); | |
8882 | this.defs.appendChild(_372); | |
8883 | }; | |
8884 | PlotKit.SweetSVGRenderer.prototype._renderBarChart=function(){ | |
8885 | var bind=MochiKit.Base.bind; | |
8886 | var _379=Color.blackColor().toRGBString(); | |
8887 | var _380="fill:"+_379+";fill-opacity:0.15"; | |
8888 | var _381="stroke-width: 2.0; stroke:"+Color.whiteColor().toRGBString(); | |
8889 | var _382=function(_383,bar){ | |
8890 | var x=this.area.w*bar.x+this.area.x; | |
8891 | var y=this.area.h*bar.y+this.area.y; | |
8892 | var w=this.area.w*bar.w; | |
8893 | var h=this.area.h*bar.h; | |
8894 | if((w<1)||(h<1)){ | |
8895 | return; | |
8896 | } | |
8897 | _383["style"]=_381; | |
8898 | this._drawRect(x-2,y-1,w+4,h+2,{"style":_380}); | |
8899 | this._drawRect(x,y,w,h,_383); | |
8900 | }; | |
8901 | this._renderBarOrLine(this.layout.bars,bind(_382,this)); | |
8902 | }; | |
8903 | PlotKit.SweetSVGRenderer.prototype._renderLineChart=function(){ | |
8904 | var bind=MochiKit.Base.bind; | |
8905 | var _384=Color.blackColor().toRGBString(); | |
8906 | var _385="fill:"+_384+";fill-opacity:0.15"; | |
8907 | var _386="stroke-width: 2.0; stroke:"+Color.whiteColor().toRGBString(); | |
8908 | var _387=function(_388,_389){ | |
8909 | this._tempPointsBuffer+=(this.area.w*_389.x+this.area.x)+","+(this.area.h*_389.y+this.area.y)+" "; | |
8910 | }; | |
8911 | var _390=function(_391){ | |
8912 | this._tempPointsBuffer=""; | |
8913 | this._tempPointsBuffer+=(this.area.x)+","+(this.area.y+this.area.h)+" "; | |
8914 | }; | |
8915 | var _392=function(_393){ | |
8916 | this._tempPointsBuffer+=(this.area.w+this.area.x)+","+(this.area.h+this.area.y); | |
8917 | _393["points"]=this._tempPointsBuffer; | |
8918 | _393["stroke"]="none"; | |
8919 | _393["transform"]="translate(-2, -1)"; | |
8920 | _393["style"]=_385; | |
8921 | var _394=this.createSVGElement("polygon",_393); | |
8922 | this.root.appendChild(_394); | |
8923 | _393["transform"]=""; | |
8924 | _393["style"]=_386; | |
8925 | var elem=this.createSVGElement("polygon",_393); | |
8926 | this.root.appendChild(elem); | |
8927 | }; | |
8928 | this._renderBarOrLine(this.layout.points,bind(_387,this),bind(_390,this),bind(_392,this)); | |
8929 | }; | |
8930 | PlotKit.SweetSVGRenderer.prototype._renderPieChart=function(){ | |
8931 | var _395=this.area.x+this.area.w*0.5; | |
8932 | var _396=this.area.y+this.area.h*0.5; | |
8933 | var _397=Color.blackColor().toRGBString(); | |
8934 | var _398=Math.min(this.area.w*this.options.pieRadius,this.area.h*this.options.pieRadius); | |
8935 | var _399="fill:"+_397+";fill-opacity:0.15"; | |
8936 | var _400=this.createSVGElement("circle",{"style":_399,"cx":_395+1,"cy":_396+1,"r":_398+1}); | |
8937 | this.root.appendChild(_400); | |
8938 | PlotKit.SweetSVGRenderer.__super__._renderPieChart.call(this); | |
8939 | }; | |
8940 | PlotKit.SweetSVGRenderer.prototype._renderBackground=function(){ | |
8941 | var _401={"fill":this.options.backgroundColor.toRGBString(),"stroke":"none"}; | |
8942 | if(this.layout.style=="bar"||this.layout.style=="line"){ | |
8943 | this._drawRect(this.area.x,this.area.y,this.area.w,this.area.h,_401); | |
8944 | var _402=this.layout.yticks; | |
8945 | var _403=false; | |
8946 | if(this.layout.style=="bar"&&this.layout.options.barOrientation=="horizontal"){ | |
8947 | _402=this.layout.xticks; | |
8948 | _403=true; | |
8949 | } | |
8950 | for(var i=0;i<_402.length;i++){ | |
8951 | var x=0; | |
8952 | var y=0; | |
8953 | var w=0; | |
8954 | var h=0; | |
8955 | if(_403){ | |
8956 | x=_402[i][0]*this.area.w+this.area.x; | |
8957 | y=this.area.y; | |
8958 | w=1; | |
8959 | h=this.area.w; | |
8960 | }else{ | |
8961 | x=this.area.x; | |
8962 | y=_402[i][0]*this.area.h+this.area.y; | |
8963 | w=this.area.w; | |
8964 | h=1; | |
8965 | } | |
8966 | this._drawRect(x,y,w,h,{"fill":this.options.axisLineColor.toRGBString()}); | |
8967 | } | |
8968 | }else{ | |
8969 | PlotKit.SweetSVGRenderer.__super__._renderBackground.call(this); | |
8970 | } | |
8971 | }; | |
8972 | PlotKit.SweetSVG={}; | |
8973 | PlotKit.SweetSVG.SweetSVGRenderer=PlotKit.SweetSVGRenderer; | |
8974 | PlotKit.SweetSVG.EXPORT=["SweetSVGRenderer"]; | |
8975 | PlotKit.SweetSVG.EXPORT_OK=["SweetSVGRenderer"]; | |
8976 | PlotKit.SweetSVG.__new__=function(){ | |
8977 | var m=MochiKit.Base; | |
8978 | m.nameFunctions(this); | |
8979 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
8980 | }; | |
8981 | PlotKit.SweetSVG.__new__(); | |
8982 | MochiKit.Base._exportSymbols(this,PlotKit.SweetSVG); | |
8983 | try{ | |
8984 | if(typeof (PlotKit.CanvasRenderer)=="undefined"){ | |
8985 | throw ""; | |
8986 | } | |
8987 | } | |
8988 | catch(e){ | |
8989 | throw "PlotKit.EasyPlot depends on all of PlotKit's components"; | |
8990 | } | |
8991 | if(typeof (PlotKit.EasyPlot)=="undefined"){ | |
8992 | PlotKit.EasyPlot={}; | |
8993 | } | |
8994 | PlotKit.EasyPlot.NAME="PlotKit.EasyPlot"; | |
8995 | PlotKit.EasyPlot.VERSION=PlotKit.VERSION; | |
8996 | PlotKit.EasyPlot.__repr__=function(){ | |
8997 | return "["+this.NAME+" "+this.VERSION+"]"; | |
8998 | }; | |
8999 | PlotKit.EasyPlot.toString=function(){ | |
9000 | return this.__repr__(); | |
9001 | }; | |
9002 | PlotKit.EasyPlot=function(_404,_405,_406,_407){ | |
9003 | this.layout=new Layout(_404,_405); | |
9004 | this.divElem=_406; | |
9005 | this.width=parseInt(_406.getAttribute("width")); | |
9006 | this.height=parseInt(_406.getAttribute("height")); | |
9007 | this.deferredCount=0; | |
9008 | if(this.width<1){ | |
9009 | this.width=this.divElem.width?this.divElem.width:300; | |
9010 | } | |
9011 | if(this.height<1){ | |
9012 | this.height=this.divElem.height?this.divElem.height:300; | |
9013 | } | |
9014 | if(isArrayLike(_407)){ | |
9015 | for(var i=0;i<_407.length;i++){ | |
9016 | if(typeof (_407[i])=="string"){ | |
9017 | this.deferredCount++; | |
9018 | var d=MochiKit.Async.doSimpleXMLHttpRequest(_407[i]); | |
9019 | d.addCallback(MochiKit.Base.bind(PlotKit.EasyPlot.onDataLoaded,this)); | |
9020 | }else{ | |
9021 | if(isArrayLike(_407[i])){ | |
9022 | this.layout.addDataset("data-"+i,_407[i]); | |
9023 | } | |
9024 | } | |
9025 | } | |
9026 | }else{ | |
9027 | if(!isUndefinedOrNull(_407)){ | |
9028 | throw "Passed datasources are not Array like"; | |
9029 | } | |
9030 | } | |
9031 | if(CanvasRenderer.isSupported()){ | |
9032 | this.element=CANVAS({"id":this.divElem.getAttribute("id")+"-canvas","width":this.width,"height":this.height},""); | |
9033 | this.divElem.appendChild(this.element); | |
9034 | this.renderer=new SweetCanvasRenderer(this.element,this.layout,_405); | |
9035 | }else{ | |
9036 | if(SVGRenderer.isSupported()){ | |
9037 | this.element=SVGRenderer.SVG({"id":this.divElem.getAttribute("id")+"-svg","width":this.width,"height":this.height,"version":"1.1","baseProfile":"full"},""); | |
9038 | this.divElem.appendChild(this.element); | |
9039 | this.renderer=new SweetSVGRenderer(this.element,this.layout,_405); | |
9040 | } | |
9041 | } | |
9042 | if((this.deferredCount==0)&&(PlotKit.Base.keys(this.layout.datasets).length>0)){ | |
9043 | this.layout.evaluate(); | |
9044 | this.renderer.clear(); | |
9045 | this.renderer.render(); | |
9046 | } | |
9047 | }; | |
9048 | PlotKit.EasyPlot.onDataLoaded=function(_409){ | |
9049 | var _410=new Array(); | |
9050 | var _411=_409.responseText.split("\n"); | |
9051 | for(var i=0;i<_411.length;i++){ | |
9052 | var _412=MochiKit.Format.strip(_411[i]); | |
9053 | if((_412.length>1)&&(_412.charAt(0)!="#")){ | |
9054 | _410.push(_412.split(",")); | |
9055 | } | |
9056 | } | |
9057 | this.layout.addDataset("data-ajax-"+this.deferredCount,_410); | |
9058 | this.deferredCount--; | |
9059 | if((this.deferredCount==0)&&(PlotKit.Base.keys(this.layout.datasets).length>0)){ | |
9060 | this.layout.evaluate(); | |
9061 | this.renderer.clear(); | |
9062 | this.renderer.render(); | |
9063 | } | |
9064 | }; | |
9065 | PlotKit.EasyPlot.prototype.reload=function(){ | |
9066 | this.layout.evaluate(); | |
9067 | this.renderer.clear(); | |
9068 | this.renderer.render(); | |
9069 | }; | |
9070 | PlotKit.EasyPlotModule={}; | |
9071 | PlotKit.EasyPlotModule.EasyPlot=PlotKit.EasyPlot; | |
9072 | PlotKit.EasyPlotModule.EXPORT=["EasyPlot"]; | |
9073 | PlotKit.EasyPlotModule.EXPORT_OK=[]; | |
9074 | PlotKit.EasyPlotModule.__new__=function(){ | |
9075 | var m=MochiKit.Base; | |
9076 | m.nameFunctions(this); | |
9077 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
9078 | }; | |
9079 | PlotKit.EasyPlotModule.__new__(); | |
9080 | MochiKit.Base._exportSymbols(this,PlotKit.EasyPlotModule); | |
9081 | ||
9082 | ||
9083 | // Copyright 2006 Dan Vanderkam (danvdk@gmail.com) | |
9084 | // All Rights Reserved. | |
9085 | ||
9086 | /** | |
9087 | * @fileoverview Subclasses various parts of PlotKit to meet the additional | |
9088 | * needs of DateGraph: grid overlays and error bars | |
9089 | */ | |
9090 | ||
9091 | // Subclass PlotKit.Layout to add: | |
9092 | // 1. Sigma/errorBars properties | |
9093 | // 2. Copy error terms for PlotKit.CanvasRenderer._renderLineChart | |
9094 | ||
9095 | /** | |
9096 | * Creates a new DateGraphLayout object. Options are the same as those allowed | |
9097 | * by the PlotKit.Layout constructor. | |
9098 | * @param {Object} options Options for PlotKit.Layout | |
9099 | * @return {Object} The DateGraphLayout object | |
9100 | */ | |
9101 | DateGraphLayout = function(options) { | |
9102 | PlotKit.Layout.call(this, "line", options); | |
9103 | }; | |
9104 | DateGraphLayout.prototype = new PlotKit.Layout(); | |
9105 | ||
9106 | /** | |
9107 | * Behaves the same way as PlotKit.Layout, but also copies the errors | |
9108 | * @private | |
9109 | */ | |
9110 | DateGraphLayout.prototype.evaluateWithError = function() { | |
9111 | this.evaluate(); | |
9112 | if (!this.options.errorBars) return; | |
9113 | ||
9114 | // Copy over the error terms | |
9115 | var i = 0; // index in this.points | |
9116 | for (var setName in this.datasets) { | |
9117 | var j = 0; | |
9118 | var dataset = this.datasets[setName]; | |
9119 | if (PlotKit.Base.isFuncLike(dataset)) continue; | |
9120 | for (var j = 0; j < dataset.length; j++, i++) { | |
9121 | var item = dataset[j]; | |
9122 | var xv = parseFloat(item[0]); | |
9123 | var yv = parseFloat(item[1]); | |
9124 | ||
9125 | if (xv == this.points[i].xval && | |
9126 | yv == this.points[i].yval) { | |
9127 | this.points[i].errorMinus = parseFloat(item[2]); | |
9128 | this.points[i].errorPlus = parseFloat(item[3]); | |
9129 | } | |
9130 | } | |
9131 | } | |
9132 | }; | |
9133 | ||
9134 | /** | |
9135 | * Convenience function to remove all the data sets from a graph | |
9136 | */ | |
9137 | DateGraphLayout.prototype.removeAllDatasets = function() { | |
9138 | delete this.datasets; | |
9139 | this.datasets = new Array(); | |
9140 | }; | |
9141 | ||
9142 | /** | |
9143 | * Change the values of various layout options | |
9144 | * @param {Object} new_options an associative array of new properties | |
9145 | */ | |
9146 | DateGraphLayout.prototype.updateOptions = function(new_options) { | |
9147 | MochiKit.Base.update(this.options, new_options ? new_options : {}); | |
9148 | }; | |
9149 | ||
9150 | // Subclass PlotKit.CanvasRenderer to add: | |
9151 | // 1. X/Y grid overlay | |
9152 | // 2. Ability to draw error bars (if required) | |
9153 | ||
9154 | /** | |
9155 | * Sets some PlotKit.CanvasRenderer options | |
9156 | * @param {Object} element The canvas to attach to | |
9157 | * @param {Layout} layout The DateGraphLayout object for this graph. | |
9158 | * @param {Object} options Options to pass on to CanvasRenderer | |
9159 | */ | |
9160 | DateGraphCanvasRenderer = function(element, layout, options) { | |
9161 | PlotKit.CanvasRenderer.call(this, element, layout, options); | |
9162 | this.options.shouldFill = false; | |
9163 | this.options.shouldStroke = true; | |
9164 | this.options.drawYGrid = true; | |
9165 | this.options.drawXGrid = true; | |
9166 | this.options.gridLineColor = MochiKit.Color.Color.grayColor(); | |
9167 | MochiKit.Base.update(this.options, options); | |
9168 | ||
9169 | // TODO(danvk) This shouldn't be necessary: effects should be overlaid | |
9170 | this.options.drawBackground = false; | |
9171 | }; | |
9172 | DateGraphCanvasRenderer.prototype = new PlotKit.CanvasRenderer(); | |
9173 | ||
9174 | /** | |
9175 | * Draw an X/Y grid on top of the existing plot | |
9176 | */ | |
9177 | DateGraphCanvasRenderer.prototype.render = function() { | |
9178 | // Do the ordinary rendering, as before | |
9179 | // TODO(danvk) Call super.render() | |
9180 | this._renderLineChart(); | |
9181 | this._renderLineAxis(); | |
9182 | ||
9183 | // Draw the new X/Y grid | |
9184 | var ctx = this.element.getContext("2d"); | |
9185 | if (this.options.drawYGrid) { | |
9186 | var ticks = this.layout.yticks; | |
9187 | ctx.save(); | |
9188 | ctx.strokeStyle = this.options.gridLineColor.toRGBString(); | |
9189 | ctx.lineWidth = this.options.axisLineWidth; | |
9190 | for (var i = 0; i < ticks.length; i++) { | |
9191 | var x = this.area.x; | |
9192 | var y = this.area.y + ticks[i][0] * this.area.h; | |
9193 | ctx.beginPath(); | |
9194 | ctx.moveTo(x, y); | |
9195 | ctx.lineTo(x + this.area.w, y); | |
9196 | ctx.closePath(); | |
9197 | ctx.stroke(); | |
9198 | } | |
9199 | } | |
9200 | ||
9201 | if (this.options.drawXGrid) { | |
9202 | var ticks = this.layout.xticks; | |
9203 | ctx.save(); | |
9204 | ctx.strokeStyle = this.options.gridLineColor.toRGBString(); | |
9205 | ctx.lineWidth = this.options.axisLineWidth; | |
9206 | for (var i=0; i<ticks.length; i++) { | |
9207 | var x = this.area.x + ticks[i][0] * this.area.w; | |
9208 | var y = this.area.y + this.area.h; | |
9209 | ctx.beginPath(); | |
9210 | ctx.moveTo(x, y); | |
9211 | ctx.lineTo(x, this.area.y); | |
9212 | ctx.closePath(); | |
9213 | ctx.stroke(); | |
9214 | } | |
9215 | } | |
9216 | }; | |
9217 | ||
9218 | /** | |
9219 | * Overrides the CanvasRenderer method to draw error bars | |
9220 | */ | |
9221 | DateGraphCanvasRenderer.prototype._renderLineChart = function() { | |
9222 | var context = this.element.getContext("2d"); | |
9223 | var colorCount = this.options.colorScheme.length; | |
9224 | var colorScheme = this.options.colorScheme; | |
9225 | var setNames = MochiKit.Base.keys(this.layout.datasets); | |
9226 | var errorBars = this.layout.options.errorBars; | |
9227 | var setCount = setNames.length; | |
9228 | var bind = MochiKit.Base.bind; | |
9229 | var partial = MochiKit.Base.partial; | |
9230 | ||
9231 | //Update Points | |
9232 | var updatePoint = function(point) { | |
9233 | point.canvasx = this.area.w * point.x + this.area.x; | |
9234 | point.canvasy = this.area.h * point.y + this.area.y; | |
9235 | } | |
9236 | MochiKit.Iter.forEach(this.layout.points, updatePoint, this); | |
9237 | ||
9238 | // create paths | |
9239 | var makePath = function(ctx) { | |
9240 | for (var i = 0; i < setCount; i++) { | |
9241 | var setName = setNames[i]; | |
9242 | var color = colorScheme[i%colorCount]; | |
9243 | var strokeX = this.options.strokeColorTransform; | |
9244 | ||
9245 | // setup graphics context | |
9246 | context.save(); | |
9247 | context.strokeStyle = color.toRGBString(); | |
9248 | context.lineWidth = this.options.strokeWidth; | |
9249 | ctx.beginPath(); | |
9250 | var point = this.layout.points[0]; | |
9251 | var first_point = true; | |
9252 | var addPoint = function(ctx_, point) { | |
9253 | if (point.name == setName) { | |
9254 | if (first_point) | |
9255 | ctx_.moveTo(point.canvasx, point.canvasy); | |
9256 | else | |
9257 | ctx_.lineTo(point.canvasx, point.canvasy); | |
9258 | first_point = false; | |
9259 | } | |
9260 | }; | |
9261 | MochiKit.Iter.forEach(this.layout.points, partial(addPoint, ctx), this); | |
9262 | ctx.stroke(); | |
9263 | } | |
9264 | }; | |
9265 | ||
9266 | var makeErrorBars = function(ctx) { | |
9267 | for (var i = 0; i < setCount; i++) { | |
9268 | var setName = setNames[i]; | |
9269 | var color = colorScheme[i % colorCount]; | |
9270 | var strokeX = this.options.strokeColorTransform; | |
9271 | ||
9272 | // setup graphics context | |
9273 | context.save(); | |
9274 | context.strokeStyle = color.toRGBString(); | |
9275 | context.lineWidth = this.options.strokeWidth; | |
9276 | var prevX = -1; | |
9277 | var prevYs = [-1, -1]; | |
9278 | var count = 0; | |
9279 | var yscale = this.layout.yscale; | |
9280 | var errorTrapezoid = function(ctx_,point) { | |
9281 | count++; | |
9282 | if (point.name == setName) { | |
9283 | var newYs = [ point.y - point.errorPlus * yscale, | |
9284 | point.y + point.errorMinus * yscale ]; | |
9285 | newYs[0] = this.area.h * newYs[0] + this.area.y; | |
9286 | newYs[1] = this.area.h * newYs[1] + this.area.y; | |
9287 | if (prevX >= 0) { | |
9288 | ctx_.moveTo(prevX, prevYs[0]); | |
9289 | ctx_.lineTo(point.canvasx, newYs[0]); | |
9290 | ctx_.lineTo(point.canvasx, newYs[1]); | |
9291 | ctx_.lineTo(prevX, prevYs[1]); | |
9292 | ctx_.closePath(); | |
9293 | } | |
9294 | prevYs[0] = newYs[0]; | |
9295 | prevYs[1] = newYs[1]; | |
9296 | prevX = point.canvasx; | |
9297 | } | |
9298 | }; | |
9299 | // should be same color as the lines | |
9300 | var err_color = color.colorWithAlpha(0.15); | |
9301 | ctx.fillStyle = err_color.toRGBString(); | |
9302 | ctx.beginPath(); | |
9303 | MochiKit.Iter.forEach(this.layout.points, partial(errorTrapezoid, ctx), this); | |
9304 | ctx.fill(); | |
9305 | } | |
9306 | }; | |
9307 | ||
9308 | if (errorBars) | |
9309 | bind(makeErrorBars, this)(context); | |
9310 | bind(makePath, this)(context); | |
9311 | context.restore(); | |
9312 | }; | |
9313 | // Copyright 2006 Dan Vanderkam (danvdk@gmail.com) | |
9314 | // All Rights Reserved. | |
9315 | ||
9316 | /** | |
9317 | * @fileoverview Creates an interactive, zoomable graph based on a CSV file or | |
9318 | * string. DateGraph can handle multiple series with or without error bars. The | |
9319 | * date/value ranges will be automatically set. DateGraph uses the | |
9320 | * <canvas> tag, so it only works in FF1.5+. | |
9321 | * @author danvdk@gmail.com (Dan Vanderkam) | |
9322 | ||
9323 | Usage: | |
9324 | <div id="graphdiv" style="width:800px; height:500px;"></div> | |
9325 | <script type="text/javascript"> | |
9326 | new DateGraph(document.getElementById("graphdiv"), | |
9327 | "datafile.csv", | |
9328 | ["Series 1", "Series 2"], | |
9329 | { }); // options | |
9330 | </script> | |
9331 | ||
9332 | The CSV file is of the form | |
9333 | ||
9334 | YYYYMMDD,A1,B1,C1 | |
9335 | YYYYMMDD,A2,B2,C2 | |
9336 | ||
9337 | If null is passed as the third parameter (series names), then the first line | |
9338 | of the CSV file is assumed to contain names for each series. | |
9339 | ||
9340 | If the 'errorBars' option is set in the constructor, the input should be of | |
9341 | the form | |
9342 | ||
9343 | YYYYMMDD,A1,sigmaA1,B1,sigmaB1,... | |
9344 | YYYYMMDD,A2,sigmaA2,B2,sigmaB2,... | |
9345 | ||
9346 | If the 'fractions' option is set, the input should be of the form: | |
9347 | ||
9348 | YYYYMMDD,A1/B1,A2/B2,... | |
9349 | YYYYMMDD,A1/B1,A2/B2,... | |
9350 | ||
9351 | And error bars will be calculated automatically using a binomial distribution. | |
9352 | ||
9353 | For further documentation and examples, see http://www/~danvk/dg/ | |
9354 | ||
9355 | */ | |
9356 | ||
9357 | /** | |
9358 | * An interactive, zoomable graph | |
9359 | * @param {String | Function} file A file containing CSV data or a function that | |
9360 | * returns this data. The expected format for each line is | |
9361 | * YYYYMMDD,val1,val2,... or, if attrs.errorBars is set, | |
9362 | * YYYYMMDD,val1,stddev1,val2,stddev2,... | |
9363 | * @param {Array.<String>} labels Labels for the data series | |
9364 | * @param {Object} attrs Various other attributes, e.g. errorBars determines | |
9365 | * whether the input data contains error ranges. | |
9366 | */ | |
9367 | DateGraph = function(div, file, labels, attrs) { | |
9368 | if (arguments.length > 0) | |
9369 | this.__init__(div, file, labels, attrs); | |
9370 | }; | |
9371 | ||
9372 | DateGraph.NAME = "DateGraph"; | |
9373 | DateGraph.VERSION = "1.1"; | |
9374 | DateGraph.__repr__ = function() { | |
9375 | return "[" + this.NAME + " " + this.VERSION + "]"; | |
9376 | }; | |
9377 | DateGraph.toString = function() { | |
9378 | return this.__repr__(); | |
9379 | }; | |
9380 | ||
9381 | // Various default values | |
9382 | DateGraph.DEFAULT_ROLL_PERIOD = 1; | |
9383 | DateGraph.DEFAULT_WIDTH = 480; | |
9384 | DateGraph.DEFAULT_HEIGHT = 320; | |
9385 | DateGraph.DEFAULT_STROKE_WIDTH = 1.0; | |
9386 | DateGraph.AXIS_LINE_WIDTH = 0.3; | |
9387 | ||
9388 | /** | |
9389 | * Initializes the DateGraph. This creates a new DIV and constructs the PlotKit | |
9390 | * and interaction <canvas> inside of it. See the constructor for details | |
9391 | * on the parameters. | |
9392 | * @param {String | Function} file Source data | |
9393 | * @param {Array.<String>} labels Names of the data series | |
9394 | * @param {Object} attrs Miscellaneous other options | |
9395 | * @private | |
9396 | */ | |
9397 | DateGraph.prototype.__init__ = function(div, file, labels, attrs) { | |
9398 | // Copy the important bits into the object | |
9399 | this.maindiv_ = div; | |
9400 | this.labels_ = labels; | |
9401 | this.file_ = file; | |
9402 | this.rollPeriod_ = attrs.rollPeriod || DateGraph.DEFAULT_ROLL_PERIOD; | |
9403 | this.previousVerticalX_ = -1; | |
9404 | this.width_ = parseInt(div.style.width, 10); | |
9405 | this.height_ = parseInt(div.style.height, 10); | |
9406 | this.errorBars_ = attrs.errorBars || false; | |
9407 | this.fractions_ = attrs.fractions || false; | |
9408 | this.strokeWidth_ = attrs.strokeWidth || DateGraph.DEFAULT_STROKE_WIDTH; | |
9409 | this.dateWindow_ = attrs.dateWindow || null; | |
9410 | this.valueRange_ = attrs.valueRange || null; | |
9411 | this.labelsSeparateLines = attrs.labelsSeparateLines || false; | |
9412 | this.labelsDiv_ = attrs.labelsDiv || null; | |
9413 | this.labelsKMB_ = attrs.labelsKMB || false; | |
9414 | this.minTickSize_ = attrs.minTickSize || 0; | |
9415 | this.xValueParser_ = attrs.xValueParser || DateGraph.prototype.dateParser; | |
9416 | this.xValueFormatter_ = attrs.xValueFormatter || | |
9417 | DateGraph.prototype.dateString_; | |
9418 | this.xTicker_ = attrs.xTicker || DateGraph.prototype.dateTicker; | |
9419 | this.sigma_ = attrs.sigma || 2.0; | |
9420 | this.wilsonInterval_ = attrs.wilsonInterval || true; | |
9421 | this.customBars_ = attrs.customBars || false; | |
9422 | this.attrs_ = attrs; | |
9423 | ||
9424 | // Make a note of whether labels will be pulled from the CSV file. | |
9425 | this.labelsFromCSV_ = (this.labels_ == null); | |
9426 | if (this.labels_ == null) | |
9427 | this.labels_ = []; | |
9428 | ||
9429 | // Prototype of the callback is "void clickCallback(event, date)" | |
9430 | this.clickCallback_ = attrs.clickCallback || null; | |
9431 | ||
9432 | // Prototype of zoom callback is "void dragCallback(minDate, maxDate)" | |
9433 | this.zoomCallback_ = attrs.zoomCallback || null; | |
9434 | ||
9435 | // Create the containing DIV and other interactive elements | |
9436 | this.createInterface_(); | |
9437 | ||
9438 | // Create the PlotKit grapher | |
9439 | this.layoutOptions_ = { 'errorBars': (this.errorBars_ || this.customBars_), | |
9440 | 'xOriginIsZero': false }; | |
9441 | MochiKit.Base.update(this.layoutOptions_, attrs); | |
9442 | this.setColors_(attrs); | |
9443 | ||
9444 | this.layout_ = new DateGraphLayout(this.layoutOptions_); | |
9445 | ||
9446 | this.renderOptions_ = { colorScheme: this.colors_, | |
9447 | strokeColor: null, | |
9448 | strokeWidth: this.strokeWidth_, | |
9449 | axisLabelFontSize: 14, | |
9450 | axisLineWidth: DateGraph.AXIS_LINE_WIDTH }; | |
9451 | MochiKit.Base.update(this.renderOptions_, attrs); | |
9452 | this.plotter_ = new DateGraphCanvasRenderer(this.hidden_, this.layout_, | |
9453 | this.renderOptions_); | |
9454 | ||
9455 | this.createStatusMessage_(); | |
9456 | this.createRollInterface_(); | |
9457 | this.createDragInterface_(); | |
9458 | ||
9459 | MochiKit.DOM.addLoadEvent(this.start_()); | |
9460 | }; | |
9461 | ||
9462 | /** | |
9463 | * Returns the current rolling period, as set by the user or an option. | |
9464 | * @return {Number} The number of days in the rolling window | |
9465 | */ | |
9466 | DateGraph.prototype.rollPeriod = function() { | |
9467 | return this.rollPeriod_; | |
9468 | } | |
9469 | ||
9470 | /** | |
9471 | * Generates interface elements for the DateGraph: a containing div, a div to | |
9472 | * display the current point, and a textbox to adjust the rolling average | |
9473 | * period. | |
9474 | * @private | |
9475 | */ | |
9476 | DateGraph.prototype.createInterface_ = function() { | |
9477 | // Create the all-enclosing graph div | |
9478 | var enclosing = this.maindiv_; | |
9479 | ||
9480 | this.graphDiv = MochiKit.DOM.DIV( { style: { 'width': this.width_ + "px", | |
9481 | 'height': this.height_ + "px" | |
9482 | }}); | |
9483 | appendChildNodes(enclosing, this.graphDiv); | |
9484 | ||
9485 | // Create the canvas to store | |
9486 | var canvas = MochiKit.DOM.CANVAS; | |
9487 | this.canvas_ = canvas( { style: { 'position': 'absolute' }, | |
9488 | width: this.width_, | |
9489 | height: this.height_}); | |
9490 | appendChildNodes(this.graphDiv, this.canvas_); | |
9491 | ||
9492 | this.hidden_ = this.createPlotKitCanvas_(this.canvas_); | |
9493 | connect(this.hidden_, 'onmousemove', this, function(e) { this.mouseMove_(e) }); | |
9494 | connect(this.hidden_, 'onmouseout', this, function(e) { this.mouseOut_(e) }); | |
9495 | } | |
9496 | ||
9497 | /** | |
9498 | * Creates the canvas containing the PlotKit graph. Only plotkit ever draws on | |
9499 | * this particular canvas. All DateGraph work is done on this.canvas_. | |
9500 | * @param {Object} canvas The DateGraph canvas to over which to overlay the plot | |
9501 | * @return {Object} The newly-created canvas | |
9502 | * @private | |
9503 | */ | |
9504 | DateGraph.prototype.createPlotKitCanvas_ = function(canvas) { | |
9505 | var h = document.createElement("canvas"); | |
9506 | h.style.position = "absolute"; | |
9507 | h.style.top = canvas.style.top; | |
9508 | h.style.left = canvas.style.left; | |
9509 | h.width = this.width_; | |
9510 | h.height = this.height_; | |
9511 | MochiKit.DOM.appendChildNodes(this.graphDiv, h); | |
9512 | return h; | |
9513 | }; | |
9514 | ||
9515 | /** | |
9516 | * Generate a set of distinct colors for the data series. This is done with a | |
9517 | * color wheel. Saturation/Value are customizable, and the hue is | |
9518 | * equally-spaced around the color wheel. If a custom set of colors is | |
9519 | * specified, that is used instead. | |
9520 | * @param {Object} attrs Various attributes, e.g. saturation and value | |
9521 | * @private | |
9522 | */ | |
9523 | DateGraph.prototype.setColors_ = function(attrs) { | |
9524 | var num = this.labels_.length; | |
9525 | this.colors_ = []; | |
9526 | if (!attrs.colors) { | |
9527 | var sat = attrs.colorSaturation || 1.0; | |
9528 | var val = attrs.colorValue || 0.5; | |
9529 | for (var i = 1; i <= num; i++) { | |
9530 | var hue = (1.0*i/(1+num)); | |
9531 | this.colors_.push( MochiKit.Color.Color.fromHSV(hue, sat, val) ); | |
9532 | } | |
9533 | } else { | |
9534 | for (var i = 0; i < num; i++) { | |
9535 | var colorStr = attrs.colors[i % attrs.colors.length]; | |
9536 | this.colors_.push( MochiKit.Color.Color.fromString(colorStr) ); | |
9537 | } | |
9538 | } | |
9539 | } | |
9540 | ||
9541 | /** | |
9542 | * Create the div that contains information on the selected point(s) | |
9543 | * This goes in the top right of the canvas, unless an external div has already | |
9544 | * been specified. | |
9545 | * @private | |
9546 | */ | |
9547 | DateGraph.prototype.createStatusMessage_ = function(){ | |
9548 | if (!this.labelsDiv_) { | |
9549 | var divWidth = 250; | |
9550 | var messagestyle = { "style": { | |
9551 | "position": "absolute", | |
9552 | "fontSize": "14px", | |
9553 | "zIndex": 10, | |
9554 | "width": divWidth + "px", | |
9555 | "top": "0px", | |
9556 | "left": this.width_ - divWidth + "px", | |
9557 | "background": "white", | |
9558 | "textAlign": "left", | |
9559 | "overflow": "hidden"}}; | |
9560 | this.labelsDiv_ = MochiKit.DOM.DIV(messagestyle); | |
9561 | MochiKit.DOM.appendChildNodes(this.graphDiv, this.labelsDiv_); | |
9562 | } | |
9563 | }; | |
9564 | ||
9565 | /** | |
9566 | * Create the text box to adjust the averaging period | |
9567 | * @return {Object} The newly-created text box | |
9568 | * @private | |
9569 | */ | |
9570 | DateGraph.prototype.createRollInterface_ = function() { | |
9571 | var padding = this.plotter_.options.padding; | |
9572 | var textAttr = { "type": "text", | |
9573 | "size": "2", | |
9574 | "value": this.rollPeriod_, | |
9575 | "style": { "position": "absolute", | |
9576 | "zIndex": 10, | |
9577 | "top": (this.height_ - 25 - padding.bottom) + "px", | |
9578 | "left": (padding.left+1) + "px" } | |
9579 | }; | |
9580 | var roller = MochiKit.DOM.INPUT(textAttr); | |
9581 | var pa = this.graphDiv; | |
9582 | MochiKit.DOM.appendChildNodes(pa, roller); | |
9583 | connect(roller, 'onchange', this, | |
9584 | function() { this.adjustRoll(roller.value); }); | |
9585 | return roller; | |
9586 | } | |
9587 | ||
9588 | /** | |
9589 | * Set up all the mouse handlers needed to capture dragging behavior for zoom | |
9590 | * events. Uses MochiKit.Signal to attach all the event handlers. | |
9591 | * @private | |
9592 | */ | |
9593 | DateGraph.prototype.createDragInterface_ = function() { | |
9594 | var self = this; | |
9595 | ||
9596 | // Tracks whether the mouse is down right now | |
9597 | var mouseDown = false; | |
9598 | var dragStartX = null; | |
9599 | var dragStartY = null; | |
9600 | var dragEndX = null; | |
9601 | var dragEndY = null; | |
9602 | var prevEndX = null; | |
9603 | ||
9604 | // Utility function to convert page-wide coordinates to canvas coords | |
9605 | var px = PlotKit.Base.findPosX(this.canvas_); | |
9606 | var py = PlotKit.Base.findPosY(this.canvas_); | |
9607 | var getX = function(e) { return e.mouse().page.x - px }; | |
9608 | var getY = function(e) { return e.mouse().page.y - py }; | |
9609 | ||
9610 | // Draw zoom rectangles when the mouse is down and the user moves around | |
9611 | connect(this.hidden_, 'onmousemove', function(event) { | |
9612 | if (mouseDown) { | |
9613 | dragEndX = getX(event); | |
9614 | dragEndY = getY(event); | |
9615 | ||
9616 | self.drawZoomRect_(dragStartX, dragEndX, prevEndX); | |
9617 | prevEndX = dragEndX; | |
9618 | } | |
9619 | }); | |
9620 | ||
9621 | // Track the beginning of drag events | |
9622 | connect(this.hidden_, 'onmousedown', function(event) { | |
9623 | mouseDown = true; | |
9624 | dragStartX = getX(event); | |
9625 | dragStartY = getY(event); | |
9626 | }); | |
9627 | ||
9628 | // If the user releases the mouse button during a drag, but not over the | |
9629 | // canvas, then it doesn't count as a zooming action. | |
9630 | connect(document, 'onmouseup', this, function(event) { | |
9631 | if (mouseDown) { | |
9632 | mouseDown = false; | |
9633 | dragStartX = null; | |
9634 | dragStartY = null; | |
9635 | } | |
9636 | }); | |
9637 | ||
9638 | // Temporarily cancel the dragging event when the mouse leaves the graph | |
9639 | connect(this.hidden_, 'onmouseout', this, function(event) { | |
9640 | if (mouseDown) { | |
9641 | dragEndX = null; | |
9642 | dragEndY = null; | |
9643 | } | |
9644 | }); | |
9645 | ||
9646 | // If the mouse is released on the canvas during a drag event, then it's a | |
9647 | // zoom. Only do the zoom if it's over a large enough area (>= 10 pixels) | |
9648 | connect(this.hidden_, 'onmouseup', this, function(event) { | |
9649 | if (mouseDown) { | |
9650 | mouseDown = false; | |
9651 | dragEndX = getX(event); | |
9652 | dragEndY = getY(event); | |
9653 | var regionWidth = Math.abs(dragEndX - dragStartX); | |
9654 | var regionHeight = Math.abs(dragEndY - dragStartY); | |
9655 | ||
9656 | if (regionWidth < 2 && regionHeight < 2 && | |
9657 | self.clickCallback_ != null && | |
9658 | self.lastx_ != undefined) { | |
9659 | self.clickCallback_(event, new Date(self.lastx_)); | |
9660 | } | |
9661 | ||
9662 | if (regionWidth >= 10) { | |
9663 | self.doZoom_(Math.min(dragStartX, dragEndX), | |
9664 | Math.max(dragStartX, dragEndX)); | |
9665 | } else { | |
9666 | self.canvas_.getContext("2d").clearRect(0, 0, | |
9667 | self.canvas_.width, | |
9668 | self.canvas_.height); | |
9669 | } | |
9670 | ||
9671 | dragStartX = null; | |
9672 | dragStartY = null; | |
9673 | } | |
9674 | }); | |
9675 | ||
9676 | // Double-clicking zooms back out | |
9677 | connect(this.hidden_, 'ondblclick', this, function(event) { | |
9678 | self.dateWindow_ = null; | |
9679 | self.drawGraph_(self.rawData_); | |
9680 | var minDate = self.rawData_[0][0]; | |
9681 | var maxDate = self.rawData_[self.rawData_.length - 1][0]; | |
9682 | self.zoomCallback_(minDate, maxDate); | |
9683 | }); | |
9684 | }; | |
9685 | ||
9686 | /** | |
9687 | * Draw a gray zoom rectangle over the desired area of the canvas. Also clears | |
9688 | * up any previous zoom rectangles that were drawn. This could be optimized to | |
9689 | * avoid extra redrawing, but it's tricky to avoid interactions with the status | |
9690 | * dots. | |
9691 | * @param {Number} startX The X position where the drag started, in canvas | |
9692 | * coordinates. | |
9693 | * @param {Number} endX The current X position of the drag, in canvas coords. | |
9694 | * @param {Number} prevEndX The value of endX on the previous call to this | |
9695 | * function. Used to avoid excess redrawing | |
9696 | * @private | |
9697 | */ | |
9698 | DateGraph.prototype.drawZoomRect_ = function(startX, endX, prevEndX) { | |
9699 | var ctx = this.canvas_.getContext("2d"); | |
9700 | ||
9701 | // Clean up from the previous rect if necessary | |
9702 | if (prevEndX) { | |
9703 | ctx.clearRect(Math.min(startX, prevEndX), 0, | |
9704 | Math.abs(startX - prevEndX), this.height_); | |
9705 | } | |
9706 | ||
9707 | // Draw a light-grey rectangle to show the new viewing area | |
9708 | if (endX && startX) { | |
9709 | ctx.fillStyle = "rgba(128,128,128,0.33)"; | |
9710 | ctx.fillRect(Math.min(startX, endX), 0, | |
9711 | Math.abs(endX - startX), this.height_); | |
9712 | } | |
9713 | }; | |
9714 | ||
9715 | /** | |
9716 | * Zoom to something containing [lowX, highX]. These are pixel coordinates | |
9717 | * in the canvas. The exact zoom window may be slightly larger if there are no | |
9718 | * data points near lowX or highX. This function redraws the graph. | |
9719 | * @param {Number} lowX The leftmost pixel value that should be visible. | |
9720 | * @param {Number} highX The rightmost pixel value that should be visible. | |
9721 | * @private | |
9722 | */ | |
9723 | DateGraph.prototype.doZoom_ = function(lowX, highX) { | |
9724 | // Find the earliest and latest dates contained in this canvasx range. | |
9725 | var points = this.layout_.points; | |
9726 | var minDate = null; | |
9727 | var maxDate = null; | |
9728 | // Find the nearest [minDate, maxDate] that contains [lowX, highX] | |
9729 | for (var i = 0; i < points.length; i++) { | |
9730 | var cx = points[i].canvasx; | |
9731 | var x = points[i].xval; | |
9732 | if (cx < lowX && (minDate == null || x > minDate)) minDate = x; | |
9733 | if (cx > highX && (maxDate == null || x < maxDate)) maxDate = x; | |
9734 | } | |
9735 | // Use the extremes if either is missing | |
9736 | if (minDate == null) minDate = points[0].xval; | |
9737 | if (maxDate == null) maxDate = points[points.length-1].xval; | |
9738 | ||
9739 | this.dateWindow_ = [minDate, maxDate]; | |
9740 | this.drawGraph_(this.rawData_); | |
9741 | this.zoomCallback_(minDate, maxDate); | |
9742 | }; | |
9743 | ||
9744 | /** | |
9745 | * When the mouse moves in the canvas, display information about a nearby data | |
9746 | * point and draw dots over those points in the data series. This function | |
9747 | * takes care of cleanup of previously-drawn dots. | |
9748 | * @param {Object} event The mousemove event from the browser. | |
9749 | * @private | |
9750 | */ | |
9751 | DateGraph.prototype.mouseMove_ = function(event) { | |
9752 | var canvasx = event.mouse().page.x - PlotKit.Base.findPosX(this.hidden_); | |
9753 | var points = this.layout_.points; | |
9754 | ||
9755 | var lastx = -1; | |
9756 | var lasty = -1; | |
9757 | ||
9758 | // Loop through all the points and find the date nearest to our current | |
9759 | // location. | |
9760 | var minDist = 1e+100; | |
9761 | var idx = -1; | |
9762 | for (var i = 0; i < points.length; i++) { | |
9763 | var dist = Math.abs(points[i].canvasx - canvasx); | |
9764 | if (dist > minDist) break; | |
9765 | minDist = dist; | |
9766 | idx = i; | |
9767 | } | |
9768 | if (idx >= 0) lastx = points[idx].xval; | |
9769 | // Check that you can really highlight the last day's data | |
9770 | if (canvasx > points[points.length-1].canvasx) | |
9771 | lastx = points[points.length-1].xval; | |
9772 | ||
9773 | // Extract the points we've selected | |
9774 | var selPoints = []; | |
9775 | for (var i = 0; i < points.length; i++) { | |
9776 | if (points[i].xval == lastx) { | |
9777 | selPoints.push(points[i]); | |
9778 | } | |
9779 | } | |
9780 | ||
9781 | // Clear the previously drawn vertical, if there is one | |
9782 | var circleSize = 3; | |
9783 | var ctx = this.canvas_.getContext("2d"); | |
9784 | if (this.previousVerticalX_ >= 0) { | |
9785 | var px = this.previousVerticalX_; | |
9786 | ctx.clearRect(px - circleSize - 1, 0, 2 * circleSize + 2, this.height_); | |
9787 | } | |
9788 | ||
9789 | if (selPoints.length > 0) { | |
9790 | var canvasx = selPoints[0].canvasx; | |
9791 | ||
9792 | // Set the status message to indicate the selected point(s) | |
9793 | var replace = this.xValueFormatter_(lastx) + ":"; | |
9794 | var clen = this.colors_.length; | |
9795 | for (var i = 0; i < selPoints.length; i++) { | |
9796 | if (this.labelsSeparateLines) { | |
9797 | replace += "<br/>"; | |
9798 | } | |
9799 | var point = selPoints[i]; | |
9800 | replace += " <b><font color='" + this.colors_[i%clen].toHexString() + "'>" | |
9801 | + point.name + "</font></b>:" | |
9802 | + this.round_(point.yval, 2); | |
9803 | } | |
9804 | this.labelsDiv_.innerHTML = replace; | |
9805 | ||
9806 | // Save last x position for callbacks. | |
9807 | this.lastx_ = lastx; | |
9808 | ||
9809 | // Draw colored circles over the center of each selected point | |
9810 | ctx.save() | |
9811 | for (var i = 0; i < selPoints.length; i++) { | |
9812 | ctx.beginPath(); | |
9813 | ctx.fillStyle = this.colors_[i%clen].toRGBString(); | |
9814 | ctx.arc(canvasx, selPoints[i%clen].canvasy, circleSize, 0, 360, false); | |
9815 | ctx.fill(); | |
9816 | } | |
9817 | ctx.restore(); | |
9818 | ||
9819 | this.previousVerticalX_ = canvasx; | |
9820 | } | |
9821 | }; | |
9822 | ||
9823 | /** | |
9824 | * The mouse has left the canvas. Clear out whatever artifacts remain | |
9825 | * @param {Object} event the mouseout event from the browser. | |
9826 | * @private | |
9827 | */ | |
9828 | DateGraph.prototype.mouseOut_ = function(event) { | |
9829 | // Get rid of the overlay data | |
9830 | var ctx = this.canvas_.getContext("2d"); | |
9831 | ctx.clearRect(0, 0, this.width_, this.height_); | |
9832 | this.labelsDiv_.innerHTML = ""; | |
9833 | }; | |
9834 | ||
9835 | /** | |
9836 | * Convert a JS date (millis since epoch) to YYYY/MM/DD | |
9837 | * @param {Number} date The JavaScript date (ms since epoch) | |
9838 | * @return {String} A date of the form "YYYY/MM/DD" | |
9839 | * @private | |
9840 | */ | |
9841 | DateGraph.prototype.dateString_ = function(date) { | |
9842 | var d = new Date(date); | |
9843 | ||
9844 | // Get the year: | |
9845 | var year = "" + d.getFullYear(); | |
9846 | // Get a 0 padded month string | |
9847 | var month = "" + (d.getMonth() + 1); //months are 0-offset, sigh | |
9848 | if (month.length < 2) month = "0" + month; | |
9849 | // Get a 0 padded day string | |
9850 | var day = "" + d.getDate(); | |
9851 | if (day.length < 2) day = "0" + day; | |
9852 | ||
9853 | return year + "/" + month + "/" + day; | |
9854 | }; | |
9855 | ||
9856 | /** | |
9857 | * Round a number to the specified number of digits past the decimal point. | |
9858 | * @param {Number} num The number to round | |
9859 | * @param {Number} places The number of decimals to which to round | |
9860 | * @return {Number} The rounded number | |
9861 | * @private | |
9862 | */ | |
9863 | DateGraph.prototype.round_ = function(num, places) { | |
9864 | var shift = Math.pow(10, places); | |
9865 | return Math.round(num * shift)/shift; | |
9866 | }; | |
9867 | ||
9868 | /** | |
9869 | * Fires when there's data available to be graphed. | |
9870 | * @param {String} data Raw CSV data to be plotted | |
9871 | * @private | |
9872 | */ | |
9873 | DateGraph.prototype.loadedEvent_ = function(data) { | |
9874 | this.rawData_ = this.parseCSV_(data); | |
9875 | this.drawGraph_(this.rawData_); | |
9876 | }; | |
9877 | ||
9878 | DateGraph.prototype.months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", | |
9879 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; | |
9880 | DateGraph.prototype.quarters = ["Jan", "Apr", "Jul", "Oct"]; | |
9881 | ||
9882 | /** | |
9883 | * Add ticks on the x-axis representing years, months, quarters, weeks, or days | |
9884 | * @private | |
9885 | */ | |
9886 | DateGraph.prototype.addXTicks_ = function() { | |
9887 | // Determine the correct ticks scale on the x-axis: quarterly, monthly, ... | |
9888 | var startDate, endDate; | |
9889 | if (this.dateWindow_) { | |
9890 | startDate = this.dateWindow_[0]; | |
9891 | endDate = this.dateWindow_[1]; | |
9892 | } else { | |
9893 | startDate = this.rawData_[0][0]; | |
9894 | endDate = this.rawData_[this.rawData_.length - 1][0]; | |
9895 | } | |
9896 | ||
9897 | var xTicks = this.xTicker_(startDate, endDate); | |
9898 | this.layout_.updateOptions({xTicks: xTicks}); | |
9899 | } | |
9900 | ||
9901 | /** | |
9902 | * Add ticks to the x-axis based on a date range. | |
9903 | * @param {Number} startDate Start of the date window (millis since epoch) | |
9904 | * @param {Number} endDate End of the date window (millis since epoch) | |
9905 | * @return {Array.<Object>} Array of {label, value} tuples. | |
9906 | * @public | |
9907 | */ | |
9908 | DateGraph.prototype.dateTicker = function(startDate, endDate) { | |
9909 | var ONE_DAY = 24*60*60*1000; | |
9910 | startDate = startDate / ONE_DAY; | |
9911 | endDate = endDate / ONE_DAY; | |
9912 | var dateSpan = endDate - startDate; | |
9913 | ||
9914 | var scale = []; | |
9915 | var isMonthly = false; | |
9916 | var yearMod = 1; | |
9917 | if (dateSpan > 30 * 366) { // decadal | |
9918 | isMonthly = true; | |
9919 | scale = ["Jan"]; | |
9920 | yearMod = 10; | |
9921 | } else if (dateSpan > 4*366) { // annual | |
9922 | scale = ["Jan"]; | |
9923 | isMonthly = true; | |
9924 | } else if (dateSpan > 366) { // quarterly | |
9925 | scale = this.quarters; | |
9926 | isMonthly = true; | |
9927 | } else if (dateSpan > 40) { // monthly | |
9928 | scale = this.months; | |
9929 | isMonthly = true; | |
9930 | } else if (dateSpan > 10) { // weekly | |
9931 | for (var week = startDate - 14; week < endDate + 14; week += 7) { | |
9932 | scale.push(week * ONE_DAY); | |
9933 | } | |
9934 | } else { // daily | |
9935 | for (var day = startDate - 14; day < endDate + 14; day += 1) { | |
9936 | scale.push(day * ONE_DAY); | |
9937 | } | |
9938 | } | |
9939 | ||
9940 | var xTicks = []; | |
9941 | ||
9942 | if (isMonthly) { | |
9943 | var startYear = 1900 + (new Date(startDate* ONE_DAY)).getYear(); | |
9944 | var endYear = 1900 + (new Date(endDate * ONE_DAY)).getYear(); | |
9945 | for (var i = startYear; i <= endYear; i++) { | |
9946 | if (i % yearMod != 0) continue; | |
9947 | for (var j = 0; j < scale.length; j++ ) { | |
9948 | var date = Date.parse(scale[j] + " 1, " + i); | |
9949 | xTicks.push( {label: scale[j] + "'" + ("" + i).substr(2,2), v: date } ); | |
9950 | } | |
9951 | } | |
9952 | } else { | |
9953 | for (var i = 0; i < scale.length; i++) { | |
9954 | var date = new Date(scale[i]); | |
9955 | var year = date.getFullYear().toString(); | |
9956 | var label = this.months[date.getMonth()] + date.getDate(); | |
9957 | label += "'" + year.substr(year.length - 2, 2); | |
9958 | xTicks.push( {label: label, v: date} ); | |
9959 | } | |
9960 | } | |
9961 | return xTicks; | |
9962 | }; | |
9963 | ||
9964 | /** | |
9965 | * Add ticks when the x axis has numbers on it (instead of dates) | |
9966 | * @param {Number} startDate Start of the date window (millis since epoch) | |
9967 | * @param {Number} endDate End of the date window (millis since epoch) | |
9968 | * @return {Array.<Object>} Array of {label, value} tuples. | |
9969 | * @public | |
9970 | */ | |
9971 | DateGraph.prototype.numericTicks = function(minV, maxV) { | |
9972 | var scale; | |
9973 | if (maxV <= 0.0) { | |
9974 | scale = 1.0; | |
9975 | } else { | |
9976 | scale = Math.pow( 10, Math.floor(Math.log(maxV)/Math.log(10.0)) ); | |
9977 | } | |
9978 | ||
9979 | // Add a smallish number of ticks at human-friendly points | |
9980 | var nTicks = (maxV - minV) / scale; | |
9981 | while (2 * nTicks < 20) { | |
9982 | nTicks *= 2; | |
9983 | } | |
9984 | if ((maxV - minV) / nTicks < this.minTickSize_) { | |
9985 | nTicks = this.round_((maxV - minV) / this.minTickSize_, 1); | |
9986 | } | |
9987 | ||
9988 | // Construct labels for the ticks | |
9989 | var ticks = []; | |
9990 | for (var i = 0; i <= nTicks; i++) { | |
9991 | var tickV = minV + i * (maxV - minV) / nTicks; | |
9992 | var label = this.round_(tickV, 2); | |
9993 | if (this.labelsKMB_) { | |
9994 | var k = 1000; | |
9995 | if (tickV >= k*k*k) { | |
9996 | label = this.round_(tickV/(k*k*k), 1) + "B"; | |
9997 | } else if (tickV >= k*k) { | |
9998 | label = this.round_(tickV/(k*k), 1) + "M"; | |
9999 | } else if (tickV >= k) { | |
10000 | label = this.round_(tickV/k, 1) + "K"; | |
10001 | } | |
10002 | } | |
10003 | ticks.push( {label: label, v: tickV} ); | |
10004 | } | |
10005 | return ticks; | |
10006 | }; | |
10007 | ||
10008 | /** | |
10009 | * Adds appropriate ticks on the y-axis | |
10010 | * @param {Number} minY The minimum Y value in the data set | |
10011 | * @param {Number} maxY The maximum Y value in the data set | |
10012 | * @private | |
10013 | */ | |
10014 | DateGraph.prototype.addYTicks_ = function(minY, maxY) { | |
10015 | // Set the number of ticks so that the labels are human-friendly. | |
10016 | var ticks = this.numericTicks(minY, maxY); | |
10017 | this.layout_.updateOptions( { yAxis: [minY, maxY], | |
10018 | yTicks: ticks } ); | |
10019 | }; | |
10020 | ||
10021 | /** | |
10022 | * Update the graph with new data. Data is in the format | |
10023 | * [ [date1, val1, val2, ...], [date2, val1, val2, ...] if errorBars=false | |
10024 | * or, if errorBars=true, | |
10025 | * [ [date1, [val1,stddev1], [val2,stddev2], ...], [date2, ...], ...] | |
10026 | * @param {Array.<Object>} data The data (see above) | |
10027 | * @private | |
10028 | */ | |
10029 | DateGraph.prototype.drawGraph_ = function(data) { | |
10030 | var maxY = null; | |
10031 | this.layout_.removeAllDatasets(); | |
10032 | // Loop over all fields in the dataset | |
10033 | for (var i = 1; i < data[0].length; i++) { | |
10034 | var series = []; | |
10035 | for (var j = 0; j < data.length; j++) { | |
10036 | var date = data[j][0]; | |
10037 | series[j] = [date, data[j][i]]; | |
10038 | } | |
10039 | series = this.rollingAverage(series, this.rollPeriod_); | |
10040 | ||
10041 | // Prune down to the desired range, if necessary (for zooming) | |
10042 | var bars = this.errorBars_ || this.customBars_; | |
10043 | if (this.dateWindow_) { | |
10044 | var low = this.dateWindow_[0]; | |
10045 | var high= this.dateWindow_[1]; | |
10046 | var pruned = []; | |
10047 | for (var k = 0; k < series.length; k++) { | |
10048 | if (series[k][0] >= low && series[k][0] <= high) { | |
10049 | pruned.push(series[k]); | |
10050 | var y = bars ? series[k][1][0] : series[k][1]; | |
10051 | if (maxY == null || y > maxY) maxY = y; | |
10052 | } | |
10053 | } | |
10054 | series = pruned; | |
10055 | } else { | |
10056 | for (var j = 0; j < series.length; j++) { | |
10057 | var y = bars ? series[j][1][0] : series[j][1]; | |
10058 | if (maxY == null || y > maxY) { | |
10059 | maxY = bars ? y + series[j][1][1] : y; | |
10060 | } | |
10061 | } | |
10062 | } | |
10063 | ||
10064 | if (bars) { | |
10065 | var vals = []; | |
10066 | for (var j=0; j<series.length; j++) | |
10067 | vals[j] = [series[j][0], | |
10068 | series[j][1][0], series[j][1][1], series[j][1][2]]; | |
10069 | this.layout_.addDataset(this.labels_[i - 1], vals); | |
10070 | } else { | |
10071 | this.layout_.addDataset(this.labels_[i - 1], series); | |
10072 | } | |
10073 | } | |
10074 | ||
10075 | // Use some heuristics to come up with a good maxY value, unless it's been | |
10076 | // set explicitly by the user. | |
10077 | if (this.valueRange_ != null) { | |
10078 | this.addYTicks_(this.valueRange_[0], this.valueRange_[1]); | |
10079 | } else { | |
10080 | // Add some padding and round up to an integer to be human-friendly. | |
10081 | maxY *= 1.1; | |
10082 | if (maxY <= 0.0) maxY = 1.0; | |
10083 | else { | |
10084 | var scale = Math.pow(10, Math.floor(Math.log(maxY) / Math.log(10.0))); | |
10085 | maxY = scale * Math.ceil(maxY / scale); | |
10086 | } | |
10087 | this.addYTicks_(0, maxY); | |
10088 | } | |
10089 | ||
10090 | this.addXTicks_(); | |
10091 | ||
10092 | // Tell PlotKit to use this new data and render itself | |
10093 | this.layout_.evaluateWithError(); | |
10094 | this.plotter_.clear(); | |
10095 | this.plotter_.render(); | |
10096 | this.canvas_.getContext('2d').clearRect(0, 0, | |
10097 | this.canvas_.width, this.canvas_.height); | |
10098 | }; | |
10099 | ||
10100 | /** | |
10101 | * Calculates the rolling average of a data set. | |
10102 | * If originalData is [label, val], rolls the average of those. | |
10103 | * If originalData is [label, [, it's interpreted as [value, stddev] | |
10104 | * and the roll is returned in the same form, with appropriately reduced | |
10105 | * stddev for each value. | |
10106 | * Note that this is where fractional input (i.e. '5/10') is converted into | |
10107 | * decimal values. | |
10108 | * @param {Array} originalData The data in the appropriate format (see above) | |
10109 | * @param {Number} rollPeriod The number of days over which to average the data | |
10110 | */ | |
10111 | DateGraph.prototype.rollingAverage = function(originalData, rollPeriod) { | |
10112 | if (originalData.length < 2) | |
10113 | return originalData; | |
10114 | var rollPeriod = Math.min(rollPeriod, originalData.length - 1); | |
10115 | var rollingData = []; | |
10116 | var sigma = this.sigma_; | |
10117 | ||
10118 | if (this.fractions_) { | |
10119 | var num = 0; | |
10120 | var den = 0; // numerator/denominator | |
10121 | var mult = 100.0; | |
10122 | for (var i = 0; i < originalData.length; i++) { | |
10123 | num += originalData[i][1][0]; | |
10124 | den += originalData[i][1][1]; | |
10125 | if (i - rollPeriod >= 0) { | |
10126 | num -= originalData[i - rollPeriod][1][0]; | |
10127 | den -= originalData[i - rollPeriod][1][1]; | |
10128 | } | |
10129 | ||
10130 | var date = originalData[i][0]; | |
10131 | var value = den ? num / den : 0.0; | |
10132 | if (this.errorBars_) { | |
10133 | if (this.wilsonInterval_) { | |
10134 | // For more details on this confidence interval, see: | |
10135 | // http://en.wikipedia.org/wiki/Binomial_confidence_interval | |
10136 | if (den) { | |
10137 | var p = value < 0 ? 0 : value, n = den; | |
10138 | var pm = sigma * Math.sqrt(p*(1-p)/n + sigma*sigma/(4*n*n)); | |
10139 | var denom = 1 + sigma * sigma / den; | |
10140 | var low = (p + sigma * sigma / (2 * den) - pm) / denom; | |
10141 | var high = (p + sigma * sigma / (2 * den) + pm) / denom; | |
10142 | rollingData[i] = [date, | |
10143 | [p * mult, (p - low) * mult, (high - p) * mult]]; | |
10144 | } else { | |
10145 | rollingData[i] = [date, [0, 0, 0]]; | |
10146 | } | |
10147 | } else { | |
10148 | var stddev = den ? sigma * Math.sqrt(value * (1 - value) / den) : 1.0; | |
10149 | rollingData[i] = [date, [mult * value, mult * stddev, mult * stddev]]; | |
10150 | } | |
10151 | } else { | |
10152 | rollingData[i] = [date, mult * value]; | |
10153 | } | |
10154 | } | |
10155 | } else if (this.customBars_) { | |
10156 | // just ignore the rolling for now. | |
10157 | // TODO(danvk): do something reasonable. | |
10158 | for (var i = 0; i < originalData.length; i++) { | |
10159 | var data = originalData[i][1]; | |
10160 | var y = data[1]; | |
10161 | rollingData[i] = [originalData[i][0], [y, y - data[0], data[2] - y]]; | |
10162 | } | |
10163 | } else { | |
10164 | // Calculate the rolling average for the first rollPeriod - 1 points where | |
10165 | // there is not enough data to roll over the full number of days | |
10166 | var num_init_points = Math.min(rollPeriod - 1, originalData.length - 2); | |
10167 | if (!this.errorBars_){ | |
10168 | for (var i = 0; i < num_init_points; i++) { | |
10169 | var sum = 0; | |
10170 | for (var j = 0; j < i + 1; j++) | |
10171 | sum += originalData[j][1]; | |
10172 | rollingData[i] = [originalData[i][0], sum / (i + 1)]; | |
10173 | } | |
10174 | // Calculate the rolling average for the remaining points | |
10175 | for (var i = Math.min(rollPeriod - 1, originalData.length - 2); | |
10176 | i < originalData.length; | |
10177 | i++) { | |
10178 | var sum = 0; | |
10179 | for (var j = i - rollPeriod + 1; j < i + 1; j++) | |
10180 | sum += originalData[j][1]; | |
10181 | rollingData[i] = [originalData[i][0], sum / rollPeriod]; | |
10182 | } | |
10183 | } else { | |
10184 | for (var i = 0; i < num_init_points; i++) { | |
10185 | var sum = 0; | |
10186 | var variance = 0; | |
10187 | for (var j = 0; j < i + 1; j++) { | |
10188 | sum += originalData[j][1][0]; | |
10189 | variance += Math.pow(originalData[j][1][1], 2); | |
10190 | } | |
10191 | var stddev = Math.sqrt(variance)/(i+1); | |
10192 | rollingData[i] = [originalData[i][0], | |
10193 | [sum/(i+1), sigma * stddev, sigma * stddev]]; | |
10194 | } | |
10195 | // Calculate the rolling average for the remaining points | |
10196 | for (var i = Math.min(rollPeriod - 1, originalData.length - 2); | |
10197 | i < originalData.length; | |
10198 | i++) { | |
10199 | var sum = 0; | |
10200 | var variance = 0; | |
10201 | for (var j = i - rollPeriod + 1; j < i + 1; j++) { | |
10202 | sum += originalData[j][1][0]; | |
10203 | variance += Math.pow(originalData[j][1][1], 2); | |
10204 | } | |
10205 | var stddev = Math.sqrt(variance) / rollPeriod; | |
10206 | rollingData[i] = [originalData[i][0], | |
10207 | [sum / rollPeriod, sigma * stddev, sigma * stddev]]; | |
10208 | } | |
10209 | } | |
10210 | } | |
10211 | ||
10212 | return rollingData; | |
10213 | }; | |
10214 | ||
10215 | /** | |
10216 | * Parses a date, returning the number of milliseconds since epoch. This can be | |
10217 | * passed in as an xValueParser in the DateGraph constructor. | |
10218 | * @param {String} A date in YYYYMMDD format. | |
10219 | * @return {Number} Milliseconds since epoch. | |
10220 | * @public | |
10221 | */ | |
10222 | DateGraph.prototype.dateParser = function(dateStr) { | |
10223 | var dateStrSlashed; | |
10224 | if (dateStr.search("-") != -1) { | |
10225 | dateStrSlashed = dateStr.replace("-", "/", "g"); | |
10226 | } else if (dateStr.search("/") != -1) { | |
10227 | return Date.parse(dateStr); | |
10228 | } else { | |
10229 | dateStrSlashed = dateStr.substr(0,4) + "/" + dateStr.substr(4,2) | |
10230 | + "/" + dateStr.substr(6,2); | |
10231 | } | |
10232 | return Date.parse(dateStrSlashed); | |
10233 | }; | |
10234 | ||
10235 | /** | |
10236 | * Parses a string in a special csv format. We expect a csv file where each | |
10237 | * line is a date point, and the first field in each line is the date string. | |
10238 | * We also expect that all remaining fields represent series. | |
10239 | * if this.errorBars_ is set, then interpret the fields as: | |
10240 | * date, series1, stddev1, series2, stddev2, ... | |
10241 | * @param {Array.<Object>} data See above. | |
10242 | * @private | |
10243 | */ | |
10244 | DateGraph.prototype.parseCSV_ = function(data) { | |
10245 | var ret = []; | |
10246 | var lines = data.split("\n"); | |
10247 | var start = this.labelsFromCSV_ ? 1 : 0; | |
10248 | if (this.labelsFromCSV_) { | |
10249 | var labels = lines[0].split(","); | |
10250 | labels.shift(); // a "date" parameter is assumed. | |
10251 | this.labels_ = labels; | |
10252 | // regenerate automatic colors. | |
10253 | this.setColors_(this.attrs_); | |
10254 | this.renderOptions_.colorScheme = this.colors_; | |
10255 | MochiKit.Base.update(this.plotter_.options, this.renderOptions_); | |
10256 | MochiKit.Base.update(this.layoutOptions_, this.attrs_); | |
10257 | } | |
10258 | ||
10259 | for (var i = start; i < lines.length; i++) { | |
10260 | var line = lines[i]; | |
10261 | if (line.length == 0) continue; // skip blank lines | |
10262 | var inFields = line.split(','); | |
10263 | if (inFields.length < 2) | |
10264 | continue; | |
10265 | ||
10266 | var fields = []; | |
10267 | fields[0] = this.xValueParser_(inFields[0]); | |
10268 | ||
10269 | // If fractions are expected, parse the numbers as "A/B" | |
10270 | if (this.fractions_) { | |
10271 | for (var j = 1; j < inFields.length; j++) { | |
10272 | // TODO(danvk): figure out an appropriate way to flag parse errors. | |
10273 | var vals = inFields[j].split("/"); | |
10274 | fields[j] = [parseFloat(vals[0]), parseFloat(vals[1])]; | |
10275 | } | |
10276 | } else if (this.errorBars_) { | |
10277 | // If there are error bars, values are (value, stddev) pairs | |
10278 | for (var j = 1; j < inFields.length; j += 2) | |
10279 | fields[(j + 1) / 2] = [parseFloat(inFields[j]), | |
10280 | parseFloat(inFields[j + 1])]; | |
10281 | } else if (this.customBars_) { | |
10282 | // Bars are a low;center;high tuple | |
10283 | for (var j = 1; j < inFields.length; j++) { | |
10284 | var vals = inFields[j].split(";"); | |
10285 | fields[j] = [ parseFloat(vals[0]), | |
10286 | parseFloat(vals[1]), | |
10287 | parseFloat(vals[2]) ]; | |
10288 | } | |
10289 | } else { | |
10290 | // Values are just numbers | |
10291 | for (var j = 1; j < inFields.length; j++) | |
10292 | fields[j] = parseFloat(inFields[j]); | |
10293 | } | |
10294 | ret.push(fields); | |
10295 | } | |
10296 | return ret; | |
10297 | }; | |
10298 | ||
10299 | /** | |
10300 | * Get the CSV data. If it's in a function, call that function. If it's in a | |
10301 | * file, do an XMLHttpRequest to get it. | |
10302 | * @private | |
10303 | */ | |
10304 | DateGraph.prototype.start_ = function() { | |
10305 | if (typeof this.file_ == 'function') { | |
10306 | // Stubbed out to allow this to run off a filesystem | |
10307 | this.loadedEvent_(this.file_()); | |
10308 | } else { | |
10309 | var req = new XMLHttpRequest(); | |
10310 | var caller = this; | |
10311 | req.onreadystatechange = function () { | |
10312 | if (req.readyState == 4) { | |
10313 | if (req.status == 200) { | |
10314 | caller.loadedEvent_(req.responseText); | |
10315 | } | |
10316 | } | |
10317 | }; | |
10318 | ||
10319 | req.open("GET", this.file_, true); | |
10320 | req.send(null); | |
10321 | } | |
10322 | }; | |
10323 | ||
10324 | /** | |
10325 | * Changes various properties of the graph. These can include: | |
10326 | * <ul> | |
10327 | * <li>file: changes the source data for the graph</li> | |
10328 | * <li>errorBars: changes whether the data contains stddev</li> | |
10329 | * </ul> | |
10330 | * @param {Object} attrs The new properties and values | |
10331 | */ | |
10332 | DateGraph.prototype.updateOptions = function(attrs) { | |
10333 | if (attrs.errorBars) { | |
10334 | this.errorBars_ = attrs.errorBars; | |
10335 | } | |
10336 | if (attrs.customBars) { | |
10337 | this.customBars_ = attrs.customBars; | |
10338 | } | |
10339 | if (attrs.strokeWidth) { | |
10340 | this.strokeWidth_ = attrs.strokeWidth; | |
10341 | } | |
10342 | if (attrs.rollPeriod) { | |
10343 | this.rollPeriod_ = attrs.rollPeriod; | |
10344 | } | |
10345 | if (attrs.dateWindow) { | |
10346 | this.dateWindow_ = attrs.dateWindow; | |
10347 | } | |
10348 | if (attrs.valueRange) { | |
10349 | this.valueRange_ = attrs.valueRange; | |
10350 | } | |
10351 | if (attrs.minTickSize) { | |
10352 | this.minTickSize_ = attrs.minTickSize; | |
10353 | } | |
10354 | if (typeof(attrs.labels) != 'undefined') { | |
10355 | this.labels_ = attrs.labels; | |
10356 | this.labelsFromCSV_ = (attrs.labels == null); | |
10357 | } | |
10358 | this.layout_.updateOptions({ 'errorBars': this.errorBars_ }); | |
10359 | if (attrs['file'] && attrs['file'] != this.file_) { | |
10360 | this.file_ = attrs['file']; | |
10361 | this.start_(); | |
10362 | } else { | |
10363 | this.drawGraph_(this.rawData_); | |
10364 | } | |
10365 | }; | |
10366 | ||
10367 | /** | |
10368 | * Adjusts the number of days in the rolling average. Updates the graph to | |
10369 | * reflect the new averaging period. | |
10370 | * @param {Number} length Number of days over which to average the data. | |
10371 | */ | |
10372 | DateGraph.prototype.adjustRoll = function(length) { | |
10373 | this.rollPeriod_ = length; | |
10374 | this.drawGraph_(this.rawData_); | |
10375 | }; |