Chris@441
|
1 /* Prototype JavaScript framework, version 1.7
|
Chris@441
|
2 * (c) 2005-2010 Sam Stephenson
|
Chris@0
|
3 *
|
Chris@0
|
4 * Prototype is freely distributable under the terms of an MIT-style license.
|
Chris@0
|
5 * For details, see the Prototype web site: http://www.prototypejs.org/
|
Chris@0
|
6 *
|
Chris@0
|
7 *--------------------------------------------------------------------------*/
|
Chris@0
|
8
|
Chris@0
|
9 var Prototype = {
|
Chris@441
|
10
|
Chris@441
|
11 Version: '1.7',
|
Chris@441
|
12
|
Chris@441
|
13 Browser: (function(){
|
Chris@441
|
14 var ua = navigator.userAgent;
|
Chris@441
|
15 var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
|
Chris@441
|
16 return {
|
Chris@441
|
17 IE: !!window.attachEvent && !isOpera,
|
Chris@441
|
18 Opera: isOpera,
|
Chris@441
|
19 WebKit: ua.indexOf('AppleWebKit/') > -1,
|
Chris@441
|
20 Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
|
Chris@441
|
21 MobileSafari: /Apple.*Mobile/.test(ua)
|
Chris@441
|
22 }
|
Chris@441
|
23 })(),
|
Chris@0
|
24
|
Chris@0
|
25 BrowserFeatures: {
|
Chris@0
|
26 XPath: !!document.evaluate,
|
Chris@441
|
27
|
Chris@0
|
28 SelectorsAPI: !!document.querySelector,
|
Chris@441
|
29
|
Chris@441
|
30 ElementExtensions: (function() {
|
Chris@441
|
31 var constructor = window.Element || window.HTMLElement;
|
Chris@441
|
32 return !!(constructor && constructor.prototype);
|
Chris@441
|
33 })(),
|
Chris@441
|
34 SpecificElementExtensions: (function() {
|
Chris@441
|
35 if (typeof window.HTMLDivElement !== 'undefined')
|
Chris@441
|
36 return true;
|
Chris@441
|
37
|
Chris@441
|
38 var div = document.createElement('div'),
|
Chris@441
|
39 form = document.createElement('form'),
|
Chris@441
|
40 isSupported = false;
|
Chris@441
|
41
|
Chris@441
|
42 if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) {
|
Chris@441
|
43 isSupported = true;
|
Chris@441
|
44 }
|
Chris@441
|
45
|
Chris@441
|
46 div = form = null;
|
Chris@441
|
47
|
Chris@441
|
48 return isSupported;
|
Chris@441
|
49 })()
|
Chris@0
|
50 },
|
Chris@0
|
51
|
Chris@0
|
52 ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
|
Chris@0
|
53 JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
|
Chris@0
|
54
|
Chris@0
|
55 emptyFunction: function() { },
|
Chris@441
|
56
|
Chris@0
|
57 K: function(x) { return x }
|
Chris@0
|
58 };
|
Chris@0
|
59
|
Chris@0
|
60 if (Prototype.Browser.MobileSafari)
|
Chris@0
|
61 Prototype.BrowserFeatures.SpecificElementExtensions = false;
|
Chris@0
|
62
|
Chris@0
|
63
|
Chris@0
|
64 var Abstract = { };
|
Chris@0
|
65
|
Chris@0
|
66
|
Chris@0
|
67 var Try = {
|
Chris@0
|
68 these: function() {
|
Chris@0
|
69 var returnValue;
|
Chris@0
|
70
|
Chris@0
|
71 for (var i = 0, length = arguments.length; i < length; i++) {
|
Chris@0
|
72 var lambda = arguments[i];
|
Chris@0
|
73 try {
|
Chris@0
|
74 returnValue = lambda();
|
Chris@0
|
75 break;
|
Chris@0
|
76 } catch (e) { }
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 return returnValue;
|
Chris@0
|
80 }
|
Chris@0
|
81 };
|
Chris@0
|
82
|
Chris@441
|
83 /* Based on Alex Arnell's inheritance implementation. */
|
Chris@441
|
84
|
Chris@441
|
85 var Class = (function() {
|
Chris@441
|
86
|
Chris@441
|
87 var IS_DONTENUM_BUGGY = (function(){
|
Chris@441
|
88 for (var p in { toString: 1 }) {
|
Chris@441
|
89 if (p === 'toString') return false;
|
Chris@441
|
90 }
|
Chris@441
|
91 return true;
|
Chris@441
|
92 })();
|
Chris@441
|
93
|
Chris@441
|
94 function subclass() {};
|
Chris@441
|
95 function create() {
|
Chris@441
|
96 var parent = null, properties = $A(arguments);
|
Chris@441
|
97 if (Object.isFunction(properties[0]))
|
Chris@441
|
98 parent = properties.shift();
|
Chris@441
|
99
|
Chris@441
|
100 function klass() {
|
Chris@441
|
101 this.initialize.apply(this, arguments);
|
Chris@441
|
102 }
|
Chris@441
|
103
|
Chris@441
|
104 Object.extend(klass, Class.Methods);
|
Chris@441
|
105 klass.superclass = parent;
|
Chris@441
|
106 klass.subclasses = [];
|
Chris@441
|
107
|
Chris@441
|
108 if (parent) {
|
Chris@441
|
109 subclass.prototype = parent.prototype;
|
Chris@441
|
110 klass.prototype = new subclass;
|
Chris@441
|
111 parent.subclasses.push(klass);
|
Chris@441
|
112 }
|
Chris@441
|
113
|
Chris@441
|
114 for (var i = 0, length = properties.length; i < length; i++)
|
Chris@441
|
115 klass.addMethods(properties[i]);
|
Chris@441
|
116
|
Chris@441
|
117 if (!klass.prototype.initialize)
|
Chris@441
|
118 klass.prototype.initialize = Prototype.emptyFunction;
|
Chris@441
|
119
|
Chris@441
|
120 klass.prototype.constructor = klass;
|
Chris@441
|
121 return klass;
|
Chris@441
|
122 }
|
Chris@441
|
123
|
Chris@441
|
124 function addMethods(source) {
|
Chris@441
|
125 var ancestor = this.superclass && this.superclass.prototype,
|
Chris@441
|
126 properties = Object.keys(source);
|
Chris@441
|
127
|
Chris@441
|
128 if (IS_DONTENUM_BUGGY) {
|
Chris@441
|
129 if (source.toString != Object.prototype.toString)
|
Chris@441
|
130 properties.push("toString");
|
Chris@441
|
131 if (source.valueOf != Object.prototype.valueOf)
|
Chris@441
|
132 properties.push("valueOf");
|
Chris@441
|
133 }
|
Chris@441
|
134
|
Chris@441
|
135 for (var i = 0, length = properties.length; i < length; i++) {
|
Chris@441
|
136 var property = properties[i], value = source[property];
|
Chris@441
|
137 if (ancestor && Object.isFunction(value) &&
|
Chris@441
|
138 value.argumentNames()[0] == "$super") {
|
Chris@441
|
139 var method = value;
|
Chris@441
|
140 value = (function(m) {
|
Chris@441
|
141 return function() { return ancestor[m].apply(this, arguments); };
|
Chris@441
|
142 })(property).wrap(method);
|
Chris@441
|
143
|
Chris@441
|
144 value.valueOf = method.valueOf.bind(method);
|
Chris@441
|
145 value.toString = method.toString.bind(method);
|
Chris@441
|
146 }
|
Chris@441
|
147 this.prototype[property] = value;
|
Chris@441
|
148 }
|
Chris@441
|
149
|
Chris@441
|
150 return this;
|
Chris@441
|
151 }
|
Chris@441
|
152
|
Chris@441
|
153 return {
|
Chris@441
|
154 create: create,
|
Chris@441
|
155 Methods: {
|
Chris@441
|
156 addMethods: addMethods
|
Chris@441
|
157 }
|
Chris@441
|
158 };
|
Chris@441
|
159 })();
|
Chris@441
|
160 (function() {
|
Chris@441
|
161
|
Chris@441
|
162 var _toString = Object.prototype.toString,
|
Chris@441
|
163 NULL_TYPE = 'Null',
|
Chris@441
|
164 UNDEFINED_TYPE = 'Undefined',
|
Chris@441
|
165 BOOLEAN_TYPE = 'Boolean',
|
Chris@441
|
166 NUMBER_TYPE = 'Number',
|
Chris@441
|
167 STRING_TYPE = 'String',
|
Chris@441
|
168 OBJECT_TYPE = 'Object',
|
Chris@441
|
169 FUNCTION_CLASS = '[object Function]',
|
Chris@441
|
170 BOOLEAN_CLASS = '[object Boolean]',
|
Chris@441
|
171 NUMBER_CLASS = '[object Number]',
|
Chris@441
|
172 STRING_CLASS = '[object String]',
|
Chris@441
|
173 ARRAY_CLASS = '[object Array]',
|
Chris@441
|
174 DATE_CLASS = '[object Date]',
|
Chris@441
|
175 NATIVE_JSON_STRINGIFY_SUPPORT = window.JSON &&
|
Chris@441
|
176 typeof JSON.stringify === 'function' &&
|
Chris@441
|
177 JSON.stringify(0) === '0' &&
|
Chris@441
|
178 typeof JSON.stringify(Prototype.K) === 'undefined';
|
Chris@441
|
179
|
Chris@441
|
180 function Type(o) {
|
Chris@441
|
181 switch(o) {
|
Chris@441
|
182 case null: return NULL_TYPE;
|
Chris@441
|
183 case (void 0): return UNDEFINED_TYPE;
|
Chris@441
|
184 }
|
Chris@441
|
185 var type = typeof o;
|
Chris@441
|
186 switch(type) {
|
Chris@441
|
187 case 'boolean': return BOOLEAN_TYPE;
|
Chris@441
|
188 case 'number': return NUMBER_TYPE;
|
Chris@441
|
189 case 'string': return STRING_TYPE;
|
Chris@441
|
190 }
|
Chris@441
|
191 return OBJECT_TYPE;
|
Chris@441
|
192 }
|
Chris@441
|
193
|
Chris@441
|
194 function extend(destination, source) {
|
Chris@441
|
195 for (var property in source)
|
Chris@441
|
196 destination[property] = source[property];
|
Chris@441
|
197 return destination;
|
Chris@441
|
198 }
|
Chris@441
|
199
|
Chris@441
|
200 function inspect(object) {
|
Chris@441
|
201 try {
|
Chris@441
|
202 if (isUndefined(object)) return 'undefined';
|
Chris@441
|
203 if (object === null) return 'null';
|
Chris@441
|
204 return object.inspect ? object.inspect() : String(object);
|
Chris@441
|
205 } catch (e) {
|
Chris@441
|
206 if (e instanceof RangeError) return '...';
|
Chris@441
|
207 throw e;
|
Chris@441
|
208 }
|
Chris@441
|
209 }
|
Chris@441
|
210
|
Chris@441
|
211 function toJSON(value) {
|
Chris@441
|
212 return Str('', { '': value }, []);
|
Chris@441
|
213 }
|
Chris@441
|
214
|
Chris@441
|
215 function Str(key, holder, stack) {
|
Chris@441
|
216 var value = holder[key],
|
Chris@441
|
217 type = typeof value;
|
Chris@441
|
218
|
Chris@441
|
219 if (Type(value) === OBJECT_TYPE && typeof value.toJSON === 'function') {
|
Chris@441
|
220 value = value.toJSON(key);
|
Chris@441
|
221 }
|
Chris@441
|
222
|
Chris@441
|
223 var _class = _toString.call(value);
|
Chris@441
|
224
|
Chris@441
|
225 switch (_class) {
|
Chris@441
|
226 case NUMBER_CLASS:
|
Chris@441
|
227 case BOOLEAN_CLASS:
|
Chris@441
|
228 case STRING_CLASS:
|
Chris@441
|
229 value = value.valueOf();
|
Chris@441
|
230 }
|
Chris@441
|
231
|
Chris@441
|
232 switch (value) {
|
Chris@441
|
233 case null: return 'null';
|
Chris@441
|
234 case true: return 'true';
|
Chris@441
|
235 case false: return 'false';
|
Chris@441
|
236 }
|
Chris@441
|
237
|
Chris@441
|
238 type = typeof value;
|
Chris@441
|
239 switch (type) {
|
Chris@441
|
240 case 'string':
|
Chris@441
|
241 return value.inspect(true);
|
Chris@441
|
242 case 'number':
|
Chris@441
|
243 return isFinite(value) ? String(value) : 'null';
|
Chris@441
|
244 case 'object':
|
Chris@441
|
245
|
Chris@441
|
246 for (var i = 0, length = stack.length; i < length; i++) {
|
Chris@441
|
247 if (stack[i] === value) { throw new TypeError(); }
|
Chris@441
|
248 }
|
Chris@441
|
249 stack.push(value);
|
Chris@441
|
250
|
Chris@441
|
251 var partial = [];
|
Chris@441
|
252 if (_class === ARRAY_CLASS) {
|
Chris@441
|
253 for (var i = 0, length = value.length; i < length; i++) {
|
Chris@441
|
254 var str = Str(i, value, stack);
|
Chris@441
|
255 partial.push(typeof str === 'undefined' ? 'null' : str);
|
Chris@441
|
256 }
|
Chris@441
|
257 partial = '[' + partial.join(',') + ']';
|
Chris@441
|
258 } else {
|
Chris@441
|
259 var keys = Object.keys(value);
|
Chris@441
|
260 for (var i = 0, length = keys.length; i < length; i++) {
|
Chris@441
|
261 var key = keys[i], str = Str(key, value, stack);
|
Chris@441
|
262 if (typeof str !== "undefined") {
|
Chris@441
|
263 partial.push(key.inspect(true)+ ':' + str);
|
Chris@441
|
264 }
|
Chris@441
|
265 }
|
Chris@441
|
266 partial = '{' + partial.join(',') + '}';
|
Chris@441
|
267 }
|
Chris@441
|
268 stack.pop();
|
Chris@441
|
269 return partial;
|
Chris@441
|
270 }
|
Chris@441
|
271 }
|
Chris@441
|
272
|
Chris@441
|
273 function stringify(object) {
|
Chris@441
|
274 return JSON.stringify(object);
|
Chris@441
|
275 }
|
Chris@441
|
276
|
Chris@441
|
277 function toQueryString(object) {
|
Chris@441
|
278 return $H(object).toQueryString();
|
Chris@441
|
279 }
|
Chris@441
|
280
|
Chris@441
|
281 function toHTML(object) {
|
Chris@441
|
282 return object && object.toHTML ? object.toHTML() : String.interpret(object);
|
Chris@441
|
283 }
|
Chris@441
|
284
|
Chris@441
|
285 function keys(object) {
|
Chris@441
|
286 if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); }
|
Chris@441
|
287 var results = [];
|
Chris@441
|
288 for (var property in object) {
|
Chris@441
|
289 if (object.hasOwnProperty(property)) {
|
Chris@441
|
290 results.push(property);
|
Chris@441
|
291 }
|
Chris@441
|
292 }
|
Chris@441
|
293 return results;
|
Chris@441
|
294 }
|
Chris@441
|
295
|
Chris@441
|
296 function values(object) {
|
Chris@441
|
297 var results = [];
|
Chris@441
|
298 for (var property in object)
|
Chris@441
|
299 results.push(object[property]);
|
Chris@441
|
300 return results;
|
Chris@441
|
301 }
|
Chris@441
|
302
|
Chris@441
|
303 function clone(object) {
|
Chris@441
|
304 return extend({ }, object);
|
Chris@441
|
305 }
|
Chris@441
|
306
|
Chris@441
|
307 function isElement(object) {
|
Chris@441
|
308 return !!(object && object.nodeType == 1);
|
Chris@441
|
309 }
|
Chris@441
|
310
|
Chris@441
|
311 function isArray(object) {
|
Chris@441
|
312 return _toString.call(object) === ARRAY_CLASS;
|
Chris@441
|
313 }
|
Chris@441
|
314
|
Chris@441
|
315 var hasNativeIsArray = (typeof Array.isArray == 'function')
|
Chris@441
|
316 && Array.isArray([]) && !Array.isArray({});
|
Chris@441
|
317
|
Chris@441
|
318 if (hasNativeIsArray) {
|
Chris@441
|
319 isArray = Array.isArray;
|
Chris@441
|
320 }
|
Chris@441
|
321
|
Chris@441
|
322 function isHash(object) {
|
Chris@441
|
323 return object instanceof Hash;
|
Chris@441
|
324 }
|
Chris@441
|
325
|
Chris@441
|
326 function isFunction(object) {
|
Chris@441
|
327 return _toString.call(object) === FUNCTION_CLASS;
|
Chris@441
|
328 }
|
Chris@441
|
329
|
Chris@441
|
330 function isString(object) {
|
Chris@441
|
331 return _toString.call(object) === STRING_CLASS;
|
Chris@441
|
332 }
|
Chris@441
|
333
|
Chris@441
|
334 function isNumber(object) {
|
Chris@441
|
335 return _toString.call(object) === NUMBER_CLASS;
|
Chris@441
|
336 }
|
Chris@441
|
337
|
Chris@441
|
338 function isDate(object) {
|
Chris@441
|
339 return _toString.call(object) === DATE_CLASS;
|
Chris@441
|
340 }
|
Chris@441
|
341
|
Chris@441
|
342 function isUndefined(object) {
|
Chris@441
|
343 return typeof object === "undefined";
|
Chris@441
|
344 }
|
Chris@441
|
345
|
Chris@441
|
346 extend(Object, {
|
Chris@441
|
347 extend: extend,
|
Chris@441
|
348 inspect: inspect,
|
Chris@441
|
349 toJSON: NATIVE_JSON_STRINGIFY_SUPPORT ? stringify : toJSON,
|
Chris@441
|
350 toQueryString: toQueryString,
|
Chris@441
|
351 toHTML: toHTML,
|
Chris@441
|
352 keys: Object.keys || keys,
|
Chris@441
|
353 values: values,
|
Chris@441
|
354 clone: clone,
|
Chris@441
|
355 isElement: isElement,
|
Chris@441
|
356 isArray: isArray,
|
Chris@441
|
357 isHash: isHash,
|
Chris@441
|
358 isFunction: isFunction,
|
Chris@441
|
359 isString: isString,
|
Chris@441
|
360 isNumber: isNumber,
|
Chris@441
|
361 isDate: isDate,
|
Chris@441
|
362 isUndefined: isUndefined
|
Chris@441
|
363 });
|
Chris@441
|
364 })();
|
Chris@441
|
365 Object.extend(Function.prototype, (function() {
|
Chris@441
|
366 var slice = Array.prototype.slice;
|
Chris@441
|
367
|
Chris@441
|
368 function update(array, args) {
|
Chris@441
|
369 var arrayLength = array.length, length = args.length;
|
Chris@441
|
370 while (length--) array[arrayLength + length] = args[length];
|
Chris@441
|
371 return array;
|
Chris@441
|
372 }
|
Chris@441
|
373
|
Chris@441
|
374 function merge(array, args) {
|
Chris@441
|
375 array = slice.call(array, 0);
|
Chris@441
|
376 return update(array, args);
|
Chris@441
|
377 }
|
Chris@441
|
378
|
Chris@441
|
379 function argumentNames() {
|
Chris@441
|
380 var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
|
Chris@441
|
381 .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
|
Chris@441
|
382 .replace(/\s+/g, '').split(',');
|
Chris@441
|
383 return names.length == 1 && !names[0] ? [] : names;
|
Chris@441
|
384 }
|
Chris@441
|
385
|
Chris@441
|
386 function bind(context) {
|
Chris@441
|
387 if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
|
Chris@441
|
388 var __method = this, args = slice.call(arguments, 1);
|
Chris@441
|
389 return function() {
|
Chris@441
|
390 var a = merge(args, arguments);
|
Chris@441
|
391 return __method.apply(context, a);
|
Chris@441
|
392 }
|
Chris@441
|
393 }
|
Chris@441
|
394
|
Chris@441
|
395 function bindAsEventListener(context) {
|
Chris@441
|
396 var __method = this, args = slice.call(arguments, 1);
|
Chris@441
|
397 return function(event) {
|
Chris@441
|
398 var a = update([event || window.event], args);
|
Chris@441
|
399 return __method.apply(context, a);
|
Chris@441
|
400 }
|
Chris@441
|
401 }
|
Chris@441
|
402
|
Chris@441
|
403 function curry() {
|
Chris@441
|
404 if (!arguments.length) return this;
|
Chris@441
|
405 var __method = this, args = slice.call(arguments, 0);
|
Chris@441
|
406 return function() {
|
Chris@441
|
407 var a = merge(args, arguments);
|
Chris@441
|
408 return __method.apply(this, a);
|
Chris@441
|
409 }
|
Chris@441
|
410 }
|
Chris@441
|
411
|
Chris@441
|
412 function delay(timeout) {
|
Chris@441
|
413 var __method = this, args = slice.call(arguments, 1);
|
Chris@441
|
414 timeout = timeout * 1000;
|
Chris@441
|
415 return window.setTimeout(function() {
|
Chris@441
|
416 return __method.apply(__method, args);
|
Chris@441
|
417 }, timeout);
|
Chris@441
|
418 }
|
Chris@441
|
419
|
Chris@441
|
420 function defer() {
|
Chris@441
|
421 var args = update([0.01], arguments);
|
Chris@441
|
422 return this.delay.apply(this, args);
|
Chris@441
|
423 }
|
Chris@441
|
424
|
Chris@441
|
425 function wrap(wrapper) {
|
Chris@441
|
426 var __method = this;
|
Chris@441
|
427 return function() {
|
Chris@441
|
428 var a = update([__method.bind(this)], arguments);
|
Chris@441
|
429 return wrapper.apply(this, a);
|
Chris@441
|
430 }
|
Chris@441
|
431 }
|
Chris@441
|
432
|
Chris@441
|
433 function methodize() {
|
Chris@441
|
434 if (this._methodized) return this._methodized;
|
Chris@441
|
435 var __method = this;
|
Chris@441
|
436 return this._methodized = function() {
|
Chris@441
|
437 var a = update([this], arguments);
|
Chris@441
|
438 return __method.apply(null, a);
|
Chris@441
|
439 };
|
Chris@441
|
440 }
|
Chris@441
|
441
|
Chris@441
|
442 return {
|
Chris@441
|
443 argumentNames: argumentNames,
|
Chris@441
|
444 bind: bind,
|
Chris@441
|
445 bindAsEventListener: bindAsEventListener,
|
Chris@441
|
446 curry: curry,
|
Chris@441
|
447 delay: delay,
|
Chris@441
|
448 defer: defer,
|
Chris@441
|
449 wrap: wrap,
|
Chris@441
|
450 methodize: methodize
|
Chris@441
|
451 }
|
Chris@441
|
452 })());
|
Chris@441
|
453
|
Chris@441
|
454
|
Chris@441
|
455
|
Chris@441
|
456 (function(proto) {
|
Chris@441
|
457
|
Chris@441
|
458
|
Chris@441
|
459 function toISOString() {
|
Chris@441
|
460 return this.getUTCFullYear() + '-' +
|
Chris@441
|
461 (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
|
Chris@441
|
462 this.getUTCDate().toPaddedString(2) + 'T' +
|
Chris@441
|
463 this.getUTCHours().toPaddedString(2) + ':' +
|
Chris@441
|
464 this.getUTCMinutes().toPaddedString(2) + ':' +
|
Chris@441
|
465 this.getUTCSeconds().toPaddedString(2) + 'Z';
|
Chris@441
|
466 }
|
Chris@441
|
467
|
Chris@441
|
468
|
Chris@441
|
469 function toJSON() {
|
Chris@441
|
470 return this.toISOString();
|
Chris@441
|
471 }
|
Chris@441
|
472
|
Chris@441
|
473 if (!proto.toISOString) proto.toISOString = toISOString;
|
Chris@441
|
474 if (!proto.toJSON) proto.toJSON = toJSON;
|
Chris@441
|
475
|
Chris@441
|
476 })(Date.prototype);
|
Chris@441
|
477
|
Chris@441
|
478
|
Chris@0
|
479 RegExp.prototype.match = RegExp.prototype.test;
|
Chris@0
|
480
|
Chris@0
|
481 RegExp.escape = function(str) {
|
Chris@0
|
482 return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
|
Chris@0
|
483 };
|
Chris@0
|
484 var PeriodicalExecuter = Class.create({
|
Chris@0
|
485 initialize: function(callback, frequency) {
|
Chris@0
|
486 this.callback = callback;
|
Chris@0
|
487 this.frequency = frequency;
|
Chris@0
|
488 this.currentlyExecuting = false;
|
Chris@0
|
489
|
Chris@0
|
490 this.registerCallback();
|
Chris@0
|
491 },
|
Chris@0
|
492
|
Chris@0
|
493 registerCallback: function() {
|
Chris@0
|
494 this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
|
Chris@0
|
495 },
|
Chris@0
|
496
|
Chris@0
|
497 execute: function() {
|
Chris@0
|
498 this.callback(this);
|
Chris@0
|
499 },
|
Chris@0
|
500
|
Chris@0
|
501 stop: function() {
|
Chris@0
|
502 if (!this.timer) return;
|
Chris@0
|
503 clearInterval(this.timer);
|
Chris@0
|
504 this.timer = null;
|
Chris@0
|
505 },
|
Chris@0
|
506
|
Chris@0
|
507 onTimerEvent: function() {
|
Chris@0
|
508 if (!this.currentlyExecuting) {
|
Chris@0
|
509 try {
|
Chris@0
|
510 this.currentlyExecuting = true;
|
Chris@0
|
511 this.execute();
|
Chris@0
|
512 this.currentlyExecuting = false;
|
Chris@441
|
513 } catch(e) {
|
Chris@441
|
514 this.currentlyExecuting = false;
|
Chris@441
|
515 throw e;
|
Chris@0
|
516 }
|
Chris@0
|
517 }
|
Chris@0
|
518 }
|
Chris@0
|
519 });
|
Chris@0
|
520 Object.extend(String, {
|
Chris@0
|
521 interpret: function(value) {
|
Chris@0
|
522 return value == null ? '' : String(value);
|
Chris@0
|
523 },
|
Chris@0
|
524 specialChar: {
|
Chris@0
|
525 '\b': '\\b',
|
Chris@0
|
526 '\t': '\\t',
|
Chris@0
|
527 '\n': '\\n',
|
Chris@0
|
528 '\f': '\\f',
|
Chris@0
|
529 '\r': '\\r',
|
Chris@0
|
530 '\\': '\\\\'
|
Chris@0
|
531 }
|
Chris@0
|
532 });
|
Chris@0
|
533
|
Chris@441
|
534 Object.extend(String.prototype, (function() {
|
Chris@441
|
535 var NATIVE_JSON_PARSE_SUPPORT = window.JSON &&
|
Chris@441
|
536 typeof JSON.parse === 'function' &&
|
Chris@441
|
537 JSON.parse('{"test": true}').test;
|
Chris@441
|
538
|
Chris@441
|
539 function prepareReplacement(replacement) {
|
Chris@441
|
540 if (Object.isFunction(replacement)) return replacement;
|
Chris@441
|
541 var template = new Template(replacement);
|
Chris@441
|
542 return function(match) { return template.evaluate(match) };
|
Chris@441
|
543 }
|
Chris@441
|
544
|
Chris@441
|
545 function gsub(pattern, replacement) {
|
Chris@0
|
546 var result = '', source = this, match;
|
Chris@441
|
547 replacement = prepareReplacement(replacement);
|
Chris@441
|
548
|
Chris@441
|
549 if (Object.isString(pattern))
|
Chris@441
|
550 pattern = RegExp.escape(pattern);
|
Chris@441
|
551
|
Chris@441
|
552 if (!(pattern.length || pattern.source)) {
|
Chris@441
|
553 replacement = replacement('');
|
Chris@441
|
554 return replacement + source.split('').join(replacement) + replacement;
|
Chris@441
|
555 }
|
Chris@0
|
556
|
Chris@0
|
557 while (source.length > 0) {
|
Chris@0
|
558 if (match = source.match(pattern)) {
|
Chris@0
|
559 result += source.slice(0, match.index);
|
Chris@0
|
560 result += String.interpret(replacement(match));
|
Chris@0
|
561 source = source.slice(match.index + match[0].length);
|
Chris@0
|
562 } else {
|
Chris@0
|
563 result += source, source = '';
|
Chris@0
|
564 }
|
Chris@0
|
565 }
|
Chris@0
|
566 return result;
|
Chris@441
|
567 }
|
Chris@441
|
568
|
Chris@441
|
569 function sub(pattern, replacement, count) {
|
Chris@441
|
570 replacement = prepareReplacement(replacement);
|
Chris@0
|
571 count = Object.isUndefined(count) ? 1 : count;
|
Chris@0
|
572
|
Chris@0
|
573 return this.gsub(pattern, function(match) {
|
Chris@0
|
574 if (--count < 0) return match[0];
|
Chris@0
|
575 return replacement(match);
|
Chris@0
|
576 });
|
Chris@441
|
577 }
|
Chris@441
|
578
|
Chris@441
|
579 function scan(pattern, iterator) {
|
Chris@0
|
580 this.gsub(pattern, iterator);
|
Chris@0
|
581 return String(this);
|
Chris@441
|
582 }
|
Chris@441
|
583
|
Chris@441
|
584 function truncate(length, truncation) {
|
Chris@0
|
585 length = length || 30;
|
Chris@0
|
586 truncation = Object.isUndefined(truncation) ? '...' : truncation;
|
Chris@0
|
587 return this.length > length ?
|
Chris@0
|
588 this.slice(0, length - truncation.length) + truncation : String(this);
|
Chris@441
|
589 }
|
Chris@441
|
590
|
Chris@441
|
591 function strip() {
|
Chris@0
|
592 return this.replace(/^\s+/, '').replace(/\s+$/, '');
|
Chris@441
|
593 }
|
Chris@441
|
594
|
Chris@441
|
595 function stripTags() {
|
Chris@441
|
596 return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, '');
|
Chris@441
|
597 }
|
Chris@441
|
598
|
Chris@441
|
599 function stripScripts() {
|
Chris@0
|
600 return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
|
Chris@441
|
601 }
|
Chris@441
|
602
|
Chris@441
|
603 function extractScripts() {
|
Chris@441
|
604 var matchAll = new RegExp(Prototype.ScriptFragment, 'img'),
|
Chris@441
|
605 matchOne = new RegExp(Prototype.ScriptFragment, 'im');
|
Chris@0
|
606 return (this.match(matchAll) || []).map(function(scriptTag) {
|
Chris@0
|
607 return (scriptTag.match(matchOne) || ['', ''])[1];
|
Chris@0
|
608 });
|
Chris@441
|
609 }
|
Chris@441
|
610
|
Chris@441
|
611 function evalScripts() {
|
Chris@0
|
612 return this.extractScripts().map(function(script) { return eval(script) });
|
Chris@441
|
613 }
|
Chris@441
|
614
|
Chris@441
|
615 function escapeHTML() {
|
Chris@441
|
616 return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
Chris@441
|
617 }
|
Chris@441
|
618
|
Chris@441
|
619 function unescapeHTML() {
|
Chris@441
|
620 return this.stripTags().replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&');
|
Chris@441
|
621 }
|
Chris@441
|
622
|
Chris@441
|
623
|
Chris@441
|
624 function toQueryParams(separator) {
|
Chris@0
|
625 var match = this.strip().match(/([^?#]*)(#.*)?$/);
|
Chris@0
|
626 if (!match) return { };
|
Chris@0
|
627
|
Chris@0
|
628 return match[1].split(separator || '&').inject({ }, function(hash, pair) {
|
Chris@0
|
629 if ((pair = pair.split('='))[0]) {
|
Chris@441
|
630 var key = decodeURIComponent(pair.shift()),
|
Chris@441
|
631 value = pair.length > 1 ? pair.join('=') : pair[0];
|
Chris@441
|
632
|
Chris@0
|
633 if (value != undefined) value = decodeURIComponent(value);
|
Chris@0
|
634
|
Chris@0
|
635 if (key in hash) {
|
Chris@0
|
636 if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
|
Chris@0
|
637 hash[key].push(value);
|
Chris@0
|
638 }
|
Chris@0
|
639 else hash[key] = value;
|
Chris@0
|
640 }
|
Chris@0
|
641 return hash;
|
Chris@0
|
642 });
|
Chris@441
|
643 }
|
Chris@441
|
644
|
Chris@441
|
645 function toArray() {
|
Chris@0
|
646 return this.split('');
|
Chris@441
|
647 }
|
Chris@441
|
648
|
Chris@441
|
649 function succ() {
|
Chris@0
|
650 return this.slice(0, this.length - 1) +
|
Chris@0
|
651 String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
|
Chris@441
|
652 }
|
Chris@441
|
653
|
Chris@441
|
654 function times(count) {
|
Chris@0
|
655 return count < 1 ? '' : new Array(count + 1).join(this);
|
Chris@441
|
656 }
|
Chris@441
|
657
|
Chris@441
|
658 function camelize() {
|
Chris@441
|
659 return this.replace(/-+(.)?/g, function(match, chr) {
|
Chris@441
|
660 return chr ? chr.toUpperCase() : '';
|
Chris@441
|
661 });
|
Chris@441
|
662 }
|
Chris@441
|
663
|
Chris@441
|
664 function capitalize() {
|
Chris@0
|
665 return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
|
Chris@441
|
666 }
|
Chris@441
|
667
|
Chris@441
|
668 function underscore() {
|
Chris@441
|
669 return this.replace(/::/g, '/')
|
Chris@441
|
670 .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
Chris@441
|
671 .replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
Chris@441
|
672 .replace(/-/g, '_')
|
Chris@441
|
673 .toLowerCase();
|
Chris@441
|
674 }
|
Chris@441
|
675
|
Chris@441
|
676 function dasherize() {
|
Chris@441
|
677 return this.replace(/_/g, '-');
|
Chris@441
|
678 }
|
Chris@441
|
679
|
Chris@441
|
680 function inspect(useDoubleQuotes) {
|
Chris@441
|
681 var escapedString = this.replace(/[\x00-\x1f\\]/g, function(character) {
|
Chris@441
|
682 if (character in String.specialChar) {
|
Chris@441
|
683 return String.specialChar[character];
|
Chris@441
|
684 }
|
Chris@441
|
685 return '\\u00' + character.charCodeAt().toPaddedString(2, 16);
|
Chris@0
|
686 });
|
Chris@0
|
687 if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
|
Chris@0
|
688 return "'" + escapedString.replace(/'/g, '\\\'') + "'";
|
Chris@441
|
689 }
|
Chris@441
|
690
|
Chris@441
|
691 function unfilterJSON(filter) {
|
Chris@441
|
692 return this.replace(filter || Prototype.JSONFilter, '$1');
|
Chris@441
|
693 }
|
Chris@441
|
694
|
Chris@441
|
695 function isJSON() {
|
Chris@0
|
696 var str = this;
|
Chris@0
|
697 if (str.blank()) return false;
|
Chris@441
|
698 str = str.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@');
|
Chris@441
|
699 str = str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
|
Chris@441
|
700 str = str.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
|
Chris@441
|
701 return (/^[\],:{}\s]*$/).test(str);
|
Chris@441
|
702 }
|
Chris@441
|
703
|
Chris@441
|
704 function evalJSON(sanitize) {
|
Chris@441
|
705 var json = this.unfilterJSON(),
|
Chris@441
|
706 cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
Chris@441
|
707 if (cx.test(json)) {
|
Chris@441
|
708 json = json.replace(cx, function (a) {
|
Chris@441
|
709 return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
Chris@441
|
710 });
|
Chris@441
|
711 }
|
Chris@0
|
712 try {
|
Chris@0
|
713 if (!sanitize || json.isJSON()) return eval('(' + json + ')');
|
Chris@0
|
714 } catch (e) { }
|
Chris@0
|
715 throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
|
Chris@441
|
716 }
|
Chris@441
|
717
|
Chris@441
|
718 function parseJSON() {
|
Chris@441
|
719 var json = this.unfilterJSON();
|
Chris@441
|
720 return JSON.parse(json);
|
Chris@441
|
721 }
|
Chris@441
|
722
|
Chris@441
|
723 function include(pattern) {
|
Chris@0
|
724 return this.indexOf(pattern) > -1;
|
Chris@441
|
725 }
|
Chris@441
|
726
|
Chris@441
|
727 function startsWith(pattern) {
|
Chris@441
|
728 return this.lastIndexOf(pattern, 0) === 0;
|
Chris@441
|
729 }
|
Chris@441
|
730
|
Chris@441
|
731 function endsWith(pattern) {
|
Chris@0
|
732 var d = this.length - pattern.length;
|
Chris@441
|
733 return d >= 0 && this.indexOf(pattern, d) === d;
|
Chris@441
|
734 }
|
Chris@441
|
735
|
Chris@441
|
736 function empty() {
|
Chris@0
|
737 return this == '';
|
Chris@441
|
738 }
|
Chris@441
|
739
|
Chris@441
|
740 function blank() {
|
Chris@0
|
741 return /^\s*$/.test(this);
|
Chris@441
|
742 }
|
Chris@441
|
743
|
Chris@441
|
744 function interpolate(object, pattern) {
|
Chris@0
|
745 return new Template(this, pattern).evaluate(object);
|
Chris@0
|
746 }
|
Chris@441
|
747
|
Chris@441
|
748 return {
|
Chris@441
|
749 gsub: gsub,
|
Chris@441
|
750 sub: sub,
|
Chris@441
|
751 scan: scan,
|
Chris@441
|
752 truncate: truncate,
|
Chris@441
|
753 strip: String.prototype.trim || strip,
|
Chris@441
|
754 stripTags: stripTags,
|
Chris@441
|
755 stripScripts: stripScripts,
|
Chris@441
|
756 extractScripts: extractScripts,
|
Chris@441
|
757 evalScripts: evalScripts,
|
Chris@441
|
758 escapeHTML: escapeHTML,
|
Chris@441
|
759 unescapeHTML: unescapeHTML,
|
Chris@441
|
760 toQueryParams: toQueryParams,
|
Chris@441
|
761 parseQuery: toQueryParams,
|
Chris@441
|
762 toArray: toArray,
|
Chris@441
|
763 succ: succ,
|
Chris@441
|
764 times: times,
|
Chris@441
|
765 camelize: camelize,
|
Chris@441
|
766 capitalize: capitalize,
|
Chris@441
|
767 underscore: underscore,
|
Chris@441
|
768 dasherize: dasherize,
|
Chris@441
|
769 inspect: inspect,
|
Chris@441
|
770 unfilterJSON: unfilterJSON,
|
Chris@441
|
771 isJSON: isJSON,
|
Chris@441
|
772 evalJSON: NATIVE_JSON_PARSE_SUPPORT ? parseJSON : evalJSON,
|
Chris@441
|
773 include: include,
|
Chris@441
|
774 startsWith: startsWith,
|
Chris@441
|
775 endsWith: endsWith,
|
Chris@441
|
776 empty: empty,
|
Chris@441
|
777 blank: blank,
|
Chris@441
|
778 interpolate: interpolate
|
Chris@441
|
779 };
|
Chris@441
|
780 })());
|
Chris@0
|
781
|
Chris@0
|
782 var Template = Class.create({
|
Chris@0
|
783 initialize: function(template, pattern) {
|
Chris@0
|
784 this.template = template.toString();
|
Chris@0
|
785 this.pattern = pattern || Template.Pattern;
|
Chris@0
|
786 },
|
Chris@0
|
787
|
Chris@0
|
788 evaluate: function(object) {
|
Chris@441
|
789 if (object && Object.isFunction(object.toTemplateReplacements))
|
Chris@0
|
790 object = object.toTemplateReplacements();
|
Chris@0
|
791
|
Chris@0
|
792 return this.template.gsub(this.pattern, function(match) {
|
Chris@441
|
793 if (object == null) return (match[1] + '');
|
Chris@0
|
794
|
Chris@0
|
795 var before = match[1] || '';
|
Chris@0
|
796 if (before == '\\') return match[2];
|
Chris@0
|
797
|
Chris@441
|
798 var ctx = object, expr = match[3],
|
Chris@441
|
799 pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
|
Chris@441
|
800
|
Chris@0
|
801 match = pattern.exec(expr);
|
Chris@0
|
802 if (match == null) return before;
|
Chris@0
|
803
|
Chris@0
|
804 while (match != null) {
|
Chris@441
|
805 var comp = match[1].startsWith('[') ? match[2].replace(/\\\\]/g, ']') : match[1];
|
Chris@0
|
806 ctx = ctx[comp];
|
Chris@0
|
807 if (null == ctx || '' == match[3]) break;
|
Chris@0
|
808 expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
|
Chris@0
|
809 match = pattern.exec(expr);
|
Chris@0
|
810 }
|
Chris@0
|
811
|
Chris@0
|
812 return before + String.interpret(ctx);
|
Chris@0
|
813 });
|
Chris@0
|
814 }
|
Chris@0
|
815 });
|
Chris@0
|
816 Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
|
Chris@0
|
817
|
Chris@0
|
818 var $break = { };
|
Chris@0
|
819
|
Chris@441
|
820 var Enumerable = (function() {
|
Chris@441
|
821 function each(iterator, context) {
|
Chris@0
|
822 var index = 0;
|
Chris@0
|
823 try {
|
Chris@0
|
824 this._each(function(value) {
|
Chris@0
|
825 iterator.call(context, value, index++);
|
Chris@0
|
826 });
|
Chris@0
|
827 } catch (e) {
|
Chris@0
|
828 if (e != $break) throw e;
|
Chris@0
|
829 }
|
Chris@0
|
830 return this;
|
Chris@441
|
831 }
|
Chris@441
|
832
|
Chris@441
|
833 function eachSlice(number, iterator, context) {
|
Chris@0
|
834 var index = -number, slices = [], array = this.toArray();
|
Chris@0
|
835 if (number < 1) return array;
|
Chris@0
|
836 while ((index += number) < array.length)
|
Chris@0
|
837 slices.push(array.slice(index, index+number));
|
Chris@0
|
838 return slices.collect(iterator, context);
|
Chris@441
|
839 }
|
Chris@441
|
840
|
Chris@441
|
841 function all(iterator, context) {
|
Chris@0
|
842 iterator = iterator || Prototype.K;
|
Chris@0
|
843 var result = true;
|
Chris@0
|
844 this.each(function(value, index) {
|
Chris@0
|
845 result = result && !!iterator.call(context, value, index);
|
Chris@0
|
846 if (!result) throw $break;
|
Chris@0
|
847 });
|
Chris@0
|
848 return result;
|
Chris@441
|
849 }
|
Chris@441
|
850
|
Chris@441
|
851 function any(iterator, context) {
|
Chris@0
|
852 iterator = iterator || Prototype.K;
|
Chris@0
|
853 var result = false;
|
Chris@0
|
854 this.each(function(value, index) {
|
Chris@0
|
855 if (result = !!iterator.call(context, value, index))
|
Chris@0
|
856 throw $break;
|
Chris@0
|
857 });
|
Chris@0
|
858 return result;
|
Chris@441
|
859 }
|
Chris@441
|
860
|
Chris@441
|
861 function collect(iterator, context) {
|
Chris@0
|
862 iterator = iterator || Prototype.K;
|
Chris@0
|
863 var results = [];
|
Chris@0
|
864 this.each(function(value, index) {
|
Chris@0
|
865 results.push(iterator.call(context, value, index));
|
Chris@0
|
866 });
|
Chris@0
|
867 return results;
|
Chris@441
|
868 }
|
Chris@441
|
869
|
Chris@441
|
870 function detect(iterator, context) {
|
Chris@0
|
871 var result;
|
Chris@0
|
872 this.each(function(value, index) {
|
Chris@0
|
873 if (iterator.call(context, value, index)) {
|
Chris@0
|
874 result = value;
|
Chris@0
|
875 throw $break;
|
Chris@0
|
876 }
|
Chris@0
|
877 });
|
Chris@0
|
878 return result;
|
Chris@441
|
879 }
|
Chris@441
|
880
|
Chris@441
|
881 function findAll(iterator, context) {
|
Chris@0
|
882 var results = [];
|
Chris@0
|
883 this.each(function(value, index) {
|
Chris@0
|
884 if (iterator.call(context, value, index))
|
Chris@0
|
885 results.push(value);
|
Chris@0
|
886 });
|
Chris@0
|
887 return results;
|
Chris@441
|
888 }
|
Chris@441
|
889
|
Chris@441
|
890 function grep(filter, iterator, context) {
|
Chris@0
|
891 iterator = iterator || Prototype.K;
|
Chris@0
|
892 var results = [];
|
Chris@0
|
893
|
Chris@0
|
894 if (Object.isString(filter))
|
Chris@441
|
895 filter = new RegExp(RegExp.escape(filter));
|
Chris@0
|
896
|
Chris@0
|
897 this.each(function(value, index) {
|
Chris@0
|
898 if (filter.match(value))
|
Chris@0
|
899 results.push(iterator.call(context, value, index));
|
Chris@0
|
900 });
|
Chris@0
|
901 return results;
|
Chris@441
|
902 }
|
Chris@441
|
903
|
Chris@441
|
904 function include(object) {
|
Chris@0
|
905 if (Object.isFunction(this.indexOf))
|
Chris@0
|
906 if (this.indexOf(object) != -1) return true;
|
Chris@0
|
907
|
Chris@0
|
908 var found = false;
|
Chris@0
|
909 this.each(function(value) {
|
Chris@0
|
910 if (value == object) {
|
Chris@0
|
911 found = true;
|
Chris@0
|
912 throw $break;
|
Chris@0
|
913 }
|
Chris@0
|
914 });
|
Chris@0
|
915 return found;
|
Chris@441
|
916 }
|
Chris@441
|
917
|
Chris@441
|
918 function inGroupsOf(number, fillWith) {
|
Chris@0
|
919 fillWith = Object.isUndefined(fillWith) ? null : fillWith;
|
Chris@0
|
920 return this.eachSlice(number, function(slice) {
|
Chris@0
|
921 while(slice.length < number) slice.push(fillWith);
|
Chris@0
|
922 return slice;
|
Chris@0
|
923 });
|
Chris@441
|
924 }
|
Chris@441
|
925
|
Chris@441
|
926 function inject(memo, iterator, context) {
|
Chris@0
|
927 this.each(function(value, index) {
|
Chris@0
|
928 memo = iterator.call(context, memo, value, index);
|
Chris@0
|
929 });
|
Chris@0
|
930 return memo;
|
Chris@441
|
931 }
|
Chris@441
|
932
|
Chris@441
|
933 function invoke(method) {
|
Chris@0
|
934 var args = $A(arguments).slice(1);
|
Chris@0
|
935 return this.map(function(value) {
|
Chris@0
|
936 return value[method].apply(value, args);
|
Chris@0
|
937 });
|
Chris@441
|
938 }
|
Chris@441
|
939
|
Chris@441
|
940 function max(iterator, context) {
|
Chris@0
|
941 iterator = iterator || Prototype.K;
|
Chris@0
|
942 var result;
|
Chris@0
|
943 this.each(function(value, index) {
|
Chris@0
|
944 value = iterator.call(context, value, index);
|
Chris@0
|
945 if (result == null || value >= result)
|
Chris@0
|
946 result = value;
|
Chris@0
|
947 });
|
Chris@0
|
948 return result;
|
Chris@441
|
949 }
|
Chris@441
|
950
|
Chris@441
|
951 function min(iterator, context) {
|
Chris@0
|
952 iterator = iterator || Prototype.K;
|
Chris@0
|
953 var result;
|
Chris@0
|
954 this.each(function(value, index) {
|
Chris@0
|
955 value = iterator.call(context, value, index);
|
Chris@0
|
956 if (result == null || value < result)
|
Chris@0
|
957 result = value;
|
Chris@0
|
958 });
|
Chris@0
|
959 return result;
|
Chris@441
|
960 }
|
Chris@441
|
961
|
Chris@441
|
962 function partition(iterator, context) {
|
Chris@0
|
963 iterator = iterator || Prototype.K;
|
Chris@0
|
964 var trues = [], falses = [];
|
Chris@0
|
965 this.each(function(value, index) {
|
Chris@0
|
966 (iterator.call(context, value, index) ?
|
Chris@0
|
967 trues : falses).push(value);
|
Chris@0
|
968 });
|
Chris@0
|
969 return [trues, falses];
|
Chris@441
|
970 }
|
Chris@441
|
971
|
Chris@441
|
972 function pluck(property) {
|
Chris@0
|
973 var results = [];
|
Chris@0
|
974 this.each(function(value) {
|
Chris@0
|
975 results.push(value[property]);
|
Chris@0
|
976 });
|
Chris@0
|
977 return results;
|
Chris@441
|
978 }
|
Chris@441
|
979
|
Chris@441
|
980 function reject(iterator, context) {
|
Chris@0
|
981 var results = [];
|
Chris@0
|
982 this.each(function(value, index) {
|
Chris@0
|
983 if (!iterator.call(context, value, index))
|
Chris@0
|
984 results.push(value);
|
Chris@0
|
985 });
|
Chris@0
|
986 return results;
|
Chris@441
|
987 }
|
Chris@441
|
988
|
Chris@441
|
989 function sortBy(iterator, context) {
|
Chris@0
|
990 return this.map(function(value, index) {
|
Chris@0
|
991 return {
|
Chris@0
|
992 value: value,
|
Chris@0
|
993 criteria: iterator.call(context, value, index)
|
Chris@0
|
994 };
|
Chris@0
|
995 }).sort(function(left, right) {
|
Chris@0
|
996 var a = left.criteria, b = right.criteria;
|
Chris@0
|
997 return a < b ? -1 : a > b ? 1 : 0;
|
Chris@0
|
998 }).pluck('value');
|
Chris@441
|
999 }
|
Chris@441
|
1000
|
Chris@441
|
1001 function toArray() {
|
Chris@0
|
1002 return this.map();
|
Chris@441
|
1003 }
|
Chris@441
|
1004
|
Chris@441
|
1005 function zip() {
|
Chris@0
|
1006 var iterator = Prototype.K, args = $A(arguments);
|
Chris@0
|
1007 if (Object.isFunction(args.last()))
|
Chris@0
|
1008 iterator = args.pop();
|
Chris@0
|
1009
|
Chris@0
|
1010 var collections = [this].concat(args).map($A);
|
Chris@0
|
1011 return this.map(function(value, index) {
|
Chris@0
|
1012 return iterator(collections.pluck(index));
|
Chris@0
|
1013 });
|
Chris@441
|
1014 }
|
Chris@441
|
1015
|
Chris@441
|
1016 function size() {
|
Chris@0
|
1017 return this.toArray().length;
|
Chris@441
|
1018 }
|
Chris@441
|
1019
|
Chris@441
|
1020 function inspect() {
|
Chris@0
|
1021 return '#<Enumerable:' + this.toArray().inspect() + '>';
|
Chris@0
|
1022 }
|
Chris@441
|
1023
|
Chris@441
|
1024
|
Chris@441
|
1025
|
Chris@441
|
1026
|
Chris@441
|
1027
|
Chris@441
|
1028
|
Chris@441
|
1029
|
Chris@441
|
1030
|
Chris@441
|
1031
|
Chris@441
|
1032 return {
|
Chris@441
|
1033 each: each,
|
Chris@441
|
1034 eachSlice: eachSlice,
|
Chris@441
|
1035 all: all,
|
Chris@441
|
1036 every: all,
|
Chris@441
|
1037 any: any,
|
Chris@441
|
1038 some: any,
|
Chris@441
|
1039 collect: collect,
|
Chris@441
|
1040 map: collect,
|
Chris@441
|
1041 detect: detect,
|
Chris@441
|
1042 findAll: findAll,
|
Chris@441
|
1043 select: findAll,
|
Chris@441
|
1044 filter: findAll,
|
Chris@441
|
1045 grep: grep,
|
Chris@441
|
1046 include: include,
|
Chris@441
|
1047 member: include,
|
Chris@441
|
1048 inGroupsOf: inGroupsOf,
|
Chris@441
|
1049 inject: inject,
|
Chris@441
|
1050 invoke: invoke,
|
Chris@441
|
1051 max: max,
|
Chris@441
|
1052 min: min,
|
Chris@441
|
1053 partition: partition,
|
Chris@441
|
1054 pluck: pluck,
|
Chris@441
|
1055 reject: reject,
|
Chris@441
|
1056 sortBy: sortBy,
|
Chris@441
|
1057 toArray: toArray,
|
Chris@441
|
1058 entries: toArray,
|
Chris@441
|
1059 zip: zip,
|
Chris@441
|
1060 size: size,
|
Chris@441
|
1061 inspect: inspect,
|
Chris@441
|
1062 find: detect
|
Chris@441
|
1063 };
|
Chris@441
|
1064 })();
|
Chris@441
|
1065
|
Chris@0
|
1066 function $A(iterable) {
|
Chris@0
|
1067 if (!iterable) return [];
|
Chris@441
|
1068 if ('toArray' in Object(iterable)) return iterable.toArray();
|
Chris@0
|
1069 var length = iterable.length || 0, results = new Array(length);
|
Chris@0
|
1070 while (length--) results[length] = iterable[length];
|
Chris@0
|
1071 return results;
|
Chris@0
|
1072 }
|
Chris@0
|
1073
|
Chris@441
|
1074
|
Chris@441
|
1075 function $w(string) {
|
Chris@441
|
1076 if (!Object.isString(string)) return [];
|
Chris@441
|
1077 string = string.strip();
|
Chris@441
|
1078 return string ? string.split(/\s+/) : [];
|
Chris@0
|
1079 }
|
Chris@0
|
1080
|
Chris@0
|
1081 Array.from = $A;
|
Chris@0
|
1082
|
Chris@441
|
1083
|
Chris@441
|
1084 (function() {
|
Chris@441
|
1085 var arrayProto = Array.prototype,
|
Chris@441
|
1086 slice = arrayProto.slice,
|
Chris@441
|
1087 _each = arrayProto.forEach; // use native browser JS 1.6 implementation if available
|
Chris@441
|
1088
|
Chris@441
|
1089 function each(iterator, context) {
|
Chris@441
|
1090 for (var i = 0, length = this.length >>> 0; i < length; i++) {
|
Chris@441
|
1091 if (i in this) iterator.call(context, this[i], i, this);
|
Chris@441
|
1092 }
|
Chris@441
|
1093 }
|
Chris@441
|
1094 if (!_each) _each = each;
|
Chris@441
|
1095
|
Chris@441
|
1096 function clear() {
|
Chris@0
|
1097 this.length = 0;
|
Chris@0
|
1098 return this;
|
Chris@441
|
1099 }
|
Chris@441
|
1100
|
Chris@441
|
1101 function first() {
|
Chris@0
|
1102 return this[0];
|
Chris@441
|
1103 }
|
Chris@441
|
1104
|
Chris@441
|
1105 function last() {
|
Chris@0
|
1106 return this[this.length - 1];
|
Chris@441
|
1107 }
|
Chris@441
|
1108
|
Chris@441
|
1109 function compact() {
|
Chris@0
|
1110 return this.select(function(value) {
|
Chris@0
|
1111 return value != null;
|
Chris@0
|
1112 });
|
Chris@441
|
1113 }
|
Chris@441
|
1114
|
Chris@441
|
1115 function flatten() {
|
Chris@0
|
1116 return this.inject([], function(array, value) {
|
Chris@441
|
1117 if (Object.isArray(value))
|
Chris@441
|
1118 return array.concat(value.flatten());
|
Chris@441
|
1119 array.push(value);
|
Chris@441
|
1120 return array;
|
Chris@0
|
1121 });
|
Chris@441
|
1122 }
|
Chris@441
|
1123
|
Chris@441
|
1124 function without() {
|
Chris@441
|
1125 var values = slice.call(arguments, 0);
|
Chris@0
|
1126 return this.select(function(value) {
|
Chris@0
|
1127 return !values.include(value);
|
Chris@0
|
1128 });
|
Chris@441
|
1129 }
|
Chris@441
|
1130
|
Chris@441
|
1131 function reverse(inline) {
|
Chris@441
|
1132 return (inline === false ? this.toArray() : this)._reverse();
|
Chris@441
|
1133 }
|
Chris@441
|
1134
|
Chris@441
|
1135 function uniq(sorted) {
|
Chris@0
|
1136 return this.inject([], function(array, value, index) {
|
Chris@0
|
1137 if (0 == index || (sorted ? array.last() != value : !array.include(value)))
|
Chris@0
|
1138 array.push(value);
|
Chris@0
|
1139 return array;
|
Chris@0
|
1140 });
|
Chris@441
|
1141 }
|
Chris@441
|
1142
|
Chris@441
|
1143 function intersect(array) {
|
Chris@0
|
1144 return this.uniq().findAll(function(item) {
|
Chris@0
|
1145 return array.detect(function(value) { return item === value });
|
Chris@0
|
1146 });
|
Chris@441
|
1147 }
|
Chris@441
|
1148
|
Chris@441
|
1149
|
Chris@441
|
1150 function clone() {
|
Chris@441
|
1151 return slice.call(this, 0);
|
Chris@441
|
1152 }
|
Chris@441
|
1153
|
Chris@441
|
1154 function size() {
|
Chris@0
|
1155 return this.length;
|
Chris@441
|
1156 }
|
Chris@441
|
1157
|
Chris@441
|
1158 function inspect() {
|
Chris@0
|
1159 return '[' + this.map(Object.inspect).join(', ') + ']';
|
Chris@441
|
1160 }
|
Chris@441
|
1161
|
Chris@441
|
1162 function indexOf(item, i) {
|
Chris@441
|
1163 i || (i = 0);
|
Chris@441
|
1164 var length = this.length;
|
Chris@441
|
1165 if (i < 0) i = length + i;
|
Chris@441
|
1166 for (; i < length; i++)
|
Chris@441
|
1167 if (this[i] === item) return i;
|
Chris@441
|
1168 return -1;
|
Chris@441
|
1169 }
|
Chris@441
|
1170
|
Chris@441
|
1171 function lastIndexOf(item, i) {
|
Chris@441
|
1172 i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
|
Chris@441
|
1173 var n = this.slice(0, i).reverse().indexOf(item);
|
Chris@441
|
1174 return (n < 0) ? n : i - n - 1;
|
Chris@441
|
1175 }
|
Chris@441
|
1176
|
Chris@441
|
1177 function concat() {
|
Chris@441
|
1178 var array = slice.call(this, 0), item;
|
Chris@0
|
1179 for (var i = 0, length = arguments.length; i < length; i++) {
|
Chris@441
|
1180 item = arguments[i];
|
Chris@441
|
1181 if (Object.isArray(item) && !('callee' in item)) {
|
Chris@441
|
1182 for (var j = 0, arrayLength = item.length; j < arrayLength; j++)
|
Chris@441
|
1183 array.push(item[j]);
|
Chris@0
|
1184 } else {
|
Chris@441
|
1185 array.push(item);
|
Chris@0
|
1186 }
|
Chris@0
|
1187 }
|
Chris@0
|
1188 return array;
|
Chris@441
|
1189 }
|
Chris@441
|
1190
|
Chris@441
|
1191 Object.extend(arrayProto, Enumerable);
|
Chris@441
|
1192
|
Chris@441
|
1193 if (!arrayProto._reverse)
|
Chris@441
|
1194 arrayProto._reverse = arrayProto.reverse;
|
Chris@441
|
1195
|
Chris@441
|
1196 Object.extend(arrayProto, {
|
Chris@441
|
1197 _each: _each,
|
Chris@441
|
1198 clear: clear,
|
Chris@441
|
1199 first: first,
|
Chris@441
|
1200 last: last,
|
Chris@441
|
1201 compact: compact,
|
Chris@441
|
1202 flatten: flatten,
|
Chris@441
|
1203 without: without,
|
Chris@441
|
1204 reverse: reverse,
|
Chris@441
|
1205 uniq: uniq,
|
Chris@441
|
1206 intersect: intersect,
|
Chris@441
|
1207 clone: clone,
|
Chris@441
|
1208 toArray: clone,
|
Chris@441
|
1209 size: size,
|
Chris@441
|
1210 inspect: inspect
|
Chris@441
|
1211 });
|
Chris@441
|
1212
|
Chris@441
|
1213 var CONCAT_ARGUMENTS_BUGGY = (function() {
|
Chris@441
|
1214 return [].concat(arguments)[0][0] !== 1;
|
Chris@441
|
1215 })(1,2)
|
Chris@441
|
1216
|
Chris@441
|
1217 if (CONCAT_ARGUMENTS_BUGGY) arrayProto.concat = concat;
|
Chris@441
|
1218
|
Chris@441
|
1219 if (!arrayProto.indexOf) arrayProto.indexOf = indexOf;
|
Chris@441
|
1220 if (!arrayProto.lastIndexOf) arrayProto.lastIndexOf = lastIndexOf;
|
Chris@441
|
1221 })();
|
Chris@0
|
1222 function $H(object) {
|
Chris@0
|
1223 return new Hash(object);
|
Chris@0
|
1224 };
|
Chris@0
|
1225
|
Chris@0
|
1226 var Hash = Class.create(Enumerable, (function() {
|
Chris@441
|
1227 function initialize(object) {
|
Chris@441
|
1228 this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
|
Chris@441
|
1229 }
|
Chris@441
|
1230
|
Chris@441
|
1231
|
Chris@441
|
1232 function _each(iterator) {
|
Chris@441
|
1233 for (var key in this._object) {
|
Chris@441
|
1234 var value = this._object[key], pair = [key, value];
|
Chris@441
|
1235 pair.key = key;
|
Chris@441
|
1236 pair.value = value;
|
Chris@441
|
1237 iterator(pair);
|
Chris@441
|
1238 }
|
Chris@441
|
1239 }
|
Chris@441
|
1240
|
Chris@441
|
1241 function set(key, value) {
|
Chris@441
|
1242 return this._object[key] = value;
|
Chris@441
|
1243 }
|
Chris@441
|
1244
|
Chris@441
|
1245 function get(key) {
|
Chris@441
|
1246 if (this._object[key] !== Object.prototype[key])
|
Chris@441
|
1247 return this._object[key];
|
Chris@441
|
1248 }
|
Chris@441
|
1249
|
Chris@441
|
1250 function unset(key) {
|
Chris@441
|
1251 var value = this._object[key];
|
Chris@441
|
1252 delete this._object[key];
|
Chris@441
|
1253 return value;
|
Chris@441
|
1254 }
|
Chris@441
|
1255
|
Chris@441
|
1256 function toObject() {
|
Chris@441
|
1257 return Object.clone(this._object);
|
Chris@441
|
1258 }
|
Chris@441
|
1259
|
Chris@441
|
1260
|
Chris@441
|
1261
|
Chris@441
|
1262 function keys() {
|
Chris@441
|
1263 return this.pluck('key');
|
Chris@441
|
1264 }
|
Chris@441
|
1265
|
Chris@441
|
1266 function values() {
|
Chris@441
|
1267 return this.pluck('value');
|
Chris@441
|
1268 }
|
Chris@441
|
1269
|
Chris@441
|
1270 function index(value) {
|
Chris@441
|
1271 var match = this.detect(function(pair) {
|
Chris@441
|
1272 return pair.value === value;
|
Chris@441
|
1273 });
|
Chris@441
|
1274 return match && match.key;
|
Chris@441
|
1275 }
|
Chris@441
|
1276
|
Chris@441
|
1277 function merge(object) {
|
Chris@441
|
1278 return this.clone().update(object);
|
Chris@441
|
1279 }
|
Chris@441
|
1280
|
Chris@441
|
1281 function update(object) {
|
Chris@441
|
1282 return new Hash(object).inject(this, function(result, pair) {
|
Chris@441
|
1283 result.set(pair.key, pair.value);
|
Chris@441
|
1284 return result;
|
Chris@441
|
1285 });
|
Chris@441
|
1286 }
|
Chris@0
|
1287
|
Chris@0
|
1288 function toQueryPair(key, value) {
|
Chris@0
|
1289 if (Object.isUndefined(value)) return key;
|
Chris@0
|
1290 return key + '=' + encodeURIComponent(String.interpret(value));
|
Chris@0
|
1291 }
|
Chris@0
|
1292
|
Chris@441
|
1293 function toQueryString() {
|
Chris@441
|
1294 return this.inject([], function(results, pair) {
|
Chris@441
|
1295 var key = encodeURIComponent(pair.key), values = pair.value;
|
Chris@441
|
1296
|
Chris@441
|
1297 if (values && typeof values == 'object') {
|
Chris@441
|
1298 if (Object.isArray(values)) {
|
Chris@441
|
1299 var queryValues = [];
|
Chris@441
|
1300 for (var i = 0, len = values.length, value; i < len; i++) {
|
Chris@441
|
1301 value = values[i];
|
Chris@441
|
1302 queryValues.push(toQueryPair(key, value));
|
Chris@441
|
1303 }
|
Chris@441
|
1304 return results.concat(queryValues);
|
Chris@441
|
1305 }
|
Chris@441
|
1306 } else results.push(toQueryPair(key, values));
|
Chris@441
|
1307 return results;
|
Chris@441
|
1308 }).join('&');
|
Chris@441
|
1309 }
|
Chris@441
|
1310
|
Chris@441
|
1311 function inspect() {
|
Chris@441
|
1312 return '#<Hash:{' + this.map(function(pair) {
|
Chris@441
|
1313 return pair.map(Object.inspect).join(': ');
|
Chris@441
|
1314 }).join(', ') + '}>';
|
Chris@441
|
1315 }
|
Chris@441
|
1316
|
Chris@441
|
1317 function clone() {
|
Chris@441
|
1318 return new Hash(this);
|
Chris@441
|
1319 }
|
Chris@441
|
1320
|
Chris@0
|
1321 return {
|
Chris@441
|
1322 initialize: initialize,
|
Chris@441
|
1323 _each: _each,
|
Chris@441
|
1324 set: set,
|
Chris@441
|
1325 get: get,
|
Chris@441
|
1326 unset: unset,
|
Chris@441
|
1327 toObject: toObject,
|
Chris@441
|
1328 toTemplateReplacements: toObject,
|
Chris@441
|
1329 keys: keys,
|
Chris@441
|
1330 values: values,
|
Chris@441
|
1331 index: index,
|
Chris@441
|
1332 merge: merge,
|
Chris@441
|
1333 update: update,
|
Chris@441
|
1334 toQueryString: toQueryString,
|
Chris@441
|
1335 inspect: inspect,
|
Chris@441
|
1336 toJSON: toObject,
|
Chris@441
|
1337 clone: clone
|
Chris@441
|
1338 };
|
Chris@0
|
1339 })());
|
Chris@0
|
1340
|
Chris@0
|
1341 Hash.from = $H;
|
Chris@441
|
1342 Object.extend(Number.prototype, (function() {
|
Chris@441
|
1343 function toColorPart() {
|
Chris@441
|
1344 return this.toPaddedString(2, 16);
|
Chris@441
|
1345 }
|
Chris@441
|
1346
|
Chris@441
|
1347 function succ() {
|
Chris@441
|
1348 return this + 1;
|
Chris@441
|
1349 }
|
Chris@441
|
1350
|
Chris@441
|
1351 function times(iterator, context) {
|
Chris@441
|
1352 $R(0, this, true).each(iterator, context);
|
Chris@441
|
1353 return this;
|
Chris@441
|
1354 }
|
Chris@441
|
1355
|
Chris@441
|
1356 function toPaddedString(length, radix) {
|
Chris@441
|
1357 var string = this.toString(radix || 10);
|
Chris@441
|
1358 return '0'.times(length - string.length) + string;
|
Chris@441
|
1359 }
|
Chris@441
|
1360
|
Chris@441
|
1361 function abs() {
|
Chris@441
|
1362 return Math.abs(this);
|
Chris@441
|
1363 }
|
Chris@441
|
1364
|
Chris@441
|
1365 function round() {
|
Chris@441
|
1366 return Math.round(this);
|
Chris@441
|
1367 }
|
Chris@441
|
1368
|
Chris@441
|
1369 function ceil() {
|
Chris@441
|
1370 return Math.ceil(this);
|
Chris@441
|
1371 }
|
Chris@441
|
1372
|
Chris@441
|
1373 function floor() {
|
Chris@441
|
1374 return Math.floor(this);
|
Chris@441
|
1375 }
|
Chris@441
|
1376
|
Chris@441
|
1377 return {
|
Chris@441
|
1378 toColorPart: toColorPart,
|
Chris@441
|
1379 succ: succ,
|
Chris@441
|
1380 times: times,
|
Chris@441
|
1381 toPaddedString: toPaddedString,
|
Chris@441
|
1382 abs: abs,
|
Chris@441
|
1383 round: round,
|
Chris@441
|
1384 ceil: ceil,
|
Chris@441
|
1385 floor: floor
|
Chris@441
|
1386 };
|
Chris@441
|
1387 })());
|
Chris@441
|
1388
|
Chris@441
|
1389 function $R(start, end, exclusive) {
|
Chris@441
|
1390 return new ObjectRange(start, end, exclusive);
|
Chris@441
|
1391 }
|
Chris@441
|
1392
|
Chris@441
|
1393 var ObjectRange = Class.create(Enumerable, (function() {
|
Chris@441
|
1394 function initialize(start, end, exclusive) {
|
Chris@0
|
1395 this.start = start;
|
Chris@0
|
1396 this.end = end;
|
Chris@0
|
1397 this.exclusive = exclusive;
|
Chris@441
|
1398 }
|
Chris@441
|
1399
|
Chris@441
|
1400 function _each(iterator) {
|
Chris@0
|
1401 var value = this.start;
|
Chris@0
|
1402 while (this.include(value)) {
|
Chris@0
|
1403 iterator(value);
|
Chris@0
|
1404 value = value.succ();
|
Chris@0
|
1405 }
|
Chris@441
|
1406 }
|
Chris@441
|
1407
|
Chris@441
|
1408 function include(value) {
|
Chris@0
|
1409 if (value < this.start)
|
Chris@0
|
1410 return false;
|
Chris@0
|
1411 if (this.exclusive)
|
Chris@0
|
1412 return value < this.end;
|
Chris@0
|
1413 return value <= this.end;
|
Chris@0
|
1414 }
|
Chris@441
|
1415
|
Chris@441
|
1416 return {
|
Chris@441
|
1417 initialize: initialize,
|
Chris@441
|
1418 _each: _each,
|
Chris@441
|
1419 include: include
|
Chris@441
|
1420 };
|
Chris@441
|
1421 })());
|
Chris@441
|
1422
|
Chris@441
|
1423
|
Chris@0
|
1424
|
Chris@0
|
1425 var Ajax = {
|
Chris@0
|
1426 getTransport: function() {
|
Chris@0
|
1427 return Try.these(
|
Chris@0
|
1428 function() {return new XMLHttpRequest()},
|
Chris@0
|
1429 function() {return new ActiveXObject('Msxml2.XMLHTTP')},
|
Chris@0
|
1430 function() {return new ActiveXObject('Microsoft.XMLHTTP')}
|
Chris@0
|
1431 ) || false;
|
Chris@0
|
1432 },
|
Chris@0
|
1433
|
Chris@0
|
1434 activeRequestCount: 0
|
Chris@0
|
1435 };
|
Chris@0
|
1436
|
Chris@0
|
1437 Ajax.Responders = {
|
Chris@0
|
1438 responders: [],
|
Chris@0
|
1439
|
Chris@0
|
1440 _each: function(iterator) {
|
Chris@0
|
1441 this.responders._each(iterator);
|
Chris@0
|
1442 },
|
Chris@0
|
1443
|
Chris@0
|
1444 register: function(responder) {
|
Chris@0
|
1445 if (!this.include(responder))
|
Chris@0
|
1446 this.responders.push(responder);
|
Chris@0
|
1447 },
|
Chris@0
|
1448
|
Chris@0
|
1449 unregister: function(responder) {
|
Chris@0
|
1450 this.responders = this.responders.without(responder);
|
Chris@0
|
1451 },
|
Chris@0
|
1452
|
Chris@0
|
1453 dispatch: function(callback, request, transport, json) {
|
Chris@0
|
1454 this.each(function(responder) {
|
Chris@0
|
1455 if (Object.isFunction(responder[callback])) {
|
Chris@0
|
1456 try {
|
Chris@0
|
1457 responder[callback].apply(responder, [request, transport, json]);
|
Chris@0
|
1458 } catch (e) { }
|
Chris@0
|
1459 }
|
Chris@0
|
1460 });
|
Chris@0
|
1461 }
|
Chris@0
|
1462 };
|
Chris@0
|
1463
|
Chris@0
|
1464 Object.extend(Ajax.Responders, Enumerable);
|
Chris@0
|
1465
|
Chris@0
|
1466 Ajax.Responders.register({
|
Chris@0
|
1467 onCreate: function() { Ajax.activeRequestCount++ },
|
Chris@0
|
1468 onComplete: function() { Ajax.activeRequestCount-- }
|
Chris@0
|
1469 });
|
Chris@0
|
1470 Ajax.Base = Class.create({
|
Chris@0
|
1471 initialize: function(options) {
|
Chris@0
|
1472 this.options = {
|
Chris@0
|
1473 method: 'post',
|
Chris@0
|
1474 asynchronous: true,
|
Chris@0
|
1475 contentType: 'application/x-www-form-urlencoded',
|
Chris@0
|
1476 encoding: 'UTF-8',
|
Chris@0
|
1477 parameters: '',
|
Chris@0
|
1478 evalJSON: true,
|
Chris@0
|
1479 evalJS: true
|
Chris@0
|
1480 };
|
Chris@0
|
1481 Object.extend(this.options, options || { });
|
Chris@0
|
1482
|
Chris@0
|
1483 this.options.method = this.options.method.toLowerCase();
|
Chris@0
|
1484
|
Chris@441
|
1485 if (Object.isHash(this.options.parameters))
|
Chris@0
|
1486 this.options.parameters = this.options.parameters.toObject();
|
Chris@0
|
1487 }
|
Chris@0
|
1488 });
|
Chris@0
|
1489 Ajax.Request = Class.create(Ajax.Base, {
|
Chris@0
|
1490 _complete: false,
|
Chris@0
|
1491
|
Chris@0
|
1492 initialize: function($super, url, options) {
|
Chris@0
|
1493 $super(options);
|
Chris@0
|
1494 this.transport = Ajax.getTransport();
|
Chris@0
|
1495 this.request(url);
|
Chris@0
|
1496 },
|
Chris@0
|
1497
|
Chris@0
|
1498 request: function(url) {
|
Chris@0
|
1499 this.url = url;
|
Chris@0
|
1500 this.method = this.options.method;
|
Chris@441
|
1501 var params = Object.isString(this.options.parameters) ?
|
Chris@441
|
1502 this.options.parameters :
|
Chris@441
|
1503 Object.toQueryString(this.options.parameters);
|
Chris@0
|
1504
|
Chris@0
|
1505 if (!['get', 'post'].include(this.method)) {
|
Chris@441
|
1506 params += (params ? '&' : '') + "_method=" + this.method;
|
Chris@0
|
1507 this.method = 'post';
|
Chris@0
|
1508 }
|
Chris@0
|
1509
|
Chris@441
|
1510 if (params && this.method === 'get') {
|
Chris@441
|
1511 this.url += (this.url.include('?') ? '&' : '?') + params;
|
Chris@0
|
1512 }
|
Chris@0
|
1513
|
Chris@441
|
1514 this.parameters = params.toQueryParams();
|
Chris@441
|
1515
|
Chris@0
|
1516 try {
|
Chris@0
|
1517 var response = new Ajax.Response(this);
|
Chris@0
|
1518 if (this.options.onCreate) this.options.onCreate(response);
|
Chris@0
|
1519 Ajax.Responders.dispatch('onCreate', this, response);
|
Chris@0
|
1520
|
Chris@0
|
1521 this.transport.open(this.method.toUpperCase(), this.url,
|
Chris@0
|
1522 this.options.asynchronous);
|
Chris@0
|
1523
|
Chris@0
|
1524 if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
|
Chris@0
|
1525
|
Chris@0
|
1526 this.transport.onreadystatechange = this.onStateChange.bind(this);
|
Chris@0
|
1527 this.setRequestHeaders();
|
Chris@0
|
1528
|
Chris@0
|
1529 this.body = this.method == 'post' ? (this.options.postBody || params) : null;
|
Chris@0
|
1530 this.transport.send(this.body);
|
Chris@0
|
1531
|
Chris@0
|
1532 /* Force Firefox to handle ready state 4 for synchronous requests */
|
Chris@0
|
1533 if (!this.options.asynchronous && this.transport.overrideMimeType)
|
Chris@0
|
1534 this.onStateChange();
|
Chris@0
|
1535
|
Chris@0
|
1536 }
|
Chris@0
|
1537 catch (e) {
|
Chris@0
|
1538 this.dispatchException(e);
|
Chris@0
|
1539 }
|
Chris@0
|
1540 },
|
Chris@0
|
1541
|
Chris@0
|
1542 onStateChange: function() {
|
Chris@0
|
1543 var readyState = this.transport.readyState;
|
Chris@0
|
1544 if (readyState > 1 && !((readyState == 4) && this._complete))
|
Chris@0
|
1545 this.respondToReadyState(this.transport.readyState);
|
Chris@0
|
1546 },
|
Chris@0
|
1547
|
Chris@0
|
1548 setRequestHeaders: function() {
|
Chris@0
|
1549 var headers = {
|
Chris@0
|
1550 'X-Requested-With': 'XMLHttpRequest',
|
Chris@0
|
1551 'X-Prototype-Version': Prototype.Version,
|
Chris@0
|
1552 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
|
Chris@0
|
1553 };
|
Chris@0
|
1554
|
Chris@0
|
1555 if (this.method == 'post') {
|
Chris@0
|
1556 headers['Content-type'] = this.options.contentType +
|
Chris@0
|
1557 (this.options.encoding ? '; charset=' + this.options.encoding : '');
|
Chris@0
|
1558
|
Chris@0
|
1559 /* Force "Connection: close" for older Mozilla browsers to work
|
Chris@0
|
1560 * around a bug where XMLHttpRequest sends an incorrect
|
Chris@0
|
1561 * Content-length header. See Mozilla Bugzilla #246651.
|
Chris@0
|
1562 */
|
Chris@0
|
1563 if (this.transport.overrideMimeType &&
|
Chris@0
|
1564 (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
|
Chris@0
|
1565 headers['Connection'] = 'close';
|
Chris@0
|
1566 }
|
Chris@0
|
1567
|
Chris@0
|
1568 if (typeof this.options.requestHeaders == 'object') {
|
Chris@0
|
1569 var extras = this.options.requestHeaders;
|
Chris@0
|
1570
|
Chris@0
|
1571 if (Object.isFunction(extras.push))
|
Chris@0
|
1572 for (var i = 0, length = extras.length; i < length; i += 2)
|
Chris@0
|
1573 headers[extras[i]] = extras[i+1];
|
Chris@0
|
1574 else
|
Chris@0
|
1575 $H(extras).each(function(pair) { headers[pair.key] = pair.value });
|
Chris@0
|
1576 }
|
Chris@0
|
1577
|
Chris@0
|
1578 for (var name in headers)
|
Chris@0
|
1579 this.transport.setRequestHeader(name, headers[name]);
|
Chris@0
|
1580 },
|
Chris@0
|
1581
|
Chris@0
|
1582 success: function() {
|
Chris@0
|
1583 var status = this.getStatus();
|
Chris@441
|
1584 return !status || (status >= 200 && status < 300) || status == 304;
|
Chris@0
|
1585 },
|
Chris@0
|
1586
|
Chris@0
|
1587 getStatus: function() {
|
Chris@0
|
1588 try {
|
Chris@441
|
1589 if (this.transport.status === 1223) return 204;
|
Chris@0
|
1590 return this.transport.status || 0;
|
Chris@0
|
1591 } catch (e) { return 0 }
|
Chris@0
|
1592 },
|
Chris@0
|
1593
|
Chris@0
|
1594 respondToReadyState: function(readyState) {
|
Chris@0
|
1595 var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
|
Chris@0
|
1596
|
Chris@0
|
1597 if (state == 'Complete') {
|
Chris@0
|
1598 try {
|
Chris@0
|
1599 this._complete = true;
|
Chris@0
|
1600 (this.options['on' + response.status]
|
Chris@0
|
1601 || this.options['on' + (this.success() ? 'Success' : 'Failure')]
|
Chris@0
|
1602 || Prototype.emptyFunction)(response, response.headerJSON);
|
Chris@0
|
1603 } catch (e) {
|
Chris@0
|
1604 this.dispatchException(e);
|
Chris@0
|
1605 }
|
Chris@0
|
1606
|
Chris@0
|
1607 var contentType = response.getHeader('Content-type');
|
Chris@0
|
1608 if (this.options.evalJS == 'force'
|
Chris@0
|
1609 || (this.options.evalJS && this.isSameOrigin() && contentType
|
Chris@0
|
1610 && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
|
Chris@0
|
1611 this.evalResponse();
|
Chris@0
|
1612 }
|
Chris@0
|
1613
|
Chris@0
|
1614 try {
|
Chris@0
|
1615 (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
|
Chris@0
|
1616 Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
|
Chris@0
|
1617 } catch (e) {
|
Chris@0
|
1618 this.dispatchException(e);
|
Chris@0
|
1619 }
|
Chris@0
|
1620
|
Chris@0
|
1621 if (state == 'Complete') {
|
Chris@0
|
1622 this.transport.onreadystatechange = Prototype.emptyFunction;
|
Chris@0
|
1623 }
|
Chris@0
|
1624 },
|
Chris@0
|
1625
|
Chris@0
|
1626 isSameOrigin: function() {
|
Chris@0
|
1627 var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
|
Chris@0
|
1628 return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
|
Chris@0
|
1629 protocol: location.protocol,
|
Chris@0
|
1630 domain: document.domain,
|
Chris@0
|
1631 port: location.port ? ':' + location.port : ''
|
Chris@0
|
1632 }));
|
Chris@0
|
1633 },
|
Chris@0
|
1634
|
Chris@0
|
1635 getHeader: function(name) {
|
Chris@0
|
1636 try {
|
Chris@0
|
1637 return this.transport.getResponseHeader(name) || null;
|
Chris@441
|
1638 } catch (e) { return null; }
|
Chris@0
|
1639 },
|
Chris@0
|
1640
|
Chris@0
|
1641 evalResponse: function() {
|
Chris@0
|
1642 try {
|
Chris@0
|
1643 return eval((this.transport.responseText || '').unfilterJSON());
|
Chris@0
|
1644 } catch (e) {
|
Chris@0
|
1645 this.dispatchException(e);
|
Chris@0
|
1646 }
|
Chris@0
|
1647 },
|
Chris@0
|
1648
|
Chris@0
|
1649 dispatchException: function(exception) {
|
Chris@0
|
1650 (this.options.onException || Prototype.emptyFunction)(this, exception);
|
Chris@0
|
1651 Ajax.Responders.dispatch('onException', this, exception);
|
Chris@0
|
1652 }
|
Chris@0
|
1653 });
|
Chris@0
|
1654
|
Chris@0
|
1655 Ajax.Request.Events =
|
Chris@0
|
1656 ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
|
Chris@0
|
1657
|
Chris@441
|
1658
|
Chris@441
|
1659
|
Chris@441
|
1660
|
Chris@441
|
1661
|
Chris@441
|
1662
|
Chris@441
|
1663
|
Chris@441
|
1664
|
Chris@0
|
1665 Ajax.Response = Class.create({
|
Chris@0
|
1666 initialize: function(request){
|
Chris@0
|
1667 this.request = request;
|
Chris@0
|
1668 var transport = this.transport = request.transport,
|
Chris@0
|
1669 readyState = this.readyState = transport.readyState;
|
Chris@0
|
1670
|
Chris@441
|
1671 if ((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
|
Chris@0
|
1672 this.status = this.getStatus();
|
Chris@0
|
1673 this.statusText = this.getStatusText();
|
Chris@0
|
1674 this.responseText = String.interpret(transport.responseText);
|
Chris@0
|
1675 this.headerJSON = this._getHeaderJSON();
|
Chris@0
|
1676 }
|
Chris@0
|
1677
|
Chris@441
|
1678 if (readyState == 4) {
|
Chris@0
|
1679 var xml = transport.responseXML;
|
Chris@0
|
1680 this.responseXML = Object.isUndefined(xml) ? null : xml;
|
Chris@0
|
1681 this.responseJSON = this._getResponseJSON();
|
Chris@0
|
1682 }
|
Chris@0
|
1683 },
|
Chris@0
|
1684
|
Chris@0
|
1685 status: 0,
|
Chris@441
|
1686
|
Chris@0
|
1687 statusText: '',
|
Chris@0
|
1688
|
Chris@0
|
1689 getStatus: Ajax.Request.prototype.getStatus,
|
Chris@0
|
1690
|
Chris@0
|
1691 getStatusText: function() {
|
Chris@0
|
1692 try {
|
Chris@0
|
1693 return this.transport.statusText || '';
|
Chris@0
|
1694 } catch (e) { return '' }
|
Chris@0
|
1695 },
|
Chris@0
|
1696
|
Chris@0
|
1697 getHeader: Ajax.Request.prototype.getHeader,
|
Chris@0
|
1698
|
Chris@0
|
1699 getAllHeaders: function() {
|
Chris@0
|
1700 try {
|
Chris@0
|
1701 return this.getAllResponseHeaders();
|
Chris@0
|
1702 } catch (e) { return null }
|
Chris@0
|
1703 },
|
Chris@0
|
1704
|
Chris@0
|
1705 getResponseHeader: function(name) {
|
Chris@0
|
1706 return this.transport.getResponseHeader(name);
|
Chris@0
|
1707 },
|
Chris@0
|
1708
|
Chris@0
|
1709 getAllResponseHeaders: function() {
|
Chris@0
|
1710 return this.transport.getAllResponseHeaders();
|
Chris@0
|
1711 },
|
Chris@0
|
1712
|
Chris@0
|
1713 _getHeaderJSON: function() {
|
Chris@0
|
1714 var json = this.getHeader('X-JSON');
|
Chris@0
|
1715 if (!json) return null;
|
Chris@0
|
1716 json = decodeURIComponent(escape(json));
|
Chris@0
|
1717 try {
|
Chris@0
|
1718 return json.evalJSON(this.request.options.sanitizeJSON ||
|
Chris@0
|
1719 !this.request.isSameOrigin());
|
Chris@0
|
1720 } catch (e) {
|
Chris@0
|
1721 this.request.dispatchException(e);
|
Chris@0
|
1722 }
|
Chris@0
|
1723 },
|
Chris@0
|
1724
|
Chris@0
|
1725 _getResponseJSON: function() {
|
Chris@0
|
1726 var options = this.request.options;
|
Chris@0
|
1727 if (!options.evalJSON || (options.evalJSON != 'force' &&
|
Chris@0
|
1728 !(this.getHeader('Content-type') || '').include('application/json')) ||
|
Chris@0
|
1729 this.responseText.blank())
|
Chris@0
|
1730 return null;
|
Chris@0
|
1731 try {
|
Chris@0
|
1732 return this.responseText.evalJSON(options.sanitizeJSON ||
|
Chris@0
|
1733 !this.request.isSameOrigin());
|
Chris@0
|
1734 } catch (e) {
|
Chris@0
|
1735 this.request.dispatchException(e);
|
Chris@0
|
1736 }
|
Chris@0
|
1737 }
|
Chris@0
|
1738 });
|
Chris@0
|
1739
|
Chris@0
|
1740 Ajax.Updater = Class.create(Ajax.Request, {
|
Chris@0
|
1741 initialize: function($super, container, url, options) {
|
Chris@0
|
1742 this.container = {
|
Chris@0
|
1743 success: (container.success || container),
|
Chris@0
|
1744 failure: (container.failure || (container.success ? null : container))
|
Chris@0
|
1745 };
|
Chris@0
|
1746
|
Chris@0
|
1747 options = Object.clone(options);
|
Chris@0
|
1748 var onComplete = options.onComplete;
|
Chris@0
|
1749 options.onComplete = (function(response, json) {
|
Chris@0
|
1750 this.updateContent(response.responseText);
|
Chris@0
|
1751 if (Object.isFunction(onComplete)) onComplete(response, json);
|
Chris@0
|
1752 }).bind(this);
|
Chris@0
|
1753
|
Chris@0
|
1754 $super(url, options);
|
Chris@0
|
1755 },
|
Chris@0
|
1756
|
Chris@0
|
1757 updateContent: function(responseText) {
|
Chris@0
|
1758 var receiver = this.container[this.success() ? 'success' : 'failure'],
|
Chris@0
|
1759 options = this.options;
|
Chris@0
|
1760
|
Chris@0
|
1761 if (!options.evalScripts) responseText = responseText.stripScripts();
|
Chris@0
|
1762
|
Chris@0
|
1763 if (receiver = $(receiver)) {
|
Chris@0
|
1764 if (options.insertion) {
|
Chris@0
|
1765 if (Object.isString(options.insertion)) {
|
Chris@0
|
1766 var insertion = { }; insertion[options.insertion] = responseText;
|
Chris@0
|
1767 receiver.insert(insertion);
|
Chris@0
|
1768 }
|
Chris@0
|
1769 else options.insertion(receiver, responseText);
|
Chris@0
|
1770 }
|
Chris@0
|
1771 else receiver.update(responseText);
|
Chris@0
|
1772 }
|
Chris@0
|
1773 }
|
Chris@0
|
1774 });
|
Chris@0
|
1775
|
Chris@0
|
1776 Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
|
Chris@0
|
1777 initialize: function($super, container, url, options) {
|
Chris@0
|
1778 $super(options);
|
Chris@0
|
1779 this.onComplete = this.options.onComplete;
|
Chris@0
|
1780
|
Chris@0
|
1781 this.frequency = (this.options.frequency || 2);
|
Chris@0
|
1782 this.decay = (this.options.decay || 1);
|
Chris@0
|
1783
|
Chris@0
|
1784 this.updater = { };
|
Chris@0
|
1785 this.container = container;
|
Chris@0
|
1786 this.url = url;
|
Chris@0
|
1787
|
Chris@0
|
1788 this.start();
|
Chris@0
|
1789 },
|
Chris@0
|
1790
|
Chris@0
|
1791 start: function() {
|
Chris@0
|
1792 this.options.onComplete = this.updateComplete.bind(this);
|
Chris@0
|
1793 this.onTimerEvent();
|
Chris@0
|
1794 },
|
Chris@0
|
1795
|
Chris@0
|
1796 stop: function() {
|
Chris@0
|
1797 this.updater.options.onComplete = undefined;
|
Chris@0
|
1798 clearTimeout(this.timer);
|
Chris@0
|
1799 (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
|
Chris@0
|
1800 },
|
Chris@0
|
1801
|
Chris@0
|
1802 updateComplete: function(response) {
|
Chris@0
|
1803 if (this.options.decay) {
|
Chris@0
|
1804 this.decay = (response.responseText == this.lastText ?
|
Chris@0
|
1805 this.decay * this.options.decay : 1);
|
Chris@0
|
1806
|
Chris@0
|
1807 this.lastText = response.responseText;
|
Chris@0
|
1808 }
|
Chris@0
|
1809 this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
|
Chris@0
|
1810 },
|
Chris@0
|
1811
|
Chris@0
|
1812 onTimerEvent: function() {
|
Chris@0
|
1813 this.updater = new Ajax.Updater(this.container, this.url, this.options);
|
Chris@0
|
1814 }
|
Chris@0
|
1815 });
|
Chris@441
|
1816
|
Chris@441
|
1817
|
Chris@0
|
1818 function $(element) {
|
Chris@0
|
1819 if (arguments.length > 1) {
|
Chris@0
|
1820 for (var i = 0, elements = [], length = arguments.length; i < length; i++)
|
Chris@0
|
1821 elements.push($(arguments[i]));
|
Chris@0
|
1822 return elements;
|
Chris@0
|
1823 }
|
Chris@0
|
1824 if (Object.isString(element))
|
Chris@0
|
1825 element = document.getElementById(element);
|
Chris@0
|
1826 return Element.extend(element);
|
Chris@0
|
1827 }
|
Chris@0
|
1828
|
Chris@0
|
1829 if (Prototype.BrowserFeatures.XPath) {
|
Chris@0
|
1830 document._getElementsByXPath = function(expression, parentElement) {
|
Chris@0
|
1831 var results = [];
|
Chris@0
|
1832 var query = document.evaluate(expression, $(parentElement) || document,
|
Chris@0
|
1833 null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
Chris@0
|
1834 for (var i = 0, length = query.snapshotLength; i < length; i++)
|
Chris@0
|
1835 results.push(Element.extend(query.snapshotItem(i)));
|
Chris@0
|
1836 return results;
|
Chris@0
|
1837 };
|
Chris@0
|
1838 }
|
Chris@0
|
1839
|
Chris@0
|
1840 /*--------------------------------------------------------------------------*/
|
Chris@0
|
1841
|
Chris@441
|
1842 if (!Node) var Node = { };
|
Chris@0
|
1843
|
Chris@0
|
1844 if (!Node.ELEMENT_NODE) {
|
Chris@0
|
1845 Object.extend(Node, {
|
Chris@0
|
1846 ELEMENT_NODE: 1,
|
Chris@0
|
1847 ATTRIBUTE_NODE: 2,
|
Chris@0
|
1848 TEXT_NODE: 3,
|
Chris@0
|
1849 CDATA_SECTION_NODE: 4,
|
Chris@0
|
1850 ENTITY_REFERENCE_NODE: 5,
|
Chris@0
|
1851 ENTITY_NODE: 6,
|
Chris@0
|
1852 PROCESSING_INSTRUCTION_NODE: 7,
|
Chris@0
|
1853 COMMENT_NODE: 8,
|
Chris@0
|
1854 DOCUMENT_NODE: 9,
|
Chris@0
|
1855 DOCUMENT_TYPE_NODE: 10,
|
Chris@0
|
1856 DOCUMENT_FRAGMENT_NODE: 11,
|
Chris@0
|
1857 NOTATION_NODE: 12
|
Chris@0
|
1858 });
|
Chris@0
|
1859 }
|
Chris@0
|
1860
|
Chris@441
|
1861
|
Chris@441
|
1862
|
Chris@441
|
1863 (function(global) {
|
Chris@441
|
1864 function shouldUseCache(tagName, attributes) {
|
Chris@441
|
1865 if (tagName === 'select') return false;
|
Chris@441
|
1866 if ('type' in attributes) return false;
|
Chris@441
|
1867 return true;
|
Chris@441
|
1868 }
|
Chris@441
|
1869
|
Chris@441
|
1870 var HAS_EXTENDED_CREATE_ELEMENT_SYNTAX = (function(){
|
Chris@441
|
1871 try {
|
Chris@441
|
1872 var el = document.createElement('<input name="x">');
|
Chris@441
|
1873 return el.tagName.toLowerCase() === 'input' && el.name === 'x';
|
Chris@441
|
1874 }
|
Chris@441
|
1875 catch(err) {
|
Chris@441
|
1876 return false;
|
Chris@441
|
1877 }
|
Chris@441
|
1878 })();
|
Chris@441
|
1879
|
Chris@441
|
1880 var element = global.Element;
|
Chris@441
|
1881
|
Chris@441
|
1882 global.Element = function(tagName, attributes) {
|
Chris@0
|
1883 attributes = attributes || { };
|
Chris@0
|
1884 tagName = tagName.toLowerCase();
|
Chris@0
|
1885 var cache = Element.cache;
|
Chris@441
|
1886
|
Chris@441
|
1887 if (HAS_EXTENDED_CREATE_ELEMENT_SYNTAX && attributes.name) {
|
Chris@0
|
1888 tagName = '<' + tagName + ' name="' + attributes.name + '">';
|
Chris@0
|
1889 delete attributes.name;
|
Chris@0
|
1890 return Element.writeAttribute(document.createElement(tagName), attributes);
|
Chris@0
|
1891 }
|
Chris@441
|
1892
|
Chris@0
|
1893 if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
|
Chris@441
|
1894
|
Chris@441
|
1895 var node = shouldUseCache(tagName, attributes) ?
|
Chris@441
|
1896 cache[tagName].cloneNode(false) : document.createElement(tagName);
|
Chris@441
|
1897
|
Chris@441
|
1898 return Element.writeAttribute(node, attributes);
|
Chris@0
|
1899 };
|
Chris@441
|
1900
|
Chris@441
|
1901 Object.extend(global.Element, element || { });
|
Chris@441
|
1902 if (element) global.Element.prototype = element.prototype;
|
Chris@441
|
1903
|
Chris@441
|
1904 })(this);
|
Chris@441
|
1905
|
Chris@441
|
1906 Element.idCounter = 1;
|
Chris@0
|
1907 Element.cache = { };
|
Chris@0
|
1908
|
Chris@441
|
1909 Element._purgeElement = function(element) {
|
Chris@441
|
1910 var uid = element._prototypeUID;
|
Chris@441
|
1911 if (uid) {
|
Chris@441
|
1912 Element.stopObserving(element);
|
Chris@441
|
1913 element._prototypeUID = void 0;
|
Chris@441
|
1914 delete Element.Storage[uid];
|
Chris@441
|
1915 }
|
Chris@441
|
1916 }
|
Chris@441
|
1917
|
Chris@0
|
1918 Element.Methods = {
|
Chris@0
|
1919 visible: function(element) {
|
Chris@0
|
1920 return $(element).style.display != 'none';
|
Chris@0
|
1921 },
|
Chris@0
|
1922
|
Chris@0
|
1923 toggle: function(element) {
|
Chris@0
|
1924 element = $(element);
|
Chris@0
|
1925 Element[Element.visible(element) ? 'hide' : 'show'](element);
|
Chris@0
|
1926 return element;
|
Chris@0
|
1927 },
|
Chris@0
|
1928
|
Chris@0
|
1929 hide: function(element) {
|
Chris@0
|
1930 element = $(element);
|
Chris@0
|
1931 element.style.display = 'none';
|
Chris@0
|
1932 return element;
|
Chris@0
|
1933 },
|
Chris@0
|
1934
|
Chris@0
|
1935 show: function(element) {
|
Chris@0
|
1936 element = $(element);
|
Chris@0
|
1937 element.style.display = '';
|
Chris@0
|
1938 return element;
|
Chris@0
|
1939 },
|
Chris@0
|
1940
|
Chris@0
|
1941 remove: function(element) {
|
Chris@0
|
1942 element = $(element);
|
Chris@0
|
1943 element.parentNode.removeChild(element);
|
Chris@0
|
1944 return element;
|
Chris@0
|
1945 },
|
Chris@0
|
1946
|
Chris@441
|
1947 update: (function(){
|
Chris@441
|
1948
|
Chris@441
|
1949 var SELECT_ELEMENT_INNERHTML_BUGGY = (function(){
|
Chris@441
|
1950 var el = document.createElement("select"),
|
Chris@441
|
1951 isBuggy = true;
|
Chris@441
|
1952 el.innerHTML = "<option value=\"test\">test</option>";
|
Chris@441
|
1953 if (el.options && el.options[0]) {
|
Chris@441
|
1954 isBuggy = el.options[0].nodeName.toUpperCase() !== "OPTION";
|
Chris@441
|
1955 }
|
Chris@441
|
1956 el = null;
|
Chris@441
|
1957 return isBuggy;
|
Chris@441
|
1958 })();
|
Chris@441
|
1959
|
Chris@441
|
1960 var TABLE_ELEMENT_INNERHTML_BUGGY = (function(){
|
Chris@441
|
1961 try {
|
Chris@441
|
1962 var el = document.createElement("table");
|
Chris@441
|
1963 if (el && el.tBodies) {
|
Chris@441
|
1964 el.innerHTML = "<tbody><tr><td>test</td></tr></tbody>";
|
Chris@441
|
1965 var isBuggy = typeof el.tBodies[0] == "undefined";
|
Chris@441
|
1966 el = null;
|
Chris@441
|
1967 return isBuggy;
|
Chris@441
|
1968 }
|
Chris@441
|
1969 } catch (e) {
|
Chris@441
|
1970 return true;
|
Chris@441
|
1971 }
|
Chris@441
|
1972 })();
|
Chris@441
|
1973
|
Chris@441
|
1974 var LINK_ELEMENT_INNERHTML_BUGGY = (function() {
|
Chris@441
|
1975 try {
|
Chris@441
|
1976 var el = document.createElement('div');
|
Chris@441
|
1977 el.innerHTML = "<link>";
|
Chris@441
|
1978 var isBuggy = (el.childNodes.length === 0);
|
Chris@441
|
1979 el = null;
|
Chris@441
|
1980 return isBuggy;
|
Chris@441
|
1981 } catch(e) {
|
Chris@441
|
1982 return true;
|
Chris@441
|
1983 }
|
Chris@441
|
1984 })();
|
Chris@441
|
1985
|
Chris@441
|
1986 var ANY_INNERHTML_BUGGY = SELECT_ELEMENT_INNERHTML_BUGGY ||
|
Chris@441
|
1987 TABLE_ELEMENT_INNERHTML_BUGGY || LINK_ELEMENT_INNERHTML_BUGGY;
|
Chris@441
|
1988
|
Chris@441
|
1989 var SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING = (function () {
|
Chris@441
|
1990 var s = document.createElement("script"),
|
Chris@441
|
1991 isBuggy = false;
|
Chris@441
|
1992 try {
|
Chris@441
|
1993 s.appendChild(document.createTextNode(""));
|
Chris@441
|
1994 isBuggy = !s.firstChild ||
|
Chris@441
|
1995 s.firstChild && s.firstChild.nodeType !== 3;
|
Chris@441
|
1996 } catch (e) {
|
Chris@441
|
1997 isBuggy = true;
|
Chris@441
|
1998 }
|
Chris@441
|
1999 s = null;
|
Chris@441
|
2000 return isBuggy;
|
Chris@441
|
2001 })();
|
Chris@441
|
2002
|
Chris@441
|
2003
|
Chris@441
|
2004 function update(element, content) {
|
Chris@441
|
2005 element = $(element);
|
Chris@441
|
2006 var purgeElement = Element._purgeElement;
|
Chris@441
|
2007
|
Chris@441
|
2008 var descendants = element.getElementsByTagName('*'),
|
Chris@441
|
2009 i = descendants.length;
|
Chris@441
|
2010 while (i--) purgeElement(descendants[i]);
|
Chris@441
|
2011
|
Chris@441
|
2012 if (content && content.toElement)
|
Chris@441
|
2013 content = content.toElement();
|
Chris@441
|
2014
|
Chris@441
|
2015 if (Object.isElement(content))
|
Chris@441
|
2016 return element.update().insert(content);
|
Chris@441
|
2017
|
Chris@441
|
2018 content = Object.toHTML(content);
|
Chris@441
|
2019
|
Chris@441
|
2020 var tagName = element.tagName.toUpperCase();
|
Chris@441
|
2021
|
Chris@441
|
2022 if (tagName === 'SCRIPT' && SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING) {
|
Chris@441
|
2023 element.text = content;
|
Chris@441
|
2024 return element;
|
Chris@441
|
2025 }
|
Chris@441
|
2026
|
Chris@441
|
2027 if (ANY_INNERHTML_BUGGY) {
|
Chris@441
|
2028 if (tagName in Element._insertionTranslations.tags) {
|
Chris@441
|
2029 while (element.firstChild) {
|
Chris@441
|
2030 element.removeChild(element.firstChild);
|
Chris@441
|
2031 }
|
Chris@441
|
2032 Element._getContentFromAnonymousElement(tagName, content.stripScripts())
|
Chris@441
|
2033 .each(function(node) {
|
Chris@441
|
2034 element.appendChild(node)
|
Chris@441
|
2035 });
|
Chris@441
|
2036 } else if (LINK_ELEMENT_INNERHTML_BUGGY && Object.isString(content) && content.indexOf('<link') > -1) {
|
Chris@441
|
2037 while (element.firstChild) {
|
Chris@441
|
2038 element.removeChild(element.firstChild);
|
Chris@441
|
2039 }
|
Chris@441
|
2040 var nodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts(), true);
|
Chris@441
|
2041 nodes.each(function(node) { element.appendChild(node) });
|
Chris@441
|
2042 }
|
Chris@441
|
2043 else {
|
Chris@441
|
2044 element.innerHTML = content.stripScripts();
|
Chris@441
|
2045 }
|
Chris@441
|
2046 }
|
Chris@441
|
2047 else {
|
Chris@441
|
2048 element.innerHTML = content.stripScripts();
|
Chris@441
|
2049 }
|
Chris@441
|
2050
|
Chris@441
|
2051 content.evalScripts.bind(content).defer();
|
Chris@441
|
2052 return element;
|
Chris@441
|
2053 }
|
Chris@441
|
2054
|
Chris@441
|
2055 return update;
|
Chris@441
|
2056 })(),
|
Chris@0
|
2057
|
Chris@0
|
2058 replace: function(element, content) {
|
Chris@0
|
2059 element = $(element);
|
Chris@0
|
2060 if (content && content.toElement) content = content.toElement();
|
Chris@0
|
2061 else if (!Object.isElement(content)) {
|
Chris@0
|
2062 content = Object.toHTML(content);
|
Chris@0
|
2063 var range = element.ownerDocument.createRange();
|
Chris@0
|
2064 range.selectNode(element);
|
Chris@0
|
2065 content.evalScripts.bind(content).defer();
|
Chris@0
|
2066 content = range.createContextualFragment(content.stripScripts());
|
Chris@0
|
2067 }
|
Chris@0
|
2068 element.parentNode.replaceChild(content, element);
|
Chris@0
|
2069 return element;
|
Chris@0
|
2070 },
|
Chris@0
|
2071
|
Chris@0
|
2072 insert: function(element, insertions) {
|
Chris@0
|
2073 element = $(element);
|
Chris@0
|
2074
|
Chris@0
|
2075 if (Object.isString(insertions) || Object.isNumber(insertions) ||
|
Chris@0
|
2076 Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
|
Chris@0
|
2077 insertions = {bottom:insertions};
|
Chris@0
|
2078
|
Chris@0
|
2079 var content, insert, tagName, childNodes;
|
Chris@0
|
2080
|
Chris@0
|
2081 for (var position in insertions) {
|
Chris@0
|
2082 content = insertions[position];
|
Chris@0
|
2083 position = position.toLowerCase();
|
Chris@0
|
2084 insert = Element._insertionTranslations[position];
|
Chris@0
|
2085
|
Chris@0
|
2086 if (content && content.toElement) content = content.toElement();
|
Chris@0
|
2087 if (Object.isElement(content)) {
|
Chris@0
|
2088 insert(element, content);
|
Chris@0
|
2089 continue;
|
Chris@0
|
2090 }
|
Chris@0
|
2091
|
Chris@0
|
2092 content = Object.toHTML(content);
|
Chris@0
|
2093
|
Chris@0
|
2094 tagName = ((position == 'before' || position == 'after')
|
Chris@0
|
2095 ? element.parentNode : element).tagName.toUpperCase();
|
Chris@0
|
2096
|
Chris@0
|
2097 childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
|
Chris@0
|
2098
|
Chris@0
|
2099 if (position == 'top' || position == 'after') childNodes.reverse();
|
Chris@0
|
2100 childNodes.each(insert.curry(element));
|
Chris@0
|
2101
|
Chris@0
|
2102 content.evalScripts.bind(content).defer();
|
Chris@0
|
2103 }
|
Chris@0
|
2104
|
Chris@0
|
2105 return element;
|
Chris@0
|
2106 },
|
Chris@0
|
2107
|
Chris@0
|
2108 wrap: function(element, wrapper, attributes) {
|
Chris@0
|
2109 element = $(element);
|
Chris@0
|
2110 if (Object.isElement(wrapper))
|
Chris@0
|
2111 $(wrapper).writeAttribute(attributes || { });
|
Chris@0
|
2112 else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);
|
Chris@0
|
2113 else wrapper = new Element('div', wrapper);
|
Chris@0
|
2114 if (element.parentNode)
|
Chris@0
|
2115 element.parentNode.replaceChild(wrapper, element);
|
Chris@0
|
2116 wrapper.appendChild(element);
|
Chris@0
|
2117 return wrapper;
|
Chris@0
|
2118 },
|
Chris@0
|
2119
|
Chris@0
|
2120 inspect: function(element) {
|
Chris@0
|
2121 element = $(element);
|
Chris@0
|
2122 var result = '<' + element.tagName.toLowerCase();
|
Chris@0
|
2123 $H({'id': 'id', 'className': 'class'}).each(function(pair) {
|
Chris@441
|
2124 var property = pair.first(),
|
Chris@441
|
2125 attribute = pair.last(),
|
Chris@441
|
2126 value = (element[property] || '').toString();
|
Chris@0
|
2127 if (value) result += ' ' + attribute + '=' + value.inspect(true);
|
Chris@0
|
2128 });
|
Chris@0
|
2129 return result + '>';
|
Chris@0
|
2130 },
|
Chris@0
|
2131
|
Chris@441
|
2132 recursivelyCollect: function(element, property, maximumLength) {
|
Chris@0
|
2133 element = $(element);
|
Chris@441
|
2134 maximumLength = maximumLength || -1;
|
Chris@0
|
2135 var elements = [];
|
Chris@441
|
2136
|
Chris@441
|
2137 while (element = element[property]) {
|
Chris@0
|
2138 if (element.nodeType == 1)
|
Chris@0
|
2139 elements.push(Element.extend(element));
|
Chris@441
|
2140 if (elements.length == maximumLength)
|
Chris@441
|
2141 break;
|
Chris@441
|
2142 }
|
Chris@441
|
2143
|
Chris@0
|
2144 return elements;
|
Chris@0
|
2145 },
|
Chris@0
|
2146
|
Chris@0
|
2147 ancestors: function(element) {
|
Chris@441
|
2148 return Element.recursivelyCollect(element, 'parentNode');
|
Chris@0
|
2149 },
|
Chris@0
|
2150
|
Chris@0
|
2151 descendants: function(element) {
|
Chris@441
|
2152 return Element.select(element, "*");
|
Chris@0
|
2153 },
|
Chris@0
|
2154
|
Chris@0
|
2155 firstDescendant: function(element) {
|
Chris@0
|
2156 element = $(element).firstChild;
|
Chris@0
|
2157 while (element && element.nodeType != 1) element = element.nextSibling;
|
Chris@0
|
2158 return $(element);
|
Chris@0
|
2159 },
|
Chris@0
|
2160
|
Chris@0
|
2161 immediateDescendants: function(element) {
|
Chris@441
|
2162 var results = [], child = $(element).firstChild;
|
Chris@441
|
2163 while (child) {
|
Chris@441
|
2164 if (child.nodeType === 1) {
|
Chris@441
|
2165 results.push(Element.extend(child));
|
Chris@441
|
2166 }
|
Chris@441
|
2167 child = child.nextSibling;
|
Chris@441
|
2168 }
|
Chris@441
|
2169 return results;
|
Chris@0
|
2170 },
|
Chris@0
|
2171
|
Chris@441
|
2172 previousSiblings: function(element, maximumLength) {
|
Chris@441
|
2173 return Element.recursivelyCollect(element, 'previousSibling');
|
Chris@0
|
2174 },
|
Chris@0
|
2175
|
Chris@0
|
2176 nextSiblings: function(element) {
|
Chris@441
|
2177 return Element.recursivelyCollect(element, 'nextSibling');
|
Chris@0
|
2178 },
|
Chris@0
|
2179
|
Chris@0
|
2180 siblings: function(element) {
|
Chris@0
|
2181 element = $(element);
|
Chris@441
|
2182 return Element.previousSiblings(element).reverse()
|
Chris@441
|
2183 .concat(Element.nextSiblings(element));
|
Chris@0
|
2184 },
|
Chris@0
|
2185
|
Chris@0
|
2186 match: function(element, selector) {
|
Chris@441
|
2187 element = $(element);
|
Chris@0
|
2188 if (Object.isString(selector))
|
Chris@441
|
2189 return Prototype.Selector.match(element, selector);
|
Chris@441
|
2190 return selector.match(element);
|
Chris@0
|
2191 },
|
Chris@0
|
2192
|
Chris@0
|
2193 up: function(element, expression, index) {
|
Chris@0
|
2194 element = $(element);
|
Chris@0
|
2195 if (arguments.length == 1) return $(element.parentNode);
|
Chris@441
|
2196 var ancestors = Element.ancestors(element);
|
Chris@0
|
2197 return Object.isNumber(expression) ? ancestors[expression] :
|
Chris@441
|
2198 Prototype.Selector.find(ancestors, expression, index);
|
Chris@0
|
2199 },
|
Chris@0
|
2200
|
Chris@0
|
2201 down: function(element, expression, index) {
|
Chris@0
|
2202 element = $(element);
|
Chris@441
|
2203 if (arguments.length == 1) return Element.firstDescendant(element);
|
Chris@441
|
2204 return Object.isNumber(expression) ? Element.descendants(element)[expression] :
|
Chris@0
|
2205 Element.select(element, expression)[index || 0];
|
Chris@0
|
2206 },
|
Chris@0
|
2207
|
Chris@0
|
2208 previous: function(element, expression, index) {
|
Chris@0
|
2209 element = $(element);
|
Chris@441
|
2210 if (Object.isNumber(expression)) index = expression, expression = false;
|
Chris@441
|
2211 if (!Object.isNumber(index)) index = 0;
|
Chris@441
|
2212
|
Chris@441
|
2213 if (expression) {
|
Chris@441
|
2214 return Prototype.Selector.find(element.previousSiblings(), expression, index);
|
Chris@441
|
2215 } else {
|
Chris@441
|
2216 return element.recursivelyCollect("previousSibling", index + 1)[index];
|
Chris@441
|
2217 }
|
Chris@0
|
2218 },
|
Chris@0
|
2219
|
Chris@0
|
2220 next: function(element, expression, index) {
|
Chris@0
|
2221 element = $(element);
|
Chris@441
|
2222 if (Object.isNumber(expression)) index = expression, expression = false;
|
Chris@441
|
2223 if (!Object.isNumber(index)) index = 0;
|
Chris@441
|
2224
|
Chris@441
|
2225 if (expression) {
|
Chris@441
|
2226 return Prototype.Selector.find(element.nextSiblings(), expression, index);
|
Chris@441
|
2227 } else {
|
Chris@441
|
2228 var maximumLength = Object.isNumber(index) ? index + 1 : 1;
|
Chris@441
|
2229 return element.recursivelyCollect("nextSibling", index + 1)[index];
|
Chris@441
|
2230 }
|
Chris@0
|
2231 },
|
Chris@0
|
2232
|
Chris@441
|
2233
|
Chris@441
|
2234 select: function(element) {
|
Chris@441
|
2235 element = $(element);
|
Chris@441
|
2236 var expressions = Array.prototype.slice.call(arguments, 1).join(', ');
|
Chris@441
|
2237 return Prototype.Selector.select(expressions, element);
|
Chris@0
|
2238 },
|
Chris@0
|
2239
|
Chris@441
|
2240 adjacent: function(element) {
|
Chris@441
|
2241 element = $(element);
|
Chris@441
|
2242 var expressions = Array.prototype.slice.call(arguments, 1).join(', ');
|
Chris@441
|
2243 return Prototype.Selector.select(expressions, element.parentNode).without(element);
|
Chris@0
|
2244 },
|
Chris@0
|
2245
|
Chris@0
|
2246 identify: function(element) {
|
Chris@0
|
2247 element = $(element);
|
Chris@441
|
2248 var id = Element.readAttribute(element, 'id');
|
Chris@0
|
2249 if (id) return id;
|
Chris@441
|
2250 do { id = 'anonymous_element_' + Element.idCounter++ } while ($(id));
|
Chris@441
|
2251 Element.writeAttribute(element, 'id', id);
|
Chris@0
|
2252 return id;
|
Chris@0
|
2253 },
|
Chris@0
|
2254
|
Chris@0
|
2255 readAttribute: function(element, name) {
|
Chris@0
|
2256 element = $(element);
|
Chris@0
|
2257 if (Prototype.Browser.IE) {
|
Chris@0
|
2258 var t = Element._attributeTranslations.read;
|
Chris@0
|
2259 if (t.values[name]) return t.values[name](element, name);
|
Chris@0
|
2260 if (t.names[name]) name = t.names[name];
|
Chris@0
|
2261 if (name.include(':')) {
|
Chris@0
|
2262 return (!element.attributes || !element.attributes[name]) ? null :
|
Chris@0
|
2263 element.attributes[name].value;
|
Chris@0
|
2264 }
|
Chris@0
|
2265 }
|
Chris@0
|
2266 return element.getAttribute(name);
|
Chris@0
|
2267 },
|
Chris@0
|
2268
|
Chris@0
|
2269 writeAttribute: function(element, name, value) {
|
Chris@0
|
2270 element = $(element);
|
Chris@0
|
2271 var attributes = { }, t = Element._attributeTranslations.write;
|
Chris@0
|
2272
|
Chris@0
|
2273 if (typeof name == 'object') attributes = name;
|
Chris@0
|
2274 else attributes[name] = Object.isUndefined(value) ? true : value;
|
Chris@0
|
2275
|
Chris@0
|
2276 for (var attr in attributes) {
|
Chris@0
|
2277 name = t.names[attr] || attr;
|
Chris@0
|
2278 value = attributes[attr];
|
Chris@0
|
2279 if (t.values[attr]) name = t.values[attr](element, value);
|
Chris@0
|
2280 if (value === false || value === null)
|
Chris@0
|
2281 element.removeAttribute(name);
|
Chris@0
|
2282 else if (value === true)
|
Chris@0
|
2283 element.setAttribute(name, name);
|
Chris@0
|
2284 else element.setAttribute(name, value);
|
Chris@0
|
2285 }
|
Chris@0
|
2286 return element;
|
Chris@0
|
2287 },
|
Chris@0
|
2288
|
Chris@0
|
2289 getHeight: function(element) {
|
Chris@441
|
2290 return Element.getDimensions(element).height;
|
Chris@0
|
2291 },
|
Chris@0
|
2292
|
Chris@0
|
2293 getWidth: function(element) {
|
Chris@441
|
2294 return Element.getDimensions(element).width;
|
Chris@0
|
2295 },
|
Chris@0
|
2296
|
Chris@0
|
2297 classNames: function(element) {
|
Chris@0
|
2298 return new Element.ClassNames(element);
|
Chris@0
|
2299 },
|
Chris@0
|
2300
|
Chris@0
|
2301 hasClassName: function(element, className) {
|
Chris@0
|
2302 if (!(element = $(element))) return;
|
Chris@0
|
2303 var elementClassName = element.className;
|
Chris@0
|
2304 return (elementClassName.length > 0 && (elementClassName == className ||
|
Chris@0
|
2305 new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
|
Chris@0
|
2306 },
|
Chris@0
|
2307
|
Chris@0
|
2308 addClassName: function(element, className) {
|
Chris@0
|
2309 if (!(element = $(element))) return;
|
Chris@441
|
2310 if (!Element.hasClassName(element, className))
|
Chris@0
|
2311 element.className += (element.className ? ' ' : '') + className;
|
Chris@0
|
2312 return element;
|
Chris@0
|
2313 },
|
Chris@0
|
2314
|
Chris@0
|
2315 removeClassName: function(element, className) {
|
Chris@0
|
2316 if (!(element = $(element))) return;
|
Chris@0
|
2317 element.className = element.className.replace(
|
Chris@0
|
2318 new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
|
Chris@0
|
2319 return element;
|
Chris@0
|
2320 },
|
Chris@0
|
2321
|
Chris@0
|
2322 toggleClassName: function(element, className) {
|
Chris@0
|
2323 if (!(element = $(element))) return;
|
Chris@441
|
2324 return Element[Element.hasClassName(element, className) ?
|
Chris@441
|
2325 'removeClassName' : 'addClassName'](element, className);
|
Chris@0
|
2326 },
|
Chris@0
|
2327
|
Chris@0
|
2328 cleanWhitespace: function(element) {
|
Chris@0
|
2329 element = $(element);
|
Chris@0
|
2330 var node = element.firstChild;
|
Chris@0
|
2331 while (node) {
|
Chris@0
|
2332 var nextNode = node.nextSibling;
|
Chris@0
|
2333 if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
|
Chris@0
|
2334 element.removeChild(node);
|
Chris@0
|
2335 node = nextNode;
|
Chris@0
|
2336 }
|
Chris@0
|
2337 return element;
|
Chris@0
|
2338 },
|
Chris@0
|
2339
|
Chris@0
|
2340 empty: function(element) {
|
Chris@0
|
2341 return $(element).innerHTML.blank();
|
Chris@0
|
2342 },
|
Chris@0
|
2343
|
Chris@0
|
2344 descendantOf: function(element, ancestor) {
|
Chris@0
|
2345 element = $(element), ancestor = $(ancestor);
|
Chris@0
|
2346
|
Chris@0
|
2347 if (element.compareDocumentPosition)
|
Chris@0
|
2348 return (element.compareDocumentPosition(ancestor) & 8) === 8;
|
Chris@0
|
2349
|
Chris@0
|
2350 if (ancestor.contains)
|
Chris@0
|
2351 return ancestor.contains(element) && ancestor !== element;
|
Chris@0
|
2352
|
Chris@0
|
2353 while (element = element.parentNode)
|
Chris@0
|
2354 if (element == ancestor) return true;
|
Chris@0
|
2355
|
Chris@0
|
2356 return false;
|
Chris@0
|
2357 },
|
Chris@0
|
2358
|
Chris@0
|
2359 scrollTo: function(element) {
|
Chris@0
|
2360 element = $(element);
|
Chris@441
|
2361 var pos = Element.cumulativeOffset(element);
|
Chris@0
|
2362 window.scrollTo(pos[0], pos[1]);
|
Chris@0
|
2363 return element;
|
Chris@0
|
2364 },
|
Chris@0
|
2365
|
Chris@0
|
2366 getStyle: function(element, style) {
|
Chris@0
|
2367 element = $(element);
|
Chris@0
|
2368 style = style == 'float' ? 'cssFloat' : style.camelize();
|
Chris@0
|
2369 var value = element.style[style];
|
Chris@0
|
2370 if (!value || value == 'auto') {
|
Chris@0
|
2371 var css = document.defaultView.getComputedStyle(element, null);
|
Chris@0
|
2372 value = css ? css[style] : null;
|
Chris@0
|
2373 }
|
Chris@0
|
2374 if (style == 'opacity') return value ? parseFloat(value) : 1.0;
|
Chris@0
|
2375 return value == 'auto' ? null : value;
|
Chris@0
|
2376 },
|
Chris@0
|
2377
|
Chris@0
|
2378 getOpacity: function(element) {
|
Chris@0
|
2379 return $(element).getStyle('opacity');
|
Chris@0
|
2380 },
|
Chris@0
|
2381
|
Chris@0
|
2382 setStyle: function(element, styles) {
|
Chris@0
|
2383 element = $(element);
|
Chris@0
|
2384 var elementStyle = element.style, match;
|
Chris@0
|
2385 if (Object.isString(styles)) {
|
Chris@0
|
2386 element.style.cssText += ';' + styles;
|
Chris@0
|
2387 return styles.include('opacity') ?
|
Chris@0
|
2388 element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
|
Chris@0
|
2389 }
|
Chris@0
|
2390 for (var property in styles)
|
Chris@0
|
2391 if (property == 'opacity') element.setOpacity(styles[property]);
|
Chris@0
|
2392 else
|
Chris@0
|
2393 elementStyle[(property == 'float' || property == 'cssFloat') ?
|
Chris@0
|
2394 (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
|
Chris@0
|
2395 property] = styles[property];
|
Chris@0
|
2396
|
Chris@0
|
2397 return element;
|
Chris@0
|
2398 },
|
Chris@0
|
2399
|
Chris@0
|
2400 setOpacity: function(element, value) {
|
Chris@0
|
2401 element = $(element);
|
Chris@0
|
2402 element.style.opacity = (value == 1 || value === '') ? '' :
|
Chris@0
|
2403 (value < 0.00001) ? 0 : value;
|
Chris@0
|
2404 return element;
|
Chris@0
|
2405 },
|
Chris@0
|
2406
|
Chris@0
|
2407 makePositioned: function(element) {
|
Chris@0
|
2408 element = $(element);
|
Chris@0
|
2409 var pos = Element.getStyle(element, 'position');
|
Chris@0
|
2410 if (pos == 'static' || !pos) {
|
Chris@0
|
2411 element._madePositioned = true;
|
Chris@0
|
2412 element.style.position = 'relative';
|
Chris@0
|
2413 if (Prototype.Browser.Opera) {
|
Chris@0
|
2414 element.style.top = 0;
|
Chris@0
|
2415 element.style.left = 0;
|
Chris@0
|
2416 }
|
Chris@0
|
2417 }
|
Chris@0
|
2418 return element;
|
Chris@0
|
2419 },
|
Chris@0
|
2420
|
Chris@0
|
2421 undoPositioned: function(element) {
|
Chris@0
|
2422 element = $(element);
|
Chris@0
|
2423 if (element._madePositioned) {
|
Chris@0
|
2424 element._madePositioned = undefined;
|
Chris@0
|
2425 element.style.position =
|
Chris@0
|
2426 element.style.top =
|
Chris@0
|
2427 element.style.left =
|
Chris@0
|
2428 element.style.bottom =
|
Chris@0
|
2429 element.style.right = '';
|
Chris@0
|
2430 }
|
Chris@0
|
2431 return element;
|
Chris@0
|
2432 },
|
Chris@0
|
2433
|
Chris@0
|
2434 makeClipping: function(element) {
|
Chris@0
|
2435 element = $(element);
|
Chris@0
|
2436 if (element._overflow) return element;
|
Chris@0
|
2437 element._overflow = Element.getStyle(element, 'overflow') || 'auto';
|
Chris@0
|
2438 if (element._overflow !== 'hidden')
|
Chris@0
|
2439 element.style.overflow = 'hidden';
|
Chris@0
|
2440 return element;
|
Chris@0
|
2441 },
|
Chris@0
|
2442
|
Chris@0
|
2443 undoClipping: function(element) {
|
Chris@0
|
2444 element = $(element);
|
Chris@0
|
2445 if (!element._overflow) return element;
|
Chris@0
|
2446 element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
|
Chris@0
|
2447 element._overflow = null;
|
Chris@0
|
2448 return element;
|
Chris@0
|
2449 },
|
Chris@0
|
2450
|
Chris@0
|
2451 clonePosition: function(element, source) {
|
Chris@0
|
2452 var options = Object.extend({
|
Chris@0
|
2453 setLeft: true,
|
Chris@0
|
2454 setTop: true,
|
Chris@0
|
2455 setWidth: true,
|
Chris@0
|
2456 setHeight: true,
|
Chris@0
|
2457 offsetTop: 0,
|
Chris@0
|
2458 offsetLeft: 0
|
Chris@0
|
2459 }, arguments[2] || { });
|
Chris@0
|
2460
|
Chris@0
|
2461 source = $(source);
|
Chris@441
|
2462 var p = Element.viewportOffset(source), delta = [0, 0], parent = null;
|
Chris@441
|
2463
|
Chris@0
|
2464 element = $(element);
|
Chris@441
|
2465
|
Chris@0
|
2466 if (Element.getStyle(element, 'position') == 'absolute') {
|
Chris@441
|
2467 parent = Element.getOffsetParent(element);
|
Chris@441
|
2468 delta = Element.viewportOffset(parent);
|
Chris@0
|
2469 }
|
Chris@0
|
2470
|
Chris@0
|
2471 if (parent == document.body) {
|
Chris@0
|
2472 delta[0] -= document.body.offsetLeft;
|
Chris@0
|
2473 delta[1] -= document.body.offsetTop;
|
Chris@0
|
2474 }
|
Chris@0
|
2475
|
Chris@0
|
2476 if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
|
Chris@0
|
2477 if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
|
Chris@0
|
2478 if (options.setWidth) element.style.width = source.offsetWidth + 'px';
|
Chris@0
|
2479 if (options.setHeight) element.style.height = source.offsetHeight + 'px';
|
Chris@0
|
2480 return element;
|
Chris@0
|
2481 }
|
Chris@0
|
2482 };
|
Chris@0
|
2483
|
Chris@0
|
2484 Object.extend(Element.Methods, {
|
Chris@0
|
2485 getElementsBySelector: Element.Methods.select,
|
Chris@441
|
2486
|
Chris@0
|
2487 childElements: Element.Methods.immediateDescendants
|
Chris@0
|
2488 });
|
Chris@0
|
2489
|
Chris@0
|
2490 Element._attributeTranslations = {
|
Chris@0
|
2491 write: {
|
Chris@0
|
2492 names: {
|
Chris@0
|
2493 className: 'class',
|
Chris@0
|
2494 htmlFor: 'for'
|
Chris@0
|
2495 },
|
Chris@0
|
2496 values: { }
|
Chris@0
|
2497 }
|
Chris@0
|
2498 };
|
Chris@0
|
2499
|
Chris@0
|
2500 if (Prototype.Browser.Opera) {
|
Chris@0
|
2501 Element.Methods.getStyle = Element.Methods.getStyle.wrap(
|
Chris@0
|
2502 function(proceed, element, style) {
|
Chris@0
|
2503 switch (style) {
|
Chris@0
|
2504 case 'height': case 'width':
|
Chris@0
|
2505 if (!Element.visible(element)) return null;
|
Chris@0
|
2506
|
Chris@0
|
2507 var dim = parseInt(proceed(element, style), 10);
|
Chris@0
|
2508
|
Chris@0
|
2509 if (dim !== element['offset' + style.capitalize()])
|
Chris@0
|
2510 return dim + 'px';
|
Chris@0
|
2511
|
Chris@0
|
2512 var properties;
|
Chris@0
|
2513 if (style === 'height') {
|
Chris@0
|
2514 properties = ['border-top-width', 'padding-top',
|
Chris@0
|
2515 'padding-bottom', 'border-bottom-width'];
|
Chris@0
|
2516 }
|
Chris@0
|
2517 else {
|
Chris@0
|
2518 properties = ['border-left-width', 'padding-left',
|
Chris@0
|
2519 'padding-right', 'border-right-width'];
|
Chris@0
|
2520 }
|
Chris@0
|
2521 return properties.inject(dim, function(memo, property) {
|
Chris@0
|
2522 var val = proceed(element, property);
|
Chris@0
|
2523 return val === null ? memo : memo - parseInt(val, 10);
|
Chris@0
|
2524 }) + 'px';
|
Chris@0
|
2525 default: return proceed(element, style);
|
Chris@0
|
2526 }
|
Chris@0
|
2527 }
|
Chris@0
|
2528 );
|
Chris@0
|
2529
|
Chris@0
|
2530 Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(
|
Chris@0
|
2531 function(proceed, element, attribute) {
|
Chris@0
|
2532 if (attribute === 'title') return element.title;
|
Chris@0
|
2533 return proceed(element, attribute);
|
Chris@0
|
2534 }
|
Chris@0
|
2535 );
|
Chris@0
|
2536 }
|
Chris@0
|
2537
|
Chris@0
|
2538 else if (Prototype.Browser.IE) {
|
Chris@0
|
2539 Element.Methods.getStyle = function(element, style) {
|
Chris@0
|
2540 element = $(element);
|
Chris@0
|
2541 style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
|
Chris@0
|
2542 var value = element.style[style];
|
Chris@0
|
2543 if (!value && element.currentStyle) value = element.currentStyle[style];
|
Chris@0
|
2544
|
Chris@0
|
2545 if (style == 'opacity') {
|
Chris@0
|
2546 if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
|
Chris@0
|
2547 if (value[1]) return parseFloat(value[1]) / 100;
|
Chris@0
|
2548 return 1.0;
|
Chris@0
|
2549 }
|
Chris@0
|
2550
|
Chris@0
|
2551 if (value == 'auto') {
|
Chris@0
|
2552 if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
|
Chris@0
|
2553 return element['offset' + style.capitalize()] + 'px';
|
Chris@0
|
2554 return null;
|
Chris@0
|
2555 }
|
Chris@0
|
2556 return value;
|
Chris@0
|
2557 };
|
Chris@0
|
2558
|
Chris@0
|
2559 Element.Methods.setOpacity = function(element, value) {
|
Chris@0
|
2560 function stripAlpha(filter){
|
Chris@0
|
2561 return filter.replace(/alpha\([^\)]*\)/gi,'');
|
Chris@0
|
2562 }
|
Chris@0
|
2563 element = $(element);
|
Chris@0
|
2564 var currentStyle = element.currentStyle;
|
Chris@0
|
2565 if ((currentStyle && !currentStyle.hasLayout) ||
|
Chris@0
|
2566 (!currentStyle && element.style.zoom == 'normal'))
|
Chris@0
|
2567 element.style.zoom = 1;
|
Chris@0
|
2568
|
Chris@0
|
2569 var filter = element.getStyle('filter'), style = element.style;
|
Chris@0
|
2570 if (value == 1 || value === '') {
|
Chris@0
|
2571 (filter = stripAlpha(filter)) ?
|
Chris@0
|
2572 style.filter = filter : style.removeAttribute('filter');
|
Chris@0
|
2573 return element;
|
Chris@0
|
2574 } else if (value < 0.00001) value = 0;
|
Chris@0
|
2575 style.filter = stripAlpha(filter) +
|
Chris@0
|
2576 'alpha(opacity=' + (value * 100) + ')';
|
Chris@0
|
2577 return element;
|
Chris@0
|
2578 };
|
Chris@0
|
2579
|
Chris@441
|
2580 Element._attributeTranslations = (function(){
|
Chris@441
|
2581
|
Chris@441
|
2582 var classProp = 'className',
|
Chris@441
|
2583 forProp = 'for',
|
Chris@441
|
2584 el = document.createElement('div');
|
Chris@441
|
2585
|
Chris@441
|
2586 el.setAttribute(classProp, 'x');
|
Chris@441
|
2587
|
Chris@441
|
2588 if (el.className !== 'x') {
|
Chris@441
|
2589 el.setAttribute('class', 'x');
|
Chris@441
|
2590 if (el.className === 'x') {
|
Chris@441
|
2591 classProp = 'class';
|
Chris@441
|
2592 }
|
Chris@441
|
2593 }
|
Chris@441
|
2594 el = null;
|
Chris@441
|
2595
|
Chris@441
|
2596 el = document.createElement('label');
|
Chris@441
|
2597 el.setAttribute(forProp, 'x');
|
Chris@441
|
2598 if (el.htmlFor !== 'x') {
|
Chris@441
|
2599 el.setAttribute('htmlFor', 'x');
|
Chris@441
|
2600 if (el.htmlFor === 'x') {
|
Chris@441
|
2601 forProp = 'htmlFor';
|
Chris@441
|
2602 }
|
Chris@441
|
2603 }
|
Chris@441
|
2604 el = null;
|
Chris@441
|
2605
|
Chris@441
|
2606 return {
|
Chris@441
|
2607 read: {
|
Chris@441
|
2608 names: {
|
Chris@441
|
2609 'class': classProp,
|
Chris@441
|
2610 'className': classProp,
|
Chris@441
|
2611 'for': forProp,
|
Chris@441
|
2612 'htmlFor': forProp
|
Chris@0
|
2613 },
|
Chris@441
|
2614 values: {
|
Chris@441
|
2615 _getAttr: function(element, attribute) {
|
Chris@441
|
2616 return element.getAttribute(attribute);
|
Chris@441
|
2617 },
|
Chris@441
|
2618 _getAttr2: function(element, attribute) {
|
Chris@441
|
2619 return element.getAttribute(attribute, 2);
|
Chris@441
|
2620 },
|
Chris@441
|
2621 _getAttrNode: function(element, attribute) {
|
Chris@441
|
2622 var node = element.getAttributeNode(attribute);
|
Chris@441
|
2623 return node ? node.value : "";
|
Chris@441
|
2624 },
|
Chris@441
|
2625 _getEv: (function(){
|
Chris@441
|
2626
|
Chris@441
|
2627 var el = document.createElement('div'), f;
|
Chris@441
|
2628 el.onclick = Prototype.emptyFunction;
|
Chris@441
|
2629 var value = el.getAttribute('onclick');
|
Chris@441
|
2630
|
Chris@441
|
2631 if (String(value).indexOf('{') > -1) {
|
Chris@441
|
2632 f = function(element, attribute) {
|
Chris@441
|
2633 attribute = element.getAttribute(attribute);
|
Chris@441
|
2634 if (!attribute) return null;
|
Chris@441
|
2635 attribute = attribute.toString();
|
Chris@441
|
2636 attribute = attribute.split('{')[1];
|
Chris@441
|
2637 attribute = attribute.split('}')[0];
|
Chris@441
|
2638 return attribute.strip();
|
Chris@441
|
2639 };
|
Chris@441
|
2640 }
|
Chris@441
|
2641 else if (value === '') {
|
Chris@441
|
2642 f = function(element, attribute) {
|
Chris@441
|
2643 attribute = element.getAttribute(attribute);
|
Chris@441
|
2644 if (!attribute) return null;
|
Chris@441
|
2645 return attribute.strip();
|
Chris@441
|
2646 };
|
Chris@441
|
2647 }
|
Chris@441
|
2648 el = null;
|
Chris@441
|
2649 return f;
|
Chris@441
|
2650 })(),
|
Chris@441
|
2651 _flag: function(element, attribute) {
|
Chris@441
|
2652 return $(element).hasAttribute(attribute) ? attribute : null;
|
Chris@441
|
2653 },
|
Chris@441
|
2654 style: function(element) {
|
Chris@441
|
2655 return element.style.cssText.toLowerCase();
|
Chris@441
|
2656 },
|
Chris@441
|
2657 title: function(element) {
|
Chris@441
|
2658 return element.title;
|
Chris@441
|
2659 }
|
Chris@0
|
2660 }
|
Chris@0
|
2661 }
|
Chris@0
|
2662 }
|
Chris@441
|
2663 })();
|
Chris@0
|
2664
|
Chris@0
|
2665 Element._attributeTranslations.write = {
|
Chris@0
|
2666 names: Object.extend({
|
Chris@0
|
2667 cellpadding: 'cellPadding',
|
Chris@0
|
2668 cellspacing: 'cellSpacing'
|
Chris@0
|
2669 }, Element._attributeTranslations.read.names),
|
Chris@0
|
2670 values: {
|
Chris@0
|
2671 checked: function(element, value) {
|
Chris@0
|
2672 element.checked = !!value;
|
Chris@0
|
2673 },
|
Chris@0
|
2674
|
Chris@0
|
2675 style: function(element, value) {
|
Chris@0
|
2676 element.style.cssText = value ? value : '';
|
Chris@0
|
2677 }
|
Chris@0
|
2678 }
|
Chris@0
|
2679 };
|
Chris@0
|
2680
|
Chris@0
|
2681 Element._attributeTranslations.has = {};
|
Chris@0
|
2682
|
Chris@0
|
2683 $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
|
Chris@0
|
2684 'encType maxLength readOnly longDesc frameBorder').each(function(attr) {
|
Chris@0
|
2685 Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
|
Chris@0
|
2686 Element._attributeTranslations.has[attr.toLowerCase()] = attr;
|
Chris@0
|
2687 });
|
Chris@0
|
2688
|
Chris@0
|
2689 (function(v) {
|
Chris@0
|
2690 Object.extend(v, {
|
Chris@441
|
2691 href: v._getAttr2,
|
Chris@441
|
2692 src: v._getAttr2,
|
Chris@0
|
2693 type: v._getAttr,
|
Chris@0
|
2694 action: v._getAttrNode,
|
Chris@0
|
2695 disabled: v._flag,
|
Chris@0
|
2696 checked: v._flag,
|
Chris@0
|
2697 readonly: v._flag,
|
Chris@0
|
2698 multiple: v._flag,
|
Chris@0
|
2699 onload: v._getEv,
|
Chris@0
|
2700 onunload: v._getEv,
|
Chris@0
|
2701 onclick: v._getEv,
|
Chris@0
|
2702 ondblclick: v._getEv,
|
Chris@0
|
2703 onmousedown: v._getEv,
|
Chris@0
|
2704 onmouseup: v._getEv,
|
Chris@0
|
2705 onmouseover: v._getEv,
|
Chris@0
|
2706 onmousemove: v._getEv,
|
Chris@0
|
2707 onmouseout: v._getEv,
|
Chris@0
|
2708 onfocus: v._getEv,
|
Chris@0
|
2709 onblur: v._getEv,
|
Chris@0
|
2710 onkeypress: v._getEv,
|
Chris@0
|
2711 onkeydown: v._getEv,
|
Chris@0
|
2712 onkeyup: v._getEv,
|
Chris@0
|
2713 onsubmit: v._getEv,
|
Chris@0
|
2714 onreset: v._getEv,
|
Chris@0
|
2715 onselect: v._getEv,
|
Chris@0
|
2716 onchange: v._getEv
|
Chris@0
|
2717 });
|
Chris@0
|
2718 })(Element._attributeTranslations.read.values);
|
Chris@441
|
2719
|
Chris@441
|
2720 if (Prototype.BrowserFeatures.ElementExtensions) {
|
Chris@441
|
2721 (function() {
|
Chris@441
|
2722 function _descendants(element) {
|
Chris@441
|
2723 var nodes = element.getElementsByTagName('*'), results = [];
|
Chris@441
|
2724 for (var i = 0, node; node = nodes[i]; i++)
|
Chris@441
|
2725 if (node.tagName !== "!") // Filter out comment nodes.
|
Chris@441
|
2726 results.push(node);
|
Chris@441
|
2727 return results;
|
Chris@441
|
2728 }
|
Chris@441
|
2729
|
Chris@441
|
2730 Element.Methods.down = function(element, expression, index) {
|
Chris@441
|
2731 element = $(element);
|
Chris@441
|
2732 if (arguments.length == 1) return element.firstDescendant();
|
Chris@441
|
2733 return Object.isNumber(expression) ? _descendants(element)[expression] :
|
Chris@441
|
2734 Element.select(element, expression)[index || 0];
|
Chris@441
|
2735 }
|
Chris@441
|
2736 })();
|
Chris@441
|
2737 }
|
Chris@441
|
2738
|
Chris@0
|
2739 }
|
Chris@0
|
2740
|
Chris@0
|
2741 else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {
|
Chris@0
|
2742 Element.Methods.setOpacity = function(element, value) {
|
Chris@0
|
2743 element = $(element);
|
Chris@0
|
2744 element.style.opacity = (value == 1) ? 0.999999 :
|
Chris@0
|
2745 (value === '') ? '' : (value < 0.00001) ? 0 : value;
|
Chris@0
|
2746 return element;
|
Chris@0
|
2747 };
|
Chris@0
|
2748 }
|
Chris@0
|
2749
|
Chris@0
|
2750 else if (Prototype.Browser.WebKit) {
|
Chris@0
|
2751 Element.Methods.setOpacity = function(element, value) {
|
Chris@0
|
2752 element = $(element);
|
Chris@0
|
2753 element.style.opacity = (value == 1 || value === '') ? '' :
|
Chris@0
|
2754 (value < 0.00001) ? 0 : value;
|
Chris@0
|
2755
|
Chris@0
|
2756 if (value == 1)
|
Chris@441
|
2757 if (element.tagName.toUpperCase() == 'IMG' && element.width) {
|
Chris@0
|
2758 element.width++; element.width--;
|
Chris@0
|
2759 } else try {
|
Chris@0
|
2760 var n = document.createTextNode(' ');
|
Chris@0
|
2761 element.appendChild(n);
|
Chris@0
|
2762 element.removeChild(n);
|
Chris@0
|
2763 } catch (e) { }
|
Chris@0
|
2764
|
Chris@0
|
2765 return element;
|
Chris@0
|
2766 };
|
Chris@0
|
2767 }
|
Chris@0
|
2768
|
Chris@441
|
2769 if ('outerHTML' in document.documentElement) {
|
Chris@0
|
2770 Element.Methods.replace = function(element, content) {
|
Chris@0
|
2771 element = $(element);
|
Chris@0
|
2772
|
Chris@0
|
2773 if (content && content.toElement) content = content.toElement();
|
Chris@0
|
2774 if (Object.isElement(content)) {
|
Chris@0
|
2775 element.parentNode.replaceChild(content, element);
|
Chris@0
|
2776 return element;
|
Chris@0
|
2777 }
|
Chris@0
|
2778
|
Chris@0
|
2779 content = Object.toHTML(content);
|
Chris@0
|
2780 var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
|
Chris@0
|
2781
|
Chris@0
|
2782 if (Element._insertionTranslations.tags[tagName]) {
|
Chris@441
|
2783 var nextSibling = element.next(),
|
Chris@441
|
2784 fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
|
Chris@0
|
2785 parent.removeChild(element);
|
Chris@0
|
2786 if (nextSibling)
|
Chris@0
|
2787 fragments.each(function(node) { parent.insertBefore(node, nextSibling) });
|
Chris@0
|
2788 else
|
Chris@0
|
2789 fragments.each(function(node) { parent.appendChild(node) });
|
Chris@0
|
2790 }
|
Chris@0
|
2791 else element.outerHTML = content.stripScripts();
|
Chris@0
|
2792
|
Chris@0
|
2793 content.evalScripts.bind(content).defer();
|
Chris@0
|
2794 return element;
|
Chris@0
|
2795 };
|
Chris@0
|
2796 }
|
Chris@0
|
2797
|
Chris@0
|
2798 Element._returnOffset = function(l, t) {
|
Chris@0
|
2799 var result = [l, t];
|
Chris@0
|
2800 result.left = l;
|
Chris@0
|
2801 result.top = t;
|
Chris@0
|
2802 return result;
|
Chris@0
|
2803 };
|
Chris@0
|
2804
|
Chris@441
|
2805 Element._getContentFromAnonymousElement = function(tagName, html, force) {
|
Chris@441
|
2806 var div = new Element('div'),
|
Chris@441
|
2807 t = Element._insertionTranslations.tags[tagName];
|
Chris@441
|
2808
|
Chris@441
|
2809 var workaround = false;
|
Chris@441
|
2810 if (t) workaround = true;
|
Chris@441
|
2811 else if (force) {
|
Chris@441
|
2812 workaround = true;
|
Chris@441
|
2813 t = ['', '', 0];
|
Chris@441
|
2814 }
|
Chris@441
|
2815
|
Chris@441
|
2816 if (workaround) {
|
Chris@441
|
2817 div.innerHTML = ' ' + t[0] + html + t[1];
|
Chris@441
|
2818 div.removeChild(div.firstChild);
|
Chris@441
|
2819 for (var i = t[2]; i--; ) {
|
Chris@441
|
2820 div = div.firstChild;
|
Chris@441
|
2821 }
|
Chris@441
|
2822 }
|
Chris@441
|
2823 else {
|
Chris@441
|
2824 div.innerHTML = html;
|
Chris@441
|
2825 }
|
Chris@0
|
2826 return $A(div.childNodes);
|
Chris@0
|
2827 };
|
Chris@0
|
2828
|
Chris@0
|
2829 Element._insertionTranslations = {
|
Chris@0
|
2830 before: function(element, node) {
|
Chris@0
|
2831 element.parentNode.insertBefore(node, element);
|
Chris@0
|
2832 },
|
Chris@0
|
2833 top: function(element, node) {
|
Chris@0
|
2834 element.insertBefore(node, element.firstChild);
|
Chris@0
|
2835 },
|
Chris@0
|
2836 bottom: function(element, node) {
|
Chris@0
|
2837 element.appendChild(node);
|
Chris@0
|
2838 },
|
Chris@0
|
2839 after: function(element, node) {
|
Chris@0
|
2840 element.parentNode.insertBefore(node, element.nextSibling);
|
Chris@0
|
2841 },
|
Chris@0
|
2842 tags: {
|
Chris@0
|
2843 TABLE: ['<table>', '</table>', 1],
|
Chris@0
|
2844 TBODY: ['<table><tbody>', '</tbody></table>', 2],
|
Chris@0
|
2845 TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],
|
Chris@0
|
2846 TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
|
Chris@0
|
2847 SELECT: ['<select>', '</select>', 1]
|
Chris@0
|
2848 }
|
Chris@0
|
2849 };
|
Chris@0
|
2850
|
Chris@0
|
2851 (function() {
|
Chris@441
|
2852 var tags = Element._insertionTranslations.tags;
|
Chris@441
|
2853 Object.extend(tags, {
|
Chris@441
|
2854 THEAD: tags.TBODY,
|
Chris@441
|
2855 TFOOT: tags.TBODY,
|
Chris@441
|
2856 TH: tags.TD
|
Chris@0
|
2857 });
|
Chris@441
|
2858 })();
|
Chris@0
|
2859
|
Chris@0
|
2860 Element.Methods.Simulated = {
|
Chris@0
|
2861 hasAttribute: function(element, attribute) {
|
Chris@0
|
2862 attribute = Element._attributeTranslations.has[attribute] || attribute;
|
Chris@0
|
2863 var node = $(element).getAttributeNode(attribute);
|
Chris@0
|
2864 return !!(node && node.specified);
|
Chris@0
|
2865 }
|
Chris@0
|
2866 };
|
Chris@0
|
2867
|
Chris@0
|
2868 Element.Methods.ByTag = { };
|
Chris@0
|
2869
|
Chris@0
|
2870 Object.extend(Element, Element.Methods);
|
Chris@0
|
2871
|
Chris@441
|
2872 (function(div) {
|
Chris@441
|
2873
|
Chris@441
|
2874 if (!Prototype.BrowserFeatures.ElementExtensions && div['__proto__']) {
|
Chris@441
|
2875 window.HTMLElement = { };
|
Chris@441
|
2876 window.HTMLElement.prototype = div['__proto__'];
|
Chris@441
|
2877 Prototype.BrowserFeatures.ElementExtensions = true;
|
Chris@441
|
2878 }
|
Chris@441
|
2879
|
Chris@441
|
2880 div = null;
|
Chris@441
|
2881
|
Chris@441
|
2882 })(document.createElement('div'));
|
Chris@0
|
2883
|
Chris@0
|
2884 Element.extend = (function() {
|
Chris@441
|
2885
|
Chris@441
|
2886 function checkDeficiency(tagName) {
|
Chris@441
|
2887 if (typeof window.Element != 'undefined') {
|
Chris@441
|
2888 var proto = window.Element.prototype;
|
Chris@441
|
2889 if (proto) {
|
Chris@441
|
2890 var id = '_' + (Math.random()+'').slice(2),
|
Chris@441
|
2891 el = document.createElement(tagName);
|
Chris@441
|
2892 proto[id] = 'x';
|
Chris@441
|
2893 var isBuggy = (el[id] !== 'x');
|
Chris@441
|
2894 delete proto[id];
|
Chris@441
|
2895 el = null;
|
Chris@441
|
2896 return isBuggy;
|
Chris@441
|
2897 }
|
Chris@441
|
2898 }
|
Chris@441
|
2899 return false;
|
Chris@441
|
2900 }
|
Chris@441
|
2901
|
Chris@441
|
2902 function extendElementWith(element, methods) {
|
Chris@441
|
2903 for (var property in methods) {
|
Chris@441
|
2904 var value = methods[property];
|
Chris@0
|
2905 if (Object.isFunction(value) && !(property in element))
|
Chris@0
|
2906 element[property] = value.methodize();
|
Chris@0
|
2907 }
|
Chris@441
|
2908 }
|
Chris@441
|
2909
|
Chris@441
|
2910 var HTMLOBJECTELEMENT_PROTOTYPE_BUGGY = checkDeficiency('object');
|
Chris@441
|
2911
|
Chris@441
|
2912 if (Prototype.BrowserFeatures.SpecificElementExtensions) {
|
Chris@441
|
2913 if (HTMLOBJECTELEMENT_PROTOTYPE_BUGGY) {
|
Chris@441
|
2914 return function(element) {
|
Chris@441
|
2915 if (element && typeof element._extendedByPrototype == 'undefined') {
|
Chris@441
|
2916 var t = element.tagName;
|
Chris@441
|
2917 if (t && (/^(?:object|applet|embed)$/i.test(t))) {
|
Chris@441
|
2918 extendElementWith(element, Element.Methods);
|
Chris@441
|
2919 extendElementWith(element, Element.Methods.Simulated);
|
Chris@441
|
2920 extendElementWith(element, Element.Methods.ByTag[t.toUpperCase()]);
|
Chris@441
|
2921 }
|
Chris@441
|
2922 }
|
Chris@441
|
2923 return element;
|
Chris@441
|
2924 }
|
Chris@441
|
2925 }
|
Chris@441
|
2926 return Prototype.K;
|
Chris@441
|
2927 }
|
Chris@441
|
2928
|
Chris@441
|
2929 var Methods = { }, ByTag = Element.Methods.ByTag;
|
Chris@441
|
2930
|
Chris@441
|
2931 var extend = Object.extend(function(element) {
|
Chris@441
|
2932 if (!element || typeof element._extendedByPrototype != 'undefined' ||
|
Chris@441
|
2933 element.nodeType != 1 || element == window) return element;
|
Chris@441
|
2934
|
Chris@441
|
2935 var methods = Object.clone(Methods),
|
Chris@441
|
2936 tagName = element.tagName.toUpperCase();
|
Chris@441
|
2937
|
Chris@441
|
2938 if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
|
Chris@441
|
2939
|
Chris@441
|
2940 extendElementWith(element, methods);
|
Chris@0
|
2941
|
Chris@0
|
2942 element._extendedByPrototype = Prototype.emptyFunction;
|
Chris@0
|
2943 return element;
|
Chris@0
|
2944
|
Chris@0
|
2945 }, {
|
Chris@0
|
2946 refresh: function() {
|
Chris@0
|
2947 if (!Prototype.BrowserFeatures.ElementExtensions) {
|
Chris@0
|
2948 Object.extend(Methods, Element.Methods);
|
Chris@0
|
2949 Object.extend(Methods, Element.Methods.Simulated);
|
Chris@0
|
2950 }
|
Chris@0
|
2951 }
|
Chris@0
|
2952 });
|
Chris@0
|
2953
|
Chris@0
|
2954 extend.refresh();
|
Chris@0
|
2955 return extend;
|
Chris@0
|
2956 })();
|
Chris@0
|
2957
|
Chris@441
|
2958 if (document.documentElement.hasAttribute) {
|
Chris@441
|
2959 Element.hasAttribute = function(element, attribute) {
|
Chris@441
|
2960 return element.hasAttribute(attribute);
|
Chris@441
|
2961 };
|
Chris@441
|
2962 }
|
Chris@441
|
2963 else {
|
Chris@441
|
2964 Element.hasAttribute = Element.Methods.Simulated.hasAttribute;
|
Chris@441
|
2965 }
|
Chris@0
|
2966
|
Chris@0
|
2967 Element.addMethods = function(methods) {
|
Chris@0
|
2968 var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
|
Chris@0
|
2969
|
Chris@0
|
2970 if (!methods) {
|
Chris@0
|
2971 Object.extend(Form, Form.Methods);
|
Chris@0
|
2972 Object.extend(Form.Element, Form.Element.Methods);
|
Chris@0
|
2973 Object.extend(Element.Methods.ByTag, {
|
Chris@0
|
2974 "FORM": Object.clone(Form.Methods),
|
Chris@0
|
2975 "INPUT": Object.clone(Form.Element.Methods),
|
Chris@0
|
2976 "SELECT": Object.clone(Form.Element.Methods),
|
Chris@441
|
2977 "TEXTAREA": Object.clone(Form.Element.Methods),
|
Chris@441
|
2978 "BUTTON": Object.clone(Form.Element.Methods)
|
Chris@0
|
2979 });
|
Chris@0
|
2980 }
|
Chris@0
|
2981
|
Chris@0
|
2982 if (arguments.length == 2) {
|
Chris@0
|
2983 var tagName = methods;
|
Chris@0
|
2984 methods = arguments[1];
|
Chris@0
|
2985 }
|
Chris@0
|
2986
|
Chris@0
|
2987 if (!tagName) Object.extend(Element.Methods, methods || { });
|
Chris@0
|
2988 else {
|
Chris@0
|
2989 if (Object.isArray(tagName)) tagName.each(extend);
|
Chris@0
|
2990 else extend(tagName);
|
Chris@0
|
2991 }
|
Chris@0
|
2992
|
Chris@0
|
2993 function extend(tagName) {
|
Chris@0
|
2994 tagName = tagName.toUpperCase();
|
Chris@0
|
2995 if (!Element.Methods.ByTag[tagName])
|
Chris@0
|
2996 Element.Methods.ByTag[tagName] = { };
|
Chris@0
|
2997 Object.extend(Element.Methods.ByTag[tagName], methods);
|
Chris@0
|
2998 }
|
Chris@0
|
2999
|
Chris@0
|
3000 function copy(methods, destination, onlyIfAbsent) {
|
Chris@0
|
3001 onlyIfAbsent = onlyIfAbsent || false;
|
Chris@0
|
3002 for (var property in methods) {
|
Chris@0
|
3003 var value = methods[property];
|
Chris@0
|
3004 if (!Object.isFunction(value)) continue;
|
Chris@0
|
3005 if (!onlyIfAbsent || !(property in destination))
|
Chris@0
|
3006 destination[property] = value.methodize();
|
Chris@0
|
3007 }
|
Chris@0
|
3008 }
|
Chris@0
|
3009
|
Chris@0
|
3010 function findDOMClass(tagName) {
|
Chris@0
|
3011 var klass;
|
Chris@0
|
3012 var trans = {
|
Chris@0
|
3013 "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
|
Chris@0
|
3014 "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
|
Chris@0
|
3015 "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
|
Chris@0
|
3016 "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
|
Chris@0
|
3017 "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
|
Chris@0
|
3018 "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
|
Chris@0
|
3019 "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
|
Chris@0
|
3020 "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
|
Chris@0
|
3021 "FrameSet", "IFRAME": "IFrame"
|
Chris@0
|
3022 };
|
Chris@0
|
3023 if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
|
Chris@0
|
3024 if (window[klass]) return window[klass];
|
Chris@0
|
3025 klass = 'HTML' + tagName + 'Element';
|
Chris@0
|
3026 if (window[klass]) return window[klass];
|
Chris@0
|
3027 klass = 'HTML' + tagName.capitalize() + 'Element';
|
Chris@0
|
3028 if (window[klass]) return window[klass];
|
Chris@0
|
3029
|
Chris@441
|
3030 var element = document.createElement(tagName),
|
Chris@441
|
3031 proto = element['__proto__'] || element.constructor.prototype;
|
Chris@441
|
3032
|
Chris@441
|
3033 element = null;
|
Chris@441
|
3034 return proto;
|
Chris@441
|
3035 }
|
Chris@441
|
3036
|
Chris@441
|
3037 var elementPrototype = window.HTMLElement ? HTMLElement.prototype :
|
Chris@441
|
3038 Element.prototype;
|
Chris@0
|
3039
|
Chris@0
|
3040 if (F.ElementExtensions) {
|
Chris@441
|
3041 copy(Element.Methods, elementPrototype);
|
Chris@441
|
3042 copy(Element.Methods.Simulated, elementPrototype, true);
|
Chris@0
|
3043 }
|
Chris@0
|
3044
|
Chris@0
|
3045 if (F.SpecificElementExtensions) {
|
Chris@0
|
3046 for (var tag in Element.Methods.ByTag) {
|
Chris@0
|
3047 var klass = findDOMClass(tag);
|
Chris@0
|
3048 if (Object.isUndefined(klass)) continue;
|
Chris@0
|
3049 copy(T[tag], klass.prototype);
|
Chris@0
|
3050 }
|
Chris@0
|
3051 }
|
Chris@0
|
3052
|
Chris@0
|
3053 Object.extend(Element, Element.Methods);
|
Chris@0
|
3054 delete Element.ByTag;
|
Chris@0
|
3055
|
Chris@0
|
3056 if (Element.extend.refresh) Element.extend.refresh();
|
Chris@0
|
3057 Element.cache = { };
|
Chris@0
|
3058 };
|
Chris@0
|
3059
|
Chris@441
|
3060
|
Chris@0
|
3061 document.viewport = {
|
Chris@441
|
3062
|
Chris@0
|
3063 getDimensions: function() {
|
Chris@441
|
3064 return { width: this.getWidth(), height: this.getHeight() };
|
Chris@0
|
3065 },
|
Chris@0
|
3066
|
Chris@0
|
3067 getScrollOffsets: function() {
|
Chris@0
|
3068 return Element._returnOffset(
|
Chris@0
|
3069 window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
|
Chris@441
|
3070 window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
|
Chris@0
|
3071 }
|
Chris@0
|
3072 };
|
Chris@441
|
3073
|
Chris@441
|
3074 (function(viewport) {
|
Chris@441
|
3075 var B = Prototype.Browser, doc = document, element, property = {};
|
Chris@441
|
3076
|
Chris@441
|
3077 function getRootElement() {
|
Chris@441
|
3078 if (B.WebKit && !doc.evaluate)
|
Chris@441
|
3079 return document;
|
Chris@441
|
3080
|
Chris@441
|
3081 if (B.Opera && window.parseFloat(window.opera.version()) < 9.5)
|
Chris@441
|
3082 return document.body;
|
Chris@441
|
3083
|
Chris@441
|
3084 return document.documentElement;
|
Chris@441
|
3085 }
|
Chris@441
|
3086
|
Chris@441
|
3087 function define(D) {
|
Chris@441
|
3088 if (!element) element = getRootElement();
|
Chris@441
|
3089
|
Chris@441
|
3090 property[D] = 'client' + D;
|
Chris@441
|
3091
|
Chris@441
|
3092 viewport['get' + D] = function() { return element[property[D]] };
|
Chris@441
|
3093 return viewport['get' + D]();
|
Chris@441
|
3094 }
|
Chris@441
|
3095
|
Chris@441
|
3096 viewport.getWidth = define.curry('Width');
|
Chris@441
|
3097
|
Chris@441
|
3098 viewport.getHeight = define.curry('Height');
|
Chris@441
|
3099 })(document.viewport);
|
Chris@441
|
3100
|
Chris@441
|
3101
|
Chris@441
|
3102 Element.Storage = {
|
Chris@441
|
3103 UID: 1
|
Chris@441
|
3104 };
|
Chris@441
|
3105
|
Chris@441
|
3106 Element.addMethods({
|
Chris@441
|
3107 getStorage: function(element) {
|
Chris@441
|
3108 if (!(element = $(element))) return;
|
Chris@441
|
3109
|
Chris@441
|
3110 var uid;
|
Chris@441
|
3111 if (element === window) {
|
Chris@441
|
3112 uid = 0;
|
Chris@0
|
3113 } else {
|
Chris@441
|
3114 if (typeof element._prototypeUID === "undefined")
|
Chris@441
|
3115 element._prototypeUID = Element.Storage.UID++;
|
Chris@441
|
3116 uid = element._prototypeUID;
|
Chris@0
|
3117 }
|
Chris@0
|
3118
|
Chris@441
|
3119 if (!Element.Storage[uid])
|
Chris@441
|
3120 Element.Storage[uid] = $H();
|
Chris@441
|
3121
|
Chris@441
|
3122 return Element.Storage[uid];
|
Chris@0
|
3123 },
|
Chris@0
|
3124
|
Chris@441
|
3125 store: function(element, key, value) {
|
Chris@441
|
3126 if (!(element = $(element))) return;
|
Chris@441
|
3127
|
Chris@441
|
3128 if (arguments.length === 2) {
|
Chris@441
|
3129 Element.getStorage(element).update(key);
|
Chris@441
|
3130 } else {
|
Chris@441
|
3131 Element.getStorage(element).set(key, value);
|
Chris@441
|
3132 }
|
Chris@441
|
3133
|
Chris@441
|
3134 return element;
|
Chris@441
|
3135 },
|
Chris@441
|
3136
|
Chris@441
|
3137 retrieve: function(element, key, defaultValue) {
|
Chris@441
|
3138 if (!(element = $(element))) return;
|
Chris@441
|
3139 var hash = Element.getStorage(element), value = hash.get(key);
|
Chris@441
|
3140
|
Chris@441
|
3141 if (Object.isUndefined(value)) {
|
Chris@441
|
3142 hash.set(key, defaultValue);
|
Chris@441
|
3143 value = defaultValue;
|
Chris@441
|
3144 }
|
Chris@441
|
3145
|
Chris@441
|
3146 return value;
|
Chris@441
|
3147 },
|
Chris@441
|
3148
|
Chris@441
|
3149 clone: function(element, deep) {
|
Chris@441
|
3150 if (!(element = $(element))) return;
|
Chris@441
|
3151 var clone = element.cloneNode(deep);
|
Chris@441
|
3152 clone._prototypeUID = void 0;
|
Chris@441
|
3153 if (deep) {
|
Chris@441
|
3154 var descendants = Element.select(clone, '*'),
|
Chris@441
|
3155 i = descendants.length;
|
Chris@441
|
3156 while (i--) {
|
Chris@441
|
3157 descendants[i]._prototypeUID = void 0;
|
Chris@441
|
3158 }
|
Chris@441
|
3159 }
|
Chris@441
|
3160 return Element.extend(clone);
|
Chris@441
|
3161 },
|
Chris@441
|
3162
|
Chris@441
|
3163 purge: function(element) {
|
Chris@441
|
3164 if (!(element = $(element))) return;
|
Chris@441
|
3165 var purgeElement = Element._purgeElement;
|
Chris@441
|
3166
|
Chris@441
|
3167 purgeElement(element);
|
Chris@441
|
3168
|
Chris@441
|
3169 var descendants = element.getElementsByTagName('*'),
|
Chris@441
|
3170 i = descendants.length;
|
Chris@441
|
3171
|
Chris@441
|
3172 while (i--) purgeElement(descendants[i]);
|
Chris@441
|
3173
|
Chris@441
|
3174 return null;
|
Chris@441
|
3175 }
|
Chris@441
|
3176 });
|
Chris@441
|
3177
|
Chris@441
|
3178 (function() {
|
Chris@441
|
3179
|
Chris@441
|
3180 function toDecimal(pctString) {
|
Chris@441
|
3181 var match = pctString.match(/^(\d+)%?$/i);
|
Chris@441
|
3182 if (!match) return null;
|
Chris@441
|
3183 return (Number(match[1]) / 100);
|
Chris@441
|
3184 }
|
Chris@441
|
3185
|
Chris@441
|
3186 function getPixelValue(value, property, context) {
|
Chris@441
|
3187 var element = null;
|
Chris@441
|
3188 if (Object.isElement(value)) {
|
Chris@441
|
3189 element = value;
|
Chris@441
|
3190 value = element.getStyle(property);
|
Chris@441
|
3191 }
|
Chris@441
|
3192
|
Chris@441
|
3193 if (value === null) {
|
Chris@441
|
3194 return null;
|
Chris@441
|
3195 }
|
Chris@441
|
3196
|
Chris@441
|
3197 if ((/^(?:-)?\d+(\.\d+)?(px)?$/i).test(value)) {
|
Chris@441
|
3198 return window.parseFloat(value);
|
Chris@441
|
3199 }
|
Chris@441
|
3200
|
Chris@441
|
3201 var isPercentage = value.include('%'), isViewport = (context === document.viewport);
|
Chris@441
|
3202
|
Chris@441
|
3203 if (/\d/.test(value) && element && element.runtimeStyle && !(isPercentage && isViewport)) {
|
Chris@441
|
3204 var style = element.style.left, rStyle = element.runtimeStyle.left;
|
Chris@441
|
3205 element.runtimeStyle.left = element.currentStyle.left;
|
Chris@441
|
3206 element.style.left = value || 0;
|
Chris@441
|
3207 value = element.style.pixelLeft;
|
Chris@441
|
3208 element.style.left = style;
|
Chris@441
|
3209 element.runtimeStyle.left = rStyle;
|
Chris@441
|
3210
|
Chris@441
|
3211 return value;
|
Chris@441
|
3212 }
|
Chris@441
|
3213
|
Chris@441
|
3214 if (element && isPercentage) {
|
Chris@441
|
3215 context = context || element.parentNode;
|
Chris@441
|
3216 var decimal = toDecimal(value);
|
Chris@441
|
3217 var whole = null;
|
Chris@441
|
3218 var position = element.getStyle('position');
|
Chris@441
|
3219
|
Chris@441
|
3220 var isHorizontal = property.include('left') || property.include('right') ||
|
Chris@441
|
3221 property.include('width');
|
Chris@441
|
3222
|
Chris@441
|
3223 var isVertical = property.include('top') || property.include('bottom') ||
|
Chris@441
|
3224 property.include('height');
|
Chris@441
|
3225
|
Chris@441
|
3226 if (context === document.viewport) {
|
Chris@441
|
3227 if (isHorizontal) {
|
Chris@441
|
3228 whole = document.viewport.getWidth();
|
Chris@441
|
3229 } else if (isVertical) {
|
Chris@441
|
3230 whole = document.viewport.getHeight();
|
Chris@441
|
3231 }
|
Chris@441
|
3232 } else {
|
Chris@441
|
3233 if (isHorizontal) {
|
Chris@441
|
3234 whole = $(context).measure('width');
|
Chris@441
|
3235 } else if (isVertical) {
|
Chris@441
|
3236 whole = $(context).measure('height');
|
Chris@441
|
3237 }
|
Chris@441
|
3238 }
|
Chris@441
|
3239
|
Chris@441
|
3240 return (whole === null) ? 0 : whole * decimal;
|
Chris@441
|
3241 }
|
Chris@441
|
3242
|
Chris@441
|
3243 return 0;
|
Chris@441
|
3244 }
|
Chris@441
|
3245
|
Chris@441
|
3246 function toCSSPixels(number) {
|
Chris@441
|
3247 if (Object.isString(number) && number.endsWith('px')) {
|
Chris@441
|
3248 return number;
|
Chris@441
|
3249 }
|
Chris@441
|
3250 return number + 'px';
|
Chris@441
|
3251 }
|
Chris@441
|
3252
|
Chris@441
|
3253 function isDisplayed(element) {
|
Chris@441
|
3254 var originalElement = element;
|
Chris@441
|
3255 while (element && element.parentNode) {
|
Chris@441
|
3256 var display = element.getStyle('display');
|
Chris@441
|
3257 if (display === 'none') {
|
Chris@441
|
3258 return false;
|
Chris@441
|
3259 }
|
Chris@441
|
3260 element = $(element.parentNode);
|
Chris@441
|
3261 }
|
Chris@0
|
3262 return true;
|
Chris@441
|
3263 }
|
Chris@441
|
3264
|
Chris@441
|
3265 var hasLayout = Prototype.K;
|
Chris@441
|
3266 if ('currentStyle' in document.documentElement) {
|
Chris@441
|
3267 hasLayout = function(element) {
|
Chris@441
|
3268 if (!element.currentStyle.hasLayout) {
|
Chris@441
|
3269 element.style.zoom = 1;
|
Chris@441
|
3270 }
|
Chris@441
|
3271 return element;
|
Chris@441
|
3272 };
|
Chris@441
|
3273 }
|
Chris@441
|
3274
|
Chris@441
|
3275 function cssNameFor(key) {
|
Chris@441
|
3276 if (key.include('border')) key = key + '-width';
|
Chris@441
|
3277 return key.camelize();
|
Chris@441
|
3278 }
|
Chris@441
|
3279
|
Chris@441
|
3280 Element.Layout = Class.create(Hash, {
|
Chris@441
|
3281 initialize: function($super, element, preCompute) {
|
Chris@441
|
3282 $super();
|
Chris@441
|
3283 this.element = $(element);
|
Chris@441
|
3284
|
Chris@441
|
3285 Element.Layout.PROPERTIES.each( function(property) {
|
Chris@441
|
3286 this._set(property, null);
|
Chris@441
|
3287 }, this);
|
Chris@441
|
3288
|
Chris@441
|
3289 if (preCompute) {
|
Chris@441
|
3290 this._preComputing = true;
|
Chris@441
|
3291 this._begin();
|
Chris@441
|
3292 Element.Layout.PROPERTIES.each( this._compute, this );
|
Chris@441
|
3293 this._end();
|
Chris@441
|
3294 this._preComputing = false;
|
Chris@441
|
3295 }
|
Chris@441
|
3296 },
|
Chris@441
|
3297
|
Chris@441
|
3298 _set: function(property, value) {
|
Chris@441
|
3299 return Hash.prototype.set.call(this, property, value);
|
Chris@441
|
3300 },
|
Chris@441
|
3301
|
Chris@441
|
3302 set: function(property, value) {
|
Chris@441
|
3303 throw "Properties of Element.Layout are read-only.";
|
Chris@441
|
3304 },
|
Chris@441
|
3305
|
Chris@441
|
3306 get: function($super, property) {
|
Chris@441
|
3307 var value = $super(property);
|
Chris@441
|
3308 return value === null ? this._compute(property) : value;
|
Chris@441
|
3309 },
|
Chris@441
|
3310
|
Chris@441
|
3311 _begin: function() {
|
Chris@441
|
3312 if (this._prepared) return;
|
Chris@441
|
3313
|
Chris@441
|
3314 var element = this.element;
|
Chris@441
|
3315 if (isDisplayed(element)) {
|
Chris@441
|
3316 this._prepared = true;
|
Chris@441
|
3317 return;
|
Chris@441
|
3318 }
|
Chris@441
|
3319
|
Chris@441
|
3320 var originalStyles = {
|
Chris@441
|
3321 position: element.style.position || '',
|
Chris@441
|
3322 width: element.style.width || '',
|
Chris@441
|
3323 visibility: element.style.visibility || '',
|
Chris@441
|
3324 display: element.style.display || ''
|
Chris@441
|
3325 };
|
Chris@441
|
3326
|
Chris@441
|
3327 element.store('prototype_original_styles', originalStyles);
|
Chris@441
|
3328
|
Chris@441
|
3329 var position = element.getStyle('position'),
|
Chris@441
|
3330 width = element.getStyle('width');
|
Chris@441
|
3331
|
Chris@441
|
3332 if (width === "0px" || width === null) {
|
Chris@441
|
3333 element.style.display = 'block';
|
Chris@441
|
3334 width = element.getStyle('width');
|
Chris@441
|
3335 }
|
Chris@441
|
3336
|
Chris@441
|
3337 var context = (position === 'fixed') ? document.viewport :
|
Chris@441
|
3338 element.parentNode;
|
Chris@441
|
3339
|
Chris@441
|
3340 element.setStyle({
|
Chris@441
|
3341 position: 'absolute',
|
Chris@441
|
3342 visibility: 'hidden',
|
Chris@441
|
3343 display: 'block'
|
Chris@441
|
3344 });
|
Chris@441
|
3345
|
Chris@441
|
3346 var positionedWidth = element.getStyle('width');
|
Chris@441
|
3347
|
Chris@441
|
3348 var newWidth;
|
Chris@441
|
3349 if (width && (positionedWidth === width)) {
|
Chris@441
|
3350 newWidth = getPixelValue(element, 'width', context);
|
Chris@441
|
3351 } else if (position === 'absolute' || position === 'fixed') {
|
Chris@441
|
3352 newWidth = getPixelValue(element, 'width', context);
|
Chris@441
|
3353 } else {
|
Chris@441
|
3354 var parent = element.parentNode, pLayout = $(parent).getLayout();
|
Chris@441
|
3355
|
Chris@441
|
3356 newWidth = pLayout.get('width') -
|
Chris@441
|
3357 this.get('margin-left') -
|
Chris@441
|
3358 this.get('border-left') -
|
Chris@441
|
3359 this.get('padding-left') -
|
Chris@441
|
3360 this.get('padding-right') -
|
Chris@441
|
3361 this.get('border-right') -
|
Chris@441
|
3362 this.get('margin-right');
|
Chris@441
|
3363 }
|
Chris@441
|
3364
|
Chris@441
|
3365 element.setStyle({ width: newWidth + 'px' });
|
Chris@441
|
3366
|
Chris@441
|
3367 this._prepared = true;
|
Chris@441
|
3368 },
|
Chris@441
|
3369
|
Chris@441
|
3370 _end: function() {
|
Chris@441
|
3371 var element = this.element;
|
Chris@441
|
3372 var originalStyles = element.retrieve('prototype_original_styles');
|
Chris@441
|
3373 element.store('prototype_original_styles', null);
|
Chris@441
|
3374 element.setStyle(originalStyles);
|
Chris@441
|
3375 this._prepared = false;
|
Chris@441
|
3376 },
|
Chris@441
|
3377
|
Chris@441
|
3378 _compute: function(property) {
|
Chris@441
|
3379 var COMPUTATIONS = Element.Layout.COMPUTATIONS;
|
Chris@441
|
3380 if (!(property in COMPUTATIONS)) {
|
Chris@441
|
3381 throw "Property not found.";
|
Chris@441
|
3382 }
|
Chris@441
|
3383
|
Chris@441
|
3384 return this._set(property, COMPUTATIONS[property].call(this, this.element));
|
Chris@441
|
3385 },
|
Chris@441
|
3386
|
Chris@441
|
3387 toObject: function() {
|
Chris@441
|
3388 var args = $A(arguments);
|
Chris@441
|
3389 var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
|
Chris@441
|
3390 args.join(' ').split(' ');
|
Chris@441
|
3391 var obj = {};
|
Chris@441
|
3392 keys.each( function(key) {
|
Chris@441
|
3393 if (!Element.Layout.PROPERTIES.include(key)) return;
|
Chris@441
|
3394 var value = this.get(key);
|
Chris@441
|
3395 if (value != null) obj[key] = value;
|
Chris@441
|
3396 }, this);
|
Chris@441
|
3397 return obj;
|
Chris@441
|
3398 },
|
Chris@441
|
3399
|
Chris@441
|
3400 toHash: function() {
|
Chris@441
|
3401 var obj = this.toObject.apply(this, arguments);
|
Chris@441
|
3402 return new Hash(obj);
|
Chris@441
|
3403 },
|
Chris@441
|
3404
|
Chris@441
|
3405 toCSS: function() {
|
Chris@441
|
3406 var args = $A(arguments);
|
Chris@441
|
3407 var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
|
Chris@441
|
3408 args.join(' ').split(' ');
|
Chris@441
|
3409 var css = {};
|
Chris@441
|
3410
|
Chris@441
|
3411 keys.each( function(key) {
|
Chris@441
|
3412 if (!Element.Layout.PROPERTIES.include(key)) return;
|
Chris@441
|
3413 if (Element.Layout.COMPOSITE_PROPERTIES.include(key)) return;
|
Chris@441
|
3414
|
Chris@441
|
3415 var value = this.get(key);
|
Chris@441
|
3416 if (value != null) css[cssNameFor(key)] = value + 'px';
|
Chris@441
|
3417 }, this);
|
Chris@441
|
3418 return css;
|
Chris@441
|
3419 },
|
Chris@441
|
3420
|
Chris@441
|
3421 inspect: function() {
|
Chris@441
|
3422 return "#<Element.Layout>";
|
Chris@0
|
3423 }
|
Chris@441
|
3424 });
|
Chris@441
|
3425
|
Chris@441
|
3426 Object.extend(Element.Layout, {
|
Chris@441
|
3427 PROPERTIES: $w('height width top left right bottom border-left border-right border-top border-bottom padding-left padding-right padding-top padding-bottom margin-top margin-bottom margin-left margin-right padding-box-width padding-box-height border-box-width border-box-height margin-box-width margin-box-height'),
|
Chris@441
|
3428
|
Chris@441
|
3429 COMPOSITE_PROPERTIES: $w('padding-box-width padding-box-height margin-box-width margin-box-height border-box-width border-box-height'),
|
Chris@441
|
3430
|
Chris@441
|
3431 COMPUTATIONS: {
|
Chris@441
|
3432 'height': function(element) {
|
Chris@441
|
3433 if (!this._preComputing) this._begin();
|
Chris@441
|
3434
|
Chris@441
|
3435 var bHeight = this.get('border-box-height');
|
Chris@441
|
3436 if (bHeight <= 0) {
|
Chris@441
|
3437 if (!this._preComputing) this._end();
|
Chris@441
|
3438 return 0;
|
Chris@441
|
3439 }
|
Chris@441
|
3440
|
Chris@441
|
3441 var bTop = this.get('border-top'),
|
Chris@441
|
3442 bBottom = this.get('border-bottom');
|
Chris@441
|
3443
|
Chris@441
|
3444 var pTop = this.get('padding-top'),
|
Chris@441
|
3445 pBottom = this.get('padding-bottom');
|
Chris@441
|
3446
|
Chris@441
|
3447 if (!this._preComputing) this._end();
|
Chris@441
|
3448
|
Chris@441
|
3449 return bHeight - bTop - bBottom - pTop - pBottom;
|
Chris@441
|
3450 },
|
Chris@441
|
3451
|
Chris@441
|
3452 'width': function(element) {
|
Chris@441
|
3453 if (!this._preComputing) this._begin();
|
Chris@441
|
3454
|
Chris@441
|
3455 var bWidth = this.get('border-box-width');
|
Chris@441
|
3456 if (bWidth <= 0) {
|
Chris@441
|
3457 if (!this._preComputing) this._end();
|
Chris@441
|
3458 return 0;
|
Chris@441
|
3459 }
|
Chris@441
|
3460
|
Chris@441
|
3461 var bLeft = this.get('border-left'),
|
Chris@441
|
3462 bRight = this.get('border-right');
|
Chris@441
|
3463
|
Chris@441
|
3464 var pLeft = this.get('padding-left'),
|
Chris@441
|
3465 pRight = this.get('padding-right');
|
Chris@441
|
3466
|
Chris@441
|
3467 if (!this._preComputing) this._end();
|
Chris@441
|
3468
|
Chris@441
|
3469 return bWidth - bLeft - bRight - pLeft - pRight;
|
Chris@441
|
3470 },
|
Chris@441
|
3471
|
Chris@441
|
3472 'padding-box-height': function(element) {
|
Chris@441
|
3473 var height = this.get('height'),
|
Chris@441
|
3474 pTop = this.get('padding-top'),
|
Chris@441
|
3475 pBottom = this.get('padding-bottom');
|
Chris@441
|
3476
|
Chris@441
|
3477 return height + pTop + pBottom;
|
Chris@441
|
3478 },
|
Chris@441
|
3479
|
Chris@441
|
3480 'padding-box-width': function(element) {
|
Chris@441
|
3481 var width = this.get('width'),
|
Chris@441
|
3482 pLeft = this.get('padding-left'),
|
Chris@441
|
3483 pRight = this.get('padding-right');
|
Chris@441
|
3484
|
Chris@441
|
3485 return width + pLeft + pRight;
|
Chris@441
|
3486 },
|
Chris@441
|
3487
|
Chris@441
|
3488 'border-box-height': function(element) {
|
Chris@441
|
3489 if (!this._preComputing) this._begin();
|
Chris@441
|
3490 var height = element.offsetHeight;
|
Chris@441
|
3491 if (!this._preComputing) this._end();
|
Chris@441
|
3492 return height;
|
Chris@441
|
3493 },
|
Chris@441
|
3494
|
Chris@441
|
3495 'border-box-width': function(element) {
|
Chris@441
|
3496 if (!this._preComputing) this._begin();
|
Chris@441
|
3497 var width = element.offsetWidth;
|
Chris@441
|
3498 if (!this._preComputing) this._end();
|
Chris@441
|
3499 return width;
|
Chris@441
|
3500 },
|
Chris@441
|
3501
|
Chris@441
|
3502 'margin-box-height': function(element) {
|
Chris@441
|
3503 var bHeight = this.get('border-box-height'),
|
Chris@441
|
3504 mTop = this.get('margin-top'),
|
Chris@441
|
3505 mBottom = this.get('margin-bottom');
|
Chris@441
|
3506
|
Chris@441
|
3507 if (bHeight <= 0) return 0;
|
Chris@441
|
3508
|
Chris@441
|
3509 return bHeight + mTop + mBottom;
|
Chris@441
|
3510 },
|
Chris@441
|
3511
|
Chris@441
|
3512 'margin-box-width': function(element) {
|
Chris@441
|
3513 var bWidth = this.get('border-box-width'),
|
Chris@441
|
3514 mLeft = this.get('margin-left'),
|
Chris@441
|
3515 mRight = this.get('margin-right');
|
Chris@441
|
3516
|
Chris@441
|
3517 if (bWidth <= 0) return 0;
|
Chris@441
|
3518
|
Chris@441
|
3519 return bWidth + mLeft + mRight;
|
Chris@441
|
3520 },
|
Chris@441
|
3521
|
Chris@441
|
3522 'top': function(element) {
|
Chris@441
|
3523 var offset = element.positionedOffset();
|
Chris@441
|
3524 return offset.top;
|
Chris@441
|
3525 },
|
Chris@441
|
3526
|
Chris@441
|
3527 'bottom': function(element) {
|
Chris@441
|
3528 var offset = element.positionedOffset(),
|
Chris@441
|
3529 parent = element.getOffsetParent(),
|
Chris@441
|
3530 pHeight = parent.measure('height');
|
Chris@441
|
3531
|
Chris@441
|
3532 var mHeight = this.get('border-box-height');
|
Chris@441
|
3533
|
Chris@441
|
3534 return pHeight - mHeight - offset.top;
|
Chris@441
|
3535 },
|
Chris@441
|
3536
|
Chris@441
|
3537 'left': function(element) {
|
Chris@441
|
3538 var offset = element.positionedOffset();
|
Chris@441
|
3539 return offset.left;
|
Chris@441
|
3540 },
|
Chris@441
|
3541
|
Chris@441
|
3542 'right': function(element) {
|
Chris@441
|
3543 var offset = element.positionedOffset(),
|
Chris@441
|
3544 parent = element.getOffsetParent(),
|
Chris@441
|
3545 pWidth = parent.measure('width');
|
Chris@441
|
3546
|
Chris@441
|
3547 var mWidth = this.get('border-box-width');
|
Chris@441
|
3548
|
Chris@441
|
3549 return pWidth - mWidth - offset.left;
|
Chris@441
|
3550 },
|
Chris@441
|
3551
|
Chris@441
|
3552 'padding-top': function(element) {
|
Chris@441
|
3553 return getPixelValue(element, 'paddingTop');
|
Chris@441
|
3554 },
|
Chris@441
|
3555
|
Chris@441
|
3556 'padding-bottom': function(element) {
|
Chris@441
|
3557 return getPixelValue(element, 'paddingBottom');
|
Chris@441
|
3558 },
|
Chris@441
|
3559
|
Chris@441
|
3560 'padding-left': function(element) {
|
Chris@441
|
3561 return getPixelValue(element, 'paddingLeft');
|
Chris@441
|
3562 },
|
Chris@441
|
3563
|
Chris@441
|
3564 'padding-right': function(element) {
|
Chris@441
|
3565 return getPixelValue(element, 'paddingRight');
|
Chris@441
|
3566 },
|
Chris@441
|
3567
|
Chris@441
|
3568 'border-top': function(element) {
|
Chris@441
|
3569 return getPixelValue(element, 'borderTopWidth');
|
Chris@441
|
3570 },
|
Chris@441
|
3571
|
Chris@441
|
3572 'border-bottom': function(element) {
|
Chris@441
|
3573 return getPixelValue(element, 'borderBottomWidth');
|
Chris@441
|
3574 },
|
Chris@441
|
3575
|
Chris@441
|
3576 'border-left': function(element) {
|
Chris@441
|
3577 return getPixelValue(element, 'borderLeftWidth');
|
Chris@441
|
3578 },
|
Chris@441
|
3579
|
Chris@441
|
3580 'border-right': function(element) {
|
Chris@441
|
3581 return getPixelValue(element, 'borderRightWidth');
|
Chris@441
|
3582 },
|
Chris@441
|
3583
|
Chris@441
|
3584 'margin-top': function(element) {
|
Chris@441
|
3585 return getPixelValue(element, 'marginTop');
|
Chris@441
|
3586 },
|
Chris@441
|
3587
|
Chris@441
|
3588 'margin-bottom': function(element) {
|
Chris@441
|
3589 return getPixelValue(element, 'marginBottom');
|
Chris@441
|
3590 },
|
Chris@441
|
3591
|
Chris@441
|
3592 'margin-left': function(element) {
|
Chris@441
|
3593 return getPixelValue(element, 'marginLeft');
|
Chris@441
|
3594 },
|
Chris@441
|
3595
|
Chris@441
|
3596 'margin-right': function(element) {
|
Chris@441
|
3597 return getPixelValue(element, 'marginRight');
|
Chris@441
|
3598 }
|
Chris@0
|
3599 }
|
Chris@441
|
3600 });
|
Chris@441
|
3601
|
Chris@441
|
3602 if ('getBoundingClientRect' in document.documentElement) {
|
Chris@441
|
3603 Object.extend(Element.Layout.COMPUTATIONS, {
|
Chris@441
|
3604 'right': function(element) {
|
Chris@441
|
3605 var parent = hasLayout(element.getOffsetParent());
|
Chris@441
|
3606 var rect = element.getBoundingClientRect(),
|
Chris@441
|
3607 pRect = parent.getBoundingClientRect();
|
Chris@441
|
3608
|
Chris@441
|
3609 return (pRect.right - rect.right).round();
|
Chris@441
|
3610 },
|
Chris@441
|
3611
|
Chris@441
|
3612 'bottom': function(element) {
|
Chris@441
|
3613 var parent = hasLayout(element.getOffsetParent());
|
Chris@441
|
3614 var rect = element.getBoundingClientRect(),
|
Chris@441
|
3615 pRect = parent.getBoundingClientRect();
|
Chris@441
|
3616
|
Chris@441
|
3617 return (pRect.bottom - rect.bottom).round();
|
Chris@441
|
3618 }
|
Chris@441
|
3619 });
|
Chris@441
|
3620 }
|
Chris@441
|
3621
|
Chris@441
|
3622 Element.Offset = Class.create({
|
Chris@441
|
3623 initialize: function(left, top) {
|
Chris@441
|
3624 this.left = left.round();
|
Chris@441
|
3625 this.top = top.round();
|
Chris@441
|
3626
|
Chris@441
|
3627 this[0] = this.left;
|
Chris@441
|
3628 this[1] = this.top;
|
Chris@441
|
3629 },
|
Chris@441
|
3630
|
Chris@441
|
3631 relativeTo: function(offset) {
|
Chris@441
|
3632 return new Element.Offset(
|
Chris@441
|
3633 this.left - offset.left,
|
Chris@441
|
3634 this.top - offset.top
|
Chris@441
|
3635 );
|
Chris@441
|
3636 },
|
Chris@441
|
3637
|
Chris@441
|
3638 inspect: function() {
|
Chris@441
|
3639 return "#<Element.Offset left: #{left} top: #{top}>".interpolate(this);
|
Chris@441
|
3640 },
|
Chris@441
|
3641
|
Chris@441
|
3642 toString: function() {
|
Chris@441
|
3643 return "[#{left}, #{top}]".interpolate(this);
|
Chris@441
|
3644 },
|
Chris@441
|
3645
|
Chris@441
|
3646 toArray: function() {
|
Chris@441
|
3647 return [this.left, this.top];
|
Chris@441
|
3648 }
|
Chris@441
|
3649 });
|
Chris@441
|
3650
|
Chris@441
|
3651 function getLayout(element, preCompute) {
|
Chris@441
|
3652 return new Element.Layout(element, preCompute);
|
Chris@441
|
3653 }
|
Chris@441
|
3654
|
Chris@441
|
3655 function measure(element, property) {
|
Chris@441
|
3656 return $(element).getLayout().get(property);
|
Chris@441
|
3657 }
|
Chris@441
|
3658
|
Chris@441
|
3659 function getDimensions(element) {
|
Chris@441
|
3660 element = $(element);
|
Chris@441
|
3661 var display = Element.getStyle(element, 'display');
|
Chris@441
|
3662
|
Chris@441
|
3663 if (display && display !== 'none') {
|
Chris@441
|
3664 return { width: element.offsetWidth, height: element.offsetHeight };
|
Chris@441
|
3665 }
|
Chris@441
|
3666
|
Chris@441
|
3667 var style = element.style;
|
Chris@441
|
3668 var originalStyles = {
|
Chris@441
|
3669 visibility: style.visibility,
|
Chris@441
|
3670 position: style.position,
|
Chris@441
|
3671 display: style.display
|
Chris@441
|
3672 };
|
Chris@441
|
3673
|
Chris@441
|
3674 var newStyles = {
|
Chris@441
|
3675 visibility: 'hidden',
|
Chris@441
|
3676 display: 'block'
|
Chris@441
|
3677 };
|
Chris@441
|
3678
|
Chris@441
|
3679 if (originalStyles.position !== 'fixed')
|
Chris@441
|
3680 newStyles.position = 'absolute';
|
Chris@441
|
3681
|
Chris@441
|
3682 Element.setStyle(element, newStyles);
|
Chris@441
|
3683
|
Chris@441
|
3684 var dimensions = {
|
Chris@441
|
3685 width: element.offsetWidth,
|
Chris@441
|
3686 height: element.offsetHeight
|
Chris@441
|
3687 };
|
Chris@441
|
3688
|
Chris@441
|
3689 Element.setStyle(element, originalStyles);
|
Chris@441
|
3690
|
Chris@441
|
3691 return dimensions;
|
Chris@441
|
3692 }
|
Chris@441
|
3693
|
Chris@441
|
3694 function getOffsetParent(element) {
|
Chris@441
|
3695 element = $(element);
|
Chris@441
|
3696
|
Chris@441
|
3697 if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element))
|
Chris@441
|
3698 return $(document.body);
|
Chris@441
|
3699
|
Chris@441
|
3700 var isInline = (Element.getStyle(element, 'display') === 'inline');
|
Chris@441
|
3701 if (!isInline && element.offsetParent) return $(element.offsetParent);
|
Chris@441
|
3702
|
Chris@441
|
3703 while ((element = element.parentNode) && element !== document.body) {
|
Chris@441
|
3704 if (Element.getStyle(element, 'position') !== 'static') {
|
Chris@441
|
3705 return isHtml(element) ? $(document.body) : $(element);
|
Chris@441
|
3706 }
|
Chris@441
|
3707 }
|
Chris@441
|
3708
|
Chris@441
|
3709 return $(document.body);
|
Chris@441
|
3710 }
|
Chris@441
|
3711
|
Chris@441
|
3712
|
Chris@441
|
3713 function cumulativeOffset(element) {
|
Chris@441
|
3714 element = $(element);
|
Chris@441
|
3715 var valueT = 0, valueL = 0;
|
Chris@441
|
3716 if (element.parentNode) {
|
Chris@441
|
3717 do {
|
Chris@441
|
3718 valueT += element.offsetTop || 0;
|
Chris@441
|
3719 valueL += element.offsetLeft || 0;
|
Chris@441
|
3720 element = element.offsetParent;
|
Chris@441
|
3721 } while (element);
|
Chris@441
|
3722 }
|
Chris@441
|
3723 return new Element.Offset(valueL, valueT);
|
Chris@441
|
3724 }
|
Chris@441
|
3725
|
Chris@441
|
3726 function positionedOffset(element) {
|
Chris@441
|
3727 element = $(element);
|
Chris@441
|
3728
|
Chris@441
|
3729 var layout = element.getLayout();
|
Chris@441
|
3730
|
Chris@441
|
3731 var valueT = 0, valueL = 0;
|
Chris@441
|
3732 do {
|
Chris@441
|
3733 valueT += element.offsetTop || 0;
|
Chris@441
|
3734 valueL += element.offsetLeft || 0;
|
Chris@441
|
3735 element = element.offsetParent;
|
Chris@441
|
3736 if (element) {
|
Chris@441
|
3737 if (isBody(element)) break;
|
Chris@441
|
3738 var p = Element.getStyle(element, 'position');
|
Chris@441
|
3739 if (p !== 'static') break;
|
Chris@441
|
3740 }
|
Chris@441
|
3741 } while (element);
|
Chris@441
|
3742
|
Chris@441
|
3743 valueL -= layout.get('margin-top');
|
Chris@441
|
3744 valueT -= layout.get('margin-left');
|
Chris@441
|
3745
|
Chris@441
|
3746 return new Element.Offset(valueL, valueT);
|
Chris@441
|
3747 }
|
Chris@441
|
3748
|
Chris@441
|
3749 function cumulativeScrollOffset(element) {
|
Chris@441
|
3750 var valueT = 0, valueL = 0;
|
Chris@441
|
3751 do {
|
Chris@441
|
3752 valueT += element.scrollTop || 0;
|
Chris@441
|
3753 valueL += element.scrollLeft || 0;
|
Chris@441
|
3754 element = element.parentNode;
|
Chris@441
|
3755 } while (element);
|
Chris@441
|
3756 return new Element.Offset(valueL, valueT);
|
Chris@441
|
3757 }
|
Chris@441
|
3758
|
Chris@441
|
3759 function viewportOffset(forElement) {
|
Chris@441
|
3760 element = $(element);
|
Chris@441
|
3761 var valueT = 0, valueL = 0, docBody = document.body;
|
Chris@441
|
3762
|
Chris@441
|
3763 var element = forElement;
|
Chris@441
|
3764 do {
|
Chris@441
|
3765 valueT += element.offsetTop || 0;
|
Chris@441
|
3766 valueL += element.offsetLeft || 0;
|
Chris@441
|
3767 if (element.offsetParent == docBody &&
|
Chris@441
|
3768 Element.getStyle(element, 'position') == 'absolute') break;
|
Chris@441
|
3769 } while (element = element.offsetParent);
|
Chris@441
|
3770
|
Chris@441
|
3771 element = forElement;
|
Chris@441
|
3772 do {
|
Chris@441
|
3773 if (element != docBody) {
|
Chris@441
|
3774 valueT -= element.scrollTop || 0;
|
Chris@441
|
3775 valueL -= element.scrollLeft || 0;
|
Chris@441
|
3776 }
|
Chris@441
|
3777 } while (element = element.parentNode);
|
Chris@441
|
3778 return new Element.Offset(valueL, valueT);
|
Chris@441
|
3779 }
|
Chris@441
|
3780
|
Chris@441
|
3781 function absolutize(element) {
|
Chris@441
|
3782 element = $(element);
|
Chris@441
|
3783
|
Chris@441
|
3784 if (Element.getStyle(element, 'position') === 'absolute') {
|
Chris@441
|
3785 return element;
|
Chris@441
|
3786 }
|
Chris@441
|
3787
|
Chris@441
|
3788 var offsetParent = getOffsetParent(element);
|
Chris@441
|
3789 var eOffset = element.viewportOffset(),
|
Chris@441
|
3790 pOffset = offsetParent.viewportOffset();
|
Chris@441
|
3791
|
Chris@441
|
3792 var offset = eOffset.relativeTo(pOffset);
|
Chris@441
|
3793 var layout = element.getLayout();
|
Chris@441
|
3794
|
Chris@441
|
3795 element.store('prototype_absolutize_original_styles', {
|
Chris@441
|
3796 left: element.getStyle('left'),
|
Chris@441
|
3797 top: element.getStyle('top'),
|
Chris@441
|
3798 width: element.getStyle('width'),
|
Chris@441
|
3799 height: element.getStyle('height')
|
Chris@441
|
3800 });
|
Chris@441
|
3801
|
Chris@441
|
3802 element.setStyle({
|
Chris@441
|
3803 position: 'absolute',
|
Chris@441
|
3804 top: offset.top + 'px',
|
Chris@441
|
3805 left: offset.left + 'px',
|
Chris@441
|
3806 width: layout.get('width') + 'px',
|
Chris@441
|
3807 height: layout.get('height') + 'px'
|
Chris@441
|
3808 });
|
Chris@441
|
3809
|
Chris@441
|
3810 return element;
|
Chris@441
|
3811 }
|
Chris@441
|
3812
|
Chris@441
|
3813 function relativize(element) {
|
Chris@441
|
3814 element = $(element);
|
Chris@441
|
3815 if (Element.getStyle(element, 'position') === 'relative') {
|
Chris@441
|
3816 return element;
|
Chris@441
|
3817 }
|
Chris@441
|
3818
|
Chris@441
|
3819 var originalStyles =
|
Chris@441
|
3820 element.retrieve('prototype_absolutize_original_styles');
|
Chris@441
|
3821
|
Chris@441
|
3822 if (originalStyles) element.setStyle(originalStyles);
|
Chris@441
|
3823 return element;
|
Chris@441
|
3824 }
|
Chris@441
|
3825
|
Chris@441
|
3826 if (Prototype.Browser.IE) {
|
Chris@441
|
3827 getOffsetParent = getOffsetParent.wrap(
|
Chris@441
|
3828 function(proceed, element) {
|
Chris@441
|
3829 element = $(element);
|
Chris@441
|
3830
|
Chris@441
|
3831 if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element))
|
Chris@441
|
3832 return $(document.body);
|
Chris@441
|
3833
|
Chris@441
|
3834 var position = element.getStyle('position');
|
Chris@441
|
3835 if (position !== 'static') return proceed(element);
|
Chris@441
|
3836
|
Chris@441
|
3837 element.setStyle({ position: 'relative' });
|
Chris@441
|
3838 var value = proceed(element);
|
Chris@441
|
3839 element.setStyle({ position: position });
|
Chris@441
|
3840 return value;
|
Chris@441
|
3841 }
|
Chris@441
|
3842 );
|
Chris@441
|
3843
|
Chris@441
|
3844 positionedOffset = positionedOffset.wrap(function(proceed, element) {
|
Chris@441
|
3845 element = $(element);
|
Chris@441
|
3846 if (!element.parentNode) return new Element.Offset(0, 0);
|
Chris@441
|
3847 var position = element.getStyle('position');
|
Chris@441
|
3848 if (position !== 'static') return proceed(element);
|
Chris@441
|
3849
|
Chris@441
|
3850 var offsetParent = element.getOffsetParent();
|
Chris@441
|
3851 if (offsetParent && offsetParent.getStyle('position') === 'fixed')
|
Chris@441
|
3852 hasLayout(offsetParent);
|
Chris@441
|
3853
|
Chris@441
|
3854 element.setStyle({ position: 'relative' });
|
Chris@441
|
3855 var value = proceed(element);
|
Chris@441
|
3856 element.setStyle({ position: position });
|
Chris@441
|
3857 return value;
|
Chris@441
|
3858 });
|
Chris@441
|
3859 } else if (Prototype.Browser.Webkit) {
|
Chris@441
|
3860 cumulativeOffset = function(element) {
|
Chris@441
|
3861 element = $(element);
|
Chris@441
|
3862 var valueT = 0, valueL = 0;
|
Chris@441
|
3863 do {
|
Chris@441
|
3864 valueT += element.offsetTop || 0;
|
Chris@441
|
3865 valueL += element.offsetLeft || 0;
|
Chris@441
|
3866 if (element.offsetParent == document.body)
|
Chris@441
|
3867 if (Element.getStyle(element, 'position') == 'absolute') break;
|
Chris@441
|
3868
|
Chris@441
|
3869 element = element.offsetParent;
|
Chris@441
|
3870 } while (element);
|
Chris@441
|
3871
|
Chris@441
|
3872 return new Element.Offset(valueL, valueT);
|
Chris@441
|
3873 };
|
Chris@441
|
3874 }
|
Chris@441
|
3875
|
Chris@441
|
3876
|
Chris@441
|
3877 Element.addMethods({
|
Chris@441
|
3878 getLayout: getLayout,
|
Chris@441
|
3879 measure: measure,
|
Chris@441
|
3880 getDimensions: getDimensions,
|
Chris@441
|
3881 getOffsetParent: getOffsetParent,
|
Chris@441
|
3882 cumulativeOffset: cumulativeOffset,
|
Chris@441
|
3883 positionedOffset: positionedOffset,
|
Chris@441
|
3884 cumulativeScrollOffset: cumulativeScrollOffset,
|
Chris@441
|
3885 viewportOffset: viewportOffset,
|
Chris@441
|
3886 absolutize: absolutize,
|
Chris@441
|
3887 relativize: relativize
|
Chris@441
|
3888 });
|
Chris@441
|
3889
|
Chris@441
|
3890 function isBody(element) {
|
Chris@441
|
3891 return element.nodeName.toUpperCase() === 'BODY';
|
Chris@441
|
3892 }
|
Chris@441
|
3893
|
Chris@441
|
3894 function isHtml(element) {
|
Chris@441
|
3895 return element.nodeName.toUpperCase() === 'HTML';
|
Chris@441
|
3896 }
|
Chris@441
|
3897
|
Chris@441
|
3898 function isDocument(element) {
|
Chris@441
|
3899 return element.nodeType === Node.DOCUMENT_NODE;
|
Chris@441
|
3900 }
|
Chris@441
|
3901
|
Chris@441
|
3902 function isDetached(element) {
|
Chris@441
|
3903 return element !== document.body &&
|
Chris@441
|
3904 !Element.descendantOf(element, document.body);
|
Chris@441
|
3905 }
|
Chris@441
|
3906
|
Chris@441
|
3907 if ('getBoundingClientRect' in document.documentElement) {
|
Chris@441
|
3908 Element.addMethods({
|
Chris@441
|
3909 viewportOffset: function(element) {
|
Chris@441
|
3910 element = $(element);
|
Chris@441
|
3911 if (isDetached(element)) return new Element.Offset(0, 0);
|
Chris@441
|
3912
|
Chris@441
|
3913 var rect = element.getBoundingClientRect(),
|
Chris@441
|
3914 docEl = document.documentElement;
|
Chris@441
|
3915 return new Element.Offset(rect.left - docEl.clientLeft,
|
Chris@441
|
3916 rect.top - docEl.clientTop);
|
Chris@441
|
3917 }
|
Chris@441
|
3918 });
|
Chris@441
|
3919 }
|
Chris@441
|
3920 })();
|
Chris@441
|
3921 window.$$ = function() {
|
Chris@441
|
3922 var expression = $A(arguments).join(', ');
|
Chris@441
|
3923 return Prototype.Selector.select(expression, document);
|
Chris@441
|
3924 };
|
Chris@441
|
3925
|
Chris@441
|
3926 Prototype.Selector = (function() {
|
Chris@441
|
3927
|
Chris@441
|
3928 function select() {
|
Chris@441
|
3929 throw new Error('Method "Prototype.Selector.select" must be defined.');
|
Chris@441
|
3930 }
|
Chris@441
|
3931
|
Chris@441
|
3932 function match() {
|
Chris@441
|
3933 throw new Error('Method "Prototype.Selector.match" must be defined.');
|
Chris@441
|
3934 }
|
Chris@441
|
3935
|
Chris@441
|
3936 function find(elements, expression, index) {
|
Chris@441
|
3937 index = index || 0;
|
Chris@441
|
3938 var match = Prototype.Selector.match, length = elements.length, matchIndex = 0, i;
|
Chris@441
|
3939
|
Chris@441
|
3940 for (i = 0; i < length; i++) {
|
Chris@441
|
3941 if (match(elements[i], expression) && index == matchIndex++) {
|
Chris@441
|
3942 return Element.extend(elements[i]);
|
Chris@441
|
3943 }
|
Chris@441
|
3944 }
|
Chris@441
|
3945 }
|
Chris@441
|
3946
|
Chris@441
|
3947 function extendElements(elements) {
|
Chris@441
|
3948 for (var i = 0, length = elements.length; i < length; i++) {
|
Chris@441
|
3949 Element.extend(elements[i]);
|
Chris@441
|
3950 }
|
Chris@441
|
3951 return elements;
|
Chris@441
|
3952 }
|
Chris@441
|
3953
|
Chris@441
|
3954
|
Chris@441
|
3955 var K = Prototype.K;
|
Chris@441
|
3956
|
Chris@441
|
3957 return {
|
Chris@441
|
3958 select: select,
|
Chris@441
|
3959 match: match,
|
Chris@441
|
3960 find: find,
|
Chris@441
|
3961 extendElements: (Element.extend === K) ? K : extendElements,
|
Chris@441
|
3962 extendElement: Element.extend
|
Chris@441
|
3963 };
|
Chris@441
|
3964 })();
|
Chris@441
|
3965 Prototype._original_property = window.Sizzle;
|
Chris@441
|
3966 /*!
|
Chris@441
|
3967 * Sizzle CSS Selector Engine - v1.0
|
Chris@441
|
3968 * Copyright 2009, The Dojo Foundation
|
Chris@441
|
3969 * Released under the MIT, BSD, and GPL Licenses.
|
Chris@441
|
3970 * More information: http://sizzlejs.com/
|
Chris@441
|
3971 */
|
Chris@441
|
3972 (function(){
|
Chris@441
|
3973
|
Chris@441
|
3974 var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
|
Chris@441
|
3975 done = 0,
|
Chris@441
|
3976 toString = Object.prototype.toString,
|
Chris@441
|
3977 hasDuplicate = false,
|
Chris@441
|
3978 baseHasDuplicate = true;
|
Chris@441
|
3979
|
Chris@441
|
3980 [0, 0].sort(function(){
|
Chris@441
|
3981 baseHasDuplicate = false;
|
Chris@441
|
3982 return 0;
|
Chris@441
|
3983 });
|
Chris@441
|
3984
|
Chris@441
|
3985 var Sizzle = function(selector, context, results, seed) {
|
Chris@441
|
3986 results = results || [];
|
Chris@441
|
3987 var origContext = context = context || document;
|
Chris@441
|
3988
|
Chris@441
|
3989 if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
|
Chris@441
|
3990 return [];
|
Chris@441
|
3991 }
|
Chris@441
|
3992
|
Chris@441
|
3993 if ( !selector || typeof selector !== "string" ) {
|
Chris@441
|
3994 return results;
|
Chris@441
|
3995 }
|
Chris@441
|
3996
|
Chris@441
|
3997 var parts = [], m, set, checkSet, check, mode, extra, prune = true, contextXML = isXML(context),
|
Chris@441
|
3998 soFar = selector;
|
Chris@441
|
3999
|
Chris@441
|
4000 while ( (chunker.exec(""), m = chunker.exec(soFar)) !== null ) {
|
Chris@441
|
4001 soFar = m[3];
|
Chris@441
|
4002
|
Chris@441
|
4003 parts.push( m[1] );
|
Chris@441
|
4004
|
Chris@441
|
4005 if ( m[2] ) {
|
Chris@441
|
4006 extra = m[3];
|
Chris@441
|
4007 break;
|
Chris@441
|
4008 }
|
Chris@441
|
4009 }
|
Chris@441
|
4010
|
Chris@441
|
4011 if ( parts.length > 1 && origPOS.exec( selector ) ) {
|
Chris@441
|
4012 if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
|
Chris@441
|
4013 set = posProcess( parts[0] + parts[1], context );
|
Chris@441
|
4014 } else {
|
Chris@441
|
4015 set = Expr.relative[ parts[0] ] ?
|
Chris@441
|
4016 [ context ] :
|
Chris@441
|
4017 Sizzle( parts.shift(), context );
|
Chris@441
|
4018
|
Chris@441
|
4019 while ( parts.length ) {
|
Chris@441
|
4020 selector = parts.shift();
|
Chris@441
|
4021
|
Chris@441
|
4022 if ( Expr.relative[ selector ] )
|
Chris@441
|
4023 selector += parts.shift();
|
Chris@441
|
4024
|
Chris@441
|
4025 set = posProcess( selector, set );
|
Chris@441
|
4026 }
|
Chris@441
|
4027 }
|
Chris@441
|
4028 } else {
|
Chris@441
|
4029 if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
|
Chris@441
|
4030 Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
|
Chris@441
|
4031 var ret = Sizzle.find( parts.shift(), context, contextXML );
|
Chris@441
|
4032 context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0];
|
Chris@441
|
4033 }
|
Chris@441
|
4034
|
Chris@441
|
4035 if ( context ) {
|
Chris@441
|
4036 var ret = seed ?
|
Chris@441
|
4037 { expr: parts.pop(), set: makeArray(seed) } :
|
Chris@441
|
4038 Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
|
Chris@441
|
4039 set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set;
|
Chris@441
|
4040
|
Chris@441
|
4041 if ( parts.length > 0 ) {
|
Chris@441
|
4042 checkSet = makeArray(set);
|
Chris@441
|
4043 } else {
|
Chris@441
|
4044 prune = false;
|
Chris@441
|
4045 }
|
Chris@441
|
4046
|
Chris@441
|
4047 while ( parts.length ) {
|
Chris@441
|
4048 var cur = parts.pop(), pop = cur;
|
Chris@441
|
4049
|
Chris@441
|
4050 if ( !Expr.relative[ cur ] ) {
|
Chris@441
|
4051 cur = "";
|
Chris@441
|
4052 } else {
|
Chris@441
|
4053 pop = parts.pop();
|
Chris@441
|
4054 }
|
Chris@441
|
4055
|
Chris@441
|
4056 if ( pop == null ) {
|
Chris@441
|
4057 pop = context;
|
Chris@441
|
4058 }
|
Chris@441
|
4059
|
Chris@441
|
4060 Expr.relative[ cur ]( checkSet, pop, contextXML );
|
Chris@441
|
4061 }
|
Chris@441
|
4062 } else {
|
Chris@441
|
4063 checkSet = parts = [];
|
Chris@441
|
4064 }
|
Chris@441
|
4065 }
|
Chris@441
|
4066
|
Chris@441
|
4067 if ( !checkSet ) {
|
Chris@441
|
4068 checkSet = set;
|
Chris@441
|
4069 }
|
Chris@441
|
4070
|
Chris@441
|
4071 if ( !checkSet ) {
|
Chris@441
|
4072 throw "Syntax error, unrecognized expression: " + (cur || selector);
|
Chris@441
|
4073 }
|
Chris@441
|
4074
|
Chris@441
|
4075 if ( toString.call(checkSet) === "[object Array]" ) {
|
Chris@441
|
4076 if ( !prune ) {
|
Chris@441
|
4077 results.push.apply( results, checkSet );
|
Chris@441
|
4078 } else if ( context && context.nodeType === 1 ) {
|
Chris@441
|
4079 for ( var i = 0; checkSet[i] != null; i++ ) {
|
Chris@441
|
4080 if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
|
Chris@441
|
4081 results.push( set[i] );
|
Chris@441
|
4082 }
|
Chris@441
|
4083 }
|
Chris@441
|
4084 } else {
|
Chris@441
|
4085 for ( var i = 0; checkSet[i] != null; i++ ) {
|
Chris@441
|
4086 if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
|
Chris@441
|
4087 results.push( set[i] );
|
Chris@441
|
4088 }
|
Chris@441
|
4089 }
|
Chris@441
|
4090 }
|
Chris@441
|
4091 } else {
|
Chris@441
|
4092 makeArray( checkSet, results );
|
Chris@441
|
4093 }
|
Chris@441
|
4094
|
Chris@441
|
4095 if ( extra ) {
|
Chris@441
|
4096 Sizzle( extra, origContext, results, seed );
|
Chris@441
|
4097 Sizzle.uniqueSort( results );
|
Chris@441
|
4098 }
|
Chris@441
|
4099
|
Chris@441
|
4100 return results;
|
Chris@441
|
4101 };
|
Chris@441
|
4102
|
Chris@441
|
4103 Sizzle.uniqueSort = function(results){
|
Chris@441
|
4104 if ( sortOrder ) {
|
Chris@441
|
4105 hasDuplicate = baseHasDuplicate;
|
Chris@441
|
4106 results.sort(sortOrder);
|
Chris@441
|
4107
|
Chris@441
|
4108 if ( hasDuplicate ) {
|
Chris@441
|
4109 for ( var i = 1; i < results.length; i++ ) {
|
Chris@441
|
4110 if ( results[i] === results[i-1] ) {
|
Chris@441
|
4111 results.splice(i--, 1);
|
Chris@441
|
4112 }
|
Chris@441
|
4113 }
|
Chris@441
|
4114 }
|
Chris@441
|
4115 }
|
Chris@441
|
4116
|
Chris@441
|
4117 return results;
|
Chris@441
|
4118 };
|
Chris@441
|
4119
|
Chris@441
|
4120 Sizzle.matches = function(expr, set){
|
Chris@441
|
4121 return Sizzle(expr, null, null, set);
|
Chris@441
|
4122 };
|
Chris@441
|
4123
|
Chris@441
|
4124 Sizzle.find = function(expr, context, isXML){
|
Chris@441
|
4125 var set, match;
|
Chris@441
|
4126
|
Chris@441
|
4127 if ( !expr ) {
|
Chris@441
|
4128 return [];
|
Chris@441
|
4129 }
|
Chris@441
|
4130
|
Chris@441
|
4131 for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
|
Chris@441
|
4132 var type = Expr.order[i], match;
|
Chris@441
|
4133
|
Chris@441
|
4134 if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
|
Chris@441
|
4135 var left = match[1];
|
Chris@441
|
4136 match.splice(1,1);
|
Chris@441
|
4137
|
Chris@441
|
4138 if ( left.substr( left.length - 1 ) !== "\\" ) {
|
Chris@441
|
4139 match[1] = (match[1] || "").replace(/\\/g, "");
|
Chris@441
|
4140 set = Expr.find[ type ]( match, context, isXML );
|
Chris@441
|
4141 if ( set != null ) {
|
Chris@441
|
4142 expr = expr.replace( Expr.match[ type ], "" );
|
Chris@0
|
4143 break;
|
Chris@0
|
4144 }
|
Chris@0
|
4145 }
|
Chris@0
|
4146 }
|
Chris@441
|
4147 }
|
Chris@441
|
4148
|
Chris@441
|
4149 if ( !set ) {
|
Chris@441
|
4150 set = context.getElementsByTagName("*");
|
Chris@441
|
4151 }
|
Chris@441
|
4152
|
Chris@441
|
4153 return {set: set, expr: expr};
|
Chris@441
|
4154 };
|
Chris@441
|
4155
|
Chris@441
|
4156 Sizzle.filter = function(expr, set, inplace, not){
|
Chris@441
|
4157 var old = expr, result = [], curLoop = set, match, anyFound,
|
Chris@441
|
4158 isXMLFilter = set && set[0] && isXML(set[0]);
|
Chris@441
|
4159
|
Chris@441
|
4160 while ( expr && set.length ) {
|
Chris@441
|
4161 for ( var type in Expr.filter ) {
|
Chris@441
|
4162 if ( (match = Expr.match[ type ].exec( expr )) != null ) {
|
Chris@441
|
4163 var filter = Expr.filter[ type ], found, item;
|
Chris@441
|
4164 anyFound = false;
|
Chris@441
|
4165
|
Chris@441
|
4166 if ( curLoop == result ) {
|
Chris@441
|
4167 result = [];
|
Chris@441
|
4168 }
|
Chris@441
|
4169
|
Chris@441
|
4170 if ( Expr.preFilter[ type ] ) {
|
Chris@441
|
4171 match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
|
Chris@441
|
4172
|
Chris@441
|
4173 if ( !match ) {
|
Chris@441
|
4174 anyFound = found = true;
|
Chris@441
|
4175 } else if ( match === true ) {
|
Chris@441
|
4176 continue;
|
Chris@441
|
4177 }
|
Chris@441
|
4178 }
|
Chris@441
|
4179
|
Chris@441
|
4180 if ( match ) {
|
Chris@441
|
4181 for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
|
Chris@441
|
4182 if ( item ) {
|
Chris@441
|
4183 found = filter( item, match, i, curLoop );
|
Chris@441
|
4184 var pass = not ^ !!found;
|
Chris@441
|
4185
|
Chris@441
|
4186 if ( inplace && found != null ) {
|
Chris@441
|
4187 if ( pass ) {
|
Chris@441
|
4188 anyFound = true;
|
Chris@441
|
4189 } else {
|
Chris@441
|
4190 curLoop[i] = false;
|
Chris@441
|
4191 }
|
Chris@441
|
4192 } else if ( pass ) {
|
Chris@441
|
4193 result.push( item );
|
Chris@441
|
4194 anyFound = true;
|
Chris@441
|
4195 }
|
Chris@441
|
4196 }
|
Chris@441
|
4197 }
|
Chris@441
|
4198 }
|
Chris@441
|
4199
|
Chris@441
|
4200 if ( found !== undefined ) {
|
Chris@441
|
4201 if ( !inplace ) {
|
Chris@441
|
4202 curLoop = result;
|
Chris@441
|
4203 }
|
Chris@441
|
4204
|
Chris@441
|
4205 expr = expr.replace( Expr.match[ type ], "" );
|
Chris@441
|
4206
|
Chris@441
|
4207 if ( !anyFound ) {
|
Chris@441
|
4208 return [];
|
Chris@441
|
4209 }
|
Chris@441
|
4210
|
Chris@0
|
4211 break;
|
Chris@0
|
4212 }
|
Chris@0
|
4213 }
|
Chris@0
|
4214 }
|
Chris@0
|
4215
|
Chris@441
|
4216 if ( expr == old ) {
|
Chris@441
|
4217 if ( anyFound == null ) {
|
Chris@441
|
4218 throw "Syntax error, unrecognized expression: " + expr;
|
Chris@441
|
4219 } else {
|
Chris@441
|
4220 break;
|
Chris@441
|
4221 }
|
Chris@441
|
4222 }
|
Chris@441
|
4223
|
Chris@441
|
4224 old = expr;
|
Chris@441
|
4225 }
|
Chris@441
|
4226
|
Chris@441
|
4227 return curLoop;
|
Chris@441
|
4228 };
|
Chris@441
|
4229
|
Chris@441
|
4230 var Expr = Sizzle.selectors = {
|
Chris@441
|
4231 order: [ "ID", "NAME", "TAG" ],
|
Chris@441
|
4232 match: {
|
Chris@441
|
4233 ID: /#((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
|
Chris@441
|
4234 CLASS: /\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
|
Chris@441
|
4235 NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/,
|
Chris@441
|
4236 ATTR: /\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,
|
Chris@441
|
4237 TAG: /^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/,
|
Chris@441
|
4238 CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,
|
Chris@441
|
4239 POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,
|
Chris@441
|
4240 PSEUDO: /:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/
|
Chris@0
|
4241 },
|
Chris@441
|
4242 leftMatch: {},
|
Chris@441
|
4243 attrMap: {
|
Chris@441
|
4244 "class": "className",
|
Chris@441
|
4245 "for": "htmlFor"
|
Chris@441
|
4246 },
|
Chris@441
|
4247 attrHandle: {
|
Chris@441
|
4248 href: function(elem){
|
Chris@441
|
4249 return elem.getAttribute("href");
|
Chris@0
|
4250 }
|
Chris@0
|
4251 },
|
Chris@441
|
4252 relative: {
|
Chris@441
|
4253 "+": function(checkSet, part, isXML){
|
Chris@441
|
4254 var isPartStr = typeof part === "string",
|
Chris@441
|
4255 isTag = isPartStr && !/\W/.test(part),
|
Chris@441
|
4256 isPartStrNotTag = isPartStr && !isTag;
|
Chris@441
|
4257
|
Chris@441
|
4258 if ( isTag && !isXML ) {
|
Chris@441
|
4259 part = part.toUpperCase();
|
Chris@441
|
4260 }
|
Chris@441
|
4261
|
Chris@441
|
4262 for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
|
Chris@441
|
4263 if ( (elem = checkSet[i]) ) {
|
Chris@441
|
4264 while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
|
Chris@441
|
4265
|
Chris@441
|
4266 checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ?
|
Chris@441
|
4267 elem || false :
|
Chris@441
|
4268 elem === part;
|
Chris@441
|
4269 }
|
Chris@441
|
4270 }
|
Chris@441
|
4271
|
Chris@441
|
4272 if ( isPartStrNotTag ) {
|
Chris@441
|
4273 Sizzle.filter( part, checkSet, true );
|
Chris@441
|
4274 }
|
Chris@441
|
4275 },
|
Chris@441
|
4276 ">": function(checkSet, part, isXML){
|
Chris@441
|
4277 var isPartStr = typeof part === "string";
|
Chris@441
|
4278
|
Chris@441
|
4279 if ( isPartStr && !/\W/.test(part) ) {
|
Chris@441
|
4280 part = isXML ? part : part.toUpperCase();
|
Chris@441
|
4281
|
Chris@441
|
4282 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
|
Chris@441
|
4283 var elem = checkSet[i];
|
Chris@441
|
4284 if ( elem ) {
|
Chris@441
|
4285 var parent = elem.parentNode;
|
Chris@441
|
4286 checkSet[i] = parent.nodeName === part ? parent : false;
|
Chris@441
|
4287 }
|
Chris@441
|
4288 }
|
Chris@441
|
4289 } else {
|
Chris@441
|
4290 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
|
Chris@441
|
4291 var elem = checkSet[i];
|
Chris@441
|
4292 if ( elem ) {
|
Chris@441
|
4293 checkSet[i] = isPartStr ?
|
Chris@441
|
4294 elem.parentNode :
|
Chris@441
|
4295 elem.parentNode === part;
|
Chris@441
|
4296 }
|
Chris@441
|
4297 }
|
Chris@441
|
4298
|
Chris@441
|
4299 if ( isPartStr ) {
|
Chris@441
|
4300 Sizzle.filter( part, checkSet, true );
|
Chris@441
|
4301 }
|
Chris@441
|
4302 }
|
Chris@441
|
4303 },
|
Chris@441
|
4304 "": function(checkSet, part, isXML){
|
Chris@441
|
4305 var doneName = done++, checkFn = dirCheck;
|
Chris@441
|
4306
|
Chris@441
|
4307 if ( !/\W/.test(part) ) {
|
Chris@441
|
4308 var nodeCheck = part = isXML ? part : part.toUpperCase();
|
Chris@441
|
4309 checkFn = dirNodeCheck;
|
Chris@441
|
4310 }
|
Chris@441
|
4311
|
Chris@441
|
4312 checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML);
|
Chris@441
|
4313 },
|
Chris@441
|
4314 "~": function(checkSet, part, isXML){
|
Chris@441
|
4315 var doneName = done++, checkFn = dirCheck;
|
Chris@441
|
4316
|
Chris@441
|
4317 if ( typeof part === "string" && !/\W/.test(part) ) {
|
Chris@441
|
4318 var nodeCheck = part = isXML ? part : part.toUpperCase();
|
Chris@441
|
4319 checkFn = dirNodeCheck;
|
Chris@441
|
4320 }
|
Chris@441
|
4321
|
Chris@441
|
4322 checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML);
|
Chris@441
|
4323 }
|
Chris@441
|
4324 },
|
Chris@441
|
4325 find: {
|
Chris@441
|
4326 ID: function(match, context, isXML){
|
Chris@441
|
4327 if ( typeof context.getElementById !== "undefined" && !isXML ) {
|
Chris@441
|
4328 var m = context.getElementById(match[1]);
|
Chris@441
|
4329 return m ? [m] : [];
|
Chris@441
|
4330 }
|
Chris@441
|
4331 },
|
Chris@441
|
4332 NAME: function(match, context, isXML){
|
Chris@441
|
4333 if ( typeof context.getElementsByName !== "undefined" ) {
|
Chris@441
|
4334 var ret = [], results = context.getElementsByName(match[1]);
|
Chris@441
|
4335
|
Chris@441
|
4336 for ( var i = 0, l = results.length; i < l; i++ ) {
|
Chris@441
|
4337 if ( results[i].getAttribute("name") === match[1] ) {
|
Chris@441
|
4338 ret.push( results[i] );
|
Chris@441
|
4339 }
|
Chris@441
|
4340 }
|
Chris@441
|
4341
|
Chris@441
|
4342 return ret.length === 0 ? null : ret;
|
Chris@441
|
4343 }
|
Chris@441
|
4344 },
|
Chris@441
|
4345 TAG: function(match, context){
|
Chris@441
|
4346 return context.getElementsByTagName(match[1]);
|
Chris@441
|
4347 }
|
Chris@441
|
4348 },
|
Chris@441
|
4349 preFilter: {
|
Chris@441
|
4350 CLASS: function(match, curLoop, inplace, result, not, isXML){
|
Chris@441
|
4351 match = " " + match[1].replace(/\\/g, "") + " ";
|
Chris@441
|
4352
|
Chris@441
|
4353 if ( isXML ) {
|
Chris@441
|
4354 return match;
|
Chris@441
|
4355 }
|
Chris@441
|
4356
|
Chris@441
|
4357 for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
|
Chris@441
|
4358 if ( elem ) {
|
Chris@441
|
4359 if ( not ^ (elem.className && (" " + elem.className + " ").indexOf(match) >= 0) ) {
|
Chris@441
|
4360 if ( !inplace )
|
Chris@441
|
4361 result.push( elem );
|
Chris@441
|
4362 } else if ( inplace ) {
|
Chris@441
|
4363 curLoop[i] = false;
|
Chris@0
|
4364 }
|
Chris@0
|
4365 }
|
Chris@0
|
4366 }
|
Chris@441
|
4367
|
Chris@441
|
4368 return false;
|
Chris@441
|
4369 },
|
Chris@441
|
4370 ID: function(match){
|
Chris@441
|
4371 return match[1].replace(/\\/g, "");
|
Chris@441
|
4372 },
|
Chris@441
|
4373 TAG: function(match, curLoop){
|
Chris@441
|
4374 for ( var i = 0; curLoop[i] === false; i++ ){}
|
Chris@441
|
4375 return curLoop[i] && isXML(curLoop[i]) ? match[1] : match[1].toUpperCase();
|
Chris@441
|
4376 },
|
Chris@441
|
4377 CHILD: function(match){
|
Chris@441
|
4378 if ( match[1] == "nth" ) {
|
Chris@441
|
4379 var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
|
Chris@441
|
4380 match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" ||
|
Chris@441
|
4381 !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
|
Chris@441
|
4382
|
Chris@441
|
4383 match[2] = (test[1] + (test[2] || 1)) - 0;
|
Chris@441
|
4384 match[3] = test[3] - 0;
|
Chris@441
|
4385 }
|
Chris@441
|
4386
|
Chris@441
|
4387 match[0] = done++;
|
Chris@441
|
4388
|
Chris@441
|
4389 return match;
|
Chris@441
|
4390 },
|
Chris@441
|
4391 ATTR: function(match, curLoop, inplace, result, not, isXML){
|
Chris@441
|
4392 var name = match[1].replace(/\\/g, "");
|
Chris@441
|
4393
|
Chris@441
|
4394 if ( !isXML && Expr.attrMap[name] ) {
|
Chris@441
|
4395 match[1] = Expr.attrMap[name];
|
Chris@441
|
4396 }
|
Chris@441
|
4397
|
Chris@441
|
4398 if ( match[2] === "~=" ) {
|
Chris@441
|
4399 match[4] = " " + match[4] + " ";
|
Chris@441
|
4400 }
|
Chris@441
|
4401
|
Chris@441
|
4402 return match;
|
Chris@441
|
4403 },
|
Chris@441
|
4404 PSEUDO: function(match, curLoop, inplace, result, not){
|
Chris@441
|
4405 if ( match[1] === "not" ) {
|
Chris@441
|
4406 if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
|
Chris@441
|
4407 match[3] = Sizzle(match[3], null, null, curLoop);
|
Chris@441
|
4408 } else {
|
Chris@441
|
4409 var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
|
Chris@441
|
4410 if ( !inplace ) {
|
Chris@441
|
4411 result.push.apply( result, ret );
|
Chris@441
|
4412 }
|
Chris@441
|
4413 return false;
|
Chris@441
|
4414 }
|
Chris@441
|
4415 } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
|
Chris@441
|
4416 return true;
|
Chris@441
|
4417 }
|
Chris@441
|
4418
|
Chris@441
|
4419 return match;
|
Chris@441
|
4420 },
|
Chris@441
|
4421 POS: function(match){
|
Chris@441
|
4422 match.unshift( true );
|
Chris@441
|
4423 return match;
|
Chris@0
|
4424 }
|
Chris@441
|
4425 },
|
Chris@441
|
4426 filters: {
|
Chris@441
|
4427 enabled: function(elem){
|
Chris@441
|
4428 return elem.disabled === false && elem.type !== "hidden";
|
Chris@441
|
4429 },
|
Chris@441
|
4430 disabled: function(elem){
|
Chris@441
|
4431 return elem.disabled === true;
|
Chris@441
|
4432 },
|
Chris@441
|
4433 checked: function(elem){
|
Chris@441
|
4434 return elem.checked === true;
|
Chris@441
|
4435 },
|
Chris@441
|
4436 selected: function(elem){
|
Chris@441
|
4437 elem.parentNode.selectedIndex;
|
Chris@441
|
4438 return elem.selected === true;
|
Chris@441
|
4439 },
|
Chris@441
|
4440 parent: function(elem){
|
Chris@441
|
4441 return !!elem.firstChild;
|
Chris@441
|
4442 },
|
Chris@441
|
4443 empty: function(elem){
|
Chris@441
|
4444 return !elem.firstChild;
|
Chris@441
|
4445 },
|
Chris@441
|
4446 has: function(elem, i, match){
|
Chris@441
|
4447 return !!Sizzle( match[3], elem ).length;
|
Chris@441
|
4448 },
|
Chris@441
|
4449 header: function(elem){
|
Chris@441
|
4450 return /h\d/i.test( elem.nodeName );
|
Chris@441
|
4451 },
|
Chris@441
|
4452 text: function(elem){
|
Chris@441
|
4453 return "text" === elem.type;
|
Chris@441
|
4454 },
|
Chris@441
|
4455 radio: function(elem){
|
Chris@441
|
4456 return "radio" === elem.type;
|
Chris@441
|
4457 },
|
Chris@441
|
4458 checkbox: function(elem){
|
Chris@441
|
4459 return "checkbox" === elem.type;
|
Chris@441
|
4460 },
|
Chris@441
|
4461 file: function(elem){
|
Chris@441
|
4462 return "file" === elem.type;
|
Chris@441
|
4463 },
|
Chris@441
|
4464 password: function(elem){
|
Chris@441
|
4465 return "password" === elem.type;
|
Chris@441
|
4466 },
|
Chris@441
|
4467 submit: function(elem){
|
Chris@441
|
4468 return "submit" === elem.type;
|
Chris@441
|
4469 },
|
Chris@441
|
4470 image: function(elem){
|
Chris@441
|
4471 return "image" === elem.type;
|
Chris@441
|
4472 },
|
Chris@441
|
4473 reset: function(elem){
|
Chris@441
|
4474 return "reset" === elem.type;
|
Chris@441
|
4475 },
|
Chris@441
|
4476 button: function(elem){
|
Chris@441
|
4477 return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON";
|
Chris@441
|
4478 },
|
Chris@441
|
4479 input: function(elem){
|
Chris@441
|
4480 return /input|select|textarea|button/i.test(elem.nodeName);
|
Chris@441
|
4481 }
|
Chris@441
|
4482 },
|
Chris@441
|
4483 setFilters: {
|
Chris@441
|
4484 first: function(elem, i){
|
Chris@441
|
4485 return i === 0;
|
Chris@441
|
4486 },
|
Chris@441
|
4487 last: function(elem, i, match, array){
|
Chris@441
|
4488 return i === array.length - 1;
|
Chris@441
|
4489 },
|
Chris@441
|
4490 even: function(elem, i){
|
Chris@441
|
4491 return i % 2 === 0;
|
Chris@441
|
4492 },
|
Chris@441
|
4493 odd: function(elem, i){
|
Chris@441
|
4494 return i % 2 === 1;
|
Chris@441
|
4495 },
|
Chris@441
|
4496 lt: function(elem, i, match){
|
Chris@441
|
4497 return i < match[3] - 0;
|
Chris@441
|
4498 },
|
Chris@441
|
4499 gt: function(elem, i, match){
|
Chris@441
|
4500 return i > match[3] - 0;
|
Chris@441
|
4501 },
|
Chris@441
|
4502 nth: function(elem, i, match){
|
Chris@441
|
4503 return match[3] - 0 == i;
|
Chris@441
|
4504 },
|
Chris@441
|
4505 eq: function(elem, i, match){
|
Chris@441
|
4506 return match[3] - 0 == i;
|
Chris@441
|
4507 }
|
Chris@441
|
4508 },
|
Chris@441
|
4509 filter: {
|
Chris@441
|
4510 PSEUDO: function(elem, match, i, array){
|
Chris@441
|
4511 var name = match[1], filter = Expr.filters[ name ];
|
Chris@441
|
4512
|
Chris@441
|
4513 if ( filter ) {
|
Chris@441
|
4514 return filter( elem, i, match, array );
|
Chris@441
|
4515 } else if ( name === "contains" ) {
|
Chris@441
|
4516 return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
|
Chris@441
|
4517 } else if ( name === "not" ) {
|
Chris@441
|
4518 var not = match[3];
|
Chris@441
|
4519
|
Chris@441
|
4520 for ( var i = 0, l = not.length; i < l; i++ ) {
|
Chris@441
|
4521 if ( not[i] === elem ) {
|
Chris@441
|
4522 return false;
|
Chris@441
|
4523 }
|
Chris@441
|
4524 }
|
Chris@441
|
4525
|
Chris@441
|
4526 return true;
|
Chris@441
|
4527 }
|
Chris@441
|
4528 },
|
Chris@441
|
4529 CHILD: function(elem, match){
|
Chris@441
|
4530 var type = match[1], node = elem;
|
Chris@441
|
4531 switch (type) {
|
Chris@441
|
4532 case 'only':
|
Chris@441
|
4533 case 'first':
|
Chris@441
|
4534 while ( (node = node.previousSibling) ) {
|
Chris@441
|
4535 if ( node.nodeType === 1 ) return false;
|
Chris@441
|
4536 }
|
Chris@441
|
4537 if ( type == 'first') return true;
|
Chris@441
|
4538 node = elem;
|
Chris@441
|
4539 case 'last':
|
Chris@441
|
4540 while ( (node = node.nextSibling) ) {
|
Chris@441
|
4541 if ( node.nodeType === 1 ) return false;
|
Chris@441
|
4542 }
|
Chris@441
|
4543 return true;
|
Chris@441
|
4544 case 'nth':
|
Chris@441
|
4545 var first = match[2], last = match[3];
|
Chris@441
|
4546
|
Chris@441
|
4547 if ( first == 1 && last == 0 ) {
|
Chris@441
|
4548 return true;
|
Chris@441
|
4549 }
|
Chris@441
|
4550
|
Chris@441
|
4551 var doneName = match[0],
|
Chris@441
|
4552 parent = elem.parentNode;
|
Chris@441
|
4553
|
Chris@441
|
4554 if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
|
Chris@441
|
4555 var count = 0;
|
Chris@441
|
4556 for ( node = parent.firstChild; node; node = node.nextSibling ) {
|
Chris@441
|
4557 if ( node.nodeType === 1 ) {
|
Chris@441
|
4558 node.nodeIndex = ++count;
|
Chris@441
|
4559 }
|
Chris@441
|
4560 }
|
Chris@441
|
4561 parent.sizcache = doneName;
|
Chris@441
|
4562 }
|
Chris@441
|
4563
|
Chris@441
|
4564 var diff = elem.nodeIndex - last;
|
Chris@441
|
4565 if ( first == 0 ) {
|
Chris@441
|
4566 return diff == 0;
|
Chris@441
|
4567 } else {
|
Chris@441
|
4568 return ( diff % first == 0 && diff / first >= 0 );
|
Chris@441
|
4569 }
|
Chris@441
|
4570 }
|
Chris@441
|
4571 },
|
Chris@441
|
4572 ID: function(elem, match){
|
Chris@441
|
4573 return elem.nodeType === 1 && elem.getAttribute("id") === match;
|
Chris@441
|
4574 },
|
Chris@441
|
4575 TAG: function(elem, match){
|
Chris@441
|
4576 return (match === "*" && elem.nodeType === 1) || elem.nodeName === match;
|
Chris@441
|
4577 },
|
Chris@441
|
4578 CLASS: function(elem, match){
|
Chris@441
|
4579 return (" " + (elem.className || elem.getAttribute("class")) + " ")
|
Chris@441
|
4580 .indexOf( match ) > -1;
|
Chris@441
|
4581 },
|
Chris@441
|
4582 ATTR: function(elem, match){
|
Chris@441
|
4583 var name = match[1],
|
Chris@441
|
4584 result = Expr.attrHandle[ name ] ?
|
Chris@441
|
4585 Expr.attrHandle[ name ]( elem ) :
|
Chris@441
|
4586 elem[ name ] != null ?
|
Chris@441
|
4587 elem[ name ] :
|
Chris@441
|
4588 elem.getAttribute( name ),
|
Chris@441
|
4589 value = result + "",
|
Chris@441
|
4590 type = match[2],
|
Chris@441
|
4591 check = match[4];
|
Chris@441
|
4592
|
Chris@441
|
4593 return result == null ?
|
Chris@441
|
4594 type === "!=" :
|
Chris@441
|
4595 type === "=" ?
|
Chris@441
|
4596 value === check :
|
Chris@441
|
4597 type === "*=" ?
|
Chris@441
|
4598 value.indexOf(check) >= 0 :
|
Chris@441
|
4599 type === "~=" ?
|
Chris@441
|
4600 (" " + value + " ").indexOf(check) >= 0 :
|
Chris@441
|
4601 !check ?
|
Chris@441
|
4602 value && result !== false :
|
Chris@441
|
4603 type === "!=" ?
|
Chris@441
|
4604 value != check :
|
Chris@441
|
4605 type === "^=" ?
|
Chris@441
|
4606 value.indexOf(check) === 0 :
|
Chris@441
|
4607 type === "$=" ?
|
Chris@441
|
4608 value.substr(value.length - check.length) === check :
|
Chris@441
|
4609 type === "|=" ?
|
Chris@441
|
4610 value === check || value.substr(0, check.length + 1) === check + "-" :
|
Chris@441
|
4611 false;
|
Chris@441
|
4612 },
|
Chris@441
|
4613 POS: function(elem, match, i, array){
|
Chris@441
|
4614 var name = match[2], filter = Expr.setFilters[ name ];
|
Chris@441
|
4615
|
Chris@441
|
4616 if ( filter ) {
|
Chris@441
|
4617 return filter( elem, i, match, array );
|
Chris@0
|
4618 }
|
Chris@0
|
4619 }
|
Chris@441
|
4620 }
|
Chris@441
|
4621 };
|
Chris@441
|
4622
|
Chris@441
|
4623 var origPOS = Expr.match.POS;
|
Chris@441
|
4624
|
Chris@441
|
4625 for ( var type in Expr.match ) {
|
Chris@441
|
4626 Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
|
Chris@441
|
4627 Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source );
|
Chris@441
|
4628 }
|
Chris@441
|
4629
|
Chris@441
|
4630 var makeArray = function(array, results) {
|
Chris@441
|
4631 array = Array.prototype.slice.call( array, 0 );
|
Chris@441
|
4632
|
Chris@441
|
4633 if ( results ) {
|
Chris@441
|
4634 results.push.apply( results, array );
|
Chris@441
|
4635 return results;
|
Chris@441
|
4636 }
|
Chris@441
|
4637
|
Chris@441
|
4638 return array;
|
Chris@441
|
4639 };
|
Chris@441
|
4640
|
Chris@441
|
4641 try {
|
Chris@441
|
4642 Array.prototype.slice.call( document.documentElement.childNodes, 0 );
|
Chris@441
|
4643
|
Chris@441
|
4644 } catch(e){
|
Chris@441
|
4645 makeArray = function(array, results) {
|
Chris@441
|
4646 var ret = results || [];
|
Chris@441
|
4647
|
Chris@441
|
4648 if ( toString.call(array) === "[object Array]" ) {
|
Chris@441
|
4649 Array.prototype.push.apply( ret, array );
|
Chris@441
|
4650 } else {
|
Chris@441
|
4651 if ( typeof array.length === "number" ) {
|
Chris@441
|
4652 for ( var i = 0, l = array.length; i < l; i++ ) {
|
Chris@441
|
4653 ret.push( array[i] );
|
Chris@0
|
4654 }
|
Chris@441
|
4655 } else {
|
Chris@441
|
4656 for ( var i = 0; array[i]; i++ ) {
|
Chris@441
|
4657 ret.push( array[i] );
|
Chris@0
|
4658 }
|
Chris@0
|
4659 }
|
Chris@0
|
4660 }
|
Chris@441
|
4661
|
Chris@441
|
4662 return ret;
|
Chris@441
|
4663 };
|
Chris@441
|
4664 }
|
Chris@441
|
4665
|
Chris@441
|
4666 var sortOrder;
|
Chris@441
|
4667
|
Chris@441
|
4668 if ( document.documentElement.compareDocumentPosition ) {
|
Chris@441
|
4669 sortOrder = function( a, b ) {
|
Chris@441
|
4670 if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
|
Chris@441
|
4671 if ( a == b ) {
|
Chris@441
|
4672 hasDuplicate = true;
|
Chris@441
|
4673 }
|
Chris@441
|
4674 return 0;
|
Chris@0
|
4675 }
|
Chris@441
|
4676
|
Chris@441
|
4677 var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
|
Chris@441
|
4678 if ( ret === 0 ) {
|
Chris@441
|
4679 hasDuplicate = true;
|
Chris@441
|
4680 }
|
Chris@441
|
4681 return ret;
|
Chris@441
|
4682 };
|
Chris@441
|
4683 } else if ( "sourceIndex" in document.documentElement ) {
|
Chris@441
|
4684 sortOrder = function( a, b ) {
|
Chris@441
|
4685 if ( !a.sourceIndex || !b.sourceIndex ) {
|
Chris@441
|
4686 if ( a == b ) {
|
Chris@441
|
4687 hasDuplicate = true;
|
Chris@441
|
4688 }
|
Chris@441
|
4689 return 0;
|
Chris@441
|
4690 }
|
Chris@441
|
4691
|
Chris@441
|
4692 var ret = a.sourceIndex - b.sourceIndex;
|
Chris@441
|
4693 if ( ret === 0 ) {
|
Chris@441
|
4694 hasDuplicate = true;
|
Chris@441
|
4695 }
|
Chris@441
|
4696 return ret;
|
Chris@441
|
4697 };
|
Chris@441
|
4698 } else if ( document.createRange ) {
|
Chris@441
|
4699 sortOrder = function( a, b ) {
|
Chris@441
|
4700 if ( !a.ownerDocument || !b.ownerDocument ) {
|
Chris@441
|
4701 if ( a == b ) {
|
Chris@441
|
4702 hasDuplicate = true;
|
Chris@441
|
4703 }
|
Chris@441
|
4704 return 0;
|
Chris@441
|
4705 }
|
Chris@441
|
4706
|
Chris@441
|
4707 var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
|
Chris@441
|
4708 aRange.setStart(a, 0);
|
Chris@441
|
4709 aRange.setEnd(a, 0);
|
Chris@441
|
4710 bRange.setStart(b, 0);
|
Chris@441
|
4711 bRange.setEnd(b, 0);
|
Chris@441
|
4712 var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
|
Chris@441
|
4713 if ( ret === 0 ) {
|
Chris@441
|
4714 hasDuplicate = true;
|
Chris@441
|
4715 }
|
Chris@441
|
4716 return ret;
|
Chris@441
|
4717 };
|
Chris@441
|
4718 }
|
Chris@441
|
4719
|
Chris@441
|
4720 (function(){
|
Chris@441
|
4721 var form = document.createElement("div"),
|
Chris@441
|
4722 id = "script" + (new Date).getTime();
|
Chris@441
|
4723 form.innerHTML = "<a name='" + id + "'/>";
|
Chris@441
|
4724
|
Chris@441
|
4725 var root = document.documentElement;
|
Chris@441
|
4726 root.insertBefore( form, root.firstChild );
|
Chris@441
|
4727
|
Chris@441
|
4728 if ( !!document.getElementById( id ) ) {
|
Chris@441
|
4729 Expr.find.ID = function(match, context, isXML){
|
Chris@441
|
4730 if ( typeof context.getElementById !== "undefined" && !isXML ) {
|
Chris@441
|
4731 var m = context.getElementById(match[1]);
|
Chris@441
|
4732 return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
|
Chris@441
|
4733 }
|
Chris@441
|
4734 };
|
Chris@441
|
4735
|
Chris@441
|
4736 Expr.filter.ID = function(elem, match){
|
Chris@441
|
4737 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
|
Chris@441
|
4738 return elem.nodeType === 1 && node && node.nodeValue === match;
|
Chris@441
|
4739 };
|
Chris@441
|
4740 }
|
Chris@441
|
4741
|
Chris@441
|
4742 root.removeChild( form );
|
Chris@441
|
4743 root = form = null; // release memory in IE
|
Chris@441
|
4744 })();
|
Chris@441
|
4745
|
Chris@441
|
4746 (function(){
|
Chris@441
|
4747
|
Chris@441
|
4748 var div = document.createElement("div");
|
Chris@441
|
4749 div.appendChild( document.createComment("") );
|
Chris@441
|
4750
|
Chris@441
|
4751 if ( div.getElementsByTagName("*").length > 0 ) {
|
Chris@441
|
4752 Expr.find.TAG = function(match, context){
|
Chris@441
|
4753 var results = context.getElementsByTagName(match[1]);
|
Chris@441
|
4754
|
Chris@441
|
4755 if ( match[1] === "*" ) {
|
Chris@441
|
4756 var tmp = [];
|
Chris@441
|
4757
|
Chris@441
|
4758 for ( var i = 0; results[i]; i++ ) {
|
Chris@441
|
4759 if ( results[i].nodeType === 1 ) {
|
Chris@441
|
4760 tmp.push( results[i] );
|
Chris@441
|
4761 }
|
Chris@0
|
4762 }
|
Chris@441
|
4763
|
Chris@441
|
4764 results = tmp;
|
Chris@0
|
4765 }
|
Chris@441
|
4766
|
Chris@441
|
4767 return results;
|
Chris@441
|
4768 };
|
Chris@441
|
4769 }
|
Chris@441
|
4770
|
Chris@441
|
4771 div.innerHTML = "<a href='#'></a>";
|
Chris@441
|
4772 if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
|
Chris@441
|
4773 div.firstChild.getAttribute("href") !== "#" ) {
|
Chris@441
|
4774 Expr.attrHandle.href = function(elem){
|
Chris@441
|
4775 return elem.getAttribute("href", 2);
|
Chris@441
|
4776 };
|
Chris@441
|
4777 }
|
Chris@441
|
4778
|
Chris@441
|
4779 div = null; // release memory in IE
|
Chris@441
|
4780 })();
|
Chris@441
|
4781
|
Chris@441
|
4782 if ( document.querySelectorAll ) (function(){
|
Chris@441
|
4783 var oldSizzle = Sizzle, div = document.createElement("div");
|
Chris@441
|
4784 div.innerHTML = "<p class='TEST'></p>";
|
Chris@441
|
4785
|
Chris@441
|
4786 if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
|
Chris@441
|
4787 return;
|
Chris@441
|
4788 }
|
Chris@441
|
4789
|
Chris@441
|
4790 Sizzle = function(query, context, extra, seed){
|
Chris@441
|
4791 context = context || document;
|
Chris@441
|
4792
|
Chris@441
|
4793 if ( !seed && context.nodeType === 9 && !isXML(context) ) {
|
Chris@441
|
4794 try {
|
Chris@441
|
4795 return makeArray( context.querySelectorAll(query), extra );
|
Chris@441
|
4796 } catch(e){}
|
Chris@441
|
4797 }
|
Chris@441
|
4798
|
Chris@441
|
4799 return oldSizzle(query, context, extra, seed);
|
Chris@441
|
4800 };
|
Chris@441
|
4801
|
Chris@441
|
4802 for ( var prop in oldSizzle ) {
|
Chris@441
|
4803 Sizzle[ prop ] = oldSizzle[ prop ];
|
Chris@441
|
4804 }
|
Chris@441
|
4805
|
Chris@441
|
4806 div = null; // release memory in IE
|
Chris@441
|
4807 })();
|
Chris@441
|
4808
|
Chris@441
|
4809 if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
|
Chris@441
|
4810 var div = document.createElement("div");
|
Chris@441
|
4811 div.innerHTML = "<div class='test e'></div><div class='test'></div>";
|
Chris@441
|
4812
|
Chris@441
|
4813 if ( div.getElementsByClassName("e").length === 0 )
|
Chris@441
|
4814 return;
|
Chris@441
|
4815
|
Chris@441
|
4816 div.lastChild.className = "e";
|
Chris@441
|
4817
|
Chris@441
|
4818 if ( div.getElementsByClassName("e").length === 1 )
|
Chris@441
|
4819 return;
|
Chris@441
|
4820
|
Chris@441
|
4821 Expr.order.splice(1, 0, "CLASS");
|
Chris@441
|
4822 Expr.find.CLASS = function(match, context, isXML) {
|
Chris@441
|
4823 if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
|
Chris@441
|
4824 return context.getElementsByClassName(match[1]);
|
Chris@441
|
4825 }
|
Chris@441
|
4826 };
|
Chris@441
|
4827
|
Chris@441
|
4828 div = null; // release memory in IE
|
Chris@441
|
4829 })();
|
Chris@441
|
4830
|
Chris@441
|
4831 function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
|
Chris@441
|
4832 var sibDir = dir == "previousSibling" && !isXML;
|
Chris@441
|
4833 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
|
Chris@441
|
4834 var elem = checkSet[i];
|
Chris@441
|
4835 if ( elem ) {
|
Chris@441
|
4836 if ( sibDir && elem.nodeType === 1 ){
|
Chris@441
|
4837 elem.sizcache = doneName;
|
Chris@441
|
4838 elem.sizset = i;
|
Chris@441
|
4839 }
|
Chris@441
|
4840 elem = elem[dir];
|
Chris@441
|
4841 var match = false;
|
Chris@441
|
4842
|
Chris@441
|
4843 while ( elem ) {
|
Chris@441
|
4844 if ( elem.sizcache === doneName ) {
|
Chris@441
|
4845 match = checkSet[elem.sizset];
|
Chris@441
|
4846 break;
|
Chris@0
|
4847 }
|
Chris@441
|
4848
|
Chris@441
|
4849 if ( elem.nodeType === 1 && !isXML ){
|
Chris@441
|
4850 elem.sizcache = doneName;
|
Chris@441
|
4851 elem.sizset = i;
|
Chris@441
|
4852 }
|
Chris@441
|
4853
|
Chris@441
|
4854 if ( elem.nodeName === cur ) {
|
Chris@441
|
4855 match = elem;
|
Chris@441
|
4856 break;
|
Chris@441
|
4857 }
|
Chris@441
|
4858
|
Chris@441
|
4859 elem = elem[dir];
|
Chris@0
|
4860 }
|
Chris@441
|
4861
|
Chris@441
|
4862 checkSet[i] = match;
|
Chris@441
|
4863 }
|
Chris@441
|
4864 }
|
Chris@441
|
4865 }
|
Chris@441
|
4866
|
Chris@441
|
4867 function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
|
Chris@441
|
4868 var sibDir = dir == "previousSibling" && !isXML;
|
Chris@441
|
4869 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
|
Chris@441
|
4870 var elem = checkSet[i];
|
Chris@441
|
4871 if ( elem ) {
|
Chris@441
|
4872 if ( sibDir && elem.nodeType === 1 ) {
|
Chris@441
|
4873 elem.sizcache = doneName;
|
Chris@441
|
4874 elem.sizset = i;
|
Chris@0
|
4875 }
|
Chris@441
|
4876 elem = elem[dir];
|
Chris@441
|
4877 var match = false;
|
Chris@441
|
4878
|
Chris@441
|
4879 while ( elem ) {
|
Chris@441
|
4880 if ( elem.sizcache === doneName ) {
|
Chris@441
|
4881 match = checkSet[elem.sizset];
|
Chris@441
|
4882 break;
|
Chris@0
|
4883 }
|
Chris@441
|
4884
|
Chris@441
|
4885 if ( elem.nodeType === 1 ) {
|
Chris@441
|
4886 if ( !isXML ) {
|
Chris@441
|
4887 elem.sizcache = doneName;
|
Chris@441
|
4888 elem.sizset = i;
|
Chris@441
|
4889 }
|
Chris@441
|
4890 if ( typeof cur !== "string" ) {
|
Chris@441
|
4891 if ( elem === cur ) {
|
Chris@441
|
4892 match = true;
|
Chris@441
|
4893 break;
|
Chris@441
|
4894 }
|
Chris@441
|
4895
|
Chris@441
|
4896 } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
|
Chris@441
|
4897 match = elem;
|
Chris@441
|
4898 break;
|
Chris@441
|
4899 }
|
Chris@0
|
4900 }
|
Chris@441
|
4901
|
Chris@441
|
4902 elem = elem[dir];
|
Chris@0
|
4903 }
|
Chris@441
|
4904
|
Chris@441
|
4905 checkSet[i] = match;
|
Chris@0
|
4906 }
|
Chris@441
|
4907 }
|
Chris@0
|
4908 }
|
Chris@0
|
4909
|
Chris@441
|
4910 var contains = document.compareDocumentPosition ? function(a, b){
|
Chris@441
|
4911 return a.compareDocumentPosition(b) & 16;
|
Chris@441
|
4912 } : function(a, b){
|
Chris@441
|
4913 return a !== b && (a.contains ? a.contains(b) : true);
|
Chris@441
|
4914 };
|
Chris@441
|
4915
|
Chris@441
|
4916 var isXML = function(elem){
|
Chris@441
|
4917 return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
|
Chris@441
|
4918 !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML";
|
Chris@441
|
4919 };
|
Chris@441
|
4920
|
Chris@441
|
4921 var posProcess = function(selector, context){
|
Chris@441
|
4922 var tmpSet = [], later = "", match,
|
Chris@441
|
4923 root = context.nodeType ? [context] : context;
|
Chris@441
|
4924
|
Chris@441
|
4925 while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
|
Chris@441
|
4926 later += match[0];
|
Chris@441
|
4927 selector = selector.replace( Expr.match.PSEUDO, "" );
|
Chris@441
|
4928 }
|
Chris@441
|
4929
|
Chris@441
|
4930 selector = Expr.relative[selector] ? selector + "*" : selector;
|
Chris@441
|
4931
|
Chris@441
|
4932 for ( var i = 0, l = root.length; i < l; i++ ) {
|
Chris@441
|
4933 Sizzle( selector, root[i], tmpSet );
|
Chris@441
|
4934 }
|
Chris@441
|
4935
|
Chris@441
|
4936 return Sizzle.filter( later, tmpSet );
|
Chris@441
|
4937 };
|
Chris@441
|
4938
|
Chris@441
|
4939
|
Chris@441
|
4940 window.Sizzle = Sizzle;
|
Chris@441
|
4941
|
Chris@441
|
4942 })();
|
Chris@441
|
4943
|
Chris@441
|
4944 ;(function(engine) {
|
Chris@441
|
4945 var extendElements = Prototype.Selector.extendElements;
|
Chris@441
|
4946
|
Chris@441
|
4947 function select(selector, scope) {
|
Chris@441
|
4948 return extendElements(engine(selector, scope || document));
|
Chris@441
|
4949 }
|
Chris@441
|
4950
|
Chris@441
|
4951 function match(element, selector) {
|
Chris@441
|
4952 return engine.matches(selector, [element]).length == 1;
|
Chris@441
|
4953 }
|
Chris@441
|
4954
|
Chris@441
|
4955 Prototype.Selector.engine = engine;
|
Chris@441
|
4956 Prototype.Selector.select = select;
|
Chris@441
|
4957 Prototype.Selector.match = match;
|
Chris@441
|
4958 })(Sizzle);
|
Chris@441
|
4959
|
Chris@441
|
4960 window.Sizzle = Prototype._original_property;
|
Chris@441
|
4961 delete Prototype._original_property;
|
Chris@441
|
4962
|
Chris@0
|
4963 var Form = {
|
Chris@0
|
4964 reset: function(form) {
|
Chris@441
|
4965 form = $(form);
|
Chris@441
|
4966 form.reset();
|
Chris@0
|
4967 return form;
|
Chris@0
|
4968 },
|
Chris@0
|
4969
|
Chris@0
|
4970 serializeElements: function(elements, options) {
|
Chris@0
|
4971 if (typeof options != 'object') options = { hash: !!options };
|
Chris@0
|
4972 else if (Object.isUndefined(options.hash)) options.hash = true;
|
Chris@441
|
4973 var key, value, submitted = false, submit = options.submit, accumulator, initial;
|
Chris@441
|
4974
|
Chris@441
|
4975 if (options.hash) {
|
Chris@441
|
4976 initial = {};
|
Chris@441
|
4977 accumulator = function(result, key, value) {
|
Chris@441
|
4978 if (key in result) {
|
Chris@441
|
4979 if (!Object.isArray(result[key])) result[key] = [result[key]];
|
Chris@441
|
4980 result[key].push(value);
|
Chris@441
|
4981 } else result[key] = value;
|
Chris@441
|
4982 return result;
|
Chris@441
|
4983 };
|
Chris@441
|
4984 } else {
|
Chris@441
|
4985 initial = '';
|
Chris@441
|
4986 accumulator = function(result, key, value) {
|
Chris@441
|
4987 return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
Chris@441
|
4988 }
|
Chris@441
|
4989 }
|
Chris@441
|
4990
|
Chris@441
|
4991 return elements.inject(initial, function(result, element) {
|
Chris@0
|
4992 if (!element.disabled && element.name) {
|
Chris@0
|
4993 key = element.name; value = $(element).getValue();
|
Chris@0
|
4994 if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted &&
|
Chris@0
|
4995 submit !== false && (!submit || key == submit) && (submitted = true)))) {
|
Chris@441
|
4996 result = accumulator(result, key, value);
|
Chris@0
|
4997 }
|
Chris@0
|
4998 }
|
Chris@0
|
4999 return result;
|
Chris@0
|
5000 });
|
Chris@0
|
5001 }
|
Chris@0
|
5002 };
|
Chris@0
|
5003
|
Chris@0
|
5004 Form.Methods = {
|
Chris@0
|
5005 serialize: function(form, options) {
|
Chris@0
|
5006 return Form.serializeElements(Form.getElements(form), options);
|
Chris@0
|
5007 },
|
Chris@0
|
5008
|
Chris@0
|
5009 getElements: function(form) {
|
Chris@441
|
5010 var elements = $(form).getElementsByTagName('*'),
|
Chris@441
|
5011 element,
|
Chris@441
|
5012 arr = [ ],
|
Chris@441
|
5013 serializers = Form.Element.Serializers;
|
Chris@441
|
5014 for (var i = 0; element = elements[i]; i++) {
|
Chris@441
|
5015 arr.push(element);
|
Chris@441
|
5016 }
|
Chris@441
|
5017 return arr.inject([], function(elements, child) {
|
Chris@441
|
5018 if (serializers[child.tagName.toLowerCase()])
|
Chris@441
|
5019 elements.push(Element.extend(child));
|
Chris@441
|
5020 return elements;
|
Chris@441
|
5021 })
|
Chris@0
|
5022 },
|
Chris@0
|
5023
|
Chris@0
|
5024 getInputs: function(form, typeName, name) {
|
Chris@0
|
5025 form = $(form);
|
Chris@0
|
5026 var inputs = form.getElementsByTagName('input');
|
Chris@0
|
5027
|
Chris@0
|
5028 if (!typeName && !name) return $A(inputs).map(Element.extend);
|
Chris@0
|
5029
|
Chris@0
|
5030 for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
|
Chris@0
|
5031 var input = inputs[i];
|
Chris@0
|
5032 if ((typeName && input.type != typeName) || (name && input.name != name))
|
Chris@0
|
5033 continue;
|
Chris@0
|
5034 matchingInputs.push(Element.extend(input));
|
Chris@0
|
5035 }
|
Chris@0
|
5036
|
Chris@0
|
5037 return matchingInputs;
|
Chris@0
|
5038 },
|
Chris@0
|
5039
|
Chris@0
|
5040 disable: function(form) {
|
Chris@0
|
5041 form = $(form);
|
Chris@0
|
5042 Form.getElements(form).invoke('disable');
|
Chris@0
|
5043 return form;
|
Chris@0
|
5044 },
|
Chris@0
|
5045
|
Chris@0
|
5046 enable: function(form) {
|
Chris@0
|
5047 form = $(form);
|
Chris@0
|
5048 Form.getElements(form).invoke('enable');
|
Chris@0
|
5049 return form;
|
Chris@0
|
5050 },
|
Chris@0
|
5051
|
Chris@0
|
5052 findFirstElement: function(form) {
|
Chris@0
|
5053 var elements = $(form).getElements().findAll(function(element) {
|
Chris@0
|
5054 return 'hidden' != element.type && !element.disabled;
|
Chris@0
|
5055 });
|
Chris@0
|
5056 var firstByIndex = elements.findAll(function(element) {
|
Chris@0
|
5057 return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
|
Chris@0
|
5058 }).sortBy(function(element) { return element.tabIndex }).first();
|
Chris@0
|
5059
|
Chris@0
|
5060 return firstByIndex ? firstByIndex : elements.find(function(element) {
|
Chris@441
|
5061 return /^(?:input|select|textarea)$/i.test(element.tagName);
|
Chris@0
|
5062 });
|
Chris@0
|
5063 },
|
Chris@0
|
5064
|
Chris@0
|
5065 focusFirstElement: function(form) {
|
Chris@0
|
5066 form = $(form);
|
Chris@441
|
5067 var element = form.findFirstElement();
|
Chris@441
|
5068 if (element) element.activate();
|
Chris@0
|
5069 return form;
|
Chris@0
|
5070 },
|
Chris@0
|
5071
|
Chris@0
|
5072 request: function(form, options) {
|
Chris@0
|
5073 form = $(form), options = Object.clone(options || { });
|
Chris@0
|
5074
|
Chris@0
|
5075 var params = options.parameters, action = form.readAttribute('action') || '';
|
Chris@0
|
5076 if (action.blank()) action = window.location.href;
|
Chris@0
|
5077 options.parameters = form.serialize(true);
|
Chris@0
|
5078
|
Chris@0
|
5079 if (params) {
|
Chris@0
|
5080 if (Object.isString(params)) params = params.toQueryParams();
|
Chris@0
|
5081 Object.extend(options.parameters, params);
|
Chris@0
|
5082 }
|
Chris@0
|
5083
|
Chris@0
|
5084 if (form.hasAttribute('method') && !options.method)
|
Chris@0
|
5085 options.method = form.method;
|
Chris@0
|
5086
|
Chris@0
|
5087 return new Ajax.Request(action, options);
|
Chris@0
|
5088 }
|
Chris@0
|
5089 };
|
Chris@0
|
5090
|
Chris@0
|
5091 /*--------------------------------------------------------------------------*/
|
Chris@0
|
5092
|
Chris@441
|
5093
|
Chris@0
|
5094 Form.Element = {
|
Chris@0
|
5095 focus: function(element) {
|
Chris@0
|
5096 $(element).focus();
|
Chris@0
|
5097 return element;
|
Chris@0
|
5098 },
|
Chris@0
|
5099
|
Chris@0
|
5100 select: function(element) {
|
Chris@0
|
5101 $(element).select();
|
Chris@0
|
5102 return element;
|
Chris@0
|
5103 }
|
Chris@0
|
5104 };
|
Chris@0
|
5105
|
Chris@0
|
5106 Form.Element.Methods = {
|
Chris@441
|
5107
|
Chris@0
|
5108 serialize: function(element) {
|
Chris@0
|
5109 element = $(element);
|
Chris@0
|
5110 if (!element.disabled && element.name) {
|
Chris@0
|
5111 var value = element.getValue();
|
Chris@0
|
5112 if (value != undefined) {
|
Chris@0
|
5113 var pair = { };
|
Chris@0
|
5114 pair[element.name] = value;
|
Chris@0
|
5115 return Object.toQueryString(pair);
|
Chris@0
|
5116 }
|
Chris@0
|
5117 }
|
Chris@0
|
5118 return '';
|
Chris@0
|
5119 },
|
Chris@0
|
5120
|
Chris@0
|
5121 getValue: function(element) {
|
Chris@0
|
5122 element = $(element);
|
Chris@0
|
5123 var method = element.tagName.toLowerCase();
|
Chris@0
|
5124 return Form.Element.Serializers[method](element);
|
Chris@0
|
5125 },
|
Chris@0
|
5126
|
Chris@0
|
5127 setValue: function(element, value) {
|
Chris@0
|
5128 element = $(element);
|
Chris@0
|
5129 var method = element.tagName.toLowerCase();
|
Chris@0
|
5130 Form.Element.Serializers[method](element, value);
|
Chris@0
|
5131 return element;
|
Chris@0
|
5132 },
|
Chris@0
|
5133
|
Chris@0
|
5134 clear: function(element) {
|
Chris@0
|
5135 $(element).value = '';
|
Chris@0
|
5136 return element;
|
Chris@0
|
5137 },
|
Chris@0
|
5138
|
Chris@0
|
5139 present: function(element) {
|
Chris@0
|
5140 return $(element).value != '';
|
Chris@0
|
5141 },
|
Chris@0
|
5142
|
Chris@0
|
5143 activate: function(element) {
|
Chris@0
|
5144 element = $(element);
|
Chris@0
|
5145 try {
|
Chris@0
|
5146 element.focus();
|
Chris@0
|
5147 if (element.select && (element.tagName.toLowerCase() != 'input' ||
|
Chris@441
|
5148 !(/^(?:button|reset|submit)$/i.test(element.type))))
|
Chris@0
|
5149 element.select();
|
Chris@0
|
5150 } catch (e) { }
|
Chris@0
|
5151 return element;
|
Chris@0
|
5152 },
|
Chris@0
|
5153
|
Chris@0
|
5154 disable: function(element) {
|
Chris@0
|
5155 element = $(element);
|
Chris@0
|
5156 element.disabled = true;
|
Chris@0
|
5157 return element;
|
Chris@0
|
5158 },
|
Chris@0
|
5159
|
Chris@0
|
5160 enable: function(element) {
|
Chris@0
|
5161 element = $(element);
|
Chris@0
|
5162 element.disabled = false;
|
Chris@0
|
5163 return element;
|
Chris@0
|
5164 }
|
Chris@0
|
5165 };
|
Chris@0
|
5166
|
Chris@0
|
5167 /*--------------------------------------------------------------------------*/
|
Chris@0
|
5168
|
Chris@0
|
5169 var Field = Form.Element;
|
Chris@441
|
5170
|
Chris@0
|
5171 var $F = Form.Element.Methods.getValue;
|
Chris@0
|
5172
|
Chris@0
|
5173 /*--------------------------------------------------------------------------*/
|
Chris@0
|
5174
|
Chris@441
|
5175 Form.Element.Serializers = (function() {
|
Chris@441
|
5176 function input(element, value) {
|
Chris@0
|
5177 switch (element.type.toLowerCase()) {
|
Chris@0
|
5178 case 'checkbox':
|
Chris@0
|
5179 case 'radio':
|
Chris@441
|
5180 return inputSelector(element, value);
|
Chris@0
|
5181 default:
|
Chris@441
|
5182 return valueSelector(element, value);
|
Chris@0
|
5183 }
|
Chris@441
|
5184 }
|
Chris@441
|
5185
|
Chris@441
|
5186 function inputSelector(element, value) {
|
Chris@441
|
5187 if (Object.isUndefined(value))
|
Chris@441
|
5188 return element.checked ? element.value : null;
|
Chris@0
|
5189 else element.checked = !!value;
|
Chris@441
|
5190 }
|
Chris@441
|
5191
|
Chris@441
|
5192 function valueSelector(element, value) {
|
Chris@0
|
5193 if (Object.isUndefined(value)) return element.value;
|
Chris@0
|
5194 else element.value = value;
|
Chris@441
|
5195 }
|
Chris@441
|
5196
|
Chris@441
|
5197 function select(element, value) {
|
Chris@0
|
5198 if (Object.isUndefined(value))
|
Chris@441
|
5199 return (element.type === 'select-one' ? selectOne : selectMany)(element);
|
Chris@441
|
5200
|
Chris@441
|
5201 var opt, currentValue, single = !Object.isArray(value);
|
Chris@441
|
5202 for (var i = 0, length = element.length; i < length; i++) {
|
Chris@441
|
5203 opt = element.options[i];
|
Chris@441
|
5204 currentValue = this.optionValue(opt);
|
Chris@441
|
5205 if (single) {
|
Chris@441
|
5206 if (currentValue == value) {
|
Chris@441
|
5207 opt.selected = true;
|
Chris@441
|
5208 return;
|
Chris@0
|
5209 }
|
Chris@0
|
5210 }
|
Chris@441
|
5211 else opt.selected = value.include(currentValue);
|
Chris@0
|
5212 }
|
Chris@441
|
5213 }
|
Chris@441
|
5214
|
Chris@441
|
5215 function selectOne(element) {
|
Chris@0
|
5216 var index = element.selectedIndex;
|
Chris@441
|
5217 return index >= 0 ? optionValue(element.options[index]) : null;
|
Chris@441
|
5218 }
|
Chris@441
|
5219
|
Chris@441
|
5220 function selectMany(element) {
|
Chris@0
|
5221 var values, length = element.length;
|
Chris@0
|
5222 if (!length) return null;
|
Chris@0
|
5223
|
Chris@0
|
5224 for (var i = 0, values = []; i < length; i++) {
|
Chris@0
|
5225 var opt = element.options[i];
|
Chris@441
|
5226 if (opt.selected) values.push(optionValue(opt));
|
Chris@0
|
5227 }
|
Chris@0
|
5228 return values;
|
Chris@441
|
5229 }
|
Chris@441
|
5230
|
Chris@441
|
5231 function optionValue(opt) {
|
Chris@441
|
5232 return Element.hasAttribute(opt, 'value') ? opt.value : opt.text;
|
Chris@441
|
5233 }
|
Chris@441
|
5234
|
Chris@441
|
5235 return {
|
Chris@441
|
5236 input: input,
|
Chris@441
|
5237 inputSelector: inputSelector,
|
Chris@441
|
5238 textarea: valueSelector,
|
Chris@441
|
5239 select: select,
|
Chris@441
|
5240 selectOne: selectOne,
|
Chris@441
|
5241 selectMany: selectMany,
|
Chris@441
|
5242 optionValue: optionValue,
|
Chris@441
|
5243 button: valueSelector
|
Chris@441
|
5244 };
|
Chris@441
|
5245 })();
|
Chris@0
|
5246
|
Chris@0
|
5247 /*--------------------------------------------------------------------------*/
|
Chris@0
|
5248
|
Chris@441
|
5249
|
Chris@0
|
5250 Abstract.TimedObserver = Class.create(PeriodicalExecuter, {
|
Chris@0
|
5251 initialize: function($super, element, frequency, callback) {
|
Chris@0
|
5252 $super(callback, frequency);
|
Chris@0
|
5253 this.element = $(element);
|
Chris@0
|
5254 this.lastValue = this.getValue();
|
Chris@0
|
5255 },
|
Chris@0
|
5256
|
Chris@0
|
5257 execute: function() {
|
Chris@0
|
5258 var value = this.getValue();
|
Chris@0
|
5259 if (Object.isString(this.lastValue) && Object.isString(value) ?
|
Chris@0
|
5260 this.lastValue != value : String(this.lastValue) != String(value)) {
|
Chris@0
|
5261 this.callback(this.element, value);
|
Chris@0
|
5262 this.lastValue = value;
|
Chris@0
|
5263 }
|
Chris@0
|
5264 }
|
Chris@0
|
5265 });
|
Chris@0
|
5266
|
Chris@0
|
5267 Form.Element.Observer = Class.create(Abstract.TimedObserver, {
|
Chris@0
|
5268 getValue: function() {
|
Chris@0
|
5269 return Form.Element.getValue(this.element);
|
Chris@0
|
5270 }
|
Chris@0
|
5271 });
|
Chris@0
|
5272
|
Chris@0
|
5273 Form.Observer = Class.create(Abstract.TimedObserver, {
|
Chris@0
|
5274 getValue: function() {
|
Chris@0
|
5275 return Form.serialize(this.element);
|
Chris@0
|
5276 }
|
Chris@0
|
5277 });
|
Chris@0
|
5278
|
Chris@0
|
5279 /*--------------------------------------------------------------------------*/
|
Chris@0
|
5280
|
Chris@0
|
5281 Abstract.EventObserver = Class.create({
|
Chris@0
|
5282 initialize: function(element, callback) {
|
Chris@0
|
5283 this.element = $(element);
|
Chris@0
|
5284 this.callback = callback;
|
Chris@0
|
5285
|
Chris@0
|
5286 this.lastValue = this.getValue();
|
Chris@0
|
5287 if (this.element.tagName.toLowerCase() == 'form')
|
Chris@0
|
5288 this.registerFormCallbacks();
|
Chris@0
|
5289 else
|
Chris@0
|
5290 this.registerCallback(this.element);
|
Chris@0
|
5291 },
|
Chris@0
|
5292
|
Chris@0
|
5293 onElementEvent: function() {
|
Chris@0
|
5294 var value = this.getValue();
|
Chris@0
|
5295 if (this.lastValue != value) {
|
Chris@0
|
5296 this.callback(this.element, value);
|
Chris@0
|
5297 this.lastValue = value;
|
Chris@0
|
5298 }
|
Chris@0
|
5299 },
|
Chris@0
|
5300
|
Chris@0
|
5301 registerFormCallbacks: function() {
|
Chris@0
|
5302 Form.getElements(this.element).each(this.registerCallback, this);
|
Chris@0
|
5303 },
|
Chris@0
|
5304
|
Chris@0
|
5305 registerCallback: function(element) {
|
Chris@0
|
5306 if (element.type) {
|
Chris@0
|
5307 switch (element.type.toLowerCase()) {
|
Chris@0
|
5308 case 'checkbox':
|
Chris@0
|
5309 case 'radio':
|
Chris@0
|
5310 Event.observe(element, 'click', this.onElementEvent.bind(this));
|
Chris@0
|
5311 break;
|
Chris@0
|
5312 default:
|
Chris@0
|
5313 Event.observe(element, 'change', this.onElementEvent.bind(this));
|
Chris@0
|
5314 break;
|
Chris@0
|
5315 }
|
Chris@0
|
5316 }
|
Chris@0
|
5317 }
|
Chris@0
|
5318 });
|
Chris@0
|
5319
|
Chris@0
|
5320 Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
|
Chris@0
|
5321 getValue: function() {
|
Chris@0
|
5322 return Form.Element.getValue(this.element);
|
Chris@0
|
5323 }
|
Chris@0
|
5324 });
|
Chris@0
|
5325
|
Chris@0
|
5326 Form.EventObserver = Class.create(Abstract.EventObserver, {
|
Chris@0
|
5327 getValue: function() {
|
Chris@0
|
5328 return Form.serialize(this.element);
|
Chris@0
|
5329 }
|
Chris@0
|
5330 });
|
Chris@441
|
5331 (function() {
|
Chris@441
|
5332
|
Chris@441
|
5333 var Event = {
|
Chris@441
|
5334 KEY_BACKSPACE: 8,
|
Chris@441
|
5335 KEY_TAB: 9,
|
Chris@441
|
5336 KEY_RETURN: 13,
|
Chris@441
|
5337 KEY_ESC: 27,
|
Chris@441
|
5338 KEY_LEFT: 37,
|
Chris@441
|
5339 KEY_UP: 38,
|
Chris@441
|
5340 KEY_RIGHT: 39,
|
Chris@441
|
5341 KEY_DOWN: 40,
|
Chris@441
|
5342 KEY_DELETE: 46,
|
Chris@441
|
5343 KEY_HOME: 36,
|
Chris@441
|
5344 KEY_END: 35,
|
Chris@441
|
5345 KEY_PAGEUP: 33,
|
Chris@441
|
5346 KEY_PAGEDOWN: 34,
|
Chris@441
|
5347 KEY_INSERT: 45,
|
Chris@441
|
5348
|
Chris@441
|
5349 cache: {}
|
Chris@441
|
5350 };
|
Chris@441
|
5351
|
Chris@441
|
5352 var docEl = document.documentElement;
|
Chris@441
|
5353 var MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED = 'onmouseenter' in docEl
|
Chris@441
|
5354 && 'onmouseleave' in docEl;
|
Chris@441
|
5355
|
Chris@441
|
5356
|
Chris@441
|
5357
|
Chris@441
|
5358 var isIELegacyEvent = function(event) { return false; };
|
Chris@441
|
5359
|
Chris@441
|
5360 if (window.attachEvent) {
|
Chris@441
|
5361 if (window.addEventListener) {
|
Chris@441
|
5362 isIELegacyEvent = function(event) {
|
Chris@441
|
5363 return !(event instanceof window.Event);
|
Chris@441
|
5364 };
|
Chris@441
|
5365 } else {
|
Chris@441
|
5366 isIELegacyEvent = function(event) { return true; };
|
Chris@0
|
5367 }
|
Chris@441
|
5368 }
|
Chris@441
|
5369
|
Chris@441
|
5370 var _isButton;
|
Chris@441
|
5371
|
Chris@441
|
5372 function _isButtonForDOMEvents(event, code) {
|
Chris@441
|
5373 return event.which ? (event.which === code + 1) : (event.button === code);
|
Chris@441
|
5374 }
|
Chris@441
|
5375
|
Chris@441
|
5376 var legacyButtonMap = { 0: 1, 1: 4, 2: 2 };
|
Chris@441
|
5377 function _isButtonForLegacyEvents(event, code) {
|
Chris@441
|
5378 return event.button === legacyButtonMap[code];
|
Chris@441
|
5379 }
|
Chris@441
|
5380
|
Chris@441
|
5381 function _isButtonForWebKit(event, code) {
|
Chris@441
|
5382 switch (code) {
|
Chris@441
|
5383 case 0: return event.which == 1 && !event.metaKey;
|
Chris@441
|
5384 case 1: return event.which == 2 || (event.which == 1 && event.metaKey);
|
Chris@441
|
5385 case 2: return event.which == 3;
|
Chris@441
|
5386 default: return false;
|
Chris@441
|
5387 }
|
Chris@441
|
5388 }
|
Chris@441
|
5389
|
Chris@441
|
5390 if (window.attachEvent) {
|
Chris@441
|
5391 if (!window.addEventListener) {
|
Chris@441
|
5392 _isButton = _isButtonForLegacyEvents;
|
Chris@441
|
5393 } else {
|
Chris@441
|
5394 _isButton = function(event, code) {
|
Chris@441
|
5395 return isIELegacyEvent(event) ? _isButtonForLegacyEvents(event, code) :
|
Chris@441
|
5396 _isButtonForDOMEvents(event, code);
|
Chris@441
|
5397 }
|
Chris@441
|
5398 }
|
Chris@0
|
5399 } else if (Prototype.Browser.WebKit) {
|
Chris@441
|
5400 _isButton = _isButtonForWebKit;
|
Chris@441
|
5401 } else {
|
Chris@441
|
5402 _isButton = _isButtonForDOMEvents;
|
Chris@441
|
5403 }
|
Chris@441
|
5404
|
Chris@441
|
5405 function isLeftClick(event) { return _isButton(event, 0) }
|
Chris@441
|
5406
|
Chris@441
|
5407 function isMiddleClick(event) { return _isButton(event, 1) }
|
Chris@441
|
5408
|
Chris@441
|
5409 function isRightClick(event) { return _isButton(event, 2) }
|
Chris@441
|
5410
|
Chris@441
|
5411 function element(event) {
|
Chris@441
|
5412 event = Event.extend(event);
|
Chris@441
|
5413
|
Chris@441
|
5414 var node = event.target, type = event.type,
|
Chris@441
|
5415 currentTarget = event.currentTarget;
|
Chris@441
|
5416
|
Chris@441
|
5417 if (currentTarget && currentTarget.tagName) {
|
Chris@441
|
5418 if (type === 'load' || type === 'error' ||
|
Chris@441
|
5419 (type === 'click' && currentTarget.tagName.toLowerCase() === 'input'
|
Chris@441
|
5420 && currentTarget.type === 'radio'))
|
Chris@441
|
5421 node = currentTarget;
|
Chris@441
|
5422 }
|
Chris@441
|
5423
|
Chris@441
|
5424 if (node.nodeType == Node.TEXT_NODE)
|
Chris@441
|
5425 node = node.parentNode;
|
Chris@441
|
5426
|
Chris@441
|
5427 return Element.extend(node);
|
Chris@441
|
5428 }
|
Chris@441
|
5429
|
Chris@441
|
5430 function findElement(event, expression) {
|
Chris@441
|
5431 var element = Event.element(event);
|
Chris@441
|
5432
|
Chris@441
|
5433 if (!expression) return element;
|
Chris@441
|
5434 while (element) {
|
Chris@441
|
5435 if (Object.isElement(element) && Prototype.Selector.match(element, expression)) {
|
Chris@441
|
5436 return Element.extend(element);
|
Chris@0
|
5437 }
|
Chris@441
|
5438 element = element.parentNode;
|
Chris@0
|
5439 }
|
Chris@441
|
5440 }
|
Chris@441
|
5441
|
Chris@441
|
5442 function pointer(event) {
|
Chris@441
|
5443 return { x: pointerX(event), y: pointerY(event) };
|
Chris@441
|
5444 }
|
Chris@441
|
5445
|
Chris@441
|
5446 function pointerX(event) {
|
Chris@441
|
5447 var docElement = document.documentElement,
|
Chris@441
|
5448 body = document.body || { scrollLeft: 0 };
|
Chris@441
|
5449
|
Chris@441
|
5450 return event.pageX || (event.clientX +
|
Chris@441
|
5451 (docElement.scrollLeft || body.scrollLeft) -
|
Chris@441
|
5452 (docElement.clientLeft || 0));
|
Chris@441
|
5453 }
|
Chris@441
|
5454
|
Chris@441
|
5455 function pointerY(event) {
|
Chris@441
|
5456 var docElement = document.documentElement,
|
Chris@441
|
5457 body = document.body || { scrollTop: 0 };
|
Chris@441
|
5458
|
Chris@441
|
5459 return event.pageY || (event.clientY +
|
Chris@441
|
5460 (docElement.scrollTop || body.scrollTop) -
|
Chris@441
|
5461 (docElement.clientTop || 0));
|
Chris@441
|
5462 }
|
Chris@441
|
5463
|
Chris@441
|
5464
|
Chris@441
|
5465 function stop(event) {
|
Chris@441
|
5466 Event.extend(event);
|
Chris@441
|
5467 event.preventDefault();
|
Chris@441
|
5468 event.stopPropagation();
|
Chris@441
|
5469
|
Chris@441
|
5470 event.stopped = true;
|
Chris@441
|
5471 }
|
Chris@441
|
5472
|
Chris@441
|
5473
|
Chris@441
|
5474 Event.Methods = {
|
Chris@441
|
5475 isLeftClick: isLeftClick,
|
Chris@441
|
5476 isMiddleClick: isMiddleClick,
|
Chris@441
|
5477 isRightClick: isRightClick,
|
Chris@441
|
5478
|
Chris@441
|
5479 element: element,
|
Chris@441
|
5480 findElement: findElement,
|
Chris@441
|
5481
|
Chris@441
|
5482 pointer: pointer,
|
Chris@441
|
5483 pointerX: pointerX,
|
Chris@441
|
5484 pointerY: pointerY,
|
Chris@441
|
5485
|
Chris@441
|
5486 stop: stop
|
Chris@0
|
5487 };
|
Chris@441
|
5488
|
Chris@0
|
5489 var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
|
Chris@0
|
5490 m[name] = Event.Methods[name].methodize();
|
Chris@0
|
5491 return m;
|
Chris@0
|
5492 });
|
Chris@0
|
5493
|
Chris@441
|
5494 if (window.attachEvent) {
|
Chris@441
|
5495 function _relatedTarget(event) {
|
Chris@441
|
5496 var element;
|
Chris@441
|
5497 switch (event.type) {
|
Chris@441
|
5498 case 'mouseover':
|
Chris@441
|
5499 case 'mouseenter':
|
Chris@441
|
5500 element = event.fromElement;
|
Chris@441
|
5501 break;
|
Chris@441
|
5502 case 'mouseout':
|
Chris@441
|
5503 case 'mouseleave':
|
Chris@441
|
5504 element = event.toElement;
|
Chris@441
|
5505 break;
|
Chris@441
|
5506 default:
|
Chris@441
|
5507 return null;
|
Chris@441
|
5508 }
|
Chris@441
|
5509 return Element.extend(element);
|
Chris@441
|
5510 }
|
Chris@441
|
5511
|
Chris@441
|
5512 var additionalMethods = {
|
Chris@0
|
5513 stopPropagation: function() { this.cancelBubble = true },
|
Chris@0
|
5514 preventDefault: function() { this.returnValue = false },
|
Chris@441
|
5515 inspect: function() { return '[object Event]' }
|
Chris@441
|
5516 };
|
Chris@441
|
5517
|
Chris@441
|
5518 Event.extend = function(event, element) {
|
Chris@0
|
5519 if (!event) return false;
|
Chris@441
|
5520
|
Chris@441
|
5521 if (!isIELegacyEvent(event)) return event;
|
Chris@441
|
5522
|
Chris@0
|
5523 if (event._extendedByPrototype) return event;
|
Chris@0
|
5524 event._extendedByPrototype = Prototype.emptyFunction;
|
Chris@441
|
5525
|
Chris@0
|
5526 var pointer = Event.pointer(event);
|
Chris@441
|
5527
|
Chris@0
|
5528 Object.extend(event, {
|
Chris@441
|
5529 target: event.srcElement || element,
|
Chris@441
|
5530 relatedTarget: _relatedTarget(event),
|
Chris@0
|
5531 pageX: pointer.x,
|
Chris@0
|
5532 pageY: pointer.y
|
Chris@0
|
5533 });
|
Chris@441
|
5534
|
Chris@441
|
5535 Object.extend(event, methods);
|
Chris@441
|
5536 Object.extend(event, additionalMethods);
|
Chris@441
|
5537
|
Chris@441
|
5538 return event;
|
Chris@0
|
5539 };
|
Chris@0
|
5540 } else {
|
Chris@441
|
5541 Event.extend = Prototype.K;
|
Chris@441
|
5542 }
|
Chris@441
|
5543
|
Chris@441
|
5544 if (window.addEventListener) {
|
Chris@441
|
5545 Event.prototype = window.Event.prototype || document.createEvent('HTMLEvents').__proto__;
|
Chris@0
|
5546 Object.extend(Event.prototype, methods);
|
Chris@441
|
5547 }
|
Chris@441
|
5548
|
Chris@441
|
5549 function _createResponder(element, eventName, handler) {
|
Chris@441
|
5550 var registry = Element.retrieve(element, 'prototype_event_registry');
|
Chris@441
|
5551
|
Chris@441
|
5552 if (Object.isUndefined(registry)) {
|
Chris@441
|
5553 CACHE.push(element);
|
Chris@441
|
5554 registry = Element.retrieve(element, 'prototype_event_registry', $H());
|
Chris@441
|
5555 }
|
Chris@441
|
5556
|
Chris@441
|
5557 var respondersForEvent = registry.get(eventName);
|
Chris@441
|
5558 if (Object.isUndefined(respondersForEvent)) {
|
Chris@441
|
5559 respondersForEvent = [];
|
Chris@441
|
5560 registry.set(eventName, respondersForEvent);
|
Chris@441
|
5561 }
|
Chris@441
|
5562
|
Chris@441
|
5563 if (respondersForEvent.pluck('handler').include(handler)) return false;
|
Chris@441
|
5564
|
Chris@441
|
5565 var responder;
|
Chris@441
|
5566 if (eventName.include(":")) {
|
Chris@441
|
5567 responder = function(event) {
|
Chris@441
|
5568 if (Object.isUndefined(event.eventName))
|
Chris@441
|
5569 return false;
|
Chris@441
|
5570
|
Chris@441
|
5571 if (event.eventName !== eventName)
|
Chris@441
|
5572 return false;
|
Chris@441
|
5573
|
Chris@441
|
5574 Event.extend(event, element);
|
Chris@441
|
5575 handler.call(element, event);
|
Chris@441
|
5576 };
|
Chris@441
|
5577 } else {
|
Chris@441
|
5578 if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED &&
|
Chris@441
|
5579 (eventName === "mouseenter" || eventName === "mouseleave")) {
|
Chris@441
|
5580 if (eventName === "mouseenter" || eventName === "mouseleave") {
|
Chris@441
|
5581 responder = function(event) {
|
Chris@441
|
5582 Event.extend(event, element);
|
Chris@441
|
5583
|
Chris@441
|
5584 var parent = event.relatedTarget;
|
Chris@441
|
5585 while (parent && parent !== element) {
|
Chris@441
|
5586 try { parent = parent.parentNode; }
|
Chris@441
|
5587 catch(e) { parent = element; }
|
Chris@441
|
5588 }
|
Chris@441
|
5589
|
Chris@441
|
5590 if (parent === element) return;
|
Chris@441
|
5591
|
Chris@441
|
5592 handler.call(element, event);
|
Chris@441
|
5593 };
|
Chris@441
|
5594 }
|
Chris@441
|
5595 } else {
|
Chris@441
|
5596 responder = function(event) {
|
Chris@441
|
5597 Event.extend(event, element);
|
Chris@441
|
5598 handler.call(element, event);
|
Chris@441
|
5599 };
|
Chris@441
|
5600 }
|
Chris@441
|
5601 }
|
Chris@441
|
5602
|
Chris@441
|
5603 responder.handler = handler;
|
Chris@441
|
5604 respondersForEvent.push(responder);
|
Chris@441
|
5605 return responder;
|
Chris@441
|
5606 }
|
Chris@441
|
5607
|
Chris@441
|
5608 function _destroyCache() {
|
Chris@441
|
5609 for (var i = 0, length = CACHE.length; i < length; i++) {
|
Chris@441
|
5610 Event.stopObserving(CACHE[i]);
|
Chris@441
|
5611 CACHE[i] = null;
|
Chris@441
|
5612 }
|
Chris@441
|
5613 }
|
Chris@441
|
5614
|
Chris@441
|
5615 var CACHE = [];
|
Chris@441
|
5616
|
Chris@441
|
5617 if (Prototype.Browser.IE)
|
Chris@441
|
5618 window.attachEvent('onunload', _destroyCache);
|
Chris@441
|
5619
|
Chris@441
|
5620 if (Prototype.Browser.WebKit)
|
Chris@441
|
5621 window.addEventListener('unload', Prototype.emptyFunction, false);
|
Chris@441
|
5622
|
Chris@441
|
5623
|
Chris@441
|
5624 var _getDOMEventName = Prototype.K,
|
Chris@441
|
5625 translations = { mouseenter: "mouseover", mouseleave: "mouseout" };
|
Chris@441
|
5626
|
Chris@441
|
5627 if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED) {
|
Chris@441
|
5628 _getDOMEventName = function(eventName) {
|
Chris@441
|
5629 return (translations[eventName] || eventName);
|
Chris@441
|
5630 };
|
Chris@441
|
5631 }
|
Chris@441
|
5632
|
Chris@441
|
5633 function observe(element, eventName, handler) {
|
Chris@441
|
5634 element = $(element);
|
Chris@441
|
5635
|
Chris@441
|
5636 var responder = _createResponder(element, eventName, handler);
|
Chris@441
|
5637
|
Chris@441
|
5638 if (!responder) return element;
|
Chris@441
|
5639
|
Chris@441
|
5640 if (eventName.include(':')) {
|
Chris@441
|
5641 if (element.addEventListener)
|
Chris@441
|
5642 element.addEventListener("dataavailable", responder, false);
|
Chris@441
|
5643 else {
|
Chris@441
|
5644 element.attachEvent("ondataavailable", responder);
|
Chris@441
|
5645 element.attachEvent("onlosecapture", responder);
|
Chris@441
|
5646 }
|
Chris@441
|
5647 } else {
|
Chris@441
|
5648 var actualEventName = _getDOMEventName(eventName);
|
Chris@441
|
5649
|
Chris@441
|
5650 if (element.addEventListener)
|
Chris@441
|
5651 element.addEventListener(actualEventName, responder, false);
|
Chris@441
|
5652 else
|
Chris@441
|
5653 element.attachEvent("on" + actualEventName, responder);
|
Chris@441
|
5654 }
|
Chris@441
|
5655
|
Chris@441
|
5656 return element;
|
Chris@441
|
5657 }
|
Chris@441
|
5658
|
Chris@441
|
5659 function stopObserving(element, eventName, handler) {
|
Chris@441
|
5660 element = $(element);
|
Chris@441
|
5661
|
Chris@441
|
5662 var registry = Element.retrieve(element, 'prototype_event_registry');
|
Chris@441
|
5663 if (!registry) return element;
|
Chris@441
|
5664
|
Chris@441
|
5665 if (!eventName) {
|
Chris@441
|
5666 registry.each( function(pair) {
|
Chris@441
|
5667 var eventName = pair.key;
|
Chris@441
|
5668 stopObserving(element, eventName);
|
Chris@441
|
5669 });
|
Chris@441
|
5670 return element;
|
Chris@441
|
5671 }
|
Chris@441
|
5672
|
Chris@441
|
5673 var responders = registry.get(eventName);
|
Chris@441
|
5674 if (!responders) return element;
|
Chris@441
|
5675
|
Chris@441
|
5676 if (!handler) {
|
Chris@441
|
5677 responders.each(function(r) {
|
Chris@441
|
5678 stopObserving(element, eventName, r.handler);
|
Chris@441
|
5679 });
|
Chris@441
|
5680 return element;
|
Chris@441
|
5681 }
|
Chris@441
|
5682
|
Chris@441
|
5683 var i = responders.length, responder;
|
Chris@441
|
5684 while (i--) {
|
Chris@441
|
5685 if (responders[i].handler === handler) {
|
Chris@441
|
5686 responder = responders[i];
|
Chris@441
|
5687 break;
|
Chris@441
|
5688 }
|
Chris@441
|
5689 }
|
Chris@441
|
5690 if (!responder) return element;
|
Chris@441
|
5691
|
Chris@441
|
5692 if (eventName.include(':')) {
|
Chris@441
|
5693 if (element.removeEventListener)
|
Chris@441
|
5694 element.removeEventListener("dataavailable", responder, false);
|
Chris@441
|
5695 else {
|
Chris@441
|
5696 element.detachEvent("ondataavailable", responder);
|
Chris@441
|
5697 element.detachEvent("onlosecapture", responder);
|
Chris@441
|
5698 }
|
Chris@441
|
5699 } else {
|
Chris@441
|
5700 var actualEventName = _getDOMEventName(eventName);
|
Chris@441
|
5701 if (element.removeEventListener)
|
Chris@441
|
5702 element.removeEventListener(actualEventName, responder, false);
|
Chris@441
|
5703 else
|
Chris@441
|
5704 element.detachEvent('on' + actualEventName, responder);
|
Chris@441
|
5705 }
|
Chris@441
|
5706
|
Chris@441
|
5707 registry.set(eventName, responders.without(responder));
|
Chris@441
|
5708
|
Chris@441
|
5709 return element;
|
Chris@441
|
5710 }
|
Chris@441
|
5711
|
Chris@441
|
5712 function fire(element, eventName, memo, bubble) {
|
Chris@441
|
5713 element = $(element);
|
Chris@441
|
5714
|
Chris@441
|
5715 if (Object.isUndefined(bubble))
|
Chris@441
|
5716 bubble = true;
|
Chris@441
|
5717
|
Chris@441
|
5718 if (element == document && document.createEvent && !element.dispatchEvent)
|
Chris@441
|
5719 element = document.documentElement;
|
Chris@441
|
5720
|
Chris@441
|
5721 var event;
|
Chris@441
|
5722 if (document.createEvent) {
|
Chris@441
|
5723 event = document.createEvent('HTMLEvents');
|
Chris@441
|
5724 event.initEvent('dataavailable', bubble, true);
|
Chris@441
|
5725 } else {
|
Chris@441
|
5726 event = document.createEventObject();
|
Chris@441
|
5727 event.eventType = bubble ? 'ondataavailable' : 'onlosecapture';
|
Chris@441
|
5728 }
|
Chris@441
|
5729
|
Chris@441
|
5730 event.eventName = eventName;
|
Chris@441
|
5731 event.memo = memo || { };
|
Chris@441
|
5732
|
Chris@441
|
5733 if (document.createEvent)
|
Chris@441
|
5734 element.dispatchEvent(event);
|
Chris@441
|
5735 else
|
Chris@441
|
5736 element.fireEvent(event.eventType, event);
|
Chris@441
|
5737
|
Chris@441
|
5738 return Event.extend(event);
|
Chris@441
|
5739 }
|
Chris@441
|
5740
|
Chris@441
|
5741 Event.Handler = Class.create({
|
Chris@441
|
5742 initialize: function(element, eventName, selector, callback) {
|
Chris@441
|
5743 this.element = $(element);
|
Chris@441
|
5744 this.eventName = eventName;
|
Chris@441
|
5745 this.selector = selector;
|
Chris@441
|
5746 this.callback = callback;
|
Chris@441
|
5747 this.handler = this.handleEvent.bind(this);
|
Chris@441
|
5748 },
|
Chris@441
|
5749
|
Chris@441
|
5750 start: function() {
|
Chris@441
|
5751 Event.observe(this.element, this.eventName, this.handler);
|
Chris@441
|
5752 return this;
|
Chris@441
|
5753 },
|
Chris@441
|
5754
|
Chris@441
|
5755 stop: function() {
|
Chris@441
|
5756 Event.stopObserving(this.element, this.eventName, this.handler);
|
Chris@441
|
5757 return this;
|
Chris@441
|
5758 },
|
Chris@441
|
5759
|
Chris@441
|
5760 handleEvent: function(event) {
|
Chris@441
|
5761 var element = Event.findElement(event, this.selector);
|
Chris@441
|
5762 if (element) this.callback.call(this.element, event, element);
|
Chris@441
|
5763 }
|
Chris@441
|
5764 });
|
Chris@441
|
5765
|
Chris@441
|
5766 function on(element, eventName, selector, callback) {
|
Chris@441
|
5767 element = $(element);
|
Chris@441
|
5768 if (Object.isFunction(selector) && Object.isUndefined(callback)) {
|
Chris@441
|
5769 callback = selector, selector = null;
|
Chris@441
|
5770 }
|
Chris@441
|
5771
|
Chris@441
|
5772 return new Event.Handler(element, eventName, selector, callback).start();
|
Chris@441
|
5773 }
|
Chris@441
|
5774
|
Chris@441
|
5775 Object.extend(Event, Event.Methods);
|
Chris@441
|
5776
|
Chris@441
|
5777 Object.extend(Event, {
|
Chris@441
|
5778 fire: fire,
|
Chris@441
|
5779 observe: observe,
|
Chris@441
|
5780 stopObserving: stopObserving,
|
Chris@441
|
5781 on: on
|
Chris@441
|
5782 });
|
Chris@441
|
5783
|
Chris@441
|
5784 Element.addMethods({
|
Chris@441
|
5785 fire: fire,
|
Chris@441
|
5786
|
Chris@441
|
5787 observe: observe,
|
Chris@441
|
5788
|
Chris@441
|
5789 stopObserving: stopObserving,
|
Chris@441
|
5790
|
Chris@441
|
5791 on: on
|
Chris@441
|
5792 });
|
Chris@441
|
5793
|
Chris@441
|
5794 Object.extend(document, {
|
Chris@441
|
5795 fire: fire.methodize(),
|
Chris@441
|
5796
|
Chris@441
|
5797 observe: observe.methodize(),
|
Chris@441
|
5798
|
Chris@441
|
5799 stopObserving: stopObserving.methodize(),
|
Chris@441
|
5800
|
Chris@441
|
5801 on: on.methodize(),
|
Chris@441
|
5802
|
Chris@441
|
5803 loaded: false
|
Chris@441
|
5804 });
|
Chris@441
|
5805
|
Chris@441
|
5806 if (window.Event) Object.extend(window.Event, Event);
|
Chris@441
|
5807 else window.Event = Event;
|
Chris@0
|
5808 })();
|
Chris@0
|
5809
|
Chris@0
|
5810 (function() {
|
Chris@0
|
5811 /* Support for the DOMContentLoaded event is based on work by Dan Webb,
|
Chris@441
|
5812 Matthias Miller, Dean Edwards, John Resig, and Diego Perini. */
|
Chris@0
|
5813
|
Chris@0
|
5814 var timer;
|
Chris@0
|
5815
|
Chris@0
|
5816 function fireContentLoadedEvent() {
|
Chris@0
|
5817 if (document.loaded) return;
|
Chris@441
|
5818 if (timer) window.clearTimeout(timer);
|
Chris@0
|
5819 document.loaded = true;
|
Chris@441
|
5820 document.fire('dom:loaded');
|
Chris@441
|
5821 }
|
Chris@441
|
5822
|
Chris@441
|
5823 function checkReadyState() {
|
Chris@441
|
5824 if (document.readyState === 'complete') {
|
Chris@441
|
5825 document.stopObserving('readystatechange', checkReadyState);
|
Chris@441
|
5826 fireContentLoadedEvent();
|
Chris@441
|
5827 }
|
Chris@441
|
5828 }
|
Chris@441
|
5829
|
Chris@441
|
5830 function pollDoScroll() {
|
Chris@441
|
5831 try { document.documentElement.doScroll('left'); }
|
Chris@441
|
5832 catch(e) {
|
Chris@441
|
5833 timer = pollDoScroll.defer();
|
Chris@441
|
5834 return;
|
Chris@441
|
5835 }
|
Chris@441
|
5836 fireContentLoadedEvent();
|
Chris@0
|
5837 }
|
Chris@0
|
5838
|
Chris@0
|
5839 if (document.addEventListener) {
|
Chris@441
|
5840 document.addEventListener('DOMContentLoaded', fireContentLoadedEvent, false);
|
Chris@0
|
5841 } else {
|
Chris@441
|
5842 document.observe('readystatechange', checkReadyState);
|
Chris@441
|
5843 if (window == top)
|
Chris@441
|
5844 timer = pollDoScroll.defer();
|
Chris@441
|
5845 }
|
Chris@441
|
5846
|
Chris@441
|
5847 Event.observe(window, 'load', fireContentLoadedEvent);
|
Chris@0
|
5848 })();
|
Chris@441
|
5849
|
Chris@441
|
5850 Element.addMethods();
|
Chris@441
|
5851
|
Chris@0
|
5852 /*------------------------------- DEPRECATED -------------------------------*/
|
Chris@0
|
5853
|
Chris@0
|
5854 Hash.toQueryString = Object.toQueryString;
|
Chris@0
|
5855
|
Chris@0
|
5856 var Toggle = { display: Element.toggle };
|
Chris@0
|
5857
|
Chris@0
|
5858 Element.Methods.childOf = Element.Methods.descendantOf;
|
Chris@0
|
5859
|
Chris@0
|
5860 var Insertion = {
|
Chris@0
|
5861 Before: function(element, content) {
|
Chris@0
|
5862 return Element.insert(element, {before:content});
|
Chris@0
|
5863 },
|
Chris@0
|
5864
|
Chris@0
|
5865 Top: function(element, content) {
|
Chris@0
|
5866 return Element.insert(element, {top:content});
|
Chris@0
|
5867 },
|
Chris@0
|
5868
|
Chris@0
|
5869 Bottom: function(element, content) {
|
Chris@0
|
5870 return Element.insert(element, {bottom:content});
|
Chris@0
|
5871 },
|
Chris@0
|
5872
|
Chris@0
|
5873 After: function(element, content) {
|
Chris@0
|
5874 return Element.insert(element, {after:content});
|
Chris@0
|
5875 }
|
Chris@0
|
5876 };
|
Chris@0
|
5877
|
Chris@0
|
5878 var $continue = new Error('"throw $continue" is deprecated, use "return" instead');
|
Chris@0
|
5879
|
Chris@0
|
5880 var Position = {
|
Chris@0
|
5881 includeScrollOffsets: false,
|
Chris@0
|
5882
|
Chris@0
|
5883 prepare: function() {
|
Chris@0
|
5884 this.deltaX = window.pageXOffset
|
Chris@0
|
5885 || document.documentElement.scrollLeft
|
Chris@0
|
5886 || document.body.scrollLeft
|
Chris@0
|
5887 || 0;
|
Chris@0
|
5888 this.deltaY = window.pageYOffset
|
Chris@0
|
5889 || document.documentElement.scrollTop
|
Chris@0
|
5890 || document.body.scrollTop
|
Chris@0
|
5891 || 0;
|
Chris@0
|
5892 },
|
Chris@0
|
5893
|
Chris@0
|
5894 within: function(element, x, y) {
|
Chris@0
|
5895 if (this.includeScrollOffsets)
|
Chris@0
|
5896 return this.withinIncludingScrolloffsets(element, x, y);
|
Chris@0
|
5897 this.xcomp = x;
|
Chris@0
|
5898 this.ycomp = y;
|
Chris@0
|
5899 this.offset = Element.cumulativeOffset(element);
|
Chris@0
|
5900
|
Chris@0
|
5901 return (y >= this.offset[1] &&
|
Chris@0
|
5902 y < this.offset[1] + element.offsetHeight &&
|
Chris@0
|
5903 x >= this.offset[0] &&
|
Chris@0
|
5904 x < this.offset[0] + element.offsetWidth);
|
Chris@0
|
5905 },
|
Chris@0
|
5906
|
Chris@0
|
5907 withinIncludingScrolloffsets: function(element, x, y) {
|
Chris@0
|
5908 var offsetcache = Element.cumulativeScrollOffset(element);
|
Chris@0
|
5909
|
Chris@0
|
5910 this.xcomp = x + offsetcache[0] - this.deltaX;
|
Chris@0
|
5911 this.ycomp = y + offsetcache[1] - this.deltaY;
|
Chris@0
|
5912 this.offset = Element.cumulativeOffset(element);
|
Chris@0
|
5913
|
Chris@0
|
5914 return (this.ycomp >= this.offset[1] &&
|
Chris@0
|
5915 this.ycomp < this.offset[1] + element.offsetHeight &&
|
Chris@0
|
5916 this.xcomp >= this.offset[0] &&
|
Chris@0
|
5917 this.xcomp < this.offset[0] + element.offsetWidth);
|
Chris@0
|
5918 },
|
Chris@0
|
5919
|
Chris@0
|
5920 overlap: function(mode, element) {
|
Chris@0
|
5921 if (!mode) return 0;
|
Chris@0
|
5922 if (mode == 'vertical')
|
Chris@0
|
5923 return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
|
Chris@0
|
5924 element.offsetHeight;
|
Chris@0
|
5925 if (mode == 'horizontal')
|
Chris@0
|
5926 return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
|
Chris@0
|
5927 element.offsetWidth;
|
Chris@0
|
5928 },
|
Chris@0
|
5929
|
Chris@0
|
5930
|
Chris@0
|
5931 cumulativeOffset: Element.Methods.cumulativeOffset,
|
Chris@0
|
5932
|
Chris@0
|
5933 positionedOffset: Element.Methods.positionedOffset,
|
Chris@0
|
5934
|
Chris@0
|
5935 absolutize: function(element) {
|
Chris@0
|
5936 Position.prepare();
|
Chris@0
|
5937 return Element.absolutize(element);
|
Chris@0
|
5938 },
|
Chris@0
|
5939
|
Chris@0
|
5940 relativize: function(element) {
|
Chris@0
|
5941 Position.prepare();
|
Chris@0
|
5942 return Element.relativize(element);
|
Chris@0
|
5943 },
|
Chris@0
|
5944
|
Chris@0
|
5945 realOffset: Element.Methods.cumulativeScrollOffset,
|
Chris@0
|
5946
|
Chris@0
|
5947 offsetParent: Element.Methods.getOffsetParent,
|
Chris@0
|
5948
|
Chris@0
|
5949 page: Element.Methods.viewportOffset,
|
Chris@0
|
5950
|
Chris@0
|
5951 clone: function(source, target, options) {
|
Chris@0
|
5952 options = options || { };
|
Chris@0
|
5953 return Element.clonePosition(target, source, options);
|
Chris@0
|
5954 }
|
Chris@0
|
5955 };
|
Chris@0
|
5956
|
Chris@0
|
5957 /*--------------------------------------------------------------------------*/
|
Chris@0
|
5958
|
Chris@0
|
5959 if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
|
Chris@0
|
5960 function iter(name) {
|
Chris@0
|
5961 return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
|
Chris@0
|
5962 }
|
Chris@0
|
5963
|
Chris@0
|
5964 instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
|
Chris@0
|
5965 function(element, className) {
|
Chris@0
|
5966 className = className.toString().strip();
|
Chris@0
|
5967 var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
|
Chris@0
|
5968 return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
|
Chris@0
|
5969 } : function(element, className) {
|
Chris@0
|
5970 className = className.toString().strip();
|
Chris@0
|
5971 var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
|
Chris@0
|
5972 if (!classNames && !className) return elements;
|
Chris@0
|
5973
|
Chris@0
|
5974 var nodes = $(element).getElementsByTagName('*');
|
Chris@0
|
5975 className = ' ' + className + ' ';
|
Chris@0
|
5976
|
Chris@0
|
5977 for (var i = 0, child, cn; child = nodes[i]; i++) {
|
Chris@0
|
5978 if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
|
Chris@0
|
5979 (classNames && classNames.all(function(name) {
|
Chris@0
|
5980 return !name.toString().blank() && cn.include(' ' + name + ' ');
|
Chris@0
|
5981 }))))
|
Chris@0
|
5982 elements.push(Element.extend(child));
|
Chris@0
|
5983 }
|
Chris@0
|
5984 return elements;
|
Chris@0
|
5985 };
|
Chris@0
|
5986
|
Chris@0
|
5987 return function(className, parentElement) {
|
Chris@0
|
5988 return $(parentElement || document.body).getElementsByClassName(className);
|
Chris@0
|
5989 };
|
Chris@0
|
5990 }(Element.Methods);
|
Chris@0
|
5991
|
Chris@0
|
5992 /*--------------------------------------------------------------------------*/
|
Chris@0
|
5993
|
Chris@0
|
5994 Element.ClassNames = Class.create();
|
Chris@0
|
5995 Element.ClassNames.prototype = {
|
Chris@0
|
5996 initialize: function(element) {
|
Chris@0
|
5997 this.element = $(element);
|
Chris@0
|
5998 },
|
Chris@0
|
5999
|
Chris@0
|
6000 _each: function(iterator) {
|
Chris@0
|
6001 this.element.className.split(/\s+/).select(function(name) {
|
Chris@0
|
6002 return name.length > 0;
|
Chris@0
|
6003 })._each(iterator);
|
Chris@0
|
6004 },
|
Chris@0
|
6005
|
Chris@0
|
6006 set: function(className) {
|
Chris@0
|
6007 this.element.className = className;
|
Chris@0
|
6008 },
|
Chris@0
|
6009
|
Chris@0
|
6010 add: function(classNameToAdd) {
|
Chris@0
|
6011 if (this.include(classNameToAdd)) return;
|
Chris@0
|
6012 this.set($A(this).concat(classNameToAdd).join(' '));
|
Chris@0
|
6013 },
|
Chris@0
|
6014
|
Chris@0
|
6015 remove: function(classNameToRemove) {
|
Chris@0
|
6016 if (!this.include(classNameToRemove)) return;
|
Chris@0
|
6017 this.set($A(this).without(classNameToRemove).join(' '));
|
Chris@0
|
6018 },
|
Chris@0
|
6019
|
Chris@0
|
6020 toString: function() {
|
Chris@0
|
6021 return $A(this).join(' ');
|
Chris@0
|
6022 }
|
Chris@0
|
6023 };
|
Chris@0
|
6024
|
Chris@0
|
6025 Object.extend(Element.ClassNames.prototype, Enumerable);
|
Chris@0
|
6026
|
Chris@0
|
6027 /*--------------------------------------------------------------------------*/
|
Chris@0
|
6028
|
Chris@441
|
6029 (function() {
|
Chris@441
|
6030 window.Selector = Class.create({
|
Chris@441
|
6031 initialize: function(expression) {
|
Chris@441
|
6032 this.expression = expression.strip();
|
Chris@441
|
6033 },
|
Chris@441
|
6034
|
Chris@441
|
6035 findElements: function(rootElement) {
|
Chris@441
|
6036 return Prototype.Selector.select(this.expression, rootElement);
|
Chris@441
|
6037 },
|
Chris@441
|
6038
|
Chris@441
|
6039 match: function(element) {
|
Chris@441
|
6040 return Prototype.Selector.match(element, this.expression);
|
Chris@441
|
6041 },
|
Chris@441
|
6042
|
Chris@441
|
6043 toString: function() {
|
Chris@441
|
6044 return this.expression;
|
Chris@441
|
6045 },
|
Chris@441
|
6046
|
Chris@441
|
6047 inspect: function() {
|
Chris@441
|
6048 return "#<Selector: " + this.expression + ">";
|
Chris@441
|
6049 }
|
Chris@441
|
6050 });
|
Chris@441
|
6051
|
Chris@441
|
6052 Object.extend(Selector, {
|
Chris@441
|
6053 matchElements: function(elements, expression) {
|
Chris@441
|
6054 var match = Prototype.Selector.match,
|
Chris@441
|
6055 results = [];
|
Chris@441
|
6056
|
Chris@441
|
6057 for (var i = 0, length = elements.length; i < length; i++) {
|
Chris@441
|
6058 var element = elements[i];
|
Chris@441
|
6059 if (match(element, expression)) {
|
Chris@441
|
6060 results.push(Element.extend(element));
|
Chris@441
|
6061 }
|
Chris@441
|
6062 }
|
Chris@441
|
6063 return results;
|
Chris@441
|
6064 },
|
Chris@441
|
6065
|
Chris@441
|
6066 findElement: function(elements, expression, index) {
|
Chris@441
|
6067 index = index || 0;
|
Chris@441
|
6068 var matchIndex = 0, element;
|
Chris@441
|
6069 for (var i = 0, length = elements.length; i < length; i++) {
|
Chris@441
|
6070 element = elements[i];
|
Chris@441
|
6071 if (Prototype.Selector.match(element, expression) && index === matchIndex++) {
|
Chris@441
|
6072 return Element.extend(element);
|
Chris@441
|
6073 }
|
Chris@441
|
6074 }
|
Chris@441
|
6075 },
|
Chris@441
|
6076
|
Chris@441
|
6077 findChildElements: function(element, expressions) {
|
Chris@441
|
6078 var selector = expressions.toArray().join(', ');
|
Chris@441
|
6079 return Prototype.Selector.select(selector, element || document);
|
Chris@441
|
6080 }
|
Chris@441
|
6081 });
|
Chris@441
|
6082 })();
|