Searching for lines matching __proto__ in 425K pages described in http://philip.html5.org/data/dotbot-20090424.txt www.civwiki.de/Bef%C3%B6rderungen_%28Civ4_FFH%29 document.createElement('div').__proto__ && www.civwiki.de/Bef%C3%B6rderungen_%28Civ4_FFH%29 document.createElement('div').__proto__ !== www.civwiki.de/Bef%C3%B6rderungen_%28Civ4_FFH%29 document.createElement('form').__proto__ www.civwiki.de/Bef%C3%B6rderungen_%28Civ4_FFH%29 document.createElement('div').__proto__) { www.civwiki.de/Bef%C3%B6rderungen_%28Civ4_FFH%29 window.HTMLElement.prototype = document.createElement('div').__proto__; www.civwiki.de/Bef%C3%B6rderungen_%28Civ4_FFH%29 window[klass].prototype = document.createElement(tagName).__proto__; www.civwiki.de/Bef%C3%B6rderungen_%28Civ4_FFH%29 Event.prototype = Event.prototype || document.createEvent("HTMLEvents").__proto__; us.anuncioo.com/tags/classifieds/sale-prefabricated-house klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__; annonces.ptitchef.com/tags/annonces/levure-marque?sort=date_2 klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__; www.louer-pour-les-vacances.com/a-la-mer/autres/6-personnes klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__; www.propertyindex.com/buying/s/14664/Properties-For-Sale-in-Aldsworth/1/a/ if (mouseEvt && mouseEvt.__proto__ && mouseEvt.__proto__.__defineGetter__) www.propertyindex.com/buying/s/14664/Properties-For-Sale-in-Aldsworth/1/a/ mouseEvt.__proto__.__defineGetter__('pageX', function() www.propertyindex.com/buying/s/14664/Properties-For-Sale-in-Aldsworth/1/a/ mouseEvt.__proto__.__defineGetter__('pageY', function() www.freemorn.com/music/guitar_chord_dictionary.html var Brwsr=(function x(){})[-5]=='x'?'FF3':(function x(){})[-6]=='x'?'FF2':/a/[-1]=='a'?'FF':'\v'=='v'?'IE':/a/.__proto__=='//'?'Saf':/s/.test(/a/.toString)?'Chr':/^function \(/.test([].sort)?'Op':'Unknown'; es.anuncioo.com/trabajo/oferta/educacion-y-cultura/andalucia/sevilla/escuela-de-estetica-eladio-1251175 klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__; labs.peritor.com/webistrano/browser/trunk/vendor/rails/railties/html/javascripts/prototype.js?rev=1
Line | Â |
---|---|
1 | /*Â Prototype JavaScript framework, version 1.5.1 |
2 | Â *Â (c) 2005-2007 Sam Stephenson |
3 | Â * |
4 | Â *Â Prototype is freely distributable under the terms of an MIT-style license. |
5 | Â *Â For details, see the Prototype web site: http://www.prototypejs.org/ |
6 | Â * |
7 | /*--------------------------------------------------------------------------*/ |
8 | |
9 | var Prototype = { |
10 | Â Version: '1.5.1', |
11 | |
12 | Â Browser: { |
13 | Â Â IE:Â Â Â !!(window.attachEvent && !window.opera), |
14 | Â Â Opera:Â !!window.opera, |
15 | Â Â WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, |
16 | Â Â Gecko:Â navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1 |
17 | Â }, |
18 | |
19 | Â BrowserFeatures: { |
20 | Â Â XPath: !!document.evaluate, |
21 | Â Â ElementExtensions: !!window.HTMLElement, |
22 | Â Â SpecificElementExtensions: |
23 | Â Â Â (document.createElement('div').__proto__ !== |
24 | Â Â Â Â document.createElement('form').__proto__) |
25 | Â }, |
26 | |
27 | Â ScriptFragment: '<script[^>]*>([\u0001-\uFFFF]*?)</script>', |
28 | Â JSONFilter: /^\/\*-secure-\s*(.*)\s*\*\/\s*$/, |
29 | |
30 | Â emptyFunction: function() { }, |
31 | Â K: function(x) { return x } |
32 | } |
33 | |
34 | var Class = { |
35 | Â create: function() { |
36 | Â Â return function() { |
37 | Â Â Â this.initialize.apply(this, arguments); |
38 | Â Â } |
39 | Â } |
40 | } |
41 | |
42 | var Abstract = new Object(); |
43 | |
44 | Object.extend = function(destination, source) { |
45 | Â for (var property in source) { |
46 | Â Â destination[property] = source[property]; |
47 | Â } |
48 | Â return destination; |
49 | } |
50 | |
51 | Object.extend(Object, { |
52 | Â inspect: function(object) { |
53 | Â Â try { |
54 | Â Â Â if (object === undefined) return 'undefined'; |
55 | Â Â Â if (object === null) return 'null'; |
56 | Â Â Â return object.inspect ? object.inspect() : object.toString(); |
57 | Â Â } catch (e) { |
58 | Â Â Â if (e instanceof RangeError) return '...'; |
59 | Â Â Â throw e; |
60 | Â Â } |
61 | Â }, |
62 | |
63 | Â toJSON: function(object) { |
64 | Â Â var type = typeof object; |
65 | Â Â switch(type) { |
66 | Â Â Â case 'undefined': |
67 | Â Â Â case 'function': |
68 | Â Â Â case 'unknown': return; |
69 | Â Â Â case 'boolean': return object.toString(); |
70 | Â Â } |
71 | Â Â if (object === null) return 'null'; |
72 | Â Â if (object.toJSON) return object.toJSON(); |
73 | Â Â if (object.ownerDocument === document) return; |
74 | Â Â var results = []; |
75 | Â Â for (var property in object) { |
76 | Â Â Â var value = Object.toJSON(object[property]); |
77 | Â Â Â if (value !== undefined) |
78 | Â Â Â Â results.push(property.toJSON() + ': ' + value); |
79 | Â Â } |
80 | Â Â return '{' + results.join(', ') + '}'; |
81 | Â }, |
82 | |
83 | Â keys: function(object) { |
84 | Â Â var keys = []; |
85 | Â Â for (var property in object) |
86 | Â Â Â keys.push(property); |
87 | Â Â return keys; |
88 | Â }, |
89 | |
90 | Â values: function(object) { |
91 | Â Â var values = []; |
92 | Â Â for (var property in object) |
93 | Â Â Â values.push(object[property]); |
94 | Â Â return values; |
95 | Â }, |
96 | |
97 | Â clone: function(object) { |
98 | Â Â return Object.extend({}, object); |
99 | Â } |
100 | }); |
101 | |
102 | Function.prototype.bind = function() { |
103 | Â var __method = this, args = $A(arguments), object = args.shift(); |
104 | Â return function() { |
105 | Â Â return __method.apply(object, args.concat($A(arguments))); |
106 | Â } |
107 | } |
108 | |
109 | Function.prototype.bindAsEventListener = function(object) { |
110 | Â var __method = this, args = $A(arguments), object = args.shift(); |
111 | Â return function(event) { |
112 | Â Â return __method.apply(object, [event || window.event].concat(args)); |
113 | Â } |
114 | } |
115 | |
116 | Object.extend(Number.prototype, { |
117 | Â toColorPart: function() { |
118 | Â Â return this.toPaddedString(2, 16); |
119 | Â }, |
120 | |
121 | Â succ: function() { |
122 | Â Â return this + 1; |
123 | Â }, |
124 | |
125 | Â times: function(iterator) { |
126 | Â Â $R(0, this, true).each(iterator); |
127 | Â Â return this; |
128 | Â }, |
129 | |
130 | Â toPaddedString: function(length, radix) { |
131 | Â Â var string = this.toString(radix || 10); |
132 | Â Â return '0'.times(length - string.length) + string; |
133 | Â }, |
134 | |
135 | Â toJSON: function() { |
136 | Â Â return isFinite(this) ? this.toString() : 'null'; |
137 | Â } |
138 | }); |
139 | |
140 | Date.prototype.toJSON = function() { |
141 | Â return '"' + this.getFullYear() + '-' + |
142 | Â Â (this.getMonth() + 1).toPaddedString(2) + '-' + |
143 | Â Â this.getDate().toPaddedString(2) + 'T' + |
144 | Â Â this.getHours().toPaddedString(2) + ':' + |
145 | Â Â this.getMinutes().toPaddedString(2) + ':' + |
146 | Â Â this.getSeconds().toPaddedString(2) + '"'; |
147 | }; |
148 | |
149 | var Try = { |
150 | Â these: function() { |
151 | Â Â var returnValue; |
152 | |
153 | Â Â for (var i = 0, length = arguments.length; i < length; i++) { |
154 | Â Â Â var lambda = arguments[i]; |
155 | Â Â Â try { |
156 | Â Â Â Â returnValue = lambda(); |
157 | Â Â Â Â break; |
158 | Â Â Â } catch (e) {} |
159 | Â Â } |
160 | |
161 | Â Â return returnValue; |
162 | Â } |
163 | } |
164 | |
165 | /*--------------------------------------------------------------------------*/ |
166 | |
167 | var PeriodicalExecuter = Class.create(); |
168 | PeriodicalExecuter.prototype = { |
169 | Â initialize: function(callback, frequency) { |
170 | Â Â this.callback = callback; |
171 | Â Â this.frequency = frequency; |
172 | Â Â this.currentlyExecuting = false; |
173 | |
174 | Â Â this.registerCallback(); |
175 | Â }, |
176 | |
177 | Â registerCallback: function() { |
178 | Â Â this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); |
179 | Â }, |
180 | |
181 | Â stop: function() { |
182 | Â Â if (!this.timer) return; |
183 | Â Â clearInterval(this.timer); |
184 | Â Â this.timer = null; |
185 | Â }, |
186 | |
187 | Â onTimerEvent: function() { |
188 | Â Â if (!this.currentlyExecuting) { |
189 | Â Â Â try { |
190 | Â Â Â Â this.currentlyExecuting = true; |
191 | Â Â Â Â this.callback(this); |
192 | Â Â Â } finally { |
193 | Â Â Â Â this.currentlyExecuting = false; |
194 | Â Â Â } |
195 | Â Â } |
196 | Â } |
197 | } |
198 | Object.extend(String, { |
199 | Â interpret: function(value) { |
200 | Â Â return value == null ? '' : String(value); |
201 | Â }, |
202 | Â specialChar: { |
203 | Â Â '\b': '\\b', |
204 | Â Â '\t': '\\t', |
205 | Â Â '\n': '\\n', |
206 | Â Â '\f': '\\f', |
207 | Â Â '\r': '\\r', |
208 | Â Â '\\': '\\\\' |
209 | Â } |
210 | }); |
211 | |
212 | Object.extend(String.prototype, { |
213 | Â gsub: function(pattern, replacement) { |
214 | Â Â var result = '', source = this, match; |
215 | Â Â replacement = arguments.callee.prepareReplacement(replacement); |
216 | |
217 | Â Â while (source.length > 0) { |
218 | Â Â Â if (match = source.match(pattern)) { |
219 | Â Â Â Â result += source.slice(0, match.index); |
220 | Â Â Â Â result += String.interpret(replacement(match)); |
221 |     source = source.slice(match.index + match[0].length); |
222 | Â Â Â } else { |
223 | Â Â Â Â result += source, source = ''; |
224 | Â Â Â } |
225 | Â Â } |
226 | Â Â return result; |
227 | Â }, |
228 | |
229 | Â sub: function(pattern, replacement, count) { |
230 | Â Â replacement = this.gsub.prepareReplacement(replacement); |
231 | Â Â count = count === undefined ? 1 : count; |
232 | |
233 | Â Â return this.gsub(pattern, function(match) { |
234 | Â Â Â if (--count < 0) return match[0]; |
235 | Â Â Â return replacement(match); |
236 | Â Â }); |
237 | Â }, |
238 | |
239 | Â scan: function(pattern, iterator) { |
240 | Â Â this.gsub(pattern, iterator); |
241 | Â Â return this; |
242 | Â }, |
243 | |
244 | Â truncate: function(length, truncation) { |
245 | Â Â length = length || 30; |
246 | Â Â truncation = truncation === undefined ? '...' : truncation; |
247 | Â Â return this.length > length ? |
248 | Â Â Â this.slice(0, length - truncation.length) + truncation : this; |
249 | Â }, |
250 | |
251 | Â strip: function() { |
252 | Â Â return this.replace(/^\s+/, '').replace(/\s+$/, ''); |
253 | Â }, |
254 | |
255 | Â stripTags: function() { |
256 | Â Â return this.replace(/<\/?[^>]+>/gi, ''); |
257 | Â }, |
258 | |
259 | Â stripScripts: function() { |
260 | Â Â return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), ''); |
261 | Â }, |
262 | |
263 | Â extractScripts: function() { |
264 | Â Â var matchAll = new RegExp(Prototype.ScriptFragment, 'img'); |
265 | Â Â var matchOne = new RegExp(Prototype.ScriptFragment, 'im'); |
266 | Â Â return (this.match(matchAll) || []).map(function(scriptTag) { |
267 | Â Â Â return (scriptTag.match(matchOne) || ['', ''])[1]; |
268 | Â Â }); |
269 | Â }, |
270 | |
271 | Â evalScripts: function() { |
272 | Â Â return this.extractScripts().map(function(script) { return eval(script) }); |
273 | Â }, |
274 | |
275 | Â escapeHTML: function() { |
276 | Â Â var self = arguments.callee; |
277 | Â Â self.text.data = this; |
278 | Â Â return self.div.innerHTML; |
279 | Â }, |
280 | |
281 | Â unescapeHTML: function() { |
282 | Â Â var div = document.createElement('div'); |
283 | Â Â div.innerHTML = this.stripTags(); |
284 | Â Â return div.childNodes[0] ? (div.childNodes.length > 1 ? |
285 | Â Â Â $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) : |
286 | Â Â Â div.childNodes[0].nodeValue) : ''; |
287 | Â }, |
288 | |
289 | Â toQueryParams: function(separator) { |
290 | Â Â var match = this.strip().match(/([^?#]*)(#.*)?$/); |
291 | Â Â if (!match) return {}; |
292 | |
293 | Â Â return match[1].split(separator || '&').inject({}, function(hash, pair) { |
294 | Â Â Â if ((pair = pair.split('='))[0]) { |
295 | Â Â Â Â var key = decodeURIComponent(pair.shift()); |
296 | Â Â Â Â var value = pair.length > 1 ? pair.join('=') : pair[0]; |
297 | Â Â Â Â if (value != undefined) value = decodeURIComponent(value); |
298 | |
299 | Â Â Â Â if (key in hash) { |
300 | Â Â Â Â Â if (hash[key].constructor != Array) hash[key] = [hash[key]]; |
301 | Â Â Â Â Â hash[key].push(value); |
302 | Â Â Â Â } |
303 | Â Â Â Â else hash[key] = value; |
304 | Â Â Â } |
305 | Â Â Â return hash; |
306 | Â Â }); |
307 | Â }, |
308 | |
309 | Â toArray: function() { |
310 | Â Â return this.split(''); |
311 | Â }, |
312 | |
313 | Â succ: function() { |
314 | Â Â return this.slice(0, this.length - 1) + |
315 | Â Â Â String.fromCharCode(this.charCodeAt(this.length - 1) + 1); |
316 | Â }, |
317 | |
318 | Â times: function(count) { |
319 | Â Â var result = ''; |
320 | Â Â for (var i = 0; i < count; i++) result += this; |
321 | Â Â return result; |
322 | Â }, |
323 | |
324 | Â camelize: function() { |
325 | Â Â var parts = this.split('-'), len = parts.length; |
326 | Â Â if (len == 1) return parts[0]; |
327 | |
328 | Â Â var camelized = this.charAt(0) == '-' |
329 | Â Â Â ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1) |
330 | Â Â Â : parts[0]; |
331 | |
332 | Â Â for (var i = 1; i < len; i++) |
333 | Â Â Â camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1); |
334 | |
335 | Â Â return camelized; |
336 | Â }, |
337 | |
338 | Â capitalize: function() { |
339 | Â Â return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase(); |
340 | Â }, |
341 | |
342 | Â underscore: function() { |
343 | Â Â return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase(); |
344 | Â }, |
345 | |
346 | Â dasherize: function() { |
347 | Â Â return this.gsub(/_/,'-'); |
348 | Â }, |
349 | |
350 | Â inspect: function(useDoubleQuotes) { |
351 | Â Â var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) { |
352 | Â Â Â var character = String.specialChar[match[0]]; |
353 | Â Â Â return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16); |
354 | Â Â }); |
355 | Â Â if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"'; |
356 | Â Â return "'" + escapedString.replace(/'/g, '\\\'') + "'"; |
357 | Â }, |
358 | |
359 | Â toJSON: function() { |
360 | Â Â return this.inspect(true); |
361 | Â }, |
362 | |
363 | Â unfilterJSON: function(filter) { |
364 | Â Â return this.sub(filter || Prototype.JSONFilter, '#{1}'); |
365 | Â }, |
366 | |
367 | Â evalJSON: function(sanitize) { |
368 | Â Â var json = this.unfilterJSON(); |
369 | Â Â try { |
370 | Â Â Â if (!sanitize || (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(json))) |
371 | Â Â Â Â return eval('(' + json + ')'); |
372 | Â Â } catch (e) { } |
373 | Â Â throw new SyntaxError('Badly formed JSON string: ' + this.inspect()); |
374 | Â }, |
375 | |
376 | Â include: function(pattern) { |
377 | Â Â return this.indexOf(pattern) > -1; |
378 | Â }, |
379 | |
380 | Â startsWith: function(pattern) { |
381 | Â Â return this.indexOf(pattern) === 0; |
382 | Â }, |
383 | |
384 | Â endsWith: function(pattern) { |
385 | Â Â var d = this.length - pattern.length; |
386 | Â Â return d >= 0 && this.lastIndexOf(pattern) === d; |
387 | Â }, |
388 | |
389 | Â empty: function() { |
390 | Â Â return this == ''; |
391 | Â }, |
392 | |
393 | Â blank: function() { |
394 | Â Â return /^\s*$/.test(this); |
395 | Â } |
396 | }); |
397 | |
398 | if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, { |
399 | Â escapeHTML: function() { |
400 | Â Â return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); |
401 | Â }, |
402 | Â unescapeHTML: function() { |
403 | Â Â return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); |
404 | Â } |
405 | }); |
406 | |
407 | String.prototype.gsub.prepareReplacement = function(replacement) { |
408 | Â if (typeof replacement == 'function') return replacement; |
409 | Â var template = new Template(replacement); |
410 | Â return function(match) { return template.evaluate(match) }; |
411 | } |
412 | |
413 | String.prototype.parseQuery = String.prototype.toQueryParams; |
414 | |
415 | Object.extend(String.prototype.escapeHTML, { |
416 | Â div:Â document.createElement('div'), |
417 | Â text: document.createTextNode('') |
418 | }); |
419 | |
420 | with (String.prototype.escapeHTML) div.appendChild(text); |
421 | |
422 | var Template = Class.create(); |
423 | Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; |
424 | Template.prototype = { |
425 | Â initialize: function(template, pattern) { |
426 | Â Â this.template = template.toString(); |
427 |   this.pattern = pattern || Template.Pattern; |
428 | Â }, |
429 | |
430 | Â evaluate: function(object) { |
431 | Â Â return this.template.gsub(this.pattern, function(match) { |
432 | Â Â Â var before = match[1]; |
433 | Â Â Â if (before == '\\') return match[2]; |
434 | Â Â Â return before + String.interpret(object[match[3]]); |
435 | Â Â }); |
436 | Â } |
437 | } |
438 | |
439 | var $break = {}, $continue = new Error('"throw $continue" is deprecated, use "return" instead'); |
440 | |
441 | var Enumerable = { |
442 | Â each: function(iterator) { |
443 | Â Â var index = 0; |
444 | Â Â try { |
445 | Â Â Â this._each(function(value) { |
446 | Â Â Â Â iterator(value, index++); |
447 | Â Â Â }); |
448 | Â Â } catch (e) { |
449 | Â Â Â if (e != $break) throw e; |
450 | Â Â } |
451 | Â Â return this; |
452 | Â }, |
453 | |
454 | Â eachSlice: function(number, iterator) { |
455 | Â Â var index = -number, slices = [], array = this.toArray(); |
456 | Â Â while ((index += number) < array.length) |
457 | Â Â Â slices.push(array.slice(index, index+number)); |
458 | Â Â return slices.map(iterator); |
459 | Â }, |
460 | |
461 | Â all: function(iterator) { |
462 | Â Â var result = true; |
463 | Â Â this.each(function(value, index) { |
464 | Â Â Â result = result && !!(iterator || Prototype.K)(value, index); |
465 | Â Â Â if (!result) throw $break; |
466 | Â Â }); |
467 | Â Â return result; |
468 | Â }, |
469 | |
470 | Â any: function(iterator) { |
471 | Â Â var result = false; |
472 | Â Â this.each(function(value, index) { |
473 | Â Â Â if (result = !!(iterator || Prototype.K)(value, index)) |
474 | Â Â Â Â throw $break; |
475 | Â Â }); |
476 | Â Â return result; |
477 | Â }, |
478 | |
479 | Â collect: function(iterator) { |
480 | Â Â var results = []; |
481 | Â Â this.each(function(value, index) { |
482 | Â Â Â results.push((iterator || Prototype.K)(value, index)); |
483 | Â Â }); |
484 | Â Â return results; |
485 | Â }, |
486 | |
487 | Â detect: function(iterator) { |
488 | Â Â var result; |
489 | Â Â this.each(function(value, index) { |
490 | Â Â Â if (iterator(value, index)) { |
491 | Â Â Â Â result = value; |
492 | Â Â Â Â throw $break; |
493 | Â Â Â } |
494 | Â Â }); |
495 | Â Â return result; |
496 | Â }, |
497 | |
498 | Â findAll: function(iterator) { |
499 | Â Â var results = []; |
500 | Â Â this.each(function(value, index) { |
501 | Â Â Â if (iterator(value, index)) |
502 | Â Â Â Â results.push(value); |
503 | Â Â }); |
504 | Â Â return results; |
505 | Â }, |
506 | |
507 | Â grep: function(pattern, iterator) { |
508 | Â Â var results = []; |
509 | Â Â this.each(function(value, index) { |
510 | Â Â Â var stringValue = value.toString(); |
511 | Â Â Â if (stringValue.match(pattern)) |
512 | Â Â Â Â results.push((iterator || Prototype.K)(value, index)); |
513 | Â Â }) |
514 | Â Â return results; |
515 | Â }, |
516 | |
517 | Â include: function(object) { |
518 | Â Â var found = false; |
519 | Â Â this.each(function(value) { |
520 | Â Â Â if (value == object) { |
521 | Â Â Â Â found = true; |
522 | Â Â Â Â throw $break; |
523 | Â Â Â } |
524 | Â Â }); |
525 | Â Â return found; |
526 | Â }, |
527 | |
528 | Â inGroupsOf: function(number, fillWith) { |
529 | Â Â fillWith = fillWith === undefined ? null : fillWith; |
530 | Â Â return this.eachSlice(number, function(slice) { |
531 | Â Â Â while(slice.length < number) slice.push(fillWith); |
532 | Â Â Â return slice; |
533 | Â Â }); |
534 | Â }, |
535 | |
536 | Â inject: function(memo, iterator) { |
537 | Â Â this.each(function(value, index) { |
538 | Â Â Â memo = iterator(memo, value, index); |
539 | Â Â }); |
540 | Â Â return memo; |
541 | Â }, |
542 | |
543 | Â invoke: function(method) { |
544 | Â Â var args = $A(arguments).slice(1); |
545 | Â Â return this.map(function(value) { |
546 | Â Â Â return value[method].apply(value, args); |
547 | Â Â }); |
548 | Â }, |
549 | |
550 | Â max: function(iterator) { |
551 | Â Â var result; |
552 | Â Â this.each(function(value, index) { |
553 | Â Â Â value = (iterator || Prototype.K)(value, index); |
554 | Â Â Â if (result == undefined || value >= result) |
555 | Â Â Â Â result = value; |
556 | Â Â }); |
557 | Â Â return result; |
558 | Â }, |
559 | |
560 | Â min: function(iterator) { |
561 | Â Â var result; |
562 | Â Â this.each(function(value, index) { |
563 | Â Â Â value = (iterator || Prototype.K)(value, index); |
564 | Â Â Â if (result == undefined || value < result) |
565 | Â Â Â Â result = value; |
566 | Â Â }); |
567 | Â Â return result; |
568 | Â }, |
569 | |
570 | Â partition: function(iterator) { |
571 | Â Â var trues = [], falses = []; |
572 | Â Â this.each(function(value, index) { |
573 | Â Â Â ((iterator || Prototype.K)(value, index) ? |
574 | Â Â Â Â trues : falses).push(value); |
575 | Â Â }); |
576 | Â Â return [trues, falses]; |
577 | Â }, |
578 | |
579 | Â pluck: function(property) { |
580 | Â Â var results = []; |
581 | Â Â this.each(function(value, index) { |
582 | Â Â Â results.push(value[property]); |
583 | Â Â }); |
584 | Â Â return results; |
585 | Â }, |
586 | |
587 | Â reject: function(iterator) { |
588 | Â Â var results = []; |
589 | Â Â this.each(function(value, index) { |
590 | Â Â Â if (!iterator(value, index)) |
591 | Â Â Â Â results.push(value); |
592 | Â Â }); |
593 | Â Â return results; |
594 | Â }, |
595 | |
596 | Â sortBy: function(iterator) { |
597 | Â Â return this.map(function(value, index) { |
598 | Â Â Â return {value: value, criteria: iterator(value, index)}; |
599 | Â Â }).sort(function(left, right) { |
600 | Â Â Â var a = left.criteria, b = right.criteria; |
601 | Â Â Â return a < b ? -1 : a > b ? 1 : 0; |
602 | Â Â }).pluck('value'); |
603 | Â }, |
604 | |
605 | Â toArray: function() { |
606 | Â Â return this.map(); |
607 | Â }, |
608 | |
609 | Â zip: function() { |
610 | Â Â var iterator = Prototype.K, args = $A(arguments); |
611 | Â Â if (typeof args.last() == 'function') |
612 | Â Â Â iterator = args.pop(); |
613 | |
614 | Â Â var collections = [this].concat(args).map($A); |
615 | Â Â return this.map(function(value, index) { |
616 | Â Â Â return iterator(collections.pluck(index)); |
617 | Â Â }); |
618 | Â }, |
619 | |
620 | Â size: function() { |
621 | Â Â return this.toArray().length; |
622 | Â }, |
623 | |
624 | Â inspect: function() { |
625 | Â Â return '#<Enumerable:' + this.toArray().inspect() + '>'; |
626 | Â } |
627 | } |
628 | |
629 | Object.extend(Enumerable, { |
630 | Â map:Â Â Â Enumerable.collect, |
631 | Â find:Â Â Enumerable.detect, |
632 | Â select:Â Enumerable.findAll, |
633 | Â member:Â Enumerable.include, |
634 | Â entries: Enumerable.toArray |
635 | }); |
636 | var $A = Array.from = function(iterable) { |
637 | Â if (!iterable) return []; |
638 | Â if (iterable.toArray) { |
639 | Â Â return iterable.toArray(); |
640 | Â } else { |
641 | Â Â var results = []; |
642 | Â Â for (var i = 0, length = iterable.length; i < length; i++) |
643 | Â Â Â results.push(iterable[i]); |
644 | Â Â return results; |
645 | Â } |
646 | } |
647 | |
648 | if (Prototype.Browser.WebKit) { |
649 | Â $A = Array.from = function(iterable) { |
650 | Â Â if (!iterable) return []; |
651 | Â Â if (!(typeof iterable == 'function' && iterable == '[object NodeList]') && |
652 | Â Â Â iterable.toArray) { |
653 | Â Â Â return iterable.toArray(); |
654 | Â Â } else { |
655 | Â Â Â var results = []; |
656 | Â Â Â for (var i = 0, length = iterable.length; i < length; i++) |
657 | Â Â Â Â results.push(iterable[i]); |
658 | Â Â Â return results; |
659 | Â Â } |
660 | Â } |
661 | } |
662 | |
663 | Object.extend(Array.prototype, Enumerable); |
664 | |
665 | if (!Array.prototype._reverse) |
666 | Â Array.prototype._reverse = Array.prototype.reverse; |
667 | |
668 | Object.extend(Array.prototype, { |
669 | Â _each: function(iterator) { |
670 | Â Â for (var i = 0, length = this.length; i < length; i++) |
671 | Â Â Â iterator(this[i]); |
672 | Â }, |
673 | |
674 | Â clear: function() { |
675 | Â Â this.length = 0; |
676 | Â Â return this; |
677 | Â }, |
678 | |
679 | Â first: function() { |
680 | Â Â return this[0]; |
681 | Â }, |
682 | |
683 | Â last: function() { |
684 | Â Â return this[this.length - 1]; |
685 | Â }, |
686 | |
687 | Â compact: function() { |
688 | Â Â return this.select(function(value) { |
689 | Â Â Â return value != null; |
690 | Â Â }); |
691 | Â }, |
692 | |
693 | Â flatten: function() { |
694 | Â Â return this.inject([], function(array, value) { |
695 | Â Â Â return array.concat(value && value.constructor == Array ? |
696 | Â Â Â Â value.flatten() : [value]); |
697 | Â Â }); |
698 | Â }, |
699 | |
700 | Â without: function() { |
701 | Â Â var values = $A(arguments); |
702 | Â Â return this.select(function(value) { |
703 | Â Â Â return !values.include(value); |
704 | Â Â }); |
705 | Â }, |
706 | |
707 | Â indexOf: function(object) { |
708 | Â Â for (var i = 0, length = this.length; i < length; i++) |
709 | Â Â Â if (this[i] == object) return i; |
710 | Â Â return -1; |
711 | Â }, |
712 | |
713 | Â reverse: function(inline) { |
714 | Â Â return (inline !== false ? this : this.toArray())._reverse(); |
715 | Â }, |
716 | |
717 | Â reduce: function() { |
718 | Â Â return this.length > 1 ? this : this[0]; |
719 | Â }, |
720 | |
721 | Â uniq: function(sorted) { |
722 | Â Â return this.inject([], function(array, value, index) { |
723 | Â Â Â if (0 == index || (sorted ? array.last() != value : !array.include(value))) |
724 | Â Â Â Â array.push(value); |
725 | Â Â Â return array; |
726 | Â Â }); |
727 | Â }, |
728 | |
729 | Â clone: function() { |
730 | Â Â return [].concat(this); |
731 | Â }, |
732 | |
733 | Â size: function() { |
734 | Â Â return this.length; |
735 | Â }, |
736 | |
737 | Â inspect: function() { |
738 | Â Â return '[' + this.map(Object.inspect).join(', ') + ']'; |
739 | Â }, |
740 | |
741 | Â toJSON: function() { |
742 | Â Â var results = []; |
743 | Â Â this.each(function(object) { |
744 | Â Â Â var value = Object.toJSON(object); |
745 | Â Â Â if (value !== undefined) results.push(value); |
746 | Â Â }); |
747 | Â Â return '[' + results.join(', ') + ']'; |
748 | Â } |
749 | }); |
750 | |
751 | Array.prototype.toArray = Array.prototype.clone; |
752 | |
753 | function $w(string) { |
754 | Â string = string.strip(); |
755 | Â return string ? string.split(/\s+/) : []; |
756 | } |
757 | |
758 | if (Prototype.Browser.Opera){ |
759 | Â Array.prototype.concat = function() { |
760 | Â Â var array = []; |
761 | Â Â for (var i = 0, length = this.length; i < length; i++) array.push(this[i]); |
762 | Â Â for (var i = 0, length = arguments.length; i < length; i++) { |
763 | Â Â Â if (arguments[i].constructor == Array) { |
764 | Â Â Â Â for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++) |
765 | Â Â Â Â Â array.push(arguments[i][j]); |
766 | Â Â Â } else { |
767 | Â Â Â Â array.push(arguments[i]); |
768 | Â Â Â } |
769 | Â Â } |
770 | Â Â return array; |
771 | Â } |
772 | } |
773 | var Hash = function(object) { |
774 | Â if (object instanceof Hash) this.merge(object); |
775 | Â else Object.extend(this, object || {}); |
776 | }; |
777 | |
778 | Object.extend(Hash, { |
779 | Â toQueryString: function(obj) { |
780 | Â Â var parts = []; |
781 | Â Â parts.add = arguments.callee.addPair; |
782 | |
783 | Â Â this.prototype._each.call(obj, function(pair) { |
784 | Â Â Â if (!pair.key) return; |
785 | Â Â Â var value = pair.value; |
786 | |
787 | Â Â Â if (value && typeof value == 'object') { |
788 | Â Â Â Â if (value.constructor == Array) value.each(function(value) { |
789 | Â Â Â Â Â parts.add(pair.key, value); |
790 | Â Â Â Â }); |
791 | Â Â Â Â return; |
792 | Â Â Â } |
793 | Â Â Â parts.add(pair.key, value); |
794 | Â Â }); |
795 | |
796 | Â Â return parts.join('&'); |
797 | Â }, |
798 | |
799 | Â toJSON: function(object) { |
800 | Â Â var results = []; |
801 | Â Â this.prototype._each.call(object, function(pair) { |
802 | Â Â Â var value = Object.toJSON(pair.value); |
803 | Â Â Â if (value !== undefined) results.push(pair.key.toJSON() + ': ' + value); |
804 | Â Â }); |
805 | Â Â return '{' + results.join(', ') + '}'; |
806 | Â } |
807 | }); |
808 | |
809 | Hash.toQueryString.addPair = function(key, value, prefix) { |
810 | Â key = encodeURIComponent(key); |
811 | Â if (value === undefined) this.push(key); |
812 | Â else this.push(key + '=' + (value == null ? '' : encodeURIComponent(value))); |
813 | } |
814 | |
815 | Object.extend(Hash.prototype, Enumerable); |
816 | Object.extend(Hash.prototype, { |
817 | Â _each: function(iterator) { |
818 | Â Â for (var key in this) { |
819 | Â Â Â var value = this[key]; |
820 | Â Â Â if (value && value == Hash.prototype[key]) continue; |
821 | |
822 | Â Â Â var pair = [key, value]; |
823 | Â Â Â pair.key = key; |
824 | Â Â Â pair.value = value; |
825 | Â Â Â iterator(pair); |
826 | Â Â } |
827 | Â }, |
828 | |
829 | Â keys: function() { |
830 | Â Â return this.pluck('key'); |
831 | Â }, |
832 | |
833 | Â values: function() { |
834 | Â Â return this.pluck('value'); |
835 | Â }, |
836 | |
837 | Â merge: function(hash) { |
838 | Â Â return $H(hash).inject(this, function(mergedHash, pair) { |
839 | Â Â Â mergedHash[pair.key] = pair.value; |
840 | Â Â Â return mergedHash; |
841 | Â Â }); |
842 | Â }, |
843 | |
844 | Â remove: function() { |
845 | Â Â var result; |
846 | Â Â for(var i = 0, length = arguments.length; i < length; i++) { |
847 | Â Â Â var value = this[arguments[i]]; |
848 | Â Â Â if (value !== undefined){ |
849 | Â Â Â Â if (result === undefined) result = value; |
850 | Â Â Â Â else { |
851 | Â Â Â Â Â if (result.constructor != Array) result = [result]; |
852 | Â Â Â Â Â result.push(value) |
853 | Â Â Â Â } |
854 | Â Â Â } |
855 | Â Â Â delete this[arguments[i]]; |
856 | Â Â } |
857 | Â Â return result; |
858 | Â }, |
859 | |
860 | Â toQueryString: function() { |
861 | Â Â return Hash.toQueryString(this); |
862 | Â }, |
863 | |
864 | Â inspect: function() { |
865 | Â Â return '#<Hash:{' + this.map(function(pair) { |
866 | Â Â Â return pair.map(Object.inspect).join(': '); |
867 | Â Â }).join(', ') + '}>'; |
868 | Â }, |
869 | |
870 | Â toJSON: function() { |
871 | Â Â return Hash.toJSON(this); |
872 | Â } |
873 | }); |
874 | |
875 | function $H(object) { |
876 | Â if (object instanceof Hash) return object; |
877 | Â return new Hash(object); |
878 | }; |
879 | |
880 | // Safari iterates over shadowed properties |
881 | if (function() { |
882 | Â var i = 0, Test = function(value) { this.key = value }; |
883 | Â Test.prototype.key = 'foo'; |
884 | Â for (var property in new Test('bar')) i++; |
885 | Â return i > 1; |
886 | }()) Hash.prototype._each = function(iterator) { |
887 | Â var cache = []; |
888 | Â for (var key in this) { |
889 | Â Â var value = this[key]; |
890 | Â Â if ((value && value == Hash.prototype[key]) || cache.include(key)) continue; |
891 | Â Â cache.push(key); |
892 | Â Â var pair = [key, value]; |
893 | Â Â pair.key = key; |
894 | Â Â pair.value = value; |
895 | Â Â iterator(pair); |
896 | Â } |
897 | }; |
898 | ObjectRange = Class.create(); |
899 | Object.extend(ObjectRange.prototype, Enumerable); |
900 | Object.extend(ObjectRange.prototype, { |
901 | Â initialize: function(start, end, exclusive) { |
902 | Â Â this.start = start; |
903 | Â Â this.end = end; |
904 | Â Â this.exclusive = exclusive; |
905 | Â }, |
906 | |
907 | Â _each: function(iterator) { |
908 | Â Â var value = this.start; |
909 | Â Â while (this.include(value)) { |
910 | Â Â Â iterator(value); |
911 | Â Â Â value = value.succ(); |
912 | Â Â } |
913 | Â }, |
914 | |
915 | Â include: function(value) { |
916 | Â Â if (value < this.start) |
917 | Â Â Â return false; |
918 | Â Â if (this.exclusive) |
919 | Â Â Â return value < this.end; |
920 | Â Â return value <= this.end; |
921 | Â } |
922 | }); |
923 | |
924 | var $R = function(start, end, exclusive) { |
925 | Â return new ObjectRange(start, end, exclusive); |
926 | } |
927 | |
928 | var Ajax = { |
929 | Â getTransport: function() { |
930 | Â Â return Try.these( |
931 | Â Â Â function() {return new XMLHttpRequest()}, |
932 | Â Â Â function() {return new ActiveXObject('Msxml2.XMLHTTP')}, |
933 | Â Â Â function() {return new ActiveXObject('Microsoft.XMLHTTP')} |
934 | Â Â ) || false; |
935 | Â }, |
936 | |
937 | Â activeRequestCount: 0 |
938 | } |
939 | |
940 | Ajax.Responders = { |
941 | Â responders: [], |
942 | |
943 | Â _each: function(iterator) { |
944 | Â Â this.responders._each(iterator); |
945 | Â }, |
946 | |
947 | Â register: function(responder) { |
948 | Â Â if (!this.include(responder)) |
949 | Â Â Â this.responders.push(responder); |
950 | Â }, |
951 | |
952 | Â unregister: function(responder) { |
953 | Â Â this.responders = this.responders.without(responder); |
954 | Â }, |
955 | |
956 | Â dispatch: function(callback, request, transport, json) { |
957 | Â Â this.each(function(responder) { |
958 | Â Â Â if (typeof responder[callback] == 'function') { |
959 | Â Â Â Â try { |
960 | Â Â Â Â Â responder[callback].apply(responder, [request, transport, json]); |
961 | Â Â Â Â } catch (e) {} |
962 | Â Â Â } |
963 | Â Â }); |
964 | Â } |
965 | }; |
966 | |
967 | Object.extend(Ajax.Responders, Enumerable); |
968 | |
969 | Ajax.Responders.register({ |
970 | Â onCreate: function() { |
971 | Â Â Ajax.activeRequestCount++; |
972 | Â }, |
973 | Â onComplete: function() { |
974 | Â Â Ajax.activeRequestCount--; |
975 | Â } |
976 | }); |
977 | |
978 | Ajax.Base = function() {}; |
979 | Ajax.Base.prototype = { |
980 | Â setOptions: function(options) { |
981 | Â Â this.options = { |
982 | Â Â Â method:Â Â Â Â 'post', |
983 | Â Â Â asynchronous: true, |
984 | Â Â Â contentType:Â 'application/x-www-form-urlencoded', |
985 | Â Â Â encoding:Â Â Â 'UTF-8', |
986 | Â Â Â parameters:Â Â '' |
987 | Â Â } |
988 | Â Â Object.extend(this.options, options || {}); |
989 | |
990 | Â Â this.options.method = this.options.method.toLowerCase(); |
991 | Â Â if (typeof this.options.parameters == 'string') |
992 | Â Â Â this.options.parameters = this.options.parameters.toQueryParams(); |
993 | Â } |
994 | } |
995 | |
996 | Ajax.Request = Class.create(); |
997 | Ajax.Request.Events = |
998 | Â ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; |
999 | |
1000 | Ajax.Request.prototype = Object.extend(new Ajax.Base(), { |
1001 | Â _complete: false, |
1002 | |
1003 | Â initialize: function(url, options) { |
1004 | Â Â this.transport = Ajax.getTransport(); |
1005 | Â Â this.setOptions(options); |
1006 | Â Â this.request(url); |
1007 | Â }, |
1008 | |
1009 | Â request: function(url) { |
1010 | Â Â this.url = url; |
1011 | Â Â this.method = this.options.method; |
1012 | Â Â var params = Object.clone(this.options.parameters); |
1013 | |
1014 | Â Â if (!['get', 'post'].include(this.method)) { |
1015 | Â Â Â // simulate other verbs over post |
1016 | Â Â Â params['_method'] = this.method; |
1017 | Â Â Â this.method = 'post'; |
1018 | Â Â } |
1019 | |
1020 | Â Â this.parameters = params; |
1021 | |
1022 | Â Â if (params = Hash.toQueryString(params)) { |
1023 | Â Â Â // when GET, append parameters to URL |
1024 | Â Â Â if (this.method == 'get') |
1025 | Â Â Â Â this.url += (this.url.include('?') ? '&' : '?') + params; |
1026 | Â Â Â else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) |
1027 | Â Â Â Â params += '&_='; |
1028 | Â Â } |
1029 | |
1030 | Â Â try { |
1031 | Â Â Â if (this.options.onCreate) this.options.onCreate(this.transport); |
1032 | Â Â Â Ajax.Responders.dispatch('onCreate', this, this.transport); |
1033 | |
1034 | Â Â Â this.transport.open(this.method.toUpperCase(), this.url, |
1035 | Â Â Â Â this.options.asynchronous); |
1036 | |
1037 | Â Â Â if (this.options.asynchronous) |
1038 | Â Â Â Â setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10); |
1039 | |
1040 | Â Â Â this.transport.onreadystatechange = this.onStateChange.bind(this); |
1041 | Â Â Â this.setRequestHeaders(); |
1042 | |
1043 | Â Â Â this.body = this.method == 'post' ? (this.options.postBody || params) : null; |
1044 | Â Â Â this.transport.send(this.body); |
1045 | |
1046 | Â Â Â /* Force Firefox to handle ready state 4 for synchronous requests */ |
1047 | Â Â Â if (!this.options.asynchronous && this.transport.overrideMimeType) |
1048 | Â Â Â Â this.onStateChange(); |
1049 | |
1050 | Â Â } |
1051 | Â Â catch (e) { |
1052 | Â Â Â this.dispatchException(e); |
1053 | Â Â } |
1054 | Â }, |
1055 | |
1056 | Â onStateChange: function() { |
1057 | Â Â var readyState = this.transport.readyState; |
1058 | Â Â if (readyState > 1 && !((readyState == 4) && this._complete)) |
1059 | Â Â Â this.respondToReadyState(this.transport.readyState); |
1060 | Â }, |
1061 | |
1062 | Â setRequestHeaders: function() { |
1063 | Â Â var headers = { |
1064 | Â Â Â 'X-Requested-With': 'XMLHttpRequest', |
1065 | Â Â Â 'X-Prototype-Version': Prototype.Version, |
1066 | Â Â Â 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*' |
1067 | Â Â }; |
1068 | |
1069 | Â Â if (this.method == 'post') { |
1070 | Â Â Â headers['Content-type'] = this.options.contentType + |
1071 | Â Â Â Â (this.options.encoding ? '; charset=' + this.options.encoding : ''); |
1072 | |
1073 | Â Â Â /* Force "Connection: close" for older Mozilla browsers to work |
1074 | Â Â Â Â * around a bug where XMLHttpRequest sends an incorrect |
1075 | Â Â Â Â * Content-length header. See Mozilla Bugzilla #246651. |
1076 | Â Â Â Â */ |
1077 | Â Â Â if (this.transport.overrideMimeType && |
1078 | Â Â Â Â Â (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) |
1079 | Â Â Â Â Â Â headers['Connection'] = 'close'; |
1080 | Â Â } |
1081 | |
1082 | Â Â // user-defined headers |
1083 | Â Â if (typeof this.options.requestHeaders == 'object') { |
1084 | Â Â Â var extras = this.options.requestHeaders; |
1085 | |
1086 | Â Â Â if (typeof extras.push == 'function') |
1087 | Â Â Â Â for (var i = 0, length = extras.length; i < length; i += 2) |
1088 | Â Â Â Â Â headers[extras[i]] = extras[i+1]; |
1089 | Â Â Â else |
1090 | Â Â Â Â $H(extras).each(function(pair) { headers[pair.key] = pair.value }); |
1091 | Â Â } |
1092 | |
1093 | Â Â for (var name in headers) |
1094 | Â Â Â this.transport.setRequestHeader(name, headers[name]); |
1095 | Â }, |
1096 | |
1097 | Â success: function() { |
1098 | Â Â return !this.transport.status |
1099 | Â Â Â Â || (this.transport.status >= 200 && this.transport.status < 300); |
1100 | Â }, |
1101 | |
1102 | Â respondToReadyState: function(readyState) { |
1103 | Â Â var state = Ajax.Request.Events[readyState]; |
1104 | Â Â var transport = this.transport, json = this.evalJSON(); |
1105 | |
1106 | Â Â if (state == 'Complete') { |
1107 | Â Â Â try { |
1108 | Â Â Â Â this._complete = true; |
1109 | Â Â Â Â (this.options['on' + this.transport.status] |
1110 | Â Â Â Â Â || this.options['on' + (this.success() ? 'Success' : 'Failure')] |
1111 | Â Â Â Â Â || Prototype.emptyFunction)(transport, json); |
1112 | Â Â Â } catch (e) { |
1113 | Â Â Â Â this.dispatchException(e); |
1114 | Â Â Â } |
1115 | |
1116 | Â Â Â var contentType = this.getHeader('Content-type'); |
1117 | Â Â Â if (contentType && contentType.strip(). |
1118 | Â Â Â Â match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i)) |
1119 | Â Â Â Â Â this.evalResponse(); |
1120 | Â Â } |
1121 | |
1122 | Â Â try { |
1123 | Â Â Â (this.options['on' + state] || Prototype.emptyFunction)(transport, json); |
1124 | Â Â Â Ajax.Responders.dispatch('on' + state, this, transport, json); |
1125 | Â Â } catch (e) { |
1126 | Â Â Â this.dispatchException(e); |
1127 | Â Â } |
1128 | |
1129 | Â Â if (state == 'Complete') { |
1130 | Â Â Â // avoid memory leak in MSIE: clean up |
1131 | Â Â Â this.transport.onreadystatechange = Prototype.emptyFunction; |
1132 | Â Â } |
1133 | Â }, |
1134 | |
1135 | Â getHeader: function(name) { |
1136 | Â Â try { |
1137 | Â Â Â return this.transport.getResponseHeader(name); |
1138 | Â Â } catch (e) { return null } |
1139 | Â }, |
1140 | |
1141 | Â evalJSON: function() { |
1142 | Â Â try { |
1143 | Â Â Â var json = this.getHeader('X-JSON'); |
1144 | Â Â Â return json ? json.evalJSON() : null; |
1145 | Â Â } catch (e) { return null } |
1146 | Â }, |
1147 | |
1148 | Â evalResponse: function() { |
1149 | Â Â try { |
1150 | Â Â Â return eval((this.transport.responseText || '').unfilterJSON()); |
1151 | Â Â } catch (e) { |
1152 | Â Â Â this.dispatchException(e); |
1153 | Â Â } |
1154 | Â }, |
1155 | |
1156 | Â dispatchException: function(exception) { |
1157 | Â Â (this.options.onException || Prototype.emptyFunction)(this, exception); |
1158 | Â Â Ajax.Responders.dispatch('onException', this, exception); |
1159 | Â } |
1160 | }); |
1161 | |
1162 | Ajax.Updater = Class.create(); |
1163 | |
1164 | Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), { |
1165 | Â initialize: function(container, url, options) { |
1166 | Â Â this.container = { |
1167 | Â Â Â success: (container.success || container), |
1168 | Â Â Â failure: (container.failure || (container.success ? null : container)) |
1169 | Â Â } |
1170 | |
1171 | Â Â this.transport = Ajax.getTransport(); |
1172 | Â Â this.setOptions(options); |
1173 | |
1174 | Â Â var onComplete = this.options.onComplete || Prototype.emptyFunction; |
1175 | Â Â this.options.onComplete = (function(transport, param) { |
1176 | Â Â Â this.updateContent(); |
1177 | Â Â Â onComplete(transport, param); |
1178 | Â Â }).bind(this); |
1179 | |
1180 | Â Â this.request(url); |
1181 | Â }, |
1182 | |
1183 | Â updateContent: function() { |
1184 | Â Â var receiver = this.container[this.success() ? 'success' : 'failure']; |
1185 | Â Â var response = this.transport.responseText; |
1186 | |
1187 | Â Â if (!this.options.evalScripts) response = response.stripScripts(); |
1188 | |
1189 | Â Â if (receiver = $(receiver)) { |
1190 | Â Â Â if (this.options.insertion) |
1191 | Â Â Â Â new this.options.insertion(receiver, response); |
1192 | Â Â Â else |
1193 | Â Â Â Â receiver.update(response); |
1194 | Â Â } |
1195 | |
1196 | Â Â if (this.success()) { |
1197 | Â Â Â if (this.onComplete) |
1198 | Â Â Â Â setTimeout(this.onComplete.bind(this), 10); |
1199 | Â Â } |
1200 | Â } |
1201 | }); |
1202 | |
1203 | Ajax.PeriodicalUpdater = Class.create(); |
1204 | Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), { |
1205 | Â initialize: function(container, url, options) { |
1206 | Â Â this.setOptions(options); |
1207 | Â Â this.onComplete = this.options.onComplete; |
1208 | |
1209 | Â Â this.frequency = (this.options.frequency || 2); |
1210 | Â Â this.decay = (this.options.decay || 1); |
1211 | |
1212 | Â Â this.updater = {}; |
1213 | Â Â this.container = container; |
1214 | Â Â this.url = url; |
1215 | |
1216 | Â Â this.start(); |
1217 | Â }, |
1218 | |
1219 | Â start: function() { |
1220 | Â Â this.options.onComplete = this.updateComplete.bind(this); |
1221 | Â Â this.onTimerEvent(); |
1222 | Â }, |
1223 | |
1224 | Â stop: function() { |
1225 | Â Â this.updater.options.onComplete = undefined; |
1226 | Â Â clearTimeout(this.timer); |
1227 | Â Â (this.onComplete || Prototype.emptyFunction).apply(this, arguments); |
1228 | Â }, |
1229 | |
1230 | Â updateComplete: function(request) { |
1231 | Â Â if (this.options.decay) { |
1232 | Â Â Â this.decay = (request.responseText == this.lastText ? |
1233 | Â Â Â Â this.decay * this.options.decay : 1); |
1234 | |
1235 | Â Â Â this.lastText = request.responseText; |
1236 | Â Â } |
1237 | Â Â this.timer = setTimeout(this.onTimerEvent.bind(this), |
1238 | Â Â Â this.decay * this.frequency * 1000); |
1239 | Â }, |
1240 | |
1241 | Â onTimerEvent: function() { |
1242 | Â Â this.updater = new Ajax.Updater(this.container, this.url, this.options); |
1243 | Â } |
1244 | }); |
1245 | function $(element) { |
1246 | Â if (arguments.length > 1) { |
1247 | Â Â for (var i = 0, elements = [], length = arguments.length; i < length; i++) |
1248 | Â Â Â elements.push($(arguments[i])); |
1249 | Â Â return elements; |
1250 | Â } |
1251 | Â if (typeof element == 'string') |
1252 | Â Â element = document.getElementById(element); |
1253 | Â return Element.extend(element); |
1254 | } |
1255 | |
1256 | if (Prototype.BrowserFeatures.XPath) { |
1257 | Â document._getElementsByXPath = function(expression, parentElement) { |
1258 | Â Â var results = []; |
1259 | Â Â var query = document.evaluate(expression, $(parentElement) || document, |
1260 | Â Â Â null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); |
1261 | Â Â for (var i = 0, length = query.snapshotLength; i < length; i++) |
1262 | Â Â Â results.push(query.snapshotItem(i)); |
1263 | Â Â return results; |
1264 | Â }; |
1265 | |
1266 | Â document.getElementsByClassName = function(className, parentElement) { |
1267 | Â Â var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]"; |
1268 | Â Â return document._getElementsByXPath(q, parentElement); |
1269 | Â } |
1270 | |
1271 | } else document.getElementsByClassName = function(className, parentElement) { |
1272 | Â var children = ($(parentElement) || document.body).getElementsByTagName('*'); |
1273 | Â var elements = [], child; |
1274 | Â for (var i = 0, length = children.length; i < length; i++) { |
1275 | Â Â child = children[i]; |
1276 | Â Â if (Element.hasClassName(child, className)) |
1277 | Â Â Â elements.push(Element.extend(child)); |
1278 | Â } |
1279 | Â return elements; |
1280 | }; |
1281 | |
1282 | /*--------------------------------------------------------------------------*/ |
1283 | |
1284 | if (!window.Element) var Element = {}; |
1285 | |
1286 | Element.extend = function(element) { |
1287 | Â var F = Prototype.BrowserFeatures; |
1288 | Â if (!element || !element.tagName || element.nodeType == 3 || |
1289 | Â Â element._extended || F.SpecificElementExtensions || element == window) |
1290 | Â Â return element; |
1291 | |
1292 | Â var methods = {}, tagName = element.tagName, cache = Element.extend.cache, |
1293 | Â Â T = Element.Methods.ByTag; |
1294 | |
1295 | Â // extend methods for all tags (Safari doesn't need this) |
1296 | Â if (!F.ElementExtensions) { |
1297 | Â Â Object.extend(methods, Element.Methods), |
1298 | Â Â Object.extend(methods, Element.Methods.Simulated); |
1299 | Â } |
1300 | |
1301 | Â // extend methods for specific tags |
1302 | Â if (T[tagName]) Object.extend(methods, T[tagName]); |
1303 | |
1304 | Â for (var property in methods) { |
1305 | Â Â var value = methods[property]; |
1306 | Â Â if (typeof value == 'function' && !(property in element)) |
1307 | Â Â Â element[property] = cache.findOrStore(value); |
1308 | Â } |
1309 | |
1310 | Â element._extended = Prototype.emptyFunction; |
1311 | Â return element; |
1312 | }; |
1313 | |
1314 | Element.extend.cache = { |
1315 | Â findOrStore: function(value) { |
1316 | Â Â return this[value] = this[value] || function() { |
1317 | Â Â Â return value.apply(null, [this].concat($A(arguments))); |
1318 | Â Â } |
1319 | Â } |
1320 | }; |
1321 | |
1322 | Element.Methods = { |
1323 | Â visible: function(element) { |
1324 | Â Â return $(element).style.display != 'none'; |
1325 | Â }, |
1326 | |
1327 | Â toggle: function(element) { |
1328 | Â Â element = $(element); |
1329 | Â Â Element[Element.visible(element) ? 'hide' : 'show'](element); |
1330 | Â Â return element; |
1331 | Â }, |
1332 | |
1333 | Â hide: function(element) { |
1334 | Â Â $(element).style.display = 'none'; |
1335 | Â Â return element; |
1336 | Â }, |
1337 | |
1338 | Â show: function(element) { |
1339 | Â Â $(element).style.display = ''; |
1340 | Â Â return element; |
1341 | Â }, |
1342 | |
1343 | Â remove: function(element) { |
1344 | Â Â element = $(element); |
1345 | Â Â element.parentNode.removeChild(element); |
1346 | Â Â return element; |
1347 | Â }, |
1348 | |
1349 | Â update: function(element, html) { |
1350 | Â Â html = typeof html == 'undefined' ? '' : html.toString(); |
1351 | Â Â $(element).innerHTML = html.stripScripts(); |
1352 | Â Â setTimeout(function() {html.evalScripts()}, 10); |
1353 | Â Â return element; |
1354 | Â }, |
1355 | |
1356 | Â replace: function(element, html) { |
1357 | Â Â element = $(element); |
1358 | Â Â html = typeof html == 'undefined' ? '' : html.toString(); |
1359 | Â Â if (element.outerHTML) { |
1360 | Â Â Â element.outerHTML = html.stripScripts(); |
1361 | Â Â } else { |
1362 | Â Â Â var range = element.ownerDocument.createRange(); |
1363 | Â Â Â range.selectNodeContents(element); |
1364 | Â Â Â element.parentNode.replaceChild( |
1365 | Â Â Â Â range.createContextualFragment(html.stripScripts()), element); |
1366 | Â Â } |
1367 | Â Â setTimeout(function() {html.evalScripts()}, 10); |
1368 | Â Â return element; |
1369 | Â }, |
1370 | |
1371 | Â inspect: function(element) { |
1372 | Â Â element = $(element); |
1373 | Â Â var result = '<' + element.tagName.toLowerCase(); |
1374 | Â Â $H({'id': 'id', 'className': 'class'}).each(function(pair) { |
1375 | Â Â Â var property = pair.first(), attribute = pair.last(); |
1376 | Â Â Â var value = (element[property] || '').toString(); |
1377 | Â Â Â if (value) result += ' ' + attribute + '=' + value.inspect(true); |
1378 | Â Â }); |
1379 | Â Â return result + '>'; |
1380 | Â }, |
1381 | |
1382 | Â recursivelyCollect: function(element, property) { |
1383 | Â Â element = $(element); |
1384 | Â Â var elements = []; |
1385 | Â Â while (element = element[property]) |
1386 | Â Â Â if (element.nodeType == 1) |
1387 | Â Â Â Â elements.push(Element.extend(element)); |
1388 | Â Â return elements; |
1389 | Â }, |
1390 | |
1391 | Â ancestors: function(element) { |
1392 | Â Â return $(element).recursivelyCollect('parentNode'); |
1393 | Â }, |
1394 | |
1395 | Â descendants: function(element) { |
1396 | Â Â return $A($(element).getElementsByTagName('*')).each(Element.extend); |
1397 | Â }, |
1398 | |
1399 | Â firstDescendant: function(element) { |
1400 | Â Â element = $(element).firstChild; |
1401 | Â Â while (element && element.nodeType != 1) element = element.nextSibling; |
1402 | Â Â return $(element); |
1403 | Â }, |
1404 | |
1405 | Â immediateDescendants: function(element) { |
1406 | Â Â if (!(element = $(element).firstChild)) return []; |
1407 | Â Â while (element && element.nodeType != 1) element = element.nextSibling; |
1408 | Â Â if (element) return [element].concat($(element).nextSiblings()); |
1409 | Â Â return []; |
1410 | Â }, |
1411 | |
1412 | Â previousSiblings: function(element) { |
1413 | Â Â return $(element).recursivelyCollect('previousSibling'); |
1414 | Â }, |
1415 | |
1416 | Â nextSiblings: function(element) { |
1417 | Â Â return $(element).recursivelyCollect('nextSibling'); |
1418 | Â }, |
1419 | |
1420 | Â siblings: function(element) { |
1421 | Â Â element = $(element); |
1422 | Â Â return element.previousSiblings().reverse().concat(element.nextSiblings()); |
1423 | Â }, |
1424 | |
1425 | Â match: function(element, selector) { |
1426 | Â Â if (typeof selector == 'string') |
1427 | Â Â Â selector = new Selector(selector); |
1428 | Â Â return selector.match($(element)); |
1429 | Â }, |
1430 | |
1431 | Â up: function(element, expression, index) { |
1432 | Â Â element = $(element); |
1433 | Â Â if (arguments.length == 1) return $(element.parentNode); |
1434 | Â Â var ancestors = element.ancestors(); |
1435 | Â Â return expression ? Selector.findElement(ancestors, expression, index) : |
1436 | Â Â Â ancestors[index || 0]; |
1437 | Â }, |
1438 | |
1439 | Â down: function(element, expression, index) { |
1440 | Â Â element = $(element); |
1441 | Â Â if (arguments.length == 1) return element.firstDescendant(); |
1442 | Â Â var descendants = element.descendants(); |
1443 | Â Â return expression ? Selector.findElement(descendants, expression, index) : |
1444 | Â Â Â descendants[index || 0]; |
1445 | Â }, |
1446 | |
1447 | Â previous: function(element, expression, index) { |
1448 | Â Â element = $(element); |
1449 | Â Â if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element)); |
1450 | Â Â var previousSiblings = element.previousSiblings(); |
1451 | Â Â return expression ? Selector.findElement(previousSiblings, expression, index) : |
1452 | Â Â Â previousSiblings[index || 0]; |
1453 | Â }, |
1454 | |
1455 | Â next: function(element, expression, index) { |
1456 | Â Â element = $(element); |
1457 | Â Â if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element)); |
1458 | Â Â var nextSiblings = element.nextSiblings(); |
1459 | Â Â return expression ? Selector.findElement(nextSiblings, expression, index) : |
1460 | Â Â Â nextSiblings[index || 0]; |
1461 | Â }, |
1462 | |
1463 | Â getElementsBySelector: function() { |
1464 | Â Â var args = $A(arguments), element = $(args.shift()); |
1465 | Â Â return Selector.findChildElements(element, args); |
1466 | Â }, |
1467 | |
1468 | Â getElementsByClassName: function(element, className) { |
1469 | Â Â return document.getElementsByClassName(className, element); |
1470 | Â }, |
1471 | |
1472 | Â readAttribute: function(element, name) { |
1473 | Â Â element = $(element); |
1474 | Â Â if (Prototype.Browser.IE) { |
1475 | Â Â Â if (!element.attributes) return null; |
1476 | Â Â Â var t = Element._attributeTranslations; |
1477 | Â Â Â if (t.values[name]) return t.values[name](element, name); |
1478 | Â Â Â if (t.names[name])Â name = t.names[name]; |
1479 | Â Â Â var attribute = element.attributes[name]; |
1480 | Â Â Â return attribute ? attribute.nodeValue : null; |
1481 | Â Â } |
1482 | Â Â return element.getAttribute(name); |
1483 | Â }, |
1484 | |
1485 | Â getHeight: function(element) { |
1486 | Â Â return $(element).getDimensions().height; |
1487 | Â }, |
1488 | |
1489 | Â getWidth: function(element) { |
1490 | Â Â return $(element).getDimensions().width; |
1491 | Â }, |
1492 | |
1493 | Â classNames: function(element) { |
1494 | Â Â return new Element.ClassNames(element); |
1495 | Â }, |
1496 | |
1497 | Â hasClassName: function(element, className) { |
1498 | Â Â if (!(element = $(element))) return; |
1499 | Â Â var elementClassName = element.className; |
1500 | Â Â if (elementClassName.length == 0) return false; |
1501 | Â Â if (elementClassName == className || |
1502 | Â Â Â Â elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) |
1503 | Â Â Â return true; |
1504 | Â Â return false; |
1505 | Â }, |
1506 | |
1507 | Â addClassName: function(element, className) { |
1508 | Â Â if (!(element = $(element))) return; |
1509 | Â Â Element.classNames(element).add(className); |
1510 | Â Â return element; |
1511 | Â }, |
1512 | |
1513 | Â removeClassName: function(element, className) { |
1514 | Â Â if (!(element = $(element))) return; |
1515 | Â Â Element.classNames(element).remove(className); |
1516 | Â Â return element; |
1517 | Â }, |
1518 | |
1519 | Â toggleClassName: function(element, className) { |
1520 | Â Â if (!(element = $(element))) return; |
1521 | Â Â Element.classNames(element)[element.hasClassName(className) ? 'remove' : 'add'](className); |
1522 | Â Â return element; |
1523 | Â }, |
1524 | |
1525 | Â observe: function() { |
1526 | Â Â Event.observe.apply(Event, arguments); |
1527 | Â Â return $A(arguments).first(); |
1528 | Â }, |
1529 | |
1530 | Â stopObserving: function() { |
1531 | Â Â Event.stopObserving.apply(Event, arguments); |
1532 | Â Â return $A(arguments).first(); |
1533 | Â }, |
1534 | |
1535 | Â // removes whitespace-only text node children |
1536 | Â cleanWhitespace: function(element) { |
1537 | Â Â element = $(element); |
1538 | Â Â var node = element.firstChild; |
1539 | Â Â while (node) { |
1540 | Â Â Â var nextNode = node.nextSibling; |
1541 | Â Â Â if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) |
1542 | Â Â Â Â element.removeChild(node); |
1543 | Â Â Â node = nextNode; |
1544 | Â Â } |
1545 | Â Â return element; |
1546 | Â }, |
1547 | |
1548 | Â empty: function(element) { |
1549 | Â Â return $(element).innerHTML.blank(); |
1550 | Â }, |
1551 | |
1552 | Â descendantOf: function(element, ancestor) { |
1553 | Â Â element = $(element), ancestor = $(ancestor); |
1554 | Â Â while (element = element.parentNode) |
1555 | Â Â Â if (element == ancestor) return true; |
1556 | Â Â return false; |
1557 | Â }, |
1558 | |
1559 | Â scrollTo: function(element) { |
1560 | Â Â element = $(element); |
1561 | Â Â var pos = Position.cumulativeOffset(element); |
1562 | Â Â window.scrollTo(pos[0], pos[1]); |
1563 | Â Â return element; |
1564 | Â }, |
1565 | |
1566 | Â getStyle: function(element, style) { |
1567 | Â Â element = $(element); |
1568 | Â Â style = style == 'float' ? 'cssFloat' : style.camelize(); |
1569 | Â Â var value = element.style[style]; |
1570 | Â Â if (!value) { |
1571 | Â Â Â var css = document.defaultView.getComputedStyle(element, null); |
1572 | Â Â Â value = css ? css[style] : null; |
1573 | Â Â } |
1574 | Â Â if (style == 'opacity') return value ? parseFloat(value) : 1.0; |
1575 | Â Â return value == 'auto' ? null : value; |
1576 | Â }, |
1577 | |
1578 | Â getOpacity: function(element) { |
1579 | Â Â return $(element).getStyle('opacity'); |
1580 | Â }, |
1581 | |
1582 | Â setStyle: function(element, styles, camelized) { |
1583 | Â Â element = $(element); |
1584 | Â Â var elementStyle = element.style; |
1585 | |
1586 | Â Â for (var property in styles) |
1587 | Â Â Â if (property == 'opacity') element.setOpacity(styles[property]) |
1588 | Â Â Â else |
1589 | Â Â Â Â elementStyle[(property == 'float' || property == 'cssFloat') ? |
1590 | Â Â Â Â Â (elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') : |
1591 | Â Â Â Â Â (camelized ? property : property.camelize())] = styles[property]; |
1592 | |
1593 | Â Â return element; |
1594 | Â }, |
1595 | |
1596 | Â setOpacity: function(element, value) { |
1597 | Â Â element = $(element); |
1598 | Â Â element.style.opacity = (value == 1 || value === '') ? '' : |
1599 | Â Â Â (value < 0.00001) ? 0 : value; |
1600 | Â Â return element; |
1601 | Â }, |
1602 | |
1603 | Â getDimensions: function(element) { |
1604 | Â Â element = $(element); |
1605 | Â Â var display = $(element).getStyle('display'); |
1606 | Â Â if (display != 'none' && display != null) // Safari bug |
1607 | Â Â Â return {width: element.offsetWidth, height: element.offsetHeight}; |
1608 | |
1609 | Â Â // All *Width and *Height properties give 0 on elements with display none, |
1610 | Â Â // so enable the element temporarily |
1611 | Â Â var els = element.style; |
1612 | Â Â var originalVisibility = els.visibility; |
1613 | Â Â var originalPosition = els.position; |
1614 | Â Â var originalDisplay = els.display; |
1615 | Â Â els.visibility = 'hidden'; |
1616 | Â Â els.position = 'absolute'; |
1617 | Â Â els.display = 'block'; |
1618 | Â Â var originalWidth = element.clientWidth; |
1619 | Â Â var originalHeight = element.clientHeight; |
1620 | Â Â els.display = originalDisplay; |
1621 | Â Â els.position = originalPosition; |
1622 | Â Â els.visibility = originalVisibility; |
1623 | Â Â return {width: originalWidth, height: originalHeight}; |
1624 | Â }, |
1625 | |
1626 | Â makePositioned: function(element) { |
1627 | Â Â element = $(element); |
1628 | Â Â var pos = Element.getStyle(element, 'position'); |
1629 | Â Â if (pos == 'static' || !pos) { |
1630 | Â Â Â element._madePositioned = true; |
1631 | Â Â Â element.style.position = 'relative'; |
1632 | Â Â Â // Opera returns the offset relative to the positioning context, when an |
1633 | Â Â Â // element is position relative but top and left have not been defined |
1634 | Â Â Â if (window.opera) { |
1635 | Â Â Â Â element.style.top = 0; |
1636 | Â Â Â Â element.style.left = 0; |
1637 | Â Â Â } |
1638 | Â Â } |
1639 | Â Â return element; |
1640 | Â }, |
1641 | |
1642 | Â undoPositioned: function(element) { |
1643 | Â Â element = $(element); |
1644 | Â Â if (element._madePositioned) { |
1645 | Â Â Â element._madePositioned = undefined; |
1646 | Â Â Â element.style.position = |
1647 | Â Â Â Â element.style.top = |
1648 | Â Â Â Â element.style.left = |
1649 | Â Â Â Â element.style.bottom = |
1650 | Â Â Â Â element.style.right = ''; |
1651 | Â Â } |
1652 | Â Â return element; |
1653 | Â }, |
1654 | |
1655 | Â makeClipping: function(element) { |
1656 | Â Â element = $(element); |
1657 | Â Â if (element._overflow) return element; |
1658 | Â Â element._overflow = element.style.overflow || 'auto'; |
1659 | Â Â if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden') |
1660 | Â Â Â element.style.overflow = 'hidden'; |
1661 | Â Â return element; |
1662 | Â }, |
1663 | |
1664 | Â undoClipping: function(element) { |
1665 | Â Â element = $(element); |
1666 | Â Â if (!element._overflow) return element; |
1667 | Â Â element.style.overflow = element._overflow == 'auto' ? '' : element._overflow; |
1668 | Â Â element._overflow = null; |
1669 | Â Â return element; |
1670 | Â } |
1671 | }; |
1672 | |
1673 | Object.extend(Element.Methods, { |
1674 | Â childOf: Element.Methods.descendantOf, |
1675 | Â childElements: Element.Methods.immediateDescendants |
1676 | }); |
1677 | |
1678 | if (Prototype.Browser.Opera) { |
1679 | Â Element.Methods._getStyle = Element.Methods.getStyle; |
1680 | Â Element.Methods.getStyle = function(element, style) { |
1681 | Â Â switch(style) { |
1682 | Â Â Â case 'left': |
1683 | Â Â Â case 'top': |
1684 | Â Â Â case 'right': |
1685 | Â Â Â case 'bottom': |
1686 | Â Â Â Â if (Element._getStyle(element, 'position') == 'static') return null; |
1687 | Â Â Â default: return Element._getStyle(element, style); |
1688 | Â Â } |
1689 | Â }; |
1690 | } |
1691 | else if (Prototype.Browser.IE) { |
1692 | Â Element.Methods.getStyle = function(element, style) { |
1693 | Â Â element = $(element); |
1694 | Â Â style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize(); |
1695 | Â Â var value = element.style[style]; |
1696 | Â Â if (!value && element.currentStyle) value = element.currentStyle[style]; |
1697 | |
1698 | Â Â if (style == 'opacity') { |
1699 | Â Â Â if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) |
1700 | Â Â Â Â if (value[1]) return parseFloat(value[1]) / 100; |
1701 | Â Â Â return 1.0; |
1702 | Â Â } |
1703 | |
1704 | Â Â if (value == 'auto') { |
1705 | Â Â Â if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none')) |
1706 | Â Â Â Â return element['offset'+style.capitalize()] + 'px'; |
1707 | Â Â Â return null; |
1708 | Â Â } |
1709 | Â Â return value; |
1710 | Â }; |
1711 | |
1712 | Â Element.Methods.setOpacity = function(element, value) { |
1713 | Â Â element = $(element); |
1714 | Â Â var filter = element.getStyle('filter'), style = element.style; |
1715 | Â Â if (value == 1 || value === '') { |
1716 | Â Â Â style.filter = filter.replace(/alpha\([^\)]*\)/gi,''); |
1717 | Â Â Â return element; |
1718 | Â Â } else if (value < 0.00001) value = 0; |
1719 | Â Â style.filter = filter.replace(/alpha\([^\)]*\)/gi, '') + |
1720 | Â Â Â 'alpha(opacity=' + (value * 100) + ')'; |
1721 | Â Â return element; |
1722 | Â }; |
1723 | |
1724 | Â // IE is missing .innerHTML support for TABLE-related elements |
1725 | Â Element.Methods.update = function(element, html) { |
1726 | Â Â element = $(element); |
1727 | Â Â html = typeof html == 'undefined' ? '' : html.toString(); |
1728 | Â Â var tagName = element.tagName.toUpperCase(); |
1729 | Â Â if (['THEAD','TBODY','TR','TD'].include(tagName)) { |
1730 | Â Â Â var div = document.createElement('div'); |
1731 | Â Â Â switch (tagName) { |
1732 | Â Â Â Â case 'THEAD': |
1733 | Â Â Â Â case 'TBODY': |
1734 | Â Â Â Â Â div.innerHTML = '<table><tbody>' +Â html.stripScripts() + '</tbody></table>'; |
1735 | Â Â Â Â Â depth = 2; |
1736 | Â Â Â Â Â break; |
1737 | Â Â Â Â case 'TR': |
1738 | Â Â Â Â Â div.innerHTML = '<table><tbody><tr>' +Â html.stripScripts() + '</tr></tbody></table>'; |
1739 | Â Â Â Â Â depth = 3; |
1740 | Â Â Â Â Â break; |
1741 | Â Â Â Â case 'TD': |
1742 | Â Â Â Â Â div.innerHTML = '<table><tbody><tr><td>' +Â html.stripScripts() + '</td></tr></tbody></table>'; |
1743 | Â Â Â Â Â depth = 4; |
1744 | Â Â Â } |
1745 | Â Â Â $A(element.childNodes).each(function(node) { element.removeChild(node) }); |
1746 | Â Â Â depth.times(function() { div = div.firstChild }); |
1747 | Â Â Â $A(div.childNodes).each(function(node) { element.appendChild(node) }); |
1748 | Â Â } else { |
1749 | Â Â Â element.innerHTML = html.stripScripts(); |
1750 | Â Â } |
1751 | Â Â setTimeout(function() { html.evalScripts() }, 10); |
1752 | Â Â return element; |
1753 | Â } |
1754 | } |
1755 | else if (Prototype.Browser.Gecko) { |
1756 | Â Element.Methods.setOpacity = function(element, value) { |
1757 | Â Â element = $(element); |
1758 | Â Â element.style.opacity = (value == 1) ? 0.999999 : |
1759 | Â Â Â (value === '') ? '' : (value < 0.00001) ? 0 : value; |
1760 | Â Â return element; |
1761 | Â }; |
1762 | } |
1763 | |
1764 | Element._attributeTranslations = { |
1765 | Â names: { |
1766 | Â Â colspan:Â Â "colSpan", |
1767 | Â Â rowspan:Â Â "rowSpan", |
1768 | Â Â valign:Â Â "vAlign", |
1769 | Â Â datetime:Â "dateTime", |
1770 | Â Â accesskey: "accessKey", |
1771 | Â Â tabindex:Â "tabIndex", |
1772 | Â Â enctype:Â Â "encType", |
1773 | Â Â maxlength: "maxLength", |
1774 | Â Â readonly:Â "readOnly", |
1775 | Â Â longdesc:Â "longDesc" |
1776 | Â }, |
1777 | Â values: { |
1778 | Â Â _getAttr: function(element, attribute) { |
1779 | Â Â Â return element.getAttribute(attribute, 2); |
1780 | Â Â }, |
1781 | Â Â _flag: function(element, attribute) { |
1782 | Â Â Â return $(element).hasAttribute(attribute) ? attribute : null; |
1783 | Â Â }, |
1784 | Â Â style: function(element) { |
1785 | Â Â Â return element.style.cssText.toLowerCase(); |
1786 | Â Â }, |
1787 | Â Â title: function(element) { |
1788 | Â Â Â var node = element.getAttributeNode('title'); |
1789 | Â Â Â return node.specified ? node.nodeValue : null; |
1790 | Â Â } |
1791 | Â } |
1792 | }; |
1793 | |
1794 | (function() { |
1795 | Â Object.extend(this, { |
1796 | Â Â href: this._getAttr, |
1797 | Â Â src:Â this._getAttr, |
1798 | Â Â type: this._getAttr, |
1799 | Â Â disabled: this._flag, |
1800 | Â Â checked:Â this._flag, |
1801 | Â Â readonly: this._flag, |
1802 | Â Â multiple: this._flag |
1803 | Â }); |
1804 | }).call(Element._attributeTranslations.values); |
1805 | |
1806 | Element.Methods.Simulated = { |
1807 | Â hasAttribute: function(element, attribute) { |
1808 | Â Â var t = Element._attributeTranslations, node; |
1809 | Â Â attribute = t.names[attribute] || attribute; |
1810 | Â Â node = $(element).getAttributeNode(attribute); |
1811 | Â Â return node && node.specified; |
1812 | Â } |
1813 | }; |
1814 | |
1815 | Element.Methods.ByTag = {}; |
1816 | |
1817 | Object.extend(Element, Element.Methods); |
1818 | |
1819 | if (!Prototype.BrowserFeatures.ElementExtensions && |
1820 | Â document.createElement('div').__proto__) { |
1821 | Â window.HTMLElement = {}; |
1822 | Â window.HTMLElement.prototype = document.createElement('div').__proto__; |
1823 | Â Prototype.BrowserFeatures.ElementExtensions = true; |
1824 | } |
1825 | |
1826 | Element.hasAttribute = function(element, attribute) { |
1827 | Â if (element.hasAttribute) return element.hasAttribute(attribute); |
1828 | Â return Element.Methods.Simulated.hasAttribute(element, attribute); |
1829 | }; |
1830 | |
1831 | Element.addMethods = function(methods) { |
1832 | Â var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag; |
1833 | |
1834 | Â if (!methods) { |
1835 | Â Â Object.extend(Form, Form.Methods); |
1836 | Â Â Object.extend(Form.Element, Form.Element.Methods); |
1837 | Â Â Object.extend(Element.Methods.ByTag, { |
1838 | Â Â Â "FORM":Â Â Â Object.clone(Form.Methods), |
1839 | Â Â Â "INPUT":Â Â Object.clone(Form.Element.Methods), |
1840 | Â Â Â "SELECT":Â Â Object.clone(Form.Element.Methods), |
1841 | Â Â Â "TEXTAREA": Object.clone(Form.Element.Methods) |
1842 | Â Â }); |
1843 | Â } |
1844 | |
1845 | Â if (arguments.length == 2) { |
1846 | Â Â var tagName = methods; |
1847 | Â Â methods = arguments[1]; |
1848 | Â } |
1849 | |
1850 | Â if (!tagName) Object.extend(Element.Methods, methods || {}); |
1851 | Â else { |
1852 | Â Â if (tagName.constructor == Array) tagName.each(extend); |
1853 | Â Â else extend(tagName); |
1854 | Â } |
1855 | |
1856 | Â function extend(tagName) { |
1857 | Â Â tagName = tagName.toUpperCase(); |
1858 | Â Â if (!Element.Methods.ByTag[tagName]) |
1859 | Â Â Â Element.Methods.ByTag[tagName] = {}; |
1860 | Â Â Object.extend(Element.Methods.ByTag[tagName], methods); |
1861 | Â } |
1862 | |
1863 | Â function copy(methods, destination, onlyIfAbsent) { |
1864 | Â Â onlyIfAbsent = onlyIfAbsent || false; |
1865 | Â Â var cache = Element.extend.cache; |
1866 | Â Â for (var property in methods) { |
1867 | Â Â Â var value = methods[property]; |
1868 | Â Â Â if (!onlyIfAbsent || !(property in destination)) |
1869 | Â Â Â Â destination[property] = cache.findOrStore(value); |
1870 | Â Â } |
1871 | Â } |
1872 | |
1873 | Â function findDOMClass(tagName) { |
1874 | Â Â var klass; |
1875 | Â Â var trans = { |
1876 | Â Â Â "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph", |
1877 | Â Â Â "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList", |
1878 | Â Â Â "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading", |
1879 | Â Â Â "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote", |
1880 | Â Â Â "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION": |
1881 | Â Â Â "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD": |
1882 | Â Â Â "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR": |
1883 | Â Â Â "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET": |
1884 | Â Â Â "FrameSet", "IFRAME": "IFrame" |
1885 | Â Â }; |
1886 | Â Â if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element'; |
1887 | Â Â if (window[klass]) return window[klass]; |
1888 | Â Â klass = 'HTML' + tagName + 'Element'; |
1889 | Â Â if (window[klass]) return window[klass]; |
1890 | Â Â klass = 'HTML' + tagName.capitalize() + 'Element'; |
1891 | Â Â if (window[klass]) return window[klass]; |
1892 | |
1893 | Â Â window[klass] = {}; |
1894 | Â Â window[klass].prototype = document.createElement(tagName).__proto__; |
1895 | Â Â return window[klass]; |
1896 | Â } |
1897 | |
1898 | Â if (F.ElementExtensions) { |
1899 | Â Â copy(Element.Methods, HTMLElement.prototype); |
1900 | Â Â copy(Element.Methods.Simulated, HTMLElement.prototype, true); |
1901 | Â } |
1902 | |
1903 | Â if (F.SpecificElementExtensions) { |
1904 | Â Â for (var tag in Element.Methods.ByTag) { |
1905 | Â Â Â var klass = findDOMClass(tag); |
1906 | Â Â Â if (typeof klass == "undefined") continue; |
1907 | Â Â Â copy(T[tag], klass.prototype); |
1908 | Â Â } |
1909 | Â } |
1910 | |
1911 | Â Object.extend(Element, Element.Methods); |
1912 | Â delete Element.ByTag; |
1913 | }; |
1914 | |
1915 | var Toggle = { display: Element.toggle }; |
1916 | |
1917 | /*--------------------------------------------------------------------------*/ |
1918 | |
1919 | Abstract.Insertion = function(adjacency) { |
1920 | Â this.adjacency = adjacency; |
1921 | } |
1922 | |
1923 | Abstract.Insertion.prototype = { |
1924 | Â initialize: function(element, content) { |
1925 | Â Â this.element = $(element); |
1926 | Â Â this.content = content.stripScripts(); |
1927 | |
1928 | Â Â if (this.adjacency && this.element.insertAdjacentHTML) { |
1929 | Â Â Â try { |
1930 | Â Â Â Â this.element.insertAdjacentHTML(this.adjacency, this.content); |
1931 | Â Â Â } catch (e) { |
1932 | Â Â Â Â var tagName = this.element.tagName.toUpperCase(); |
1933 | Â Â Â Â if (['TBODY', 'TR'].include(tagName)) { |
1934 | Â Â Â Â Â this.insertContent(this.contentFromAnonymousTable()); |
1935 | Â Â Â Â } else { |
1936 | Â Â Â Â Â throw e; |
1937 | Â Â Â Â } |
1938 | Â Â Â } |
1939 | Â Â } else { |
1940 | Â Â Â this.range = this.element.ownerDocument.createRange(); |
1941 | Â Â Â if (this.initializeRange) this.initializeRange(); |
1942 | Â Â Â this.insertContent([this.range.createContextualFragment(this.content)]); |
1943 | Â Â } |
1944 | |
1945 | Â Â setTimeout(function() {content.evalScripts()}, 10); |
1946 | Â }, |
1947 | |
1948 | Â contentFromAnonymousTable: function() { |
1949 | Â Â var div = document.createElement('div'); |
1950 | Â Â div.innerHTML = '<table><tbody>' + this.content + '</tbody></table>'; |
1951 | Â Â return $A(div.childNodes[0].childNodes[0].childNodes); |
1952 | Â } |
1953 | } |
1954 | |
1955 | var Insertion = new Object(); |
1956 | |
1957 | Insertion.Before = Class.create(); |
1958 | Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), { |
1959 | Â initializeRange: function() { |
1960 | Â Â this.range.setStartBefore(this.element); |
1961 | Â }, |
1962 | |
1963 | Â insertContent: function(fragments) { |
1964 | Â Â fragments.each((function(fragment) { |
1965 | Â Â Â this.element.parentNode.insertBefore(fragment, this.element); |
1966 | Â Â }).bind(this)); |
1967 | Â } |
1968 | }); |
1969 | |
1970 | Insertion.Top = Class.create(); |
1971 | Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), { |
1972 | Â initializeRange: function() { |
1973 | Â Â this.range.selectNodeContents(this.element); |
1974 | Â Â this.range.collapse(true); |
1975 | Â }, |
1976 | |
1977 | Â insertContent: function(fragments) { |
1978 | Â Â fragments.reverse(false).each((function(fragment) { |
1979 | Â Â Â this.element.insertBefore(fragment, this.element.firstChild); |
1980 | Â Â }).bind(this)); |
1981 | Â } |
1982 | }); |
1983 | |
1984 | Insertion.Bottom = Class.create(); |
1985 | Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), { |
1986 | Â initializeRange: function() { |
1987 | Â Â this.range.selectNodeContents(this.element); |
1988 | Â Â this.range.collapse(this.element); |
1989 | Â }, |
1990 | |
1991 | Â insertContent: function(fragments) { |
1992 | Â Â fragments.each((function(fragment) { |
1993 | Â Â Â this.element.appendChild(fragment); |
1994 | Â Â }).bind(this)); |
1995 | Â } |
1996 | }); |
1997 | |
1998 | Insertion.After = Class.create(); |
1999 | Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), { |
2000 | Â initializeRange: function() { |
2001 | Â Â this.range.setStartAfter(this.element); |
2002 | Â }, |
2003 | |
2004 | Â insertContent: function(fragments) { |
2005 | Â Â fragments.each((function(fragment) { |
2006 | Â Â Â this.element.parentNode.insertBefore(fragment, |
2007 | Â Â Â Â this.element.nextSibling); |
2008 | Â Â }).bind(this)); |
2009 | Â } |
2010 | }); |
2011 | |
2012 | /*--------------------------------------------------------------------------*/ |
2013 | |
2014 | Element.ClassNames = Class.create(); |
2015 | Element.ClassNames.prototype = { |
2016 | Â initialize: function(element) { |
2017 | Â Â this.element = $(element); |
2018 | Â }, |
2019 | |
2020 | Â _each: function(iterator) { |
2021 | Â Â this.element.className.split(/\s+/).select(function(name) { |
2022 | Â Â Â return name.length > 0; |
2023 | Â Â })._each(iterator); |
2024 | Â }, |
2025 | |
2026 | Â set: function(className) { |
2027 | Â Â this.element.className = className; |
2028 | Â }, |
2029 | |
2030 | Â add: function(classNameToAdd) { |
2031 | Â Â if (this.include(classNameToAdd)) return; |
2032 | Â Â this.set($A(this).concat(classNameToAdd).join(' ')); |
2033 | Â }, |
2034 | |
2035 | Â remove: function(classNameToRemove) { |
2036 | Â Â if (!this.include(classNameToRemove)) return; |
2037 | Â Â this.set($A(this).without(classNameToRemove).join(' ')); |
2038 | Â }, |
2039 | |
2040 | Â toString: function() { |
2041 | Â Â return $A(this).join(' '); |
2042 | Â } |
2043 | }; |
2044 | |
2045 | Object.extend(Element.ClassNames.prototype, Enumerable); |
2046 | /* Portions of the Selector class are derived from Jack SlocumâÂÂs DomQuery, |
2047 | Â * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style |
2048 |  * license. Please see http://www.yui-ext.com/ for more information. */ |
2049 | |
2050 | var Selector = Class.create(); |
2051 | |
2052 | Selector.prototype = { |
2053 | Â initialize: function(expression) { |
2054 | Â Â this.expression = expression.strip(); |
2055 | Â Â this.compileMatcher(); |
2056 | Â }, |
2057 | |
2058 | Â compileMatcher: function() { |
2059 | Â Â // Selectors with namespaced attributes can't use the XPath version |
2060 | Â Â if (Prototype.BrowserFeatures.XPath && !(/\[[\w-]*?:/).test(this.expression)) |
2061 | Â Â Â return this.compileXPathMatcher(); |
2062 | |
2063 | Â Â var e = this.expression, ps = Selector.patterns, h = Selector.handlers, |
2064 | Â Â Â Â c = Selector.criteria, le, p, m; |
2065 | |
2066 | Â Â if (Selector._cache[e]) { |
2067 | Â Â Â this.matcher = Selector._cache[e]; return; |
2068 | Â Â } |
2069 | Â Â this.matcher = ["this.matcher = function(root) {", |
2070 | Â Â Â Â Â Â Â Â Â Â "var r = root, h = Selector.handlers, c = false, n;"]; |
2071 | |
2072 | Â Â while (e && le != e && (/\S/).test(e)) { |
2073 | Â Â Â le = e; |
2074 | Â Â Â for (var i in ps) { |
2075 | Â Â Â Â p = ps[i]; |
2076 | Â Â Â Â if (m = e.match(p)) { |
2077 | Â Â Â Â Â this.matcher.push(typeof c[i] == 'function' ? c[i](m) : |
2078 | Â Â Â Â Â Â Â new Template(c[i]).evaluate(m)); |
2079 | Â Â Â Â Â e = e.replace(m[0], ''); |
2080 | Â Â Â Â Â break; |
2081 | Â Â Â Â } |
2082 | Â Â Â } |
2083 | Â Â } |
2084 | |
2085 | Â Â this.matcher.push("return h.unique(n);\n}"); |
2086 | Â Â eval(this.matcher.join('\n')); |
2087 | Â Â Selector._cache[this.expression] = this.matcher; |
2088 | Â }, |
2089 | |
2090 | Â compileXPathMatcher: function() { |
2091 | Â Â var e = this.expression, ps = Selector.patterns, |
2092 |     x = Selector.xpath, le, m; |
2093 | |
2094 | Â Â if (Selector._cache[e]) { |
2095 | Â Â Â this.xpath = Selector._cache[e]; return; |
2096 | Â Â } |
2097 | |
2098 | Â Â this.matcher = ['.//*']; |
2099 | Â Â while (e && le != e && (/\S/).test(e)) { |
2100 | Â Â Â le = e; |
2101 | Â Â Â for (var i in ps) { |
2102 | Â Â Â Â if (m = e.match(ps[i])) { |
2103 | Â Â Â Â Â this.matcher.push(typeof x[i] == 'function' ? x[i](m) : |
2104 | Â Â Â Â Â Â new Template(x[i]).evaluate(m)); |
2105 | Â Â Â Â Â e = e.replace(m[0], ''); |
2106 | Â Â Â Â Â break; |
2107 | Â Â Â Â } |
2108 | Â Â Â } |
2109 | Â Â } |
2110 | |
2111 | Â Â this.xpath = this.matcher.join(''); |
2112 | Â Â Selector._cache[this.expression] = this.xpath; |
2113 | Â }, |
2114 | |
2115 | Â findElements: function(root) { |
2116 | Â Â root = root || document; |
2117 | Â Â if (this.xpath) return document._getElementsByXPath(this.xpath, root); |
2118 | Â Â return this.matcher(root); |
2119 | Â }, |
2120 | |
2121 | Â match: function(element) { |
2122 | Â Â return this.findElements(document).include(element); |
2123 | Â }, |
2124 | |
2125 | Â toString: function() { |
2126 | Â Â return this.expression; |
2127 | Â }, |
2128 | |
2129 | Â inspect: function() { |
2130 | Â Â return "#<Selector:" + this.expression.inspect() + ">"; |
2131 | Â } |
2132 | }; |
2133 | |
2134 | Object.extend(Selector, { |
2135 | Â _cache: {}, |
2136 | |
2137 | Â xpath: { |
2138 | Â Â descendant:Â Â "//*", |
2139 | Â Â child:Â Â Â Â "/*", |
2140 | Â Â adjacent:Â Â Â "/following-sibling::*[1]", |
2141 | Â Â laterSibling: '/following-sibling::*', |
2142 | Â Â tagName:Â Â Â function(m) { |
2143 | Â Â Â if (m[1] == '*') return ''; |
2144 | Â Â Â return "[local-name()='" + m[1].toLowerCase() + |
2145 | Â Â Â Â Â Â Â "' or local-name()='" + m[1].toUpperCase() + "']"; |
2146 | Â Â }, |
2147 | Â Â className:Â Â "[contains(concat(' ', @class, ' '), ' #{1} ')]", |
2148 | Â Â id:Â Â Â Â Â Â "[@id='#{1}']", |
2149 | Â Â attrPresence: "[@#{1}]", |
2150 | Â Â attr: function(m) { |
2151 | Â Â Â m[3] = m[5] || m[6]; |
2152 | Â Â Â return new Template(Selector.xpath.operators[m[2]]).evaluate(m); |
2153 | Â Â }, |
2154 | Â Â pseudo: function(m) { |
2155 | Â Â Â var h = Selector.xpath.pseudos[m[1]]; |
2156 | Â Â Â if (!h) return ''; |
2157 | Â Â Â if (typeof h === 'function') return h(m); |
2158 | Â Â Â return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m); |
2159 | Â Â }, |
2160 | Â Â operators: { |
2161 | Â Â Â '=':Â "[@#{1}='#{3}']", |
2162 | Â Â Â '!=': "[@#{1}!='#{3}']", |
2163 | Â Â Â '^=': "[starts-with(@#{1}, '#{3}')]", |
2164 | Â Â Â '$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']", |
2165 | Â Â Â '*=': "[contains(@#{1}, '#{3}')]", |
2166 | Â Â Â '~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]", |
2167 | Â Â Â '|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]" |
2168 | Â Â }, |
2169 | Â Â pseudos: { |
2170 | Â Â Â 'first-child': '[not(preceding-sibling::*)]', |
2171 | Â Â Â 'last-child':Â '[not(following-sibling::*)]', |
2172 | Â Â Â 'only-child':Â '[not(preceding-sibling::* or following-sibling::*)]', |
2173 | Â Â Â 'empty':Â Â Â Â "[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]", |
2174 | Â Â Â 'checked':Â Â Â "[@checked]", |
2175 | Â Â Â 'disabled':Â Â "[@disabled]", |
2176 | Â Â Â 'enabled':Â Â Â "[not(@disabled)]", |
2177 | Â Â Â 'not': function(m) { |
2178 | Â Â Â Â var e = m[6], p = Selector.patterns, |
2179 | Â Â Â Â Â Â x = Selector.xpath, le, m, v; |
2180 | |
2181 | Â Â Â Â var exclusion = []; |
2182 | Â Â Â Â while (e && le != e && (/\S/).test(e)) { |
2183 | Â Â Â Â Â le = e; |
2184 | Â Â Â Â Â for (var i in p) { |
2185 | Â Â Â Â Â Â if (m = e.match(p[i])) { |
2186 | Â Â Â Â Â Â Â v = typeof x[i] == 'function' ? x[i](m) : new Template(x[i]).evaluate(m); |
2187 | Â Â Â Â Â Â Â exclusion.push("(" + v.substring(1, v.length - 1) + ")"); |
2188 | Â Â Â Â Â Â Â e = e.replace(m[0], ''); |
2189 | Â Â Â Â Â Â Â break; |
2190 | Â Â Â Â Â Â } |
2191 | Â Â Â Â Â } |
2192 | Â Â Â Â } |
2193 | Â Â Â Â return "[not(" + exclusion.join(" and ") + ")]"; |
2194 | Â Â Â }, |
2195 | Â Â Â 'nth-child':Â Â Â function(m) { |
2196 | Â Â Â Â return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m); |
2197 | Â Â Â }, |
2198 | Â Â Â 'nth-last-child': function(m) { |
2199 | Â Â Â Â return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m); |
2200 | Â Â Â }, |
2201 | Â Â Â 'nth-of-type':Â Â function(m) { |
2202 | Â Â Â Â return Selector.xpath.pseudos.nth("position() ", m); |
2203 | Â Â Â }, |
2204 | Â Â Â 'nth-last-of-type': function(m) { |
2205 | Â Â Â Â return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m); |
2206 | Â Â Â }, |
2207 | Â Â Â 'first-of-type':Â function(m) { |
2208 | Â Â Â Â m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m); |
2209 | Â Â Â }, |
2210 | Â Â Â 'last-of-type':Â Â function(m) { |
2211 | Â Â Â Â m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m); |
2212 | Â Â Â }, |
2213 | Â Â Â 'only-of-type':Â Â function(m) { |
2214 | Â Â Â Â var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m); |
2215 | Â Â Â }, |
2216 | Â Â Â nth: function(fragment, m) { |
2217 | Â Â Â Â var mm, formula = m[6], predicate; |
2218 | Â Â Â Â if (formula == 'even') formula = '2n+0'; |
2219 | Â Â Â Â if (formula == 'odd')Â formula = '2n+1'; |
2220 | Â Â Â Â if (mm = formula.match(/^(\d+)$/)) // digit only |
2221 | Â Â Â Â Â return '[' + fragment + "= " + mm[1] + ']'; |
2222 | Â Â Â Â if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b |
2223 | Â Â Â Â Â if (mm[1] == "-") mm[1] = -1; |
2224 | Â Â Â Â Â var a = mm[1] ? Number(mm[1]) : 1; |
2225 | Â Â Â Â Â var b = mm[2] ? Number(mm[2]) : 0; |
2226 | Â Â Â Â Â predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " + |
2227 | Â Â Â Â Â "((#{fragment} - #{b}) div #{a} >= 0)]"; |
2228 | Â Â Â Â Â return new Template(predicate).evaluate({ |
2229 | Â Â Â Â Â Â fragment: fragment, a: a, b: b }); |
2230 | Â Â Â Â } |
2231 | Â Â Â } |
2232 | Â Â } |
2233 | Â }, |
2234 | |
2235 | Â criteria: { |
2236 | Â Â tagName:Â Â Â 'n = h.tagName(n, r, "#{1}", c);Â Â c = false;', |
2237 | Â Â className:Â Â 'n = h.className(n, r, "#{1}", c); c = false;', |
2238 | Â Â id:Â Â Â Â Â Â 'n = h.id(n, r, "#{1}", c);Â Â Â Â c = false;', |
2239 | Â Â attrPresence: 'n = h.attrPresence(n, r, "#{1}"); c = false;', |
2240 | Â Â attr: function(m) { |
2241 | Â Â Â m[3] = (m[5] || m[6]); |
2242 | Â Â Â return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}"); c = false;').evaluate(m); |
2243 | Â Â }, |
2244 | Â Â pseudo:Â Â Â Â function(m) { |
2245 | Â Â Â if (m[6]) m[6] = m[6].replace(/"/g, '\\"'); |
2246 | Â Â Â return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m); |
2247 | Â Â }, |
2248 | Â Â descendant:Â Â 'c = "descendant";', |
2249 | Â Â child:Â Â Â Â 'c = "child";', |
2250 | Â Â adjacent:Â Â Â 'c = "adjacent";', |
2251 | Â Â laterSibling: 'c = "laterSibling";' |
2252 | Â }, |
2253 | |
2254 | Â patterns: { |
2255 | Â Â // combinators must be listed first |
2256 | Â Â // (and descendant needs to be last combinator) |
2257 | Â Â laterSibling: /^\s*~\s*/, |
2258 | Â Â child:Â Â Â Â /^\s*>\s*/, |
2259 | Â Â adjacent:Â Â Â /^\s*\+\s*/, |
2260 | Â Â descendant:Â Â /^\s/, |
2261 | |
2262 | Â Â // selectors follow |
2263 | Â Â tagName:Â Â Â /^\s*(\*|[\w\-]+)(\b|$)?/, |
2264 | Â Â id:Â Â Â Â Â Â /^#([\w\-\*]+)(\b|$)/, |
2265 | Â Â className:Â Â /^\.([\w\-\*]+)(\b|$)/, |
2266 | Â Â pseudo:Â Â Â Â /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|\s|(?=:))/, |
2267 | Â Â attrPresence: /^\[([\w]+)\]/, |
2268 | Â Â attr:Â Â Â Â Â /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\]]*?)\4|([^'"][^\]]*?)))?\]/ |
2269 | Â }, |
2270 | |
2271 | Â handlers: { |
2272 | Â Â // UTILITY FUNCTIONS |
2273 | Â Â // joins two collections |
2274 | Â Â concat: function(a, b) { |
2275 | Â Â Â for (var i = 0, node; node = b[i]; i++) |
2276 | Â Â Â Â a.push(node); |
2277 | Â Â Â return a; |
2278 | Â Â }, |
2279 | |
2280 | Â Â // marks an array of nodes for counting |
2281 | Â Â mark: function(nodes) { |
2282 | Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2283 | Â Â Â Â node._counted = true; |
2284 | Â Â Â return nodes; |
2285 | Â Â }, |
2286 | |
2287 | Â Â unmark: function(nodes) { |
2288 | Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2289 | Â Â Â Â node._counted = undefined; |
2290 | Â Â Â return nodes; |
2291 | Â Â }, |
2292 | |
2293 | Â Â // mark each child node with its position (for nth calls) |
2294 | Â Â // "ofType" flag indicates whether we're indexing for nth-of-type |
2295 | Â Â // rather than nth-child |
2296 | Â Â index: function(parentNode, reverse, ofType) { |
2297 | Â Â Â parentNode._counted = true; |
2298 | Â Â Â if (reverse) { |
2299 | Â Â Â Â for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) { |
2300 | Â Â Â Â Â node = nodes[i]; |
2301 | Â Â Â Â Â if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; |
2302 | Â Â Â Â } |
2303 | Â Â Â } else { |
2304 | Â Â Â Â for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++) |
2305 | Â Â Â Â Â if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; |
2306 | Â Â Â } |
2307 | Â Â }, |
2308 | |
2309 | Â Â // filters out duplicates and extends all nodes |
2310 | Â Â unique: function(nodes) { |
2311 | Â Â Â if (nodes.length == 0) return nodes; |
2312 | Â Â Â var results = [], n; |
2313 | Â Â Â for (var i = 0, l = nodes.length; i < l; i++) |
2314 | Â Â Â Â if (!(n = nodes[i])._counted) { |
2315 | Â Â Â Â Â n._counted = true; |
2316 | Â Â Â Â Â results.push(Element.extend(n)); |
2317 | Â Â Â Â } |
2318 | Â Â Â return Selector.handlers.unmark(results); |
2319 | Â Â }, |
2320 | |
2321 | Â Â // COMBINATOR FUNCTIONS |
2322 | Â Â descendant: function(nodes) { |
2323 | Â Â Â var h = Selector.handlers; |
2324 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) |
2325 | Â Â Â Â h.concat(results, node.getElementsByTagName('*')); |
2326 | Â Â Â return results; |
2327 | Â Â }, |
2328 | |
2329 | Â Â child: function(nodes) { |
2330 | Â Â Â var h = Selector.handlers; |
2331 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) { |
2332 | Â Â Â Â for (var j = 0, children = [], child; child = node.childNodes[j]; j++) |
2333 | Â Â Â Â Â if (child.nodeType == 1 && child.tagName != '!') results.push(child); |
2334 | Â Â Â } |
2335 | Â Â Â return results; |
2336 | Â Â }, |
2337 | |
2338 | Â Â adjacent: function(nodes) { |
2339 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) { |
2340 | Â Â Â Â var next = this.nextElementSibling(node); |
2341 | Â Â Â Â if (next) results.push(next); |
2342 | Â Â Â } |
2343 | Â Â Â return results; |
2344 | Â Â }, |
2345 | |
2346 | Â Â laterSibling: function(nodes) { |
2347 | Â Â Â var h = Selector.handlers; |
2348 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) |
2349 | Â Â Â Â h.concat(results, Element.nextSiblings(node)); |
2350 | Â Â Â return results; |
2351 | Â Â }, |
2352 | |
2353 | Â Â nextElementSibling: function(node) { |
2354 | Â Â Â while (node = node.nextSibling) |
2355 | Â Â Â Â Â Â Â if (node.nodeType == 1) return node; |
2356 | Â Â Â return null; |
2357 | Â Â }, |
2358 | |
2359 | Â Â previousElementSibling: function(node) { |
2360 | Â Â Â while (node = node.previousSibling) |
2361 | Â Â Â Â if (node.nodeType == 1) return node; |
2362 | Â Â Â return null; |
2363 | Â Â }, |
2364 | |
2365 | Â Â // TOKEN FUNCTIONS |
2366 | Â Â tagName: function(nodes, root, tagName, combinator) { |
2367 | Â Â Â tagName = tagName.toUpperCase(); |
2368 | Â Â Â var results = [], h = Selector.handlers; |
2369 | Â Â Â if (nodes) { |
2370 | Â Â Â Â if (combinator) { |
2371 | Â Â Â Â Â // fastlane for ordinary descendant combinators |
2372 | Â Â Â Â Â if (combinator == "descendant") { |
2373 | Â Â Â Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2374 | Â Â Â Â Â Â Â h.concat(results, node.getElementsByTagName(tagName)); |
2375 | Â Â Â Â Â Â return results; |
2376 | Â Â Â Â Â } else nodes = this[combinator](nodes); |
2377 | Â Â Â Â Â if (tagName == "*") return nodes; |
2378 | Â Â Â Â } |
2379 | Â Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2380 | Â Â Â Â Â if (node.tagName.toUpperCase() == tagName) results.push(node); |
2381 | Â Â Â Â return results; |
2382 | Â Â Â } else return root.getElementsByTagName(tagName); |
2383 | Â Â }, |
2384 | |
2385 | Â Â id: function(nodes, root, id, combinator) { |
2386 | Â Â Â var targetNode = $(id), h = Selector.handlers; |
2387 | Â Â Â if (!nodes && root == document) return targetNode ? [targetNode] : []; |
2388 | Â Â Â if (nodes) { |
2389 | Â Â Â Â if (combinator) { |
2390 | Â Â Â Â Â if (combinator == 'child') { |
2391 | Â Â Â Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2392 | Â Â Â Â Â Â Â if (targetNode.parentNode == node) return [targetNode]; |
2393 | Â Â Â Â Â } else if (combinator == 'descendant') { |
2394 | Â Â Â Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2395 | Â Â Â Â Â Â Â if (Element.descendantOf(targetNode, node)) return [targetNode]; |
2396 | Â Â Â Â Â } else if (combinator == 'adjacent') { |
2397 | Â Â Â Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2398 | Â Â Â Â Â Â Â if (Selector.handlers.previousElementSibling(targetNode) == node) |
2399 | Â Â Â Â Â Â Â Â return [targetNode]; |
2400 | Â Â Â Â Â } else nodes = h[combinator](nodes); |
2401 | Â Â Â Â } |
2402 | Â Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2403 | Â Â Â Â Â if (node == targetNode) return [targetNode]; |
2404 | Â Â Â Â return []; |
2405 | Â Â Â } |
2406 | Â Â Â return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : []; |
2407 | Â Â }, |
2408 | |
2409 | Â Â className: function(nodes, root, className, combinator) { |
2410 | Â Â Â if (nodes && combinator) nodes = this[combinator](nodes); |
2411 | Â Â Â return Selector.handlers.byClassName(nodes, root, className); |
2412 | Â Â }, |
2413 | |
2414 | Â Â byClassName: function(nodes, root, className) { |
2415 | Â Â Â if (!nodes) nodes = Selector.handlers.descendant([root]); |
2416 | Â Â Â var needle = ' ' + className + ' '; |
2417 | Â Â Â for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) { |
2418 | Â Â Â Â nodeClassName = node.className; |
2419 | Â Â Â Â if (nodeClassName.length == 0) continue; |
2420 | Â Â Â Â if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle)) |
2421 | Â Â Â Â Â results.push(node); |
2422 | Â Â Â } |
2423 | Â Â Â return results; |
2424 | Â Â }, |
2425 | |
2426 | Â Â attrPresence: function(nodes, root, attr) { |
2427 | Â Â Â var results = []; |
2428 | Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2429 | Â Â Â Â if (Element.hasAttribute(node, attr)) results.push(node); |
2430 | Â Â Â return results; |
2431 | Â Â }, |
2432 | |
2433 | Â Â attr: function(nodes, root, attr, value, operator) { |
2434 | Â Â Â if (!nodes) nodes = root.getElementsByTagName("*"); |
2435 | Â Â Â var handler = Selector.operators[operator], results = []; |
2436 | Â Â Â for (var i = 0, node; node = nodes[i]; i++) { |
2437 | Â Â Â Â var nodeValue = Element.readAttribute(node, attr); |
2438 | Â Â Â Â if (nodeValue === null) continue; |
2439 | Â Â Â Â if (handler(nodeValue, value)) results.push(node); |
2440 | Â Â Â } |
2441 | Â Â Â return results; |
2442 | Â Â }, |
2443 | |
2444 | Â Â pseudo: function(nodes, name, value, root, combinator) { |
2445 | Â Â Â if (nodes && combinator) nodes = this[combinator](nodes); |
2446 | Â Â Â if (!nodes) nodes = root.getElementsByTagName("*"); |
2447 | Â Â Â return Selector.pseudos[name](nodes, value, root); |
2448 | Â Â } |
2449 | Â }, |
2450 | |
2451 | Â pseudos: { |
2452 | Â Â 'first-child': function(nodes, value, root) { |
2453 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) { |
2454 | Â Â Â Â if (Selector.handlers.previousElementSibling(node)) continue; |
2455 | Â Â Â Â Â results.push(node); |
2456 | Â Â Â } |
2457 | Â Â Â return results; |
2458 | Â Â }, |
2459 | Â Â 'last-child': function(nodes, value, root) { |
2460 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) { |
2461 | Â Â Â Â if (Selector.handlers.nextElementSibling(node)) continue; |
2462 | Â Â Â Â Â results.push(node); |
2463 | Â Â Â } |
2464 | Â Â Â return results; |
2465 | Â Â }, |
2466 | Â Â 'only-child': function(nodes, value, root) { |
2467 | Â Â Â var h = Selector.handlers; |
2468 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) |
2469 | Â Â Â Â if (!h.previousElementSibling(node) && !h.nextElementSibling(node)) |
2470 | Â Â Â Â Â results.push(node); |
2471 | Â Â Â return results; |
2472 | Â Â }, |
2473 | Â Â 'nth-child':Â Â Â Â function(nodes, formula, root) { |
2474 | Â Â Â return Selector.pseudos.nth(nodes, formula, root); |
2475 | Â Â }, |
2476 | Â Â 'nth-last-child':Â Â function(nodes, formula, root) { |
2477 | Â Â Â return Selector.pseudos.nth(nodes, formula, root, true); |
2478 | Â Â }, |
2479 | Â Â 'nth-of-type':Â Â Â function(nodes, formula, root) { |
2480 | Â Â Â return Selector.pseudos.nth(nodes, formula, root, false, true); |
2481 | Â Â }, |
2482 | Â Â 'nth-last-of-type': function(nodes, formula, root) { |
2483 | Â Â Â return Selector.pseudos.nth(nodes, formula, root, true, true); |
2484 | Â Â }, |
2485 | Â Â 'first-of-type':Â Â function(nodes, formula, root) { |
2486 | Â Â Â return Selector.pseudos.nth(nodes, "1", root, false, true); |
2487 | Â Â }, |
2488 | Â Â 'last-of-type':Â Â Â function(nodes, formula, root) { |
2489 | Â Â Â return Selector.pseudos.nth(nodes, "1", root, true, true); |
2490 | Â Â }, |
2491 | Â Â 'only-of-type':Â Â Â function(nodes, formula, root) { |
2492 | Â Â Â var p = Selector.pseudos; |
2493 | Â Â Â return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root); |
2494 | Â Â }, |
2495 | |
2496 | Â Â // handles the an+b logic |
2497 | Â Â getIndices: function(a, b, total) { |
2498 | Â Â Â if (a == 0) return b > 0 ? [b] : []; |
2499 | Â Â Â return $R(1, total).inject([], function(memo, i) { |
2500 | Â Â Â Â if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i); |
2501 | Â Â Â Â return memo; |
2502 | Â Â Â }); |
2503 | Â Â }, |
2504 | |
2505 | Â Â // handles nth(-last)-child, nth(-last)-of-type, and (first|last)-of-type |
2506 | Â Â nth: function(nodes, formula, root, reverse, ofType) { |
2507 | Â Â Â if (nodes.length == 0) return []; |
2508 | Â Â Â if (formula == 'even') formula = '2n+0'; |
2509 | Â Â Â if (formula == 'odd')Â formula = '2n+1'; |
2510 | Â Â Â var h = Selector.handlers, results = [], indexed = [], m; |
2511 | Â Â Â h.mark(nodes); |
2512 | Â Â Â for (var i = 0, node; node = nodes[i]; i++) { |
2513 | Â Â Â Â if (!node.parentNode._counted) { |
2514 | Â Â Â Â Â h.index(node.parentNode, reverse, ofType); |
2515 | Â Â Â Â Â indexed.push(node.parentNode); |
2516 | Â Â Â Â } |
2517 | Â Â Â } |
2518 | Â Â Â if (formula.match(/^\d+$/)) { // just a number |
2519 | Â Â Â Â formula = Number(formula); |
2520 | Â Â Â Â for (var i = 0, node; node = nodes[i]; i++) |
2521 | Â Â Â Â Â if (node.nodeIndex == formula) results.push(node); |
2522 | Â Â Â } else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b |
2523 | Â Â Â Â if (m[1] == "-") m[1] = -1; |
2524 | Â Â Â Â var a = m[1] ? Number(m[1]) : 1; |
2525 | Â Â Â Â var b = m[2] ? Number(m[2]) : 0; |
2526 | Â Â Â Â var indices = Selector.pseudos.getIndices(a, b, nodes.length); |
2527 | Â Â Â Â for (var i = 0, node, l = indices.length; node = nodes[i]; i++) { |
2528 | Â Â Â Â Â for (var j = 0; j < l; j++) |
2529 | Â Â Â Â Â Â if (node.nodeIndex == indices[j]) results.push(node); |
2530 | Â Â Â Â } |
2531 | Â Â Â } |
2532 | Â Â Â h.unmark(nodes); |
2533 | Â Â Â h.unmark(indexed); |
2534 | Â Â Â return results; |
2535 | Â Â }, |
2536 | |
2537 | Â Â 'empty': function(nodes, value, root) { |
2538 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) { |
2539 | Â Â Â Â // IE treats comments as element nodes |
2540 | Â Â Â Â if (node.tagName == '!' || (node.firstChild && !node.innerHTML.match(/^\s*$/))) continue; |
2541 | Â Â Â Â results.push(node); |
2542 | Â Â Â } |
2543 | Â Â Â return results; |
2544 | Â Â }, |
2545 | |
2546 | Â Â 'not': function(nodes, selector, root) { |
2547 | Â Â Â var h = Selector.handlers, selectorType, m; |
2548 | Â Â Â var exclusions = new Selector(selector).findElements(root); |
2549 | Â Â Â h.mark(exclusions); |
2550 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) |
2551 | Â Â Â Â if (!node._counted) results.push(node); |
2552 | Â Â Â h.unmark(exclusions); |
2553 | Â Â Â return results; |
2554 | Â Â }, |
2555 | |
2556 | Â Â 'enabled': function(nodes, value, root) { |
2557 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) |
2558 | Â Â Â Â if (!node.disabled) results.push(node); |
2559 | Â Â Â return results; |
2560 | Â Â }, |
2561 | |
2562 | Â Â 'disabled': function(nodes, value, root) { |
2563 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) |
2564 | Â Â Â Â if (node.disabled) results.push(node); |
2565 | Â Â Â return results; |
2566 | Â Â }, |
2567 | |
2568 | Â Â 'checked': function(nodes, value, root) { |
2569 | Â Â Â for (var i = 0, results = [], node; node = nodes[i]; i++) |
2570 | Â Â Â Â if (node.checked) results.push(node); |
2571 | Â Â Â return results; |
2572 | Â Â } |
2573 | Â }, |
2574 | |
2575 | Â operators: { |
2576 | Â Â '=':Â function(nv, v) { return nv == v; }, |
2577 | Â Â '!=': function(nv, v) { return nv != v; }, |
2578 | Â Â '^=': function(nv, v) { return nv.startsWith(v); }, |
2579 | Â Â '$=': function(nv, v) { return nv.endsWith(v); }, |
2580 | Â Â '*=': function(nv, v) { return nv.include(v); }, |
2581 | Â Â '~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); }, |
2582 | Â Â '|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); } |
2583 | Â }, |
2584 | |
2585 | Â matchElements: function(elements, expression) { |
2586 | Â Â var matches = new Selector(expression).findElements(), h = Selector.handlers; |
2587 | Â Â h.mark(matches); |
2588 | Â Â for (var i = 0, results = [], element; element = elements[i]; i++) |
2589 | Â Â Â if (element._counted) results.push(element); |
2590 | Â Â h.unmark(matches); |
2591 | Â Â return results; |
2592 | Â }, |
2593 | |
2594 | Â findElement: function(elements, expression, index) { |
2595 | Â Â if (typeof expression == 'number') { |
2596 | Â Â Â index = expression; expression = false; |
2597 | Â Â } |
2598 | Â Â return Selector.matchElements(elements, expression || '*')[index || 0]; |
2599 | Â }, |
2600 | |
2601 | Â findChildElements: function(element, expressions) { |
2602 | Â Â var exprs = expressions.join(','), expressions = []; |
2603 | Â Â exprs.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) { |
2604 | Â Â Â expressions.push(m[1].strip()); |
2605 | Â Â }); |
2606 | Â Â var results = [], h = Selector.handlers; |
2607 | Â Â for (var i = 0, l = expressions.length, selector; i < l; i++) { |
2608 | Â Â Â selector = new Selector(expressions[i].strip()); |
2609 | Â Â Â h.concat(results, selector.findElements(element)); |
2610 | Â Â } |
2611 | Â Â return (l > 1) ? h.unique(results) : results; |
2612 | Â } |
2613 | }); |
2614 | |
2615 | function $$() { |
2616 | Â return Selector.findChildElements(document, $A(arguments)); |
2617 | } |
2618 | var Form = { |
2619 | Â reset: function(form) { |
2620 | Â Â $(form).reset(); |
2621 | Â Â return form; |
2622 | Â }, |
2623 | |
2624 | Â serializeElements: function(elements, getHash) { |
2625 | Â Â var data = elements.inject({}, function(result, element) { |
2626 | Â Â Â if (!element.disabled && element.name) { |
2627 | Â Â Â Â var key = element.name, value = $(element).getValue(); |
2628 | Â Â Â Â if (value != null) { |
2629 | Â Â Â Â Â Â Â Â if (key in result) { |
2630 | Â Â Â Â Â Â if (result[key].constructor != Array) result[key] = [result[key]]; |
2631 | Â Â Â Â Â Â result[key].push(value); |
2632 | Â Â Â Â Â } |
2633 | Â Â Â Â Â else result[key] = value; |
2634 | Â Â Â Â } |
2635 | Â Â Â } |
2636 | Â Â Â return result; |
2637 | Â Â }); |
2638 | |
2639 | Â Â return getHash ? data : Hash.toQueryString(data); |
2640 | Â } |
2641 | }; |
2642 | |
2643 | Form.Methods = { |
2644 | Â serialize: function(form, getHash) { |
2645 | Â Â return Form.serializeElements(Form.getElements(form), getHash); |
2646 | Â }, |
2647 | |
2648 | Â getElements: function(form) { |
2649 | Â Â return $A($(form).getElementsByTagName('*')).inject([], |
2650 | Â Â Â function(elements, child) { |
2651 | Â Â Â Â if (Form.Element.Serializers[child.tagName.toLowerCase()]) |
2652 | Â Â Â Â Â elements.push(Element.extend(child)); |
2653 | Â Â Â Â return elements; |
2654 | Â Â Â } |
2655 | Â Â ); |
2656 | Â }, |
2657 | |
2658 | Â getInputs: function(form, typeName, name) { |
2659 | Â Â form = $(form); |
2660 | Â Â var inputs = form.getElementsByTagName('input'); |
2661 | |
2662 | Â Â if (!typeName && !name) return $A(inputs).map(Element.extend); |
2663 | |
2664 | Â Â for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) { |
2665 | Â Â Â var input = inputs[i]; |
2666 | Â Â Â if ((typeName && input.type != typeName) || (name && input.name != name)) |
2667 | Â Â Â Â continue; |
2668 | Â Â Â matchingInputs.push(Element.extend(input)); |
2669 | Â Â } |
2670 | |
2671 | Â Â return matchingInputs; |
2672 | Â }, |
2673 | |
2674 | Â disable: function(form) { |
2675 | Â Â form = $(form); |
2676 | Â Â Form.getElements(form).invoke('disable'); |
2677 | Â Â return form; |
2678 | Â }, |
2679 | |
2680 | Â enable: function(form) { |
2681 | Â Â form = $(form); |
2682 | Â Â Form.getElements(form).invoke('enable'); |
2683 | Â Â return form; |
2684 | Â }, |
2685 | |
2686 | Â findFirstElement: function(form) { |
2687 | Â Â return $(form).getElements().find(function(element) { |
2688 | Â Â Â return element.type != 'hidden' && !element.disabled && |
2689 | Â Â Â Â ['input', 'select', 'textarea'].include(element.tagName.toLowerCase()); |
2690 | Â Â }); |
2691 | Â }, |
2692 | |
2693 | Â focusFirstElement: function(form) { |
2694 | Â Â form = $(form); |
2695 | Â Â form.findFirstElement().activate(); |
2696 | Â Â return form; |
2697 | Â }, |
2698 | |
2699 | Â request: function(form, options) { |
2700 | Â Â form = $(form), options = Object.clone(options || {}); |
2701 | |
2702 | Â Â var params = options.parameters; |
2703 | Â Â options.parameters = form.serialize(true); |
2704 | |
2705 | Â Â if (params) { |
2706 | Â Â Â if (typeof params == 'string') params = params.toQueryParams(); |
2707 | Â Â Â Object.extend(options.parameters, params); |
2708 | Â Â } |
2709 | |
2710 | Â Â if (form.hasAttribute('method') && !options.method) |
2711 | Â Â Â options.method = form.method; |
2712 | |
2713 | Â Â return new Ajax.Request(form.readAttribute('action'), options); |
2714 | Â } |
2715 | } |
2716 | |
2717 | /*--------------------------------------------------------------------------*/ |
2718 | |
2719 | Form.Element = { |
2720 | Â focus: function(element) { |
2721 | Â Â $(element).focus(); |
2722 | Â Â return element; |
2723 | Â }, |
2724 | |
2725 | Â select: function(element) { |
2726 | Â Â $(element).select(); |
2727 | Â Â return element; |
2728 | Â } |
2729 | } |
2730 | |
2731 | Form.Element.Methods = { |
2732 | Â serialize: function(element) { |
2733 | Â Â element = $(element); |
2734 | Â Â if (!element.disabled && element.name) { |
2735 | Â Â Â var value = element.getValue(); |
2736 | Â Â Â if (value != undefined) { |
2737 | Â Â Â Â var pair = {}; |
2738 | Â Â Â Â pair[element.name] = value; |
2739 | Â Â Â Â return Hash.toQueryString(pair); |
2740 | Â Â Â } |
2741 | Â Â } |
2742 | Â Â return ''; |
2743 | Â }, |
2744 | |
2745 | Â getValue: function(element) { |
2746 | Â Â element = $(element); |
2747 | Â Â var method = element.tagName.toLowerCase(); |
2748 | Â Â return Form.Element.Serializers[method](element); |
2749 | Â }, |
2750 | |
2751 | Â clear: function(element) { |
2752 | Â Â $(element).value = ''; |
2753 | Â Â return element; |
2754 | Â }, |
2755 | |
2756 | Â present: function(element) { |
2757 | Â Â return $(element).value != ''; |
2758 | Â }, |
2759 | |
2760 | Â activate: function(element) { |
2761 | Â Â element = $(element); |
2762 | Â Â try { |
2763 | Â Â Â element.focus(); |
2764 | Â Â Â if (element.select && (element.tagName.toLowerCase() != 'input' || |
2765 | Â Â Â Â !['button', 'reset', 'submit'].include(element.type))) |
2766 | Â Â Â Â element.select(); |
2767 | Â Â } catch (e) {} |
2768 | Â Â return element; |
2769 | Â }, |
2770 | |
2771 | Â disable: function(element) { |
2772 | Â Â element = $(element); |
2773 | Â Â element.blur(); |
2774 | Â Â element.disabled = true; |
2775 | Â Â return element; |
2776 | Â }, |
2777 | |
2778 | Â enable: function(element) { |
2779 | Â Â element = $(element); |
2780 | Â Â element.disabled = false; |
2781 | Â Â return element; |
2782 | Â } |
2783 | } |
2784 | |
2785 | /*--------------------------------------------------------------------------*/ |
2786 | |
2787 | var Field = Form.Element; |
2788 | var $F = Form.Element.Methods.getValue; |
2789 | |
2790 | /*--------------------------------------------------------------------------*/ |
2791 | |
2792 | Form.Element.Serializers = { |
2793 | Â input: function(element) { |
2794 | Â Â switch (element.type.toLowerCase()) { |
2795 | Â Â Â case 'checkbox': |
2796 | Â Â Â case 'radio': |
2797 | Â Â Â Â return Form.Element.Serializers.inputSelector(element); |
2798 | Â Â Â default: |
2799 | Â Â Â Â return Form.Element.Serializers.textarea(element); |
2800 | Â Â } |
2801 | Â }, |
2802 | |
2803 | Â inputSelector: function(element) { |
2804 | Â Â return element.checked ? element.value : null; |
2805 | Â }, |
2806 | |
2807 | Â textarea: function(element) { |
2808 | Â Â return element.value; |
2809 | Â }, |
2810 | |
2811 | Â select: function(element) { |
2812 | Â Â return this[element.type == 'select-one' ? |
2813 | Â Â Â 'selectOne' : 'selectMany'](element); |
2814 | Â }, |
2815 | |
2816 | Â selectOne: function(element) { |
2817 | Â Â var index = element.selectedIndex; |
2818 | Â Â return index >= 0 ? this.optionValue(element.options[index]) : null; |
2819 | Â }, |
2820 | |
2821 | Â selectMany: function(element) { |
2822 | Â Â var values, length = element.length; |
2823 | Â Â if (!length) return null; |
2824 | |
2825 | Â Â for (var i = 0, values = []; i < length; i++) { |
2826 | Â Â Â var opt = element.options[i]; |
2827 | Â Â Â if (opt.selected) values.push(this.optionValue(opt)); |
2828 | Â Â } |
2829 | Â Â return values; |
2830 | Â }, |
2831 | |
2832 | Â optionValue: function(opt) { |
2833 | Â Â // extend element because hasAttribute may not be native |
2834 | Â Â return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text; |
2835 | Â } |
2836 | } |
2837 | |
2838 | /*--------------------------------------------------------------------------*/ |
2839 | |
2840 | Abstract.TimedObserver = function() {} |
2841 | Abstract.TimedObserver.prototype = { |
2842 | Â initialize: function(element, frequency, callback) { |
2843 | Â Â this.frequency = frequency; |
2844 |   this.element  = $(element); |
2845 |   this.callback = callback; |
2846 | |
2847 | Â Â this.lastValue = this.getValue(); |
2848 | Â Â this.registerCallback(); |
2849 | Â }, |
2850 | |
2851 | Â registerCallback: function() { |
2852 | Â Â setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); |
2853 | Â }, |
2854 | |
2855 | Â onTimerEvent: function() { |
2856 | Â Â var value = this.getValue(); |
2857 | Â Â var changed = ('string' == typeof this.lastValue && 'string' == typeof value |
2858 | Â Â Â ? this.lastValue != value : String(this.lastValue) != String(value)); |
2859 | Â Â if (changed) { |
2860 | Â Â Â this.callback(this.element, value); |
2861 | Â Â Â this.lastValue = value; |
2862 | Â Â } |
2863 | Â } |
2864 | } |
2865 | |
2866 | Form.Element.Observer = Class.create(); |
2867 | Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { |
2868 | Â getValue: function() { |
2869 | Â Â return Form.Element.getValue(this.element); |
2870 | Â } |
2871 | }); |
2872 | |
2873 | Form.Observer = Class.create(); |
2874 | Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), { |
2875 | Â getValue: function() { |
2876 | Â Â return Form.serialize(this.element); |
2877 | Â } |
2878 | }); |
2879 | |
2880 | /*--------------------------------------------------------------------------*/ |
2881 | |
2882 | Abstract.EventObserver = function() {} |
2883 | Abstract.EventObserver.prototype = { |
2884 | Â initialize: function(element, callback) { |
2885 |   this.element = $(element); |
2886 | Â Â this.callback = callback; |
2887 | |
2888 | Â Â this.lastValue = this.getValue(); |
2889 | Â Â if (this.element.tagName.toLowerCase() == 'form') |
2890 | Â Â Â this.registerFormCallbacks(); |
2891 | Â Â else |
2892 | Â Â Â this.registerCallback(this.element); |
2893 | Â }, |
2894 | |
2895 | Â onElementEvent: function() { |
2896 | Â Â var value = this.getValue(); |
2897 | Â Â if (this.lastValue != value) { |
2898 | Â Â Â this.callback(this.element, value); |
2899 | Â Â Â this.lastValue = value; |
2900 | Â Â } |
2901 | Â }, |
2902 | |
2903 | Â registerFormCallbacks: function() { |
2904 | Â Â Form.getElements(this.element).each(this.registerCallback.bind(this)); |
2905 | Â }, |
2906 | |
2907 | Â registerCallback: function(element) { |
2908 | Â Â if (element.type) { |
2909 | Â Â Â switch (element.type.toLowerCase()) { |
2910 | Â Â Â Â case 'checkbox': |
2911 | Â Â Â Â case 'radio': |
2912 | Â Â Â Â Â Event.observe(element, 'click', this.onElementEvent.bind(this)); |
2913 | Â Â Â Â Â break; |
2914 | Â Â Â Â default: |
2915 | Â Â Â Â Â Event.observe(element, 'change', this.onElementEvent.bind(this)); |
2916 | Â Â Â Â Â break; |
2917 | Â Â Â } |
2918 | Â Â } |
2919 | Â } |
2920 | } |
2921 | |
2922 | Form.Element.EventObserver = Class.create(); |
2923 | Form.Element.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { |
2924 | Â getValue: function() { |
2925 | Â Â return Form.Element.getValue(this.element); |
2926 | Â } |
2927 | }); |
2928 | |
2929 | Form.EventObserver = Class.create(); |
2930 | Form.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), { |
2931 | Â getValue: function() { |
2932 | Â Â return Form.serialize(this.element); |
2933 | Â } |
2934 | }); |
2935 | if (!window.Event) { |
2936 | Â var Event = new Object(); |
2937 | } |
2938 | |
2939 | Object.extend(Event, { |
2940 | Â KEY_BACKSPACE: 8, |
2941 | Â KEY_TAB:Â Â Â Â 9, |
2942 | Â KEY_RETURN:Â Â 13, |
2943 | Â KEY_ESC:Â Â Â 27, |
2944 | Â KEY_LEFT:Â Â Â 37, |
2945 | Â KEY_UP:Â Â Â Â 38, |
2946 | Â KEY_RIGHT:Â Â 39, |
2947 | Â KEY_DOWN:Â Â Â 40, |
2948 | Â KEY_DELETE:Â Â 46, |
2949 | Â KEY_HOME:Â Â Â 36, |
2950 | Â KEY_END:Â Â Â 35, |
2951 | Â KEY_PAGEUP:Â Â 33, |
2952 | Â KEY_PAGEDOWN: 34, |
2953 | |
2954 | Â element: function(event) { |
2955 | Â Â return $(event.target || event.srcElement); |
2956 | Â }, |
2957 | |
2958 | Â isLeftClick: function(event) { |
2959 | Â Â return (((event.which) && (event.which == 1)) || |
2960 | Â Â Â Â Â Â ((event.button) && (event.button == 1))); |
2961 | Â }, |
2962 | |
2963 | Â pointerX: function(event) { |
2964 | Â Â return event.pageX || (event.clientX + |
2965 | Â Â Â (document.documentElement.scrollLeft || document.body.scrollLeft)); |
2966 | Â }, |
2967 | |
2968 | Â pointerY: function(event) { |
2969 | Â Â return event.pageY || (event.clientY + |
2970 | Â Â Â (document.documentElement.scrollTop || document.body.scrollTop)); |
2971 | Â }, |
2972 | |
2973 | Â stop: function(event) { |
2974 | Â Â if (event.preventDefault) { |
2975 | Â Â Â event.preventDefault(); |
2976 | Â Â Â event.stopPropagation(); |
2977 | Â Â } else { |
2978 | Â Â Â event.returnValue = false; |
2979 | Â Â Â event.cancelBubble = true; |
2980 | Â Â } |
2981 | Â }, |
2982 | |
2983 | Â // find the first node with the given tagName, starting from the |
2984 | Â // node the event was triggered on; traverses the DOM upwards |
2985 | Â findElement: function(event, tagName) { |
2986 | Â Â var element = Event.element(event); |
2987 | Â Â while (element.parentNode && (!element.tagName || |
2988 | Â Â Â Â (element.tagName.toUpperCase() != tagName.toUpperCase()))) |
2989 | Â Â Â element = element.parentNode; |
2990 | Â Â return element; |
2991 | Â }, |
2992 | |
2993 | Â observers: false, |
2994 | |
2995 | Â _observeAndCache: function(element, name, observer, useCapture) { |
2996 | Â Â if (!this.observers) this.observers = []; |
2997 | Â Â if (element.addEventListener) { |
2998 | Â Â Â this.observers.push([element, name, observer, useCapture]); |
2999 | Â Â Â element.addEventListener(name, observer, useCapture); |
3000 | Â Â } else if (element.attachEvent) { |
3001 | Â Â Â this.observers.push([element, name, observer, useCapture]); |
3002 | Â Â Â element.attachEvent('on' + name, observer); |
3003 | Â Â } |
3004 | Â }, |
3005 | |
3006 | Â unloadCache: function() { |
3007 | Â Â if (!Event.observers) return; |
3008 | Â Â for (var i = 0, length = Event.observers.length; i < length; i++) { |
3009 | Â Â Â Event.stopObserving.apply(this, Event.observers[i]); |
3010 | Â Â Â Event.observers[i][0] = null; |
3011 | Â Â } |
3012 | Â Â Event.observers = false; |
3013 | Â }, |
3014 | |
3015 | Â observe: function(element, name, observer, useCapture) { |
3016 | Â Â element = $(element); |
3017 | Â Â useCapture = useCapture || false; |
3018 | |
3019 | Â Â if (name == 'keypress' && |
3020 | Â Â Â (Prototype.Browser.WebKit || element.attachEvent)) |
3021 | Â Â Â name = 'keydown'; |
3022 | |
3023 | Â Â Event._observeAndCache(element, name, observer, useCapture); |
3024 | Â }, |
3025 | |
3026 | Â stopObserving: function(element, name, observer, useCapture) { |
3027 | Â Â element = $(element); |
3028 | Â Â useCapture = useCapture || false; |
3029 | |
3030 | Â Â if (name == 'keypress' && |
3031 | Â Â Â Â (Prototype.Browser.WebKit || element.attachEvent)) |
3032 | Â Â Â name = 'keydown'; |
3033 | |
3034 | Â Â if (element.removeEventListener) { |
3035 | Â Â Â element.removeEventListener(name, observer, useCapture); |
3036 | Â Â } else if (element.detachEvent) { |
3037 | Â Â Â try { |
3038 | Â Â Â Â element.detachEvent('on' + name, observer); |
3039 | Â Â Â } catch (e) {} |
3040 | Â Â } |
3041 | Â } |
3042 | }); |
3043 | |
3044 | /* prevent memory leaks in IE */ |
3045 | if (Prototype.Browser.IE) |
3046 | Â Event.observe(window, 'unload', Event.unloadCache, false); |
3047 | var Position = { |
3048 | Â // set to true if needed, warning: firefox performance problems |
3049 | Â // NOT neeeded for page scrolling, only if draggable contained in |
3050 | Â // scrollable elements |
3051 | Â includeScrollOffsets: false, |
3052 | |
3053 | Â // must be called before calling withinIncludingScrolloffset, every time the |
3054 | Â // page is scrolled |
3055 | Â prepare: function() { |
3056 | Â Â this.deltaX =Â window.pageXOffset |
3057 | Â Â Â Â Â Â Â Â || document.documentElement.scrollLeft |
3058 | Â Â Â Â Â Â Â Â || document.body.scrollLeft |
3059 | Â Â Â Â Â Â Â Â || 0; |
3060 | Â Â this.deltaY =Â window.pageYOffset |
3061 | Â Â Â Â Â Â Â Â || document.documentElement.scrollTop |
3062 | Â Â Â Â Â Â Â Â || document.body.scrollTop |
3063 | Â Â Â Â Â Â Â Â || 0; |
3064 | Â }, |
3065 | |
3066 | Â realOffset: function(element) { |
3067 | Â Â var valueT = 0, valueL = 0; |
3068 | Â Â do { |
3069 |    valueT += element.scrollTop || 0; |
3070 | Â Â Â valueL += element.scrollLeft || 0; |
3071 | Â Â Â element = element.parentNode; |
3072 | Â Â } while (element); |
3073 | Â Â return [valueL, valueT]; |
3074 | Â }, |
3075 | |
3076 | Â cumulativeOffset: function(element) { |
3077 | Â Â var valueT = 0, valueL = 0; |
3078 | Â Â do { |
3079 |    valueT += element.offsetTop || 0; |
3080 | Â Â Â valueL += element.offsetLeft || 0; |
3081 | Â Â Â element = element.offsetParent; |
3082 | Â Â } while (element); |
3083 | Â Â return [valueL, valueT]; |
3084 | Â }, |
3085 | |
3086 | Â positionedOffset: function(element) { |
3087 | Â Â var valueT = 0, valueL = 0; |
3088 | Â Â do { |
3089 |    valueT += element.offsetTop || 0; |
3090 | Â Â Â valueL += element.offsetLeft || 0; |
3091 | Â Â Â element = element.offsetParent; |
3092 | Â Â Â if (element) { |
3093 | Â Â Â Â if(element.tagName=='BODY') break; |
3094 | Â Â Â Â var p = Element.getStyle(element, 'position'); |
3095 | Â Â Â Â if (p == 'relative' || p == 'absolute') break; |
3096 | Â Â Â } |
3097 | Â Â } while (element); |
3098 | Â Â return [valueL, valueT]; |
3099 | Â }, |
3100 | |
3101 | Â offsetParent: function(element) { |
3102 | Â Â if (element.offsetParent) return element.offsetParent; |
3103 | Â Â if (element == document.body) return element; |
3104 | |
3105 | Â Â while ((element = element.parentNode) && element != document.body) |
3106 | Â Â Â if (Element.getStyle(element, 'position') != 'static') |
3107 | Â Â Â Â return element; |
3108 | |
3109 | Â Â return document.body; |
3110 | Â }, |
3111 | |
3112 | Â // caches x/y coordinate pair to use with overlap |
3113 | Â within: function(element, x, y) { |
3114 | Â Â if (this.includeScrollOffsets) |
3115 | Â Â Â return this.withinIncludingScrolloffsets(element, x, y); |
3116 | Â Â this.xcomp = x; |
3117 | Â Â this.ycomp = y; |
3118 | Â Â this.offset = this.cumulativeOffset(element); |
3119 | |
3120 | Â Â return (y >= this.offset[1] && |
3121 | Â Â Â Â Â Â y <Â this.offset[1] + element.offsetHeight && |
3122 | Â Â Â Â Â Â x >= this.offset[0] && |
3123 | Â Â Â Â Â Â x <Â this.offset[0] + element.offsetWidth); |
3124 | Â }, |
3125 | |
3126 | Â withinIncludingScrolloffsets: function(element, x, y) { |
3127 | Â Â var offsetcache = this.realOffset(element); |
3128 | |
3129 | Â Â this.xcomp = x + offsetcache[0] - this.deltaX; |
3130 | Â Â this.ycomp = y + offsetcache[1] - this.deltaY; |
3131 | Â Â this.offset = this.cumulativeOffset(element); |
3132 | |
3133 | Â Â return (this.ycomp >= this.offset[1] && |
3134 | Â Â Â Â Â Â this.ycomp <Â this.offset[1] + element.offsetHeight && |
3135 | Â Â Â Â Â Â this.xcomp >= this.offset[0] && |
3136 | Â Â Â Â Â Â this.xcomp <Â this.offset[0] + element.offsetWidth); |
3137 | Â }, |
3138 | |
3139 | Â // within must be called directly before |
3140 | Â overlap: function(mode, element) { |
3141 | Â Â if (!mode) return 0; |
3142 | Â Â if (mode == 'vertical') |
3143 | Â Â Â return ((this.offset[1] + element.offsetHeight) - this.ycomp) / |
3144 | Â Â Â Â element.offsetHeight; |
3145 | Â Â if (mode == 'horizontal') |
3146 | Â Â Â return ((this.offset[0] + element.offsetWidth) - this.xcomp) / |
3147 | Â Â Â Â element.offsetWidth; |
3148 | Â }, |
3149 | |
3150 | Â page: function(forElement) { |
3151 | Â Â var valueT = 0, valueL = 0; |
3152 | |
3153 | Â Â var element = forElement; |
3154 | Â Â do { |
3155 |    valueT += element.offsetTop || 0; |
3156 | Â Â Â valueL += element.offsetLeft || 0; |
3157 | |
3158 | Â Â Â // Safari fix |
3159 | Â Â Â if (element.offsetParent == document.body) |
3160 | Â Â Â Â if (Element.getStyle(element,'position')=='absolute') break; |
3161 | |
3162 | Â Â } while (element = element.offsetParent); |
3163 | |
3164 | Â Â element = forElement; |
3165 | Â Â do { |
3166 | Â Â Â if (!window.opera || element.tagName=='BODY') { |
3167 |     valueT -= element.scrollTop || 0; |
3168 | Â Â Â Â valueL -= element.scrollLeft || 0; |
3169 | Â Â Â } |
3170 | Â Â } while (element = element.parentNode); |
3171 | |
3172 | Â Â return [valueL, valueT]; |
3173 | Â }, |
3174 | |
3175 | Â clone: function(source, target) { |
3176 | Â Â var options = Object.extend({ |
3177 | Â Â Â setLeft:Â Â true, |
3178 | Â Â Â setTop:Â Â Â true, |
3179 | Â Â Â setWidth:Â Â true, |
3180 | Â Â Â setHeight:Â true, |
3181 | Â Â Â offsetTop:Â 0, |
3182 | Â Â Â offsetLeft: 0 |
3183 | Â Â }, arguments[2] || {}) |
3184 | |
3185 | Â Â // find page position of source |
3186 | Â Â source = $(source); |
3187 | Â Â var p = Position.page(source); |
3188 | |
3189 | Â Â // find coordinate system to use |
3190 | Â Â target = $(target); |
3191 | Â Â var delta = [0, 0]; |
3192 | Â Â var parent = null; |
3193 | Â Â // delta [0,0] will do fine with position: fixed elements, |
3194 | Â Â // position:absolute needs offsetParent deltas |
3195 | Â Â if (Element.getStyle(target,'position') == 'absolute') { |
3196 | Â Â Â parent = Position.offsetParent(target); |
3197 | Â Â Â delta = Position.page(parent); |
3198 | Â Â } |
3199 | |
3200 | Â Â // correct by body offsets (fixes Safari) |
3201 | Â Â if (parent == document.body) { |
3202 | Â Â Â delta[0] -= document.body.offsetLeft; |
3203 | Â Â Â delta[1] -= document.body.offsetTop; |
3204 | Â Â } |
3205 | |
3206 | Â Â // set position |
3207 |   if(options.setLeft)  target.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px'; |
3208 |   if(options.setTop)  target.style.top  = (p[1] - delta[1] + options.offsetTop) + 'px'; |
3209 | Â Â if(options.setWidth)Â target.style.width = source.offsetWidth + 'px'; |
3210 | Â Â if(options.setHeight) target.style.height = source.offsetHeight + 'px'; |
3211 | Â }, |
3212 | |
3213 | Â absolutize: function(element) { |
3214 | Â Â element = $(element); |
3215 | Â Â if (element.style.position == 'absolute') return; |
3216 | Â Â Position.prepare(); |
3217 | |
3218 | Â Â var offsets = Position.positionedOffset(element); |
3219 |   var top   = offsets[1]; |
3220 |   var left  = offsets[0]; |
3221 |   var width  = element.clientWidth; |
3222 |   var height = element.clientHeight; |
3223 | |
3224 |   element._originalLeft  = left - parseFloat(element.style.left || 0); |
3225 |   element._originalTop  = top - parseFloat(element.style.top || 0); |
3226 |   element._originalWidth = element.style.width; |
3227 | Â Â element._originalHeight = element.style.height; |
3228 | |
3229 | Â Â element.style.position = 'absolute'; |
3230 |   element.style.top  = top + 'px'; |
3231 |   element.style.left  = left + 'px'; |
3232 |   element.style.width = width + 'px'; |
3233 | Â Â element.style.height = height + 'px'; |
3234 | Â }, |
3235 | |
3236 | Â relativize: function(element) { |
3237 | Â Â element = $(element); |
3238 | Â Â if (element.style.position == 'relative') return; |
3239 | Â Â Position.prepare(); |
3240 | |
3241 | Â Â element.style.position = 'relative'; |
3242 |   var top = parseFloat(element.style.top || 0) - (element._originalTop || 0); |
3243 | Â Â var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0); |
3244 | |
3245 |   element.style.top  = top + 'px'; |
3246 |   element.style.left  = left + 'px'; |
3247 | Â Â element.style.height = element._originalHeight; |
3248 |   element.style.width = element._originalWidth; |
3249 | Â } |
3250 | } |
3251 | |
3252 | // Safari returns margins on body which is incorrect if the child is absolutely |
3253 | // positioned. For performance reasons, redefine Position.cumulativeOffset for |
3254 | // KHTML/WebKit only. |
3255 | if (Prototype.Browser.WebKit) { |
3256 | Â Position.cumulativeOffset = function(element) { |
3257 | Â Â var valueT = 0, valueL = 0; |
3258 | Â Â do { |
3259 |    valueT += element.offsetTop || 0; |
3260 | Â Â Â valueL += element.offsetLeft || 0; |
3261 | Â Â Â if (element.offsetParent == document.body) |
3262 | Â Â Â Â if (Element.getStyle(element, 'position') == 'absolute') break; |
3263 | |
3264 | Â Â Â element = element.offsetParent; |
3265 | Â Â } while (element); |
3266 | |
3267 | Â Â return [valueL, valueT]; |
3268 | Â } |
3269 | } |
3270 | |
3271 | Element.addMethods(); |