alloy-js-test-san 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/README.rdoc +83 -0
  2. data/Rakefile +27 -0
  3. data/VERSION.yml +4 -0
  4. data/bin/jstest +10 -0
  5. data/lib/js_test_san/runner.rb +70 -0
  6. data/lib/js_test_san/test.rb +17 -0
  7. data/lib/js_test_san/test_case.rb +103 -0
  8. data/lib/js_test_san.rb +2 -0
  9. data/test/fixtures/a_unit_test.html +27 -0
  10. data/test/fixtures/a_unit_test.js +22 -0
  11. data/test/regression/prototype/unit/ajax_test.html +29 -0
  12. data/test/regression/prototype/unit/array_test.html +28 -0
  13. data/test/regression/prototype/unit/assets/prototype.js +4900 -0
  14. data/test/regression/prototype/unit/assets/unittest.css +50 -0
  15. data/test/regression/prototype/unit/assets/unittest.js +615 -0
  16. data/test/regression/prototype/unit/assets/unittest_transport.js +1 -0
  17. data/test/regression/prototype/unit/base_test.html +27 -0
  18. data/test/regression/prototype/unit/class_test.html +27 -0
  19. data/test/regression/prototype/unit/date_test.html +27 -0
  20. data/test/regression/prototype/unit/dom_test.html +304 -0
  21. data/test/regression/prototype/unit/element_mixins_test.html +30 -0
  22. data/test/regression/prototype/unit/enumerable_test.html +35 -0
  23. data/test/regression/prototype/unit/event_test.html +31 -0
  24. data/test/regression/prototype/unit/fixtures/ajax.html +2 -0
  25. data/test/regression/prototype/unit/fixtures/ajax.js +42 -0
  26. data/test/regression/prototype/unit/fixtures/array.html +1 -0
  27. data/test/regression/prototype/unit/fixtures/class.js +83 -0
  28. data/test/regression/prototype/unit/fixtures/content.html +1 -0
  29. data/test/regression/prototype/unit/fixtures/data.json +1 -0
  30. data/test/regression/prototype/unit/fixtures/dom.css +84 -0
  31. data/test/regression/prototype/unit/fixtures/dom.html +278 -0
  32. data/test/regression/prototype/unit/fixtures/dom.js +17 -0
  33. data/test/regression/prototype/unit/fixtures/element_mixins.html +4 -0
  34. data/test/regression/prototype/unit/fixtures/element_mixins.js +2 -0
  35. data/test/regression/prototype/unit/fixtures/empty.html +0 -0
  36. data/test/regression/prototype/unit/fixtures/empty.js +1 -0
  37. data/test/regression/prototype/unit/fixtures/enumerable.html +8 -0
  38. data/test/regression/prototype/unit/fixtures/enumerable.js +23 -0
  39. data/test/regression/prototype/unit/fixtures/event.html +4 -0
  40. data/test/regression/prototype/unit/fixtures/form.html +108 -0
  41. data/test/regression/prototype/unit/fixtures/function.js +13 -0
  42. data/test/regression/prototype/unit/fixtures/hash.js +25 -0
  43. data/test/regression/prototype/unit/fixtures/hello.js +1 -0
  44. data/test/regression/prototype/unit/fixtures/logo.gif +0 -0
  45. data/test/regression/prototype/unit/fixtures/object.html +6 -0
  46. data/test/regression/prototype/unit/fixtures/object.js +7 -0
  47. data/test/regression/prototype/unit/fixtures/position.html +9 -0
  48. data/test/regression/prototype/unit/fixtures/selector.html +71 -0
  49. data/test/regression/prototype/unit/fixtures/string.js +8 -0
  50. data/test/regression/prototype/unit/fixtures/unittest.html +18 -0
  51. data/test/regression/prototype/unit/form_test.html +135 -0
  52. data/test/regression/prototype/unit/function_test.html +27 -0
  53. data/test/regression/prototype/unit/hash_test.html +27 -0
  54. data/test/regression/prototype/unit/number_test.html +27 -0
  55. data/test/regression/prototype/unit/object_test.html +32 -0
  56. data/test/regression/prototype/unit/periodical_executer_test.html +27 -0
  57. data/test/regression/prototype/unit/position_test.html +36 -0
  58. data/test/regression/prototype/unit/prototype_test.html +27 -0
  59. data/test/regression/prototype/unit/range_test.html +27 -0
  60. data/test/regression/prototype/unit/regexp_test.html +27 -0
  61. data/test/regression/prototype/unit/selector_test.html +98 -0
  62. data/test/regression/prototype/unit/string_test.html +27 -0
  63. data/test/regression/prototype/unit/tests/ajax_test.js +379 -0
  64. data/test/regression/prototype/unit/tests/array_test.js +186 -0
  65. data/test/regression/prototype/unit/tests/base_test.js +43 -0
  66. data/test/regression/prototype/unit/tests/class_test.js +136 -0
  67. data/test/regression/prototype/unit/tests/date_test.js +5 -0
  68. data/test/regression/prototype/unit/tests/dom_test.js +1493 -0
  69. data/test/regression/prototype/unit/tests/element_mixins_test.js +32 -0
  70. data/test/regression/prototype/unit/tests/enumerable_test.js +271 -0
  71. data/test/regression/prototype/unit/tests/event_test.js +235 -0
  72. data/test/regression/prototype/unit/tests/form_test.js +382 -0
  73. data/test/regression/prototype/unit/tests/function_test.js +133 -0
  74. data/test/regression/prototype/unit/tests/hash_test.js +178 -0
  75. data/test/regression/prototype/unit/tests/number_test.js +44 -0
  76. data/test/regression/prototype/unit/tests/object_test.js +180 -0
  77. data/test/regression/prototype/unit/tests/periodical_executer_test.js +15 -0
  78. data/test/regression/prototype/unit/tests/position_test.js +44 -0
  79. data/test/regression/prototype/unit/tests/prototype_test.js +43 -0
  80. data/test/regression/prototype/unit/tests/range_test.js +58 -0
  81. data/test/regression/prototype/unit/tests/regexp_test.js +42 -0
  82. data/test/regression/prototype/unit/tests/selector_test.js +408 -0
  83. data/test/regression/prototype/unit/tests/string_test.js +548 -0
  84. data/test/regression/prototype/unit/tests/unittest_test.js +148 -0
  85. data/test/regression/prototype/unit/unittest_test.html +45 -0
  86. data/test/regression/prototype/upstream +1 -0
  87. data/test/test_helper.rb +20 -0
  88. data/test/unit/runner_test.rb +165 -0
  89. data/test/unit/test_case_test.rb +167 -0
  90. data/test/unit/test_test.rb +24 -0
  91. metadata +145 -0
@@ -0,0 +1,4900 @@
1
+ /* Prototype JavaScript framework, version 1.6.1_rc2
2
+ * (c) 2005-2009 Sam Stephenson
3
+ *
4
+ * Prototype is freely distributable under the terms of an MIT-style license.
5
+ * For details, see the Prototype web site: http://www.prototypejs.org/
6
+ *
7
+ *--------------------------------------------------------------------------*/
8
+
9
+ var Prototype = {
10
+ Version: '1.6.1_rc2',
11
+
12
+ Browser: {
13
+ IE: !!(window.attachEvent &&
14
+ navigator.userAgent.indexOf('Opera') === -1),
15
+ Opera: navigator.userAgent.indexOf('Opera') > -1,
16
+ WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
17
+ Gecko: navigator.userAgent.indexOf('Gecko') > -1 &&
18
+ navigator.userAgent.indexOf('KHTML') === -1,
19
+ MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
20
+ },
21
+
22
+ BrowserFeatures: {
23
+ XPath: !!document.evaluate,
24
+ SelectorsAPI: !!document.querySelector,
25
+ ElementExtensions: (function() {
26
+ if (window.HTMLElement && window.HTMLElement.prototype)
27
+ return true;
28
+ if (window.Element && window.Element.prototype)
29
+ return true;
30
+ })(),
31
+ SpecificElementExtensions: (function() {
32
+ if (typeof window.HTMLDivElement !== 'undefined')
33
+ return true;
34
+
35
+ var div = document.createElement('div');
36
+ if (div['__proto__'] && div['__proto__'] !==
37
+ document.createElement('form')['__proto__']) {
38
+ return true;
39
+ }
40
+
41
+ return false;
42
+ })()
43
+ },
44
+
45
+ ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
46
+ JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
47
+
48
+ emptyFunction: function() { },
49
+ K: function(x) { return x }
50
+ };
51
+
52
+ if (Prototype.Browser.MobileSafari)
53
+ Prototype.BrowserFeatures.SpecificElementExtensions = false;
54
+
55
+
56
+ var Abstract = { };
57
+
58
+
59
+ var Try = {
60
+ these: function() {
61
+ var returnValue;
62
+
63
+ for (var i = 0, length = arguments.length; i < length; i++) {
64
+ var lambda = arguments[i];
65
+ try {
66
+ returnValue = lambda();
67
+ break;
68
+ } catch (e) { }
69
+ }
70
+
71
+ return returnValue;
72
+ }
73
+ };
74
+
75
+ /* Based on Alex Arnell's inheritance implementation. */
76
+
77
+ var Class = (function() {
78
+ function create() {
79
+ var parent = null, properties = $A(arguments);
80
+ if (Object.isFunction(properties[0]))
81
+ parent = properties.shift();
82
+
83
+ function klass() {
84
+ this.initialize.apply(this, arguments);
85
+ }
86
+
87
+ Object.extend(klass, Class.Methods);
88
+ klass.superclass = parent;
89
+ klass.subclasses = [];
90
+
91
+ if (parent) {
92
+ var subclass = function() {};
93
+ subclass.prototype = parent.prototype;
94
+ klass.prototype = new subclass;
95
+ parent.subclasses.push(klass);
96
+ }
97
+
98
+ for (var i = 0; i < properties.length; i++)
99
+ klass.addMethods(properties[i]);
100
+
101
+ if (!klass.prototype.initialize)
102
+ klass.prototype.initialize = Prototype.emptyFunction;
103
+
104
+ klass.prototype.constructor = klass;
105
+ return klass;
106
+ }
107
+
108
+ function addMethods(source) {
109
+ var ancestor = this.superclass && this.superclass.prototype;
110
+ var properties = Object.keys(source);
111
+
112
+ if (!Object.keys({ toString: true }).length) {
113
+ if (source.toString != Object.prototype.toString)
114
+ properties.push("toString");
115
+ if (source.valueOf != Object.prototype.valueOf)
116
+ properties.push("valueOf");
117
+ }
118
+
119
+ for (var i = 0, length = properties.length; i < length; i++) {
120
+ var property = properties[i], value = source[property];
121
+ if (ancestor && Object.isFunction(value) &&
122
+ value.argumentNames().first() == "$super") {
123
+ var method = value;
124
+ value = (function(m) {
125
+ return function() { return ancestor[m].apply(this, arguments); };
126
+ })(property).wrap(method);
127
+
128
+ value.valueOf = method.valueOf.bind(method);
129
+ value.toString = method.toString.bind(method);
130
+ }
131
+ this.prototype[property] = value;
132
+ }
133
+
134
+ return this;
135
+ }
136
+
137
+ return {
138
+ create: create,
139
+ Methods: {
140
+ addMethods: addMethods
141
+ }
142
+ };
143
+ })();
144
+ (function() {
145
+
146
+ function getClass(object) {
147
+ return Object.prototype.toString.call(object)
148
+ .match(/^\[object\s(.*)\]$/)[1];
149
+ }
150
+
151
+ function extend(destination, source) {
152
+ for (var property in source)
153
+ destination[property] = source[property];
154
+ return destination;
155
+ }
156
+
157
+ function inspect(object) {
158
+ try {
159
+ if (isUndefined(object)) return 'undefined';
160
+ if (object === null) return 'null';
161
+ return object.inspect ? object.inspect() : String(object);
162
+ } catch (e) {
163
+ if (e instanceof RangeError) return '...';
164
+ throw e;
165
+ }
166
+ }
167
+
168
+ function toJSON(object) {
169
+ var type = typeof object;
170
+ switch (type) {
171
+ case 'undefined':
172
+ case 'function':
173
+ case 'unknown': return;
174
+ case 'boolean': return object.toString();
175
+ }
176
+
177
+ if (object === null) return 'null';
178
+ if (object.toJSON) return object.toJSON();
179
+ if (isElement(object)) return;
180
+
181
+ var results = [];
182
+ for (var property in object) {
183
+ var value = toJSON(object[property]);
184
+ if (!isUndefined(value))
185
+ results.push(property.toJSON() + ': ' + value);
186
+ }
187
+
188
+ return '{' + results.join(', ') + '}';
189
+ }
190
+
191
+ function toQueryString(object) {
192
+ return $H(object).toQueryString();
193
+ }
194
+
195
+ function toHTML(object) {
196
+ return object && object.toHTML ? object.toHTML() : String.interpret(object);
197
+ }
198
+
199
+ function keys(object) {
200
+ var results = [];
201
+ for (var property in object)
202
+ results.push(property);
203
+ return results;
204
+ }
205
+
206
+ function values(object) {
207
+ var results = [];
208
+ for (var property in object)
209
+ results.push(object[property]);
210
+ return results;
211
+ }
212
+
213
+ function clone(object) {
214
+ return extend({ }, object);
215
+ }
216
+
217
+ function isElement(object) {
218
+ return !!(object && object.nodeType == 1);
219
+ }
220
+
221
+ function isArray(object) {
222
+ return getClass(object) === "Array";
223
+ }
224
+
225
+
226
+ function isHash(object) {
227
+ return object instanceof Hash;
228
+ }
229
+
230
+ function isFunction(object) {
231
+ return typeof object === "function";
232
+ }
233
+
234
+ function isString(object) {
235
+ return getClass(object) === "String";
236
+ }
237
+
238
+ function isNumber(object) {
239
+ return getClass(object) === "Number";
240
+ }
241
+
242
+ function isUndefined(object) {
243
+ return typeof object === "undefined";
244
+ }
245
+
246
+ extend(Object, {
247
+ extend: extend,
248
+ inspect: inspect,
249
+ toJSON: toJSON,
250
+ toQueryString: toQueryString,
251
+ toHTML: toHTML,
252
+ keys: keys,
253
+ values: values,
254
+ clone: clone,
255
+ isElement: isElement,
256
+ isArray: isArray,
257
+ isHash: isHash,
258
+ isFunction: isFunction,
259
+ isString: isString,
260
+ isNumber: isNumber,
261
+ isUndefined: isUndefined
262
+ });
263
+ })();
264
+ Object.extend(Function.prototype, (function() {
265
+ var slice = Array.prototype.slice;
266
+
267
+ function update(array, args) {
268
+ var arrayLength = array.length, length = args.length;
269
+ while (length--) array[arrayLength + length] = args[length];
270
+ return array;
271
+ }
272
+
273
+ function merge(array, args) {
274
+ array = slice.call(array, 0);
275
+ return update(array, args);
276
+ }
277
+
278
+ function argumentNames() {
279
+ var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
280
+ .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
281
+ .replace(/\s+/g, '').split(',');
282
+ return names.length == 1 && !names[0] ? [] : names;
283
+ }
284
+
285
+ function bind(context) {
286
+ if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
287
+ var __method = this, args = slice.call(arguments, 1);
288
+ return function() {
289
+ var a = merge(args, arguments);
290
+ return __method.apply(context, a);
291
+ }
292
+ }
293
+
294
+ function bindAsEventListener(context) {
295
+ var __method = this, args = slice.call(arguments, 1);
296
+ return function(event) {
297
+ var a = update([event || window.event], args);
298
+ return __method.apply(context, a);
299
+ }
300
+ }
301
+
302
+ function curry() {
303
+ if (!arguments.length) return this;
304
+ var __method = this, args = slice.call(arguments, 0);
305
+ return function() {
306
+ var a = merge(args, arguments);
307
+ return __method.apply(this, a);
308
+ }
309
+ }
310
+
311
+ function delay(timeout) {
312
+ var __method = this, args = slice.call(arguments, 1);
313
+ timeout = timeout * 1000
314
+ return window.setTimeout(function() {
315
+ return __method.apply(__method, args);
316
+ }, timeout);
317
+ }
318
+
319
+ function defer() {
320
+ var args = update([0.01], arguments);
321
+ return this.delay.apply(this, args);
322
+ }
323
+
324
+ function wrap(wrapper) {
325
+ var __method = this;
326
+ return function() {
327
+ var a = update([__method.bind(this)], arguments);
328
+ return wrapper.apply(this, a);
329
+ }
330
+ }
331
+
332
+ function methodize() {
333
+ if (this._methodized) return this._methodized;
334
+ var __method = this;
335
+ return this._methodized = function() {
336
+ var a = update([this], arguments);
337
+ return __method.apply(null, a);
338
+ };
339
+ }
340
+
341
+ return {
342
+ argumentNames: argumentNames,
343
+ bind: bind,
344
+ bindAsEventListener: bindAsEventListener,
345
+ curry: curry,
346
+ delay: delay,
347
+ defer: defer,
348
+ wrap: wrap,
349
+ methodize: methodize
350
+ }
351
+ })());
352
+
353
+
354
+ Date.prototype.toJSON = function() {
355
+ return '"' + this.getUTCFullYear() + '-' +
356
+ (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
357
+ this.getUTCDate().toPaddedString(2) + 'T' +
358
+ this.getUTCHours().toPaddedString(2) + ':' +
359
+ this.getUTCMinutes().toPaddedString(2) + ':' +
360
+ this.getUTCSeconds().toPaddedString(2) + 'Z"';
361
+ };
362
+
363
+
364
+ RegExp.prototype.match = RegExp.prototype.test;
365
+
366
+ RegExp.escape = function(str) {
367
+ return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
368
+ };
369
+ var PeriodicalExecuter = Class.create({
370
+ initialize: function(callback, frequency) {
371
+ this.callback = callback;
372
+ this.frequency = frequency;
373
+ this.currentlyExecuting = false;
374
+
375
+ this.registerCallback();
376
+ },
377
+
378
+ registerCallback: function() {
379
+ this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
380
+ },
381
+
382
+ execute: function() {
383
+ this.callback(this);
384
+ },
385
+
386
+ stop: function() {
387
+ if (!this.timer) return;
388
+ clearInterval(this.timer);
389
+ this.timer = null;
390
+ },
391
+
392
+ onTimerEvent: function() {
393
+ if (!this.currentlyExecuting) {
394
+ try {
395
+ this.currentlyExecuting = true;
396
+ this.execute();
397
+ } catch(e) {
398
+ /* empty catch for clients that don't support try/finally */
399
+ }
400
+ finally {
401
+ this.currentlyExecuting = false;
402
+ }
403
+ }
404
+ }
405
+ });
406
+ Object.extend(String, {
407
+ interpret: function(value) {
408
+ return value == null ? '' : String(value);
409
+ },
410
+ specialChar: {
411
+ '\b': '\\b',
412
+ '\t': '\\t',
413
+ '\n': '\\n',
414
+ '\f': '\\f',
415
+ '\r': '\\r',
416
+ '\\': '\\\\'
417
+ }
418
+ });
419
+
420
+ Object.extend(String.prototype, (function() {
421
+
422
+ function prepareReplacement(replacement) {
423
+ if (Object.isFunction(replacement)) return replacement;
424
+ var template = new Template(replacement);
425
+ return function(match) { return template.evaluate(match) };
426
+ }
427
+
428
+ function gsub(pattern, replacement) {
429
+ var result = '', source = this, match;
430
+ replacement = prepareReplacement(replacement);
431
+
432
+ if (Object.isString(pattern))
433
+ pattern = RegExp.escape(pattern);
434
+
435
+ if (!(pattern.length || pattern.source)) {
436
+ replacement = replacement('');
437
+ return replacement + source.split('').join(replacement) + replacement;
438
+ }
439
+
440
+ while (source.length > 0) {
441
+ if (match = source.match(pattern)) {
442
+ result += source.slice(0, match.index);
443
+ result += String.interpret(replacement(match));
444
+ source = source.slice(match.index + match[0].length);
445
+ } else {
446
+ result += source, source = '';
447
+ }
448
+ }
449
+ return result;
450
+ }
451
+
452
+ function sub(pattern, replacement, count) {
453
+ replacement = prepareReplacement(replacement);
454
+ count = Object.isUndefined(count) ? 1 : count;
455
+
456
+ return this.gsub(pattern, function(match) {
457
+ if (--count < 0) return match[0];
458
+ return replacement(match);
459
+ });
460
+ }
461
+
462
+ function scan(pattern, iterator) {
463
+ this.gsub(pattern, iterator);
464
+ return String(this);
465
+ }
466
+
467
+ function truncate(length, truncation) {
468
+ length = length || 30;
469
+ truncation = Object.isUndefined(truncation) ? '...' : truncation;
470
+ return this.length > length ?
471
+ this.slice(0, length - truncation.length) + truncation : String(this);
472
+ }
473
+
474
+ function strip() {
475
+ return this.replace(/^\s+/, '').replace(/\s+$/, '');
476
+ }
477
+
478
+ function stripTags() {
479
+ return this.replace(/<\/?[^>]+>/gi, '');
480
+ }
481
+
482
+ function stripScripts() {
483
+ return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
484
+ }
485
+
486
+ function extractScripts() {
487
+ var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
488
+ var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
489
+ return (this.match(matchAll) || []).map(function(scriptTag) {
490
+ return (scriptTag.match(matchOne) || ['', ''])[1];
491
+ });
492
+ }
493
+
494
+ function evalScripts() {
495
+ return this.extractScripts().map(function(script) { return eval(script) });
496
+ }
497
+
498
+ function escapeHTML() {
499
+ escapeHTML.text.data = this;
500
+ return escapeHTML.div.innerHTML;
501
+ }
502
+
503
+ function unescapeHTML() {
504
+ var div = document.createElement('div');
505
+ div.innerHTML = this.stripTags();
506
+ return div.childNodes[0] ? (div.childNodes.length > 1 ?
507
+ $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) :
508
+ div.childNodes[0].nodeValue) : '';
509
+ }
510
+
511
+ function toQueryParams(separator) {
512
+ var match = this.strip().match(/([^?#]*)(#.*)?$/);
513
+ if (!match) return { };
514
+
515
+ return match[1].split(separator || '&').inject({ }, function(hash, pair) {
516
+ if ((pair = pair.split('='))[0]) {
517
+ var key = decodeURIComponent(pair.shift());
518
+ var value = pair.length > 1 ? pair.join('=') : pair[0];
519
+ if (value != undefined) value = decodeURIComponent(value);
520
+
521
+ if (key in hash) {
522
+ if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
523
+ hash[key].push(value);
524
+ }
525
+ else hash[key] = value;
526
+ }
527
+ return hash;
528
+ });
529
+ }
530
+
531
+ function toArray() {
532
+ return this.split('');
533
+ }
534
+
535
+ function succ() {
536
+ return this.slice(0, this.length - 1) +
537
+ String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
538
+ }
539
+
540
+ function times(count) {
541
+ return count < 1 ? '' : new Array(count + 1).join(this);
542
+ }
543
+
544
+ function camelize() {
545
+ var parts = this.split('-'), len = parts.length;
546
+ if (len == 1) return parts[0];
547
+
548
+ var camelized = this.charAt(0) == '-'
549
+ ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
550
+ : parts[0];
551
+
552
+ for (var i = 1; i < len; i++)
553
+ camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
554
+
555
+ return camelized;
556
+ }
557
+
558
+ function capitalize() {
559
+ return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
560
+ }
561
+
562
+ function underscore() {
563
+ return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
564
+ }
565
+
566
+ function dasherize() {
567
+ return this.gsub(/_/,'-');
568
+ }
569
+
570
+ function inspect(useDoubleQuotes) {
571
+ var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) {
572
+ var character = String.specialChar[match[0]];
573
+ return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
574
+ });
575
+ if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
576
+ return "'" + escapedString.replace(/'/g, '\\\'') + "'";
577
+ }
578
+
579
+ function toJSON() {
580
+ return this.inspect(true);
581
+ }
582
+
583
+ function unfilterJSON(filter) {
584
+ return this.sub(filter || Prototype.JSONFilter, '#{1}');
585
+ }
586
+
587
+ function isJSON() {
588
+ var str = this;
589
+ if (str.blank()) return false;
590
+ str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
591
+ return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
592
+ }
593
+
594
+ function evalJSON(sanitize) {
595
+ var json = this.unfilterJSON();
596
+ try {
597
+ if (!sanitize || json.isJSON()) return eval('(' + json + ')');
598
+ } catch (e) { }
599
+ throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
600
+ }
601
+
602
+ function include(pattern) {
603
+ return this.indexOf(pattern) > -1;
604
+ }
605
+
606
+ function startsWith(pattern) {
607
+ return this.indexOf(pattern) === 0;
608
+ }
609
+
610
+ function endsWith(pattern) {
611
+ var d = this.length - pattern.length;
612
+ return d >= 0 && this.lastIndexOf(pattern) === d;
613
+ }
614
+
615
+ function empty() {
616
+ return this == '';
617
+ }
618
+
619
+ function blank() {
620
+ return /^\s*$/.test(this);
621
+ }
622
+
623
+ function interpolate(object, pattern) {
624
+ return new Template(this, pattern).evaluate(object);
625
+ }
626
+
627
+ return {
628
+ gsub: gsub,
629
+ sub: sub,
630
+ scan: scan,
631
+ truncate: truncate,
632
+ strip: strip,
633
+ stripTags: stripTags,
634
+ stripScripts: stripScripts,
635
+ extractScripts: extractScripts,
636
+ evalScripts: evalScripts,
637
+ escapeHTML: escapeHTML,
638
+ unescapeHTML: unescapeHTML,
639
+ toQueryParams: toQueryParams,
640
+ parseQuery: toQueryParams,
641
+ toArray: toArray,
642
+ succ: succ,
643
+ times: times,
644
+ camelize: camelize,
645
+ capitalize: capitalize,
646
+ underscore: underscore,
647
+ dasherize: dasherize,
648
+ inspect: inspect,
649
+ toJSON: toJSON,
650
+ unfilterJSON: unfilterJSON,
651
+ isJSON: isJSON,
652
+ evalJSON: evalJSON,
653
+ include: include,
654
+ startsWith: startsWith,
655
+ endsWith: endsWith,
656
+ empty: empty,
657
+ blank: blank,
658
+ interpolate: interpolate
659
+ };
660
+ })());
661
+
662
+ Object.extend(String.prototype.escapeHTML, {
663
+ div: document.createElement('div'),
664
+ text: document.createTextNode('')
665
+ });
666
+
667
+ String.prototype.escapeHTML.div.appendChild(String.prototype.escapeHTML.text);
668
+
669
+ if ('<\n>'.escapeHTML() !== '&lt;\n&gt;') {
670
+ String.prototype.escapeHTML = function() {
671
+ return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
672
+ }
673
+ }
674
+
675
+ if ('&lt;\n&gt;'.unescapeHTML() !== '<\n>') {
676
+ String.prototype.unescapeHTML = function() {
677
+ return this.stripTags().replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
678
+ }
679
+ }
680
+ var Template = Class.create({
681
+ initialize: function(template, pattern) {
682
+ this.template = template.toString();
683
+ this.pattern = pattern || Template.Pattern;
684
+ },
685
+
686
+ evaluate: function(object) {
687
+ if (Object.isFunction(object.toTemplateReplacements))
688
+ object = object.toTemplateReplacements();
689
+
690
+ return this.template.gsub(this.pattern, function(match) {
691
+ if (object == null) return '';
692
+
693
+ var before = match[1] || '';
694
+ if (before == '\\') return match[2];
695
+
696
+ var ctx = object, expr = match[3];
697
+ var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
698
+ match = pattern.exec(expr);
699
+ if (match == null) return before;
700
+
701
+ while (match != null) {
702
+ var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1];
703
+ ctx = ctx[comp];
704
+ if (null == ctx || '' == match[3]) break;
705
+ expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
706
+ match = pattern.exec(expr);
707
+ }
708
+
709
+ return before + String.interpret(ctx);
710
+ });
711
+ }
712
+ });
713
+ Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
714
+
715
+ var $break = { };
716
+
717
+ var Enumerable = (function() {
718
+ function each(iterator, context) {
719
+ var index = 0;
720
+ try {
721
+ this._each(function(value) {
722
+ iterator.call(context, value, index++);
723
+ });
724
+ } catch (e) {
725
+ if (e != $break) throw e;
726
+ }
727
+ return this;
728
+ }
729
+
730
+ function eachSlice(number, iterator, context) {
731
+ var index = -number, slices = [], array = this.toArray();
732
+ if (number < 1) return array;
733
+ while ((index += number) < array.length)
734
+ slices.push(array.slice(index, index+number));
735
+ return slices.collect(iterator, context);
736
+ }
737
+
738
+ function all(iterator, context) {
739
+ iterator = iterator || Prototype.K;
740
+ var result = true;
741
+ this.each(function(value, index) {
742
+ result = result && !!iterator.call(context, value, index);
743
+ if (!result) throw $break;
744
+ });
745
+ return result;
746
+ }
747
+
748
+ function any(iterator, context) {
749
+ iterator = iterator || Prototype.K;
750
+ var result = false;
751
+ this.each(function(value, index) {
752
+ if (result = !!iterator.call(context, value, index))
753
+ throw $break;
754
+ });
755
+ return result;
756
+ }
757
+
758
+ function collect(iterator, context) {
759
+ iterator = iterator || Prototype.K;
760
+ var results = [];
761
+ this.each(function(value, index) {
762
+ results.push(iterator.call(context, value, index));
763
+ });
764
+ return results;
765
+ }
766
+
767
+ function detect(iterator, context) {
768
+ var result;
769
+ this.each(function(value, index) {
770
+ if (iterator.call(context, value, index)) {
771
+ result = value;
772
+ throw $break;
773
+ }
774
+ });
775
+ return result;
776
+ }
777
+
778
+ function findAll(iterator, context) {
779
+ var results = [];
780
+ this.each(function(value, index) {
781
+ if (iterator.call(context, value, index))
782
+ results.push(value);
783
+ });
784
+ return results;
785
+ }
786
+
787
+ function grep(filter, iterator, context) {
788
+ iterator = iterator || Prototype.K;
789
+ var results = [];
790
+
791
+ if (Object.isString(filter))
792
+ filter = new RegExp(RegExp.escape(filter));
793
+
794
+ this.each(function(value, index) {
795
+ if (filter.match(value))
796
+ results.push(iterator.call(context, value, index));
797
+ });
798
+ return results;
799
+ }
800
+
801
+ function include(object) {
802
+ if (Object.isFunction(this.indexOf))
803
+ if (this.indexOf(object) != -1) return true;
804
+
805
+ var found = false;
806
+ this.each(function(value) {
807
+ if (value == object) {
808
+ found = true;
809
+ throw $break;
810
+ }
811
+ });
812
+ return found;
813
+ }
814
+
815
+ function inGroupsOf(number, fillWith) {
816
+ fillWith = Object.isUndefined(fillWith) ? null : fillWith;
817
+ return this.eachSlice(number, function(slice) {
818
+ while(slice.length < number) slice.push(fillWith);
819
+ return slice;
820
+ });
821
+ }
822
+
823
+ function inject(memo, iterator, context) {
824
+ this.each(function(value, index) {
825
+ memo = iterator.call(context, memo, value, index);
826
+ });
827
+ return memo;
828
+ }
829
+
830
+ function invoke(method) {
831
+ var args = $A(arguments).slice(1);
832
+ return this.map(function(value) {
833
+ return value[method].apply(value, args);
834
+ });
835
+ }
836
+
837
+ function max(iterator, context) {
838
+ iterator = iterator || Prototype.K;
839
+ var result;
840
+ this.each(function(value, index) {
841
+ value = iterator.call(context, value, index);
842
+ if (result == null || value >= result)
843
+ result = value;
844
+ });
845
+ return result;
846
+ }
847
+
848
+ function min(iterator, context) {
849
+ iterator = iterator || Prototype.K;
850
+ var result;
851
+ this.each(function(value, index) {
852
+ value = iterator.call(context, value, index);
853
+ if (result == null || value < result)
854
+ result = value;
855
+ });
856
+ return result;
857
+ }
858
+
859
+ function partition(iterator, context) {
860
+ iterator = iterator || Prototype.K;
861
+ var trues = [], falses = [];
862
+ this.each(function(value, index) {
863
+ (iterator.call(context, value, index) ?
864
+ trues : falses).push(value);
865
+ });
866
+ return [trues, falses];
867
+ }
868
+
869
+ function pluck(property) {
870
+ var results = [];
871
+ this.each(function(value) {
872
+ results.push(value[property]);
873
+ });
874
+ return results;
875
+ }
876
+
877
+ function reject(iterator, context) {
878
+ var results = [];
879
+ this.each(function(value, index) {
880
+ if (!iterator.call(context, value, index))
881
+ results.push(value);
882
+ });
883
+ return results;
884
+ }
885
+
886
+ function sortBy(iterator, context) {
887
+ return this.map(function(value, index) {
888
+ return {
889
+ value: value,
890
+ criteria: iterator.call(context, value, index)
891
+ };
892
+ }).sort(function(left, right) {
893
+ var a = left.criteria, b = right.criteria;
894
+ return a < b ? -1 : a > b ? 1 : 0;
895
+ }).pluck('value');
896
+ }
897
+
898
+ function toArray() {
899
+ return this.map();
900
+ }
901
+
902
+ function zip() {
903
+ var iterator = Prototype.K, args = $A(arguments);
904
+ if (Object.isFunction(args.last()))
905
+ iterator = args.pop();
906
+
907
+ var collections = [this].concat(args).map($A);
908
+ return this.map(function(value, index) {
909
+ return iterator(collections.pluck(index));
910
+ });
911
+ }
912
+
913
+ function size() {
914
+ return this.toArray().length;
915
+ }
916
+
917
+ function inspect() {
918
+ return '#<Enumerable:' + this.toArray().inspect() + '>';
919
+ }
920
+
921
+
922
+
923
+
924
+
925
+
926
+
927
+
928
+
929
+ return {
930
+ each: each,
931
+ eachSlice: eachSlice,
932
+ all: all,
933
+ every: all,
934
+ any: any,
935
+ some: any,
936
+ collect: collect,
937
+ map: collect,
938
+ detect: detect,
939
+ findAll: findAll,
940
+ select: findAll,
941
+ filter: findAll,
942
+ grep: grep,
943
+ include: include,
944
+ member: include,
945
+ inGroupsOf: inGroupsOf,
946
+ inject: inject,
947
+ invoke: invoke,
948
+ max: max,
949
+ min: min,
950
+ partition: partition,
951
+ pluck: pluck,
952
+ reject: reject,
953
+ sortBy: sortBy,
954
+ toArray: toArray,
955
+ entries: toArray,
956
+ zip: zip,
957
+ size: size,
958
+ inspect: inspect,
959
+ find: detect
960
+ };
961
+ })();
962
+ function $A(iterable) {
963
+ if (!iterable) return [];
964
+ if ('toArray' in iterable) return iterable.toArray();
965
+ var length = iterable.length || 0, results = new Array(length);
966
+ while (length--) results[length] = iterable[length];
967
+ return results;
968
+ }
969
+
970
+ function $w(string) {
971
+ if (!Object.isString(string)) return [];
972
+ string = string.strip();
973
+ return string ? string.split(/\s+/) : [];
974
+ }
975
+
976
+ Array.from = $A;
977
+
978
+
979
+ (function() {
980
+ var arrayProto = Array.prototype,
981
+ slice = arrayProto.slice,
982
+ _each = arrayProto.forEach; // use native browser JS 1.6 implementation if available
983
+
984
+ function each(iterator) {
985
+ for (var i = 0, length = this.length; i < length; i++)
986
+ iterator(this[i]);
987
+ }
988
+ if (!_each) _each = each;
989
+
990
+ function clear() {
991
+ this.length = 0;
992
+ return this;
993
+ }
994
+
995
+ function first() {
996
+ return this[0];
997
+ }
998
+
999
+ function last() {
1000
+ return this[this.length - 1];
1001
+ }
1002
+
1003
+ function compact() {
1004
+ return this.select(function(value) {
1005
+ return value != null;
1006
+ });
1007
+ }
1008
+
1009
+ function flatten() {
1010
+ return this.inject([], function(array, value) {
1011
+ if (Object.isArray(value))
1012
+ return array.concat(value.flatten());
1013
+ array.push(value);
1014
+ return array;
1015
+ });
1016
+ }
1017
+
1018
+ function without() {
1019
+ var values = slice.call(arguments, 0);
1020
+ return this.select(function(value) {
1021
+ return !values.include(value);
1022
+ });
1023
+ }
1024
+
1025
+ function reverse(inline) {
1026
+ return (inline !== false ? this : this.toArray())._reverse();
1027
+ }
1028
+
1029
+ function uniq(sorted) {
1030
+ return this.inject([], function(array, value, index) {
1031
+ if (0 == index || (sorted ? array.last() != value : !array.include(value)))
1032
+ array.push(value);
1033
+ return array;
1034
+ });
1035
+ }
1036
+
1037
+ function intersect(array) {
1038
+ return this.uniq().findAll(function(item) {
1039
+ return array.detect(function(value) { return item === value });
1040
+ });
1041
+ }
1042
+
1043
+
1044
+ function clone() {
1045
+ return slice.call(this, 0);
1046
+ }
1047
+
1048
+ function size() {
1049
+ return this.length;
1050
+ }
1051
+
1052
+ function inspect() {
1053
+ return '[' + this.map(Object.inspect).join(', ') + ']';
1054
+ }
1055
+
1056
+ function toJSON() {
1057
+ var results = [];
1058
+ this.each(function(object) {
1059
+ var value = Object.toJSON(object);
1060
+ if (!Object.isUndefined(value)) results.push(value);
1061
+ });
1062
+ return '[' + results.join(', ') + ']';
1063
+ }
1064
+
1065
+ function indexOf(item, i) {
1066
+ i || (i = 0);
1067
+ var length = this.length;
1068
+ if (i < 0) i = length + i;
1069
+ for (; i < length; i++)
1070
+ if (this[i] === item) return i;
1071
+ return -1;
1072
+ }
1073
+
1074
+ function lastIndexOf(item, i) {
1075
+ i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
1076
+ var n = this.slice(0, i).reverse().indexOf(item);
1077
+ return (n < 0) ? n : i - n - 1;
1078
+ }
1079
+
1080
+ function concat() {
1081
+ var array = slice.call(this, 0), item;
1082
+ for (var i = 0, length = arguments.length; i < length; i++) {
1083
+ item = arguments[i];
1084
+ if (Object.isArray(item) && !('callee' in item)) {
1085
+ for (var j = 0, arrayLength = item.length; j < arrayLength; j++)
1086
+ array.push(item[j]);
1087
+ } else {
1088
+ array.push(item);
1089
+ }
1090
+ }
1091
+ return array;
1092
+ }
1093
+
1094
+ Object.extend(arrayProto, Enumerable);
1095
+
1096
+ if (!arrayProto._reverse)
1097
+ arrayProto._reverse = arrayProto.reverse;
1098
+
1099
+ Object.extend(arrayProto, {
1100
+ _each: _each,
1101
+ clear: clear,
1102
+ first: first,
1103
+ last: last,
1104
+ compact: compact,
1105
+ flatten: flatten,
1106
+ without: without,
1107
+ reverse: reverse,
1108
+ uniq: uniq,
1109
+ intersect: intersect,
1110
+ clone: clone,
1111
+ toArray: clone,
1112
+ size: size,
1113
+ inspect: inspect,
1114
+ toJSON: toJSON
1115
+ });
1116
+
1117
+ var CONCAT_ARGUMENTS_BUGGY = (function() {
1118
+ return [].concat(arguments)[0][0] !== 1;
1119
+ })(1,2)
1120
+
1121
+ if (CONCAT_ARGUMENTS_BUGGY) arrayProto.concat = concat;
1122
+
1123
+ if (!arrayProto.indexOf) arrayProto.indexOf = indexOf;
1124
+ if (!arrayProto.lastIndexOf) arrayProto.lastIndexOf = lastIndexOf;
1125
+ })();
1126
+ function $H(object) {
1127
+ return new Hash(object);
1128
+ };
1129
+
1130
+ var Hash = Class.create(Enumerable, (function() {
1131
+ function initialize(object) {
1132
+ this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
1133
+ }
1134
+
1135
+ function _each(iterator) {
1136
+ for (var key in this._object) {
1137
+ var value = this._object[key], pair = [key, value];
1138
+ pair.key = key;
1139
+ pair.value = value;
1140
+ iterator(pair);
1141
+ }
1142
+ }
1143
+
1144
+ function set(key, value) {
1145
+ return this._object[key] = value;
1146
+ }
1147
+
1148
+ function get(key) {
1149
+ if (this._object[key] !== Object.prototype[key])
1150
+ return this._object[key];
1151
+ }
1152
+
1153
+ function unset(key) {
1154
+ var value = this._object[key];
1155
+ delete this._object[key];
1156
+ return value;
1157
+ }
1158
+
1159
+ function toObject() {
1160
+ return Object.clone(this._object);
1161
+ }
1162
+
1163
+ function keys() {
1164
+ return this.pluck('key');
1165
+ }
1166
+
1167
+ function values() {
1168
+ return this.pluck('value');
1169
+ }
1170
+
1171
+ function index(value) {
1172
+ var match = this.detect(function(pair) {
1173
+ return pair.value === value;
1174
+ });
1175
+ return match && match.key;
1176
+ }
1177
+
1178
+ function merge(object) {
1179
+ return this.clone().update(object);
1180
+ }
1181
+
1182
+ function update(object) {
1183
+ return new Hash(object).inject(this, function(result, pair) {
1184
+ result.set(pair.key, pair.value);
1185
+ return result;
1186
+ });
1187
+ }
1188
+
1189
+ function toQueryPair(key, value) {
1190
+ if (Object.isUndefined(value)) return key;
1191
+ return key + '=' + encodeURIComponent(String.interpret(value));
1192
+ }
1193
+
1194
+ function toQueryString() {
1195
+ return this.inject([], function(results, pair) {
1196
+ var key = encodeURIComponent(pair.key), values = pair.value;
1197
+
1198
+ if (values && typeof values == 'object') {
1199
+ if (Object.isArray(values))
1200
+ return results.concat(values.map(toQueryPair.curry(key)));
1201
+ } else results.push(toQueryPair(key, values));
1202
+ return results;
1203
+ }).join('&');
1204
+ }
1205
+
1206
+ function inspect() {
1207
+ return '#<Hash:{' + this.map(function(pair) {
1208
+ return pair.map(Object.inspect).join(': ');
1209
+ }).join(', ') + '}>';
1210
+ }
1211
+
1212
+ function toJSON() {
1213
+ return Object.toJSON(this.toObject());
1214
+ }
1215
+
1216
+ function clone() {
1217
+ return new Hash(this);
1218
+ }
1219
+
1220
+ return {
1221
+ initialize: initialize,
1222
+ _each: _each,
1223
+ set: set,
1224
+ get: get,
1225
+ unset: unset,
1226
+ toObject: toObject,
1227
+ toTemplateReplacements: toObject,
1228
+ keys: keys,
1229
+ values: values,
1230
+ index: index,
1231
+ merge: merge,
1232
+ update: update,
1233
+ toQueryString: toQueryString,
1234
+ inspect: inspect,
1235
+ toJSON: toJSON,
1236
+ clone: clone
1237
+ };
1238
+ })());
1239
+
1240
+ Hash.from = $H;
1241
+ Object.extend(Number.prototype, (function() {
1242
+ function toColorPart() {
1243
+ return this.toPaddedString(2, 16);
1244
+ }
1245
+
1246
+ function succ() {
1247
+ return this + 1;
1248
+ }
1249
+
1250
+ function times(iterator, context) {
1251
+ $R(0, this, true).each(iterator, context);
1252
+ return this;
1253
+ }
1254
+
1255
+ function toPaddedString(length, radix) {
1256
+ var string = this.toString(radix || 10);
1257
+ return '0'.times(length - string.length) + string;
1258
+ }
1259
+
1260
+ function toJSON() {
1261
+ return isFinite(this) ? this.toString() : 'null';
1262
+ }
1263
+
1264
+ function abs() {
1265
+ return Math.abs(this);
1266
+ }
1267
+
1268
+ function round() {
1269
+ return Math.round(this);
1270
+ }
1271
+
1272
+ function ceil() {
1273
+ return Math.ceil(this);
1274
+ }
1275
+
1276
+ function floor() {
1277
+ return Math.floor(this);
1278
+ }
1279
+
1280
+ return {
1281
+ toColorPart: toColorPart,
1282
+ succ: succ,
1283
+ times: times,
1284
+ toPaddedString: toPaddedString,
1285
+ toJSON: toJSON,
1286
+ abs: abs,
1287
+ round: round,
1288
+ ceil: ceil,
1289
+ floor: floor
1290
+ };
1291
+ })());
1292
+
1293
+ function $R(start, end, exclusive) {
1294
+ return new ObjectRange(start, end, exclusive);
1295
+ }
1296
+
1297
+ var ObjectRange = Class.create(Enumerable, (function() {
1298
+ function initialize(start, end, exclusive) {
1299
+ this.start = start;
1300
+ this.end = end;
1301
+ this.exclusive = exclusive;
1302
+ }
1303
+
1304
+ function _each(iterator) {
1305
+ var value = this.start;
1306
+ while (this.include(value)) {
1307
+ iterator(value);
1308
+ value = value.succ();
1309
+ }
1310
+ }
1311
+
1312
+ function include(value) {
1313
+ if (value < this.start)
1314
+ return false;
1315
+ if (this.exclusive)
1316
+ return value < this.end;
1317
+ return value <= this.end;
1318
+ }
1319
+
1320
+ return {
1321
+ initialize: initialize,
1322
+ _each: _each,
1323
+ include: include
1324
+ };
1325
+ })());
1326
+
1327
+
1328
+
1329
+ var Ajax = {
1330
+ getTransport: function() {
1331
+ return Try.these(
1332
+ function() {return new XMLHttpRequest()},
1333
+ function() {return new ActiveXObject('Msxml2.XMLHTTP')},
1334
+ function() {return new ActiveXObject('Microsoft.XMLHTTP')}
1335
+ ) || false;
1336
+ },
1337
+
1338
+ activeRequestCount: 0
1339
+ };
1340
+
1341
+ Ajax.Responders = {
1342
+ responders: [],
1343
+
1344
+ _each: function(iterator) {
1345
+ this.responders._each(iterator);
1346
+ },
1347
+
1348
+ register: function(responder) {
1349
+ if (!this.include(responder))
1350
+ this.responders.push(responder);
1351
+ },
1352
+
1353
+ unregister: function(responder) {
1354
+ this.responders = this.responders.without(responder);
1355
+ },
1356
+
1357
+ dispatch: function(callback, request, transport, json) {
1358
+ this.each(function(responder) {
1359
+ if (Object.isFunction(responder[callback])) {
1360
+ try {
1361
+ responder[callback].apply(responder, [request, transport, json]);
1362
+ } catch (e) { }
1363
+ }
1364
+ });
1365
+ }
1366
+ };
1367
+
1368
+ Object.extend(Ajax.Responders, Enumerable);
1369
+
1370
+ Ajax.Responders.register({
1371
+ onCreate: function() { Ajax.activeRequestCount++ },
1372
+ onComplete: function() { Ajax.activeRequestCount-- }
1373
+ });
1374
+ Ajax.Base = Class.create({
1375
+ initialize: function(options) {
1376
+ this.options = {
1377
+ method: 'post',
1378
+ asynchronous: true,
1379
+ contentType: 'application/x-www-form-urlencoded',
1380
+ encoding: 'UTF-8',
1381
+ parameters: '',
1382
+ evalJSON: true,
1383
+ evalJS: true
1384
+ };
1385
+ Object.extend(this.options, options || { });
1386
+
1387
+ this.options.method = this.options.method.toLowerCase();
1388
+
1389
+ if (Object.isString(this.options.parameters))
1390
+ this.options.parameters = this.options.parameters.toQueryParams();
1391
+ else if (Object.isHash(this.options.parameters))
1392
+ this.options.parameters = this.options.parameters.toObject();
1393
+ }
1394
+ });
1395
+ Ajax.Request = Class.create(Ajax.Base, {
1396
+ _complete: false,
1397
+
1398
+ initialize: function($super, url, options) {
1399
+ $super(options);
1400
+ this.transport = Ajax.getTransport();
1401
+ this.request(url);
1402
+ },
1403
+
1404
+ request: function(url) {
1405
+ this.url = url;
1406
+ this.method = this.options.method;
1407
+ var params = Object.clone(this.options.parameters);
1408
+
1409
+ if (!['get', 'post'].include(this.method)) {
1410
+ params['_method'] = this.method;
1411
+ this.method = 'post';
1412
+ }
1413
+
1414
+ this.parameters = params;
1415
+
1416
+ if (params = Object.toQueryString(params)) {
1417
+ if (this.method == 'get')
1418
+ this.url += (this.url.include('?') ? '&' : '?') + params;
1419
+ else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
1420
+ params += '&_=';
1421
+ }
1422
+
1423
+ try {
1424
+ var response = new Ajax.Response(this);
1425
+ if (this.options.onCreate) this.options.onCreate(response);
1426
+ Ajax.Responders.dispatch('onCreate', this, response);
1427
+
1428
+ this.transport.open(this.method.toUpperCase(), this.url,
1429
+ this.options.asynchronous);
1430
+
1431
+ if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
1432
+
1433
+ this.transport.onreadystatechange = this.onStateChange.bind(this);
1434
+ this.setRequestHeaders();
1435
+
1436
+ this.body = this.method == 'post' ? (this.options.postBody || params) : null;
1437
+ this.transport.send(this.body);
1438
+
1439
+ /* Force Firefox to handle ready state 4 for synchronous requests */
1440
+ if (!this.options.asynchronous && this.transport.overrideMimeType)
1441
+ this.onStateChange();
1442
+
1443
+ }
1444
+ catch (e) {
1445
+ this.dispatchException(e);
1446
+ }
1447
+ },
1448
+
1449
+ onStateChange: function() {
1450
+ var readyState = this.transport.readyState;
1451
+ if (readyState > 1 && !((readyState == 4) && this._complete))
1452
+ this.respondToReadyState(this.transport.readyState);
1453
+ },
1454
+
1455
+ setRequestHeaders: function() {
1456
+ var headers = {
1457
+ 'X-Requested-With': 'XMLHttpRequest',
1458
+ 'X-Prototype-Version': Prototype.Version,
1459
+ 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
1460
+ };
1461
+
1462
+ if (this.method == 'post') {
1463
+ headers['Content-type'] = this.options.contentType +
1464
+ (this.options.encoding ? '; charset=' + this.options.encoding : '');
1465
+
1466
+ /* Force "Connection: close" for older Mozilla browsers to work
1467
+ * around a bug where XMLHttpRequest sends an incorrect
1468
+ * Content-length header. See Mozilla Bugzilla #246651.
1469
+ */
1470
+ if (this.transport.overrideMimeType &&
1471
+ (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
1472
+ headers['Connection'] = 'close';
1473
+ }
1474
+
1475
+ if (typeof this.options.requestHeaders == 'object') {
1476
+ var extras = this.options.requestHeaders;
1477
+
1478
+ if (Object.isFunction(extras.push))
1479
+ for (var i = 0, length = extras.length; i < length; i += 2)
1480
+ headers[extras[i]] = extras[i+1];
1481
+ else
1482
+ $H(extras).each(function(pair) { headers[pair.key] = pair.value });
1483
+ }
1484
+
1485
+ for (var name in headers)
1486
+ this.transport.setRequestHeader(name, headers[name]);
1487
+ },
1488
+
1489
+ success: function() {
1490
+ var status = this.getStatus();
1491
+ return !status || (status >= 200 && status < 300);
1492
+ },
1493
+
1494
+ getStatus: function() {
1495
+ try {
1496
+ return this.transport.status || 0;
1497
+ } catch (e) { return 0 }
1498
+ },
1499
+
1500
+ respondToReadyState: function(readyState) {
1501
+ var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
1502
+
1503
+ if (state == 'Complete') {
1504
+ try {
1505
+ this._complete = true;
1506
+ (this.options['on' + response.status]
1507
+ || this.options['on' + (this.success() ? 'Success' : 'Failure')]
1508
+ || Prototype.emptyFunction)(response, response.headerJSON);
1509
+ } catch (e) {
1510
+ this.dispatchException(e);
1511
+ }
1512
+
1513
+ var contentType = response.getHeader('Content-type');
1514
+ if (this.options.evalJS == 'force'
1515
+ || (this.options.evalJS && this.isSameOrigin() && contentType
1516
+ && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
1517
+ this.evalResponse();
1518
+ }
1519
+
1520
+ try {
1521
+ (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
1522
+ Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
1523
+ } catch (e) {
1524
+ this.dispatchException(e);
1525
+ }
1526
+
1527
+ if (state == 'Complete') {
1528
+ this.transport.onreadystatechange = Prototype.emptyFunction;
1529
+ }
1530
+ },
1531
+
1532
+ isSameOrigin: function() {
1533
+ var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
1534
+ return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
1535
+ protocol: location.protocol,
1536
+ domain: document.domain,
1537
+ port: location.port ? ':' + location.port : ''
1538
+ }));
1539
+ },
1540
+
1541
+ getHeader: function(name) {
1542
+ try {
1543
+ return this.transport.getResponseHeader(name) || null;
1544
+ } catch (e) { return null; }
1545
+ },
1546
+
1547
+ evalResponse: function() {
1548
+ try {
1549
+ return eval((this.transport.responseText || '').unfilterJSON());
1550
+ } catch (e) {
1551
+ this.dispatchException(e);
1552
+ }
1553
+ },
1554
+
1555
+ dispatchException: function(exception) {
1556
+ (this.options.onException || Prototype.emptyFunction)(this, exception);
1557
+ Ajax.Responders.dispatch('onException', this, exception);
1558
+ }
1559
+ });
1560
+
1561
+ Ajax.Request.Events =
1562
+ ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
1563
+
1564
+
1565
+
1566
+
1567
+
1568
+
1569
+
1570
+
1571
+ Ajax.Response = Class.create({
1572
+ initialize: function(request){
1573
+ this.request = request;
1574
+ var transport = this.transport = request.transport,
1575
+ readyState = this.readyState = transport.readyState;
1576
+
1577
+ if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
1578
+ this.status = this.getStatus();
1579
+ this.statusText = this.getStatusText();
1580
+ this.responseText = String.interpret(transport.responseText);
1581
+ this.headerJSON = this._getHeaderJSON();
1582
+ }
1583
+
1584
+ if(readyState == 4) {
1585
+ var xml = transport.responseXML;
1586
+ this.responseXML = Object.isUndefined(xml) ? null : xml;
1587
+ this.responseJSON = this._getResponseJSON();
1588
+ }
1589
+ },
1590
+
1591
+ status: 0,
1592
+
1593
+ statusText: '',
1594
+
1595
+ getStatus: Ajax.Request.prototype.getStatus,
1596
+
1597
+ getStatusText: function() {
1598
+ try {
1599
+ return this.transport.statusText || '';
1600
+ } catch (e) { return '' }
1601
+ },
1602
+
1603
+ getHeader: Ajax.Request.prototype.getHeader,
1604
+
1605
+ getAllHeaders: function() {
1606
+ try {
1607
+ return this.getAllResponseHeaders();
1608
+ } catch (e) { return null }
1609
+ },
1610
+
1611
+ getResponseHeader: function(name) {
1612
+ return this.transport.getResponseHeader(name);
1613
+ },
1614
+
1615
+ getAllResponseHeaders: function() {
1616
+ return this.transport.getAllResponseHeaders();
1617
+ },
1618
+
1619
+ _getHeaderJSON: function() {
1620
+ var json = this.getHeader('X-JSON');
1621
+ if (!json) return null;
1622
+ json = decodeURIComponent(escape(json));
1623
+ try {
1624
+ return json.evalJSON(this.request.options.sanitizeJSON ||
1625
+ !this.request.isSameOrigin());
1626
+ } catch (e) {
1627
+ this.request.dispatchException(e);
1628
+ }
1629
+ },
1630
+
1631
+ _getResponseJSON: function() {
1632
+ var options = this.request.options;
1633
+ if (!options.evalJSON || (options.evalJSON != 'force' &&
1634
+ !(this.getHeader('Content-type') || '').include('application/json')) ||
1635
+ this.responseText.blank())
1636
+ return null;
1637
+ try {
1638
+ return this.responseText.evalJSON(options.sanitizeJSON ||
1639
+ !this.request.isSameOrigin());
1640
+ } catch (e) {
1641
+ this.request.dispatchException(e);
1642
+ }
1643
+ }
1644
+ });
1645
+
1646
+ Ajax.Updater = Class.create(Ajax.Request, {
1647
+ initialize: function($super, container, url, options) {
1648
+ this.container = {
1649
+ success: (container.success || container),
1650
+ failure: (container.failure || (container.success ? null : container))
1651
+ };
1652
+
1653
+ options = Object.clone(options);
1654
+ var onComplete = options.onComplete;
1655
+ options.onComplete = (function(response, json) {
1656
+ this.updateContent(response.responseText);
1657
+ if (Object.isFunction(onComplete)) onComplete(response, json);
1658
+ }).bind(this);
1659
+
1660
+ $super(url, options);
1661
+ },
1662
+
1663
+ updateContent: function(responseText) {
1664
+ var receiver = this.container[this.success() ? 'success' : 'failure'],
1665
+ options = this.options;
1666
+
1667
+ if (!options.evalScripts) responseText = responseText.stripScripts();
1668
+
1669
+ if (receiver = $(receiver)) {
1670
+ if (options.insertion) {
1671
+ if (Object.isString(options.insertion)) {
1672
+ var insertion = { }; insertion[options.insertion] = responseText;
1673
+ receiver.insert(insertion);
1674
+ }
1675
+ else options.insertion(receiver, responseText);
1676
+ }
1677
+ else receiver.update(responseText);
1678
+ }
1679
+ }
1680
+ });
1681
+
1682
+ Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
1683
+ initialize: function($super, container, url, options) {
1684
+ $super(options);
1685
+ this.onComplete = this.options.onComplete;
1686
+
1687
+ this.frequency = (this.options.frequency || 2);
1688
+ this.decay = (this.options.decay || 1);
1689
+
1690
+ this.updater = { };
1691
+ this.container = container;
1692
+ this.url = url;
1693
+
1694
+ this.start();
1695
+ },
1696
+
1697
+ start: function() {
1698
+ this.options.onComplete = this.updateComplete.bind(this);
1699
+ this.onTimerEvent();
1700
+ },
1701
+
1702
+ stop: function() {
1703
+ this.updater.options.onComplete = undefined;
1704
+ clearTimeout(this.timer);
1705
+ (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
1706
+ },
1707
+
1708
+ updateComplete: function(response) {
1709
+ if (this.options.decay) {
1710
+ this.decay = (response.responseText == this.lastText ?
1711
+ this.decay * this.options.decay : 1);
1712
+
1713
+ this.lastText = response.responseText;
1714
+ }
1715
+ this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
1716
+ },
1717
+
1718
+ onTimerEvent: function() {
1719
+ this.updater = new Ajax.Updater(this.container, this.url, this.options);
1720
+ }
1721
+ });
1722
+
1723
+
1724
+
1725
+ function $(element) {
1726
+ if (arguments.length > 1) {
1727
+ for (var i = 0, elements = [], length = arguments.length; i < length; i++)
1728
+ elements.push($(arguments[i]));
1729
+ return elements;
1730
+ }
1731
+ if (Object.isString(element))
1732
+ element = document.getElementById(element);
1733
+ return Element.extend(element);
1734
+ }
1735
+
1736
+ if (Prototype.BrowserFeatures.XPath) {
1737
+ document._getElementsByXPath = function(expression, parentElement) {
1738
+ var results = [];
1739
+ var query = document.evaluate(expression, $(parentElement) || document,
1740
+ null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
1741
+ for (var i = 0, length = query.snapshotLength; i < length; i++)
1742
+ results.push(Element.extend(query.snapshotItem(i)));
1743
+ return results;
1744
+ };
1745
+ }
1746
+
1747
+ /*--------------------------------------------------------------------------*/
1748
+
1749
+ if (!window.Node) var Node = { };
1750
+
1751
+ if (!Node.ELEMENT_NODE) {
1752
+ Object.extend(Node, {
1753
+ ELEMENT_NODE: 1,
1754
+ ATTRIBUTE_NODE: 2,
1755
+ TEXT_NODE: 3,
1756
+ CDATA_SECTION_NODE: 4,
1757
+ ENTITY_REFERENCE_NODE: 5,
1758
+ ENTITY_NODE: 6,
1759
+ PROCESSING_INSTRUCTION_NODE: 7,
1760
+ COMMENT_NODE: 8,
1761
+ DOCUMENT_NODE: 9,
1762
+ DOCUMENT_TYPE_NODE: 10,
1763
+ DOCUMENT_FRAGMENT_NODE: 11,
1764
+ NOTATION_NODE: 12
1765
+ });
1766
+ }
1767
+
1768
+
1769
+ (function(global) {
1770
+
1771
+ var SETATTRIBUTE_IGNORES_NAME = (function(){
1772
+ var elForm = document.createElement("form");
1773
+ var elInput = document.createElement("input");
1774
+ var root = document.documentElement;
1775
+ elInput.setAttribute("name", "test");
1776
+ elForm.appendChild(elInput);
1777
+ root.appendChild(elForm);
1778
+ var isBuggy = elForm.elements
1779
+ ? (typeof elForm.elements.test == "undefined")
1780
+ : null;
1781
+ root.removeChild(elForm);
1782
+ elForm = elInput = null;
1783
+ return isBuggy;
1784
+ })();
1785
+
1786
+ var element = global.Element;
1787
+ global.Element = function(tagName, attributes) {
1788
+ attributes = attributes || { };
1789
+ tagName = tagName.toLowerCase();
1790
+ var cache = Element.cache;
1791
+ if (SETATTRIBUTE_IGNORES_NAME && attributes.name) {
1792
+ tagName = '<' + tagName + ' name="' + attributes.name + '">';
1793
+ delete attributes.name;
1794
+ return Element.writeAttribute(document.createElement(tagName), attributes);
1795
+ }
1796
+ if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
1797
+ return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
1798
+ };
1799
+ Object.extend(global.Element, element || { });
1800
+ if (element) global.Element.prototype = element.prototype;
1801
+ })(this);
1802
+
1803
+ Element.cache = { };
1804
+ Element.idCounter = 1;
1805
+
1806
+ Element.Methods = {
1807
+ visible: function(element) {
1808
+ return $(element).style.display != 'none';
1809
+ },
1810
+
1811
+ toggle: function(element) {
1812
+ element = $(element);
1813
+ Element[Element.visible(element) ? 'hide' : 'show'](element);
1814
+ return element;
1815
+ },
1816
+
1817
+
1818
+ hide: function(element) {
1819
+ element = $(element);
1820
+ element.style.display = 'none';
1821
+ return element;
1822
+ },
1823
+
1824
+ show: function(element) {
1825
+ element = $(element);
1826
+ element.style.display = '';
1827
+ return element;
1828
+ },
1829
+
1830
+ remove: function(element) {
1831
+ element = $(element);
1832
+ element.parentNode.removeChild(element);
1833
+ return element;
1834
+ },
1835
+
1836
+ update: (function(){
1837
+
1838
+ var SELECT_ELEMENT_INNERHTML_BUGGY = (function(){
1839
+ var el = document.createElement("select"),
1840
+ isBuggy = true;
1841
+ el.innerHTML = "<option value=\"test\">test</option>";
1842
+ if (el.options && el.options[0]) {
1843
+ isBuggy = el.options[0].nodeName.toUpperCase() !== "OPTION";
1844
+ }
1845
+ el = null;
1846
+ return isBuggy;
1847
+ })();
1848
+
1849
+ var TABLE_ELEMENT_INNERHTML_BUGGY = (function(){
1850
+ try {
1851
+ var el = document.createElement("table");
1852
+ if (el && el.tBodies) {
1853
+ el.innerHTML = "<tbody><tr><td>test</td></tr></tbody>";
1854
+ var isBuggy = typeof el.tBodies[0] == "undefined";
1855
+ el = null;
1856
+ return isBuggy;
1857
+ }
1858
+ } catch (e) {
1859
+ return true;
1860
+ }
1861
+ })();
1862
+
1863
+ var SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING = (function () {
1864
+ var s = document.createElement("script"),
1865
+ isBuggy = false;
1866
+ try {
1867
+ s.appendChild(document.createTextNode(""));
1868
+ isBuggy = !s.firstChild ||
1869
+ s.firstChild && s.firstChild.nodeType !== 3;
1870
+ } catch (e) {
1871
+ isBuggy = true;
1872
+ }
1873
+ s = null;
1874
+ return isBuggy;
1875
+ })();
1876
+
1877
+ function update(element, content) {
1878
+ element = $(element);
1879
+
1880
+ if (content && content.toElement)
1881
+ content = content.toElement();
1882
+
1883
+ if (Object.isElement(content))
1884
+ return element.update().insert(content);
1885
+
1886
+ content = Object.toHTML(content);
1887
+
1888
+ var tagName = element.tagName.toUpperCase();
1889
+
1890
+ if (tagName === 'SCRIPT' && SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING) {
1891
+ element.text = content;
1892
+ return element;
1893
+ }
1894
+
1895
+ if (SELECT_ELEMENT_INNERHTML_BUGGY || TABLE_ELEMENT_INNERHTML_BUGGY) {
1896
+ if (tagName in Element._insertionTranslations.tags) {
1897
+ $A(element.childNodes).each(function(node) {
1898
+ element.removeChild(node);
1899
+ });
1900
+ Element._getContentFromAnonymousElement(tagName, content.stripScripts())
1901
+ .each(function(node) {
1902
+ element.appendChild(node)
1903
+ });
1904
+ }
1905
+ else {
1906
+ element.innerHTML = content.stripScripts();
1907
+ }
1908
+ }
1909
+ else {
1910
+ element.innerHTML = content.stripScripts();
1911
+ }
1912
+
1913
+ content.evalScripts.bind(content).defer();
1914
+ return element;
1915
+ }
1916
+
1917
+ return update;
1918
+ })(),
1919
+
1920
+ replace: function(element, content) {
1921
+ element = $(element);
1922
+ if (content && content.toElement) content = content.toElement();
1923
+ else if (!Object.isElement(content)) {
1924
+ content = Object.toHTML(content);
1925
+ var range = element.ownerDocument.createRange();
1926
+ range.selectNode(element);
1927
+ content.evalScripts.bind(content).defer();
1928
+ content = range.createContextualFragment(content.stripScripts());
1929
+ }
1930
+ element.parentNode.replaceChild(content, element);
1931
+ return element;
1932
+ },
1933
+
1934
+ insert: function(element, insertions) {
1935
+ element = $(element);
1936
+
1937
+ if (Object.isString(insertions) || Object.isNumber(insertions) ||
1938
+ Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
1939
+ insertions = {bottom:insertions};
1940
+
1941
+ var content, insert, tagName, childNodes;
1942
+
1943
+ for (var position in insertions) {
1944
+ content = insertions[position];
1945
+ position = position.toLowerCase();
1946
+ insert = Element._insertionTranslations[position];
1947
+
1948
+ if (content && content.toElement) content = content.toElement();
1949
+ if (Object.isElement(content)) {
1950
+ insert(element, content);
1951
+ continue;
1952
+ }
1953
+
1954
+ content = Object.toHTML(content);
1955
+
1956
+ tagName = ((position == 'before' || position == 'after')
1957
+ ? element.parentNode : element).tagName.toUpperCase();
1958
+
1959
+ childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
1960
+
1961
+ if (position == 'top' || position == 'after') childNodes.reverse();
1962
+ childNodes.each(insert.curry(element));
1963
+
1964
+ content.evalScripts.bind(content).defer();
1965
+ }
1966
+
1967
+ return element;
1968
+ },
1969
+
1970
+ wrap: function(element, wrapper, attributes) {
1971
+ element = $(element);
1972
+ if (Object.isElement(wrapper))
1973
+ $(wrapper).writeAttribute(attributes || { });
1974
+ else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);
1975
+ else wrapper = new Element('div', wrapper);
1976
+ if (element.parentNode)
1977
+ element.parentNode.replaceChild(wrapper, element);
1978
+ wrapper.appendChild(element);
1979
+ return wrapper;
1980
+ },
1981
+
1982
+ inspect: function(element) {
1983
+ element = $(element);
1984
+ var result = '<' + element.tagName.toLowerCase();
1985
+ $H({'id': 'id', 'className': 'class'}).each(function(pair) {
1986
+ var property = pair.first(), attribute = pair.last();
1987
+ var value = (element[property] || '').toString();
1988
+ if (value) result += ' ' + attribute + '=' + value.inspect(true);
1989
+ });
1990
+ return result + '>';
1991
+ },
1992
+
1993
+ recursivelyCollect: function(element, property) {
1994
+ element = $(element);
1995
+ var elements = [];
1996
+ while (element = element[property])
1997
+ if (element.nodeType == 1)
1998
+ elements.push(Element.extend(element));
1999
+ return elements;
2000
+ },
2001
+
2002
+ ancestors: function(element) {
2003
+ return $(element).recursivelyCollect('parentNode');
2004
+ },
2005
+
2006
+ descendants: function(element) {
2007
+ return Element.select(element, "*");
2008
+ },
2009
+
2010
+ firstDescendant: function(element) {
2011
+ element = $(element).firstChild;
2012
+ while (element && element.nodeType != 1) element = element.nextSibling;
2013
+ return $(element);
2014
+ },
2015
+
2016
+ immediateDescendants: function(element) {
2017
+ if (!(element = $(element).firstChild)) return [];
2018
+ while (element && element.nodeType != 1) element = element.nextSibling;
2019
+ if (element) return [element].concat($(element).nextSiblings());
2020
+ return [];
2021
+ },
2022
+
2023
+ previousSiblings: function(element) {
2024
+ return $(element).recursivelyCollect('previousSibling');
2025
+ },
2026
+
2027
+ nextSiblings: function(element) {
2028
+ return $(element).recursivelyCollect('nextSibling');
2029
+ },
2030
+
2031
+ siblings: function(element) {
2032
+ element = $(element);
2033
+ return element.previousSiblings().reverse().concat(element.nextSiblings());
2034
+ },
2035
+
2036
+ match: function(element, selector) {
2037
+ if (Object.isString(selector))
2038
+ selector = new Selector(selector);
2039
+ return selector.match($(element));
2040
+ },
2041
+
2042
+ up: function(element, expression, index) {
2043
+ element = $(element);
2044
+ if (arguments.length == 1) return $(element.parentNode);
2045
+ var ancestors = element.ancestors();
2046
+ return Object.isNumber(expression) ? ancestors[expression] :
2047
+ Selector.findElement(ancestors, expression, index);
2048
+ },
2049
+
2050
+ down: function(element, expression, index) {
2051
+ element = $(element);
2052
+ if (arguments.length == 1) return element.firstDescendant();
2053
+ return Object.isNumber(expression) ? element.descendants()[expression] :
2054
+ Element.select(element, expression)[index || 0];
2055
+ },
2056
+
2057
+ previous: function(element, expression, index) {
2058
+ element = $(element);
2059
+ if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
2060
+ var previousSiblings = element.previousSiblings();
2061
+ return Object.isNumber(expression) ? previousSiblings[expression] :
2062
+ Selector.findElement(previousSiblings, expression, index);
2063
+ },
2064
+
2065
+ next: function(element, expression, index) {
2066
+ element = $(element);
2067
+ if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
2068
+ var nextSiblings = element.nextSiblings();
2069
+ return Object.isNumber(expression) ? nextSiblings[expression] :
2070
+ Selector.findElement(nextSiblings, expression, index);
2071
+ },
2072
+
2073
+
2074
+ select: function() {
2075
+ var args = $A(arguments), element = $(args.shift());
2076
+ return Selector.findChildElements(element, args);
2077
+ },
2078
+
2079
+ adjacent: function() {
2080
+ var args = $A(arguments), element = $(args.shift());
2081
+ return Selector.findChildElements(element.parentNode, args).without(element);
2082
+ },
2083
+
2084
+ identify: function(element) {
2085
+ element = $(element);
2086
+ var id = element.readAttribute('id');
2087
+ if (id) return id;
2088
+ do { id = 'anonymous_element_' + Element.idCounter++ } while ($(id));
2089
+ element.writeAttribute('id', id);
2090
+ return id;
2091
+ },
2092
+
2093
+ readAttribute: (function(){
2094
+
2095
+ var iframeGetAttributeThrowsError = (function(){
2096
+ var el = document.createElement('iframe'),
2097
+ isBuggy = false;
2098
+
2099
+ document.documentElement.appendChild(el);
2100
+ try {
2101
+ el.getAttribute('type', 2);
2102
+ } catch(e) {
2103
+ isBuggy = true;
2104
+ }
2105
+ document.documentElement.removeChild(el);
2106
+ el = null;
2107
+ return isBuggy;
2108
+ })();
2109
+
2110
+ return function(element, name) {
2111
+ element = $(element);
2112
+ if (iframeGetAttributeThrowsError &&
2113
+ name === 'type' &&
2114
+ element.tagName.toUpperCase() == 'IFRAME') {
2115
+ return element.getAttribute('type');
2116
+ }
2117
+ if (Prototype.Browser.IE) {
2118
+ var t = Element._attributeTranslations.read;
2119
+ if (t.values[name]) return t.values[name](element, name);
2120
+ if (t.names[name]) name = t.names[name];
2121
+ if (name.include(':')) {
2122
+ return (!element.attributes || !element.attributes[name]) ? null :
2123
+ element.attributes[name].value;
2124
+ }
2125
+ }
2126
+ return element.getAttribute(name);
2127
+ }
2128
+ })(),
2129
+
2130
+ writeAttribute: function(element, name, value) {
2131
+ element = $(element);
2132
+ var attributes = { }, t = Element._attributeTranslations.write;
2133
+
2134
+ if (typeof name == 'object') attributes = name;
2135
+ else attributes[name] = Object.isUndefined(value) ? true : value;
2136
+
2137
+ for (var attr in attributes) {
2138
+ name = t.names[attr] || attr;
2139
+ value = attributes[attr];
2140
+ if (t.values[attr]) name = t.values[attr](element, value);
2141
+ if (value === false || value === null)
2142
+ element.removeAttribute(name);
2143
+ else if (value === true)
2144
+ element.setAttribute(name, name);
2145
+ else element.setAttribute(name, value);
2146
+ }
2147
+ return element;
2148
+ },
2149
+
2150
+ getHeight: function(element) {
2151
+ return $(element).getDimensions().height;
2152
+ },
2153
+
2154
+ getWidth: function(element) {
2155
+ return $(element).getDimensions().width;
2156
+ },
2157
+
2158
+ classNames: function(element) {
2159
+ return new Element.ClassNames(element);
2160
+ },
2161
+
2162
+ hasClassName: function(element, className) {
2163
+ if (!(element = $(element))) return;
2164
+ var elementClassName = element.className;
2165
+ return (elementClassName.length > 0 && (elementClassName == className ||
2166
+ new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
2167
+ },
2168
+
2169
+ addClassName: function(element, className) {
2170
+ if (!(element = $(element))) return;
2171
+ if (!element.hasClassName(className))
2172
+ element.className += (element.className ? ' ' : '') + className;
2173
+ return element;
2174
+ },
2175
+
2176
+ removeClassName: function(element, className) {
2177
+ if (!(element = $(element))) return;
2178
+ element.className = element.className.replace(
2179
+ new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
2180
+ return element;
2181
+ },
2182
+
2183
+ toggleClassName: function(element, className) {
2184
+ if (!(element = $(element))) return;
2185
+ return element[element.hasClassName(className) ?
2186
+ 'removeClassName' : 'addClassName'](className);
2187
+ },
2188
+
2189
+ cleanWhitespace: function(element) {
2190
+ element = $(element);
2191
+ var node = element.firstChild;
2192
+ while (node) {
2193
+ var nextNode = node.nextSibling;
2194
+ if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
2195
+ element.removeChild(node);
2196
+ node = nextNode;
2197
+ }
2198
+ return element;
2199
+ },
2200
+
2201
+ empty: function(element) {
2202
+ return $(element).innerHTML.blank();
2203
+ },
2204
+
2205
+ descendantOf: function(element, ancestor) {
2206
+ element = $(element), ancestor = $(ancestor);
2207
+
2208
+ if (element.compareDocumentPosition)
2209
+ return (element.compareDocumentPosition(ancestor) & 8) === 8;
2210
+
2211
+ if (ancestor.contains)
2212
+ return ancestor.contains(element) && ancestor !== element;
2213
+
2214
+ while (element = element.parentNode)
2215
+ if (element == ancestor) return true;
2216
+
2217
+ return false;
2218
+ },
2219
+
2220
+ scrollTo: function(element) {
2221
+ element = $(element);
2222
+ var pos = element.cumulativeOffset();
2223
+ window.scrollTo(pos[0], pos[1]);
2224
+ return element;
2225
+ },
2226
+
2227
+ getStyle: function(element, style) {
2228
+ element = $(element);
2229
+ style = style == 'float' ? 'cssFloat' : style.camelize();
2230
+ var value = element.style[style];
2231
+ if (!value || value == 'auto') {
2232
+ var css = document.defaultView.getComputedStyle(element, null);
2233
+ value = css ? css[style] : null;
2234
+ }
2235
+ if (style == 'opacity') return value ? parseFloat(value) : 1.0;
2236
+ return value == 'auto' ? null : value;
2237
+ },
2238
+
2239
+ getOpacity: function(element) {
2240
+ return $(element).getStyle('opacity');
2241
+ },
2242
+
2243
+ setStyle: function(element, styles) {
2244
+ element = $(element);
2245
+ var elementStyle = element.style, match;
2246
+ if (Object.isString(styles)) {
2247
+ element.style.cssText += ';' + styles;
2248
+ return styles.include('opacity') ?
2249
+ element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
2250
+ }
2251
+ for (var property in styles)
2252
+ if (property == 'opacity') element.setOpacity(styles[property]);
2253
+ else
2254
+ elementStyle[(property == 'float' || property == 'cssFloat') ?
2255
+ (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
2256
+ property] = styles[property];
2257
+
2258
+ return element;
2259
+ },
2260
+
2261
+ setOpacity: function(element, value) {
2262
+ element = $(element);
2263
+ element.style.opacity = (value == 1 || value === '') ? '' :
2264
+ (value < 0.00001) ? 0 : value;
2265
+ return element;
2266
+ },
2267
+
2268
+ getDimensions: function(element) {
2269
+ element = $(element);
2270
+ var display = element.getStyle('display');
2271
+ if (display != 'none' && display != null) // Safari bug
2272
+ return {width: element.offsetWidth, height: element.offsetHeight};
2273
+
2274
+ var els = element.style;
2275
+ var originalVisibility = els.visibility;
2276
+ var originalPosition = els.position;
2277
+ var originalDisplay = els.display;
2278
+ els.visibility = 'hidden';
2279
+ if (originalPosition != 'fixed') // Switching fixed to absolute causes issues in Safari
2280
+ els.position = 'absolute';
2281
+ els.display = 'block';
2282
+ var originalWidth = element.clientWidth;
2283
+ var originalHeight = element.clientHeight;
2284
+ els.display = originalDisplay;
2285
+ els.position = originalPosition;
2286
+ els.visibility = originalVisibility;
2287
+ return {width: originalWidth, height: originalHeight};
2288
+ },
2289
+
2290
+ makePositioned: function(element) {
2291
+ element = $(element);
2292
+ var pos = Element.getStyle(element, 'position');
2293
+ if (pos == 'static' || !pos) {
2294
+ element._madePositioned = true;
2295
+ element.style.position = 'relative';
2296
+ if (Prototype.Browser.Opera) {
2297
+ element.style.top = 0;
2298
+ element.style.left = 0;
2299
+ }
2300
+ }
2301
+ return element;
2302
+ },
2303
+
2304
+ undoPositioned: function(element) {
2305
+ element = $(element);
2306
+ if (element._madePositioned) {
2307
+ element._madePositioned = undefined;
2308
+ element.style.position =
2309
+ element.style.top =
2310
+ element.style.left =
2311
+ element.style.bottom =
2312
+ element.style.right = '';
2313
+ }
2314
+ return element;
2315
+ },
2316
+
2317
+ makeClipping: function(element) {
2318
+ element = $(element);
2319
+ if (element._overflow) return element;
2320
+ element._overflow = Element.getStyle(element, 'overflow') || 'auto';
2321
+ if (element._overflow !== 'hidden')
2322
+ element.style.overflow = 'hidden';
2323
+ return element;
2324
+ },
2325
+
2326
+ undoClipping: function(element) {
2327
+ element = $(element);
2328
+ if (!element._overflow) return element;
2329
+ element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
2330
+ element._overflow = null;
2331
+ return element;
2332
+ },
2333
+
2334
+ cumulativeOffset: function(element) {
2335
+ var valueT = 0, valueL = 0;
2336
+ do {
2337
+ valueT += element.offsetTop || 0;
2338
+ valueL += element.offsetLeft || 0;
2339
+ element = element.offsetParent;
2340
+ } while (element);
2341
+ return Element._returnOffset(valueL, valueT);
2342
+ },
2343
+
2344
+ positionedOffset: function(element) {
2345
+ var valueT = 0, valueL = 0;
2346
+ do {
2347
+ valueT += element.offsetTop || 0;
2348
+ valueL += element.offsetLeft || 0;
2349
+ element = element.offsetParent;
2350
+ if (element) {
2351
+ if (element.tagName.toUpperCase() == 'BODY') break;
2352
+ var p = Element.getStyle(element, 'position');
2353
+ if (p !== 'static') break;
2354
+ }
2355
+ } while (element);
2356
+ return Element._returnOffset(valueL, valueT);
2357
+ },
2358
+
2359
+ absolutize: function(element) {
2360
+ element = $(element);
2361
+ if (element.getStyle('position') == 'absolute') return element;
2362
+
2363
+ var offsets = element.positionedOffset();
2364
+ var top = offsets[1];
2365
+ var left = offsets[0];
2366
+ var width = element.clientWidth;
2367
+ var height = element.clientHeight;
2368
+
2369
+ element._originalLeft = left - parseFloat(element.style.left || 0);
2370
+ element._originalTop = top - parseFloat(element.style.top || 0);
2371
+ element._originalWidth = element.style.width;
2372
+ element._originalHeight = element.style.height;
2373
+
2374
+ element.style.position = 'absolute';
2375
+ element.style.top = top + 'px';
2376
+ element.style.left = left + 'px';
2377
+ element.style.width = width + 'px';
2378
+ element.style.height = height + 'px';
2379
+ return element;
2380
+ },
2381
+
2382
+ relativize: function(element) {
2383
+ element = $(element);
2384
+ if (element.getStyle('position') == 'relative') return element;
2385
+
2386
+ element.style.position = 'relative';
2387
+ var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
2388
+ var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
2389
+
2390
+ element.style.top = top + 'px';
2391
+ element.style.left = left + 'px';
2392
+ element.style.height = element._originalHeight;
2393
+ element.style.width = element._originalWidth;
2394
+ return element;
2395
+ },
2396
+
2397
+ cumulativeScrollOffset: function(element) {
2398
+ var valueT = 0, valueL = 0;
2399
+ do {
2400
+ valueT += element.scrollTop || 0;
2401
+ valueL += element.scrollLeft || 0;
2402
+ element = element.parentNode;
2403
+ } while (element);
2404
+ return Element._returnOffset(valueL, valueT);
2405
+ },
2406
+
2407
+ getOffsetParent: function(element) {
2408
+ if (element.offsetParent) return $(element.offsetParent);
2409
+ if (element == document.body) return $(element);
2410
+
2411
+ while ((element = element.parentNode) && element != document.body)
2412
+ if (Element.getStyle(element, 'position') != 'static')
2413
+ return $(element);
2414
+
2415
+ return $(document.body);
2416
+ },
2417
+
2418
+ viewportOffset: function(forElement) {
2419
+ var valueT = 0, valueL = 0;
2420
+
2421
+ var element = forElement;
2422
+ do {
2423
+ valueT += element.offsetTop || 0;
2424
+ valueL += element.offsetLeft || 0;
2425
+
2426
+ if (element.offsetParent == document.body &&
2427
+ Element.getStyle(element, 'position') == 'absolute') break;
2428
+
2429
+ } while (element = element.offsetParent);
2430
+
2431
+ element = forElement;
2432
+ do {
2433
+ if (!Prototype.Browser.Opera || (element.tagName && (element.tagName.toUpperCase() == 'BODY'))) {
2434
+ valueT -= element.scrollTop || 0;
2435
+ valueL -= element.scrollLeft || 0;
2436
+ }
2437
+ } while (element = element.parentNode);
2438
+
2439
+ return Element._returnOffset(valueL, valueT);
2440
+ },
2441
+
2442
+ clonePosition: function(element, source) {
2443
+ var options = Object.extend({
2444
+ setLeft: true,
2445
+ setTop: true,
2446
+ setWidth: true,
2447
+ setHeight: true,
2448
+ offsetTop: 0,
2449
+ offsetLeft: 0
2450
+ }, arguments[2] || { });
2451
+
2452
+ source = $(source);
2453
+ var p = source.viewportOffset();
2454
+
2455
+ element = $(element);
2456
+ var delta = [0, 0];
2457
+ var parent = null;
2458
+ if (Element.getStyle(element, 'position') == 'absolute') {
2459
+ parent = element.getOffsetParent();
2460
+ delta = parent.viewportOffset();
2461
+ }
2462
+
2463
+ if (parent == document.body) {
2464
+ delta[0] -= document.body.offsetLeft;
2465
+ delta[1] -= document.body.offsetTop;
2466
+ }
2467
+
2468
+ if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
2469
+ if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
2470
+ if (options.setWidth) element.style.width = source.offsetWidth + 'px';
2471
+ if (options.setHeight) element.style.height = source.offsetHeight + 'px';
2472
+ return element;
2473
+ }
2474
+ };
2475
+
2476
+ Object.extend(Element.Methods, {
2477
+ getElementsBySelector: Element.Methods.select,
2478
+
2479
+ childElements: Element.Methods.immediateDescendants
2480
+ });
2481
+
2482
+ Element._attributeTranslations = {
2483
+ write: {
2484
+ names: {
2485
+ className: 'class',
2486
+ htmlFor: 'for'
2487
+ },
2488
+ values: { }
2489
+ }
2490
+ };
2491
+
2492
+ if (Prototype.Browser.Opera) {
2493
+ Element.Methods.getStyle = Element.Methods.getStyle.wrap(
2494
+ function(proceed, element, style) {
2495
+ switch (style) {
2496
+ case 'left': case 'top': case 'right': case 'bottom':
2497
+ if (proceed(element, 'position') === 'static') return null;
2498
+ case 'height': case 'width':
2499
+ if (!Element.visible(element)) return null;
2500
+
2501
+ var dim = parseInt(proceed(element, style), 10);
2502
+
2503
+ if (dim !== element['offset' + style.capitalize()])
2504
+ return dim + 'px';
2505
+
2506
+ var properties;
2507
+ if (style === 'height') {
2508
+ properties = ['border-top-width', 'padding-top',
2509
+ 'padding-bottom', 'border-bottom-width'];
2510
+ }
2511
+ else {
2512
+ properties = ['border-left-width', 'padding-left',
2513
+ 'padding-right', 'border-right-width'];
2514
+ }
2515
+ return properties.inject(dim, function(memo, property) {
2516
+ var val = proceed(element, property);
2517
+ return val === null ? memo : memo - parseInt(val, 10);
2518
+ }) + 'px';
2519
+ default: return proceed(element, style);
2520
+ }
2521
+ }
2522
+ );
2523
+
2524
+ Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(
2525
+ function(proceed, element, attribute) {
2526
+ if (attribute === 'title') return element.title;
2527
+ return proceed(element, attribute);
2528
+ }
2529
+ );
2530
+ }
2531
+
2532
+ else if (Prototype.Browser.IE) {
2533
+ Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap(
2534
+ function(proceed, element) {
2535
+ element = $(element);
2536
+ try { element.offsetParent }
2537
+ catch(e) { return $(document.body) }
2538
+ var position = element.getStyle('position');
2539
+ if (position !== 'static') return proceed(element);
2540
+ element.setStyle({ position: 'relative' });
2541
+ var value = proceed(element);
2542
+ element.setStyle({ position: position });
2543
+ return value;
2544
+ }
2545
+ );
2546
+
2547
+ $w('positionedOffset viewportOffset').each(function(method) {
2548
+ Element.Methods[method] = Element.Methods[method].wrap(
2549
+ function(proceed, element) {
2550
+ element = $(element);
2551
+ try { element.offsetParent }
2552
+ catch(e) { return Element._returnOffset(0,0) }
2553
+ var position = element.getStyle('position');
2554
+ if (position !== 'static') return proceed(element);
2555
+ var offsetParent = element.getOffsetParent();
2556
+ if (offsetParent && offsetParent.getStyle('position') === 'fixed')
2557
+ offsetParent.setStyle({ zoom: 1 });
2558
+ element.setStyle({ position: 'relative' });
2559
+ var value = proceed(element);
2560
+ element.setStyle({ position: position });
2561
+ return value;
2562
+ }
2563
+ );
2564
+ });
2565
+
2566
+ Element.Methods.cumulativeOffset = Element.Methods.cumulativeOffset.wrap(
2567
+ function(proceed, element) {
2568
+ try { element.offsetParent }
2569
+ catch(e) { return Element._returnOffset(0,0) }
2570
+ return proceed(element);
2571
+ }
2572
+ );
2573
+
2574
+ Element.Methods.getStyle = function(element, style) {
2575
+ element = $(element);
2576
+ style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
2577
+ var value = element.style[style];
2578
+ if (!value && element.currentStyle) value = element.currentStyle[style];
2579
+
2580
+ if (style == 'opacity') {
2581
+ if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
2582
+ if (value[1]) return parseFloat(value[1]) / 100;
2583
+ return 1.0;
2584
+ }
2585
+
2586
+ if (value == 'auto') {
2587
+ if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
2588
+ return element['offset' + style.capitalize()] + 'px';
2589
+ return null;
2590
+ }
2591
+ return value;
2592
+ };
2593
+
2594
+ Element.Methods.setOpacity = function(element, value) {
2595
+ function stripAlpha(filter){
2596
+ return filter.replace(/alpha\([^\)]*\)/gi,'');
2597
+ }
2598
+ element = $(element);
2599
+ var currentStyle = element.currentStyle;
2600
+ if ((currentStyle && !currentStyle.hasLayout) ||
2601
+ (!currentStyle && element.style.zoom == 'normal'))
2602
+ element.style.zoom = 1;
2603
+
2604
+ var filter = element.getStyle('filter'), style = element.style;
2605
+ if (value == 1 || value === '') {
2606
+ (filter = stripAlpha(filter)) ?
2607
+ style.filter = filter : style.removeAttribute('filter');
2608
+ return element;
2609
+ } else if (value < 0.00001) value = 0;
2610
+ style.filter = stripAlpha(filter) +
2611
+ 'alpha(opacity=' + (value * 100) + ')';
2612
+ return element;
2613
+ };
2614
+
2615
+ Element._attributeTranslations = (function(){
2616
+
2617
+ var classProp = 'className';
2618
+ var forProp = 'for';
2619
+
2620
+ var el = document.createElement('div');
2621
+
2622
+ el.setAttribute(classProp, 'x');
2623
+
2624
+ if (el.className !== 'x') {
2625
+ el.setAttribute('class', 'x');
2626
+ if (el.className === 'x') {
2627
+ classProp = 'class';
2628
+ }
2629
+ }
2630
+ el = null;
2631
+
2632
+ el = document.createElement('label');
2633
+ el.setAttribute(forProp, 'x');
2634
+ if (el.htmlFor !== 'x') {
2635
+ el.setAttribute('htmlFor', 'x');
2636
+ if (el.htmlFor === 'x') {
2637
+ forProp = 'htmlFor';
2638
+ }
2639
+ }
2640
+ el = null;
2641
+
2642
+ return {
2643
+ read: {
2644
+ names: {
2645
+ 'class': classProp,
2646
+ 'className': classProp,
2647
+ 'for': forProp,
2648
+ 'htmlFor': forProp
2649
+ },
2650
+ values: {
2651
+ _getAttr: function(element, attribute) {
2652
+ return element.getAttribute(attribute, 2);
2653
+ },
2654
+ _getAttrNode: function(element, attribute) {
2655
+ var node = element.getAttributeNode(attribute);
2656
+ return node ? node.value : "";
2657
+ },
2658
+ _getEv: (function(){
2659
+
2660
+ var el = document.createElement('div');
2661
+ el.onclick = Prototype.emptyFunction;
2662
+ var value = el.getAttribute('onclick');
2663
+ var f;
2664
+
2665
+ if (String(value).indexOf('{') > -1) {
2666
+ f = function(element, attribute) {
2667
+ attribute = element.getAttribute(attribute);
2668
+ if (!attribute) return null;
2669
+ attribute = attribute.toString();
2670
+ attribute = attribute.split('{')[1];
2671
+ attribute = attribute.split('}')[0];
2672
+ return attribute.strip();
2673
+ }
2674
+ }
2675
+ else if (value === '') {
2676
+ f = function(element, attribute) {
2677
+ attribute = element.getAttribute(attribute);
2678
+ if (!attribute) return null;
2679
+ return attribute.strip();
2680
+ }
2681
+ }
2682
+ el = null;
2683
+ return f;
2684
+ })(),
2685
+ _flag: function(element, attribute) {
2686
+ return $(element).hasAttribute(attribute) ? attribute : null;
2687
+ },
2688
+ style: function(element) {
2689
+ return element.style.cssText.toLowerCase();
2690
+ },
2691
+ title: function(element) {
2692
+ return element.title;
2693
+ }
2694
+ }
2695
+ }
2696
+ }
2697
+ })();
2698
+
2699
+ Element._attributeTranslations.write = {
2700
+ names: Object.extend({
2701
+ cellpadding: 'cellPadding',
2702
+ cellspacing: 'cellSpacing'
2703
+ }, Element._attributeTranslations.read.names),
2704
+ values: {
2705
+ checked: function(element, value) {
2706
+ element.checked = !!value;
2707
+ },
2708
+
2709
+ style: function(element, value) {
2710
+ element.style.cssText = value ? value : '';
2711
+ }
2712
+ }
2713
+ };
2714
+
2715
+ Element._attributeTranslations.has = {};
2716
+
2717
+ $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
2718
+ 'encType maxLength readOnly longDesc frameBorder').each(function(attr) {
2719
+ Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
2720
+ Element._attributeTranslations.has[attr.toLowerCase()] = attr;
2721
+ });
2722
+
2723
+ (function(v) {
2724
+ Object.extend(v, {
2725
+ href: v._getAttr,
2726
+ src: v._getAttr,
2727
+ type: v._getAttr,
2728
+ action: v._getAttrNode,
2729
+ disabled: v._flag,
2730
+ checked: v._flag,
2731
+ readonly: v._flag,
2732
+ multiple: v._flag,
2733
+ onload: v._getEv,
2734
+ onunload: v._getEv,
2735
+ onclick: v._getEv,
2736
+ ondblclick: v._getEv,
2737
+ onmousedown: v._getEv,
2738
+ onmouseup: v._getEv,
2739
+ onmouseover: v._getEv,
2740
+ onmousemove: v._getEv,
2741
+ onmouseout: v._getEv,
2742
+ onfocus: v._getEv,
2743
+ onblur: v._getEv,
2744
+ onkeypress: v._getEv,
2745
+ onkeydown: v._getEv,
2746
+ onkeyup: v._getEv,
2747
+ onsubmit: v._getEv,
2748
+ onreset: v._getEv,
2749
+ onselect: v._getEv,
2750
+ onchange: v._getEv
2751
+ });
2752
+ })(Element._attributeTranslations.read.values);
2753
+
2754
+ if (Prototype.BrowserFeatures.ElementExtensions) {
2755
+ (function() {
2756
+ function _descendants(element) {
2757
+ var nodes = element.getElementsByTagName('*'), results = [];
2758
+ for (var i = 0, node; node = nodes[i]; i++)
2759
+ if (node.tagName !== "!") // Filter out comment nodes.
2760
+ results.push(node);
2761
+ return results;
2762
+ }
2763
+
2764
+ Element.Methods.down = function(element, expression, index) {
2765
+ element = $(element);
2766
+ if (arguments.length == 1) return element.firstDescendant();
2767
+ return Object.isNumber(expression) ? _descendants(element)[expression] :
2768
+ Element.select(element, expression)[index || 0];
2769
+ }
2770
+ })();
2771
+ }
2772
+
2773
+ }
2774
+
2775
+ else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {
2776
+ Element.Methods.setOpacity = function(element, value) {
2777
+ element = $(element);
2778
+ element.style.opacity = (value == 1) ? 0.999999 :
2779
+ (value === '') ? '' : (value < 0.00001) ? 0 : value;
2780
+ return element;
2781
+ };
2782
+ }
2783
+
2784
+ else if (Prototype.Browser.WebKit) {
2785
+ Element.Methods.setOpacity = function(element, value) {
2786
+ element = $(element);
2787
+ element.style.opacity = (value == 1 || value === '') ? '' :
2788
+ (value < 0.00001) ? 0 : value;
2789
+
2790
+ if (value == 1)
2791
+ if(element.tagName.toUpperCase() == 'IMG' && element.width) {
2792
+ element.width++; element.width--;
2793
+ } else try {
2794
+ var n = document.createTextNode(' ');
2795
+ element.appendChild(n);
2796
+ element.removeChild(n);
2797
+ } catch (e) { }
2798
+
2799
+ return element;
2800
+ };
2801
+
2802
+ Element.Methods.cumulativeOffset = function(element) {
2803
+ var valueT = 0, valueL = 0;
2804
+ do {
2805
+ valueT += element.offsetTop || 0;
2806
+ valueL += element.offsetLeft || 0;
2807
+ if (element.offsetParent == document.body)
2808
+ if (Element.getStyle(element, 'position') == 'absolute') break;
2809
+
2810
+ element = element.offsetParent;
2811
+ } while (element);
2812
+
2813
+ return Element._returnOffset(valueL, valueT);
2814
+ };
2815
+ }
2816
+
2817
+ if ('outerHTML' in document.documentElement) {
2818
+ Element.Methods.replace = function(element, content) {
2819
+ element = $(element);
2820
+
2821
+ if (content && content.toElement) content = content.toElement();
2822
+ if (Object.isElement(content)) {
2823
+ element.parentNode.replaceChild(content, element);
2824
+ return element;
2825
+ }
2826
+
2827
+ content = Object.toHTML(content);
2828
+ var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
2829
+
2830
+ if (Element._insertionTranslations.tags[tagName]) {
2831
+ var nextSibling = element.next();
2832
+ var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
2833
+ parent.removeChild(element);
2834
+ if (nextSibling)
2835
+ fragments.each(function(node) { parent.insertBefore(node, nextSibling) });
2836
+ else
2837
+ fragments.each(function(node) { parent.appendChild(node) });
2838
+ }
2839
+ else element.outerHTML = content.stripScripts();
2840
+
2841
+ content.evalScripts.bind(content).defer();
2842
+ return element;
2843
+ };
2844
+ }
2845
+
2846
+ Element._returnOffset = function(l, t) {
2847
+ var result = [l, t];
2848
+ result.left = l;
2849
+ result.top = t;
2850
+ return result;
2851
+ };
2852
+
2853
+ Element._getContentFromAnonymousElement = function(tagName, html) {
2854
+ var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];
2855
+ if (t) {
2856
+ div.innerHTML = t[0] + html + t[1];
2857
+ t[2].times(function() { div = div.firstChild });
2858
+ } else div.innerHTML = html;
2859
+ return $A(div.childNodes);
2860
+ };
2861
+
2862
+ Element._insertionTranslations = {
2863
+ before: function(element, node) {
2864
+ element.parentNode.insertBefore(node, element);
2865
+ },
2866
+ top: function(element, node) {
2867
+ element.insertBefore(node, element.firstChild);
2868
+ },
2869
+ bottom: function(element, node) {
2870
+ element.appendChild(node);
2871
+ },
2872
+ after: function(element, node) {
2873
+ element.parentNode.insertBefore(node, element.nextSibling);
2874
+ },
2875
+ tags: {
2876
+ TABLE: ['<table>', '</table>', 1],
2877
+ TBODY: ['<table><tbody>', '</tbody></table>', 2],
2878
+ TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],
2879
+ TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
2880
+ SELECT: ['<select>', '</select>', 1]
2881
+ }
2882
+ };
2883
+
2884
+ (function() {
2885
+ Object.extend(this.tags, {
2886
+ THEAD: this.tags.TBODY,
2887
+ TFOOT: this.tags.TBODY,
2888
+ TH: this.tags.TD
2889
+ });
2890
+ }).call(Element._insertionTranslations);
2891
+
2892
+ Element.Methods.Simulated = {
2893
+ hasAttribute: function(element, attribute) {
2894
+ attribute = Element._attributeTranslations.has[attribute] || attribute;
2895
+ var node = $(element).getAttributeNode(attribute);
2896
+ return !!(node && node.specified);
2897
+ }
2898
+ };
2899
+
2900
+ Element.Methods.ByTag = { };
2901
+
2902
+ Object.extend(Element, Element.Methods);
2903
+
2904
+ (function(div) {
2905
+
2906
+ if (!Prototype.BrowserFeatures.ElementExtensions && div['__proto__']) {
2907
+ window.HTMLElement = { };
2908
+ window.HTMLElement.prototype = div['__proto__'];
2909
+ Prototype.BrowserFeatures.ElementExtensions = true;
2910
+ }
2911
+
2912
+ div = null;
2913
+
2914
+ })(document.createElement('div'))
2915
+
2916
+ Element.extend = (function() {
2917
+
2918
+ function checkDeficiency(tagName) {
2919
+ if (typeof window.Element != 'undefined') {
2920
+ var proto = window.Element.prototype;
2921
+ if (proto) {
2922
+ var id = '_' + (Math.random()+'').slice(2);
2923
+ var el = document.createElement(tagName);
2924
+ proto[id] = 'x';
2925
+ var isBuggy = (el[id] !== 'x');
2926
+ delete proto[id];
2927
+ el = null;
2928
+ return isBuggy;
2929
+ }
2930
+ }
2931
+ return false;
2932
+ }
2933
+
2934
+ function extendElementWith(element, methods) {
2935
+ for (var property in methods) {
2936
+ var value = methods[property];
2937
+ if (Object.isFunction(value) && !(property in element))
2938
+ element[property] = value.methodize();
2939
+ }
2940
+ }
2941
+
2942
+ var HTMLOBJECTELEMENT_PROTOTYPE_BUGGY = checkDeficiency('object');
2943
+ var HTMLAPPLETELEMENT_PROTOTYPE_BUGGY = checkDeficiency('applet');
2944
+
2945
+ if (Prototype.BrowserFeatures.SpecificElementExtensions) {
2946
+ if (HTMLOBJECTELEMENT_PROTOTYPE_BUGGY &&
2947
+ HTMLAPPLETELEMENT_PROTOTYPE_BUGGY) {
2948
+ return function(element) {
2949
+ if (element && element.tagName) {
2950
+ var tagName = element.tagName.toUpperCase();
2951
+ if (tagName === 'OBJECT' || tagName === 'APPLET') {
2952
+ extendElementWith(element, Element.Methods);
2953
+ if (tagName === 'OBJECT') {
2954
+ extendElementWith(element, Element.Methods.ByTag.OBJECT)
2955
+ }
2956
+ else if (tagName === 'APPLET') {
2957
+ extendElementWith(element, Element.Methods.ByTag.APPLET)
2958
+ }
2959
+ }
2960
+ }
2961
+ return element;
2962
+ }
2963
+ }
2964
+ return Prototype.K;
2965
+ }
2966
+
2967
+ var Methods = { }, ByTag = Element.Methods.ByTag;
2968
+
2969
+ var extend = Object.extend(function(element) {
2970
+ if (!element || typeof element._extendedByPrototype != 'undefined' ||
2971
+ element.nodeType != 1 || element == window) return element;
2972
+
2973
+ var methods = Object.clone(Methods),
2974
+ tagName = element.tagName.toUpperCase();
2975
+
2976
+ if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
2977
+
2978
+ extendElementWith(element, methods);
2979
+
2980
+ element._extendedByPrototype = Prototype.emptyFunction;
2981
+ return element;
2982
+
2983
+ }, {
2984
+ refresh: function() {
2985
+ if (!Prototype.BrowserFeatures.ElementExtensions) {
2986
+ Object.extend(Methods, Element.Methods);
2987
+ Object.extend(Methods, Element.Methods.Simulated);
2988
+ }
2989
+ }
2990
+ });
2991
+
2992
+ extend.refresh();
2993
+ return extend;
2994
+ })();
2995
+
2996
+ Element.hasAttribute = function(element, attribute) {
2997
+ if (element.hasAttribute) return element.hasAttribute(attribute);
2998
+ return Element.Methods.Simulated.hasAttribute(element, attribute);
2999
+ };
3000
+
3001
+ Element.addMethods = function(methods) {
3002
+ var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
3003
+
3004
+ if (!methods) {
3005
+ Object.extend(Form, Form.Methods);
3006
+ Object.extend(Form.Element, Form.Element.Methods);
3007
+ Object.extend(Element.Methods.ByTag, {
3008
+ "FORM": Object.clone(Form.Methods),
3009
+ "INPUT": Object.clone(Form.Element.Methods),
3010
+ "SELECT": Object.clone(Form.Element.Methods),
3011
+ "TEXTAREA": Object.clone(Form.Element.Methods)
3012
+ });
3013
+ }
3014
+
3015
+ if (arguments.length == 2) {
3016
+ var tagName = methods;
3017
+ methods = arguments[1];
3018
+ }
3019
+
3020
+ if (!tagName) Object.extend(Element.Methods, methods || { });
3021
+ else {
3022
+ if (Object.isArray(tagName)) tagName.each(extend);
3023
+ else extend(tagName);
3024
+ }
3025
+
3026
+ function extend(tagName) {
3027
+ tagName = tagName.toUpperCase();
3028
+ if (!Element.Methods.ByTag[tagName])
3029
+ Element.Methods.ByTag[tagName] = { };
3030
+ Object.extend(Element.Methods.ByTag[tagName], methods);
3031
+ }
3032
+
3033
+ function copy(methods, destination, onlyIfAbsent) {
3034
+ onlyIfAbsent = onlyIfAbsent || false;
3035
+ for (var property in methods) {
3036
+ var value = methods[property];
3037
+ if (!Object.isFunction(value)) continue;
3038
+ if (!onlyIfAbsent || !(property in destination))
3039
+ destination[property] = value.methodize();
3040
+ }
3041
+ }
3042
+
3043
+ function findDOMClass(tagName) {
3044
+ var klass;
3045
+ var trans = {
3046
+ "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
3047
+ "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
3048
+ "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
3049
+ "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
3050
+ "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
3051
+ "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
3052
+ "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
3053
+ "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
3054
+ "FrameSet", "IFRAME": "IFrame"
3055
+ };
3056
+ if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
3057
+ if (window[klass]) return window[klass];
3058
+ klass = 'HTML' + tagName + 'Element';
3059
+ if (window[klass]) return window[klass];
3060
+ klass = 'HTML' + tagName.capitalize() + 'Element';
3061
+ if (window[klass]) return window[klass];
3062
+
3063
+ var element = document.createElement(tagName);
3064
+ var proto = element['__proto__'] || element.constructor.prototype;
3065
+ element = null;
3066
+ return proto;
3067
+ }
3068
+
3069
+ var elementPrototype = window.HTMLElement ? HTMLElement.prototype :
3070
+ Element.prototype;
3071
+
3072
+ if (F.ElementExtensions) {
3073
+ copy(Element.Methods, elementPrototype);
3074
+ copy(Element.Methods.Simulated, elementPrototype, true);
3075
+ }
3076
+
3077
+ if (F.SpecificElementExtensions) {
3078
+ for (var tag in Element.Methods.ByTag) {
3079
+ var klass = findDOMClass(tag);
3080
+ if (Object.isUndefined(klass)) continue;
3081
+ copy(T[tag], klass.prototype);
3082
+ }
3083
+ }
3084
+
3085
+ Object.extend(Element, Element.Methods);
3086
+ delete Element.ByTag;
3087
+
3088
+ if (Element.extend.refresh) Element.extend.refresh();
3089
+ Element.cache = { };
3090
+ };
3091
+
3092
+
3093
+ document.viewport = {
3094
+
3095
+ getDimensions: function() {
3096
+ return { width: this.getWidth(), height: this.getHeight() };
3097
+ },
3098
+
3099
+ getScrollOffsets: function() {
3100
+ return Element._returnOffset(
3101
+ window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
3102
+ window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
3103
+ }
3104
+ };
3105
+
3106
+ (function(viewport) {
3107
+ var B = Prototype.Browser, doc = document, element, property = {};
3108
+
3109
+ function getRootElement() {
3110
+ if (B.WebKit && !doc.evaluate)
3111
+ return document;
3112
+
3113
+ if (B.Opera && window.parseFloat(window.opera.version()) < 9.5)
3114
+ return document.body;
3115
+
3116
+ return document.documentElement;
3117
+ }
3118
+
3119
+ function define(D) {
3120
+ if (!element) element = getRootElement();
3121
+
3122
+ property[D] = 'client' + D;
3123
+
3124
+ viewport['get' + D] = function() { return element[property[D]] };
3125
+ return viewport['get' + D]();
3126
+ }
3127
+
3128
+ viewport.getWidth = define.curry('Width');
3129
+
3130
+ viewport.getHeight = define.curry('Height');
3131
+ })(document.viewport);
3132
+
3133
+
3134
+ Element.Storage = {
3135
+ UID: 1
3136
+ };
3137
+
3138
+ Element.addMethods({
3139
+ getStorage: function(element) {
3140
+ if (!(element = $(element))) return;
3141
+
3142
+ var uid;
3143
+ if (element === window) {
3144
+ uid = 0;
3145
+ } else {
3146
+ if (typeof element._prototypeUID === "undefined")
3147
+ element._prototypeUID = [Element.Storage.UID++];
3148
+ uid = element._prototypeUID[0];
3149
+ }
3150
+
3151
+ if (!Element.Storage[uid])
3152
+ Element.Storage[uid] = $H();
3153
+
3154
+ return Element.Storage[uid];
3155
+ },
3156
+
3157
+ store: function(element, key, value) {
3158
+ if (!(element = $(element))) return;
3159
+
3160
+ if (arguments.length === 2) {
3161
+ element.getStorage().update(key);
3162
+ } else {
3163
+ element.getStorage().set(key, value);
3164
+ }
3165
+
3166
+ return element;
3167
+ },
3168
+
3169
+ retrieve: function(element, key, defaultValue) {
3170
+ if (!(element = $(element))) return;
3171
+ var hash = Element.getStorage(element), value = hash.get(key);
3172
+
3173
+ if (Object.isUndefined(value)) {
3174
+ hash.set(key, defaultValue);
3175
+ value = defaultValue;
3176
+ }
3177
+
3178
+ return value;
3179
+ },
3180
+
3181
+ clone: function(element, deep) {
3182
+ if (!(element = $(element))) return;
3183
+ var clone = element.cloneNode(deep);
3184
+ clone._prototypeUID = void 0;
3185
+ if (deep) {
3186
+ var descendants = Element.select(clone, '*'),
3187
+ i = descendants.length;
3188
+ while (i--) {
3189
+ descendants[i]._prototypeUID = void 0;
3190
+ }
3191
+ }
3192
+ return Element.extend(clone);
3193
+ }
3194
+ });
3195
+ /* Portions of the Selector class are derived from Jack Slocum's DomQuery,
3196
+ * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
3197
+ * license. Please see http://www.yui-ext.com/ for more information. */
3198
+
3199
+ var Selector = Class.create({
3200
+ initialize: function(expression) {
3201
+ this.expression = expression.strip();
3202
+
3203
+ if (this.shouldUseSelectorsAPI()) {
3204
+ this.mode = 'selectorsAPI';
3205
+ } else if (this.shouldUseXPath()) {
3206
+ this.mode = 'xpath';
3207
+ this.compileXPathMatcher();
3208
+ } else {
3209
+ this.mode = "normal";
3210
+ this.compileMatcher();
3211
+ }
3212
+
3213
+ },
3214
+
3215
+ shouldUseXPath: (function() {
3216
+
3217
+ var IS_DESCENDANT_SELECTOR_BUGGY = (function(){
3218
+ var isBuggy = false;
3219
+ if (document.evaluate && window.XPathResult) {
3220
+ var el = document.createElement('div');
3221
+ el.innerHTML = '<ul><li></li></ul><div><ul><li></li></ul></div>';
3222
+
3223
+ var xpath = ".//*[local-name()='ul' or local-name()='UL']" +
3224
+ "//*[local-name()='li' or local-name()='LI']";
3225
+
3226
+ var result = document.evaluate(xpath, el, null,
3227
+ XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
3228
+
3229
+ isBuggy = (result.snapshotLength !== 2);
3230
+ el = null;
3231
+ }
3232
+ return isBuggy;
3233
+ })();
3234
+
3235
+ return function() {
3236
+ if (!Prototype.BrowserFeatures.XPath) return false;
3237
+
3238
+ var e = this.expression;
3239
+
3240
+ if (Prototype.Browser.WebKit &&
3241
+ (e.include("-of-type") || e.include(":empty")))
3242
+ return false;
3243
+
3244
+ if ((/(\[[\w-]*?:|:checked)/).test(e))
3245
+ return false;
3246
+
3247
+ if (IS_DESCENDANT_SELECTOR_BUGGY) return false;
3248
+
3249
+ return true;
3250
+ }
3251
+
3252
+ })(),
3253
+
3254
+ shouldUseSelectorsAPI: function() {
3255
+ if (!Prototype.BrowserFeatures.SelectorsAPI) return false;
3256
+
3257
+ if (Selector.CASE_INSENSITIVE_CLASS_NAMES) return false;
3258
+
3259
+ if (!Selector._div) Selector._div = new Element('div');
3260
+
3261
+ try {
3262
+ Selector._div.querySelector(this.expression);
3263
+ } catch(e) {
3264
+ return false;
3265
+ }
3266
+
3267
+ return true;
3268
+ },
3269
+
3270
+ compileMatcher: function() {
3271
+ var e = this.expression, ps = Selector.patterns, h = Selector.handlers,
3272
+ c = Selector.criteria, le, p, m, len = ps.length, name;
3273
+
3274
+ if (Selector._cache[e]) {
3275
+ this.matcher = Selector._cache[e];
3276
+ return;
3277
+ }
3278
+
3279
+ this.matcher = ["this.matcher = function(root) {",
3280
+ "var r = root, h = Selector.handlers, c = false, n;"];
3281
+
3282
+ while (e && le != e && (/\S/).test(e)) {
3283
+ le = e;
3284
+ for (var i = 0; i<len; i++) {
3285
+ p = ps[i].re;
3286
+ name = ps[i].name;
3287
+ if (m = e.match(p)) {
3288
+ this.matcher.push(Object.isFunction(c[name]) ? c[name](m) :
3289
+ new Template(c[name]).evaluate(m));
3290
+ e = e.replace(m[0], '');
3291
+ break;
3292
+ }
3293
+ }
3294
+ }
3295
+
3296
+ this.matcher.push("return h.unique(n);\n}");
3297
+ eval(this.matcher.join('\n'));
3298
+ Selector._cache[this.expression] = this.matcher;
3299
+ },
3300
+
3301
+ compileXPathMatcher: function() {
3302
+ var e = this.expression, ps = Selector.patterns,
3303
+ x = Selector.xpath, le, m, len = ps.length, name;
3304
+
3305
+ if (Selector._cache[e]) {
3306
+ this.xpath = Selector._cache[e]; return;
3307
+ }
3308
+
3309
+ this.matcher = ['.//*'];
3310
+ while (e && le != e && (/\S/).test(e)) {
3311
+ le = e;
3312
+ for (var i = 0; i<len; i++) {
3313
+ name = ps[i].name;
3314
+ if (m = e.match(ps[i].re)) {
3315
+ this.matcher.push(Object.isFunction(x[name]) ? x[name](m) :
3316
+ new Template(x[name]).evaluate(m));
3317
+ e = e.replace(m[0], '');
3318
+ break;
3319
+ }
3320
+ }
3321
+ }
3322
+
3323
+ this.xpath = this.matcher.join('');
3324
+ Selector._cache[this.expression] = this.xpath;
3325
+ },
3326
+
3327
+ findElements: function(root) {
3328
+ root = root || document;
3329
+ var e = this.expression, results;
3330
+
3331
+ switch (this.mode) {
3332
+ case 'selectorsAPI':
3333
+ if (root !== document) {
3334
+ var oldId = root.id, id = $(root).identify();
3335
+ id = id.replace(/[\.:]/g, "\\$0");
3336
+ e = "#" + id + " " + e;
3337
+ }
3338
+
3339
+ results = $A(root.querySelectorAll(e)).map(Element.extend);
3340
+ root.id = oldId;
3341
+
3342
+ return results;
3343
+ case 'xpath':
3344
+ return document._getElementsByXPath(this.xpath, root);
3345
+ default:
3346
+ return this.matcher(root);
3347
+ }
3348
+ },
3349
+
3350
+ match: function(element) {
3351
+ this.tokens = [];
3352
+
3353
+ var e = this.expression, ps = Selector.patterns, as = Selector.assertions;
3354
+ var le, p, m, len = ps.length, name;
3355
+
3356
+ while (e && le !== e && (/\S/).test(e)) {
3357
+ le = e;
3358
+ for (var i = 0; i<len; i++) {
3359
+ p = ps[i].re;
3360
+ name = ps[i].name;
3361
+ if (m = e.match(p)) {
3362
+ if (as[name]) {
3363
+ this.tokens.push([name, Object.clone(m)]);
3364
+ e = e.replace(m[0], '');
3365
+ } else {
3366
+ return this.findElements(document).include(element);
3367
+ }
3368
+ }
3369
+ }
3370
+ }
3371
+
3372
+ var match = true, name, matches;
3373
+ for (var i = 0, token; token = this.tokens[i]; i++) {
3374
+ name = token[0], matches = token[1];
3375
+ if (!Selector.assertions[name](element, matches)) {
3376
+ match = false; break;
3377
+ }
3378
+ }
3379
+
3380
+ return match;
3381
+ },
3382
+
3383
+ toString: function() {
3384
+ return this.expression;
3385
+ },
3386
+
3387
+ inspect: function() {
3388
+ return "#<Selector:" + this.expression.inspect() + ">";
3389
+ }
3390
+ });
3391
+
3392
+ if (Prototype.BrowserFeatures.SelectorsAPI &&
3393
+ document.compatMode === 'BackCompat') {
3394
+ Selector.CASE_INSENSITIVE_CLASS_NAMES = (function(){
3395
+ var div = document.createElement('div'),
3396
+ span = document.createElement('span');
3397
+
3398
+ div.id = "prototype_test_id";
3399
+ span.className = 'Test';
3400
+ div.appendChild(span);
3401
+ var isIgnored = (div.querySelector('#prototype_test_id .test') !== null);
3402
+ div = span = null;
3403
+ return isIgnored;
3404
+ })();
3405
+ }
3406
+
3407
+ Object.extend(Selector, {
3408
+ _cache: { },
3409
+
3410
+ xpath: {
3411
+ descendant: "//*",
3412
+ child: "/*",
3413
+ adjacent: "/following-sibling::*[1]",
3414
+ laterSibling: '/following-sibling::*',
3415
+ tagName: function(m) {
3416
+ if (m[1] == '*') return '';
3417
+ return "[local-name()='" + m[1].toLowerCase() +
3418
+ "' or local-name()='" + m[1].toUpperCase() + "']";
3419
+ },
3420
+ className: "[contains(concat(' ', @class, ' '), ' #{1} ')]",
3421
+ id: "[@id='#{1}']",
3422
+ attrPresence: function(m) {
3423
+ m[1] = m[1].toLowerCase();
3424
+ return new Template("[@#{1}]").evaluate(m);
3425
+ },
3426
+ attr: function(m) {
3427
+ m[1] = m[1].toLowerCase();
3428
+ m[3] = m[5] || m[6];
3429
+ return new Template(Selector.xpath.operators[m[2]]).evaluate(m);
3430
+ },
3431
+ pseudo: function(m) {
3432
+ var h = Selector.xpath.pseudos[m[1]];
3433
+ if (!h) return '';
3434
+ if (Object.isFunction(h)) return h(m);
3435
+ return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m);
3436
+ },
3437
+ operators: {
3438
+ '=': "[@#{1}='#{3}']",
3439
+ '!=': "[@#{1}!='#{3}']",
3440
+ '^=': "[starts-with(@#{1}, '#{3}')]",
3441
+ '$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']",
3442
+ '*=': "[contains(@#{1}, '#{3}')]",
3443
+ '~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]",
3444
+ '|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]"
3445
+ },
3446
+ pseudos: {
3447
+ 'first-child': '[not(preceding-sibling::*)]',
3448
+ 'last-child': '[not(following-sibling::*)]',
3449
+ 'only-child': '[not(preceding-sibling::* or following-sibling::*)]',
3450
+ 'empty': "[count(*) = 0 and (count(text()) = 0)]",
3451
+ 'checked': "[@checked]",
3452
+ 'disabled': "[(@disabled) and (@type!='hidden')]",
3453
+ 'enabled': "[not(@disabled) and (@type!='hidden')]",
3454
+ 'not': function(m) {
3455
+ var e = m[6], p = Selector.patterns,
3456
+ x = Selector.xpath, le, v, len = p.length, name;
3457
+
3458
+ var exclusion = [];
3459
+ while (e && le != e && (/\S/).test(e)) {
3460
+ le = e;
3461
+ for (var i = 0; i<len; i++) {
3462
+ name = p[i].name
3463
+ if (m = e.match(p[i].re)) {
3464
+ v = Object.isFunction(x[name]) ? x[name](m) : new Template(x[name]).evaluate(m);
3465
+ exclusion.push("(" + v.substring(1, v.length - 1) + ")");
3466
+ e = e.replace(m[0], '');
3467
+ break;
3468
+ }
3469
+ }
3470
+ }
3471
+ return "[not(" + exclusion.join(" and ") + ")]";
3472
+ },
3473
+ 'nth-child': function(m) {
3474
+ return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m);
3475
+ },
3476
+ 'nth-last-child': function(m) {
3477
+ return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m);
3478
+ },
3479
+ 'nth-of-type': function(m) {
3480
+ return Selector.xpath.pseudos.nth("position() ", m);
3481
+ },
3482
+ 'nth-last-of-type': function(m) {
3483
+ return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m);
3484
+ },
3485
+ 'first-of-type': function(m) {
3486
+ m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m);
3487
+ },
3488
+ 'last-of-type': function(m) {
3489
+ m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m);
3490
+ },
3491
+ 'only-of-type': function(m) {
3492
+ var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m);
3493
+ },
3494
+ nth: function(fragment, m) {
3495
+ var mm, formula = m[6], predicate;
3496
+ if (formula == 'even') formula = '2n+0';
3497
+ if (formula == 'odd') formula = '2n+1';
3498
+ if (mm = formula.match(/^(\d+)$/)) // digit only
3499
+ return '[' + fragment + "= " + mm[1] + ']';
3500
+ if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
3501
+ if (mm[1] == "-") mm[1] = -1;
3502
+ var a = mm[1] ? Number(mm[1]) : 1;
3503
+ var b = mm[2] ? Number(mm[2]) : 0;
3504
+ predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " +
3505
+ "((#{fragment} - #{b}) div #{a} >= 0)]";
3506
+ return new Template(predicate).evaluate({
3507
+ fragment: fragment, a: a, b: b });
3508
+ }
3509
+ }
3510
+ }
3511
+ },
3512
+
3513
+ criteria: {
3514
+ tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;',
3515
+ className: 'n = h.className(n, r, "#{1}", c); c = false;',
3516
+ id: 'n = h.id(n, r, "#{1}", c); c = false;',
3517
+ attrPresence: 'n = h.attrPresence(n, r, "#{1}", c); c = false;',
3518
+ attr: function(m) {
3519
+ m[3] = (m[5] || m[6]);
3520
+ return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;').evaluate(m);
3521
+ },
3522
+ pseudo: function(m) {
3523
+ if (m[6]) m[6] = m[6].replace(/"/g, '\\"');
3524
+ return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m);
3525
+ },
3526
+ descendant: 'c = "descendant";',
3527
+ child: 'c = "child";',
3528
+ adjacent: 'c = "adjacent";',
3529
+ laterSibling: 'c = "laterSibling";'
3530
+ },
3531
+
3532
+ patterns: [
3533
+ { name: 'laterSibling', re: /^\s*~\s*/ },
3534
+ { name: 'child', re: /^\s*>\s*/ },
3535
+ { name: 'adjacent', re: /^\s*\+\s*/ },
3536
+ { name: 'descendant', re: /^\s/ },
3537
+
3538
+ { name: 'tagName', re: /^\s*(\*|[\w\-]+)(\b|$)?/ },
3539
+ { name: 'id', re: /^#([\w\-\*]+)(\b|$)/ },
3540
+ { name: 'className', re: /^\.([\w\-\*]+)(\b|$)/ },
3541
+ { name: 'pseudo', re: /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/ },
3542
+ { name: 'attrPresence', re: /^\[((?:[\w-]+:)?[\w-]+)\]/ },
3543
+ { name: 'attr', re: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/ }
3544
+ ],
3545
+
3546
+ assertions: {
3547
+ tagName: function(element, matches) {
3548
+ return matches[1].toUpperCase() == element.tagName.toUpperCase();
3549
+ },
3550
+
3551
+ className: function(element, matches) {
3552
+ return Element.hasClassName(element, matches[1]);
3553
+ },
3554
+
3555
+ id: function(element, matches) {
3556
+ return element.id === matches[1];
3557
+ },
3558
+
3559
+ attrPresence: function(element, matches) {
3560
+ return Element.hasAttribute(element, matches[1]);
3561
+ },
3562
+
3563
+ attr: function(element, matches) {
3564
+ var nodeValue = Element.readAttribute(element, matches[1]);
3565
+ return nodeValue && Selector.operators[matches[2]](nodeValue, matches[5] || matches[6]);
3566
+ }
3567
+ },
3568
+
3569
+ handlers: {
3570
+ concat: function(a, b) {
3571
+ for (var i = 0, node; node = b[i]; i++)
3572
+ a.push(node);
3573
+ return a;
3574
+ },
3575
+
3576
+ mark: function(nodes) {
3577
+ var _true = Prototype.emptyFunction;
3578
+ for (var i = 0, node; node = nodes[i]; i++)
3579
+ node._countedByPrototype = _true;
3580
+ return nodes;
3581
+ },
3582
+
3583
+ unmark: function(nodes) {
3584
+ for (var i = 0, node; node = nodes[i]; i++)
3585
+ node._countedByPrototype = undefined;
3586
+ return nodes;
3587
+ },
3588
+
3589
+ index: function(parentNode, reverse, ofType) {
3590
+ parentNode._countedByPrototype = Prototype.emptyFunction;
3591
+ if (reverse) {
3592
+ for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
3593
+ var node = nodes[i];
3594
+ if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
3595
+ }
3596
+ } else {
3597
+ for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
3598
+ if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
3599
+ }
3600
+ },
3601
+
3602
+ unique: function(nodes) {
3603
+ if (nodes.length == 0) return nodes;
3604
+ var results = [], n;
3605
+ for (var i = 0, l = nodes.length; i < l; i++)
3606
+ if (typeof (n = nodes[i])._countedByPrototype == 'undefined') {
3607
+ n._countedByPrototype = Prototype.emptyFunction;
3608
+ results.push(Element.extend(n));
3609
+ }
3610
+ return Selector.handlers.unmark(results);
3611
+ },
3612
+
3613
+ descendant: function(nodes) {
3614
+ var h = Selector.handlers;
3615
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
3616
+ h.concat(results, node.getElementsByTagName('*'));
3617
+ return results;
3618
+ },
3619
+
3620
+ child: function(nodes) {
3621
+ var h = Selector.handlers;
3622
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
3623
+ for (var j = 0, child; child = node.childNodes[j]; j++)
3624
+ if (child.nodeType == 1 && child.tagName != '!') results.push(child);
3625
+ }
3626
+ return results;
3627
+ },
3628
+
3629
+ adjacent: function(nodes) {
3630
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
3631
+ var next = this.nextElementSibling(node);
3632
+ if (next) results.push(next);
3633
+ }
3634
+ return results;
3635
+ },
3636
+
3637
+ laterSibling: function(nodes) {
3638
+ var h = Selector.handlers;
3639
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
3640
+ h.concat(results, Element.nextSiblings(node));
3641
+ return results;
3642
+ },
3643
+
3644
+ nextElementSibling: function(node) {
3645
+ while (node = node.nextSibling)
3646
+ if (node.nodeType == 1) return node;
3647
+ return null;
3648
+ },
3649
+
3650
+ previousElementSibling: function(node) {
3651
+ while (node = node.previousSibling)
3652
+ if (node.nodeType == 1) return node;
3653
+ return null;
3654
+ },
3655
+
3656
+ tagName: function(nodes, root, tagName, combinator) {
3657
+ var uTagName = tagName.toUpperCase();
3658
+ var results = [], h = Selector.handlers;
3659
+ if (nodes) {
3660
+ if (combinator) {
3661
+ if (combinator == "descendant") {
3662
+ for (var i = 0, node; node = nodes[i]; i++)
3663
+ h.concat(results, node.getElementsByTagName(tagName));
3664
+ return results;
3665
+ } else nodes = this[combinator](nodes);
3666
+ if (tagName == "*") return nodes;
3667
+ }
3668
+ for (var i = 0, node; node = nodes[i]; i++)
3669
+ if (node.tagName.toUpperCase() === uTagName) results.push(node);
3670
+ return results;
3671
+ } else return root.getElementsByTagName(tagName);
3672
+ },
3673
+
3674
+ id: function(nodes, root, id, combinator) {
3675
+ var targetNode = $(id), h = Selector.handlers;
3676
+
3677
+ if (root == document) {
3678
+ if (!targetNode) return [];
3679
+ if (!nodes) return [targetNode];
3680
+ } else {
3681
+ if (!root.sourceIndex || root.sourceIndex < 1) {
3682
+ var nodes = root.getElementsByTagName('*');
3683
+ for (var j = 0, node; node = nodes[j]; j++) {
3684
+ if (node.id === id) return [node];
3685
+ }
3686
+ }
3687
+ }
3688
+
3689
+ if (nodes) {
3690
+ if (combinator) {
3691
+ if (combinator == 'child') {
3692
+ for (var i = 0, node; node = nodes[i]; i++)
3693
+ if (targetNode.parentNode == node) return [targetNode];
3694
+ } else if (combinator == 'descendant') {
3695
+ for (var i = 0, node; node = nodes[i]; i++)
3696
+ if (Element.descendantOf(targetNode, node)) return [targetNode];
3697
+ } else if (combinator == 'adjacent') {
3698
+ for (var i = 0, node; node = nodes[i]; i++)
3699
+ if (Selector.handlers.previousElementSibling(targetNode) == node)
3700
+ return [targetNode];
3701
+ } else nodes = h[combinator](nodes);
3702
+ }
3703
+ for (var i = 0, node; node = nodes[i]; i++)
3704
+ if (node == targetNode) return [targetNode];
3705
+ return [];
3706
+ }
3707
+ return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : [];
3708
+ },
3709
+
3710
+ className: function(nodes, root, className, combinator) {
3711
+ if (nodes && combinator) nodes = this[combinator](nodes);
3712
+ return Selector.handlers.byClassName(nodes, root, className);
3713
+ },
3714
+
3715
+ byClassName: function(nodes, root, className) {
3716
+ if (!nodes) nodes = Selector.handlers.descendant([root]);
3717
+ var needle = ' ' + className + ' ';
3718
+ for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) {
3719
+ nodeClassName = node.className;
3720
+ if (nodeClassName.length == 0) continue;
3721
+ if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle))
3722
+ results.push(node);
3723
+ }
3724
+ return results;
3725
+ },
3726
+
3727
+ attrPresence: function(nodes, root, attr, combinator) {
3728
+ if (!nodes) nodes = root.getElementsByTagName("*");
3729
+ if (nodes && combinator) nodes = this[combinator](nodes);
3730
+ var results = [];
3731
+ for (var i = 0, node; node = nodes[i]; i++)
3732
+ if (Element.hasAttribute(node, attr)) results.push(node);
3733
+ return results;
3734
+ },
3735
+
3736
+ attr: function(nodes, root, attr, value, operator, combinator) {
3737
+ if (!nodes) nodes = root.getElementsByTagName("*");
3738
+ if (nodes && combinator) nodes = this[combinator](nodes);
3739
+ var handler = Selector.operators[operator], results = [];
3740
+ for (var i = 0, node; node = nodes[i]; i++) {
3741
+ var nodeValue = Element.readAttribute(node, attr);
3742
+ if (nodeValue === null) continue;
3743
+ if (handler(nodeValue, value)) results.push(node);
3744
+ }
3745
+ return results;
3746
+ },
3747
+
3748
+ pseudo: function(nodes, name, value, root, combinator) {
3749
+ if (nodes && combinator) nodes = this[combinator](nodes);
3750
+ if (!nodes) nodes = root.getElementsByTagName("*");
3751
+ return Selector.pseudos[name](nodes, value, root);
3752
+ }
3753
+ },
3754
+
3755
+ pseudos: {
3756
+ 'first-child': function(nodes, value, root) {
3757
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
3758
+ if (Selector.handlers.previousElementSibling(node)) continue;
3759
+ results.push(node);
3760
+ }
3761
+ return results;
3762
+ },
3763
+ 'last-child': function(nodes, value, root) {
3764
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
3765
+ if (Selector.handlers.nextElementSibling(node)) continue;
3766
+ results.push(node);
3767
+ }
3768
+ return results;
3769
+ },
3770
+ 'only-child': function(nodes, value, root) {
3771
+ var h = Selector.handlers;
3772
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
3773
+ if (!h.previousElementSibling(node) && !h.nextElementSibling(node))
3774
+ results.push(node);
3775
+ return results;
3776
+ },
3777
+ 'nth-child': function(nodes, formula, root) {
3778
+ return Selector.pseudos.nth(nodes, formula, root);
3779
+ },
3780
+ 'nth-last-child': function(nodes, formula, root) {
3781
+ return Selector.pseudos.nth(nodes, formula, root, true);
3782
+ },
3783
+ 'nth-of-type': function(nodes, formula, root) {
3784
+ return Selector.pseudos.nth(nodes, formula, root, false, true);
3785
+ },
3786
+ 'nth-last-of-type': function(nodes, formula, root) {
3787
+ return Selector.pseudos.nth(nodes, formula, root, true, true);
3788
+ },
3789
+ 'first-of-type': function(nodes, formula, root) {
3790
+ return Selector.pseudos.nth(nodes, "1", root, false, true);
3791
+ },
3792
+ 'last-of-type': function(nodes, formula, root) {
3793
+ return Selector.pseudos.nth(nodes, "1", root, true, true);
3794
+ },
3795
+ 'only-of-type': function(nodes, formula, root) {
3796
+ var p = Selector.pseudos;
3797
+ return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root);
3798
+ },
3799
+
3800
+ getIndices: function(a, b, total) {
3801
+ if (a == 0) return b > 0 ? [b] : [];
3802
+ return $R(1, total).inject([], function(memo, i) {
3803
+ if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i);
3804
+ return memo;
3805
+ });
3806
+ },
3807
+
3808
+ nth: function(nodes, formula, root, reverse, ofType) {
3809
+ if (nodes.length == 0) return [];
3810
+ if (formula == 'even') formula = '2n+0';
3811
+ if (formula == 'odd') formula = '2n+1';
3812
+ var h = Selector.handlers, results = [], indexed = [], m;
3813
+ h.mark(nodes);
3814
+ for (var i = 0, node; node = nodes[i]; i++) {
3815
+ if (!node.parentNode._countedByPrototype) {
3816
+ h.index(node.parentNode, reverse, ofType);
3817
+ indexed.push(node.parentNode);
3818
+ }
3819
+ }
3820
+ if (formula.match(/^\d+$/)) { // just a number
3821
+ formula = Number(formula);
3822
+ for (var i = 0, node; node = nodes[i]; i++)
3823
+ if (node.nodeIndex == formula) results.push(node);
3824
+ } else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
3825
+ if (m[1] == "-") m[1] = -1;
3826
+ var a = m[1] ? Number(m[1]) : 1;
3827
+ var b = m[2] ? Number(m[2]) : 0;
3828
+ var indices = Selector.pseudos.getIndices(a, b, nodes.length);
3829
+ for (var i = 0, node, l = indices.length; node = nodes[i]; i++) {
3830
+ for (var j = 0; j < l; j++)
3831
+ if (node.nodeIndex == indices[j]) results.push(node);
3832
+ }
3833
+ }
3834
+ h.unmark(nodes);
3835
+ h.unmark(indexed);
3836
+ return results;
3837
+ },
3838
+
3839
+ 'empty': function(nodes, value, root) {
3840
+ for (var i = 0, results = [], node; node = nodes[i]; i++) {
3841
+ if (node.tagName == '!' || node.firstChild) continue;
3842
+ results.push(node);
3843
+ }
3844
+ return results;
3845
+ },
3846
+
3847
+ 'not': function(nodes, selector, root) {
3848
+ var h = Selector.handlers, selectorType, m;
3849
+ var exclusions = new Selector(selector).findElements(root);
3850
+ h.mark(exclusions);
3851
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
3852
+ if (!node._countedByPrototype) results.push(node);
3853
+ h.unmark(exclusions);
3854
+ return results;
3855
+ },
3856
+
3857
+ 'enabled': function(nodes, value, root) {
3858
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
3859
+ if (!node.disabled && (!node.type || node.type !== 'hidden'))
3860
+ results.push(node);
3861
+ return results;
3862
+ },
3863
+
3864
+ 'disabled': function(nodes, value, root) {
3865
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
3866
+ if (node.disabled) results.push(node);
3867
+ return results;
3868
+ },
3869
+
3870
+ 'checked': function(nodes, value, root) {
3871
+ for (var i = 0, results = [], node; node = nodes[i]; i++)
3872
+ if (node.checked) results.push(node);
3873
+ return results;
3874
+ }
3875
+ },
3876
+
3877
+ operators: {
3878
+ '=': function(nv, v) { return nv == v; },
3879
+ '!=': function(nv, v) { return nv != v; },
3880
+ '^=': function(nv, v) { return nv == v || nv && nv.startsWith(v); },
3881
+ '$=': function(nv, v) { return nv == v || nv && nv.endsWith(v); },
3882
+ '*=': function(nv, v) { return nv == v || nv && nv.include(v); },
3883
+ '~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); },
3884
+ '|=': function(nv, v) { return ('-' + (nv || "").toUpperCase() +
3885
+ '-').include('-' + (v || "").toUpperCase() + '-'); }
3886
+ },
3887
+
3888
+ split: function(expression) {
3889
+ var expressions = [];
3890
+ expression.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
3891
+ expressions.push(m[1].strip());
3892
+ });
3893
+ return expressions;
3894
+ },
3895
+
3896
+ matchElements: function(elements, expression) {
3897
+ var matches = $$(expression), h = Selector.handlers;
3898
+ h.mark(matches);
3899
+ for (var i = 0, results = [], element; element = elements[i]; i++)
3900
+ if (element._countedByPrototype) results.push(element);
3901
+ h.unmark(matches);
3902
+ return results;
3903
+ },
3904
+
3905
+ findElement: function(elements, expression, index) {
3906
+ if (Object.isNumber(expression)) {
3907
+ index = expression; expression = false;
3908
+ }
3909
+ return Selector.matchElements(elements, expression || '*')[index || 0];
3910
+ },
3911
+
3912
+ findChildElements: function(element, expressions) {
3913
+ expressions = Selector.split(expressions.join(','));
3914
+ var results = [], h = Selector.handlers;
3915
+ for (var i = 0, l = expressions.length, selector; i < l; i++) {
3916
+ selector = new Selector(expressions[i].strip());
3917
+ h.concat(results, selector.findElements(element));
3918
+ }
3919
+ return (l > 1) ? h.unique(results) : results;
3920
+ }
3921
+ });
3922
+
3923
+ if (Prototype.Browser.IE) {
3924
+ Object.extend(Selector.handlers, {
3925
+ concat: function(a, b) {
3926
+ for (var i = 0, node; node = b[i]; i++)
3927
+ if (node.tagName !== "!") a.push(node);
3928
+ return a;
3929
+ },
3930
+
3931
+ unmark: function(nodes) {
3932
+ for (var i = 0, node; node = nodes[i]; i++)
3933
+ node.removeAttribute('_countedByPrototype');
3934
+ return nodes;
3935
+ }
3936
+ });
3937
+ }
3938
+
3939
+ function $$() {
3940
+ return Selector.findChildElements(document, $A(arguments));
3941
+ }
3942
+
3943
+ var Form = {
3944
+ reset: function(form) {
3945
+ form = $(form);
3946
+ form.reset();
3947
+ return form;
3948
+ },
3949
+
3950
+ serializeElements: function(elements, options) {
3951
+ if (typeof options != 'object') options = { hash: !!options };
3952
+ else if (Object.isUndefined(options.hash)) options.hash = true;
3953
+ var key, value, submitted = false, submit = options.submit;
3954
+
3955
+ var data = elements.inject({ }, function(result, element) {
3956
+ if (!element.disabled && element.name) {
3957
+ key = element.name; value = $(element).getValue();
3958
+ if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted &&
3959
+ submit !== false && (!submit || key == submit) && (submitted = true)))) {
3960
+ if (key in result) {
3961
+ if (!Object.isArray(result[key])) result[key] = [result[key]];
3962
+ result[key].push(value);
3963
+ }
3964
+ else result[key] = value;
3965
+ }
3966
+ }
3967
+ return result;
3968
+ });
3969
+
3970
+ return options.hash ? data : Object.toQueryString(data);
3971
+ }
3972
+ };
3973
+
3974
+ Form.Methods = {
3975
+ serialize: function(form, options) {
3976
+ return Form.serializeElements(Form.getElements(form), options);
3977
+ },
3978
+
3979
+ getElements: function(form) {
3980
+ var elements = $(form).getElementsByTagName('*'),
3981
+ element,
3982
+ arr = [ ],
3983
+ serializers = Form.Element.Serializers;
3984
+ for (var i = 0; element = elements[i]; i++) {
3985
+ arr.push(element);
3986
+ }
3987
+ return arr.inject([], function(elements, child) {
3988
+ if (serializers[child.tagName.toLowerCase()])
3989
+ elements.push(Element.extend(child));
3990
+ return elements;
3991
+ })
3992
+ },
3993
+
3994
+ getInputs: function(form, typeName, name) {
3995
+ form = $(form);
3996
+ var inputs = form.getElementsByTagName('input');
3997
+
3998
+ if (!typeName && !name) return $A(inputs).map(Element.extend);
3999
+
4000
+ for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
4001
+ var input = inputs[i];
4002
+ if ((typeName && input.type != typeName) || (name && input.name != name))
4003
+ continue;
4004
+ matchingInputs.push(Element.extend(input));
4005
+ }
4006
+
4007
+ return matchingInputs;
4008
+ },
4009
+
4010
+ disable: function(form) {
4011
+ form = $(form);
4012
+ Form.getElements(form).invoke('disable');
4013
+ return form;
4014
+ },
4015
+
4016
+ enable: function(form) {
4017
+ form = $(form);
4018
+ Form.getElements(form).invoke('enable');
4019
+ return form;
4020
+ },
4021
+
4022
+ findFirstElement: function(form) {
4023
+ var elements = $(form).getElements().findAll(function(element) {
4024
+ return 'hidden' != element.type && !element.disabled;
4025
+ });
4026
+ var firstByIndex = elements.findAll(function(element) {
4027
+ return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
4028
+ }).sortBy(function(element) { return element.tabIndex }).first();
4029
+
4030
+ return firstByIndex ? firstByIndex : elements.find(function(element) {
4031
+ return ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
4032
+ });
4033
+ },
4034
+
4035
+ focusFirstElement: function(form) {
4036
+ form = $(form);
4037
+ form.findFirstElement().activate();
4038
+ return form;
4039
+ },
4040
+
4041
+ request: function(form, options) {
4042
+ form = $(form), options = Object.clone(options || { });
4043
+
4044
+ var params = options.parameters, action = form.readAttribute('action') || '';
4045
+ if (action.blank()) action = window.location.href;
4046
+ options.parameters = form.serialize(true);
4047
+
4048
+ if (params) {
4049
+ if (Object.isString(params)) params = params.toQueryParams();
4050
+ Object.extend(options.parameters, params);
4051
+ }
4052
+
4053
+ if (form.hasAttribute('method') && !options.method)
4054
+ options.method = form.method;
4055
+
4056
+ return new Ajax.Request(action, options);
4057
+ }
4058
+ };
4059
+
4060
+ /*--------------------------------------------------------------------------*/
4061
+
4062
+
4063
+ Form.Element = {
4064
+ focus: function(element) {
4065
+ $(element).focus();
4066
+ return element;
4067
+ },
4068
+
4069
+ select: function(element) {
4070
+ $(element).select();
4071
+ return element;
4072
+ }
4073
+ };
4074
+
4075
+ Form.Element.Methods = {
4076
+
4077
+ serialize: function(element) {
4078
+ element = $(element);
4079
+ if (!element.disabled && element.name) {
4080
+ var value = element.getValue();
4081
+ if (value != undefined) {
4082
+ var pair = { };
4083
+ pair[element.name] = value;
4084
+ return Object.toQueryString(pair);
4085
+ }
4086
+ }
4087
+ return '';
4088
+ },
4089
+
4090
+ getValue: function(element) {
4091
+ element = $(element);
4092
+ var method = element.tagName.toLowerCase();
4093
+ return Form.Element.Serializers[method](element);
4094
+ },
4095
+
4096
+ setValue: function(element, value) {
4097
+ element = $(element);
4098
+ var method = element.tagName.toLowerCase();
4099
+ Form.Element.Serializers[method](element, value);
4100
+ return element;
4101
+ },
4102
+
4103
+ clear: function(element) {
4104
+ $(element).value = '';
4105
+ return element;
4106
+ },
4107
+
4108
+ present: function(element) {
4109
+ return $(element).value != '';
4110
+ },
4111
+
4112
+ activate: function(element) {
4113
+ element = $(element);
4114
+ try {
4115
+ element.focus();
4116
+ if (element.select && (element.tagName.toLowerCase() != 'input' ||
4117
+ !['button', 'reset', 'submit'].include(element.type)))
4118
+ element.select();
4119
+ } catch (e) { }
4120
+ return element;
4121
+ },
4122
+
4123
+ disable: function(element) {
4124
+ element = $(element);
4125
+ element.disabled = true;
4126
+ return element;
4127
+ },
4128
+
4129
+ enable: function(element) {
4130
+ element = $(element);
4131
+ element.disabled = false;
4132
+ return element;
4133
+ }
4134
+ };
4135
+
4136
+ /*--------------------------------------------------------------------------*/
4137
+
4138
+ var Field = Form.Element;
4139
+
4140
+ var $F = Form.Element.Methods.getValue;
4141
+
4142
+ /*--------------------------------------------------------------------------*/
4143
+
4144
+ Form.Element.Serializers = {
4145
+ input: function(element, value) {
4146
+ switch (element.type.toLowerCase()) {
4147
+ case 'checkbox':
4148
+ case 'radio':
4149
+ return Form.Element.Serializers.inputSelector(element, value);
4150
+ default:
4151
+ return Form.Element.Serializers.textarea(element, value);
4152
+ }
4153
+ },
4154
+
4155
+ inputSelector: function(element, value) {
4156
+ if (Object.isUndefined(value)) return element.checked ? element.value : null;
4157
+ else element.checked = !!value;
4158
+ },
4159
+
4160
+ textarea: function(element, value) {
4161
+ if (Object.isUndefined(value)) return element.value;
4162
+ else element.value = value;
4163
+ },
4164
+
4165
+ select: function(element, value) {
4166
+ if (Object.isUndefined(value))
4167
+ return this[element.type == 'select-one' ?
4168
+ 'selectOne' : 'selectMany'](element);
4169
+ else {
4170
+ var opt, currentValue, single = !Object.isArray(value);
4171
+ for (var i = 0, length = element.length; i < length; i++) {
4172
+ opt = element.options[i];
4173
+ currentValue = this.optionValue(opt);
4174
+ if (single) {
4175
+ if (currentValue == value) {
4176
+ opt.selected = true;
4177
+ return;
4178
+ }
4179
+ }
4180
+ else opt.selected = value.include(currentValue);
4181
+ }
4182
+ }
4183
+ },
4184
+
4185
+ selectOne: function(element) {
4186
+ var index = element.selectedIndex;
4187
+ return index >= 0 ? this.optionValue(element.options[index]) : null;
4188
+ },
4189
+
4190
+ selectMany: function(element) {
4191
+ var values, length = element.length;
4192
+ if (!length) return null;
4193
+
4194
+ for (var i = 0, values = []; i < length; i++) {
4195
+ var opt = element.options[i];
4196
+ if (opt.selected) values.push(this.optionValue(opt));
4197
+ }
4198
+ return values;
4199
+ },
4200
+
4201
+ optionValue: function(opt) {
4202
+ return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;
4203
+ }
4204
+ };
4205
+
4206
+ /*--------------------------------------------------------------------------*/
4207
+
4208
+
4209
+ Abstract.TimedObserver = Class.create(PeriodicalExecuter, {
4210
+ initialize: function($super, element, frequency, callback) {
4211
+ $super(callback, frequency);
4212
+ this.element = $(element);
4213
+ this.lastValue = this.getValue();
4214
+ },
4215
+
4216
+ execute: function() {
4217
+ var value = this.getValue();
4218
+ if (Object.isString(this.lastValue) && Object.isString(value) ?
4219
+ this.lastValue != value : String(this.lastValue) != String(value)) {
4220
+ this.callback(this.element, value);
4221
+ this.lastValue = value;
4222
+ }
4223
+ }
4224
+ });
4225
+
4226
+ Form.Element.Observer = Class.create(Abstract.TimedObserver, {
4227
+ getValue: function() {
4228
+ return Form.Element.getValue(this.element);
4229
+ }
4230
+ });
4231
+
4232
+ Form.Observer = Class.create(Abstract.TimedObserver, {
4233
+ getValue: function() {
4234
+ return Form.serialize(this.element);
4235
+ }
4236
+ });
4237
+
4238
+ /*--------------------------------------------------------------------------*/
4239
+
4240
+ Abstract.EventObserver = Class.create({
4241
+ initialize: function(element, callback) {
4242
+ this.element = $(element);
4243
+ this.callback = callback;
4244
+
4245
+ this.lastValue = this.getValue();
4246
+ if (this.element.tagName.toLowerCase() == 'form')
4247
+ this.registerFormCallbacks();
4248
+ else
4249
+ this.registerCallback(this.element);
4250
+ },
4251
+
4252
+ onElementEvent: function() {
4253
+ var value = this.getValue();
4254
+ if (this.lastValue != value) {
4255
+ this.callback(this.element, value);
4256
+ this.lastValue = value;
4257
+ }
4258
+ },
4259
+
4260
+ registerFormCallbacks: function() {
4261
+ Form.getElements(this.element).each(this.registerCallback, this);
4262
+ },
4263
+
4264
+ registerCallback: function(element) {
4265
+ if (element.type) {
4266
+ switch (element.type.toLowerCase()) {
4267
+ case 'checkbox':
4268
+ case 'radio':
4269
+ Event.observe(element, 'click', this.onElementEvent.bind(this));
4270
+ break;
4271
+ default:
4272
+ Event.observe(element, 'change', this.onElementEvent.bind(this));
4273
+ break;
4274
+ }
4275
+ }
4276
+ }
4277
+ });
4278
+
4279
+ Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
4280
+ getValue: function() {
4281
+ return Form.Element.getValue(this.element);
4282
+ }
4283
+ });
4284
+
4285
+ Form.EventObserver = Class.create(Abstract.EventObserver, {
4286
+ getValue: function() {
4287
+ return Form.serialize(this.element);
4288
+ }
4289
+ });
4290
+ (function() {
4291
+
4292
+ var Event = {
4293
+ KEY_BACKSPACE: 8,
4294
+ KEY_TAB: 9,
4295
+ KEY_RETURN: 13,
4296
+ KEY_ESC: 27,
4297
+ KEY_LEFT: 37,
4298
+ KEY_UP: 38,
4299
+ KEY_RIGHT: 39,
4300
+ KEY_DOWN: 40,
4301
+ KEY_DELETE: 46,
4302
+ KEY_HOME: 36,
4303
+ KEY_END: 35,
4304
+ KEY_PAGEUP: 33,
4305
+ KEY_PAGEDOWN: 34,
4306
+ KEY_INSERT: 45,
4307
+
4308
+ cache: {}
4309
+ };
4310
+
4311
+ var docEl = document.documentElement;
4312
+ var MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED = 'onmouseenter' in docEl
4313
+ && 'onmouseleave' in docEl;
4314
+
4315
+ var _isButton;
4316
+ if (Prototype.Browser.IE) {
4317
+ var buttonMap = { 0: 1, 1: 4, 2: 2 };
4318
+ _isButton = function(event, code) {
4319
+ return event.button === buttonMap[code];
4320
+ };
4321
+ } else if (Prototype.Browser.WebKit) {
4322
+ _isButton = function(event, code) {
4323
+ switch (code) {
4324
+ case 0: return event.which == 1 && !event.metaKey;
4325
+ case 1: return event.which == 1 && event.metaKey;
4326
+ default: return false;
4327
+ }
4328
+ };
4329
+ } else {
4330
+ _isButton = function(event, code) {
4331
+ return event.which ? (event.which === code + 1) : (event.button === code);
4332
+ };
4333
+ }
4334
+
4335
+ function isLeftClick(event) { return _isButton(event, 0) }
4336
+
4337
+ function isMiddleClick(event) { return _isButton(event, 1) }
4338
+
4339
+ function isRightClick(event) { return _isButton(event, 2) }
4340
+
4341
+ function element(event) {
4342
+ event = Event.extend(event);
4343
+
4344
+ var node = event.target, type = event.type,
4345
+ currentTarget = event.currentTarget;
4346
+
4347
+ if (currentTarget && currentTarget.tagName) {
4348
+ if (type === 'load' || type === 'error' ||
4349
+ (type === 'click' && currentTarget.tagName.toLowerCase() === 'input'
4350
+ && currentTarget.type === 'radio'))
4351
+ node = currentTarget;
4352
+ }
4353
+
4354
+ if (node.nodeType == Node.TEXT_NODE)
4355
+ node = node.parentNode;
4356
+
4357
+ return Element.extend(node);
4358
+ }
4359
+
4360
+ function findElement(event, expression) {
4361
+ var element = Event.element(event);
4362
+ if (!expression) return element;
4363
+ var elements = [element].concat(element.ancestors());
4364
+ return Selector.findElement(elements, expression, 0);
4365
+ }
4366
+
4367
+ function pointer(event) {
4368
+ return { x: pointerX(event), y: pointerY(event) };
4369
+ }
4370
+
4371
+ function pointerX(event) {
4372
+ var docElement = document.documentElement,
4373
+ body = document.body || { scrollLeft: 0 };
4374
+
4375
+ return event.pageX || (event.clientX +
4376
+ (docElement.scrollLeft || body.scrollLeft) -
4377
+ (docElement.clientLeft || 0));
4378
+ }
4379
+
4380
+ function pointerY(event) {
4381
+ var docElement = document.documentElement,
4382
+ body = document.body || { scrollTop: 0 };
4383
+
4384
+ return event.pageY || (event.clientY +
4385
+ (docElement.scrollTop || body.scrollTop) -
4386
+ (docElement.clientTop || 0));
4387
+ }
4388
+
4389
+
4390
+ function stop(event) {
4391
+ Event.extend(event);
4392
+ event.preventDefault();
4393
+ event.stopPropagation();
4394
+
4395
+ event.stopped = true;
4396
+ }
4397
+
4398
+ Event.Methods = {
4399
+ isLeftClick: isLeftClick,
4400
+ isMiddleClick: isMiddleClick,
4401
+ isRightClick: isRightClick,
4402
+
4403
+ element: element,
4404
+ findElement: findElement,
4405
+
4406
+ pointer: pointer,
4407
+ pointerX: pointerX,
4408
+ pointerY: pointerY,
4409
+
4410
+ stop: stop
4411
+ };
4412
+
4413
+
4414
+ var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
4415
+ m[name] = Event.Methods[name].methodize();
4416
+ return m;
4417
+ });
4418
+
4419
+ if (Prototype.Browser.IE) {
4420
+ function _relatedTarget(event) {
4421
+ var element;
4422
+ switch (event.type) {
4423
+ case 'mouseover': element = event.fromElement; break;
4424
+ case 'mouseout': element = event.toElement; break;
4425
+ default: return null;
4426
+ }
4427
+ return Element.extend(element);
4428
+ }
4429
+
4430
+ Object.extend(methods, {
4431
+ stopPropagation: function() { this.cancelBubble = true },
4432
+ preventDefault: function() { this.returnValue = false },
4433
+ inspect: function() { return '[object Event]' }
4434
+ });
4435
+
4436
+ Event.extend = function(event, element) {
4437
+ if (!event) return false;
4438
+ if (event._extendedByPrototype) return event;
4439
+
4440
+ event._extendedByPrototype = Prototype.emptyFunction;
4441
+ var pointer = Event.pointer(event);
4442
+
4443
+ Object.extend(event, {
4444
+ target: event.srcElement || element,
4445
+ relatedTarget: _relatedTarget(event),
4446
+ pageX: pointer.x,
4447
+ pageY: pointer.y
4448
+ });
4449
+
4450
+ return Object.extend(event, methods);
4451
+ };
4452
+ } else {
4453
+ Event.prototype = window.Event.prototype || document.createEvent('HTMLEvents').__proto__;
4454
+ Object.extend(Event.prototype, methods);
4455
+ Event.extend = Prototype.K;
4456
+ }
4457
+
4458
+ function _createResponder(element, eventName, handler) {
4459
+ var registry = Element.retrieve(element, 'prototype_event_registry');
4460
+
4461
+ if (Object.isUndefined(registry)) {
4462
+ CACHE.push(element);
4463
+ registry = Element.retrieve(element, 'prototype_event_registry', $H());
4464
+ }
4465
+
4466
+ var respondersForEvent = registry.get(eventName);
4467
+ if (Object.isUndefined()) {
4468
+ respondersForEvent = [];
4469
+ registry.set(eventName, respondersForEvent);
4470
+ }
4471
+
4472
+ if (respondersForEvent.pluck('handler').include(handler)) return false;
4473
+
4474
+ var responder;
4475
+ if (eventName.include(":")) {
4476
+ responder = function(event) {
4477
+ if (Object.isUndefined(event.eventName))
4478
+ return false;
4479
+
4480
+ if (event.eventName !== eventName)
4481
+ return false;
4482
+
4483
+ Event.extend(event, element);
4484
+ handler.call(element, event);
4485
+ };
4486
+ } else {
4487
+ if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED &&
4488
+ (eventName === "mouseenter" || eventName === "mouseleave")) {
4489
+ if (eventName === "mouseenter" || eventName === "mouseleave") {
4490
+ responder = function(event) {
4491
+ Event.extend(event, element);
4492
+
4493
+ var parent = event.relatedTarget;
4494
+ while (parent && parent !== element) {
4495
+ try { parent = parent.parentNode; }
4496
+ catch(e) { parent = element; }
4497
+ }
4498
+
4499
+ if (parent === element) return;
4500
+
4501
+ handler.call(element, event);
4502
+ };
4503
+ }
4504
+ } else {
4505
+ responder = function(event) {
4506
+ Event.extend(event, element);
4507
+ handler.call(element, event);
4508
+ };
4509
+ }
4510
+ }
4511
+
4512
+ responder.handler = handler;
4513
+ respondersForEvent.push(responder);
4514
+ return responder;
4515
+ }
4516
+
4517
+ function _destroyCache() {
4518
+ for (var i = 0, length = CACHE.length; i < length; i++) {
4519
+ Event.stopObserving(CACHE[i]);
4520
+ CACHE[i] = null;
4521
+ }
4522
+ }
4523
+
4524
+ var CACHE = [];
4525
+
4526
+ if (Prototype.Browser.IE)
4527
+ window.attachEvent('onunload', _destroyCache);
4528
+
4529
+ if (Prototype.Browser.WebKit)
4530
+ window.addEventListener('unload', Prototype.emptyFunction, false);
4531
+
4532
+
4533
+ var _getDOMEventName = Prototype.K;
4534
+
4535
+ if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED) {
4536
+ _getDOMEventName = function(eventName) {
4537
+ var translations = { mouseenter: "mouseover", mouseleave: "mouseout" };
4538
+ return eventName in translations ? translations[eventName] : eventName;
4539
+ };
4540
+ }
4541
+
4542
+ function observe(element, eventName, handler) {
4543
+ element = $(element);
4544
+
4545
+ var responder = _createResponder(element, eventName, handler);
4546
+
4547
+ if (!responder) return element;
4548
+
4549
+ if (eventName.include(':')) {
4550
+ if (element.addEventListener)
4551
+ element.addEventListener("dataavailable", responder, false);
4552
+ else {
4553
+ element.attachEvent("ondataavailable", responder);
4554
+ element.attachEvent("onfilterchange", responder);
4555
+ }
4556
+ } else {
4557
+ var actualEventName = _getDOMEventName(eventName);
4558
+
4559
+ if (element.addEventListener)
4560
+ element.addEventListener(actualEventName, responder, false);
4561
+ else
4562
+ element.attachEvent("on" + actualEventName, responder);
4563
+ }
4564
+
4565
+ return element;
4566
+ }
4567
+
4568
+ function stopObserving(element, eventName, handler) {
4569
+ element = $(element);
4570
+
4571
+ var registry = Element.retrieve(element, 'prototype_event_registry');
4572
+
4573
+ if (Object.isUndefined(registry)) return element;
4574
+
4575
+ if (eventName && !handler) {
4576
+ var responders = registry.get(eventName);
4577
+
4578
+ if (Object.isUndefined(responders)) return element;
4579
+
4580
+ responders.each( function(r) {
4581
+ Element.stopObserving(element, eventName, r.handler);
4582
+ });
4583
+ return element;
4584
+ } else if (!eventName) {
4585
+ registry.each( function(pair) {
4586
+ var eventName = pair.key, responders = pair.value;
4587
+
4588
+ responders.each( function(r) {
4589
+ Element.stopObserving(element, eventName, r.handler);
4590
+ });
4591
+ });
4592
+ return element;
4593
+ }
4594
+
4595
+ var responders = registry.get(eventName);
4596
+
4597
+ if (!responders) return;
4598
+
4599
+ var responder = responders.find( function(r) { return r.handler === handler; });
4600
+ if (!responder) return element;
4601
+
4602
+ var actualEventName = _getDOMEventName(eventName);
4603
+
4604
+ if (eventName.include(':')) {
4605
+ if (element.removeEventListener)
4606
+ element.removeEventListener("dataavailable", responder, false);
4607
+ else {
4608
+ element.detachEvent("ondataavailable", responder);
4609
+ element.detachEvent("onfilterchange", responder);
4610
+ }
4611
+ } else {
4612
+ if (element.removeEventListener)
4613
+ element.removeEventListener(actualEventName, responder, false);
4614
+ else
4615
+ element.detachEvent('on' + actualEventName, responder);
4616
+ }
4617
+
4618
+ registry.set(eventName, responders.without(responder));
4619
+
4620
+ return element;
4621
+ }
4622
+
4623
+ function fire(element, eventName, memo, bubble) {
4624
+ element = $(element);
4625
+
4626
+ if (Object.isUndefined(bubble))
4627
+ bubble = true;
4628
+
4629
+ if (element == document && document.createEvent && !element.dispatchEvent)
4630
+ element = document.documentElement;
4631
+
4632
+ var event;
4633
+ if (document.createEvent) {
4634
+ event = document.createEvent('HTMLEvents');
4635
+ event.initEvent('dataavailable', true, true);
4636
+ } else {
4637
+ event = document.createEventObject();
4638
+ event.eventType = bubble ? 'ondataavailable' : 'onfilterchange';
4639
+ }
4640
+
4641
+ event.eventName = eventName;
4642
+ event.memo = memo || { };
4643
+
4644
+ if (document.createEvent)
4645
+ element.dispatchEvent(event);
4646
+ else
4647
+ element.fireEvent(event.eventType, event);
4648
+
4649
+ return Event.extend(event);
4650
+ }
4651
+
4652
+
4653
+ Object.extend(Event, Event.Methods);
4654
+
4655
+ Object.extend(Event, {
4656
+ fire: fire,
4657
+ observe: observe,
4658
+ stopObserving: stopObserving
4659
+ });
4660
+
4661
+ Element.addMethods({
4662
+ fire: fire,
4663
+
4664
+ observe: observe,
4665
+
4666
+ stopObserving: stopObserving
4667
+ });
4668
+
4669
+ Object.extend(document, {
4670
+ fire: fire.methodize(),
4671
+
4672
+ observe: observe.methodize(),
4673
+
4674
+ stopObserving: stopObserving.methodize(),
4675
+
4676
+ loaded: false
4677
+ });
4678
+
4679
+ if (window.Event) Object.extend(window.Event, Event);
4680
+ else window.Event = Event;
4681
+ })();
4682
+
4683
+ (function() {
4684
+ /* Support for the DOMContentLoaded event is based on work by Dan Webb,
4685
+ Matthias Miller, Dean Edwards, John Resig, and Diego Perini. */
4686
+
4687
+ var timer;
4688
+
4689
+ function fireContentLoadedEvent() {
4690
+ if (document.loaded) return;
4691
+ if (timer) window.clearTimeout(timer);
4692
+ document.loaded = true;
4693
+ document.fire('dom:loaded');
4694
+ }
4695
+
4696
+ function checkReadyState() {
4697
+ if (document.readyState === 'complete') {
4698
+ document.stopObserving('readystatechange', checkReadyState);
4699
+ fireContentLoadedEvent();
4700
+ }
4701
+ }
4702
+
4703
+ function pollDoScroll() {
4704
+ try { document.documentElement.doScroll('left'); }
4705
+ catch(e) {
4706
+ timer = pollDoScroll.defer();
4707
+ return;
4708
+ }
4709
+ fireContentLoadedEvent();
4710
+ }
4711
+
4712
+ if (document.addEventListener) {
4713
+ document.addEventListener('DOMContentLoaded', fireContentLoadedEvent, false);
4714
+ } else {
4715
+ document.observe('readystatechange', checkReadyState);
4716
+ if (window == top)
4717
+ timer = pollDoScroll.defer();
4718
+ }
4719
+
4720
+ Event.observe(window, 'load', fireContentLoadedEvent);
4721
+ })();
4722
+
4723
+ Element.addMethods();
4724
+
4725
+ /*------------------------------- DEPRECATED -------------------------------*/
4726
+
4727
+ Hash.toQueryString = Object.toQueryString;
4728
+
4729
+ var Toggle = { display: Element.toggle };
4730
+
4731
+ Element.Methods.childOf = Element.Methods.descendantOf;
4732
+
4733
+ var Insertion = {
4734
+ Before: function(element, content) {
4735
+ return Element.insert(element, {before:content});
4736
+ },
4737
+
4738
+ Top: function(element, content) {
4739
+ return Element.insert(element, {top:content});
4740
+ },
4741
+
4742
+ Bottom: function(element, content) {
4743
+ return Element.insert(element, {bottom:content});
4744
+ },
4745
+
4746
+ After: function(element, content) {
4747
+ return Element.insert(element, {after:content});
4748
+ }
4749
+ };
4750
+
4751
+ var $continue = new Error('"throw $continue" is deprecated, use "return" instead');
4752
+
4753
+ var Position = {
4754
+ includeScrollOffsets: false,
4755
+
4756
+ prepare: function() {
4757
+ this.deltaX = window.pageXOffset
4758
+ || document.documentElement.scrollLeft
4759
+ || document.body.scrollLeft
4760
+ || 0;
4761
+ this.deltaY = window.pageYOffset
4762
+ || document.documentElement.scrollTop
4763
+ || document.body.scrollTop
4764
+ || 0;
4765
+ },
4766
+
4767
+ within: function(element, x, y) {
4768
+ if (this.includeScrollOffsets)
4769
+ return this.withinIncludingScrolloffsets(element, x, y);
4770
+ this.xcomp = x;
4771
+ this.ycomp = y;
4772
+ this.offset = Element.cumulativeOffset(element);
4773
+
4774
+ return (y >= this.offset[1] &&
4775
+ y < this.offset[1] + element.offsetHeight &&
4776
+ x >= this.offset[0] &&
4777
+ x < this.offset[0] + element.offsetWidth);
4778
+ },
4779
+
4780
+ withinIncludingScrolloffsets: function(element, x, y) {
4781
+ var offsetcache = Element.cumulativeScrollOffset(element);
4782
+
4783
+ this.xcomp = x + offsetcache[0] - this.deltaX;
4784
+ this.ycomp = y + offsetcache[1] - this.deltaY;
4785
+ this.offset = Element.cumulativeOffset(element);
4786
+
4787
+ return (this.ycomp >= this.offset[1] &&
4788
+ this.ycomp < this.offset[1] + element.offsetHeight &&
4789
+ this.xcomp >= this.offset[0] &&
4790
+ this.xcomp < this.offset[0] + element.offsetWidth);
4791
+ },
4792
+
4793
+ overlap: function(mode, element) {
4794
+ if (!mode) return 0;
4795
+ if (mode == 'vertical')
4796
+ return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
4797
+ element.offsetHeight;
4798
+ if (mode == 'horizontal')
4799
+ return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
4800
+ element.offsetWidth;
4801
+ },
4802
+
4803
+
4804
+ cumulativeOffset: Element.Methods.cumulativeOffset,
4805
+
4806
+ positionedOffset: Element.Methods.positionedOffset,
4807
+
4808
+ absolutize: function(element) {
4809
+ Position.prepare();
4810
+ return Element.absolutize(element);
4811
+ },
4812
+
4813
+ relativize: function(element) {
4814
+ Position.prepare();
4815
+ return Element.relativize(element);
4816
+ },
4817
+
4818
+ realOffset: Element.Methods.cumulativeScrollOffset,
4819
+
4820
+ offsetParent: Element.Methods.getOffsetParent,
4821
+
4822
+ page: Element.Methods.viewportOffset,
4823
+
4824
+ clone: function(source, target, options) {
4825
+ options = options || { };
4826
+ return Element.clonePosition(target, source, options);
4827
+ }
4828
+ };
4829
+
4830
+ /*--------------------------------------------------------------------------*/
4831
+
4832
+ if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
4833
+ function iter(name) {
4834
+ return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
4835
+ }
4836
+
4837
+ instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
4838
+ function(element, className) {
4839
+ className = className.toString().strip();
4840
+ var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
4841
+ return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
4842
+ } : function(element, className) {
4843
+ className = className.toString().strip();
4844
+ var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
4845
+ if (!classNames && !className) return elements;
4846
+
4847
+ var nodes = $(element).getElementsByTagName('*');
4848
+ className = ' ' + className + ' ';
4849
+
4850
+ for (var i = 0, child, cn; child = nodes[i]; i++) {
4851
+ if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
4852
+ (classNames && classNames.all(function(name) {
4853
+ return !name.toString().blank() && cn.include(' ' + name + ' ');
4854
+ }))))
4855
+ elements.push(Element.extend(child));
4856
+ }
4857
+ return elements;
4858
+ };
4859
+
4860
+ return function(className, parentElement) {
4861
+ return $(parentElement || document.body).getElementsByClassName(className);
4862
+ };
4863
+ }(Element.Methods);
4864
+
4865
+ /*--------------------------------------------------------------------------*/
4866
+
4867
+ Element.ClassNames = Class.create();
4868
+ Element.ClassNames.prototype = {
4869
+ initialize: function(element) {
4870
+ this.element = $(element);
4871
+ },
4872
+
4873
+ _each: function(iterator) {
4874
+ this.element.className.split(/\s+/).select(function(name) {
4875
+ return name.length > 0;
4876
+ })._each(iterator);
4877
+ },
4878
+
4879
+ set: function(className) {
4880
+ this.element.className = className;
4881
+ },
4882
+
4883
+ add: function(classNameToAdd) {
4884
+ if (this.include(classNameToAdd)) return;
4885
+ this.set($A(this).concat(classNameToAdd).join(' '));
4886
+ },
4887
+
4888
+ remove: function(classNameToRemove) {
4889
+ if (!this.include(classNameToRemove)) return;
4890
+ this.set($A(this).without(classNameToRemove).join(' '));
4891
+ },
4892
+
4893
+ toString: function() {
4894
+ return $A(this).join(' ');
4895
+ }
4896
+ };
4897
+
4898
+ Object.extend(Element.ClassNames.prototype, Enumerable);
4899
+
4900
+ /*--------------------------------------------------------------------------*/