1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Update Prototype to 1.6.0.2 (Patrick Joyce) [#599 status:committed]

This commit is contained in:
David Heinemeier Hansson 2008-07-19 13:56:38 -05:00
parent c98692abcf
commit 706425e154
3 changed files with 302 additions and 308 deletions

View file

@ -1,5 +1,7 @@
*Edge* *Edge*
* Update Prototype to 1.6.0.2 #599 [Patrick Joyce]
* Conditional GET utility methods. [Jeremy Kemper] * Conditional GET utility methods. [Jeremy Kemper]
* etag!([:admin, post, current_user]) sets the ETag response header and returns head(:not_modified) if it matches the If-None-Match request header. * etag!([:admin, post, current_user]) sets the ETag response header and returns head(:not_modified) if it matches the If-None-Match request header.
* last_modified!(post.updated_at) sets Last-Modified and returns head(:not_modified) if it's no later than If-Modified-Since. * last_modified!(post.updated_at) sets Last-Modified and returns head(:not_modified) if it's no later than If-Modified-Since.

View file

@ -1,5 +1,5 @@
/* Prototype JavaScript framework, version 1.6.0.1 /* Prototype JavaScript framework, version 1.6.0.2
* (c) 2005-2007 Sam Stephenson * (c) 2005-2008 Sam Stephenson
* *
* Prototype is freely distributable under the terms of an MIT-style license. * Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://www.prototypejs.org/ * For details, see the Prototype web site: http://www.prototypejs.org/
@ -7,7 +7,7 @@
*--------------------------------------------------------------------------*/ *--------------------------------------------------------------------------*/
var Prototype = { var Prototype = {
Version: '1.6.0.1', Version: '1.6.0.2',
Browser: { Browser: {
IE: !!(window.attachEvent && !window.opera), IE: !!(window.attachEvent && !window.opera),
@ -110,7 +110,7 @@ Object.extend(Object, {
try { try {
if (Object.isUndefined(object)) return 'undefined'; if (Object.isUndefined(object)) return 'undefined';
if (object === null) return 'null'; if (object === null) return 'null';
return object.inspect ? object.inspect() : object.toString(); return object.inspect ? object.inspect() : String(object);
} catch (e) { } catch (e) {
if (e instanceof RangeError) return '...'; if (e instanceof RangeError) return '...';
throw e; throw e;
@ -171,7 +171,8 @@ Object.extend(Object, {
}, },
isArray: function(object) { isArray: function(object) {
return object && object.constructor === Array; return object != null && typeof object == "object" &&
'splice' in object && 'join' in object;
}, },
isHash: function(object) { isHash: function(object) {
@ -578,7 +579,7 @@ var Template = Class.create({
} }
return before + String.interpret(ctx); return before + String.interpret(ctx);
}.bind(this)); });
} }
}); });
Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
@ -806,20 +807,20 @@ Object.extend(Enumerable, {
function $A(iterable) { function $A(iterable) {
if (!iterable) return []; if (!iterable) return [];
if (iterable.toArray) return iterable.toArray(); if (iterable.toArray) return iterable.toArray();
var length = iterable.length, results = new Array(length); var length = iterable.length || 0, results = new Array(length);
while (length--) results[length] = iterable[length]; while (length--) results[length] = iterable[length];
return results; return results;
} }
if (Prototype.Browser.WebKit) { if (Prototype.Browser.WebKit) {
function $A(iterable) { $A = function(iterable) {
if (!iterable) return []; if (!iterable) return [];
if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') && if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') &&
iterable.toArray) return iterable.toArray(); iterable.toArray) return iterable.toArray();
var length = iterable.length, results = new Array(length); var length = iterable.length || 0, results = new Array(length);
while (length--) results[length] = iterable[length]; while (length--) results[length] = iterable[length];
return results; return results;
} };
} }
Array.from = $A; Array.from = $A;
@ -1298,7 +1299,7 @@ Ajax.Request = Class.create(Ajax.Base, {
var contentType = response.getHeader('Content-type'); var contentType = response.getHeader('Content-type');
if (this.options.evalJS == 'force' if (this.options.evalJS == 'force'
|| (this.options.evalJS && contentType || (this.options.evalJS && this.isSameOrigin() && contentType
&& contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i))) && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
this.evalResponse(); this.evalResponse();
} }
@ -1316,9 +1317,18 @@ Ajax.Request = Class.create(Ajax.Base, {
} }
}, },
isSameOrigin: function() {
var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
protocol: location.protocol,
domain: document.domain,
port: location.port ? ':' + location.port : ''
}));
},
getHeader: function(name) { getHeader: function(name) {
try { try {
return this.transport.getResponseHeader(name); return this.transport.getResponseHeader(name) || null;
} catch (e) { return null } } catch (e) { return null }
}, },
@ -1391,7 +1401,8 @@ Ajax.Response = Class.create({
if (!json) return null; if (!json) return null;
json = decodeURIComponent(escape(json)); json = decodeURIComponent(escape(json));
try { try {
return json.evalJSON(this.request.options.sanitizeJSON); return json.evalJSON(this.request.options.sanitizeJSON ||
!this.request.isSameOrigin());
} catch (e) { } catch (e) {
this.request.dispatchException(e); this.request.dispatchException(e);
} }
@ -1404,7 +1415,8 @@ Ajax.Response = Class.create({
this.responseText.blank()) this.responseText.blank())
return null; return null;
try { try {
return this.responseText.evalJSON(options.sanitizeJSON); return this.responseText.evalJSON(options.sanitizeJSON ||
!this.request.isSameOrigin());
} catch (e) { } catch (e) {
this.request.dispatchException(e); this.request.dispatchException(e);
} }
@ -1608,24 +1620,28 @@ Element.Methods = {
Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML))) Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
insertions = {bottom:insertions}; insertions = {bottom:insertions};
var content, t, range; var content, insert, tagName, childNodes;
for (position in insertions) { for (var position in insertions) {
content = insertions[position]; content = insertions[position];
position = position.toLowerCase(); position = position.toLowerCase();
t = Element._insertionTranslations[position]; insert = Element._insertionTranslations[position];
if (content && content.toElement) content = content.toElement(); if (content && content.toElement) content = content.toElement();
if (Object.isElement(content)) { if (Object.isElement(content)) {
t.insert(element, content); insert(element, content);
continue; continue;
} }
content = Object.toHTML(content); content = Object.toHTML(content);
range = element.ownerDocument.createRange(); tagName = ((position == 'before' || position == 'after')
t.initializeRange(element, range); ? element.parentNode : element).tagName.toUpperCase();
t.insert(element, range.createContextualFragment(content.stripScripts()));
childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
if (position == 'top' || position == 'after') childNodes.reverse();
childNodes.each(insert.curry(element));
content.evalScripts.bind(content).defer(); content.evalScripts.bind(content).defer();
} }
@ -1670,7 +1686,7 @@ Element.Methods = {
}, },
descendants: function(element) { descendants: function(element) {
return $(element).getElementsBySelector("*"); return $(element).select("*");
}, },
firstDescendant: function(element) { firstDescendant: function(element) {
@ -1709,32 +1725,31 @@ Element.Methods = {
element = $(element); element = $(element);
if (arguments.length == 1) return $(element.parentNode); if (arguments.length == 1) return $(element.parentNode);
var ancestors = element.ancestors(); var ancestors = element.ancestors();
return expression ? Selector.findElement(ancestors, expression, index) : return Object.isNumber(expression) ? ancestors[expression] :
ancestors[index || 0]; Selector.findElement(ancestors, expression, index);
}, },
down: function(element, expression, index) { down: function(element, expression, index) {
element = $(element); element = $(element);
if (arguments.length == 1) return element.firstDescendant(); if (arguments.length == 1) return element.firstDescendant();
var descendants = element.descendants(); return Object.isNumber(expression) ? element.descendants()[expression] :
return expression ? Selector.findElement(descendants, expression, index) : element.select(expression)[index || 0];
descendants[index || 0];
}, },
previous: function(element, expression, index) { previous: function(element, expression, index) {
element = $(element); element = $(element);
if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element)); if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
var previousSiblings = element.previousSiblings(); var previousSiblings = element.previousSiblings();
return expression ? Selector.findElement(previousSiblings, expression, index) : return Object.isNumber(expression) ? previousSiblings[expression] :
previousSiblings[index || 0]; Selector.findElement(previousSiblings, expression, index);
}, },
next: function(element, expression, index) { next: function(element, expression, index) {
element = $(element); element = $(element);
if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element)); if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
var nextSiblings = element.nextSiblings(); var nextSiblings = element.nextSiblings();
return expression ? Selector.findElement(nextSiblings, expression, index) : return Object.isNumber(expression) ? nextSiblings[expression] :
nextSiblings[index || 0]; Selector.findElement(nextSiblings, expression, index);
}, },
select: function() { select: function() {
@ -1860,7 +1875,8 @@ Element.Methods = {
do { ancestor = ancestor.parentNode; } do { ancestor = ancestor.parentNode; }
while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode); while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode);
} }
if (nextAncestor) return (e > a && e < nextAncestor.sourceIndex); if (nextAncestor && nextAncestor.sourceIndex)
return (e > a && e < nextAncestor.sourceIndex);
} }
while (element = element.parentNode) while (element = element.parentNode)
@ -2004,7 +2020,7 @@ Element.Methods = {
if (element) { if (element) {
if (element.tagName == 'BODY') break; if (element.tagName == 'BODY') break;
var p = Element.getStyle(element, 'position'); var p = Element.getStyle(element, 'position');
if (p == 'relative' || p == 'absolute') break; if (p !== 'static') break;
} }
} while (element); } while (element);
return Element._returnOffset(valueL, valueT); return Element._returnOffset(valueL, valueT);
@ -2153,46 +2169,6 @@ Element._attributeTranslations = {
} }
}; };
if (!document.createRange || Prototype.Browser.Opera) {
Element.Methods.insert = function(element, insertions) {
element = $(element);
if (Object.isString(insertions) || Object.isNumber(insertions) ||
Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
insertions = { bottom: insertions };
var t = Element._insertionTranslations, content, position, pos, tagName;
for (position in insertions) {
content = insertions[position];
position = position.toLowerCase();
pos = t[position];
if (content && content.toElement) content = content.toElement();
if (Object.isElement(content)) {
pos.insert(element, content);
continue;
}
content = Object.toHTML(content);
tagName = ((position == 'before' || position == 'after')
? element.parentNode : element).tagName.toUpperCase();
if (t.tags[tagName]) {
var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
if (position == 'top' || position == 'after') fragments.reverse();
fragments.each(pos.insert.curry(element));
}
else element.insertAdjacentHTML(pos.adjacency, content.stripScripts());
content.evalScripts.bind(content).defer();
}
return element;
};
}
if (Prototype.Browser.Opera) { if (Prototype.Browser.Opera) {
Element.Methods.getStyle = Element.Methods.getStyle.wrap( Element.Methods.getStyle = Element.Methods.getStyle.wrap(
function(proceed, element, style) { function(proceed, element, style) {
@ -2237,12 +2213,31 @@ if (Prototype.Browser.Opera) {
} }
else if (Prototype.Browser.IE) { else if (Prototype.Browser.IE) {
$w('positionedOffset getOffsetParent viewportOffset').each(function(method) { // IE doesn't report offsets correctly for static elements, so we change them
// to "relative" to get the values, then change them back.
Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap(
function(proceed, element) {
element = $(element);
var position = element.getStyle('position');
if (position !== 'static') return proceed(element);
element.setStyle({ position: 'relative' });
var value = proceed(element);
element.setStyle({ position: position });
return value;
}
);
$w('positionedOffset viewportOffset').each(function(method) {
Element.Methods[method] = Element.Methods[method].wrap( Element.Methods[method] = Element.Methods[method].wrap(
function(proceed, element) { function(proceed, element) {
element = $(element); element = $(element);
var position = element.getStyle('position'); var position = element.getStyle('position');
if (position != 'static') return proceed(element); if (position !== 'static') return proceed(element);
// Trigger hasLayout on the offset parent so that IE6 reports
// accurate offsetTop and offsetLeft values for position: fixed.
var offsetParent = element.getOffsetParent();
if (offsetParent && offsetParent.getStyle('position') === 'fixed')
offsetParent.setStyle({ zoom: 1 });
element.setStyle({ position: 'relative' }); element.setStyle({ position: 'relative' });
var value = proceed(element); var value = proceed(element);
element.setStyle({ position: position }); element.setStyle({ position: position });
@ -2324,7 +2319,10 @@ else if (Prototype.Browser.IE) {
}; };
Element._attributeTranslations.write = { Element._attributeTranslations.write = {
names: Object.clone(Element._attributeTranslations.read.names), names: Object.extend({
cellpadding: 'cellPadding',
cellspacing: 'cellSpacing'
}, Element._attributeTranslations.read.names),
values: { values: {
checked: function(element, value) { checked: function(element, value) {
element.checked = !!value; element.checked = !!value;
@ -2444,7 +2442,7 @@ if (Prototype.Browser.IE || Prototype.Browser.Opera) {
}; };
} }
if (document.createElement('div').outerHTML) { if ('outerHTML' in document.createElement('div')) {
Element.Methods.replace = function(element, content) { Element.Methods.replace = function(element, content) {
element = $(element); element = $(element);
@ -2482,46 +2480,26 @@ Element._returnOffset = function(l, t) {
Element._getContentFromAnonymousElement = function(tagName, html) { Element._getContentFromAnonymousElement = function(tagName, html) {
var div = new Element('div'), t = Element._insertionTranslations.tags[tagName]; var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];
if (t) {
div.innerHTML = t[0] + html + t[1]; div.innerHTML = t[0] + html + t[1];
t[2].times(function() { div = div.firstChild }); t[2].times(function() { div = div.firstChild });
} else div.innerHTML = html;
return $A(div.childNodes); return $A(div.childNodes);
}; };
Element._insertionTranslations = { Element._insertionTranslations = {
before: { before: function(element, node) {
adjacency: 'beforeBegin',
insert: function(element, node) {
element.parentNode.insertBefore(node, element); element.parentNode.insertBefore(node, element);
}, },
initializeRange: function(element, range) { top: function(element, node) {
range.setStartBefore(element);
}
},
top: {
adjacency: 'afterBegin',
insert: function(element, node) {
element.insertBefore(node, element.firstChild); element.insertBefore(node, element.firstChild);
}, },
initializeRange: function(element, range) { bottom: function(element, node) {
range.selectNodeContents(element);
range.collapse(true);
}
},
bottom: {
adjacency: 'beforeEnd',
insert: function(element, node) {
element.appendChild(node); element.appendChild(node);
}
}, },
after: { after: function(element, node) {
adjacency: 'afterEnd',
insert: function(element, node) {
element.parentNode.insertBefore(node, element.nextSibling); element.parentNode.insertBefore(node, element.nextSibling);
}, },
initializeRange: function(element, range) {
range.setStartAfter(element);
}
},
tags: { tags: {
TABLE: ['<table>', '</table>', 1], TABLE: ['<table>', '</table>', 1],
TBODY: ['<table><tbody>', '</tbody></table>', 2], TBODY: ['<table><tbody>', '</tbody></table>', 2],
@ -2532,7 +2510,6 @@ Element._insertionTranslations = {
}; };
(function() { (function() {
this.bottom.initializeRange = this.top.initializeRange;
Object.extend(this.tags, { Object.extend(this.tags, {
THEAD: this.tags.TBODY, THEAD: this.tags.TBODY,
TFOOT: this.tags.TBODY, TFOOT: this.tags.TBODY,
@ -2716,7 +2693,7 @@ document.viewport = {
window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop); window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
} }
}; };
/* Portions of the Selector class are derived from Jack Slocums DomQuery, /* Portions of the Selector class are derived from Jack Slocumâs DomQuery,
* part of YUI-Ext version 0.40, distributed under the terms of an MIT-style * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
* license. Please see http://www.yui-ext.com/ for more information. */ * license. Please see http://www.yui-ext.com/ for more information. */
@ -2962,10 +2939,10 @@ Object.extend(Selector, {
tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;', tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;',
className: 'n = h.className(n, r, "#{1}", c); c = false;', className: 'n = h.className(n, r, "#{1}", c); c = false;',
id: 'n = h.id(n, r, "#{1}", c); c = false;', id: 'n = h.id(n, r, "#{1}", c); c = false;',
attrPresence: 'n = h.attrPresence(n, r, "#{1}"); c = false;', attrPresence: 'n = h.attrPresence(n, r, "#{1}", c); c = false;',
attr: function(m) { attr: function(m) {
m[3] = (m[5] || m[6]); m[3] = (m[5] || m[6]);
return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}"); c = false;').evaluate(m); return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;').evaluate(m);
}, },
pseudo: function(m) { pseudo: function(m) {
if (m[6]) m[6] = m[6].replace(/"/g, '\\"'); if (m[6]) m[6] = m[6].replace(/"/g, '\\"');
@ -2989,7 +2966,8 @@ Object.extend(Selector, {
tagName: /^\s*(\*|[\w\-]+)(\b|$)?/, tagName: /^\s*(\*|[\w\-]+)(\b|$)?/,
id: /^#([\w\-\*]+)(\b|$)/, id: /^#([\w\-\*]+)(\b|$)/,
className: /^\.([\w\-\*]+)(\b|$)/, className: /^\.([\w\-\*]+)(\b|$)/,
pseudo: /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s)|(?=:))/, pseudo:
/^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/,
attrPresence: /^\[([\w]+)\]/, attrPresence: /^\[([\w]+)\]/,
attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/ attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/
}, },
@ -3014,7 +2992,7 @@ Object.extend(Selector, {
attr: function(element, matches) { attr: function(element, matches) {
var nodeValue = Element.readAttribute(element, matches[1]); var nodeValue = Element.readAttribute(element, matches[1]);
return Selector.operators[matches[2]](nodeValue, matches[3]); return nodeValue && Selector.operators[matches[2]](nodeValue, matches[5] || matches[6]);
} }
}, },
@ -3029,14 +3007,15 @@ Object.extend(Selector, {
// marks an array of nodes for counting // marks an array of nodes for counting
mark: function(nodes) { mark: function(nodes) {
var _true = Prototype.emptyFunction;
for (var i = 0, node; node = nodes[i]; i++) for (var i = 0, node; node = nodes[i]; i++)
node._counted = true; node._countedByPrototype = _true;
return nodes; return nodes;
}, },
unmark: function(nodes) { unmark: function(nodes) {
for (var i = 0, node; node = nodes[i]; i++) for (var i = 0, node; node = nodes[i]; i++)
node._counted = undefined; node._countedByPrototype = undefined;
return nodes; return nodes;
}, },
@ -3044,15 +3023,15 @@ Object.extend(Selector, {
// "ofType" flag indicates whether we're indexing for nth-of-type // "ofType" flag indicates whether we're indexing for nth-of-type
// rather than nth-child // rather than nth-child
index: function(parentNode, reverse, ofType) { index: function(parentNode, reverse, ofType) {
parentNode._counted = true; parentNode._countedByPrototype = Prototype.emptyFunction;
if (reverse) { if (reverse) {
for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) { for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
var node = nodes[i]; var node = nodes[i];
if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
} }
} else { } else {
for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++) for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
} }
}, },
@ -3061,8 +3040,8 @@ Object.extend(Selector, {
if (nodes.length == 0) return nodes; if (nodes.length == 0) return nodes;
var results = [], n; var results = [], n;
for (var i = 0, l = nodes.length; i < l; i++) for (var i = 0, l = nodes.length; i < l; i++)
if (!(n = nodes[i])._counted) { if (!(n = nodes[i])._countedByPrototype) {
n._counted = true; n._countedByPrototype = Prototype.emptyFunction;
results.push(Element.extend(n)); results.push(Element.extend(n));
} }
return Selector.handlers.unmark(results); return Selector.handlers.unmark(results);
@ -3114,7 +3093,7 @@ Object.extend(Selector, {
// TOKEN FUNCTIONS // TOKEN FUNCTIONS
tagName: function(nodes, root, tagName, combinator) { tagName: function(nodes, root, tagName, combinator) {
tagName = tagName.toUpperCase(); var uTagName = tagName.toUpperCase();
var results = [], h = Selector.handlers; var results = [], h = Selector.handlers;
if (nodes) { if (nodes) {
if (combinator) { if (combinator) {
@ -3127,7 +3106,7 @@ Object.extend(Selector, {
if (tagName == "*") return nodes; if (tagName == "*") return nodes;
} }
for (var i = 0, node; node = nodes[i]; i++) for (var i = 0, node; node = nodes[i]; i++)
if (node.tagName.toUpperCase() == tagName) results.push(node); if (node.tagName.toUpperCase() === uTagName) results.push(node);
return results; return results;
} else return root.getElementsByTagName(tagName); } else return root.getElementsByTagName(tagName);
}, },
@ -3174,16 +3153,18 @@ Object.extend(Selector, {
return results; return results;
}, },
attrPresence: function(nodes, root, attr) { attrPresence: function(nodes, root, attr, combinator) {
if (!nodes) nodes = root.getElementsByTagName("*"); if (!nodes) nodes = root.getElementsByTagName("*");
if (nodes && combinator) nodes = this[combinator](nodes);
var results = []; var results = [];
for (var i = 0, node; node = nodes[i]; i++) for (var i = 0, node; node = nodes[i]; i++)
if (Element.hasAttribute(node, attr)) results.push(node); if (Element.hasAttribute(node, attr)) results.push(node);
return results; return results;
}, },
attr: function(nodes, root, attr, value, operator) { attr: function(nodes, root, attr, value, operator, combinator) {
if (!nodes) nodes = root.getElementsByTagName("*"); if (!nodes) nodes = root.getElementsByTagName("*");
if (nodes && combinator) nodes = this[combinator](nodes);
var handler = Selector.operators[operator], results = []; var handler = Selector.operators[operator], results = [];
for (var i = 0, node; node = nodes[i]; i++) { for (var i = 0, node; node = nodes[i]; i++) {
var nodeValue = Element.readAttribute(node, attr); var nodeValue = Element.readAttribute(node, attr);
@ -3262,7 +3243,7 @@ Object.extend(Selector, {
var h = Selector.handlers, results = [], indexed = [], m; var h = Selector.handlers, results = [], indexed = [], m;
h.mark(nodes); h.mark(nodes);
for (var i = 0, node; node = nodes[i]; i++) { for (var i = 0, node; node = nodes[i]; i++) {
if (!node.parentNode._counted) { if (!node.parentNode._countedByPrototype) {
h.index(node.parentNode, reverse, ofType); h.index(node.parentNode, reverse, ofType);
indexed.push(node.parentNode); indexed.push(node.parentNode);
} }
@ -3300,7 +3281,7 @@ Object.extend(Selector, {
var exclusions = new Selector(selector).findElements(root); var exclusions = new Selector(selector).findElements(root);
h.mark(exclusions); h.mark(exclusions);
for (var i = 0, results = [], node; node = nodes[i]; i++) for (var i = 0, results = [], node; node = nodes[i]; i++)
if (!node._counted) results.push(node); if (!node._countedByPrototype) results.push(node);
h.unmark(exclusions); h.unmark(exclusions);
return results; return results;
}, },
@ -3334,11 +3315,19 @@ Object.extend(Selector, {
'|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); } '|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); }
}, },
split: function(expression) {
var expressions = [];
expression.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
expressions.push(m[1].strip());
});
return expressions;
},
matchElements: function(elements, expression) { matchElements: function(elements, expression) {
var matches = new Selector(expression).findElements(), h = Selector.handlers; var matches = $$(expression), h = Selector.handlers;
h.mark(matches); h.mark(matches);
for (var i = 0, results = [], element; element = elements[i]; i++) for (var i = 0, results = [], element; element = elements[i]; i++)
if (element._counted) results.push(element); if (element._countedByPrototype) results.push(element);
h.unmark(matches); h.unmark(matches);
return results; return results;
}, },
@ -3351,11 +3340,7 @@ Object.extend(Selector, {
}, },
findChildElements: function(element, expressions) { findChildElements: function(element, expressions) {
var exprs = expressions.join(','); expressions = Selector.split(expressions.join(','));
expressions = [];
exprs.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
expressions.push(m[1].strip());
});
var results = [], h = Selector.handlers; var results = [], h = Selector.handlers;
for (var i = 0, l = expressions.length, selector; i < l; i++) { for (var i = 0, l = expressions.length, selector; i < l; i++) {
selector = new Selector(expressions[i].strip()); selector = new Selector(expressions[i].strip());
@ -3366,13 +3351,22 @@ Object.extend(Selector, {
}); });
if (Prototype.Browser.IE) { if (Prototype.Browser.IE) {
Object.extend(Selector.handlers, {
// IE returns comment nodes on getElementsByTagName("*"). // IE returns comment nodes on getElementsByTagName("*").
// Filter them out. // Filter them out.
Selector.handlers.concat = function(a, b) { concat: function(a, b) {
for (var i = 0, node; node = b[i]; i++) for (var i = 0, node; node = b[i]; i++)
if (node.tagName !== "!") a.push(node); if (node.tagName !== "!") a.push(node);
return a; return a;
}; },
// IE improperly serializes _countedByPrototype in (inner|outer)HTML.
unmark: function(nodes) {
for (var i = 0, node; node = nodes[i]; i++)
node.removeAttribute('_countedByPrototype');
return nodes;
}
});
} }
function $$() { function $$() {
@ -3850,9 +3844,9 @@ Object.extend(Event, (function() {
var cache = Event.cache; var cache = Event.cache;
function getEventID(element) { function getEventID(element) {
if (element._eventID) return element._eventID; if (element._prototypeEventID) return element._prototypeEventID[0];
arguments.callee.id = arguments.callee.id || 1; arguments.callee.id = arguments.callee.id || 1;
return element._eventID = ++arguments.callee.id; return element._prototypeEventID = [++arguments.callee.id];
} }
function getDOMEventName(eventName) { function getDOMEventName(eventName) {
@ -3880,7 +3874,7 @@ Object.extend(Event, (function() {
return false; return false;
Event.extend(event); Event.extend(event);
handler.call(element, event) handler.call(element, event);
}; };
wrapper.handler = handler; wrapper.handler = handler;
@ -3962,11 +3956,12 @@ Object.extend(Event, (function() {
if (element == document && document.createEvent && !element.dispatchEvent) if (element == document && document.createEvent && !element.dispatchEvent)
element = document.documentElement; element = document.documentElement;
var event;
if (document.createEvent) { if (document.createEvent) {
var event = document.createEvent("HTMLEvents"); event = document.createEvent("HTMLEvents");
event.initEvent("dataavailable", true, true); event.initEvent("dataavailable", true, true);
} else { } else {
var event = document.createEventObject(); event = document.createEventObject();
event.eventType = "ondataavailable"; event.eventType = "ondataavailable";
} }
@ -3995,20 +3990,21 @@ Element.addMethods({
Object.extend(document, { Object.extend(document, {
fire: Element.Methods.fire.methodize(), fire: Element.Methods.fire.methodize(),
observe: Element.Methods.observe.methodize(), observe: Element.Methods.observe.methodize(),
stopObserving: Element.Methods.stopObserving.methodize() stopObserving: Element.Methods.stopObserving.methodize(),
loaded: false
}); });
(function() { (function() {
/* Support for the DOMContentLoaded event is based on work by Dan Webb, /* Support for the DOMContentLoaded event is based on work by Dan Webb,
Matthias Miller, Dean Edwards and John Resig. */ Matthias Miller, Dean Edwards and John Resig. */
var timer, fired = false; var timer;
function fireContentLoadedEvent() { function fireContentLoadedEvent() {
if (fired) return; if (document.loaded) return;
if (timer) window.clearInterval(timer); if (timer) window.clearInterval(timer);
document.fire("dom:loaded"); document.fire("dom:loaded");
fired = true; document.loaded = true;
} }
if (document.addEventListener) { if (document.addEventListener) {

View file

@ -1,5 +1,5 @@
/* Prototype JavaScript framework, version 1.6.0.1 /* Prototype JavaScript framework, version 1.6.0.2
* (c) 2005-2007 Sam Stephenson * (c) 2005-2008 Sam Stephenson
* *
* Prototype is freely distributable under the terms of an MIT-style license. * Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://www.prototypejs.org/ * For details, see the Prototype web site: http://www.prototypejs.org/
@ -7,7 +7,7 @@
*--------------------------------------------------------------------------*/ *--------------------------------------------------------------------------*/
var Prototype = { var Prototype = {
Version: '1.6.0.1', Version: '1.6.0.2',
Browser: { Browser: {
IE: !!(window.attachEvent && !window.opera), IE: !!(window.attachEvent && !window.opera),
@ -110,7 +110,7 @@ Object.extend(Object, {
try { try {
if (Object.isUndefined(object)) return 'undefined'; if (Object.isUndefined(object)) return 'undefined';
if (object === null) return 'null'; if (object === null) return 'null';
return object.inspect ? object.inspect() : object.toString(); return object.inspect ? object.inspect() : String(object);
} catch (e) { } catch (e) {
if (e instanceof RangeError) return '...'; if (e instanceof RangeError) return '...';
throw e; throw e;
@ -171,7 +171,8 @@ Object.extend(Object, {
}, },
isArray: function(object) { isArray: function(object) {
return object && object.constructor === Array; return object != null && typeof object == "object" &&
'splice' in object && 'join' in object;
}, },
isHash: function(object) { isHash: function(object) {
@ -578,7 +579,7 @@ var Template = Class.create({
} }
return before + String.interpret(ctx); return before + String.interpret(ctx);
}.bind(this)); });
} }
}); });
Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
@ -806,20 +807,20 @@ Object.extend(Enumerable, {
function $A(iterable) { function $A(iterable) {
if (!iterable) return []; if (!iterable) return [];
if (iterable.toArray) return iterable.toArray(); if (iterable.toArray) return iterable.toArray();
var length = iterable.length, results = new Array(length); var length = iterable.length || 0, results = new Array(length);
while (length--) results[length] = iterable[length]; while (length--) results[length] = iterable[length];
return results; return results;
} }
if (Prototype.Browser.WebKit) { if (Prototype.Browser.WebKit) {
function $A(iterable) { $A = function(iterable) {
if (!iterable) return []; if (!iterable) return [];
if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') && if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') &&
iterable.toArray) return iterable.toArray(); iterable.toArray) return iterable.toArray();
var length = iterable.length, results = new Array(length); var length = iterable.length || 0, results = new Array(length);
while (length--) results[length] = iterable[length]; while (length--) results[length] = iterable[length];
return results; return results;
} };
} }
Array.from = $A; Array.from = $A;
@ -1298,7 +1299,7 @@ Ajax.Request = Class.create(Ajax.Base, {
var contentType = response.getHeader('Content-type'); var contentType = response.getHeader('Content-type');
if (this.options.evalJS == 'force' if (this.options.evalJS == 'force'
|| (this.options.evalJS && contentType || (this.options.evalJS && this.isSameOrigin() && contentType
&& contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i))) && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
this.evalResponse(); this.evalResponse();
} }
@ -1316,9 +1317,18 @@ Ajax.Request = Class.create(Ajax.Base, {
} }
}, },
isSameOrigin: function() {
var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
protocol: location.protocol,
domain: document.domain,
port: location.port ? ':' + location.port : ''
}));
},
getHeader: function(name) { getHeader: function(name) {
try { try {
return this.transport.getResponseHeader(name); return this.transport.getResponseHeader(name) || null;
} catch (e) { return null } } catch (e) { return null }
}, },
@ -1391,7 +1401,8 @@ Ajax.Response = Class.create({
if (!json) return null; if (!json) return null;
json = decodeURIComponent(escape(json)); json = decodeURIComponent(escape(json));
try { try {
return json.evalJSON(this.request.options.sanitizeJSON); return json.evalJSON(this.request.options.sanitizeJSON ||
!this.request.isSameOrigin());
} catch (e) { } catch (e) {
this.request.dispatchException(e); this.request.dispatchException(e);
} }
@ -1404,7 +1415,8 @@ Ajax.Response = Class.create({
this.responseText.blank()) this.responseText.blank())
return null; return null;
try { try {
return this.responseText.evalJSON(options.sanitizeJSON); return this.responseText.evalJSON(options.sanitizeJSON ||
!this.request.isSameOrigin());
} catch (e) { } catch (e) {
this.request.dispatchException(e); this.request.dispatchException(e);
} }
@ -1608,24 +1620,28 @@ Element.Methods = {
Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML))) Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
insertions = {bottom:insertions}; insertions = {bottom:insertions};
var content, t, range; var content, insert, tagName, childNodes;
for (position in insertions) { for (var position in insertions) {
content = insertions[position]; content = insertions[position];
position = position.toLowerCase(); position = position.toLowerCase();
t = Element._insertionTranslations[position]; insert = Element._insertionTranslations[position];
if (content && content.toElement) content = content.toElement(); if (content && content.toElement) content = content.toElement();
if (Object.isElement(content)) { if (Object.isElement(content)) {
t.insert(element, content); insert(element, content);
continue; continue;
} }
content = Object.toHTML(content); content = Object.toHTML(content);
range = element.ownerDocument.createRange(); tagName = ((position == 'before' || position == 'after')
t.initializeRange(element, range); ? element.parentNode : element).tagName.toUpperCase();
t.insert(element, range.createContextualFragment(content.stripScripts()));
childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
if (position == 'top' || position == 'after') childNodes.reverse();
childNodes.each(insert.curry(element));
content.evalScripts.bind(content).defer(); content.evalScripts.bind(content).defer();
} }
@ -1670,7 +1686,7 @@ Element.Methods = {
}, },
descendants: function(element) { descendants: function(element) {
return $(element).getElementsBySelector("*"); return $(element).select("*");
}, },
firstDescendant: function(element) { firstDescendant: function(element) {
@ -1709,32 +1725,31 @@ Element.Methods = {
element = $(element); element = $(element);
if (arguments.length == 1) return $(element.parentNode); if (arguments.length == 1) return $(element.parentNode);
var ancestors = element.ancestors(); var ancestors = element.ancestors();
return expression ? Selector.findElement(ancestors, expression, index) : return Object.isNumber(expression) ? ancestors[expression] :
ancestors[index || 0]; Selector.findElement(ancestors, expression, index);
}, },
down: function(element, expression, index) { down: function(element, expression, index) {
element = $(element); element = $(element);
if (arguments.length == 1) return element.firstDescendant(); if (arguments.length == 1) return element.firstDescendant();
var descendants = element.descendants(); return Object.isNumber(expression) ? element.descendants()[expression] :
return expression ? Selector.findElement(descendants, expression, index) : element.select(expression)[index || 0];
descendants[index || 0];
}, },
previous: function(element, expression, index) { previous: function(element, expression, index) {
element = $(element); element = $(element);
if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element)); if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
var previousSiblings = element.previousSiblings(); var previousSiblings = element.previousSiblings();
return expression ? Selector.findElement(previousSiblings, expression, index) : return Object.isNumber(expression) ? previousSiblings[expression] :
previousSiblings[index || 0]; Selector.findElement(previousSiblings, expression, index);
}, },
next: function(element, expression, index) { next: function(element, expression, index) {
element = $(element); element = $(element);
if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element)); if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
var nextSiblings = element.nextSiblings(); var nextSiblings = element.nextSiblings();
return expression ? Selector.findElement(nextSiblings, expression, index) : return Object.isNumber(expression) ? nextSiblings[expression] :
nextSiblings[index || 0]; Selector.findElement(nextSiblings, expression, index);
}, },
select: function() { select: function() {
@ -1860,7 +1875,8 @@ Element.Methods = {
do { ancestor = ancestor.parentNode; } do { ancestor = ancestor.parentNode; }
while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode); while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode);
} }
if (nextAncestor) return (e > a && e < nextAncestor.sourceIndex); if (nextAncestor && nextAncestor.sourceIndex)
return (e > a && e < nextAncestor.sourceIndex);
} }
while (element = element.parentNode) while (element = element.parentNode)
@ -2004,7 +2020,7 @@ Element.Methods = {
if (element) { if (element) {
if (element.tagName == 'BODY') break; if (element.tagName == 'BODY') break;
var p = Element.getStyle(element, 'position'); var p = Element.getStyle(element, 'position');
if (p == 'relative' || p == 'absolute') break; if (p !== 'static') break;
} }
} while (element); } while (element);
return Element._returnOffset(valueL, valueT); return Element._returnOffset(valueL, valueT);
@ -2153,46 +2169,6 @@ Element._attributeTranslations = {
} }
}; };
if (!document.createRange || Prototype.Browser.Opera) {
Element.Methods.insert = function(element, insertions) {
element = $(element);
if (Object.isString(insertions) || Object.isNumber(insertions) ||
Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
insertions = { bottom: insertions };
var t = Element._insertionTranslations, content, position, pos, tagName;
for (position in insertions) {
content = insertions[position];
position = position.toLowerCase();
pos = t[position];
if (content && content.toElement) content = content.toElement();
if (Object.isElement(content)) {
pos.insert(element, content);
continue;
}
content = Object.toHTML(content);
tagName = ((position == 'before' || position == 'after')
? element.parentNode : element).tagName.toUpperCase();
if (t.tags[tagName]) {
var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
if (position == 'top' || position == 'after') fragments.reverse();
fragments.each(pos.insert.curry(element));
}
else element.insertAdjacentHTML(pos.adjacency, content.stripScripts());
content.evalScripts.bind(content).defer();
}
return element;
};
}
if (Prototype.Browser.Opera) { if (Prototype.Browser.Opera) {
Element.Methods.getStyle = Element.Methods.getStyle.wrap( Element.Methods.getStyle = Element.Methods.getStyle.wrap(
function(proceed, element, style) { function(proceed, element, style) {
@ -2237,12 +2213,31 @@ if (Prototype.Browser.Opera) {
} }
else if (Prototype.Browser.IE) { else if (Prototype.Browser.IE) {
$w('positionedOffset getOffsetParent viewportOffset').each(function(method) { // IE doesn't report offsets correctly for static elements, so we change them
// to "relative" to get the values, then change them back.
Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap(
function(proceed, element) {
element = $(element);
var position = element.getStyle('position');
if (position !== 'static') return proceed(element);
element.setStyle({ position: 'relative' });
var value = proceed(element);
element.setStyle({ position: position });
return value;
}
);
$w('positionedOffset viewportOffset').each(function(method) {
Element.Methods[method] = Element.Methods[method].wrap( Element.Methods[method] = Element.Methods[method].wrap(
function(proceed, element) { function(proceed, element) {
element = $(element); element = $(element);
var position = element.getStyle('position'); var position = element.getStyle('position');
if (position != 'static') return proceed(element); if (position !== 'static') return proceed(element);
// Trigger hasLayout on the offset parent so that IE6 reports
// accurate offsetTop and offsetLeft values for position: fixed.
var offsetParent = element.getOffsetParent();
if (offsetParent && offsetParent.getStyle('position') === 'fixed')
offsetParent.setStyle({ zoom: 1 });
element.setStyle({ position: 'relative' }); element.setStyle({ position: 'relative' });
var value = proceed(element); var value = proceed(element);
element.setStyle({ position: position }); element.setStyle({ position: position });
@ -2324,7 +2319,10 @@ else if (Prototype.Browser.IE) {
}; };
Element._attributeTranslations.write = { Element._attributeTranslations.write = {
names: Object.clone(Element._attributeTranslations.read.names), names: Object.extend({
cellpadding: 'cellPadding',
cellspacing: 'cellSpacing'
}, Element._attributeTranslations.read.names),
values: { values: {
checked: function(element, value) { checked: function(element, value) {
element.checked = !!value; element.checked = !!value;
@ -2444,7 +2442,7 @@ if (Prototype.Browser.IE || Prototype.Browser.Opera) {
}; };
} }
if (document.createElement('div').outerHTML) { if ('outerHTML' in document.createElement('div')) {
Element.Methods.replace = function(element, content) { Element.Methods.replace = function(element, content) {
element = $(element); element = $(element);
@ -2482,46 +2480,26 @@ Element._returnOffset = function(l, t) {
Element._getContentFromAnonymousElement = function(tagName, html) { Element._getContentFromAnonymousElement = function(tagName, html) {
var div = new Element('div'), t = Element._insertionTranslations.tags[tagName]; var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];
if (t) {
div.innerHTML = t[0] + html + t[1]; div.innerHTML = t[0] + html + t[1];
t[2].times(function() { div = div.firstChild }); t[2].times(function() { div = div.firstChild });
} else div.innerHTML = html;
return $A(div.childNodes); return $A(div.childNodes);
}; };
Element._insertionTranslations = { Element._insertionTranslations = {
before: { before: function(element, node) {
adjacency: 'beforeBegin',
insert: function(element, node) {
element.parentNode.insertBefore(node, element); element.parentNode.insertBefore(node, element);
}, },
initializeRange: function(element, range) { top: function(element, node) {
range.setStartBefore(element);
}
},
top: {
adjacency: 'afterBegin',
insert: function(element, node) {
element.insertBefore(node, element.firstChild); element.insertBefore(node, element.firstChild);
}, },
initializeRange: function(element, range) { bottom: function(element, node) {
range.selectNodeContents(element);
range.collapse(true);
}
},
bottom: {
adjacency: 'beforeEnd',
insert: function(element, node) {
element.appendChild(node); element.appendChild(node);
}
}, },
after: { after: function(element, node) {
adjacency: 'afterEnd',
insert: function(element, node) {
element.parentNode.insertBefore(node, element.nextSibling); element.parentNode.insertBefore(node, element.nextSibling);
}, },
initializeRange: function(element, range) {
range.setStartAfter(element);
}
},
tags: { tags: {
TABLE: ['<table>', '</table>', 1], TABLE: ['<table>', '</table>', 1],
TBODY: ['<table><tbody>', '</tbody></table>', 2], TBODY: ['<table><tbody>', '</tbody></table>', 2],
@ -2532,7 +2510,6 @@ Element._insertionTranslations = {
}; };
(function() { (function() {
this.bottom.initializeRange = this.top.initializeRange;
Object.extend(this.tags, { Object.extend(this.tags, {
THEAD: this.tags.TBODY, THEAD: this.tags.TBODY,
TFOOT: this.tags.TBODY, TFOOT: this.tags.TBODY,
@ -2716,7 +2693,7 @@ document.viewport = {
window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop); window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
} }
}; };
/* Portions of the Selector class are derived from Jack Slocums DomQuery, /* Portions of the Selector class are derived from Jack Slocumâs DomQuery,
* part of YUI-Ext version 0.40, distributed under the terms of an MIT-style * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
* license. Please see http://www.yui-ext.com/ for more information. */ * license. Please see http://www.yui-ext.com/ for more information. */
@ -2962,10 +2939,10 @@ Object.extend(Selector, {
tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;', tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;',
className: 'n = h.className(n, r, "#{1}", c); c = false;', className: 'n = h.className(n, r, "#{1}", c); c = false;',
id: 'n = h.id(n, r, "#{1}", c); c = false;', id: 'n = h.id(n, r, "#{1}", c); c = false;',
attrPresence: 'n = h.attrPresence(n, r, "#{1}"); c = false;', attrPresence: 'n = h.attrPresence(n, r, "#{1}", c); c = false;',
attr: function(m) { attr: function(m) {
m[3] = (m[5] || m[6]); m[3] = (m[5] || m[6]);
return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}"); c = false;').evaluate(m); return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;').evaluate(m);
}, },
pseudo: function(m) { pseudo: function(m) {
if (m[6]) m[6] = m[6].replace(/"/g, '\\"'); if (m[6]) m[6] = m[6].replace(/"/g, '\\"');
@ -2989,7 +2966,8 @@ Object.extend(Selector, {
tagName: /^\s*(\*|[\w\-]+)(\b|$)?/, tagName: /^\s*(\*|[\w\-]+)(\b|$)?/,
id: /^#([\w\-\*]+)(\b|$)/, id: /^#([\w\-\*]+)(\b|$)/,
className: /^\.([\w\-\*]+)(\b|$)/, className: /^\.([\w\-\*]+)(\b|$)/,
pseudo: /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s)|(?=:))/, pseudo:
/^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/,
attrPresence: /^\[([\w]+)\]/, attrPresence: /^\[([\w]+)\]/,
attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/ attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/
}, },
@ -3014,7 +2992,7 @@ Object.extend(Selector, {
attr: function(element, matches) { attr: function(element, matches) {
var nodeValue = Element.readAttribute(element, matches[1]); var nodeValue = Element.readAttribute(element, matches[1]);
return Selector.operators[matches[2]](nodeValue, matches[3]); return nodeValue && Selector.operators[matches[2]](nodeValue, matches[5] || matches[6]);
} }
}, },
@ -3029,14 +3007,15 @@ Object.extend(Selector, {
// marks an array of nodes for counting // marks an array of nodes for counting
mark: function(nodes) { mark: function(nodes) {
var _true = Prototype.emptyFunction;
for (var i = 0, node; node = nodes[i]; i++) for (var i = 0, node; node = nodes[i]; i++)
node._counted = true; node._countedByPrototype = _true;
return nodes; return nodes;
}, },
unmark: function(nodes) { unmark: function(nodes) {
for (var i = 0, node; node = nodes[i]; i++) for (var i = 0, node; node = nodes[i]; i++)
node._counted = undefined; node._countedByPrototype = undefined;
return nodes; return nodes;
}, },
@ -3044,15 +3023,15 @@ Object.extend(Selector, {
// "ofType" flag indicates whether we're indexing for nth-of-type // "ofType" flag indicates whether we're indexing for nth-of-type
// rather than nth-child // rather than nth-child
index: function(parentNode, reverse, ofType) { index: function(parentNode, reverse, ofType) {
parentNode._counted = true; parentNode._countedByPrototype = Prototype.emptyFunction;
if (reverse) { if (reverse) {
for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) { for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
var node = nodes[i]; var node = nodes[i];
if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
} }
} else { } else {
for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++) for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
} }
}, },
@ -3061,8 +3040,8 @@ Object.extend(Selector, {
if (nodes.length == 0) return nodes; if (nodes.length == 0) return nodes;
var results = [], n; var results = [], n;
for (var i = 0, l = nodes.length; i < l; i++) for (var i = 0, l = nodes.length; i < l; i++)
if (!(n = nodes[i])._counted) { if (!(n = nodes[i])._countedByPrototype) {
n._counted = true; n._countedByPrototype = Prototype.emptyFunction;
results.push(Element.extend(n)); results.push(Element.extend(n));
} }
return Selector.handlers.unmark(results); return Selector.handlers.unmark(results);
@ -3114,7 +3093,7 @@ Object.extend(Selector, {
// TOKEN FUNCTIONS // TOKEN FUNCTIONS
tagName: function(nodes, root, tagName, combinator) { tagName: function(nodes, root, tagName, combinator) {
tagName = tagName.toUpperCase(); var uTagName = tagName.toUpperCase();
var results = [], h = Selector.handlers; var results = [], h = Selector.handlers;
if (nodes) { if (nodes) {
if (combinator) { if (combinator) {
@ -3127,7 +3106,7 @@ Object.extend(Selector, {
if (tagName == "*") return nodes; if (tagName == "*") return nodes;
} }
for (var i = 0, node; node = nodes[i]; i++) for (var i = 0, node; node = nodes[i]; i++)
if (node.tagName.toUpperCase() == tagName) results.push(node); if (node.tagName.toUpperCase() === uTagName) results.push(node);
return results; return results;
} else return root.getElementsByTagName(tagName); } else return root.getElementsByTagName(tagName);
}, },
@ -3174,16 +3153,18 @@ Object.extend(Selector, {
return results; return results;
}, },
attrPresence: function(nodes, root, attr) { attrPresence: function(nodes, root, attr, combinator) {
if (!nodes) nodes = root.getElementsByTagName("*"); if (!nodes) nodes = root.getElementsByTagName("*");
if (nodes && combinator) nodes = this[combinator](nodes);
var results = []; var results = [];
for (var i = 0, node; node = nodes[i]; i++) for (var i = 0, node; node = nodes[i]; i++)
if (Element.hasAttribute(node, attr)) results.push(node); if (Element.hasAttribute(node, attr)) results.push(node);
return results; return results;
}, },
attr: function(nodes, root, attr, value, operator) { attr: function(nodes, root, attr, value, operator, combinator) {
if (!nodes) nodes = root.getElementsByTagName("*"); if (!nodes) nodes = root.getElementsByTagName("*");
if (nodes && combinator) nodes = this[combinator](nodes);
var handler = Selector.operators[operator], results = []; var handler = Selector.operators[operator], results = [];
for (var i = 0, node; node = nodes[i]; i++) { for (var i = 0, node; node = nodes[i]; i++) {
var nodeValue = Element.readAttribute(node, attr); var nodeValue = Element.readAttribute(node, attr);
@ -3262,7 +3243,7 @@ Object.extend(Selector, {
var h = Selector.handlers, results = [], indexed = [], m; var h = Selector.handlers, results = [], indexed = [], m;
h.mark(nodes); h.mark(nodes);
for (var i = 0, node; node = nodes[i]; i++) { for (var i = 0, node; node = nodes[i]; i++) {
if (!node.parentNode._counted) { if (!node.parentNode._countedByPrototype) {
h.index(node.parentNode, reverse, ofType); h.index(node.parentNode, reverse, ofType);
indexed.push(node.parentNode); indexed.push(node.parentNode);
} }
@ -3300,7 +3281,7 @@ Object.extend(Selector, {
var exclusions = new Selector(selector).findElements(root); var exclusions = new Selector(selector).findElements(root);
h.mark(exclusions); h.mark(exclusions);
for (var i = 0, results = [], node; node = nodes[i]; i++) for (var i = 0, results = [], node; node = nodes[i]; i++)
if (!node._counted) results.push(node); if (!node._countedByPrototype) results.push(node);
h.unmark(exclusions); h.unmark(exclusions);
return results; return results;
}, },
@ -3334,11 +3315,19 @@ Object.extend(Selector, {
'|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); } '|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); }
}, },
split: function(expression) {
var expressions = [];
expression.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
expressions.push(m[1].strip());
});
return expressions;
},
matchElements: function(elements, expression) { matchElements: function(elements, expression) {
var matches = new Selector(expression).findElements(), h = Selector.handlers; var matches = $$(expression), h = Selector.handlers;
h.mark(matches); h.mark(matches);
for (var i = 0, results = [], element; element = elements[i]; i++) for (var i = 0, results = [], element; element = elements[i]; i++)
if (element._counted) results.push(element); if (element._countedByPrototype) results.push(element);
h.unmark(matches); h.unmark(matches);
return results; return results;
}, },
@ -3351,11 +3340,7 @@ Object.extend(Selector, {
}, },
findChildElements: function(element, expressions) { findChildElements: function(element, expressions) {
var exprs = expressions.join(','); expressions = Selector.split(expressions.join(','));
expressions = [];
exprs.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
expressions.push(m[1].strip());
});
var results = [], h = Selector.handlers; var results = [], h = Selector.handlers;
for (var i = 0, l = expressions.length, selector; i < l; i++) { for (var i = 0, l = expressions.length, selector; i < l; i++) {
selector = new Selector(expressions[i].strip()); selector = new Selector(expressions[i].strip());
@ -3366,13 +3351,22 @@ Object.extend(Selector, {
}); });
if (Prototype.Browser.IE) { if (Prototype.Browser.IE) {
Object.extend(Selector.handlers, {
// IE returns comment nodes on getElementsByTagName("*"). // IE returns comment nodes on getElementsByTagName("*").
// Filter them out. // Filter them out.
Selector.handlers.concat = function(a, b) { concat: function(a, b) {
for (var i = 0, node; node = b[i]; i++) for (var i = 0, node; node = b[i]; i++)
if (node.tagName !== "!") a.push(node); if (node.tagName !== "!") a.push(node);
return a; return a;
}; },
// IE improperly serializes _countedByPrototype in (inner|outer)HTML.
unmark: function(nodes) {
for (var i = 0, node; node = nodes[i]; i++)
node.removeAttribute('_countedByPrototype');
return nodes;
}
});
} }
function $$() { function $$() {
@ -3850,9 +3844,9 @@ Object.extend(Event, (function() {
var cache = Event.cache; var cache = Event.cache;
function getEventID(element) { function getEventID(element) {
if (element._eventID) return element._eventID; if (element._prototypeEventID) return element._prototypeEventID[0];
arguments.callee.id = arguments.callee.id || 1; arguments.callee.id = arguments.callee.id || 1;
return element._eventID = ++arguments.callee.id; return element._prototypeEventID = [++arguments.callee.id];
} }
function getDOMEventName(eventName) { function getDOMEventName(eventName) {
@ -3880,7 +3874,7 @@ Object.extend(Event, (function() {
return false; return false;
Event.extend(event); Event.extend(event);
handler.call(element, event) handler.call(element, event);
}; };
wrapper.handler = handler; wrapper.handler = handler;
@ -3962,11 +3956,12 @@ Object.extend(Event, (function() {
if (element == document && document.createEvent && !element.dispatchEvent) if (element == document && document.createEvent && !element.dispatchEvent)
element = document.documentElement; element = document.documentElement;
var event;
if (document.createEvent) { if (document.createEvent) {
var event = document.createEvent("HTMLEvents"); event = document.createEvent("HTMLEvents");
event.initEvent("dataavailable", true, true); event.initEvent("dataavailable", true, true);
} else { } else {
var event = document.createEventObject(); event = document.createEventObject();
event.eventType = "ondataavailable"; event.eventType = "ondataavailable";
} }
@ -3995,20 +3990,21 @@ Element.addMethods({
Object.extend(document, { Object.extend(document, {
fire: Element.Methods.fire.methodize(), fire: Element.Methods.fire.methodize(),
observe: Element.Methods.observe.methodize(), observe: Element.Methods.observe.methodize(),
stopObserving: Element.Methods.stopObserving.methodize() stopObserving: Element.Methods.stopObserving.methodize(),
loaded: false
}); });
(function() { (function() {
/* Support for the DOMContentLoaded event is based on work by Dan Webb, /* Support for the DOMContentLoaded event is based on work by Dan Webb,
Matthias Miller, Dean Edwards and John Resig. */ Matthias Miller, Dean Edwards and John Resig. */
var timer, fired = false; var timer;
function fireContentLoadedEvent() { function fireContentLoadedEvent() {
if (fired) return; if (document.loaded) return;
if (timer) window.clearInterval(timer); if (timer) window.clearInterval(timer);
document.fire("dom:loaded"); document.fire("dom:loaded");
fired = true; document.loaded = true;
} }
if (document.addEventListener) { if (document.addEventListener) {