You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by br...@apache.org on 2006/12/23 07:39:58 UTC
svn commit: r489860 [16/17] - in /maven/archiva/trunk: archiva-applet/
archiva-applet/src/main/java/org/apache/maven/archiva/applet/ archiva-cli/
archiva-cli/src/main/assembly/
archiva-cli/src/main/java/org/apache/maven/archiva/cli/
archiva-configurati...
Modified: maven/archiva/trunk/archiva-webapp/src/main/webapp/js/scriptaculous/prototype.js
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/webapp/js/scriptaculous/prototype.js?view=diff&rev=489860&r1=489859&r2=489860
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/webapp/js/scriptaculous/prototype.js (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/webapp/js/scriptaculous/prototype.js Fri Dec 22 22:39:46 2006
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
/* Prototype JavaScript framework, version 1.5.0_rc1
* (c) 2005 Sam Stephenson <sa...@conio.net>
*
@@ -7,260 +26,325 @@
/*--------------------------------------------------------------------------*/
var Prototype = {
- Version: '1.5.0_rc1',
- ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',
+ Version: '1.5.0_rc1',
+ ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',
- emptyFunction: function() {},
- K: function(x) {return x}
+ emptyFunction: function()
+ {
+ },
+ K: function( x )
+ {
+ return x
+ }
}
var Class = {
- create: function() {
- return function() {
- this.initialize.apply(this, arguments);
+ create: function()
+ {
+ return function()
+ {
+ this.initialize.apply(this, arguments);
+ }
}
- }
}
var Abstract = new Object();
-Object.extend = function(destination, source) {
- for (var property in source) {
- destination[property] = source[property];
- }
- return destination;
+Object.extend = function( destination, source )
+{
+ for ( var property in source )
+ {
+ destination[property] = source[property];
+ }
+ return destination;
}
Object.extend(Object, {
- inspect: function(object) {
- try {
- if (object == undefined) return 'undefined';
- if (object == null) return 'null';
- return object.inspect ? object.inspect() : object.toString();
- } catch (e) {
- if (e instanceof RangeError) return '...';
- throw e;
- }
- },
-
- keys: function(object) {
- var keys = [];
- for (var property in object)
- keys.push(property);
- return keys;
- },
-
- values: function(object) {
- var values = [];
- for (var property in object)
- values.push(object[property]);
- return values;
- },
-
- clone: function(object) {
- return Object.extend({}, object);
- }
+ inspect: function( object )
+ {
+ try
+ {
+ if ( object == undefined ) return 'undefined';
+ if ( object == null ) return 'null';
+ return object.inspect ? object.inspect() : object.toString();
+ }
+ catch ( e )
+ {
+ if ( e instanceof RangeError ) return '...';
+ throw e;
+ }
+ },
+
+ keys: function( object )
+ {
+ var keys = [];
+ for ( var property in object )
+ keys.push(property);
+ return keys;
+ },
+
+ values: function( object )
+ {
+ var values = [];
+ for ( var property in object )
+ values.push(object[property]);
+ return values;
+ },
+
+ clone: function( object )
+ {
+ return Object.extend({}, object);
+ }
});
-Function.prototype.bind = function() {
- var __method = this, args = $A(arguments), object = args.shift();
- return function() {
- return __method.apply(object, args.concat($A(arguments)));
- }
+Function.prototype.bind = function()
+{
+ var __method = this, args = $A(arguments), object = args.shift();
+ return function()
+ {
+ return __method.apply(object, args.concat($A(arguments)));
+ }
}
-Function.prototype.bindAsEventListener = function(object) {
- var __method = this, args = $A(arguments), object = args.shift();
- return function(event) {
- return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));
- }
+Function.prototype.bindAsEventListener = function( object )
+{
+ var __method = this, args = $A(arguments), object = args.shift();
+ return function( event )
+ {
+ return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));
+ }
}
Object.extend(Number.prototype, {
- toColorPart: function() {
- var digits = this.toString(16);
- if (this < 16) return '0' + digits;
- return digits;
- },
-
- succ: function() {
- return this + 1;
- },
-
- times: function(iterator) {
- $R(0, this, true).each(iterator);
- return this;
- }
+ toColorPart: function()
+ {
+ var digits = this.toString(16);
+ if ( this < 16 ) return '0' + digits;
+ return digits;
+ },
+
+ succ: function()
+ {
+ return this + 1;
+ },
+
+ times: function( iterator )
+ {
+ $R(0, this, true).each(iterator);
+ return this;
+ }
});
var Try = {
- these: function() {
- var returnValue;
+ these: function()
+ {
+ var returnValue;
+
+ for ( var i = 0; i < arguments.length; i++ )
+ {
+ var lambda = arguments[i];
+ try
+ {
+ returnValue = lambda();
+ break;
+ }
+ catch ( e )
+ {
+ }
+ }
- for (var i = 0; i < arguments.length; i++) {
- var lambda = arguments[i];
- try {
- returnValue = lambda();
- break;
- } catch (e) {}
+ return returnValue;
}
-
- return returnValue;
- }
}
/*--------------------------------------------------------------------------*/
var PeriodicalExecuter = Class.create();
PeriodicalExecuter.prototype = {
- initialize: function(callback, frequency) {
- this.callback = callback;
- this.frequency = frequency;
- this.currentlyExecuting = false;
-
- this.registerCallback();
- },
-
- registerCallback: function() {
- this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
- },
-
- stop: function() {
- if (!this.timer) return;
- clearInterval(this.timer);
- this.timer = null;
- },
-
- onTimerEvent: function() {
- if (!this.currentlyExecuting) {
- try {
- this.currentlyExecuting = true;
- this.callback(this);
- } finally {
+ initialize: function( callback, frequency )
+ {
+ this.callback = callback;
+ this.frequency = frequency;
this.currentlyExecuting = false;
- }
+
+ this.registerCallback();
+ },
+
+ registerCallback: function()
+ {
+ this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
+ },
+
+ stop: function()
+ {
+ if ( !this.timer ) return;
+ clearInterval(this.timer);
+ this.timer = null;
+ },
+
+ onTimerEvent: function()
+ {
+ if ( !this.currentlyExecuting )
+ {
+ try
+ {
+ this.currentlyExecuting = true;
+ this.callback(this);
+ }
+ finally
+ {
+ this.currentlyExecuting = false;
+ }
+ }
}
- }
}
Object.extend(String.prototype, {
- gsub: function(pattern, replacement) {
- var result = '', source = this, match;
- replacement = arguments.callee.prepareReplacement(replacement);
-
- while (source.length > 0) {
- if (match = source.match(pattern)) {
- result += source.slice(0, match.index);
- result += (replacement(match) || '').toString();
- source = source.slice(match.index + match[0].length);
- } else {
- result += source, source = '';
- }
- }
- return result;
- },
-
- sub: function(pattern, replacement, count) {
- replacement = this.gsub.prepareReplacement(replacement);
- count = count === undefined ? 1 : count;
-
- return this.gsub(pattern, function(match) {
- if (--count < 0) return match[0];
- return replacement(match);
- });
- },
-
- scan: function(pattern, iterator) {
- this.gsub(pattern, iterator);
- return this;
- },
-
- truncate: function(length, truncation) {
- length = length || 30;
- truncation = truncation === undefined ? '...' : truncation;
- return this.length > length ?
- this.slice(0, length - truncation.length) + truncation : this;
- },
-
- strip: function() {
- return this.replace(/^\s+/, '').replace(/\s+$/, '');
- },
-
- stripTags: function() {
- return this.replace(/<\/?[^>]+>/gi, '');
- },
-
- stripScripts: function() {
- return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
- },
-
- extractScripts: function() {
- var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
- var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
- return (this.match(matchAll) || []).map(function(scriptTag) {
- return (scriptTag.match(matchOne) || ['', ''])[1];
- });
- },
+ gsub: function( pattern, replacement )
+ {
+ var result = '', source = this, match;
+ replacement = arguments.callee.prepareReplacement(replacement);
+
+ while ( source.length > 0 )
+ {
+ if ( match = source.match(pattern) )
+ {
+ result += source.slice(0, match.index);
+ result += (replacement(match) || '').toString();
+ source = source.slice(match.index + match[0].length);
+ }
+ else
+ {
+ result += source,source = '';
+ }
+ }
+ return result;
+ },
- evalScripts: function() {
- return this.extractScripts().map(function(script) { return eval(script) });
- },
-
- escapeHTML: function() {
- var div = document.createElement('div');
- var text = document.createTextNode(this);
- div.appendChild(text);
- return div.innerHTML;
- },
-
- unescapeHTML: function() {
- var div = document.createElement('div');
- div.innerHTML = this.stripTags();
- return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
- },
-
- toQueryParams: function() {
- var pairs = this.match(/^\??(.*)$/)[1].split('&');
- return pairs.inject({}, function(params, pairString) {
- var pair = pairString.split('=');
- var value = pair[1] ? decodeURIComponent(pair[1]) : undefined;
- params[decodeURIComponent(pair[0])] = value;
- return params;
- });
- },
+ sub: function( pattern, replacement, count )
+ {
+ replacement = this.gsub.prepareReplacement(replacement);
+ count = count === undefined ? 1 : count;
+
+ return this.gsub(pattern, function( match )
+ {
+ if ( --count < 0 ) return match[0];
+ return replacement(match);
+ });
+ },
- toArray: function() {
- return this.split('');
- },
+ scan: function( pattern, iterator )
+ {
+ this.gsub(pattern, iterator);
+ return this;
+ },
+
+ truncate: function( length, truncation )
+ {
+ length = length || 30;
+ truncation = truncation === undefined ? '...' : truncation;
+ return this.length > length ? this.slice(0, length - truncation.length) + truncation : this;
+ },
+
+ strip: function()
+ {
+ return this.replace(/^\s+/, '').replace(/\s+$/, '');
+ },
+
+ stripTags: function()
+ {
+ return this.replace(/<\/?[^>]+>/gi, '');
+ },
+
+ stripScripts: function()
+ {
+ return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
+ },
+
+ extractScripts: function()
+ {
+ var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
+ var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
+ return (this.match(matchAll) || []).map(function( scriptTag )
+ {
+ return (scriptTag.match(matchOne) || ['', ''])[1];
+ });
+ },
- camelize: function() {
- var oStringList = this.split('-');
- if (oStringList.length == 1) return oStringList[0];
+ evalScripts: function()
+ {
+ return this.extractScripts().map(function( script )
+ {
+ return eval(script)
+ });
+ },
- var camelizedString = this.indexOf('-') == 0
- ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1)
- : oStringList[0];
+ escapeHTML: function()
+ {
+ var div = document.createElement('div');
+ var text = document.createTextNode(this);
+ div.appendChild(text);
+ return div.innerHTML;
+ },
+
+ unescapeHTML: function()
+ {
+ var div = document.createElement('div');
+ div.innerHTML = this.stripTags();
+ return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
+ },
+
+ toQueryParams: function()
+ {
+ var pairs = this.match(/^\??(.*)$/)[1].split('&');
+ return pairs.inject({}, function( params, pairString )
+ {
+ var pair = pairString.split('=');
+ var value = pair[1] ? decodeURIComponent(pair[1]) : undefined;
+ params[decodeURIComponent(pair[0])] = value;
+ return params;
+ });
+ },
- for (var i = 1, len = oStringList.length; i < len; i++) {
- var s = oStringList[i];
- camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
- }
+ toArray: function()
+ {
+ return this.split('');
+ },
+
+ camelize: function()
+ {
+ var oStringList = this.split('-');
+ if ( oStringList.length == 1 ) return oStringList[0];
+
+ var camelizedString = this.indexOf('-') == 0 ? oStringList[0].charAt(0).toUpperCase() +
+ oStringList[0].substring(1) : oStringList[0];
+
+ for ( var i = 1, len = oStringList.length; i < len; i++ )
+ {
+ var s = oStringList[i];
+ camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
+ }
- return camelizedString;
- },
+ return camelizedString;
+ },
- inspect: function(useDoubleQuotes) {
- var escapedString = this.replace(/\\/g, '\\\\');
- if (useDoubleQuotes)
- return '"' + escapedString.replace(/"/g, '\\"') + '"';
- else
- return "'" + escapedString.replace(/'/g, '\\\'') + "'";
- }
+ inspect: function( useDoubleQuotes )
+ {
+ var escapedString = this.replace(/\\/g, '\\\\');
+ if ( useDoubleQuotes )
+ return '"' + escapedString.replace(/"/g, '\\"') + '"';
+ else
+ return "'" + escapedString.replace(/'/g, '\\\'') + "'";
+ }
});
-String.prototype.gsub.prepareReplacement = function(replacement) {
- if (typeof replacement == 'function') return replacement;
- var template = new Template(replacement);
- return function(match) { return template.evaluate(match) };
+String.prototype.gsub.prepareReplacement = function( replacement )
+{
+ if ( typeof replacement == 'function' ) return replacement;
+ var template = new Template(replacement);
+ return function( match )
+ {
+ return template.evaluate(match)
+ };
}
String.prototype.parseQuery = String.prototype.toQueryParams;
@@ -268,1061 +352,1291 @@
var Template = Class.create();
Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
Template.prototype = {
- initialize: function(template, pattern) {
- this.template = template.toString();
- this.pattern = pattern || Template.Pattern;
- },
-
- evaluate: function(object) {
- return this.template.gsub(this.pattern, function(match) {
- var before = match[1];
- if (before == '\\') return match[2];
- return before + (object[match[3]] || '').toString();
- });
- }
+ initialize: function( template, pattern )
+ {
+ this.template = template.toString();
+ this.pattern = pattern || Template.Pattern;
+ },
+
+ evaluate: function( object )
+ {
+ return this.template.gsub(this.pattern, function( match )
+ {
+ var before = match[1];
+ if ( before == '\\' ) return match[2];
+ return before + (object[match[3]] || '').toString();
+ });
+ }
}
-var $break = new Object();
+var $break = new Object();
var $continue = new Object();
var Enumerable = {
- each: function(iterator) {
- var index = 0;
- try {
- this._each(function(value) {
- try {
- iterator(value, index++);
- } catch (e) {
- if (e != $continue) throw e;
- }
- });
- } catch (e) {
- if (e != $break) throw e;
- }
- },
-
- all: function(iterator) {
- var result = true;
- this.each(function(value, index) {
- result = result && !!(iterator || Prototype.K)(value, index);
- if (!result) throw $break;
- });
- return result;
- },
+ each: function( iterator )
+ {
+ var index = 0;
+ try
+ {
+ this._each(function( value )
+ {
+ try
+ {
+ iterator(value, index++);
+ }
+ catch ( e )
+ {
+ if ( e != $continue ) throw e;
+ }
+ });
+ }
+ catch ( e )
+ {
+ if ( e != $break ) throw e;
+ }
+ },
- any: function(iterator) {
- var result = false;
- this.each(function(value, index) {
- if (result = !!(iterator || Prototype.K)(value, index))
- throw $break;
- });
- return result;
- },
+ all: function( iterator )
+ {
+ var result = true;
+ this.each(function( value, index )
+ {
+ result = result && !!(iterator || Prototype.K)(value, index);
+ if ( !result ) throw $break;
+ });
+ return result;
+ },
- collect: function(iterator) {
- var results = [];
- this.each(function(value, index) {
- results.push(iterator(value, index));
- });
- return results;
- },
+ any: function( iterator )
+ {
+ var result = false;
+ this.each(function( value, index )
+ {
+ if ( result = !!(iterator || Prototype.K)(value, index) )
+ throw $break;
+ });
+ return result;
+ },
- detect: function (iterator) {
- var result;
- this.each(function(value, index) {
- if (iterator(value, index)) {
- result = value;
- throw $break;
- }
- });
- return result;
- },
+ collect: function( iterator )
+ {
+ var results = [];
+ this.each(function( value, index )
+ {
+ results.push(iterator(value, index));
+ });
+ return results;
+ },
- findAll: function(iterator) {
- var results = [];
- this.each(function(value, index) {
- if (iterator(value, index))
- results.push(value);
- });
- return results;
- },
+ detect: function ( iterator )
+ {
+ var result;
+ this.each(function( value, index )
+ {
+ if ( iterator(value, index) )
+ {
+ result = value;
+ throw $break;
+ }
+ });
+ return result;
+ },
- grep: function(pattern, iterator) {
- var results = [];
- this.each(function(value, index) {
- var stringValue = value.toString();
- if (stringValue.match(pattern))
- results.push((iterator || Prototype.K)(value, index));
- })
- return results;
- },
-
- include: function(object) {
- var found = false;
- this.each(function(value) {
- if (value == object) {
- found = true;
- throw $break;
- }
- });
- return found;
- },
+ findAll: function( iterator )
+ {
+ var results = [];
+ this.each(function( value, index )
+ {
+ if ( iterator(value, index) )
+ results.push(value);
+ });
+ return results;
+ },
- inject: function(memo, iterator) {
- this.each(function(value, index) {
- memo = iterator(memo, value, index);
- });
- return memo;
- },
+ grep: function( pattern, iterator )
+ {
+ var results = [];
+ this.each(function( value, index )
+ {
+ var stringValue = value.toString();
+ if ( stringValue.match(pattern) )
+ results.push((iterator || Prototype.K)(value, index));
+ })
+ return results;
+ },
+
+ include: function( object )
+ {
+ var found = false;
+ this.each(function( value )
+ {
+ if ( value == object )
+ {
+ found = true;
+ throw $break;
+ }
+ });
+ return found;
+ },
- invoke: function(method) {
- var args = $A(arguments).slice(1);
- return this.collect(function(value) {
- return value[method].apply(value, args);
- });
- },
+ inject: function( memo, iterator )
+ {
+ this.each(function( value, index )
+ {
+ memo = iterator(memo, value, index);
+ });
+ return memo;
+ },
- max: function(iterator) {
- var result;
- this.each(function(value, index) {
- value = (iterator || Prototype.K)(value, index);
- if (result == undefined || value >= result)
- result = value;
- });
- return result;
- },
+ invoke: function( method )
+ {
+ var args = $A(arguments).slice(1);
+ return this.collect(function( value )
+ {
+ return value[method].apply(value, args);
+ });
+ },
- min: function(iterator) {
- var result;
- this.each(function(value, index) {
- value = (iterator || Prototype.K)(value, index);
- if (result == undefined || value < result)
- result = value;
- });
- return result;
- },
+ max: function( iterator )
+ {
+ var result;
+ this.each(function( value, index )
+ {
+ value = (iterator || Prototype.K)(value, index);
+ if ( result == undefined || value >= result )
+ result = value;
+ });
+ return result;
+ },
- partition: function(iterator) {
- var trues = [], falses = [];
- this.each(function(value, index) {
- ((iterator || Prototype.K)(value, index) ?
- trues : falses).push(value);
- });
- return [trues, falses];
- },
+ min: function( iterator )
+ {
+ var result;
+ this.each(function( value, index )
+ {
+ value = (iterator || Prototype.K)(value, index);
+ if ( result == undefined || value < result )
+ result = value;
+ });
+ return result;
+ },
- pluck: function(property) {
- var results = [];
- this.each(function(value, index) {
- results.push(value[property]);
- });
- return results;
- },
+ partition: function( iterator )
+ {
+ var trues = [], falses = [];
+ this.each(function( value, index )
+ {
+ ((iterator || Prototype.K)(value, index) ? trues : falses).push(value);
+ });
+ return [trues, falses];
+ },
- reject: function(iterator) {
- var results = [];
- this.each(function(value, index) {
- if (!iterator(value, index))
- results.push(value);
- });
- return results;
- },
+ pluck: function( property )
+ {
+ var results = [];
+ this.each(function( value, index )
+ {
+ results.push(value[property]);
+ });
+ return results;
+ },
- sortBy: function(iterator) {
- return this.collect(function(value, index) {
- return {value: value, criteria: iterator(value, index)};
- }).sort(function(left, right) {
- var a = left.criteria, b = right.criteria;
- return a < b ? -1 : a > b ? 1 : 0;
- }).pluck('value');
- },
-
- toArray: function() {
- return this.collect(Prototype.K);
- },
-
- zip: function() {
- var iterator = Prototype.K, args = $A(arguments);
- if (typeof args.last() == 'function')
- iterator = args.pop();
-
- var collections = [this].concat(args).map($A);
- return this.map(function(value, index) {
- return iterator(collections.pluck(index));
- });
- },
+ reject: function( iterator )
+ {
+ var results = [];
+ this.each(function( value, index )
+ {
+ if ( !iterator(value, index) )
+ results.push(value);
+ });
+ return results;
+ },
+
+ sortBy: function( iterator )
+ {
+ return this.collect(function( value, index )
+ {
+ return {value: value, criteria: iterator(value, index)};
+ }).sort(function( left, right )
+ {
+ var a = left.criteria, b = right.criteria;
+ return a < b ? -1 : a > b ? 1 : 0;
+ }).pluck('value');
+ },
+
+ toArray: function()
+ {
+ return this.collect(Prototype.K);
+ },
+
+ zip: function()
+ {
+ var iterator = Prototype.K, args = $A(arguments);
+ if ( typeof args.last() == 'function' )
+ iterator = args.pop();
+
+ var collections = [this].concat(args).map($A);
+ return this.map(function( value, index )
+ {
+ return iterator(collections.pluck(index));
+ });
+ },
- inspect: function() {
- return '#<Enumerable:' + this.toArray().inspect() + '>';
- }
+ inspect: function()
+ {
+ return '#<Enumerable:' + this.toArray().inspect() + '>';
+ }
}
Object.extend(Enumerable, {
- map: Enumerable.collect,
- find: Enumerable.detect,
- select: Enumerable.findAll,
- member: Enumerable.include,
- entries: Enumerable.toArray
+ map: Enumerable.collect,
+ find: Enumerable.detect,
+ select: Enumerable.findAll,
+ member: Enumerable.include,
+ entries: Enumerable.toArray
});
-var $A = Array.from = function(iterable) {
- if (!iterable) return [];
- if (iterable.toArray) {
- return iterable.toArray();
- } else {
- var results = [];
- for (var i = 0; i < iterable.length; i++)
- results.push(iterable[i]);
- return results;
- }
+var $A = Array.from = function( iterable )
+{
+ if ( !iterable ) return [];
+ if ( iterable.toArray )
+ {
+ return iterable.toArray();
+ }
+ else
+ {
+ var results = [];
+ for ( var i = 0; i < iterable.length; i++ )
+ results.push(iterable[i]);
+ return results;
+ }
}
Object.extend(Array.prototype, Enumerable);
-if (!Array.prototype._reverse)
- Array.prototype._reverse = Array.prototype.reverse;
+if ( !Array.prototype._reverse )
+ Array.prototype._reverse = Array.prototype.reverse;
Object.extend(Array.prototype, {
- _each: function(iterator) {
- for (var i = 0; i < this.length; i++)
- iterator(this[i]);
- },
-
- clear: function() {
- this.length = 0;
- return this;
- },
-
- first: function() {
- return this[0];
- },
-
- last: function() {
- return this[this.length - 1];
- },
-
- compact: function() {
- return this.select(function(value) {
- return value != undefined || value != null;
- });
- },
+ _each: function( iterator )
+ {
+ for ( var i = 0; i < this.length; i++ )
+ iterator(this[i]);
+ },
+
+ clear: function()
+ {
+ this.length = 0;
+ return this;
+ },
+
+ first: function()
+ {
+ return this[0];
+ },
+
+ last: function()
+ {
+ return this[this.length - 1];
+ },
+
+ compact: function()
+ {
+ return this.select(function( value )
+ {
+ return value != undefined || value != null;
+ });
+ },
- flatten: function() {
- return this.inject([], function(array, value) {
- return array.concat(value && value.constructor == Array ?
- value.flatten() : [value]);
- });
- },
+ flatten: function()
+ {
+ return this.inject([], function( array, value )
+ {
+ return array.concat(value && value.constructor == Array ? value.flatten() : [value]);
+ });
+ },
- without: function() {
- var values = $A(arguments);
- return this.select(function(value) {
- return !values.include(value);
- });
- },
+ without: function()
+ {
+ var values = $A(arguments);
+ return this.select(function( value )
+ {
+ return !values.include(value);
+ });
+ },
- indexOf: function(object) {
- for (var i = 0; i < this.length; i++)
- if (this[i] == object) return i;
- return -1;
- },
-
- reverse: function(inline) {
- return (inline !== false ? this : this.toArray())._reverse();
- },
-
- reduce: function() {
- return this.length > 1 ? this : this[0];
- },
-
- uniq: function() {
- return this.inject([], function(array, value) {
- return array.include(value) ? array : array.concat([value]);
- });
- },
+ indexOf: function( object )
+ {
+ for ( var i = 0; i < this.length; i++ )
+ if ( this[i] == object ) return i;
+ return -1;
+ },
+
+ reverse: function( inline )
+ {
+ return (inline !== false ? this : this.toArray())._reverse();
+ },
+
+ reduce: function()
+ {
+ return this.length > 1 ? this : this[0];
+ },
+
+ uniq: function()
+ {
+ return this.inject([], function( array, value )
+ {
+ return array.include(value) ? array : array.concat([value]);
+ });
+ },
- inspect: function() {
- return '[' + this.map(Object.inspect).join(', ') + ']';
- }
+ inspect: function()
+ {
+ return '[' + this.map(Object.inspect).join(', ') + ']';
+ }
});
var Hash = {
- _each: function(iterator) {
- for (var key in this) {
- var value = this[key];
- if (typeof value == 'function') continue;
-
- var pair = [key, value];
- pair.key = key;
- pair.value = value;
- iterator(pair);
- }
- },
-
- keys: function() {
- return this.pluck('key');
- },
-
- values: function() {
- return this.pluck('value');
- },
-
- merge: function(hash) {
- return $H(hash).inject($H(this), function(mergedHash, pair) {
- mergedHash[pair.key] = pair.value;
- return mergedHash;
- });
- },
+ _each: function( iterator )
+ {
+ for ( var key in this )
+ {
+ var value = this[key];
+ if ( typeof value == 'function' ) continue;
+
+ var pair = [key, value];
+ pair.key = key;
+ pair.value = value;
+ iterator(pair);
+ }
+ },
- toQueryString: function() {
- return this.map(function(pair) {
- return pair.map(encodeURIComponent).join('=');
- }).join('&');
- },
-
- inspect: function() {
- return '#<Hash:{' + this.map(function(pair) {
- return pair.map(Object.inspect).join(': ');
- }).join(', ') + '}>';
- }
-}
-
-function $H(object) {
- var hash = Object.extend({}, object || {});
- Object.extend(hash, Enumerable);
- Object.extend(hash, Hash);
- return hash;
+ keys: function()
+ {
+ return this.pluck('key');
+ },
+
+ values: function()
+ {
+ return this.pluck('value');
+ },
+
+ merge: function( hash )
+ {
+ return $H(hash).inject($H(this), function( mergedHash, pair )
+ {
+ mergedHash[pair.key] = pair.value;
+ return mergedHash;
+ });
+ },
+
+ toQueryString: function()
+ {
+ return this.map(function( pair )
+ {
+ return pair.map(encodeURIComponent).join('=');
+ }).join('&');
+ },
+
+ inspect: function()
+ {
+ return '#<Hash:{' + this.map(function( pair )
+ {
+ return pair.map(Object.inspect).join(': ');
+ }).join(', ') + '}>';
+ }
+}
+
+function $H( object )
+{
+ var hash = Object.extend({}, object || {});
+ Object.extend(hash, Enumerable);
+ Object.extend(hash, Hash);
+ return hash;
}
ObjectRange = Class.create();
Object.extend(ObjectRange.prototype, Enumerable);
Object.extend(ObjectRange.prototype, {
- initialize: function(start, end, exclusive) {
- this.start = start;
- this.end = end;
- this.exclusive = exclusive;
- },
-
- _each: function(iterator) {
- var value = this.start;
- while (this.include(value)) {
- iterator(value);
- value = value.succ();
- }
- },
-
- include: function(value) {
- if (value < this.start)
- return false;
- if (this.exclusive)
- return value < this.end;
- return value <= this.end;
- }
+ initialize: function( start, end, exclusive )
+ {
+ this.start = start;
+ this.end = end;
+ this.exclusive = exclusive;
+ },
+
+ _each: function( iterator )
+ {
+ var value = this.start;
+ while ( this.include(value) )
+ {
+ iterator(value);
+ value = value.succ();
+ }
+ },
+
+ include: function( value )
+ {
+ if ( value < this.start )
+ return false;
+ if ( this.exclusive )
+ return value < this.end;
+ return value <= this.end;
+ }
});
-var $R = function(start, end, exclusive) {
- return new ObjectRange(start, end, exclusive);
+var $R = function( start, end, exclusive )
+{
+ return new ObjectRange(start, end, exclusive);
}
var Ajax = {
- getTransport: function() {
- return Try.these(
- function() {return new XMLHttpRequest()},
- function() {return new ActiveXObject('Msxml2.XMLHTTP')},
- function() {return new ActiveXObject('Microsoft.XMLHTTP')}
- ) || false;
- },
+ getTransport: function()
+ {
+ return Try.these(function()
+ {
+ return new XMLHttpRequest()
+ }, function()
+ {
+ return new ActiveXObject('Msxml2.XMLHTTP')
+ }, function()
+ {
+ return new ActiveXObject('Microsoft.XMLHTTP')
+ }) || false;
+ },
- activeRequestCount: 0
+ activeRequestCount: 0
}
Ajax.Responders = {
- responders: [],
+ responders: [],
- _each: function(iterator) {
- this.responders._each(iterator);
- },
-
- register: function(responderToAdd) {
- if (!this.include(responderToAdd))
- this.responders.push(responderToAdd);
- },
-
- unregister: function(responderToRemove) {
- this.responders = this.responders.without(responderToRemove);
- },
-
- dispatch: function(callback, request, transport, json) {
- this.each(function(responder) {
- if (responder[callback] && typeof responder[callback] == 'function') {
- try {
- responder[callback].apply(responder, [request, transport, json]);
- } catch (e) {}
- }
- });
- }
+ _each: function( iterator )
+ {
+ this.responders._each(iterator);
+ },
+
+ register: function( responderToAdd )
+ {
+ if ( !this.include(responderToAdd) )
+ this.responders.push(responderToAdd);
+ },
+
+ unregister: function( responderToRemove )
+ {
+ this.responders = this.responders.without(responderToRemove);
+ },
+
+ dispatch: function( callback, request, transport, json )
+ {
+ this.each(function( responder )
+ {
+ if ( responder[callback] && typeof responder[callback] == 'function' )
+ {
+ try
+ {
+ responder[callback].apply(responder, [request, transport, json]);
+ }
+ catch ( e )
+ {
+ }
+ }
+ });
+ }
};
Object.extend(Ajax.Responders, Enumerable);
Ajax.Responders.register({
- onCreate: function() {
- Ajax.activeRequestCount++;
- },
-
- onComplete: function() {
- Ajax.activeRequestCount--;
- }
+ onCreate: function()
+ {
+ Ajax.activeRequestCount++;
+ },
+
+ onComplete: function()
+ {
+ Ajax.activeRequestCount--;
+ }
});
-Ajax.Base = function() {};
+Ajax.Base = function()
+{
+};
Ajax.Base.prototype = {
- setOptions: function(options) {
- this.options = {
- method: 'post',
- asynchronous: true,
- contentType: 'application/x-www-form-urlencoded',
- parameters: ''
- }
- Object.extend(this.options, options || {});
- },
-
- responseIsSuccess: function() {
- return this.transport.status == undefined
- || this.transport.status == 0
- || (this.transport.status >= 200 && this.transport.status < 300);
- },
-
- responseIsFailure: function() {
- return !this.responseIsSuccess();
- }
+ setOptions: function( options )
+ {
+ this.options = {
+ method: 'post',
+ asynchronous: true,
+ contentType: 'application/x-www-form-urlencoded',
+ parameters: ''
+ }
+ Object.extend(this.options, options || {});
+ },
+
+ responseIsSuccess: function()
+ {
+ return this.transport.status == undefined || this.transport.status == 0 ||
+ (this.transport.status >= 200 && this.transport.status < 300);
+ },
+
+ responseIsFailure: function()
+ {
+ return !this.responseIsSuccess();
+ }
}
Ajax.Request = Class.create();
-Ajax.Request.Events =
- ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
+Ajax.Request.Events = ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
- initialize: function(url, options) {
- this.transport = Ajax.getTransport();
- this.setOptions(options);
- this.request(url);
- },
-
- request: function(url) {
- var parameters = this.options.parameters || '';
- if (parameters.length > 0) parameters += '&_=';
-
- /* Simulate other verbs over post */
- if (this.options.method != 'get' && this.options.method != 'post') {
- parameters += (parameters.length > 0 ? '&' : '') + '_method=' + this.options.method;
- this.options.method = 'post';
- }
-
- try {
- this.url = url;
- if (this.options.method == 'get' && parameters.length > 0)
- this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;
-
- Ajax.Responders.dispatch('onCreate', this, this.transport);
-
- this.transport.open(this.options.method, this.url,
- this.options.asynchronous);
-
- if (this.options.asynchronous)
- setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);
-
- this.transport.onreadystatechange = this.onStateChange.bind(this);
- this.setRequestHeaders();
-
- var body = this.options.postBody ? this.options.postBody : parameters;
- this.transport.send(this.options.method == 'post' ? body : null);
-
- /* Force Firefox to handle ready state 4 for synchronous requests */
- if (!this.options.asynchronous && this.transport.overrideMimeType)
- this.onStateChange();
-
- } catch (e) {
- this.dispatchException(e);
- }
- },
-
- setRequestHeaders: function() {
- var requestHeaders =
- ['X-Requested-With', 'XMLHttpRequest',
- 'X-Prototype-Version', Prototype.Version,
- 'Accept', 'text/javascript, text/html, application/xml, text/xml, */*'];
-
- if (this.options.method == 'post') {
- requestHeaders.push('Content-type', this.options.contentType);
-
- /* Force "Connection: close" for Mozilla browsers to work around
- * a bug where XMLHttpReqeuest sends an incorrect Content-length
- * header. See Mozilla Bugzilla #246651.
- */
- if (this.transport.overrideMimeType)
- requestHeaders.push('Connection', 'close');
- }
-
- if (this.options.requestHeaders)
- requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);
-
- for (var i = 0; i < requestHeaders.length; i += 2)
- this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
- },
-
- onStateChange: function() {
- var readyState = this.transport.readyState;
- if (readyState != 1)
- this.respondToReadyState(this.transport.readyState);
- },
-
- header: function(name) {
- try {
- return this.transport.getResponseHeader(name);
- } catch (e) {}
- },
-
- evalJSON: function() {
- try {
- return eval('(' + this.header('X-JSON') + ')');
- } catch (e) {}
- },
-
- evalResponse: function() {
- try {
- return eval(this.transport.responseText);
- } catch (e) {
- this.dispatchException(e);
- }
- },
-
- respondToReadyState: function(readyState) {
- var event = Ajax.Request.Events[readyState];
- var transport = this.transport, json = this.evalJSON();
-
- if (event == 'Complete') {
- try {
- (this.options['on' + this.transport.status]
- || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
- || Prototype.emptyFunction)(transport, json);
- } catch (e) {
- this.dispatchException(e);
- }
-
- if ((this.header('Content-type') || '').match(/^text\/javascript/i))
- this.evalResponse();
- }
-
- try {
- (this.options['on' + event] || Prototype.emptyFunction)(transport, json);
- Ajax.Responders.dispatch('on' + event, this, transport, json);
- } catch (e) {
- this.dispatchException(e);
- }
-
- /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
- if (event == 'Complete')
- this.transport.onreadystatechange = Prototype.emptyFunction;
- },
-
- dispatchException: function(exception) {
- (this.options.onException || Prototype.emptyFunction)(this, exception);
- Ajax.Responders.dispatch('onException', this, exception);
- }
+ initialize: function( url, options )
+ {
+ this.transport = Ajax.getTransport();
+ this.setOptions(options);
+ this.request(url);
+ },
+
+ request: function( url )
+ {
+ var parameters = this.options.parameters || '';
+ if ( parameters.length > 0 ) parameters += '&_=';
+
+ /* Simulate other verbs over post */
+ if ( this.options.method != 'get' && this.options.method != 'post' )
+ {
+ parameters += (parameters.length > 0 ? '&' : '') + '_method=' + this.options.method;
+ this.options.method = 'post';
+ }
+
+ try
+ {
+ this.url = url;
+ if ( this.options.method == 'get' && parameters.length > 0 )
+ this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;
+
+ Ajax.Responders.dispatch('onCreate', this, this.transport);
+
+ this.transport.open(this.options.method, this.url, this.options.asynchronous);
+
+ if ( this.options.asynchronous )
+ setTimeout(function()
+ {
+ this.respondToReadyState(1)
+ }.bind(this), 10);
+
+ this.transport.onreadystatechange = this.onStateChange.bind(this);
+ this.setRequestHeaders();
+
+ var body = this.options.postBody ? this.options.postBody : parameters;
+ this.transport.send(this.options.method == 'post' ? body : null);
+
+ /* Force Firefox to handle ready state 4 for synchronous requests */
+ if ( !this.options.asynchronous && this.transport.overrideMimeType )
+ this.onStateChange();
+
+ }
+ catch ( e )
+ {
+ this.dispatchException(e);
+ }
+ },
+
+ setRequestHeaders: function()
+ {
+ var requestHeaders = ['X-Requested-With', 'XMLHttpRequest',
+ 'X-Prototype-Version', Prototype.Version,
+ 'Accept', 'text/javascript, text/html, application/xml, text/xml, */*'];
+
+ if ( this.options.method == 'post' )
+ {
+ requestHeaders.push('Content-type', this.options.contentType);
+
+ /* Force "Connection: close" for Mozilla browsers to work around
+ * a bug where XMLHttpReqeuest sends an incorrect Content-length
+ * header. See Mozilla Bugzilla #246651.
+ */
+ if ( this.transport.overrideMimeType )
+ requestHeaders.push('Connection', 'close');
+ }
+
+ if ( this.options.requestHeaders )
+ requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);
+
+ for ( var i = 0; i < requestHeaders.length; i += 2 )
+ this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i + 1]);
+ },
+
+ onStateChange: function()
+ {
+ var readyState = this.transport.readyState;
+ if ( readyState != 1 )
+ this.respondToReadyState(this.transport.readyState);
+ },
+
+ header: function( name )
+ {
+ try
+ {
+ return this.transport.getResponseHeader(name);
+ }
+ catch ( e )
+ {
+ }
+ },
+
+ evalJSON: function()
+ {
+ try
+ {
+ return eval('(' + this.header('X-JSON') + ')');
+ }
+ catch ( e )
+ {
+ }
+ },
+
+ evalResponse: function()
+ {
+ try
+ {
+ return eval(this.transport.responseText);
+ }
+ catch ( e )
+ {
+ this.dispatchException(e);
+ }
+ },
+
+ respondToReadyState: function( readyState )
+ {
+ var event = Ajax.Request.Events[readyState];
+ var transport = this.transport, json = this.evalJSON();
+
+ if ( event == 'Complete' )
+ {
+ try
+ {
+ (this.options['on' + this.transport.status] ||
+ this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] ||
+ Prototype.emptyFunction)(transport, json);
+ }
+ catch ( e )
+ {
+ this.dispatchException(e);
+ }
+
+ if ( (this.header('Content-type') || '').match(/^text\/javascript/i) )
+ this.evalResponse();
+ }
+
+ try
+ {
+ (this.options['on' + event] || Prototype.emptyFunction)(transport, json);
+ Ajax.Responders.dispatch('on' + event, this, transport, json);
+ }
+ catch ( e )
+ {
+ this.dispatchException(e);
+ }
+
+ /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
+ if ( event == 'Complete' )
+ this.transport.onreadystatechange = Prototype.emptyFunction;
+ },
+
+ dispatchException: function( exception )
+ {
+ (this.options.onException || Prototype.emptyFunction)(this, exception);
+ Ajax.Responders.dispatch('onException', this, exception);
+ }
});
Ajax.Updater = Class.create();
Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
- initialize: function(container, url, options) {
- this.containers = {
- success: container.success ? $(container.success) : $(container),
- failure: container.failure ? $(container.failure) :
- (container.success ? null : $(container))
- }
-
- this.transport = Ajax.getTransport();
- this.setOptions(options);
-
- var onComplete = this.options.onComplete || Prototype.emptyFunction;
- this.options.onComplete = (function(transport, object) {
- this.updateContent();
- onComplete(transport, object);
- }).bind(this);
-
- this.request(url);
- },
-
- updateContent: function() {
- var receiver = this.responseIsSuccess() ?
- this.containers.success : this.containers.failure;
- var response = this.transport.responseText;
-
- if (!this.options.evalScripts)
- response = response.stripScripts();
-
- if (receiver) {
- if (this.options.insertion) {
- new this.options.insertion(receiver, response);
- } else {
- Element.update(receiver, response);
- }
- }
-
- if (this.responseIsSuccess()) {
- if (this.onComplete)
- setTimeout(this.onComplete.bind(this), 10);
+ initialize: function( container, url, options )
+ {
+ this.containers = {
+ success: container.success ? $(container.success) : $(container),
+ failure: container.failure ? $(container.failure) : (container.success ? null : $(container))
+ }
+
+ this.transport = Ajax.getTransport();
+ this.setOptions(options);
+
+ var onComplete = this.options.onComplete || Prototype.emptyFunction;
+ this.options.onComplete = (function( transport, object )
+ {
+ this.updateContent();
+ onComplete(transport, object);
+ }).bind(this);
+
+ this.request(url);
+ },
+
+ updateContent: function()
+ {
+ var receiver = this.responseIsSuccess() ? this.containers.success : this.containers.failure;
+ var response = this.transport.responseText;
+
+ if ( !this.options.evalScripts )
+ response = response.stripScripts();
+
+ if ( receiver )
+ {
+ if ( this.options.insertion )
+ {
+ new this.options.insertion(receiver, response);
+ }
+ else
+ {
+ Element.update(receiver, response);
+ }
+ }
+
+ if ( this.responseIsSuccess() )
+ {
+ if ( this.onComplete )
+ setTimeout(this.onComplete.bind(this), 10);
+ }
}
- }
});
Ajax.PeriodicalUpdater = Class.create();
Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), {
- initialize: function(container, url, options) {
- this.setOptions(options);
- this.onComplete = this.options.onComplete;
-
- this.frequency = (this.options.frequency || 2);
- this.decay = (this.options.decay || 1);
-
- this.updater = {};
- this.container = container;
- this.url = url;
-
- this.start();
- },
-
- start: function() {
- this.options.onComplete = this.updateComplete.bind(this);
- this.onTimerEvent();
- },
-
- stop: function() {
- this.updater.options.onComplete = undefined;
- clearTimeout(this.timer);
- (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
- },
-
- updateComplete: function(request) {
- if (this.options.decay) {
- this.decay = (request.responseText == this.lastText ?
- this.decay * this.options.decay : 1);
-
- this.lastText = request.responseText;
- }
- this.timer = setTimeout(this.onTimerEvent.bind(this),
- this.decay * this.frequency * 1000);
- },
-
- onTimerEvent: function() {
- this.updater = new Ajax.Updater(this.container, this.url, this.options);
- }
+ initialize: function( container, url, options )
+ {
+ this.setOptions(options);
+ this.onComplete = this.options.onComplete;
+
+ this.frequency = (this.options.frequency || 2);
+ this.decay = (this.options.decay || 1);
+
+ this.updater = {};
+ this.container = container;
+ this.url = url;
+
+ this.start();
+ },
+
+ start: function()
+ {
+ this.options.onComplete = this.updateComplete.bind(this);
+ this.onTimerEvent();
+ },
+
+ stop: function()
+ {
+ this.updater.options.onComplete = undefined;
+ clearTimeout(this.timer);
+ (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
+ },
+
+ updateComplete: function( request )
+ {
+ if ( this.options.decay )
+ {
+ this.decay = (request.responseText == this.lastText ? this.decay * this.options.decay : 1);
+
+ this.lastText = request.responseText;
+ }
+ this.timer = setTimeout(this.onTimerEvent.bind(this), this.decay * this.frequency * 1000);
+ },
+
+ onTimerEvent: function()
+ {
+ this.updater = new Ajax.Updater(this.container, this.url, this.options);
+ }
});
-function $() {
- var results = [], element;
- for (var i = 0; i < arguments.length; i++) {
- element = arguments[i];
- if (typeof element == 'string')
- element = document.getElementById(element);
- results.push(Element.extend(element));
- }
- return results.reduce();
-}
-
-document.getElementsByClassName = function(className, parentElement) {
- var children = ($(parentElement) || document.body).getElementsByTagName('*');
- return $A(children).inject([], function(elements, child) {
- if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
- elements.push(Element.extend(child));
- return elements;
- });
+function $()
+{
+ var results = [], element;
+ for ( var i = 0; i < arguments.length; i++ )
+ {
+ element = arguments[i];
+ if ( typeof element == 'string' )
+ element = document.getElementById(element);
+ results.push(Element.extend(element));
+ }
+ return results.reduce();
+}
+
+document.getElementsByClassName = function( className, parentElement )
+{
+ var children = ($(parentElement) || document.body).getElementsByTagName('*');
+ return $A(children).inject([], function( elements, child )
+ {
+ if ( child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")) )
+ elements.push(Element.extend(child));
+ return elements;
+ });
}
/*--------------------------------------------------------------------------*/
-if (!window.Element)
- var Element = new Object();
+if ( !window.Element )
+ var Element = new Object();
-Element.extend = function(element) {
- if (!element) return;
- if (_nativeExtensions || element.nodeType == 3) return element;
-
- if (!element._extended && element.tagName && element != window) {
- var methods = Object.clone(Element.Methods), cache = Element.extend.cache;
-
- if (element.tagName == 'FORM')
- Object.extend(methods, Form.Methods);
- if (['INPUT', 'TEXTAREA', 'SELECT'].include(element.tagName))
- Object.extend(methods, Form.Element.Methods);
-
- for (var property in methods) {
- var value = methods[property];
- if (typeof value == 'function')
- element[property] = cache.findOrStore(value);
+Element.extend = function( element )
+{
+ if ( !element ) return;
+ if ( _nativeExtensions || element.nodeType == 3 ) return element;
+
+ if ( !element._extended && element.tagName && element != window )
+ {
+ var methods = Object.clone(Element.Methods), cache = Element.extend.cache;
+
+ if ( element.tagName == 'FORM' )
+ Object.extend(methods, Form.Methods);
+ if ( ['INPUT', 'TEXTAREA', 'SELECT'].include(element.tagName) )
+ Object.extend(methods, Form.Element.Methods);
+
+ for ( var property in methods )
+ {
+ var value = methods[property];
+ if ( typeof value == 'function' )
+ element[property] = cache.findOrStore(value);
+ }
}
- }
- element._extended = true;
- return element;
+ element._extended = true;
+ return element;
}
Element.extend.cache = {
- findOrStore: function(value) {
- return this[value] = this[value] || function() {
- return value.apply(null, [this].concat($A(arguments)));
+ findOrStore: function( value )
+ {
+ return this[value] = this[value] || function()
+ {
+ return value.apply(null, [this].concat($A(arguments)));
+ }
}
- }
}
Element.Methods = {
- visible: function(element) {
- return $(element).style.display != 'none';
- },
-
- toggle: function(element) {
- element = $(element);
- Element[Element.visible(element) ? 'hide' : 'show'](element);
- return element;
- },
+ visible: function( element )
+ {
+ return $(element).style.display != 'none';
+ },
+
+ toggle: function( element )
+ {
+ element = $(element);
+ Element[Element.visible(element) ? 'hide' : 'show'](element);
+ return element;
+ },
- hide: function(element) {
- $(element).style.display = 'none';
- return element;
- },
+ hide: function( element )
+ {
+ $(element).style.display = 'none';
+ return element;
+ },
- show: function(element) {
- $(element).style.display = '';
- return element;
- },
+ show: function( element )
+ {
+ $(element).style.display = '';
+ return element;
+ },
- remove: function(element) {
- element = $(element);
- element.parentNode.removeChild(element);
- return element;
- },
+ remove: function( element )
+ {
+ element = $(element);
+ element.parentNode.removeChild(element);
+ return element;
+ },
- update: function(element, html) {
- $(element).innerHTML = html.stripScripts();
- setTimeout(function() {html.evalScripts()}, 10);
- return element;
- },
+ update: function( element, html )
+ {
+ $(element).innerHTML = html.stripScripts();
+ setTimeout(function()
+ {
+ html.evalScripts()
+ }, 10);
+ return element;
+ },
- replace: function(element, html) {
- element = $(element);
- if (element.outerHTML) {
- element.outerHTML = html.stripScripts();
- } else {
- var range = element.ownerDocument.createRange();
- range.selectNodeContents(element);
- element.parentNode.replaceChild(
- range.createContextualFragment(html.stripScripts()), element);
- }
- setTimeout(function() {html.evalScripts()}, 10);
- return element;
- },
+ replace: function( element, html )
+ {
+ element = $(element);
+ if ( element.outerHTML )
+ {
+ element.outerHTML = html.stripScripts();
+ }
+ else
+ {
+ var range = element.ownerDocument.createRange();
+ range.selectNodeContents(element);
+ element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), element);
+ }
+ setTimeout(function()
+ {
+ html.evalScripts()
+ }, 10);
+ return element;
+ },
- inspect: function(element) {
- element = $(element);
- var result = '<' + element.tagName.toLowerCase();
- $H({'id': 'id', 'className': 'class'}).each(function(pair) {
- var property = pair.first(), attribute = pair.last();
- var value = (element[property] || '').toString();
- if (value) result += ' ' + attribute + '=' + value.inspect(true);
- });
- return result + '>';
- },
+ inspect: function( element )
+ {
+ element = $(element);
+ var result = '<' + element.tagName.toLowerCase();
+ $H({'id': 'id', 'className': 'class'}).each(function( pair )
+ {
+ var property = pair.first(), attribute = pair.last();
+ var value = (element[property] || '').toString();
+ if ( value ) result += ' ' + attribute + '=' + value.inspect(true);
+ });
+ return result + '>';
+ },
- recursivelyCollect: function(element, property) {
- element = $(element);
- var elements = [];
- while (element = element[property])
- if (element.nodeType == 1)
- elements.push(Element.extend(element));
- return elements;
- },
-
- ancestors: function(element) {
- return $(element).recursivelyCollect('parentNode');
- },
-
- descendants: function(element) {
- element = $(element);
- return $A(element.getElementsByTagName('*'));
- },
-
- previousSiblings: function(element) {
- return $(element).recursivelyCollect('previousSibling');
- },
-
- nextSiblings: function(element) {
- return $(element).recursivelyCollect('nextSibling');
- },
-
- siblings: function(element) {
- element = $(element);
- return element.previousSiblings().reverse().concat(element.nextSiblings());
- },
-
- match: function(element, selector) {
- element = $(element);
- if (typeof selector == 'string')
- selector = new Selector(selector);
- return selector.match(element);
- },
-
- up: function(element, expression, index) {
- return Selector.findElement($(element).ancestors(), expression, index);
- },
-
- down: function(element, expression, index) {
- return Selector.findElement($(element).descendants(), expression, index);
- },
-
- previous: function(element, expression, index) {
- return Selector.findElement($(element).previousSiblings(), expression, index);
- },
-
- next: function(element, expression, index) {
- return Selector.findElement($(element).nextSiblings(), expression, index);
- },
-
- getElementsBySelector: function() {
- var args = $A(arguments), element = $(args.shift());
- return Selector.findChildElements(element, args);
- },
-
- getElementsByClassName: function(element, className) {
- element = $(element);
- return document.getElementsByClassName(className, element);
- },
-
- getHeight: function(element) {
- element = $(element);
- return element.offsetHeight;
- },
-
- classNames: function(element) {
- return new Element.ClassNames(element);
- },
-
- hasClassName: function(element, className) {
- if (!(element = $(element))) return;
- return Element.classNames(element).include(className);
- },
-
- addClassName: function(element, className) {
- if (!(element = $(element))) return;
- Element.classNames(element).add(className);
- return element;
- },
+ recursivelyCollect: function( element, property )
+ {
+ element = $(element);
+ var elements = [];
+ while ( element = element[property] )
+ if ( element.nodeType == 1 )
+ elements.push(Element.extend(element));
+ return elements;
+ },
+
+ ancestors: function( element )
+ {
+ return $(element).recursivelyCollect('parentNode');
+ },
+
+ descendants: function( element )
+ {
+ element = $(element);
+ return $A(element.getElementsByTagName('*'));
+ },
+
+ previousSiblings: function( element )
+ {
+ return $(element).recursivelyCollect('previousSibling');
+ },
+
+ nextSiblings: function( element )
+ {
+ return $(element).recursivelyCollect('nextSibling');
+ },
+
+ siblings: function( element )
+ {
+ element = $(element);
+ return element.previousSiblings().reverse().concat(element.nextSiblings());
+ },
+
+ match: function( element, selector )
+ {
+ element = $(element);
+ if ( typeof selector == 'string' )
+ selector = new Selector(selector);
+ return selector.match(element);
+ },
+
+ up: function( element, expression, index )
+ {
+ return Selector.findElement($(element).ancestors(), expression, index);
+ },
+
+ down: function( element, expression, index )
+ {
+ return Selector.findElement($(element).descendants(), expression, index);
+ },
+
+ previous: function( element, expression, index )
+ {
+ return Selector.findElement($(element).previousSiblings(), expression, index);
+ },
+
+ next: function( element, expression, index )
+ {
+ return Selector.findElement($(element).nextSiblings(), expression, index);
+ },
+
+ getElementsBySelector: function()
+ {
+ var args = $A(arguments), element = $(args.shift());
+ return Selector.findChildElements(element, args);
+ },
+
+ getElementsByClassName: function( element, className )
+ {
+ element = $(element);
+ return document.getElementsByClassName(className, element);
+ },
+
+ getHeight: function( element )
+ {
+ element = $(element);
+ return element.offsetHeight;
+ },
+
+ classNames: function( element )
+ {
+ return new Element.ClassNames(element);
+ },
+
+ hasClassName: function( element, className )
+ {
+ if ( !(element = $(element)) ) return;
+ return Element.classNames(element).include(className);
+ },
+
+ addClassName: function( element, className )
+ {
+ if ( !(element = $(element)) ) return;
+ Element.classNames(element).add(className);
+ return element;
+ },
- removeClassName: function(element, className) {
- if (!(element = $(element))) return;
- Element.classNames(element).remove(className);
- return element;
- },
+ removeClassName: function( element, className )
+ {
+ if ( !(element = $(element)) ) return;
+ Element.classNames(element).remove(className);
+ return element;
+ },
- observe: function() {
- Event.observe.apply(Event, arguments);
- return $A(arguments).first();
- },
-
- stopObserving: function() {
- Event.stopObserving.apply(Event, arguments);
- return $A(arguments).first();
- },
-
- // removes whitespace-only text node children
- cleanWhitespace: function(element) {
- element = $(element);
- var node = element.firstChild;
- while (node) {
- var nextNode = node.nextSibling;
- if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
- element.removeChild(node);
- node = nextNode;
- }
- return element;
- },
+ observe: function()
+ {
+ Event.observe.apply(Event, arguments);
+ return $A(arguments).first();
+ },
+
+ stopObserving: function()
+ {
+ Event.stopObserving.apply(Event, arguments);
+ return $A(arguments).first();
+ },
+
+// removes whitespace-only text node children
+ cleanWhitespace: function( element )
+ {
+ element = $(element);
+ var node = element.firstChild;
+ while ( node )
+ {
+ var nextNode = node.nextSibling;
+ if ( node.nodeType == 3 && !/\S/.test(node.nodeValue) )
+ element.removeChild(node);
+ node = nextNode;
+ }
+ return element;
+ },
- empty: function(element) {
- return $(element).innerHTML.match(/^\s*$/);
- },
-
- childOf: function(element, ancestor) {
- element = $(element), ancestor = $(ancestor);
- while (element = element.parentNode)
- if (element == ancestor) return true;
- return false;
- },
-
- scrollTo: function(element) {
- element = $(element);
- var x = element.x ? element.x : element.offsetLeft,
- y = element.y ? element.y : element.offsetTop;
- window.scrollTo(x, y);
- return element;
- },
+ empty: function( element )
+ {
+ return $(element).innerHTML.match(/^\s*$/);
+ },
+
+ childOf: function( element, ancestor )
+ {
+ element = $(element),ancestor = $(ancestor);
+ while ( element = element.parentNode )
+ if ( element == ancestor ) return true;
+ return false;
+ },
+
+ scrollTo: function( element )
+ {
+ element = $(element);
+ var x = element.x ? element.x : element.offsetLeft,
+ y = element.y ? element.y : element.offsetTop;
+ window.scrollTo(x, y);
+ return element;
+ },
- getStyle: function(element, style) {
- element = $(element);
- var value = element.style[style.camelize()];
- if (!value) {
- if (document.defaultView && document.defaultView.getComputedStyle) {
- var css = document.defaultView.getComputedStyle(element, null);
- value = css ? css.getPropertyValue(style) : null;
- } else if (element.currentStyle) {
- value = element.currentStyle[style.camelize()];
- }
- }
-
- if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
- if (Element.getStyle(element, 'position') == 'static') value = 'auto';
-
- return value == 'auto' ? null : value;
- },
-
- setStyle: function(element, style) {
- element = $(element);
- for (var name in style)
- element.style[name.camelize()] = style[name];
- return element;
- },
+ getStyle: function( element, style )
+ {
+ element = $(element);
+ var value = element.style[style.camelize()];
+ if ( !value )
+ {
+ if ( document.defaultView && document.defaultView.getComputedStyle )
+ {
+ var css = document.defaultView.getComputedStyle(element, null);
+ value = css ? css.getPropertyValue(style) : null;
+ }
+ else if ( element.currentStyle )
+ {
+ value = element.currentStyle[style.camelize()];
+ }
+ }
- getDimensions: function(element) {
- element = $(element);
- if (Element.getStyle(element, 'display') != 'none')
- return {width: element.offsetWidth, height: element.offsetHeight};
-
- // All *Width and *Height properties give 0 on elements with display none,
- // so enable the element temporarily
- var els = element.style;
- var originalVisibility = els.visibility;
- var originalPosition = els.position;
- els.visibility = 'hidden';
- els.position = 'absolute';
- els.display = '';
- var originalWidth = element.clientWidth;
- var originalHeight = element.clientHeight;
- els.display = 'none';
- els.position = originalPosition;
- els.visibility = originalVisibility;
- return {width: originalWidth, height: originalHeight};
- },
-
- makePositioned: function(element) {
- element = $(element);
- var pos = Element.getStyle(element, 'position');
- if (pos == 'static' || !pos) {
- element._madePositioned = true;
- element.style.position = 'relative';
- // Opera returns the offset relative to the positioning context, when an
- // element is position relative but top and left have not been defined
- if (window.opera) {
- element.style.top = 0;
- element.style.left = 0;
- }
- }
- return element;
- },
+ if ( window.opera && ['left', 'top', 'right', 'bottom'].include(style) )
+ if ( Element.getStyle(element, 'position') == 'static' ) value = 'auto';
- undoPositioned: function(element) {
- element = $(element);
- if (element._madePositioned) {
- element._madePositioned = undefined;
- element.style.position =
- element.style.top =
- element.style.left =
- element.style.bottom =
- element.style.right = '';
- }
- return element;
- },
+ return value == 'auto' ? null : value;
+ },
- makeClipping: function(element) {
- element = $(element);
- if (element._overflow) return;
- element._overflow = element.style.overflow || 'auto';
- if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden')
- element.style.overflow = 'hidden';
- return element;
- },
+ setStyle: function( element, style )
+ {
+ element = $(element);
+ for ( var name in style )
+ element.style[name.camelize()] = style[name];
+ return element;
+ },
- undoClipping: function(element) {
- element = $(element);
- if (!element._overflow) return;
- element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
- element._overflow = null;
- return element;
- }
+ getDimensions: function( element )
+ {
+ element = $(element);
+ if ( Element.getStyle(element, 'display') != 'none' )
+ return {width: element.offsetWidth, height: element.offsetHeight};
+
+ // All *Width and *Height properties give 0 on elements with display none,
+ // so enable the element temporarily
+ var els = element.style;
+ var originalVisibility = els.visibility;
+ var originalPosition = els.position;
+ els.visibility = 'hidden';
+ els.position = 'absolute';
+ els.display = '';
+ var originalWidth = element.clientWidth;
+ var originalHeight = element.clientHeight;
+ els.display = 'none';
+ els.position = originalPosition;
+ els.visibility = originalVisibility;
+ return {width: originalWidth, height: originalHeight};
+ },
+
+ makePositioned: function( element )
+ {
+ element = $(element);
+ var pos = Element.getStyle(element, 'position');
+ if ( pos == 'static' || !pos )
+ {
+ element._madePositioned = true;
+ element.style.position = 'relative';
+ // Opera returns the offset relative to the positioning context, when an
+ // element is position relative but top and left have not been defined
+ if ( window.opera )
+ {
+ element.style.top = 0;
+ element.style.left = 0;
+ }
+ }
+ return element;
+ },
+
+ undoPositioned: function( element )
+ {
+ element = $(element);
+ if ( element._madePositioned )
+ {
+ element._madePositioned = undefined;
+ element.style.position =
+ element.style.top = element.style.left = element.style.bottom = element.style.right = '';
+ }
+ return element;
+ },
+
+ makeClipping: function( element )
+ {
+ element = $(element);
+ if ( element._overflow ) return;
+ element._overflow = element.style.overflow || 'auto';
+ if ( (Element.getStyle(element, 'overflow') || 'visible') != 'hidden' )
+ element.style.overflow = 'hidden';
+ return element;
+ },
+
+ undoClipping: function( element )
+ {
+ element = $(element);
+ if ( !element._overflow ) return;
+ element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
+ element._overflow = null;
+ return element;
+ }
}
// IE is missing .innerHTML support for TABLE-related elements
-if(document.all){
- Element.Methods.update = function(element, html) {
- element = $(element);
- var tagName = element.tagName.toUpperCase();
- if (['THEAD','TBODY','TR','TD'].indexOf(tagName) > -1) {
- var div = document.createElement('div');
- switch (tagName) {
- case 'THEAD':
- case 'TBODY':
- div.innerHTML = '<table><tbody>' + html.stripScripts() + '</tbody></table>';
- depth = 2;
- break;
- case 'TR':
- div.innerHTML = '<table><tbody><tr>' + html.stripScripts() + '</tr></tbody></table>';
- depth = 3;
- break;
- case 'TD':
- div.innerHTML = '<table><tbody><tr><td>' + html.stripScripts() + '</td></tr></tbody></table>';
- depth = 4;
- }
- $A(element.childNodes).each(function(node){
- element.removeChild(node)
- });
- depth.times(function(){ div = div.firstChild });
-
- $A(div.childNodes).each(
- function(node){ element.appendChild(node) });
- } else {
- element.innerHTML = html.stripScripts();
+if ( document.all )
+{
+ Element.Methods.update = function( element, html )
+ {
+ element = $(element);
+ var tagName = element.tagName.toUpperCase();
+ if ( ['THEAD','TBODY','TR','TD'].indexOf(tagName) > -1 )
+ {
+ var div = document.createElement('div');
+ switch ( tagName )
+ {
+ case 'THEAD':
+ case 'TBODY':
+ div.innerHTML = '<table><tbody>' + html.stripScripts() + '</tbody></table>';
+ depth = 2;
+ break;
+ case 'TR':
+ div.innerHTML = '<table><tbody><tr>' + html.stripScripts() + '</tr></tbody></table>';
+ depth = 3;
+ break;
+ case 'TD':
+ div.innerHTML = '<table><tbody><tr><td>' + html.stripScripts() + '</td></tr></tbody></table>';
+ depth = 4;
+ }
+ $A(element.childNodes).each(function( node )
+ {
+ element.removeChild(node)
+ });
+ depth.times(function()
+ {
+ div = div.firstChild
+ });
+
+ $A(div.childNodes).each(function( node )
+ {
+ element.appendChild(node)
+ });
+ }
+ else
+ {
+ element.innerHTML = html.stripScripts();
+ }
+ setTimeout(function()
+ {
+ html.evalScripts()
+ }, 10);
+ return element;
}
- setTimeout(function() {html.evalScripts()}, 10);
- return element;
- }
}
Object.extend(Element, Element.Methods);
var _nativeExtensions = false;
-if (!window.HTMLElement && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) {
- /* Emulate HTMLElement, HTMLFormElement, HTMLInputElement, HTMLTextAreaElement,
- and HTMLSelectElement in Safari */
- ['', 'Form', 'Input', 'TextArea', 'Select'].each(function(tag) {
- var klass = window['HTML' + tag + 'Element'] = {};
- klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__;
- });
-}
-
-Element.addMethods = function(methods) {
- Object.extend(Element.Methods, methods || {});
-
- function copy(methods, destination) {
- var cache = Element.extend.cache;
- for (var property in methods) {
- var value = methods[property];
- destination[property] = cache.findOrStore(value);
- }
- }
-
- if (typeof HTMLElement != 'undefined') {
- copy(Element.Methods, HTMLElement.prototype);
- copy(Form.Methods, HTMLFormElement.prototype);
- [HTMLInputElement, HTMLTextAreaElement, HTMLSelectElement].each(function(klass) {
- copy(Form.Element.Methods, klass.prototype);
+if ( !window.HTMLElement && /Konqueror|Safari|KHTML/.test(navigator.userAgent) )
+{
+ /* Emulate HTMLElement, HTMLFormElement, HTMLInputElement, HTMLTextAreaElement,
+and HTMLSelectElement in Safari */
+ ['', 'Form', 'Input', 'TextArea', 'Select'].each(function( tag )
+ {
+ var klass = window['HTML' + tag + 'Element'] = {};
+ klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__;
});
- _nativeExtensions = true;
- }
+}
+
+Element.addMethods = function( methods )
+{
+ Object.extend(Element.Methods, methods || {});
+
+ function copy( methods, destination )
+ {
+ var cache = Element.extend.cache;
+ for ( var property in methods )
+ {
+ var value = methods[property];
+ destination[property] = cache.findOrStore(value);
+ }
+ }
+
+ if ( typeof HTMLElement != 'undefined' )
+ {
+ copy(Element.Methods, HTMLElement.prototype);
+ copy(Form.Methods, HTMLFormElement.prototype);
+ [HTMLInputElement, HTMLTextAreaElement, HTMLSelectElement].each(function( klass )
+ {
+ copy(Form.Element.Methods, klass.prototype);
+ });
+ _nativeExtensions = true;
+ }
}
var Toggle = new Object();
@@ -1330,348 +1644,418 @@
/*--------------------------------------------------------------------------*/
-Abstract.Insertion = function(adjacency) {
- this.adjacency = adjacency;
+Abstract.Insertion = function( adjacency )
+{
+ this.adjacency = adjacency;
}
Abstract.Insertion.prototype = {
- initialize: function(element, content) {
- this.element = $(element);
- this.content = content.stripScripts();
-
- if (this.adjacency && this.element.insertAdjacentHTML) {
- try {
- this.element.insertAdjacentHTML(this.adjacency, this.content);
- } catch (e) {
- var tagName = this.element.tagName.toLowerCase();
- if (tagName == 'tbody' || tagName == 'tr') {
- this.insertContent(this.contentFromAnonymousTable());
- } else {
- throw e;
- }
- }
- } else {
- this.range = this.element.ownerDocument.createRange();
- if (this.initializeRange) this.initializeRange();
- this.insertContent([this.range.createContextualFragment(this.content)]);
- }
-
- setTimeout(function() {content.evalScripts()}, 10);
- },
-
- contentFromAnonymousTable: function() {
- var div = document.createElement('div');
- div.innerHTML = '<table><tbody>' + this.content + '</tbody></table>';
- return $A(div.childNodes[0].childNodes[0].childNodes);
- }
+ initialize: function( element, content )
+ {
+ this.element = $(element);
+ this.content = content.stripScripts();
+
+ if ( this.adjacency && this.element.insertAdjacentHTML )
+ {
+ try
+ {
+ this.element.insertAdjacentHTML(this.adjacency, this.content);
+ }
+ catch ( e )
+ {
+ var tagName = this.element.tagName.toLowerCase();
+ if ( tagName == 'tbody' || tagName == 'tr' )
+ {
+ this.insertContent(this.contentFromAnonymousTable());
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+ else
+ {
+ this.range = this.element.ownerDocument.createRange();
+ if ( this.initializeRange ) this.initializeRange();
+ this.insertContent([this.range.createContextualFragment(this.content)]);
+ }
+
+ setTimeout(function()
+ {
+ content.evalScripts()
+ }, 10);
+ },
+
+ contentFromAnonymousTable: function()
+ {
+ var div = document.createElement('div');
+ div.innerHTML = '<table><tbody>' + this.content + '</tbody></table>';
+ return $A(div.childNodes[0].childNodes[0].childNodes);
+ }
}
var Insertion = new Object();
Insertion.Before = Class.create();
Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), {
- initializeRange: function() {
- this.range.setStartBefore(this.element);
- },
-
- insertContent: function(fragments) {
- fragments.each((function(fragment) {
- this.element.parentNode.insertBefore(fragment, this.element);
- }).bind(this));
- }
+ initializeRange: function()
+ {
+ this.range.setStartBefore(this.element);
+ },
+
+ insertContent: function( fragments )
+ {
+ fragments.each((function( fragment )
+ {
+ this.element.parentNode.insertBefore(fragment, this.element);
+ }).bind(this));
+ }
});
Insertion.Top = Class.create();
Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), {
- initializeRange: function() {
- this.range.selectNodeContents(this.element);
- this.range.collapse(true);
- },
-
- insertContent: function(fragments) {
- fragments.reverse(false).each((function(fragment) {
- this.element.insertBefore(fragment, this.element.firstChild);
- }).bind(this));
- }
+ initializeRange: function()
+ {
+ this.range.selectNodeContents(this.element);
+ this.range.collapse(true);
+ },
+
+ insertContent: function( fragments )
+ {
+ fragments.reverse(false).each((function( fragment )
+ {
+ this.element.insertBefore(fragment, this.element.firstChild);
+ }).bind(this));
+ }
});
Insertion.Bottom = Class.create();
Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), {
- initializeRange: function() {
- this.range.selectNodeContents(this.element);
- this.range.collapse(this.element);
- },
-
- insertContent: function(fragments) {
- fragments.each((function(fragment) {
- this.element.appendChild(fragment);
- }).bind(this));
- }
+ initializeRange: function()
+ {
+ this.range.selectNodeContents(this.element);
+ this.range.collapse(this.element);
+ },
+
+ insertContent: function( fragments )
+ {
+ fragments.each((function( fragment )
+ {
+ this.element.appendChild(fragment);
+ }).bind(this));
+ }
});
Insertion.After = Class.create();
Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), {
- initializeRange: function() {
- this.range.setStartAfter(this.element);
- },
-
- insertContent: function(fragments) {
- fragments.each((function(fragment) {
- this.element.parentNode.insertBefore(fragment,
- this.element.nextSibling);
- }).bind(this));
- }
+ initializeRange: function()
+ {
+ this.range.setStartAfter(this.element);
+ },
+
+ insertContent: function( fragments )
+ {
+ fragments.each((function( fragment )
+ {
+ this.element.parentNode.insertBefore(fragment, this.element.nextSibling);
+ }).bind(this));
+ }
});
/*--------------------------------------------------------------------------*/
Element.ClassNames = Class.create();
Element.ClassNames.prototype = {
- initialize: function(element) {
- this.element = $(element);
- },
-
- _each: function(iterator) {
- this.element.className.split(/\s+/).select(function(name) {
- return name.length > 0;
- })._each(iterator);
- },
-
- set: function(className) {
- this.element.className = className;
- },
-
- add: function(classNameToAdd) {
- if (this.include(classNameToAdd)) return;
- this.set(this.toArray().concat(classNameToAdd).join(' '));
- },
-
- remove: function(classNameToRemove) {
- if (!this.include(classNameToRemove)) return;
- this.set(this.select(function(className) {
- return className != classNameToRemove;
- }).join(' '));
- },
-
- toString: function() {
- return this.toArray().join(' ');
- }
+ initialize: function( element )
+ {
+ this.element = $(element);
+ },
+
+ _each: function( iterator )
+ {
+ this.element.className.split(/\s+/).select(function( name )
+ {
+ return name.length > 0;
+ })._each(iterator);
+ },
+
+ set: function( className )
+ {
+ this.element.className = className;
+ },
+
+ add: function( classNameToAdd )
+ {
+ if ( this.include(classNameToAdd) ) return;
+ this.set(this.toArray().concat(classNameToAdd).join(' '));
+ },
+
+ remove: function( classNameToRemove )
+ {
+ if ( !this.include(classNameToRemove) ) return;
+ this.set(this.select(function( className )
+ {
+ return className != classNameToRemove;
+ }).join(' '));
+ },
+
+ toString: function()
+ {
+ return this.toArray().join(' ');
+ }
}
Object.extend(Element.ClassNames.prototype, Enumerable);
var Selector = Class.create();
Selector.prototype = {
- initialize: function(expression) {
- this.params = {classNames: []};
- this.expression = expression.toString().strip();
- this.parseExpression();
- this.compileMatcher();
- },
-
- parseExpression: function() {
- function abort(message) { throw 'Parse error in selector: ' + message; }
-
- if (this.expression == '') abort('empty expression');
-
- var params = this.params, expr = this.expression, match, modifier, clause, rest;
- while (match = expr.match(/^(.*)\[([a-z0-9_:-]+?)(?:([~\|!]?=)(?:"([^"]*)"|([^\]\s]*)))?\]$/i)) {
- params.attributes = params.attributes || [];
- params.attributes.push({name: match[2], operator: match[3], value: match[4] || match[5] || ''});
- expr = match[1];
- }
-
- if (expr == '*') return this.params.wildcard = true;
-
- while (match = expr.match(/^([^a-z0-9_-])?([a-z0-9_-]+)(.*)/i)) {
- modifier = match[1], clause = match[2], rest = match[3];
- switch (modifier) {
- case '#': params.id = clause; break;
- case '.': params.classNames.push(clause); break;
- case '':
- case undefined: params.tagName = clause.toUpperCase(); break;
- default: abort(expr.inspect());
- }
- expr = rest;
- }
-
- if (expr.length > 0) abort(expr.inspect());
- },
-
- buildMatchExpression: function() {
- var params = this.params, conditions = [], clause;
-
- if (params.wildcard)
- conditions.push('true');
- if (clause = params.id)
- conditions.push('element.id == ' + clause.inspect());
- if (clause = params.tagName)
- conditions.push('element.tagName.toUpperCase() == ' + clause.inspect());
- if ((clause = params.classNames).length > 0)
- for (var i = 0; i < clause.length; i++)
- conditions.push('Element.hasClassName(element, ' + clause[i].inspect() + ')');
- if (clause = params.attributes) {
- clause.each(function(attribute) {
- var value = 'element.getAttribute(' + attribute.name.inspect() + ')';
- var splitValueBy = function(delimiter) {
- return value + ' && ' + value + '.split(' + delimiter.inspect() + ')';
- }
-
- switch (attribute.operator) {
- case '=': conditions.push(value + ' == ' + attribute.value.inspect()); break;
- case '~=': conditions.push(splitValueBy(' ') + '.include(' + attribute.value.inspect() + ')'); break;
- case '|=': conditions.push(
- splitValueBy('-') + '.first().toUpperCase() == ' + attribute.value.toUpperCase().inspect()
- ); break;
- case '!=': conditions.push(value + ' != ' + attribute.value.inspect()); break;
- case '':
- case undefined: conditions.push(value + ' != null'); break;
- default: throw 'Unknown operator ' + attribute.operator + ' in selector';
- }
- });
[... 1504 lines stripped ...]