+++ /dev/null
-/* Prototype JavaScript framework, version 1.6.0.2\r
- * (c) 2005-2008 Sam Stephenson\r
- *\r
- * Prototype is freely distributable under the terms of an MIT-style license.\r
- * For details, see the Prototype web site: http://www.prototypejs.org/\r
- *\r
- *--------------------------------------------------------------------------*/\r
-\r
-var Prototype = {\r
- Version: '1.6.0.2',\r
-\r
- Browser: {\r
- IE: !!(window.attachEvent && !window.opera),\r
- Opera: !!window.opera,\r
- WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,\r
- Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,\r
- MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)\r
- },\r
-\r
- BrowserFeatures: {\r
- XPath: !!document.evaluate,\r
- ElementExtensions: !!window.HTMLElement,\r
- SpecificElementExtensions:\r
- document.createElement('div').__proto__ &&\r
- document.createElement('div').__proto__ !==\r
- document.createElement('form').__proto__\r
- },\r
-\r
- ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',\r
- JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,\r
-\r
- emptyFunction: function() { },\r
- K: function(x) { return x }\r
-};\r
-\r
-if (Prototype.Browser.MobileSafari)\r
- Prototype.BrowserFeatures.SpecificElementExtensions = false;\r
-\r
-\r
-/* Based on Alex Arnell's inheritance implementation. */\r
-var Class = {\r
- create: function() {\r
- var parent = null, properties = $A(arguments);\r
- if (Object.isFunction(properties[0]))\r
- parent = properties.shift();\r
-\r
- function klass() {\r
- this.initialize.apply(this, arguments);\r
- }\r
-\r
- Object.extend(klass, Class.Methods);\r
- klass.superclass = parent;\r
- klass.subclasses = [];\r
-\r
- if (parent) {\r
- var subclass = function() { };\r
- subclass.prototype = parent.prototype;\r
- klass.prototype = new subclass;\r
- parent.subclasses.push(klass);\r
- }\r
-\r
- for (var i = 0; i < properties.length; i++)\r
- klass.addMethods(properties[i]);\r
-\r
- if (!klass.prototype.initialize)\r
- klass.prototype.initialize = Prototype.emptyFunction;\r
-\r
- klass.prototype.constructor = klass;\r
-\r
- return klass;\r
- }\r
-};\r
-\r
-Class.Methods = {\r
- addMethods: function(source) {\r
- var ancestor = this.superclass && this.superclass.prototype;\r
- var properties = Object.keys(source);\r
-\r
- if (!Object.keys({ toString: true }).length)\r
- properties.push("toString", "valueOf");\r
-\r
- for (var i = 0, length = properties.length; i < length; i++) {\r
- var property = properties[i], value = source[property];\r
- if (ancestor && Object.isFunction(value) &&\r
- value.argumentNames().first() == "$super") {\r
- var method = value, value = Object.extend((function(m) {\r
- return function() { return ancestor[m].apply(this, arguments) };\r
- })(property).wrap(method), {\r
- valueOf: function() { return method },\r
- toString: function() { return method.toString() }\r
- });\r
- }\r
- this.prototype[property] = value;\r
- }\r
-\r
- return this;\r
- }\r
-};\r
-\r
-var Abstract = { };\r
-\r
-Object.extend = function(destination, source) {\r
- for (var property in source)\r
- destination[property] = source[property];\r
- return destination;\r
-};\r
-\r
-Object.extend(Object, {\r
- inspect: function(object) {\r
- try {\r
- if (Object.isUndefined(object)) return 'undefined';\r
- if (object === null) return 'null';\r
- return object.inspect ? object.inspect() : String(object);\r
- } catch (e) {\r
- if (e instanceof RangeError) return '...';\r
- throw e;\r
- }\r
- },\r
-\r
- toJSON: function(object) {\r
- var type = typeof object;\r
- switch (type) {\r
- case 'undefined':\r
- case 'function':\r
- case 'unknown': return;\r
- case 'boolean': return object.toString();\r
- }\r
-\r
- if (object === null) return 'null';\r
- if (object.toJSON) return object.toJSON();\r
- if (Object.isElement(object)) return;\r
-\r
- var results = [];\r
- for (var property in object) {\r
- var value = Object.toJSON(object[property]);\r
- if (!Object.isUndefined(value))\r
- results.push(property.toJSON() + ': ' + value);\r
- }\r
-\r
- return '{' + results.join(', ') + '}';\r
- },\r
-\r
- toQueryString: function(object) {\r
- return $H(object).toQueryString();\r
- },\r
-\r
- toHTML: function(object) {\r
- return object && object.toHTML ? object.toHTML() : String.interpret(object);\r
- },\r
-\r
- keys: function(object) {\r
- var keys = [];\r
- for (var property in object)\r
- keys.push(property);\r
- return keys;\r
- },\r
-\r
- values: function(object) {\r
- var values = [];\r
- for (var property in object)\r
- values.push(object[property]);\r
- return values;\r
- },\r
-\r
- clone: function(object) {\r
- return Object.extend({ }, object);\r
- },\r
-\r
- isElement: function(object) {\r
- return object && object.nodeType == 1;\r
- },\r
-\r
- isArray: function(object) {\r
- return object != null && typeof object == "object" &&\r
- 'splice' in object && 'join' in object;\r
- },\r
-\r
- isHash: function(object) {\r
- return object instanceof Hash;\r
- },\r
-\r
- isFunction: function(object) {\r
- return typeof object == "function";\r
- },\r
-\r
- isString: function(object) {\r
- return typeof object == "string";\r
- },\r
-\r
- isNumber: function(object) {\r
- return typeof object == "number";\r
- },\r
-\r
- isUndefined: function(object) {\r
- return typeof object == "undefined";\r
- }\r
-});\r
-\r
-Object.extend(Function.prototype, {\r
- argumentNames: function() {\r
- var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip");\r
- return names.length == 1 && !names[0] ? [] : names;\r
- },\r
-\r
- bind: function() {\r
- if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;\r
- var __method = this, args = $A(arguments), object = args.shift();\r
- return function() {\r
- return __method.apply(object, args.concat($A(arguments)));\r
- }\r
- },\r
-\r
- bindAsEventListener: function() {\r
- var __method = this, args = $A(arguments), object = args.shift();\r
- return function(event) {\r
- return __method.apply(object, [event || window.event].concat(args));\r
- }\r
- },\r
-\r
- curry: function() {\r
- if (!arguments.length) return this;\r
- var __method = this, args = $A(arguments);\r
- return function() {\r
- return __method.apply(this, args.concat($A(arguments)));\r
- }\r
- },\r
-\r
- delay: function() {\r
- var __method = this, args = $A(arguments), timeout = args.shift() * 1000;\r
- return window.setTimeout(function() {\r
- return __method.apply(__method, args);\r
- }, timeout);\r
- },\r
-\r
- wrap: function(wrapper) {\r
- var __method = this;\r
- return function() {\r
- return wrapper.apply(this, [__method.bind(this)].concat($A(arguments)));\r
- }\r
- },\r
-\r
- methodize: function() {\r
- if (this._methodized) return this._methodized;\r
- var __method = this;\r
- return this._methodized = function() {\r
- return __method.apply(null, [this].concat($A(arguments)));\r
- };\r
- }\r
-});\r
-\r
-Function.prototype.defer = Function.prototype.delay.curry(0.01);\r
-\r
-Date.prototype.toJSON = function() {\r
- return '"' + this.getUTCFullYear() + '-' +\r
- (this.getUTCMonth() + 1).toPaddedString(2) + '-' +\r
- this.getUTCDate().toPaddedString(2) + 'T' +\r
- this.getUTCHours().toPaddedString(2) + ':' +\r
- this.getUTCMinutes().toPaddedString(2) + ':' +\r
- this.getUTCSeconds().toPaddedString(2) + 'Z"';\r
-};\r
-\r
-var Try = {\r
- these: function() {\r
- var returnValue;\r
-\r
- for (var i = 0, length = arguments.length; i < length; i++) {\r
- var lambda = arguments[i];\r
- try {\r
- returnValue = lambda();\r
- break;\r
- } catch (e) { }\r
- }\r
-\r
- return returnValue;\r
- }\r
-};\r
-\r
-RegExp.prototype.match = RegExp.prototype.test;\r
-\r
-RegExp.escape = function(str) {\r
- return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');\r
-};\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-var PeriodicalExecuter = Class.create({\r
- initialize: function(callback, frequency) {\r
- this.callback = callback;\r
- this.frequency = frequency;\r
- this.currentlyExecuting = false;\r
-\r
- this.registerCallback();\r
- },\r
-\r
- registerCallback: function() {\r
- this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);\r
- },\r
-\r
- execute: function() {\r
- this.callback(this);\r
- },\r
-\r
- stop: function() {\r
- if (!this.timer) return;\r
- clearInterval(this.timer);\r
- this.timer = null;\r
- },\r
-\r
- onTimerEvent: function() {\r
- if (!this.currentlyExecuting) {\r
- try {\r
- this.currentlyExecuting = true;\r
- this.execute();\r
- } finally {\r
- this.currentlyExecuting = false;\r
- }\r
- }\r
- }\r
-});\r
-Object.extend(String, {\r
- interpret: function(value) {\r
- return value == null ? '' : String(value);\r
- },\r
- specialChar: {\r
- '\b': '\\b',\r
- '\t': '\\t',\r
- '\n': '\\n',\r
- '\f': '\\f',\r
- '\r': '\\r',\r
- '\\': '\\\\'\r
- }\r
-});\r
-\r
-Object.extend(String.prototype, {\r
- gsub: function(pattern, replacement) {\r
- var result = '', source = this, match;\r
- replacement = arguments.callee.prepareReplacement(replacement);\r
-\r
- while (source.length > 0) {\r
- if (match = source.match(pattern)) {\r
- result += source.slice(0, match.index);\r
- result += String.interpret(replacement(match));\r
- source = source.slice(match.index + match[0].length);\r
- } else {\r
- result += source, source = '';\r
- }\r
- }\r
- return result;\r
- },\r
-\r
- sub: function(pattern, replacement, count) {\r
- replacement = this.gsub.prepareReplacement(replacement);\r
- count = Object.isUndefined(count) ? 1 : count;\r
-\r
- return this.gsub(pattern, function(match) {\r
- if (--count < 0) return match[0];\r
- return replacement(match);\r
- });\r
- },\r
-\r
- scan: function(pattern, iterator) {\r
- this.gsub(pattern, iterator);\r
- return String(this);\r
- },\r
-\r
- truncate: function(length, truncation) {\r
- length = length || 30;\r
- truncation = Object.isUndefined(truncation) ? '...' : truncation;\r
- return this.length > length ?\r
- this.slice(0, length - truncation.length) + truncation : String(this);\r
- },\r
-\r
- strip: function() {\r
- return this.replace(/^\s+/, '').replace(/\s+$/, '');\r
- },\r
-\r
- stripTags: function() {\r
- return this.replace(/<\/?[^>]+>/gi, '');\r
- },\r
-\r
- stripScripts: function() {\r
- return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');\r
- },\r
-\r
- extractScripts: function() {\r
- var matchAll = new RegExp(Prototype.ScriptFragment, 'img');\r
- var matchOne = new RegExp(Prototype.ScriptFragment, 'im');\r
- return (this.match(matchAll) || []).map(function(scriptTag) {\r
- return (scriptTag.match(matchOne) || ['', ''])[1];\r
- });\r
- },\r
-\r
- evalScripts: function() {\r
- return this.extractScripts().map(function(script) { return eval(script) });\r
- },\r
-\r
- escapeHTML: function() {\r
- var self = arguments.callee;\r
- self.text.data = this;\r
- return self.div.innerHTML;\r
- },\r
-\r
- unescapeHTML: function() {\r
- var div = new Element('div');\r
- div.innerHTML = this.stripTags();\r
- return div.childNodes[0] ? (div.childNodes.length > 1 ?\r
- $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) :\r
- div.childNodes[0].nodeValue) : '';\r
- },\r
-\r
- toQueryParams: function(separator) {\r
- var match = this.strip().match(/([^?#]*)(#.*)?$/);\r
- if (!match) return { };\r
-\r
- return match[1].split(separator || '&').inject({ }, function(hash, pair) {\r
- if ((pair = pair.split('='))[0]) {\r
- var key = decodeURIComponent(pair.shift());\r
- var value = pair.length > 1 ? pair.join('=') : pair[0];\r
- if (value != undefined) value = decodeURIComponent(value);\r
-\r
- if (key in hash) {\r
- if (!Object.isArray(hash[key])) hash[key] = [hash[key]];\r
- hash[key].push(value);\r
- }\r
- else hash[key] = value;\r
- }\r
- return hash;\r
- });\r
- },\r
-\r
- toArray: function() {\r
- return this.split('');\r
- },\r
-\r
- succ: function() {\r
- return this.slice(0, this.length - 1) +\r
- String.fromCharCode(this.charCodeAt(this.length - 1) + 1);\r
- },\r
-\r
- times: function(count) {\r
- return count < 1 ? '' : new Array(count + 1).join(this);\r
- },\r
-\r
- camelize: function() {\r
- var parts = this.split('-'), len = parts.length;\r
- if (len == 1) return parts[0];\r
-\r
- var camelized = this.charAt(0) == '-'\r
- ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)\r
- : parts[0];\r
-\r
- for (var i = 1; i < len; i++)\r
- camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);\r
-\r
- return camelized;\r
- },\r
-\r
- capitalize: function() {\r
- return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();\r
- },\r
-\r
- underscore: function() {\r
- return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();\r
- },\r
-\r
- dasherize: function() {\r
- return this.gsub(/_/,'-');\r
- },\r
-\r
- inspect: function(useDoubleQuotes) {\r
- var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) {\r
- var character = String.specialChar[match[0]];\r
- return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);\r
- });\r
- if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';\r
- return "'" + escapedString.replace(/'/g, '\\\'') + "'";\r
- },\r
-\r
- toJSON: function() {\r
- return this.inspect(true);\r
- },\r
-\r
- unfilterJSON: function(filter) {\r
- return this.sub(filter || Prototype.JSONFilter, '#{1}');\r
- },\r
-\r
- isJSON: function() {\r
- var str = this;\r
- if (str.blank()) return false;\r
- str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');\r
- return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);\r
- },\r
-\r
- evalJSON: function(sanitize) {\r
- var json = this.unfilterJSON();\r
- try {\r
- if (!sanitize || json.isJSON()) return eval('(' + json + ')');\r
- } catch (e) { }\r
- throw new SyntaxError('Badly formed JSON string: ' + this.inspect());\r
- },\r
-\r
- include: function(pattern) {\r
- return this.indexOf(pattern) > -1;\r
- },\r
-\r
- startsWith: function(pattern) {\r
- return this.indexOf(pattern) === 0;\r
- },\r
-\r
- endsWith: function(pattern) {\r
- var d = this.length - pattern.length;\r
- return d >= 0 && this.lastIndexOf(pattern) === d;\r
- },\r
-\r
- empty: function() {\r
- return this == '';\r
- },\r
-\r
- blank: function() {\r
- return /^\s*$/.test(this);\r
- },\r
-\r
- interpolate: function(object, pattern) {\r
- return new Template(this, pattern).evaluate(object);\r
- }\r
-});\r
-\r
-if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {\r
- escapeHTML: function() {\r
- return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');\r
- },\r
- unescapeHTML: function() {\r
- return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');\r
- }\r
-});\r
-\r
-String.prototype.gsub.prepareReplacement = function(replacement) {\r
- if (Object.isFunction(replacement)) return replacement;\r
- var template = new Template(replacement);\r
- return function(match) { return template.evaluate(match) };\r
-};\r
-\r
-String.prototype.parseQuery = String.prototype.toQueryParams;\r
-\r
-Object.extend(String.prototype.escapeHTML, {\r
- div: document.createElement('div'),\r
- text: document.createTextNode('')\r
-});\r
-\r
-with (String.prototype.escapeHTML) div.appendChild(text);\r
-\r
-var Template = Class.create({\r
- initialize: function(template, pattern) {\r
- this.template = template.toString();\r
- this.pattern = pattern || Template.Pattern;\r
- },\r
-\r
- evaluate: function(object) {\r
- if (Object.isFunction(object.toTemplateReplacements))\r
- object = object.toTemplateReplacements();\r
-\r
- return this.template.gsub(this.pattern, function(match) {\r
- if (object == null) return '';\r
-\r
- var before = match[1] || '';\r
- if (before == '\\') return match[2];\r
-\r
- var ctx = object, expr = match[3];\r
- var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;\r
- match = pattern.exec(expr);\r
- if (match == null) return before;\r
-\r
- while (match != null) {\r
- var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1];\r
- ctx = ctx[comp];\r
- if (null == ctx || '' == match[3]) break;\r
- expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);\r
- match = pattern.exec(expr);\r
- }\r
-\r
- return before + String.interpret(ctx);\r
- });\r
- }\r
-});\r
-Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;\r
-\r
-var $break = { };\r
-\r
-var Enumerable = {\r
- each: function(iterator, context) {\r
- var index = 0;\r
- iterator = iterator.bind(context);\r
- try {\r
- this._each(function(value) {\r
- iterator(value, index++);\r
- });\r
- } catch (e) {\r
- if (e != $break) throw e;\r
- }\r
- return this;\r
- },\r
-\r
- eachSlice: function(number, iterator, context) {\r
- iterator = iterator ? iterator.bind(context) : Prototype.K;\r
- var index = -number, slices = [], array = this.toArray();\r
- while ((index += number) < array.length)\r
- slices.push(array.slice(index, index+number));\r
- return slices.collect(iterator, context);\r
- },\r
-\r
- all: function(iterator, context) {\r
- iterator = iterator ? iterator.bind(context) : Prototype.K;\r
- var result = true;\r
- this.each(function(value, index) {\r
- result = result && !!iterator(value, index);\r
- if (!result) throw $break;\r
- });\r
- return result;\r
- },\r
-\r
- any: function(iterator, context) {\r
- iterator = iterator ? iterator.bind(context) : Prototype.K;\r
- var result = false;\r
- this.each(function(value, index) {\r
- if (result = !!iterator(value, index))\r
- throw $break;\r
- });\r
- return result;\r
- },\r
-\r
- collect: function(iterator, context) {\r
- iterator = iterator ? iterator.bind(context) : Prototype.K;\r
- var results = [];\r
- this.each(function(value, index) {\r
- results.push(iterator(value, index));\r
- });\r
- return results;\r
- },\r
-\r
- detect: function(iterator, context) {\r
- iterator = iterator.bind(context);\r
- var result;\r
- this.each(function(value, index) {\r
- if (iterator(value, index)) {\r
- result = value;\r
- throw $break;\r
- }\r
- });\r
- return result;\r
- },\r
-\r
- findAll: function(iterator, context) {\r
- iterator = iterator.bind(context);\r
- var results = [];\r
- this.each(function(value, index) {\r
- if (iterator(value, index))\r
- results.push(value);\r
- });\r
- return results;\r
- },\r
-\r
- grep: function(filter, iterator, context) {\r
- iterator = iterator ? iterator.bind(context) : Prototype.K;\r
- var results = [];\r
-\r
- if (Object.isString(filter))\r
- filter = new RegExp(filter);\r
-\r
- this.each(function(value, index) {\r
- if (filter.match(value))\r
- results.push(iterator(value, index));\r
- });\r
- return results;\r
- },\r
-\r
- include: function(object) {\r
- if (Object.isFunction(this.indexOf))\r
- if (this.indexOf(object) != -1) return true;\r
-\r
- var found = false;\r
- this.each(function(value) {\r
- if (value == object) {\r
- found = true;\r
- throw $break;\r
- }\r
- });\r
- return found;\r
- },\r
-\r
- inGroupsOf: function(number, fillWith) {\r
- fillWith = Object.isUndefined(fillWith) ? null : fillWith;\r
- return this.eachSlice(number, function(slice) {\r
- while(slice.length < number) slice.push(fillWith);\r
- return slice;\r
- });\r
- },\r
-\r
- inject: function(memo, iterator, context) {\r
- iterator = iterator.bind(context);\r
- this.each(function(value, index) {\r
- memo = iterator(memo, value, index);\r
- });\r
- return memo;\r
- },\r
-\r
- invoke: function(method) {\r
- var args = $A(arguments).slice(1);\r
- return this.map(function(value) {\r
- return value[method].apply(value, args);\r
- });\r
- },\r
-\r
- max: function(iterator, context) {\r
- iterator = iterator ? iterator.bind(context) : Prototype.K;\r
- var result;\r
- this.each(function(value, index) {\r
- value = iterator(value, index);\r
- if (result == null || value >= result)\r
- result = value;\r
- });\r
- return result;\r
- },\r
-\r
- min: function(iterator, context) {\r
- iterator = iterator ? iterator.bind(context) : Prototype.K;\r
- var result;\r
- this.each(function(value, index) {\r
- value = iterator(value, index);\r
- if (result == null || value < result)\r
- result = value;\r
- });\r
- return result;\r
- },\r
-\r
- partition: function(iterator, context) {\r
- iterator = iterator ? iterator.bind(context) : Prototype.K;\r
- var trues = [], falses = [];\r
- this.each(function(value, index) {\r
- (iterator(value, index) ?\r
- trues : falses).push(value);\r
- });\r
- return [trues, falses];\r
- },\r
-\r
- pluck: function(property) {\r
- var results = [];\r
- this.each(function(value) {\r
- results.push(value[property]);\r
- });\r
- return results;\r
- },\r
-\r
- reject: function(iterator, context) {\r
- iterator = iterator.bind(context);\r
- var results = [];\r
- this.each(function(value, index) {\r
- if (!iterator(value, index))\r
- results.push(value);\r
- });\r
- return results;\r
- },\r
-\r
- sortBy: function(iterator, context) {\r
- iterator = iterator.bind(context);\r
- return this.map(function(value, index) {\r
- return {value: value, criteria: iterator(value, index)};\r
- }).sort(function(left, right) {\r
- var a = left.criteria, b = right.criteria;\r
- return a < b ? -1 : a > b ? 1 : 0;\r
- }).pluck('value');\r
- },\r
-\r
- toArray: function() {\r
- return this.map();\r
- },\r
-\r
- zip: function() {\r
- var iterator = Prototype.K, args = $A(arguments);\r
- if (Object.isFunction(args.last()))\r
- iterator = args.pop();\r
-\r
- var collections = [this].concat(args).map($A);\r
- return this.map(function(value, index) {\r
- return iterator(collections.pluck(index));\r
- });\r
- },\r
-\r
- size: function() {\r
- return this.toArray().length;\r
- },\r
-\r
- inspect: function() {\r
- return '#<Enumerable:' + this.toArray().inspect() + '>';\r
- }\r
-};\r
-\r
-Object.extend(Enumerable, {\r
- map: Enumerable.collect,\r
- find: Enumerable.detect,\r
- select: Enumerable.findAll,\r
- filter: Enumerable.findAll,\r
- member: Enumerable.include,\r
- entries: Enumerable.toArray,\r
- every: Enumerable.all,\r
- some: Enumerable.any\r
-});\r
-function $A(iterable) {\r
- if (!iterable) return [];\r
- if (iterable.toArray) return iterable.toArray();\r
- var length = iterable.length || 0, results = new Array(length);\r
- while (length--) results[length] = iterable[length];\r
- return results;\r
-}\r
-\r
-if (Prototype.Browser.WebKit) {\r
- $A = function(iterable) {\r
- if (!iterable) return [];\r
- if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') &&\r
- iterable.toArray) return iterable.toArray();\r
- var length = iterable.length || 0, results = new Array(length);\r
- while (length--) results[length] = iterable[length];\r
- return results;\r
- };\r
-}\r
-\r
-Array.from = $A;\r
-\r
-Object.extend(Array.prototype, Enumerable);\r
-\r
-if (!Array.prototype._reverse) Array.prototype._reverse = Array.prototype.reverse;\r
-\r
-Object.extend(Array.prototype, {\r
- _each: function(iterator) {\r
- for (var i = 0, length = this.length; i < length; i++)\r
- iterator(this[i]);\r
- },\r
-\r
- clear: function() {\r
- this.length = 0;\r
- return this;\r
- },\r
-\r
- first: function() {\r
- return this[0];\r
- },\r
-\r
- last: function() {\r
- return this[this.length - 1];\r
- },\r
-\r
- compact: function() {\r
- return this.select(function(value) {\r
- return value != null;\r
- });\r
- },\r
-\r
- flatten: function() {\r
- return this.inject([], function(array, value) {\r
- return array.concat(Object.isArray(value) ?\r
- value.flatten() : [value]);\r
- });\r
- },\r
-\r
- without: function() {\r
- var values = $A(arguments);\r
- return this.select(function(value) {\r
- return !values.include(value);\r
- });\r
- },\r
-\r
- reverse: function(inline) {\r
- return (inline !== false ? this : this.toArray())._reverse();\r
- },\r
-\r
- reduce: function() {\r
- return this.length > 1 ? this : this[0];\r
- },\r
-\r
- uniq: function(sorted) {\r
- return this.inject([], function(array, value, index) {\r
- if (0 == index || (sorted ? array.last() != value : !array.include(value)))\r
- array.push(value);\r
- return array;\r
- });\r
- },\r
-\r
- intersect: function(array) {\r
- return this.uniq().findAll(function(item) {\r
- return array.detect(function(value) { return item === value });\r
- });\r
- },\r
-\r
- clone: function() {\r
- return [].concat(this);\r
- },\r
-\r
- size: function() {\r
- return this.length;\r
- },\r
-\r
- inspect: function() {\r
- return '[' + this.map(Object.inspect).join(', ') + ']';\r
- },\r
-\r
- toJSON: function() {\r
- var results = [];\r
- this.each(function(object) {\r
- var value = Object.toJSON(object);\r
- if (!Object.isUndefined(value)) results.push(value);\r
- });\r
- return '[' + results.join(', ') + ']';\r
- }\r
-});\r
-\r
-// use native browser JS 1.6 implementation if available\r
-if (Object.isFunction(Array.prototype.forEach))\r
- Array.prototype._each = Array.prototype.forEach;\r
-\r
-if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) {\r
- i || (i = 0);\r
- var length = this.length;\r
- if (i < 0) i = length + i;\r
- for (; i < length; i++)\r
- if (this[i] === item) return i;\r
- return -1;\r
-};\r
-\r
-if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i) {\r
- i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;\r
- var n = this.slice(0, i).reverse().indexOf(item);\r
- return (n < 0) ? n : i - n - 1;\r
-};\r
-\r
-Array.prototype.toArray = Array.prototype.clone;\r
-\r
-function $w(string) {\r
- if (!Object.isString(string)) return [];\r
- string = string.strip();\r
- return string ? string.split(/\s+/) : [];\r
-}\r
-\r
-if (Prototype.Browser.Opera){\r
- Array.prototype.concat = function() {\r
- var array = [];\r
- for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);\r
- for (var i = 0, length = arguments.length; i < length; i++) {\r
- if (Object.isArray(arguments[i])) {\r
- for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)\r
- array.push(arguments[i][j]);\r
- } else {\r
- array.push(arguments[i]);\r
- }\r
- }\r
- return array;\r
- };\r
-}\r
-Object.extend(Number.prototype, {\r
- toColorPart: function() {\r
- return this.toPaddedString(2, 16);\r
- },\r
-\r
- succ: function() {\r
- return this + 1;\r
- },\r
-\r
- times: function(iterator) {\r
- $R(0, this, true).each(iterator);\r
- return this;\r
- },\r
-\r
- toPaddedString: function(length, radix) {\r
- var string = this.toString(radix || 10);\r
- return '0'.times(length - string.length) + string;\r
- },\r
-\r
- toJSON: function() {\r
- return isFinite(this) ? this.toString() : 'null';\r
- }\r
-});\r
-\r
-$w('abs round ceil floor').each(function(method){\r
- Number.prototype[method] = Math[method].methodize();\r
-});\r
-function $H(object) {\r
- return new Hash(object);\r
-};\r
-\r
-var Hash = Class.create(Enumerable, (function() {\r
-\r
- function toQueryPair(key, value) {\r
- if (Object.isUndefined(value)) return key;\r
- return key + '=' + encodeURIComponent(String.interpret(value));\r
- }\r
-\r
- return {\r
- initialize: function(object) {\r
- this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);\r
- },\r
-\r
- _each: function(iterator) {\r
- for (var key in this._object) {\r
- var value = this._object[key], pair = [key, value];\r
- pair.key = key;\r
- pair.value = value;\r
- iterator(pair);\r
- }\r
- },\r
-\r
- set: function(key, value) {\r
- return this._object[key] = value;\r
- },\r
-\r
- get: function(key) {\r
- return this._object[key];\r
- },\r
-\r
- unset: function(key) {\r
- var value = this._object[key];\r
- delete this._object[key];\r
- return value;\r
- },\r
-\r
- toObject: function() {\r
- return Object.clone(this._object);\r
- },\r
-\r
- keys: function() {\r
- return this.pluck('key');\r
- },\r
-\r
- values: function() {\r
- return this.pluck('value');\r
- },\r
-\r
- index: function(value) {\r
- var match = this.detect(function(pair) {\r
- return pair.value === value;\r
- });\r
- return match && match.key;\r
- },\r
-\r
- merge: function(object) {\r
- return this.clone().update(object);\r
- },\r
-\r
- update: function(object) {\r
- return new Hash(object).inject(this, function(result, pair) {\r
- result.set(pair.key, pair.value);\r
- return result;\r
- });\r
- },\r
-\r
- toQueryString: function() {\r
- return this.map(function(pair) {\r
- var key = encodeURIComponent(pair.key), values = pair.value;\r
-\r
- if (values && typeof values == 'object') {\r
- if (Object.isArray(values))\r
- return values.map(toQueryPair.curry(key)).join('&');\r
- }\r
- return toQueryPair(key, values);\r
- }).join('&');\r
- },\r
-\r
- inspect: function() {\r
- return '#<Hash:{' + this.map(function(pair) {\r
- return pair.map(Object.inspect).join(': ');\r
- }).join(', ') + '}>';\r
- },\r
-\r
- toJSON: function() {\r
- return Object.toJSON(this.toObject());\r
- },\r
-\r
- clone: function() {\r
- return new Hash(this);\r
- }\r
- }\r
-})());\r
-\r
-Hash.prototype.toTemplateReplacements = Hash.prototype.toObject;\r
-Hash.from = $H;\r
-var ObjectRange = Class.create(Enumerable, {\r
- initialize: function(start, end, exclusive) {\r
- this.start = start;\r
- this.end = end;\r
- this.exclusive = exclusive;\r
- },\r
-\r
- _each: function(iterator) {\r
- var value = this.start;\r
- while (this.include(value)) {\r
- iterator(value);\r
- value = value.succ();\r
- }\r
- },\r
-\r
- include: function(value) {\r
- if (value < this.start)\r
- return false;\r
- if (this.exclusive)\r
- return value < this.end;\r
- return value <= this.end;\r
- }\r
-});\r
-\r
-var $R = function(start, end, exclusive) {\r
- return new ObjectRange(start, end, exclusive);\r
-};\r
-\r
-var Ajax = {\r
- getTransport: function() {\r
- return Try.these(\r
- function() {return new XMLHttpRequest()},\r
- function() {return new ActiveXObject('Msxml2.XMLHTTP')},\r
- function() {return new ActiveXObject('Microsoft.XMLHTTP')}\r
- ) || false;\r
- },\r
-\r
- activeRequestCount: 0\r
-};\r
-\r
-Ajax.Responders = {\r
- responders: [],\r
-\r
- _each: function(iterator) {\r
- this.responders._each(iterator);\r
- },\r
-\r
- register: function(responder) {\r
- if (!this.include(responder))\r
- this.responders.push(responder);\r
- },\r
-\r
- unregister: function(responder) {\r
- this.responders = this.responders.without(responder);\r
- },\r
-\r
- dispatch: function(callback, request, transport, json) {\r
- this.each(function(responder) {\r
- if (Object.isFunction(responder[callback])) {\r
- try {\r
- responder[callback].apply(responder, [request, transport, json]);\r
- } catch (e) { }\r
- }\r
- });\r
- }\r
-};\r
-\r
-Object.extend(Ajax.Responders, Enumerable);\r
-\r
-Ajax.Responders.register({\r
- onCreate: function() { Ajax.activeRequestCount++ },\r
- onComplete: function() { Ajax.activeRequestCount-- }\r
-});\r
-\r
-Ajax.Base = Class.create({\r
- initialize: function(options) {\r
- this.options = {\r
- method: 'post',\r
- asynchronous: true,\r
- contentType: 'application/x-www-form-urlencoded',\r
- encoding: 'UTF-8',\r
- parameters: '',\r
- evalJSON: true,\r
- evalJS: true\r
- };\r
- Object.extend(this.options, options || { });\r
-\r
- this.options.method = this.options.method.toLowerCase();\r
-\r
- if (Object.isString(this.options.parameters))\r
- this.options.parameters = this.options.parameters.toQueryParams();\r
- else if (Object.isHash(this.options.parameters))\r
- this.options.parameters = this.options.parameters.toObject();\r
- }\r
-});\r
-\r
-Ajax.Request = Class.create(Ajax.Base, {\r
- _complete: false,\r
-\r
- initialize: function($super, url, options) {\r
- $super(options);\r
- this.transport = Ajax.getTransport();\r
- this.request(url);\r
- },\r
-\r
- request: function(url) {\r
- this.url = url;\r
- this.method = this.options.method;\r
- var params = Object.clone(this.options.parameters);\r
-\r
- if (!['get', 'post'].include(this.method)) {\r
- // simulate other verbs over post\r
- params['_method'] = this.method;\r
- this.method = 'post';\r
- }\r
-\r
- this.parameters = params;\r
-\r
- if (params = Object.toQueryString(params)) {\r
- // when GET, append parameters to URL\r
- if (this.method == 'get')\r
- this.url += (this.url.include('?') ? '&' : '?') + params;\r
- else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))\r
- params += '&_=';\r
- }\r
-\r
- try {\r
- var response = new Ajax.Response(this);\r
- if (this.options.onCreate) this.options.onCreate(response);\r
- Ajax.Responders.dispatch('onCreate', this, response);\r
-\r
- this.transport.open(this.method.toUpperCase(), this.url,\r
- this.options.asynchronous);\r
-\r
- if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);\r
-\r
- this.transport.onreadystatechange = this.onStateChange.bind(this);\r
- this.setRequestHeaders();\r
-\r
- this.body = this.method == 'post' ? (this.options.postBody || params) : null;\r
- this.transport.send(this.body);\r
-\r
- /* Force Firefox to handle ready state 4 for synchronous requests */\r
- if (!this.options.asynchronous && this.transport.overrideMimeType)\r
- this.onStateChange();\r
-\r
- }\r
- catch (e) {\r
- this.dispatchException(e);\r
- }\r
- },\r
-\r
- onStateChange: function() {\r
- var readyState = this.transport.readyState;\r
- if (readyState > 1 && !((readyState == 4) && this._complete))\r
- this.respondToReadyState(this.transport.readyState);\r
- },\r
-\r
- setRequestHeaders: function() {\r
- var headers = {\r
- 'X-Requested-With': 'XMLHttpRequest',\r
- 'X-Prototype-Version': Prototype.Version,\r
- 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'\r
- };\r
-\r
- if (this.method == 'post') {\r
- headers['Content-type'] = this.options.contentType +\r
- (this.options.encoding ? '; charset=' + this.options.encoding : '');\r
-\r
- /* Force "Connection: close" for older Mozilla browsers to work\r
- * around a bug where XMLHttpRequest sends an incorrect\r
- * Content-length header. See Mozilla Bugzilla #246651.\r
- */\r
- if (this.transport.overrideMimeType &&\r
- (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)\r
- headers['Connection'] = 'close';\r
- }\r
-\r
- // user-defined headers\r
- if (typeof this.options.requestHeaders == 'object') {\r
- var extras = this.options.requestHeaders;\r
-\r
- if (Object.isFunction(extras.push))\r
- for (var i = 0, length = extras.length; i < length; i += 2)\r
- headers[extras[i]] = extras[i+1];\r
- else\r
- $H(extras).each(function(pair) { headers[pair.key] = pair.value });\r
- }\r
-\r
- for (var name in headers)\r
- this.transport.setRequestHeader(name, headers[name]);\r
- },\r
-\r
- success: function() {\r
- var status = this.getStatus();\r
- return !status || (status >= 200 && status < 300);\r
- },\r
-\r
- getStatus: function() {\r
- try {\r
- return this.transport.status || 0;\r
- } catch (e) { return 0 }\r
- },\r
-\r
- respondToReadyState: function(readyState) {\r
- var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);\r
-\r
- if (state == 'Complete') {\r
- try {\r
- this._complete = true;\r
- (this.options['on' + response.status]\r
- || this.options['on' + (this.success() ? 'Success' : 'Failure')]\r
- || Prototype.emptyFunction)(response, response.headerJSON);\r
- } catch (e) {\r
- this.dispatchException(e);\r
- }\r
-\r
- var contentType = response.getHeader('Content-type');\r
- if (this.options.evalJS == 'force'\r
- || (this.options.evalJS && this.isSameOrigin() && contentType\r
- && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))\r
- this.evalResponse();\r
- }\r
-\r
- try {\r
- (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);\r
- Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);\r
- } catch (e) {\r
- this.dispatchException(e);\r
- }\r
-\r
- if (state == 'Complete') {\r
- // avoid memory leak in MSIE: clean up\r
- this.transport.onreadystatechange = Prototype.emptyFunction;\r
- }\r
- },\r
-\r
- isSameOrigin: function() {\r
- var m = this.url.match(/^\s*https?:\/\/[^\/]*/);\r
- return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({\r
- protocol: location.protocol,\r
- domain: document.domain,\r
- port: location.port ? ':' + location.port : ''\r
- }));\r
- },\r
-\r
- getHeader: function(name) {\r
- try {\r
- return this.transport.getResponseHeader(name) || null;\r
- } catch (e) { return null }\r
- },\r
-\r
- evalResponse: function() {\r
- try {\r
- return eval((this.transport.responseText || '').unfilterJSON());\r
- } catch (e) {\r
- this.dispatchException(e);\r
- }\r
- },\r
-\r
- dispatchException: function(exception) {\r
- (this.options.onException || Prototype.emptyFunction)(this, exception);\r
- Ajax.Responders.dispatch('onException', this, exception);\r
- }\r
-});\r
-\r
-Ajax.Request.Events =\r
- ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];\r
-\r
-Ajax.Response = Class.create({\r
- initialize: function(request){\r
- this.request = request;\r
- var transport = this.transport = request.transport,\r
- readyState = this.readyState = transport.readyState;\r
-\r
- if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {\r
- this.status = this.getStatus();\r
- this.statusText = this.getStatusText();\r
- this.responseText = String.interpret(transport.responseText);\r
- this.headerJSON = this._getHeaderJSON();\r
- }\r
-\r
- if(readyState == 4) {\r
- var xml = transport.responseXML;\r
- this.responseXML = Object.isUndefined(xml) ? null : xml;\r
- this.responseJSON = this._getResponseJSON();\r
- }\r
- },\r
-\r
- status: 0,\r
- statusText: '',\r
-\r
- getStatus: Ajax.Request.prototype.getStatus,\r
-\r
- getStatusText: function() {\r
- try {\r
- return this.transport.statusText || '';\r
- } catch (e) { return '' }\r
- },\r
-\r
- getHeader: Ajax.Request.prototype.getHeader,\r
-\r
- getAllHeaders: function() {\r
- try {\r
- return this.getAllResponseHeaders();\r
- } catch (e) { return null }\r
- },\r
-\r
- getResponseHeader: function(name) {\r
- return this.transport.getResponseHeader(name);\r
- },\r
-\r
- getAllResponseHeaders: function() {\r
- return this.transport.getAllResponseHeaders();\r
- },\r
-\r
- _getHeaderJSON: function() {\r
- var json = this.getHeader('X-JSON');\r
- if (!json) return null;\r
- json = decodeURIComponent(escape(json));\r
- try {\r
- return json.evalJSON(this.request.options.sanitizeJSON ||\r
- !this.request.isSameOrigin());\r
- } catch (e) {\r
- this.request.dispatchException(e);\r
- }\r
- },\r
-\r
- _getResponseJSON: function() {\r
- var options = this.request.options;\r
- if (!options.evalJSON || (options.evalJSON != 'force' &&\r
- !(this.getHeader('Content-type') || '').include('application/json')) ||\r
- this.responseText.blank())\r
- return null;\r
- try {\r
- return this.responseText.evalJSON(options.sanitizeJSON ||\r
- !this.request.isSameOrigin());\r
- } catch (e) {\r
- this.request.dispatchException(e);\r
- }\r
- }\r
-});\r
-\r
-Ajax.Updater = Class.create(Ajax.Request, {\r
- initialize: function($super, container, url, options) {\r
- this.container = {\r
- success: (container.success || container),\r
- failure: (container.failure || (container.success ? null : container))\r
- };\r
-\r
- options = Object.clone(options);\r
- var onComplete = options.onComplete;\r
- options.onComplete = (function(response, json) {\r
- this.updateContent(response.responseText);\r
- if (Object.isFunction(onComplete)) onComplete(response, json);\r
- }).bind(this);\r
-\r
- $super(url, options);\r
- },\r
-\r
- updateContent: function(responseText) {\r
- var receiver = this.container[this.success() ? 'success' : 'failure'],\r
- options = this.options;\r
-\r
- if (!options.evalScripts) responseText = responseText.stripScripts();\r
-\r
- if (receiver = $(receiver)) {\r
- if (options.insertion) {\r
- if (Object.isString(options.insertion)) {\r
- var insertion = { }; insertion[options.insertion] = responseText;\r
- receiver.insert(insertion);\r
- }\r
- else options.insertion(receiver, responseText);\r
- }\r
- else receiver.update(responseText);\r
- }\r
- }\r
-});\r
-\r
-Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {\r
- initialize: function($super, container, url, options) {\r
- $super(options);\r
- this.onComplete = this.options.onComplete;\r
-\r
- this.frequency = (this.options.frequency || 2);\r
- this.decay = (this.options.decay || 1);\r
-\r
- this.updater = { };\r
- this.container = container;\r
- this.url = url;\r
-\r
- this.start();\r
- },\r
-\r
- start: function() {\r
- this.options.onComplete = this.updateComplete.bind(this);\r
- this.onTimerEvent();\r
- },\r
-\r
- stop: function() {\r
- this.updater.options.onComplete = undefined;\r
- clearTimeout(this.timer);\r
- (this.onComplete || Prototype.emptyFunction).apply(this, arguments);\r
- },\r
-\r
- updateComplete: function(response) {\r
- if (this.options.decay) {\r
- this.decay = (response.responseText == this.lastText ?\r
- this.decay * this.options.decay : 1);\r
-\r
- this.lastText = response.responseText;\r
- }\r
- this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);\r
- },\r
-\r
- onTimerEvent: function() {\r
- this.updater = new Ajax.Updater(this.container, this.url, this.options);\r
- }\r
-});\r
-function $(element) {\r
- if (arguments.length > 1) {\r
- for (var i = 0, elements = [], length = arguments.length; i < length; i++)\r
- elements.push($(arguments[i]));\r
- return elements;\r
- }\r
- if (Object.isString(element))\r
- element = document.getElementById(element);\r
- return Element.extend(element);\r
-}\r
-\r
-if (Prototype.BrowserFeatures.XPath) {\r
- document._getElementsByXPath = function(expression, parentElement) {\r
- var results = [];\r
- var query = document.evaluate(expression, $(parentElement) || document,\r
- null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);\r
- for (var i = 0, length = query.snapshotLength; i < length; i++)\r
- results.push(Element.extend(query.snapshotItem(i)));\r
- return results;\r
- };\r
-}\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-if (!window.Node) var Node = { };\r
-\r
-if (!Node.ELEMENT_NODE) {\r
- // DOM level 2 ECMAScript Language Binding\r
- Object.extend(Node, {\r
- ELEMENT_NODE: 1,\r
- ATTRIBUTE_NODE: 2,\r
- TEXT_NODE: 3,\r
- CDATA_SECTION_NODE: 4,\r
- ENTITY_REFERENCE_NODE: 5,\r
- ENTITY_NODE: 6,\r
- PROCESSING_INSTRUCTION_NODE: 7,\r
- COMMENT_NODE: 8,\r
- DOCUMENT_NODE: 9,\r
- DOCUMENT_TYPE_NODE: 10,\r
- DOCUMENT_FRAGMENT_NODE: 11,\r
- NOTATION_NODE: 12\r
- });\r
-}\r
-\r
-(function() {\r
- var element = this.Element;\r
- this.Element = function(tagName, attributes) {\r
- attributes = attributes || { };\r
- tagName = tagName.toLowerCase();\r
- var cache = Element.cache;\r
- if (Prototype.Browser.IE && attributes.name) {\r
- tagName = '<' + tagName + ' name="' + attributes.name + '">';\r
- delete attributes.name;\r
- return Element.writeAttribute(document.createElement(tagName), attributes);\r
- }\r
- if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));\r
- return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);\r
- };\r
- Object.extend(this.Element, element || { });\r
-}).call(window);\r
-\r
-Element.cache = { };\r
-\r
-Element.Methods = {\r
- visible: function(element) {\r
- return $(element).style.display != 'none';\r
- },\r
-\r
- toggle: function(element) {\r
- element = $(element);\r
- Element[Element.visible(element) ? 'hide' : 'show'](element);\r
- return element;\r
- },\r
-\r
- hide: function(element) {\r
- $(element).style.display = 'none';\r
- return element;\r
- },\r
-\r
- show: function(element) {\r
- $(element).style.display = '';\r
- return element;\r
- },\r
-\r
- remove: function(element) {\r
- element = $(element);\r
- element.parentNode.removeChild(element);\r
- return element;\r
- },\r
-\r
- update: function(element, content) {\r
- element = $(element);\r
- if (content && content.toElement) content = content.toElement();\r
- if (Object.isElement(content)) return element.update().insert(content);\r
- content = Object.toHTML(content);\r
- element.innerHTML = content.stripScripts();\r
- content.evalScripts.bind(content).defer();\r
- return element;\r
- },\r
-\r
- replace: function(element, content) {\r
- element = $(element);\r
- if (content && content.toElement) content = content.toElement();\r
- else if (!Object.isElement(content)) {\r
- content = Object.toHTML(content);\r
- var range = element.ownerDocument.createRange();\r
- range.selectNode(element);\r
- content.evalScripts.bind(content).defer();\r
- content = range.createContextualFragment(content.stripScripts());\r
- }\r
- element.parentNode.replaceChild(content, element);\r
- return element;\r
- },\r
-\r
- insert: function(element, insertions) {\r
- element = $(element);\r
-\r
- if (Object.isString(insertions) || Object.isNumber(insertions) ||\r
- Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))\r
- insertions = {bottom:insertions};\r
-\r
- var content, insert, tagName, childNodes;\r
-\r
- for (var position in insertions) {\r
- content = insertions[position];\r
- position = position.toLowerCase();\r
- insert = Element._insertionTranslations[position];\r
-\r
- if (content && content.toElement) content = content.toElement();\r
- if (Object.isElement(content)) {\r
- insert(element, content);\r
- continue;\r
- }\r
-\r
- content = Object.toHTML(content);\r
-\r
- tagName = ((position == 'before' || position == 'after')\r
- ? element.parentNode : element).tagName.toUpperCase();\r
-\r
- childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());\r
-\r
- if (position == 'top' || position == 'after') childNodes.reverse();\r
- childNodes.each(insert.curry(element));\r
-\r
- content.evalScripts.bind(content).defer();\r
- }\r
-\r
- return element;\r
- },\r
-\r
- wrap: function(element, wrapper, attributes) {\r
- element = $(element);\r
- if (Object.isElement(wrapper))\r
- $(wrapper).writeAttribute(attributes || { });\r
- else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);\r
- else wrapper = new Element('div', wrapper);\r
- if (element.parentNode)\r
- element.parentNode.replaceChild(wrapper, element);\r
- wrapper.appendChild(element);\r
- return wrapper;\r
- },\r
-\r
- inspect: function(element) {\r
- element = $(element);\r
- var result = '<' + element.tagName.toLowerCase();\r
- $H({'id': 'id', 'className': 'class'}).each(function(pair) {\r
- var property = pair.first(), attribute = pair.last();\r
- var value = (element[property] || '').toString();\r
- if (value) result += ' ' + attribute + '=' + value.inspect(true);\r
- });\r
- return result + '>';\r
- },\r
-\r
- recursivelyCollect: function(element, property) {\r
- element = $(element);\r
- var elements = [];\r
- while (element = element[property])\r
- if (element.nodeType == 1)\r
- elements.push(Element.extend(element));\r
- return elements;\r
- },\r
-\r
- ancestors: function(element) {\r
- return $(element).recursivelyCollect('parentNode');\r
- },\r
-\r
- descendants: function(element) {\r
- return $(element).select("*");\r
- },\r
-\r
- firstDescendant: function(element) {\r
- element = $(element).firstChild;\r
- while (element && element.nodeType != 1) element = element.nextSibling;\r
- return $(element);\r
- },\r
-\r
- immediateDescendants: function(element) {\r
- if (!(element = $(element).firstChild)) return [];\r
- while (element && element.nodeType != 1) element = element.nextSibling;\r
- if (element) return [element].concat($(element).nextSiblings());\r
- return [];\r
- },\r
-\r
- previousSiblings: function(element) {\r
- return $(element).recursivelyCollect('previousSibling');\r
- },\r
-\r
- nextSiblings: function(element) {\r
- return $(element).recursivelyCollect('nextSibling');\r
- },\r
-\r
- siblings: function(element) {\r
- element = $(element);\r
- return element.previousSiblings().reverse().concat(element.nextSiblings());\r
- },\r
-\r
- match: function(element, selector) {\r
- if (Object.isString(selector))\r
- selector = new Selector(selector);\r
- return selector.match($(element));\r
- },\r
-\r
- up: function(element, expression, index) {\r
- element = $(element);\r
- if (arguments.length == 1) return $(element.parentNode);\r
- var ancestors = element.ancestors();\r
- return Object.isNumber(expression) ? ancestors[expression] :\r
- Selector.findElement(ancestors, expression, index);\r
- },\r
-\r
- down: function(element, expression, index) {\r
- element = $(element);\r
- if (arguments.length == 1) return element.firstDescendant();\r
- return Object.isNumber(expression) ? element.descendants()[expression] :\r
- element.select(expression)[index || 0];\r
- },\r
-\r
- previous: function(element, expression, index) {\r
- element = $(element);\r
- if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));\r
- var previousSiblings = element.previousSiblings();\r
- return Object.isNumber(expression) ? previousSiblings[expression] :\r
- Selector.findElement(previousSiblings, expression, index);\r
- },\r
-\r
- next: function(element, expression, index) {\r
- element = $(element);\r
- if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));\r
- var nextSiblings = element.nextSiblings();\r
- return Object.isNumber(expression) ? nextSiblings[expression] :\r
- Selector.findElement(nextSiblings, expression, index);\r
- },\r
-\r
- select: function() {\r
- var args = $A(arguments), element = $(args.shift());\r
- return Selector.findChildElements(element, args);\r
- },\r
-\r
- adjacent: function() {\r
- var args = $A(arguments), element = $(args.shift());\r
- return Selector.findChildElements(element.parentNode, args).without(element);\r
- },\r
-\r
- identify: function(element) {\r
- element = $(element);\r
- var id = element.readAttribute('id'), self = arguments.callee;\r
- if (id) return id;\r
- do { id = 'anonymous_element_' + self.counter++ } while ($(id));\r
- element.writeAttribute('id', id);\r
- return id;\r
- },\r
-\r
- readAttribute: function(element, name) {\r
- element = $(element);\r
- if (Prototype.Browser.IE) {\r
- var t = Element._attributeTranslations.read;\r
- if (t.values[name]) return t.values[name](element, name);\r
- if (t.names[name]) name = t.names[name];\r
- if (name.include(':')) {\r
- return (!element.attributes || !element.attributes[name]) ? null :\r
- element.attributes[name].value;\r
- }\r
- }\r
- return element.getAttribute(name);\r
- },\r
-\r
- writeAttribute: function(element, name, value) {\r
- element = $(element);\r
- var attributes = { }, t = Element._attributeTranslations.write;\r
-\r
- if (typeof name == 'object') attributes = name;\r
- else attributes[name] = Object.isUndefined(value) ? true : value;\r
-\r
- for (var attr in attributes) {\r
- name = t.names[attr] || attr;\r
- value = attributes[attr];\r
- if (t.values[attr]) name = t.values[attr](element, value);\r
- if (value === false || value === null)\r
- element.removeAttribute(name);\r
- else if (value === true)\r
- element.setAttribute(name, name);\r
- else element.setAttribute(name, value);\r
- }\r
- return element;\r
- },\r
-\r
- getHeight: function(element) {\r
- return $(element).getDimensions().height;\r
- },\r
-\r
- getWidth: function(element) {\r
- return $(element).getDimensions().width;\r
- },\r
-\r
- classNames: function(element) {\r
- return new Element.ClassNames(element);\r
- },\r
-\r
- hasClassName: function(element, className) {\r
- if (!(element = $(element))) return;\r
- var elementClassName = element.className;\r
- return (elementClassName.length > 0 && (elementClassName == className ||\r
- new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));\r
- },\r
-\r
- addClassName: function(element, className) {\r
- if (!(element = $(element))) return;\r
- if (!element.hasClassName(className))\r
- element.className += (element.className ? ' ' : '') + className;\r
- return element;\r
- },\r
-\r
- removeClassName: function(element, className) {\r
- if (!(element = $(element))) return;\r
- element.className = element.className.replace(\r
- new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();\r
- return element;\r
- },\r
-\r
- toggleClassName: function(element, className) {\r
- if (!(element = $(element))) return;\r
- return element[element.hasClassName(className) ?\r
- 'removeClassName' : 'addClassName'](className);\r
- },\r
-\r
- // removes whitespace-only text node children\r
- cleanWhitespace: function(element) {\r
- element = $(element);\r
- var node = element.firstChild;\r
- while (node) {\r
- var nextNode = node.nextSibling;\r
- if (node.nodeType == 3 && !/\S/.test(node.nodeValue))\r
- element.removeChild(node);\r
- node = nextNode;\r
- }\r
- return element;\r
- },\r
-\r
- empty: function(element) {\r
- return $(element).innerHTML.blank();\r
- },\r
-\r
- descendantOf: function(element, ancestor) {\r
- element = $(element), ancestor = $(ancestor);\r
- var originalAncestor = ancestor;\r
-\r
- if (element.compareDocumentPosition)\r
- return (element.compareDocumentPosition(ancestor) & 8) === 8;\r
-\r
- if (element.sourceIndex && !Prototype.Browser.Opera) {\r
- var e = element.sourceIndex, a = ancestor.sourceIndex,\r
- nextAncestor = ancestor.nextSibling;\r
- if (!nextAncestor) {\r
- do { ancestor = ancestor.parentNode; }\r
- while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode);\r
- }\r
- if (nextAncestor && nextAncestor.sourceIndex)\r
- return (e > a && e < nextAncestor.sourceIndex);\r
- }\r
-\r
- while (element = element.parentNode)\r
- if (element == originalAncestor) return true;\r
- return false;\r
- },\r
-\r
- scrollTo: function(element) {\r
- element = $(element);\r
- var pos = element.cumulativeOffset();\r
- window.scrollTo(pos[0], pos[1]);\r
- return element;\r
- },\r
-\r
- getStyle: function(element, style) {\r
- element = $(element);\r
- style = style == 'float' ? 'cssFloat' : style.camelize();\r
- var value = element.style[style];\r
- if (!value) {\r
- var css = document.defaultView.getComputedStyle(element, null);\r
- value = css ? css[style] : null;\r
- }\r
- if (style == 'opacity') return value ? parseFloat(value) : 1.0;\r
- return value == 'auto' ? null : value;\r
- },\r
-\r
- getOpacity: function(element) {\r
- return $(element).getStyle('opacity');\r
- },\r
-\r
- setStyle: function(element, styles) {\r
- element = $(element);\r
- var elementStyle = element.style, match;\r
- if (Object.isString(styles)) {\r
- element.style.cssText += ';' + styles;\r
- return styles.include('opacity') ?\r
- element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;\r
- }\r
- for (var property in styles)\r
- if (property == 'opacity') element.setOpacity(styles[property]);\r
- else\r
- elementStyle[(property == 'float' || property == 'cssFloat') ?\r
- (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :\r
- property] = styles[property];\r
-\r
- return element;\r
- },\r
-\r
- setOpacity: function(element, value) {\r
- element = $(element);\r
- element.style.opacity = (value == 1 || value === '') ? '' :\r
- (value < 0.00001) ? 0 : value;\r
- return element;\r
- },\r
-\r
- getDimensions: function(element) {\r
- element = $(element);\r
- var display = $(element).getStyle('display');\r
- if (display != 'none' && display != null) // Safari bug\r
- return {width: element.offsetWidth, height: element.offsetHeight};\r
-\r
- // All *Width and *Height properties give 0 on elements with display none,\r
- // so enable the element temporarily\r
- var els = element.style;\r
- var originalVisibility = els.visibility;\r
- var originalPosition = els.position;\r
- var originalDisplay = els.display;\r
- els.visibility = 'hidden';\r
- els.position = 'absolute';\r
- els.display = 'block';\r
- var originalWidth = element.clientWidth;\r
- var originalHeight = element.clientHeight;\r
- els.display = originalDisplay;\r
- els.position = originalPosition;\r
- els.visibility = originalVisibility;\r
- return {width: originalWidth, height: originalHeight};\r
- },\r
-\r
- makePositioned: function(element) {\r
- element = $(element);\r
- var pos = Element.getStyle(element, 'position');\r
- if (pos == 'static' || !pos) {\r
- element._madePositioned = true;\r
- element.style.position = 'relative';\r
- // Opera returns the offset relative to the positioning context, when an\r
- // element is position relative but top and left have not been defined\r
- if (window.opera) {\r
- element.style.top = 0;\r
- element.style.left = 0;\r
- }\r
- }\r
- return element;\r
- },\r
-\r
- undoPositioned: function(element) {\r
- element = $(element);\r
- if (element._madePositioned) {\r
- element._madePositioned = undefined;\r
- element.style.position =\r
- element.style.top =\r
- element.style.left =\r
- element.style.bottom =\r
- element.style.right = '';\r
- }\r
- return element;\r
- },\r
-\r
- makeClipping: function(element) {\r
- element = $(element);\r
- if (element._overflow) return element;\r
- element._overflow = Element.getStyle(element, 'overflow') || 'auto';\r
- if (element._overflow !== 'hidden')\r
- element.style.overflow = 'hidden';\r
- return element;\r
- },\r
-\r
- undoClipping: function(element) {\r
- element = $(element);\r
- if (!element._overflow) return element;\r
- element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;\r
- element._overflow = null;\r
- return element;\r
- },\r
-\r
- cumulativeOffset: function(element) {\r
- var valueT = 0, valueL = 0;\r
- do {\r
- valueT += element.offsetTop || 0;\r
- valueL += element.offsetLeft || 0;\r
- element = element.offsetParent;\r
- } while (element);\r
- return Element._returnOffset(valueL, valueT);\r
- },\r
-\r
- positionedOffset: function(element) {\r
- var valueT = 0, valueL = 0;\r
- do {\r
- valueT += element.offsetTop || 0;\r
- valueL += element.offsetLeft || 0;\r
- element = element.offsetParent;\r
- if (element) {\r
- if (element.tagName == 'BODY') break;\r
- var p = Element.getStyle(element, 'position');\r
- if (p !== 'static') break;\r
- }\r
- } while (element);\r
- return Element._returnOffset(valueL, valueT);\r
- },\r
-\r
- absolutize: function(element) {\r
- element = $(element);\r
- if (element.getStyle('position') == 'absolute') return;\r
- // Position.prepare(); // To be done manually by Scripty when it needs it.\r
-\r
- var offsets = element.positionedOffset();\r
- var top = offsets[1];\r
- var left = offsets[0];\r
- var width = element.clientWidth;\r
- var height = element.clientHeight;\r
-\r
- element._originalLeft = left - parseFloat(element.style.left || 0);\r
- element._originalTop = top - parseFloat(element.style.top || 0);\r
- element._originalWidth = element.style.width;\r
- element._originalHeight = element.style.height;\r
-\r
- element.style.position = 'absolute';\r
- element.style.top = top + 'px';\r
- element.style.left = left + 'px';\r
- element.style.width = width + 'px';\r
- element.style.height = height + 'px';\r
- return element;\r
- },\r
-\r
- relativize: function(element) {\r
- element = $(element);\r
- if (element.getStyle('position') == 'relative') return;\r
- // Position.prepare(); // To be done manually by Scripty when it needs it.\r
-\r
- element.style.position = 'relative';\r
- var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);\r
- var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);\r
-\r
- element.style.top = top + 'px';\r
- element.style.left = left + 'px';\r
- element.style.height = element._originalHeight;\r
- element.style.width = element._originalWidth;\r
- return element;\r
- },\r
-\r
- cumulativeScrollOffset: function(element) {\r
- var valueT = 0, valueL = 0;\r
- do {\r
- valueT += element.scrollTop || 0;\r
- valueL += element.scrollLeft || 0;\r
- element = element.parentNode;\r
- } while (element);\r
- return Element._returnOffset(valueL, valueT);\r
- },\r
-\r
- getOffsetParent: function(element) {\r
- if (element.offsetParent) return $(element.offsetParent);\r
- if (element == document.body) return $(element);\r
-\r
- while ((element = element.parentNode) && element != document.body)\r
- if (Element.getStyle(element, 'position') != 'static')\r
- return $(element);\r
-\r
- return $(document.body);\r
- },\r
-\r
- viewportOffset: function(forElement) {\r
- var valueT = 0, valueL = 0;\r
-\r
- var element = forElement;\r
- do {\r
- valueT += element.offsetTop || 0;\r
- valueL += element.offsetLeft || 0;\r
-\r
- // Safari fix\r
- if (element.offsetParent == document.body &&\r
- Element.getStyle(element, 'position') == 'absolute') break;\r
-\r
- } while (element = element.offsetParent);\r
-\r
- element = forElement;\r
- do {\r
- if (!Prototype.Browser.Opera || element.tagName == 'BODY') {\r
- valueT -= element.scrollTop || 0;\r
- valueL -= element.scrollLeft || 0;\r
- }\r
- } while (element = element.parentNode);\r
-\r
- return Element._returnOffset(valueL, valueT);\r
- },\r
-\r
- clonePosition: function(element, source) {\r
- var options = Object.extend({\r
- setLeft: true,\r
- setTop: true,\r
- setWidth: true,\r
- setHeight: true,\r
- offsetTop: 0,\r
- offsetLeft: 0\r
- }, arguments[2] || { });\r
-\r
- // find page position of source\r
- source = $(source);\r
- var p = source.viewportOffset();\r
-\r
- // find coordinate system to use\r
- element = $(element);\r
- var delta = [0, 0];\r
- var parent = null;\r
- // delta [0,0] will do fine with position: fixed elements,\r
- // position:absolute needs offsetParent deltas\r
- if (Element.getStyle(element, 'position') == 'absolute') {\r
- parent = element.getOffsetParent();\r
- delta = parent.viewportOffset();\r
- }\r
-\r
- // correct by body offsets (fixes Safari)\r
- if (parent == document.body) {\r
- delta[0] -= document.body.offsetLeft;\r
- delta[1] -= document.body.offsetTop;\r
- }\r
-\r
- // set position\r
- if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';\r
- if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';\r
- if (options.setWidth) element.style.width = source.offsetWidth + 'px';\r
- if (options.setHeight) element.style.height = source.offsetHeight + 'px';\r
- return element;\r
- }\r
-};\r
-\r
-Element.Methods.identify.counter = 1;\r
-\r
-Object.extend(Element.Methods, {\r
- getElementsBySelector: Element.Methods.select,\r
- childElements: Element.Methods.immediateDescendants\r
-});\r
-\r
-Element._attributeTranslations = {\r
- write: {\r
- names: {\r
- className: 'class',\r
- htmlFor: 'for'\r
- },\r
- values: { }\r
- }\r
-};\r
-\r
-if (Prototype.Browser.Opera) {\r
- Element.Methods.getStyle = Element.Methods.getStyle.wrap(\r
- function(proceed, element, style) {\r
- switch (style) {\r
- case 'left': case 'top': case 'right': case 'bottom':\r
- if (proceed(element, 'position') === 'static') return null;\r
- case 'height': case 'width':\r
- // returns '0px' for hidden elements; we want it to return null\r
- if (!Element.visible(element)) return null;\r
-\r
- // returns the border-box dimensions rather than the content-box\r
- // dimensions, so we subtract padding and borders from the value\r
- var dim = parseInt(proceed(element, style), 10);\r
-\r
- if (dim !== element['offset' + style.capitalize()])\r
- return dim + 'px';\r
-\r
- var properties;\r
- if (style === 'height') {\r
- properties = ['border-top-width', 'padding-top',\r
- 'padding-bottom', 'border-bottom-width'];\r
- }\r
- else {\r
- properties = ['border-left-width', 'padding-left',\r
- 'padding-right', 'border-right-width'];\r
- }\r
- return properties.inject(dim, function(memo, property) {\r
- var val = proceed(element, property);\r
- return val === null ? memo : memo - parseInt(val, 10);\r
- }) + 'px';\r
- default: return proceed(element, style);\r
- }\r
- }\r
- );\r
-\r
- Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(\r
- function(proceed, element, attribute) {\r
- if (attribute === 'title') return element.title;\r
- return proceed(element, attribute);\r
- }\r
- );\r
-}\r
-\r
-else if (Prototype.Browser.IE) {\r
- // IE doesn't report offsets correctly for static elements, so we change them\r
- // to "relative" to get the values, then change them back.\r
- Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap(\r
- function(proceed, element) {\r
- element = $(element);\r
- var position = element.getStyle('position');\r
- if (position !== 'static') return proceed(element);\r
- element.setStyle({ position: 'relative' });\r
- var value = proceed(element);\r
- element.setStyle({ position: position });\r
- return value;\r
- }\r
- );\r
-\r
- $w('positionedOffset viewportOffset').each(function(method) {\r
- Element.Methods[method] = Element.Methods[method].wrap(\r
- function(proceed, element) {\r
- element = $(element);\r
- var position = element.getStyle('position');\r
- if (position !== 'static') return proceed(element);\r
- // Trigger hasLayout on the offset parent so that IE6 reports\r
- // accurate offsetTop and offsetLeft values for position: fixed.\r
- var offsetParent = element.getOffsetParent();\r
- if (offsetParent && offsetParent.getStyle('position') === 'fixed')\r
- offsetParent.setStyle({ zoom: 1 });\r
- element.setStyle({ position: 'relative' });\r
- var value = proceed(element);\r
- element.setStyle({ position: position });\r
- return value;\r
- }\r
- );\r
- });\r
-\r
- Element.Methods.getStyle = function(element, style) {\r
- element = $(element);\r
- style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();\r
- var value = element.style[style];\r
- if (!value && element.currentStyle) value = element.currentStyle[style];\r
-\r
- if (style == 'opacity') {\r
- if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))\r
- if (value[1]) return parseFloat(value[1]) / 100;\r
- return 1.0;\r
- }\r
-\r
- if (value == 'auto') {\r
- if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))\r
- return element['offset' + style.capitalize()] + 'px';\r
- return null;\r
- }\r
- return value;\r
- };\r
-\r
- Element.Methods.setOpacity = function(element, value) {\r
- function stripAlpha(filter){\r
- return filter.replace(/alpha\([^\)]*\)/gi,'');\r
- }\r
- element = $(element);\r
- var currentStyle = element.currentStyle;\r
- if ((currentStyle && !currentStyle.hasLayout) ||\r
- (!currentStyle && element.style.zoom == 'normal'))\r
- element.style.zoom = 1;\r
-\r
- var filter = element.getStyle('filter'), style = element.style;\r
- if (value == 1 || value === '') {\r
- (filter = stripAlpha(filter)) ?\r
- style.filter = filter : style.removeAttribute('filter');\r
- return element;\r
- } else if (value < 0.00001) value = 0;\r
- style.filter = stripAlpha(filter) +\r
- 'alpha(opacity=' + (value * 100) + ')';\r
- return element;\r
- };\r
-\r
- Element._attributeTranslations = {\r
- read: {\r
- names: {\r
- 'class': 'className',\r
- 'for': 'htmlFor'\r
- },\r
- values: {\r
- _getAttr: function(element, attribute) {\r
- return element.getAttribute(attribute, 2);\r
- },\r
- _getAttrNode: function(element, attribute) {\r
- var node = element.getAttributeNode(attribute);\r
- return node ? node.value : "";\r
- },\r
- _getEv: function(element, attribute) {\r
- attribute = element.getAttribute(attribute);\r
- return attribute ? attribute.toString().slice(23, -2) : null;\r
- },\r
- _flag: function(element, attribute) {\r
- return $(element).hasAttribute(attribute) ? attribute : null;\r
- },\r
- style: function(element) {\r
- return element.style.cssText.toLowerCase();\r
- },\r
- title: function(element) {\r
- return element.title;\r
- }\r
- }\r
- }\r
- };\r
-\r
- Element._attributeTranslations.write = {\r
- names: Object.extend({\r
- cellpadding: 'cellPadding',\r
- cellspacing: 'cellSpacing'\r
- }, Element._attributeTranslations.read.names),\r
- values: {\r
- checked: function(element, value) {\r
- element.checked = !!value;\r
- },\r
-\r
- style: function(element, value) {\r
- element.style.cssText = value ? value : '';\r
- }\r
- }\r
- };\r
-\r
- Element._attributeTranslations.has = {};\r
-\r
- $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +\r
- 'encType maxLength readOnly longDesc').each(function(attr) {\r
- Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;\r
- Element._attributeTranslations.has[attr.toLowerCase()] = attr;\r
- });\r
-\r
- (function(v) {\r
- Object.extend(v, {\r
- href: v._getAttr,\r
- src: v._getAttr,\r
- type: v._getAttr,\r
- action: v._getAttrNode,\r
- disabled: v._flag,\r
- checked: v._flag,\r
- readonly: v._flag,\r
- multiple: v._flag,\r
- onload: v._getEv,\r
- onunload: v._getEv,\r
- onclick: v._getEv,\r
- ondblclick: v._getEv,\r
- onmousedown: v._getEv,\r
- onmouseup: v._getEv,\r
- onmouseover: v._getEv,\r
- onmousemove: v._getEv,\r
- onmouseout: v._getEv,\r
- onfocus: v._getEv,\r
- onblur: v._getEv,\r
- onkeypress: v._getEv,\r
- onkeydown: v._getEv,\r
- onkeyup: v._getEv,\r
- onsubmit: v._getEv,\r
- onreset: v._getEv,\r
- onselect: v._getEv,\r
- onchange: v._getEv\r
- });\r
- })(Element._attributeTranslations.read.values);\r
-}\r
-\r
-else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {\r
- Element.Methods.setOpacity = function(element, value) {\r
- element = $(element);\r
- element.style.opacity = (value == 1) ? 0.999999 :\r
- (value === '') ? '' : (value < 0.00001) ? 0 : value;\r
- return element;\r
- };\r
-}\r
-\r
-else if (Prototype.Browser.WebKit) {\r
- Element.Methods.setOpacity = function(element, value) {\r
- element = $(element);\r
- element.style.opacity = (value == 1 || value === '') ? '' :\r
- (value < 0.00001) ? 0 : value;\r
-\r
- if (value == 1)\r
- if(element.tagName == 'IMG' && element.width) {\r
- element.width++; element.width--;\r
- } else try {\r
- var n = document.createTextNode(' ');\r
- element.appendChild(n);\r
- element.removeChild(n);\r
- } catch (e) { }\r
-\r
- return element;\r
- };\r
-\r
- // Safari returns margins on body which is incorrect if the child is absolutely\r
- // positioned. For performance reasons, redefine Element#cumulativeOffset for\r
- // KHTML/WebKit only.\r
- Element.Methods.cumulativeOffset = function(element) {\r
- var valueT = 0, valueL = 0;\r
- do {\r
- valueT += element.offsetTop || 0;\r
- valueL += element.offsetLeft || 0;\r
- if (element.offsetParent == document.body)\r
- if (Element.getStyle(element, 'position') == 'absolute') break;\r
-\r
- element = element.offsetParent;\r
- } while (element);\r
-\r
- return Element._returnOffset(valueL, valueT);\r
- };\r
-}\r
-\r
-if (Prototype.Browser.IE || Prototype.Browser.Opera) {\r
- // IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements\r
- Element.Methods.update = function(element, content) {\r
- element = $(element);\r
-\r
- if (content && content.toElement) content = content.toElement();\r
- if (Object.isElement(content)) return element.update().insert(content);\r
-\r
- content = Object.toHTML(content);\r
- var tagName = element.tagName.toUpperCase();\r
-\r
- if (tagName in Element._insertionTranslations.tags) {\r
- $A(element.childNodes).each(function(node) { element.removeChild(node) });\r
- Element._getContentFromAnonymousElement(tagName, content.stripScripts())\r
- .each(function(node) { element.appendChild(node) });\r
- }\r
- else element.innerHTML = content.stripScripts();\r
-\r
- content.evalScripts.bind(content).defer();\r
- return element;\r
- };\r
-}\r
-\r
-if ('outerHTML' in document.createElement('div')) {\r
- Element.Methods.replace = function(element, content) {\r
- element = $(element);\r
-\r
- if (content && content.toElement) content = content.toElement();\r
- if (Object.isElement(content)) {\r
- element.parentNode.replaceChild(content, element);\r
- return element;\r
- }\r
-\r
- content = Object.toHTML(content);\r
- var parent = element.parentNode, tagName = parent.tagName.toUpperCase();\r
-\r
- if (Element._insertionTranslations.tags[tagName]) {\r
- var nextSibling = element.next();\r
- var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());\r
- parent.removeChild(element);\r
- if (nextSibling)\r
- fragments.each(function(node) { parent.insertBefore(node, nextSibling) });\r
- else\r
- fragments.each(function(node) { parent.appendChild(node) });\r
- }\r
- else element.outerHTML = content.stripScripts();\r
-\r
- content.evalScripts.bind(content).defer();\r
- return element;\r
- };\r
-}\r
-\r
-Element._returnOffset = function(l, t) {\r
- var result = [l, t];\r
- result.left = l;\r
- result.top = t;\r
- return result;\r
-};\r
-\r
-Element._getContentFromAnonymousElement = function(tagName, html) {\r
- var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];\r
- if (t) {\r
- div.innerHTML = t[0] + html + t[1];\r
- t[2].times(function() { div = div.firstChild });\r
- } else div.innerHTML = html;\r
- return $A(div.childNodes);\r
-};\r
-\r
-Element._insertionTranslations = {\r
- before: function(element, node) {\r
- element.parentNode.insertBefore(node, element);\r
- },\r
- top: function(element, node) {\r
- element.insertBefore(node, element.firstChild);\r
- },\r
- bottom: function(element, node) {\r
- element.appendChild(node);\r
- },\r
- after: function(element, node) {\r
- element.parentNode.insertBefore(node, element.nextSibling);\r
- },\r
- tags: {\r
- TABLE: ['<table>', '</table>', 1],\r
- TBODY: ['<table><tbody>', '</tbody></table>', 2],\r
- TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],\r
- TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],\r
- SELECT: ['<select>', '</select>', 1]\r
- }\r
-};\r
-\r
-(function() {\r
- Object.extend(this.tags, {\r
- THEAD: this.tags.TBODY,\r
- TFOOT: this.tags.TBODY,\r
- TH: this.tags.TD\r
- });\r
-}).call(Element._insertionTranslations);\r
-\r
-Element.Methods.Simulated = {\r
- hasAttribute: function(element, attribute) {\r
- attribute = Element._attributeTranslations.has[attribute] || attribute;\r
- var node = $(element).getAttributeNode(attribute);\r
- return node && node.specified;\r
- }\r
-};\r
-\r
-Element.Methods.ByTag = { };\r
-\r
-Object.extend(Element, Element.Methods);\r
-\r
-if (!Prototype.BrowserFeatures.ElementExtensions &&\r
- document.createElement('div').__proto__) {\r
- window.HTMLElement = { };\r
- window.HTMLElement.prototype = document.createElement('div').__proto__;\r
- Prototype.BrowserFeatures.ElementExtensions = true;\r
-}\r
-\r
-Element.extend = (function() {\r
- if (Prototype.BrowserFeatures.SpecificElementExtensions)\r
- return Prototype.K;\r
-\r
- var Methods = { }, ByTag = Element.Methods.ByTag;\r
-\r
- var extend = Object.extend(function(element) {\r
- if (!element || element._extendedByPrototype ||\r
- element.nodeType != 1 || element == window) return element;\r
-\r
- var methods = Object.clone(Methods),\r
- tagName = element.tagName, property, value;\r
-\r
- // extend methods for specific tags\r
- if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);\r
-\r
- for (property in methods) {\r
- value = methods[property];\r
- if (Object.isFunction(value) && !(property in element))\r
- element[property] = value.methodize();\r
- }\r
-\r
- element._extendedByPrototype = Prototype.emptyFunction;\r
- return element;\r
-\r
- }, {\r
- refresh: function() {\r
- // extend methods for all tags (Safari doesn't need this)\r
- if (!Prototype.BrowserFeatures.ElementExtensions) {\r
- Object.extend(Methods, Element.Methods);\r
- Object.extend(Methods, Element.Methods.Simulated);\r
- }\r
- }\r
- });\r
-\r
- extend.refresh();\r
- return extend;\r
-})();\r
-\r
-Element.hasAttribute = function(element, attribute) {\r
- if (element.hasAttribute) return element.hasAttribute(attribute);\r
- return Element.Methods.Simulated.hasAttribute(element, attribute);\r
-};\r
-\r
-Element.addMethods = function(methods) {\r
- var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;\r
-\r
- if (!methods) {\r
- Object.extend(Form, Form.Methods);\r
- Object.extend(Form.Element, Form.Element.Methods);\r
- Object.extend(Element.Methods.ByTag, {\r
- "FORM": Object.clone(Form.Methods),\r
- "INPUT": Object.clone(Form.Element.Methods),\r
- "SELECT": Object.clone(Form.Element.Methods),\r
- "TEXTAREA": Object.clone(Form.Element.Methods)\r
- });\r
- }\r
-\r
- if (arguments.length == 2) {\r
- var tagName = methods;\r
- methods = arguments[1];\r
- }\r
-\r
- if (!tagName) Object.extend(Element.Methods, methods || { });\r
- else {\r
- if (Object.isArray(tagName)) tagName.each(extend);\r
- else extend(tagName);\r
- }\r
-\r
- function extend(tagName) {\r
- tagName = tagName.toUpperCase();\r
- if (!Element.Methods.ByTag[tagName])\r
- Element.Methods.ByTag[tagName] = { };\r
- Object.extend(Element.Methods.ByTag[tagName], methods);\r
- }\r
-\r
- function copy(methods, destination, onlyIfAbsent) {\r
- onlyIfAbsent = onlyIfAbsent || false;\r
- for (var property in methods) {\r
- var value = methods[property];\r
- if (!Object.isFunction(value)) continue;\r
- if (!onlyIfAbsent || !(property in destination))\r
- destination[property] = value.methodize();\r
- }\r
- }\r
-\r
- function findDOMClass(tagName) {\r
- var klass;\r
- var trans = {\r
- "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",\r
- "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",\r
- "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",\r
- "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",\r
- "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":\r
- "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":\r
- "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":\r
- "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":\r
- "FrameSet", "IFRAME": "IFrame"\r
- };\r
- if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';\r
- if (window[klass]) return window[klass];\r
- klass = 'HTML' + tagName + 'Element';\r
- if (window[klass]) return window[klass];\r
- klass = 'HTML' + tagName.capitalize() + 'Element';\r
- if (window[klass]) return window[klass];\r
-\r
- window[klass] = { };\r
- window[klass].prototype = document.createElement(tagName).__proto__;\r
- return window[klass];\r
- }\r
-\r
- if (F.ElementExtensions) {\r
- copy(Element.Methods, HTMLElement.prototype);\r
- copy(Element.Methods.Simulated, HTMLElement.prototype, true);\r
- }\r
-\r
- if (F.SpecificElementExtensions) {\r
- for (var tag in Element.Methods.ByTag) {\r
- var klass = findDOMClass(tag);\r
- if (Object.isUndefined(klass)) continue;\r
- copy(T[tag], klass.prototype);\r
- }\r
- }\r
-\r
- Object.extend(Element, Element.Methods);\r
- delete Element.ByTag;\r
-\r
- if (Element.extend.refresh) Element.extend.refresh();\r
- Element.cache = { };\r
-};\r
-\r
-document.viewport = {\r
- getDimensions: function() {\r
- var dimensions = { };\r
- var B = Prototype.Browser;\r
- $w('width height').each(function(d) {\r
- var D = d.capitalize();\r
- dimensions[d] = (B.WebKit && !document.evaluate) ? self['inner' + D] :\r
- (B.Opera) ? document.body['client' + D] : document.documentElement['client' + D];\r
- });\r
- return dimensions;\r
- },\r
-\r
- getWidth: function() {\r
- return this.getDimensions().width;\r
- },\r
-\r
- getHeight: function() {\r
- return this.getDimensions().height;\r
- },\r
-\r
- getScrollOffsets: function() {\r
- return Element._returnOffset(\r
- window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,\r
- window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);\r
- }\r
-};\r
-/* Portions of the Selector class are derived from Jack Slocum’s DomQuery,\r
- * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style\r
- * license. Please see http://www.yui-ext.com/ for more information. */\r
-\r
-var Selector = Class.create({\r
- initialize: function(expression) {\r
- this.expression = expression.strip();\r
- this.compileMatcher();\r
- },\r
-\r
- shouldUseXPath: function() {\r
- if (!Prototype.BrowserFeatures.XPath) return false;\r
-\r
- var e = this.expression;\r
-\r
- // Safari 3 chokes on :*-of-type and :empty\r
- if (Prototype.Browser.WebKit &&\r
- (e.include("-of-type") || e.include(":empty")))\r
- return false;\r
-\r
- // XPath can't do namespaced attributes, nor can it read\r
- // the "checked" property from DOM nodes\r
- if ((/(\[[\w-]*?:|:checked)/).test(this.expression))\r
- return false;\r
-\r
- return true;\r
- },\r
-\r
- compileMatcher: function() {\r
- if (this.shouldUseXPath())\r
- return this.compileXPathMatcher();\r
-\r
- var e = this.expression, ps = Selector.patterns, h = Selector.handlers,\r
- c = Selector.criteria, le, p, m;\r
-\r
- if (Selector._cache[e]) {\r
- this.matcher = Selector._cache[e];\r
- return;\r
- }\r
-\r
- this.matcher = ["this.matcher = function(root) {",\r
- "var r = root, h = Selector.handlers, c = false, n;"];\r
-\r
- while (e && le != e && (/\S/).test(e)) {\r
- le = e;\r
- for (var i in ps) {\r
- p = ps[i];\r
- if (m = e.match(p)) {\r
- this.matcher.push(Object.isFunction(c[i]) ? c[i](m) :\r
- new Template(c[i]).evaluate(m));\r
- e = e.replace(m[0], '');\r
- break;\r
- }\r
- }\r
- }\r
-\r
- this.matcher.push("return h.unique(n);\n}");\r
- eval(this.matcher.join('\n'));\r
- Selector._cache[this.expression] = this.matcher;\r
- },\r
-\r
- compileXPathMatcher: function() {\r
- var e = this.expression, ps = Selector.patterns,\r
- x = Selector.xpath, le, m;\r
-\r
- if (Selector._cache[e]) {\r
- this.xpath = Selector._cache[e]; return;\r
- }\r
-\r
- this.matcher = ['.//*'];\r
- while (e && le != e && (/\S/).test(e)) {\r
- le = e;\r
- for (var i in ps) {\r
- if (m = e.match(ps[i])) {\r
- this.matcher.push(Object.isFunction(x[i]) ? x[i](m) :\r
- new Template(x[i]).evaluate(m));\r
- e = e.replace(m[0], '');\r
- break;\r
- }\r
- }\r
- }\r
-\r
- this.xpath = this.matcher.join('');\r
- Selector._cache[this.expression] = this.xpath;\r
- },\r
-\r
- findElements: function(root) {\r
- root = root || document;\r
- if (this.xpath) return document._getElementsByXPath(this.xpath, root);\r
- return this.matcher(root);\r
- },\r
-\r
- match: function(element) {\r
- this.tokens = [];\r
-\r
- var e = this.expression, ps = Selector.patterns, as = Selector.assertions;\r
- var le, p, m;\r
-\r
- while (e && le !== e && (/\S/).test(e)) {\r
- le = e;\r
- for (var i in ps) {\r
- p = ps[i];\r
- if (m = e.match(p)) {\r
- // use the Selector.assertions methods unless the selector\r
- // is too complex.\r
- if (as[i]) {\r
- this.tokens.push([i, Object.clone(m)]);\r
- e = e.replace(m[0], '');\r
- } else {\r
- // reluctantly do a document-wide search\r
- // and look for a match in the array\r
- return this.findElements(document).include(element);\r
- }\r
- }\r
- }\r
- }\r
-\r
- var match = true, name, matches;\r
- for (var i = 0, token; token = this.tokens[i]; i++) {\r
- name = token[0], matches = token[1];\r
- if (!Selector.assertions[name](element, matches)) {\r
- match = false; break;\r
- }\r
- }\r
-\r
- return match;\r
- },\r
-\r
- toString: function() {\r
- return this.expression;\r
- },\r
-\r
- inspect: function() {\r
- return "#<Selector:" + this.expression.inspect() + ">";\r
- }\r
-});\r
-\r
-Object.extend(Selector, {\r
- _cache: { },\r
-\r
- xpath: {\r
- descendant: "//*",\r
- child: "/*",\r
- adjacent: "/following-sibling::*[1]",\r
- laterSibling: '/following-sibling::*',\r
- tagName: function(m) {\r
- if (m[1] == '*') return '';\r
- return "[local-name()='" + m[1].toLowerCase() +\r
- "' or local-name()='" + m[1].toUpperCase() + "']";\r
- },\r
- className: "[contains(concat(' ', @class, ' '), ' #{1} ')]",\r
- id: "[@id='#{1}']",\r
- attrPresence: function(m) {\r
- m[1] = m[1].toLowerCase();\r
- return new Template("[@#{1}]").evaluate(m);\r
- },\r
- attr: function(m) {\r
- m[1] = m[1].toLowerCase();\r
- m[3] = m[5] || m[6];\r
- return new Template(Selector.xpath.operators[m[2]]).evaluate(m);\r
- },\r
- pseudo: function(m) {\r
- var h = Selector.xpath.pseudos[m[1]];\r
- if (!h) return '';\r
- if (Object.isFunction(h)) return h(m);\r
- return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m);\r
- },\r
- operators: {\r
- '=': "[@#{1}='#{3}']",\r
- '!=': "[@#{1}!='#{3}']",\r
- '^=': "[starts-with(@#{1}, '#{3}')]",\r
- '$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']",\r
- '*=': "[contains(@#{1}, '#{3}')]",\r
- '~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]",\r
- '|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]"\r
- },\r
- pseudos: {\r
- 'first-child': '[not(preceding-sibling::*)]',\r
- 'last-child': '[not(following-sibling::*)]',\r
- 'only-child': '[not(preceding-sibling::* or following-sibling::*)]',\r
- 'empty': "[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]",\r
- 'checked': "[@checked]",\r
- 'disabled': "[@disabled]",\r
- 'enabled': "[not(@disabled)]",\r
- 'not': function(m) {\r
- var e = m[6], p = Selector.patterns,\r
- x = Selector.xpath, le, v;\r
-\r
- var exclusion = [];\r
- while (e && le != e && (/\S/).test(e)) {\r
- le = e;\r
- for (var i in p) {\r
- if (m = e.match(p[i])) {\r
- v = Object.isFunction(x[i]) ? x[i](m) : new Template(x[i]).evaluate(m);\r
- exclusion.push("(" + v.substring(1, v.length - 1) + ")");\r
- e = e.replace(m[0], '');\r
- break;\r
- }\r
- }\r
- }\r
- return "[not(" + exclusion.join(" and ") + ")]";\r
- },\r
- 'nth-child': function(m) {\r
- return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m);\r
- },\r
- 'nth-last-child': function(m) {\r
- return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m);\r
- },\r
- 'nth-of-type': function(m) {\r
- return Selector.xpath.pseudos.nth("position() ", m);\r
- },\r
- 'nth-last-of-type': function(m) {\r
- return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m);\r
- },\r
- 'first-of-type': function(m) {\r
- m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m);\r
- },\r
- 'last-of-type': function(m) {\r
- m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m);\r
- },\r
- 'only-of-type': function(m) {\r
- var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m);\r
- },\r
- nth: function(fragment, m) {\r
- var mm, formula = m[6], predicate;\r
- if (formula == 'even') formula = '2n+0';\r
- if (formula == 'odd') formula = '2n+1';\r
- if (mm = formula.match(/^(\d+)$/)) // digit only\r
- return '[' + fragment + "= " + mm[1] + ']';\r
- if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b\r
- if (mm[1] == "-") mm[1] = -1;\r
- var a = mm[1] ? Number(mm[1]) : 1;\r
- var b = mm[2] ? Number(mm[2]) : 0;\r
- predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " +\r
- "((#{fragment} - #{b}) div #{a} >= 0)]";\r
- return new Template(predicate).evaluate({\r
- fragment: fragment, a: a, b: b });\r
- }\r
- }\r
- }\r
- },\r
-\r
- criteria: {\r
- tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;',\r
- className: 'n = h.className(n, r, "#{1}", c); c = false;',\r
- id: 'n = h.id(n, r, "#{1}", c); c = false;',\r
- attrPresence: 'n = h.attrPresence(n, r, "#{1}", c); c = false;',\r
- attr: function(m) {\r
- m[3] = (m[5] || m[6]);\r
- return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;').evaluate(m);\r
- },\r
- pseudo: function(m) {\r
- if (m[6]) m[6] = m[6].replace(/"/g, '\\"');\r
- return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m);\r
- },\r
- descendant: 'c = "descendant";',\r
- child: 'c = "child";',\r
- adjacent: 'c = "adjacent";',\r
- laterSibling: 'c = "laterSibling";'\r
- },\r
-\r
- patterns: {\r
- // combinators must be listed first\r
- // (and descendant needs to be last combinator)\r
- laterSibling: /^\s*~\s*/,\r
- child: /^\s*>\s*/,\r
- adjacent: /^\s*\+\s*/,\r
- descendant: /^\s/,\r
-\r
- // selectors follow\r
- tagName: /^\s*(\*|[\w\-]+)(\b|$)?/,\r
- id: /^#([\w\-\*]+)(\b|$)/,\r
- className: /^\.([\w\-\*]+)(\b|$)/,\r
- pseudo:\r
-/^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/,\r
- attrPresence: /^\[([\w]+)\]/,\r
- attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/\r
- },\r
-\r
- // for Selector.match and Element#match\r
- assertions: {\r
- tagName: function(element, matches) {\r
- return matches[1].toUpperCase() == element.tagName.toUpperCase();\r
- },\r
-\r
- className: function(element, matches) {\r
- return Element.hasClassName(element, matches[1]);\r
- },\r
-\r
- id: function(element, matches) {\r
- return element.id === matches[1];\r
- },\r
-\r
- attrPresence: function(element, matches) {\r
- return Element.hasAttribute(element, matches[1]);\r
- },\r
-\r
- attr: function(element, matches) {\r
- var nodeValue = Element.readAttribute(element, matches[1]);\r
- return nodeValue && Selector.operators[matches[2]](nodeValue, matches[5] || matches[6]);\r
- }\r
- },\r
-\r
- handlers: {\r
- // UTILITY FUNCTIONS\r
- // joins two collections\r
- concat: function(a, b) {\r
- for (var i = 0, node; node = b[i]; i++)\r
- a.push(node);\r
- return a;\r
- },\r
-\r
- // marks an array of nodes for counting\r
- mark: function(nodes) {\r
- var _true = Prototype.emptyFunction;\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- node._countedByPrototype = _true;\r
- return nodes;\r
- },\r
-\r
- unmark: function(nodes) {\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- node._countedByPrototype = undefined;\r
- return nodes;\r
- },\r
-\r
- // mark each child node with its position (for nth calls)\r
- // "ofType" flag indicates whether we're indexing for nth-of-type\r
- // rather than nth-child\r
- index: function(parentNode, reverse, ofType) {\r
- parentNode._countedByPrototype = Prototype.emptyFunction;\r
- if (reverse) {\r
- for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {\r
- var node = nodes[i];\r
- if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;\r
- }\r
- } else {\r
- for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)\r
- if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;\r
- }\r
- },\r
-\r
- // filters out duplicates and extends all nodes\r
- unique: function(nodes) {\r
- if (nodes.length == 0) return nodes;\r
- var results = [], n;\r
- for (var i = 0, l = nodes.length; i < l; i++)\r
- if (!(n = nodes[i])._countedByPrototype) {\r
- n._countedByPrototype = Prototype.emptyFunction;\r
- results.push(Element.extend(n));\r
- }\r
- return Selector.handlers.unmark(results);\r
- },\r
-\r
- // COMBINATOR FUNCTIONS\r
- descendant: function(nodes) {\r
- var h = Selector.handlers;\r
- for (var i = 0, results = [], node; node = nodes[i]; i++)\r
- h.concat(results, node.getElementsByTagName('*'));\r
- return results;\r
- },\r
-\r
- child: function(nodes) {\r
- var h = Selector.handlers;\r
- for (var i = 0, results = [], node; node = nodes[i]; i++) {\r
- for (var j = 0, child; child = node.childNodes[j]; j++)\r
- if (child.nodeType == 1 && child.tagName != '!') results.push(child);\r
- }\r
- return results;\r
- },\r
-\r
- adjacent: function(nodes) {\r
- for (var i = 0, results = [], node; node = nodes[i]; i++) {\r
- var next = this.nextElementSibling(node);\r
- if (next) results.push(next);\r
- }\r
- return results;\r
- },\r
-\r
- laterSibling: function(nodes) {\r
- var h = Selector.handlers;\r
- for (var i = 0, results = [], node; node = nodes[i]; i++)\r
- h.concat(results, Element.nextSiblings(node));\r
- return results;\r
- },\r
-\r
- nextElementSibling: function(node) {\r
- while (node = node.nextSibling)\r
- if (node.nodeType == 1) return node;\r
- return null;\r
- },\r
-\r
- previousElementSibling: function(node) {\r
- while (node = node.previousSibling)\r
- if (node.nodeType == 1) return node;\r
- return null;\r
- },\r
-\r
- // TOKEN FUNCTIONS\r
- tagName: function(nodes, root, tagName, combinator) {\r
- var uTagName = tagName.toUpperCase();\r
- var results = [], h = Selector.handlers;\r
- if (nodes) {\r
- if (combinator) {\r
- // fastlane for ordinary descendant combinators\r
- if (combinator == "descendant") {\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- h.concat(results, node.getElementsByTagName(tagName));\r
- return results;\r
- } else nodes = this[combinator](nodes);\r
- if (tagName == "*") return nodes;\r
- }\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- if (node.tagName.toUpperCase() === uTagName) results.push(node);\r
- return results;\r
- } else return root.getElementsByTagName(tagName);\r
- },\r
-\r
- id: function(nodes, root, id, combinator) {\r
- var targetNode = $(id), h = Selector.handlers;\r
- if (!targetNode) return [];\r
- if (!nodes && root == document) return [targetNode];\r
- if (nodes) {\r
- if (combinator) {\r
- if (combinator == 'child') {\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- if (targetNode.parentNode == node) return [targetNode];\r
- } else if (combinator == 'descendant') {\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- if (Element.descendantOf(targetNode, node)) return [targetNode];\r
- } else if (combinator == 'adjacent') {\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- if (Selector.handlers.previousElementSibling(targetNode) == node)\r
- return [targetNode];\r
- } else nodes = h[combinator](nodes);\r
- }\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- if (node == targetNode) return [targetNode];\r
- return [];\r
- }\r
- return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : [];\r
- },\r
-\r
- className: function(nodes, root, className, combinator) {\r
- if (nodes && combinator) nodes = this[combinator](nodes);\r
- return Selector.handlers.byClassName(nodes, root, className);\r
- },\r
-\r
- byClassName: function(nodes, root, className) {\r
- if (!nodes) nodes = Selector.handlers.descendant([root]);\r
- var needle = ' ' + className + ' ';\r
- for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) {\r
- nodeClassName = node.className;\r
- if (nodeClassName.length == 0) continue;\r
- if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle))\r
- results.push(node);\r
- }\r
- return results;\r
- },\r
-\r
- attrPresence: function(nodes, root, attr, combinator) {\r
- if (!nodes) nodes = root.getElementsByTagName("*");\r
- if (nodes && combinator) nodes = this[combinator](nodes);\r
- var results = [];\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- if (Element.hasAttribute(node, attr)) results.push(node);\r
- return results;\r
- },\r
-\r
- attr: function(nodes, root, attr, value, operator, combinator) {\r
- if (!nodes) nodes = root.getElementsByTagName("*");\r
- if (nodes && combinator) nodes = this[combinator](nodes);\r
- var handler = Selector.operators[operator], results = [];\r
- for (var i = 0, node; node = nodes[i]; i++) {\r
- var nodeValue = Element.readAttribute(node, attr);\r
- if (nodeValue === null) continue;\r
- if (handler(nodeValue, value)) results.push(node);\r
- }\r
- return results;\r
- },\r
-\r
- pseudo: function(nodes, name, value, root, combinator) {\r
- if (nodes && combinator) nodes = this[combinator](nodes);\r
- if (!nodes) nodes = root.getElementsByTagName("*");\r
- return Selector.pseudos[name](nodes, value, root);\r
- }\r
- },\r
-\r
- pseudos: {\r
- 'first-child': function(nodes, value, root) {\r
- for (var i = 0, results = [], node; node = nodes[i]; i++) {\r
- if (Selector.handlers.previousElementSibling(node)) continue;\r
- results.push(node);\r
- }\r
- return results;\r
- },\r
- 'last-child': function(nodes, value, root) {\r
- for (var i = 0, results = [], node; node = nodes[i]; i++) {\r
- if (Selector.handlers.nextElementSibling(node)) continue;\r
- results.push(node);\r
- }\r
- return results;\r
- },\r
- 'only-child': function(nodes, value, root) {\r
- var h = Selector.handlers;\r
- for (var i = 0, results = [], node; node = nodes[i]; i++)\r
- if (!h.previousElementSibling(node) && !h.nextElementSibling(node))\r
- results.push(node);\r
- return results;\r
- },\r
- 'nth-child': function(nodes, formula, root) {\r
- return Selector.pseudos.nth(nodes, formula, root);\r
- },\r
- 'nth-last-child': function(nodes, formula, root) {\r
- return Selector.pseudos.nth(nodes, formula, root, true);\r
- },\r
- 'nth-of-type': function(nodes, formula, root) {\r
- return Selector.pseudos.nth(nodes, formula, root, false, true);\r
- },\r
- 'nth-last-of-type': function(nodes, formula, root) {\r
- return Selector.pseudos.nth(nodes, formula, root, true, true);\r
- },\r
- 'first-of-type': function(nodes, formula, root) {\r
- return Selector.pseudos.nth(nodes, "1", root, false, true);\r
- },\r
- 'last-of-type': function(nodes, formula, root) {\r
- return Selector.pseudos.nth(nodes, "1", root, true, true);\r
- },\r
- 'only-of-type': function(nodes, formula, root) {\r
- var p = Selector.pseudos;\r
- return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root);\r
- },\r
-\r
- // handles the an+b logic\r
- getIndices: function(a, b, total) {\r
- if (a == 0) return b > 0 ? [b] : [];\r
- return $R(1, total).inject([], function(memo, i) {\r
- if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i);\r
- return memo;\r
- });\r
- },\r
-\r
- // handles nth(-last)-child, nth(-last)-of-type, and (first|last)-of-type\r
- nth: function(nodes, formula, root, reverse, ofType) {\r
- if (nodes.length == 0) return [];\r
- if (formula == 'even') formula = '2n+0';\r
- if (formula == 'odd') formula = '2n+1';\r
- var h = Selector.handlers, results = [], indexed = [], m;\r
- h.mark(nodes);\r
- for (var i = 0, node; node = nodes[i]; i++) {\r
- if (!node.parentNode._countedByPrototype) {\r
- h.index(node.parentNode, reverse, ofType);\r
- indexed.push(node.parentNode);\r
- }\r
- }\r
- if (formula.match(/^\d+$/)) { // just a number\r
- formula = Number(formula);\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- if (node.nodeIndex == formula) results.push(node);\r
- } else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b\r
- if (m[1] == "-") m[1] = -1;\r
- var a = m[1] ? Number(m[1]) : 1;\r
- var b = m[2] ? Number(m[2]) : 0;\r
- var indices = Selector.pseudos.getIndices(a, b, nodes.length);\r
- for (var i = 0, node, l = indices.length; node = nodes[i]; i++) {\r
- for (var j = 0; j < l; j++)\r
- if (node.nodeIndex == indices[j]) results.push(node);\r
- }\r
- }\r
- h.unmark(nodes);\r
- h.unmark(indexed);\r
- return results;\r
- },\r
-\r
- 'empty': function(nodes, value, root) {\r
- for (var i = 0, results = [], node; node = nodes[i]; i++) {\r
- // IE treats comments as element nodes\r
- if (node.tagName == '!' || (node.firstChild && !node.innerHTML.match(/^\s*$/))) continue;\r
- results.push(node);\r
- }\r
- return results;\r
- },\r
-\r
- 'not': function(nodes, selector, root) {\r
- var h = Selector.handlers, selectorType, m;\r
- var exclusions = new Selector(selector).findElements(root);\r
- h.mark(exclusions);\r
- for (var i = 0, results = [], node; node = nodes[i]; i++)\r
- if (!node._countedByPrototype) results.push(node);\r
- h.unmark(exclusions);\r
- return results;\r
- },\r
-\r
- 'enabled': function(nodes, value, root) {\r
- for (var i = 0, results = [], node; node = nodes[i]; i++)\r
- if (!node.disabled) results.push(node);\r
- return results;\r
- },\r
-\r
- 'disabled': function(nodes, value, root) {\r
- for (var i = 0, results = [], node; node = nodes[i]; i++)\r
- if (node.disabled) results.push(node);\r
- return results;\r
- },\r
-\r
- 'checked': function(nodes, value, root) {\r
- for (var i = 0, results = [], node; node = nodes[i]; i++)\r
- if (node.checked) results.push(node);\r
- return results;\r
- }\r
- },\r
-\r
- operators: {\r
- '=': function(nv, v) { return nv == v; },\r
- '!=': function(nv, v) { return nv != v; },\r
- '^=': function(nv, v) { return nv.startsWith(v); },\r
- '$=': function(nv, v) { return nv.endsWith(v); },\r
- '*=': function(nv, v) { return nv.include(v); },\r
- '~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); },\r
- '|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); }\r
- },\r
-\r
- split: function(expression) {\r
- var expressions = [];\r
- expression.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {\r
- expressions.push(m[1].strip());\r
- });\r
- return expressions;\r
- },\r
-\r
- matchElements: function(elements, expression) {\r
- var matches = $$(expression), h = Selector.handlers;\r
- h.mark(matches);\r
- for (var i = 0, results = [], element; element = elements[i]; i++)\r
- if (element._countedByPrototype) results.push(element);\r
- h.unmark(matches);\r
- return results;\r
- },\r
-\r
- findElement: function(elements, expression, index) {\r
- if (Object.isNumber(expression)) {\r
- index = expression; expression = false;\r
- }\r
- return Selector.matchElements(elements, expression || '*')[index || 0];\r
- },\r
-\r
- findChildElements: function(element, expressions) {\r
- expressions = Selector.split(expressions.join(','));\r
- var results = [], h = Selector.handlers;\r
- for (var i = 0, l = expressions.length, selector; i < l; i++) {\r
- selector = new Selector(expressions[i].strip());\r
- h.concat(results, selector.findElements(element));\r
- }\r
- return (l > 1) ? h.unique(results) : results;\r
- }\r
-});\r
-\r
-if (Prototype.Browser.IE) {\r
- Object.extend(Selector.handlers, {\r
- // IE returns comment nodes on getElementsByTagName("*").\r
- // Filter them out.\r
- concat: function(a, b) {\r
- for (var i = 0, node; node = b[i]; i++)\r
- if (node.tagName !== "!") a.push(node);\r
- return a;\r
- },\r
-\r
- // IE improperly serializes _countedByPrototype in (inner|outer)HTML.\r
- unmark: function(nodes) {\r
- for (var i = 0, node; node = nodes[i]; i++)\r
- node.removeAttribute('_countedByPrototype');\r
- return nodes;\r
- }\r
- });\r
-}\r
-\r
-function $$() {\r
- return Selector.findChildElements(document, $A(arguments));\r
-}\r
-var Form = {\r
- reset: function(form) {\r
- $(form).reset();\r
- return form;\r
- },\r
-\r
- serializeElements: function(elements, options) {\r
- if (typeof options != 'object') options = { hash: !!options };\r
- else if (Object.isUndefined(options.hash)) options.hash = true;\r
- var key, value, submitted = false, submit = options.submit;\r
-\r
- var data = elements.inject({ }, function(result, element) {\r
- if (!element.disabled && element.name) {\r
- key = element.name; value = $(element).getValue();\r
- if (value != null && (element.type != 'submit' || (!submitted &&\r
- submit !== false && (!submit || key == submit) && (submitted = true)))) {\r
- if (key in result) {\r
- // a key is already present; construct an array of values\r
- if (!Object.isArray(result[key])) result[key] = [result[key]];\r
- result[key].push(value);\r
- }\r
- else result[key] = value;\r
- }\r
- }\r
- return result;\r
- });\r
-\r
- return options.hash ? data : Object.toQueryString(data);\r
- }\r
-};\r
-\r
-Form.Methods = {\r
- serialize: function(form, options) {\r
- return Form.serializeElements(Form.getElements(form), options);\r
- },\r
-\r
- getElements: function(form) {\r
- return $A($(form).getElementsByTagName('*')).inject([],\r
- function(elements, child) {\r
- if (Form.Element.Serializers[child.tagName.toLowerCase()])\r
- elements.push(Element.extend(child));\r
- return elements;\r
- }\r
- );\r
- },\r
-\r
- getInputs: function(form, typeName, name) {\r
- form = $(form);\r
- var inputs = form.getElementsByTagName('input');\r
-\r
- if (!typeName && !name) return $A(inputs).map(Element.extend);\r
-\r
- for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {\r
- var input = inputs[i];\r
- if ((typeName && input.type != typeName) || (name && input.name != name))\r
- continue;\r
- matchingInputs.push(Element.extend(input));\r
- }\r
-\r
- return matchingInputs;\r
- },\r
-\r
- disable: function(form) {\r
- form = $(form);\r
- Form.getElements(form).invoke('disable');\r
- return form;\r
- },\r
-\r
- enable: function(form) {\r
- form = $(form);\r
- Form.getElements(form).invoke('enable');\r
- return form;\r
- },\r
-\r
- findFirstElement: function(form) {\r
- var elements = $(form).getElements().findAll(function(element) {\r
- return 'hidden' != element.type && !element.disabled;\r
- });\r
- var firstByIndex = elements.findAll(function(element) {\r
- return element.hasAttribute('tabIndex') && element.tabIndex >= 0;\r
- }).sortBy(function(element) { return element.tabIndex }).first();\r
-\r
- return firstByIndex ? firstByIndex : elements.find(function(element) {\r
- return ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());\r
- });\r
- },\r
-\r
- focusFirstElement: function(form) {\r
- form = $(form);\r
- form.findFirstElement().activate();\r
- return form;\r
- },\r
-\r
- request: function(form, options) {\r
- form = $(form), options = Object.clone(options || { });\r
-\r
- var params = options.parameters, action = form.readAttribute('action') || '';\r
- if (action.blank()) action = window.location.href;\r
- options.parameters = form.serialize(true);\r
-\r
- if (params) {\r
- if (Object.isString(params)) params = params.toQueryParams();\r
- Object.extend(options.parameters, params);\r
- }\r
-\r
- if (form.hasAttribute('method') && !options.method)\r
- options.method = form.method;\r
-\r
- return new Ajax.Request(action, options);\r
- }\r
-};\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-Form.Element = {\r
- focus: function(element) {\r
- $(element).focus();\r
- return element;\r
- },\r
-\r
- select: function(element) {\r
- $(element).select();\r
- return element;\r
- }\r
-};\r
-\r
-Form.Element.Methods = {\r
- serialize: function(element) {\r
- element = $(element);\r
- if (!element.disabled && element.name) {\r
- var value = element.getValue();\r
- if (value != undefined) {\r
- var pair = { };\r
- pair[element.name] = value;\r
- return Object.toQueryString(pair);\r
- }\r
- }\r
- return '';\r
- },\r
-\r
- getValue: function(element) {\r
- element = $(element);\r
- var method = element.tagName.toLowerCase();\r
- return Form.Element.Serializers[method](element);\r
- },\r
-\r
- setValue: function(element, value) {\r
- element = $(element);\r
- var method = element.tagName.toLowerCase();\r
- Form.Element.Serializers[method](element, value);\r
- return element;\r
- },\r
-\r
- clear: function(element) {\r
- $(element).value = '';\r
- return element;\r
- },\r
-\r
- present: function(element) {\r
- return $(element).value != '';\r
- },\r
-\r
- activate: function(element) {\r
- element = $(element);\r
- try {\r
- element.focus();\r
- if (element.select && (element.tagName.toLowerCase() != 'input' ||\r
- !['button', 'reset', 'submit'].include(element.type)))\r
- element.select();\r
- } catch (e) { }\r
- return element;\r
- },\r
-\r
- disable: function(element) {\r
- element = $(element);\r
- element.blur();\r
- element.disabled = true;\r
- return element;\r
- },\r
-\r
- enable: function(element) {\r
- element = $(element);\r
- element.disabled = false;\r
- return element;\r
- }\r
-};\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-var Field = Form.Element;\r
-var $F = Form.Element.Methods.getValue;\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-Form.Element.Serializers = {\r
- input: function(element, value) {\r
- switch (element.type.toLowerCase()) {\r
- case 'checkbox':\r
- case 'radio':\r
- return Form.Element.Serializers.inputSelector(element, value);\r
- default:\r
- return Form.Element.Serializers.textarea(element, value);\r
- }\r
- },\r
-\r
- inputSelector: function(element, value) {\r
- if (Object.isUndefined(value)) return element.checked ? element.value : null;\r
- else element.checked = !!value;\r
- },\r
-\r
- textarea: function(element, value) {\r
- if (Object.isUndefined(value)) return element.value;\r
- else element.value = value;\r
- },\r
-\r
- select: function(element, index) {\r
- if (Object.isUndefined(index))\r
- return this[element.type == 'select-one' ?\r
- 'selectOne' : 'selectMany'](element);\r
- else {\r
- var opt, value, single = !Object.isArray(index);\r
- for (var i = 0, length = element.length; i < length; i++) {\r
- opt = element.options[i];\r
- value = this.optionValue(opt);\r
- if (single) {\r
- if (value == index) {\r
- opt.selected = true;\r
- return;\r
- }\r
- }\r
- else opt.selected = index.include(value);\r
- }\r
- }\r
- },\r
-\r
- selectOne: function(element) {\r
- var index = element.selectedIndex;\r
- return index >= 0 ? this.optionValue(element.options[index]) : null;\r
- },\r
-\r
- selectMany: function(element) {\r
- var values, length = element.length;\r
- if (!length) return null;\r
-\r
- for (var i = 0, values = []; i < length; i++) {\r
- var opt = element.options[i];\r
- if (opt.selected) values.push(this.optionValue(opt));\r
- }\r
- return values;\r
- },\r
-\r
- optionValue: function(opt) {\r
- // extend element because hasAttribute may not be native\r
- return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;\r
- }\r
-};\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-Abstract.TimedObserver = Class.create(PeriodicalExecuter, {\r
- initialize: function($super, element, frequency, callback) {\r
- $super(callback, frequency);\r
- this.element = $(element);\r
- this.lastValue = this.getValue();\r
- },\r
-\r
- execute: function() {\r
- var value = this.getValue();\r
- if (Object.isString(this.lastValue) && Object.isString(value) ?\r
- this.lastValue != value : String(this.lastValue) != String(value)) {\r
- this.callback(this.element, value);\r
- this.lastValue = value;\r
- }\r
- }\r
-});\r
-\r
-Form.Element.Observer = Class.create(Abstract.TimedObserver, {\r
- getValue: function() {\r
- return Form.Element.getValue(this.element);\r
- }\r
-});\r
-\r
-Form.Observer = Class.create(Abstract.TimedObserver, {\r
- getValue: function() {\r
- return Form.serialize(this.element);\r
- }\r
-});\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-Abstract.EventObserver = Class.create({\r
- initialize: function(element, callback) {\r
- this.element = $(element);\r
- this.callback = callback;\r
-\r
- this.lastValue = this.getValue();\r
- if (this.element.tagName.toLowerCase() == 'form')\r
- this.registerFormCallbacks();\r
- else\r
- this.registerCallback(this.element);\r
- },\r
-\r
- onElementEvent: function() {\r
- var value = this.getValue();\r
- if (this.lastValue != value) {\r
- this.callback(this.element, value);\r
- this.lastValue = value;\r
- }\r
- },\r
-\r
- registerFormCallbacks: function() {\r
- Form.getElements(this.element).each(this.registerCallback, this);\r
- },\r
-\r
- registerCallback: function(element) {\r
- if (element.type) {\r
- switch (element.type.toLowerCase()) {\r
- case 'checkbox':\r
- case 'radio':\r
- Event.observe(element, 'click', this.onElementEvent.bind(this));\r
- break;\r
- default:\r
- Event.observe(element, 'change', this.onElementEvent.bind(this));\r
- break;\r
- }\r
- }\r
- }\r
-});\r
-\r
-Form.Element.EventObserver = Class.create(Abstract.EventObserver, {\r
- getValue: function() {\r
- return Form.Element.getValue(this.element);\r
- }\r
-});\r
-\r
-Form.EventObserver = Class.create(Abstract.EventObserver, {\r
- getValue: function() {\r
- return Form.serialize(this.element);\r
- }\r
-});\r
-if (!window.Event) var Event = { };\r
-\r
-Object.extend(Event, {\r
- KEY_BACKSPACE: 8,\r
- KEY_TAB: 9,\r
- KEY_RETURN: 13,\r
- KEY_ESC: 27,\r
- KEY_LEFT: 37,\r
- KEY_UP: 38,\r
- KEY_RIGHT: 39,\r
- KEY_DOWN: 40,\r
- KEY_DELETE: 46,\r
- KEY_HOME: 36,\r
- KEY_END: 35,\r
- KEY_PAGEUP: 33,\r
- KEY_PAGEDOWN: 34,\r
- KEY_INSERT: 45,\r
-\r
- cache: { },\r
-\r
- relatedTarget: function(event) {\r
- var element;\r
- switch(event.type) {\r
- case 'mouseover': element = event.fromElement; break;\r
- case 'mouseout': element = event.toElement; break;\r
- default: return null;\r
- }\r
- return Element.extend(element);\r
- }\r
-});\r
-\r
-Event.Methods = (function() {\r
- var isButton;\r
-\r
- if (Prototype.Browser.IE) {\r
- var buttonMap = { 0: 1, 1: 4, 2: 2 };\r
- isButton = function(event, code) {\r
- return event.button == buttonMap[code];\r
- };\r
-\r
- } else if (Prototype.Browser.WebKit) {\r
- isButton = function(event, code) {\r
- switch (code) {\r
- case 0: return event.which == 1 && !event.metaKey;\r
- case 1: return event.which == 1 && event.metaKey;\r
- default: return false;\r
- }\r
- };\r
-\r
- } else {\r
- isButton = function(event, code) {\r
- return event.which ? (event.which === code + 1) : (event.button === code);\r
- };\r
- }\r
-\r
- return {\r
- isLeftClick: function(event) { return isButton(event, 0) },\r
- isMiddleClick: function(event) { return isButton(event, 1) },\r
- isRightClick: function(event) { return isButton(event, 2) },\r
-\r
- element: function(event) {\r
- var node = Event.extend(event).target;\r
- return Element.extend(node.nodeType == Node.TEXT_NODE ? node.parentNode : node);\r
- },\r
-\r
- findElement: function(event, expression) {\r
- var element = Event.element(event);\r
- if (!expression) return element;\r
- var elements = [element].concat(element.ancestors());\r
- return Selector.findElement(elements, expression, 0);\r
- },\r
-\r
- pointer: function(event) {\r
- return {\r
- x: event.pageX || (event.clientX +\r
- (document.documentElement.scrollLeft || document.body.scrollLeft)),\r
- y: event.pageY || (event.clientY +\r
- (document.documentElement.scrollTop || document.body.scrollTop))\r
- };\r
- },\r
-\r
- pointerX: function(event) { return Event.pointer(event).x },\r
- pointerY: function(event) { return Event.pointer(event).y },\r
-\r
- stop: function(event) {\r
- Event.extend(event);\r
- event.preventDefault();\r
- event.stopPropagation();\r
- event.stopped = true;\r
- }\r
- };\r
-})();\r
-\r
-Event.extend = (function() {\r
- var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {\r
- m[name] = Event.Methods[name].methodize();\r
- return m;\r
- });\r
-\r
- if (Prototype.Browser.IE) {\r
- Object.extend(methods, {\r
- stopPropagation: function() { this.cancelBubble = true },\r
- preventDefault: function() { this.returnValue = false },\r
- inspect: function() { return "[object Event]" }\r
- });\r
-\r
- return function(event) {\r
- if (!event) return false;\r
- if (event._extendedByPrototype) return event;\r
-\r
- event._extendedByPrototype = Prototype.emptyFunction;\r
- var pointer = Event.pointer(event);\r
- Object.extend(event, {\r
- target: event.srcElement,\r
- relatedTarget: Event.relatedTarget(event),\r
- pageX: pointer.x,\r
- pageY: pointer.y\r
- });\r
- return Object.extend(event, methods);\r
- };\r
-\r
- } else {\r
- Event.prototype = Event.prototype || document.createEvent("HTMLEvents").__proto__;\r
- Object.extend(Event.prototype, methods);\r
- return Prototype.K;\r
- }\r
-})();\r
-\r
-Object.extend(Event, (function() {\r
- var cache = Event.cache;\r
-\r
- function getEventID(element) {\r
- if (element._prototypeEventID) return element._prototypeEventID[0];\r
- arguments.callee.id = arguments.callee.id || 1;\r
- return element._prototypeEventID = [++arguments.callee.id];\r
- }\r
-\r
- function getDOMEventName(eventName) {\r
- if (eventName && eventName.include(':')) return "dataavailable";\r
- return eventName;\r
- }\r
-\r
- function getCacheForID(id) {\r
- return cache[id] = cache[id] || { };\r
- }\r
-\r
- function getWrappersForEventName(id, eventName) {\r
- var c = getCacheForID(id);\r
- return c[eventName] = c[eventName] || [];\r
- }\r
-\r
- function createWrapper(element, eventName, handler) {\r
- var id = getEventID(element);\r
- var c = getWrappersForEventName(id, eventName);\r
- if (c.pluck("handler").include(handler)) return false;\r
-\r
- var wrapper = function(event) {\r
- if (!Event || !Event.extend ||\r
- (event.eventName && event.eventName != eventName))\r
- return false;\r
-\r
- Event.extend(event);\r
- handler.call(element, event);\r
- };\r
-\r
- wrapper.handler = handler;\r
- c.push(wrapper);\r
- return wrapper;\r
- }\r
-\r
- function findWrapper(id, eventName, handler) {\r
- var c = getWrappersForEventName(id, eventName);\r
- return c.find(function(wrapper) { return wrapper.handler == handler });\r
- }\r
-\r
- function destroyWrapper(id, eventName, handler) {\r
- var c = getCacheForID(id);\r
- if (!c[eventName]) return false;\r
- c[eventName] = c[eventName].without(findWrapper(id, eventName, handler));\r
- }\r
-\r
- function destroyCache() {\r
- for (var id in cache)\r
- for (var eventName in cache[id])\r
- cache[id][eventName] = null;\r
- }\r
-\r
- if (window.attachEvent) {\r
- window.attachEvent("onunload", destroyCache);\r
- }\r
-\r
- return {\r
- observe: function(element, eventName, handler) {\r
- element = $(element);\r
- var name = getDOMEventName(eventName);\r
-\r
- var wrapper = createWrapper(element, eventName, handler);\r
- if (!wrapper) return element;\r
-\r
- if (element.addEventListener) {\r
- element.addEventListener(name, wrapper, false);\r
- } else {\r
- element.attachEvent("on" + name, wrapper);\r
- }\r
-\r
- return element;\r
- },\r
-\r
- stopObserving: function(element, eventName, handler) {\r
- element = $(element);\r
- var id = getEventID(element), name = getDOMEventName(eventName);\r
-\r
- if (!handler && eventName) {\r
- getWrappersForEventName(id, eventName).each(function(wrapper) {\r
- element.stopObserving(eventName, wrapper.handler);\r
- });\r
- return element;\r
-\r
- } else if (!eventName) {\r
- Object.keys(getCacheForID(id)).each(function(eventName) {\r
- element.stopObserving(eventName);\r
- });\r
- return element;\r
- }\r
-\r
- var wrapper = findWrapper(id, eventName, handler);\r
- if (!wrapper) return element;\r
-\r
- if (element.removeEventListener) {\r
- element.removeEventListener(name, wrapper, false);\r
- } else {\r
- element.detachEvent("on" + name, wrapper);\r
- }\r
-\r
- destroyWrapper(id, eventName, handler);\r
-\r
- return element;\r
- },\r
-\r
- fire: function(element, eventName, memo) {\r
- element = $(element);\r
- if (element == document && document.createEvent && !element.dispatchEvent)\r
- element = document.documentElement;\r
-\r
- var event;\r
- if (document.createEvent) {\r
- event = document.createEvent("HTMLEvents");\r
- event.initEvent("dataavailable", true, true);\r
- } else {\r
- event = document.createEventObject();\r
- event.eventType = "ondataavailable";\r
- }\r
-\r
- event.eventName = eventName;\r
- event.memo = memo || { };\r
-\r
- if (document.createEvent) {\r
- element.dispatchEvent(event);\r
- } else {\r
- element.fireEvent(event.eventType, event);\r
- }\r
-\r
- return Event.extend(event);\r
- }\r
- };\r
-})());\r
-\r
-Object.extend(Event, Event.Methods);\r
-\r
-Element.addMethods({\r
- fire: Event.fire,\r
- observe: Event.observe,\r
- stopObserving: Event.stopObserving\r
-});\r
-\r
-Object.extend(document, {\r
- fire: Element.Methods.fire.methodize(),\r
- observe: Element.Methods.observe.methodize(),\r
- stopObserving: Element.Methods.stopObserving.methodize(),\r
- loaded: false\r
-});\r
-\r
-(function() {\r
- /* Support for the DOMContentLoaded event is based on work by Dan Webb,\r
- Matthias Miller, Dean Edwards and John Resig. */\r
-\r
- var timer;\r
-\r
- function fireContentLoadedEvent() {\r
- if (document.loaded) return;\r
- if (timer) window.clearInterval(timer);\r
- document.fire("dom:loaded");\r
- document.loaded = true;\r
- }\r
-\r
- if (document.addEventListener) {\r
- if (Prototype.Browser.WebKit) {\r
- timer = window.setInterval(function() {\r
- if (/loaded|complete/.test(document.readyState))\r
- fireContentLoadedEvent();\r
- }, 0);\r
-\r
- Event.observe(window, "load", fireContentLoadedEvent);\r
-\r
- } else {\r
- document.addEventListener("DOMContentLoaded",\r
- fireContentLoadedEvent, false);\r
- }\r
-\r
- } else {\r
- document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>");\r
- $("__onDOMContentLoaded").onreadystatechange = function() {\r
- if (this.readyState == "complete") {\r
- this.onreadystatechange = null;\r
- fireContentLoadedEvent();\r
- }\r
- };\r
- }\r
-})();\r
-/*------------------------------- DEPRECATED -------------------------------*/\r
-\r
-Hash.toQueryString = Object.toQueryString;\r
-\r
-var Toggle = { display: Element.toggle };\r
-\r
-Element.Methods.childOf = Element.Methods.descendantOf;\r
-\r
-var Insertion = {\r
- Before: function(element, content) {\r
- return Element.insert(element, {before:content});\r
- },\r
-\r
- Top: function(element, content) {\r
- return Element.insert(element, {top:content});\r
- },\r
-\r
- Bottom: function(element, content) {\r
- return Element.insert(element, {bottom:content});\r
- },\r
-\r
- After: function(element, content) {\r
- return Element.insert(element, {after:content});\r
- }\r
-};\r
-\r
-var $continue = new Error('"throw $continue" is deprecated, use "return" instead');\r
-\r
-// This should be moved to script.aculo.us; notice the deprecated methods\r
-// further below, that map to the newer Element methods.\r
-var Position = {\r
- // set to true if needed, warning: firefox performance problems\r
- // NOT neeeded for page scrolling, only if draggable contained in\r
- // scrollable elements\r
- includeScrollOffsets: false,\r
-\r
- // must be called before calling withinIncludingScrolloffset, every time the\r
- // page is scrolled\r
- prepare: function() {\r
- this.deltaX = window.pageXOffset\r
- || document.documentElement.scrollLeft\r
- || document.body.scrollLeft\r
- || 0;\r
- this.deltaY = window.pageYOffset\r
- || document.documentElement.scrollTop\r
- || document.body.scrollTop\r
- || 0;\r
- },\r
-\r
- // caches x/y coordinate pair to use with overlap\r
- within: function(element, x, y) {\r
- if (this.includeScrollOffsets)\r
- return this.withinIncludingScrolloffsets(element, x, y);\r
- this.xcomp = x;\r
- this.ycomp = y;\r
- this.offset = Element.cumulativeOffset(element);\r
-\r
- return (y >= this.offset[1] &&\r
- y < this.offset[1] + element.offsetHeight &&\r
- x >= this.offset[0] &&\r
- x < this.offset[0] + element.offsetWidth);\r
- },\r
-\r
- withinIncludingScrolloffsets: function(element, x, y) {\r
- var offsetcache = Element.cumulativeScrollOffset(element);\r
-\r
- this.xcomp = x + offsetcache[0] - this.deltaX;\r
- this.ycomp = y + offsetcache[1] - this.deltaY;\r
- this.offset = Element.cumulativeOffset(element);\r
-\r
- return (this.ycomp >= this.offset[1] &&\r
- this.ycomp < this.offset[1] + element.offsetHeight &&\r
- this.xcomp >= this.offset[0] &&\r
- this.xcomp < this.offset[0] + element.offsetWidth);\r
- },\r
-\r
- // within must be called directly before\r
- overlap: function(mode, element) {\r
- if (!mode) return 0;\r
- if (mode == 'vertical')\r
- return ((this.offset[1] + element.offsetHeight) - this.ycomp) /\r
- element.offsetHeight;\r
- if (mode == 'horizontal')\r
- return ((this.offset[0] + element.offsetWidth) - this.xcomp) /\r
- element.offsetWidth;\r
- },\r
-\r
- // Deprecation layer -- use newer Element methods now (1.5.2).\r
-\r
- cumulativeOffset: Element.Methods.cumulativeOffset,\r
-\r
- positionedOffset: Element.Methods.positionedOffset,\r
-\r
- absolutize: function(element) {\r
- Position.prepare();\r
- return Element.absolutize(element);\r
- },\r
-\r
- relativize: function(element) {\r
- Position.prepare();\r
- return Element.relativize(element);\r
- },\r
-\r
- realOffset: Element.Methods.cumulativeScrollOffset,\r
-\r
- offsetParent: Element.Methods.getOffsetParent,\r
-\r
- page: Element.Methods.viewportOffset,\r
-\r
- clone: function(source, target, options) {\r
- options = options || { };\r
- return Element.clonePosition(target, source, options);\r
- }\r
-};\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){\r
- function iter(name) {\r
- return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";\r
- }\r
-\r
- instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?\r
- function(element, className) {\r
- className = className.toString().strip();\r
- var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);\r
- return cond ? document._getElementsByXPath('.//*' + cond, element) : [];\r
- } : function(element, className) {\r
- className = className.toString().strip();\r
- var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);\r
- if (!classNames && !className) return elements;\r
-\r
- var nodes = $(element).getElementsByTagName('*');\r
- className = ' ' + className + ' ';\r
-\r
- for (var i = 0, child, cn; child = nodes[i]; i++) {\r
- if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||\r
- (classNames && classNames.all(function(name) {\r
- return !name.toString().blank() && cn.include(' ' + name + ' ');\r
- }))))\r
- elements.push(Element.extend(child));\r
- }\r
- return elements;\r
- };\r
-\r
- return function(className, parentElement) {\r
- return $(parentElement || document.body).getElementsByClassName(className);\r
- };\r
-}(Element.Methods);\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-Element.ClassNames = Class.create();\r
-Element.ClassNames.prototype = {\r
- initialize: function(element) {\r
- this.element = $(element);\r
- },\r
-\r
- _each: function(iterator) {\r
- this.element.className.split(/\s+/).select(function(name) {\r
- return name.length > 0;\r
- })._each(iterator);\r
- },\r
-\r
- set: function(className) {\r
- this.element.className = className;\r
- },\r
-\r
- add: function(classNameToAdd) {\r
- if (this.include(classNameToAdd)) return;\r
- this.set($A(this).concat(classNameToAdd).join(' '));\r
- },\r
-\r
- remove: function(classNameToRemove) {\r
- if (!this.include(classNameToRemove)) return;\r
- this.set($A(this).without(classNameToRemove).join(' '));\r
- },\r
-\r
- toString: function() {\r
- return $A(this).join(' ');\r
- }\r
-};\r
-\r
-Object.extend(Element.ClassNames.prototype, Enumerable);\r
-\r
-/*--------------------------------------------------------------------------*/\r
-\r
-Element.addMethods();
\ No newline at end of file