interlock 1.0

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