0
@@ -36,8 +36,6 @@ var Prototype = {
0
if (Prototype.Browser.MobileSafari)
0
Prototype.BrowserFeatures.SpecificElementExtensions = false;
0
-if (Prototype.Browser.WebKit)
0
- Prototype.BrowserFeatures.XPath = false;
0
/* Based on Alex Arnell's inheritance implementation. */
0
@@ -110,7 +108,7 @@ Object.extend = function(destination, source) {
0
Object.extend(Object, {
0
inspect: function(object) {
0
- if (
object === undefined) return 'undefined';
0
+ if (
Object.isUndefined(object)) return 'undefined';
0
if (object === null) return 'null';
0
return object.inspect ? object.inspect() : object.toString();
0
@@ -135,7 +133,7 @@ Object.extend(Object, {
0
for (var property in object) {
0
var value = Object.toJSON(object[property]);
0
- if (
value !== undefined)
0
+ if (
!Object.isUndefined(value))
0
results.push(property.toJSON() + ': ' + value);
0
@@ -204,7 +202,7 @@ Object.extend(Function.prototype, {
0
- if (arguments.length < 2 &&
arguments[0] === undefined) return this;
0
+ if (arguments.length < 2 &&
Object.isUndefined(arguments[0])) return this;
0
var __method = this, args = $A(arguments), object = args.shift();
0
return __method.apply(object, args.concat($A(arguments)));
0
@@ -351,7 +349,7 @@ Object.extend(String.prototype, {
0
sub: function(pattern, replacement, count) {
0
replacement = this.gsub.prepareReplacement(replacement);
0
- count =
count === undefined ? 1 : count;
0
+ count =
Object.isUndefined(count) ? 1 : count;
0
return this.gsub(pattern, function(match) {
0
if (--count < 0) return match[0];
0
@@ -366,7 +364,7 @@ Object.extend(String.prototype, {
0
truncate: function(length, truncation) {
0
- truncation =
truncation === undefined ? '...' : truncation;
0
+ truncation =
Object.isUndefined(truncation) ? '...' : truncation;
0
return this.length > length ?
0
this.slice(0, length - truncation.length) + truncation : String(this);
0
@@ -486,7 +484,9 @@ Object.extend(String.prototype, {
0
- var str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
0
+ if (str.blank()) return false;
0
+ str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
0
return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
0
@@ -565,7 +565,8 @@ var Template = Class.create({
0
if (before == '\\') return match[2];
0
var ctx = object, expr = match[3];
0
- var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/, match = pattern.exec(expr);
0
+ var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
0
+ match = pattern.exec(expr);
0
if (match == null) return before;
0
while (match != null) {
0
@@ -686,7 +687,7 @@ var Enumerable = {
0
inGroupsOf: function(number, fillWith) {
0
- fillWith =
fillWith === undefined ? null : fillWith;
0
+ fillWith =
Object.isUndefined(fillWith) ? null : fillWith;
0
return this.eachSlice(number, function(slice) {
0
while(slice.length < number) slice.push(fillWith);
0
@@ -713,7 +714,7 @@ var Enumerable = {
0
this.each(function(value, index) {
0
value = iterator(value, index);
0
- if (result ==
undefined || value >= result)
0
+ if (result ==
null || value >= result)
0
@@ -724,7 +725,7 @@ var Enumerable = {
0
this.each(function(value, index) {
0
value = iterator(value, index);
0
- if (result ==
undefined || value < result)
0
+ if (result ==
null || value < result)
0
@@ -904,7 +905,7 @@ Object.extend(Array.prototype, {
0
this.each(function(object) {
0
var value = Object.toJSON(object);
0
- if (
value !== undefined) results.push(value);
0
+ if (
!Object.isUndefined(value)) results.push(value);
0
return '[' + results.join(', ') + ']';
0
@@ -984,34 +985,6 @@ function $H(object) {
0
var Hash = Class.create(Enumerable, (function() {
0
- var i = 0, Test = function(value) { this.key = value };
0
- Test.prototype.key = 'foo';
0
- for (var property in new Test('bar')) i++;
0
- function each(iterator) {
0
- for (var key in this._object) {
0
- var value = this._object[key];
0
- if (cache.include(key)) continue;
0
- var pair = [key, value];
0
- function each(iterator) {
0
- for (var key in this._object) {
0
- var value = this._object[key], pair = [key, value];
0
function toQueryPair(key, value) {
0
if (Object.isUndefined(value)) return key;
0
@@ -1023,7 +996,14 @@ var Hash = Class.create(Enumerable, (function() {
0
this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
0
+ _each: function(iterator) {
0
+ for (var key in this._object) {
0
+ var value = this._object[key], pair = [key, value];
0
set: function(key, value) {
0
return this._object[key] = value;
0
@@ -1187,8 +1167,11 @@ Ajax.Base = Class.create({
0
Object.extend(this.options, options || { });
0
this.options.method = this.options.method.toLowerCase();
0
if (Object.isString(this.options.parameters))
0
this.options.parameters = this.options.parameters.toQueryParams();
0
+ else if (Object.isHash(this.options.parameters))
0
+ this.options.parameters = this.options.parameters.toObject();
0
@@ -1371,7 +1354,7 @@ Ajax.Response = Class.create({
0
var xml = transport.responseXML;
0
- this.responseXML =
xml === undefined ? null : xml;
0
+ this.responseXML =
Object.isUndefined(xml) ? null : xml;
0
this.responseJSON = this._getResponseJSON();
0
@@ -1417,10 +1400,11 @@ Ajax.Response = Class.create({
0
_getResponseJSON: function() {
0
var options = this.request.options;
0
if (!options.evalJSON || (options.evalJSON != 'force' &&
0
- !(this.getHeader('Content-type') || '').include('application/json')))
0
+ !(this.getHeader('Content-type') || '').include('application/json')) ||
0
+ this.responseText.blank())
0
- return this.
transport.responseText.evalJSON(options.sanitizeJSON);
0
+ return this.
responseText.evalJSON(options.sanitizeJSON);
0
this.request.dispatchException(e);
0
@@ -1434,11 +1418,11 @@ Ajax.Updater = Class.create(Ajax.Request, {
0
failure: (container.failure || (container.success ? null : container))
0
- options =
options || { };
0
+ options =
Object.clone(options);
0
var onComplete = options.onComplete;
0
- options.onComplete = (function(response,
param) {
0
+ options.onComplete = (function(response,
json) {
0
this.updateContent(response.responseText);
0
- if (Object.isFunction(onComplete)) onComplete(response,
param);
0
+ if (Object.isFunction(onComplete)) onComplete(response,
json);
0
@@ -1460,10 +1444,6 @@ Ajax.Updater = Class.create(Ajax.Request, {
0
else receiver.update(responseText);
0
- if (this.onComplete) this.onComplete.bind(this).defer();
0
@@ -1690,7 +1670,7 @@ Element.Methods = {
0
descendants: function(element) {
0
- return $
A($(element).getElementsByTagName('*')).each(Element.extend);
0
+ return $
(element).getElementsBySelector("*");
0
firstDescendant: function(element) {
0
@@ -1795,10 +1775,11 @@ Element.Methods = {
0
var attributes = { }, t = Element._attributeTranslations.write;
0
if (typeof name == 'object') attributes = name;
0
- else attributes[name] =
value === undefined ? true : value;
0
+ else attributes[name] =
Object.isUndefined(value) ? true : value;
0
for (var attr in attributes) {
0
- var name = t.names[attr] || attr, value = attributes[attr];
0
+ name = t.names[attr] || attr;
0
+ value = attributes[attr];
0
if (t.values[attr]) name = t.values[attr](element, value);
0
if (value === false || value === null)
0
element.removeAttribute(name);
0
@@ -1867,6 +1848,7 @@ Element.Methods = {
0
descendantOf: function(element, ancestor) {
0
element = $(element), ancestor = $(ancestor);
0
+ var originalAncestor = ancestor;
0
if (element.compareDocumentPosition)
0
return (element.compareDocumentPosition(ancestor) & 8) === 8;
0
@@ -1882,7 +1864,7 @@ Element.Methods = {
0
while (element = element.parentNode)
0
- if (element ==
ancestor) return true;
0
+ if (element ==
originalAncestor) return true;
0
@@ -1921,7 +1903,7 @@ Element.Methods = {
0
if (property == 'opacity') element.setOpacity(styles[property]);
0
elementStyle[(property == 'float' || property == 'cssFloat') ?
0
- (
elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') :
0
+ (
Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
0
property] = styles[property];
0
@@ -2301,7 +2283,7 @@ else if (Prototype.Browser.IE) {
0
return node ? node.value : "";
0
_getEv: function(element, attribute) {
0
-
var attribute = element.getAttribute(attribute);
0
+
attribute = element.getAttribute(attribute);
0
return attribute ? attribute.toString().slice(23, -2) : null;
0
_flag: function(element, attribute) {
0
@@ -2719,9 +2701,26 @@ var Selector = Class.create({
0
+ shouldUseXPath: function() {
0
+ if (!Prototype.BrowserFeatures.XPath) return false;
0
+ var e = this.expression;
0
+ // Safari 3 chokes on :*-of-type and :empty
0
+ if (Prototype.Browser.WebKit &&
0
+ (e.include("-of-type") || e.include(":empty")))
0
+ // XPath can't do namespaced attributes, nor can it read
0
+ // the "checked" property from DOM nodes
0
+ if ((/(\[[\w-]*?:|:checked)/).test(this.expression))
0
compileMatcher: function() {
0
- // Selectors with namespaced attributes can't use the XPath version
0
- if (Prototype.BrowserFeatures.XPath && !(/(\[[\w-]*?:|:checked)/).test(this.expression))
0
+ if (this.shouldUseXPath())
0
return this.compileXPathMatcher();
0
var e = this.expression, ps = Selector.patterns, h = Selector.handlers,
0
@@ -2844,8 +2843,12 @@ Object.extend(Selector, {
0
className: "[contains(concat(' ', @class, ' '), ' #{1} ')]",
0
- attrPresence: "[@#{1}]",
0
+ attrPresence: function(m) {
0
+ m[1] = m[1].toLowerCase();
0
+ return new Template("[@#{1}]").evaluate(m);
0
+ m[1] = m[1].toLowerCase();
0
return new Template(Selector.xpath.operators[m[2]]).evaluate(m);
0
@@ -2874,7 +2877,7 @@ Object.extend(Selector, {
0
'enabled': "[not(@disabled)]",
0
var e = m[6], p = Selector.patterns,
0
- x = Selector.xpath, le,
m, v;
0
+ x = Selector.xpath, le,
v;
0
while (e && le != e && (/\S/).test(e)) {
0
@@ -3051,7 +3054,7 @@ Object.extend(Selector, {
0
child: function(nodes) {
0
var h = Selector.handlers;
0
for (var i = 0, results = [], node; node = nodes[i]; i++) {
0
- for (var j = 0, child
ren = [], child; child = node.childNodes[j]; j++)
0
+ for (var j = 0, child
; child = node.childNodes[j]; j++)
0
if (child.nodeType == 1 && child.tagName != '!') results.push(child);
0
@@ -3323,7 +3326,8 @@ Object.extend(Selector, {
0
findChildElements: function(element, expressions) {
0
- var exprs = expressions.join(','), expressions = [];
0
+ var exprs = expressions.join(',');
0
exprs.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
0
expressions.push(m[1].strip());
0
@@ -3336,6 +3340,16 @@ Object.extend(Selector, {
0
+if (Prototype.Browser.IE) {
0
+ // IE returns comment nodes on getElementsByTagName("*").
0
+ Selector.handlers.concat = function(a, b) {
0
+ for (var i = 0, node; node = b[i]; i++)
0
+ if (node.tagName !== "!") a.push(node);
0
return Selector.findChildElements(document, $A(arguments));
0
@@ -3347,7 +3361,7 @@ var Form = {
0
serializeElements: function(elements, options) {
0
if (typeof options != 'object') options = { hash: !!options };
0
- else if (
options.hash === undefined) options.hash = true;
0
+ else if (
Object.isUndefined(options.hash)) options.hash = true;
0
var key, value, submitted = false, submit = options.submit;
0
var data = elements.inject({ }, function(result, element) {
0
@@ -3545,17 +3559,17 @@ Form.Element.Serializers = {
0
inputSelector: function(element, value) {
0
- if (
value === undefined) return element.checked ? element.value : null;
0
+ if (
Object.isUndefined(value)) return element.checked ? element.value : null;
0
else element.checked = !!value;
0
textarea: function(element, value) {
0
- if (
value === undefined) return element.value;
0
+ if (
Object.isUndefined(value)) return element.value;
0
else element.value = value;
0
select: function(element, index) {
0
- if (
index === undefined)
0
+ if (
Object.isUndefined(index))
0
return this[element.type == 'select-one' ?
0
'selectOne' : 'selectMany'](element);
0
@@ -3746,7 +3760,9 @@ Event.Methods = (function() {
0
findElement: function(event, expression) {
0
var element = Event.element(event);
0
- return element.match(expression) ? element : element.up(expression);
0
+ if (!expression) return element;
0
+ var elements = [element].concat(element.ancestors());
0
+ return Selector.findElement(elements, expression, 0);
0
pointer: function(event) {
0
@@ -3938,7 +3954,7 @@ Object.extend(Event, (function() {
0
element.fireEvent(event.eventType, event);
0
+ return
Event.extend(event);