[Jifty-commit] r4330 -
jifty/branches/prototype-1.6/share/web/static/js
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Oct 29 16:28:03 EDT 2007
Author: sunnavy
Date: Mon Oct 29 16:28:02 2007
New Revision: 4330
Modified:
jifty/branches/prototype-1.6/share/web/static/js/prototype.js
Log:
onclick works on 1.6.0 rc1 with Hash part of 1.5.1.1
Modified: jifty/branches/prototype-1.6/share/web/static/js/prototype.js
==============================================================================
--- jifty/branches/prototype-1.6/share/web/static/js/prototype.js (original)
+++ jifty/branches/prototype-1.6/share/web/static/js/prototype.js Mon Oct 29 16:28:02 2007
@@ -974,125 +974,7 @@
$w('abs round ceil floor').each(function(method){
Number.prototype[method] = Math[method].methodize();
});
-function $H(object) {
- return new Hash(object);
-};
-
-var Hash = Class.create(Enumerable, (function() {
- if (function() {
- var i = 0, Test = function(value) { this.key = value };
- Test.prototype.key = 'foo';
- for (var property in new Test('bar')) i++;
- return i > 1;
- }()) {
- function each(iterator) {
- var cache = [];
- for (var key in this._object) {
- var value = this._object[key];
- if (cache.include(key)) continue;
- cache.push(key);
- var pair = [key, value];
- pair.key = key;
- pair.value = value;
- iterator(pair);
- }
- }
- } else {
- function each(iterator) {
- for (var key in this._object) {
- var value = this._object[key], pair = [key, value];
- pair.key = key;
- pair.value = value;
- iterator(pair);
- }
- }
- }
-
- function toQueryPair(key, value) {
- if (Object.isUndefined(value)) return key;
- return key + '=' + encodeURIComponent(String.interpret(value));
- }
-
- return {
- initialize: function(object) {
- this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
- },
-
- _each: each,
-
- set: function(key, value) {
- return this._object[key] = value;
- },
-
- get: function(key) {
- return this._object[key];
- },
-
- unset: function(key) {
- var value = this._object[key];
- delete this._object[key];
- return value;
- },
-
- toObject: function() {
- return Object.clone(this._object);
- },
- keys: function() {
- return this.pluck('key');
- },
-
- values: function() {
- return this.pluck('value');
- },
-
- index: function(value) {
- var match = this.detect(function(pair) {
- return pair.value === value;
- });
- return match && match.key;
- },
-
- merge: function(object) {
- return this.clone().update(object);
- },
-
- update: function(object) {
- return new Hash(object).inject(this, function(result, pair) {
- result.set(pair.key, pair.value);
- return result;
- });
- },
-
- toQueryString: function() {
- return this.map(function(pair) {
- var key = encodeURIComponent(pair.key), values = pair.value;
-
- if (values && typeof values == 'object') {
- if (Object.isArray(values))
- return values.map(toQueryPair.curry(key)).join('&');
- }
- return toQueryPair(key, values);
- }).join('&');
- },
-
- inspect: function() {
- return '#<Hash:{' + this.map(function(pair) {
- return pair.map(Object.inspect).join(': ');
- }).join(', ') + '}>';
- },
-
- toJSON: function() {
- return Object.toJSON(this.toObject());
- },
-
- clone: function() {
- return new Hash(this);
- }
- }
-})());
-
-Hash.from = $H;
var ObjectRange = Class.create(Enumerable, {
initialize: function(start, end, exclusive) {
this.start = start;
@@ -1254,18 +1136,22 @@
'X-Prototype-Version': Prototype.Version,
'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
};
+ var headerNames = [ 'X-Requested-With', 'X-Prototype-Version', 'Accept' ];
if (this.method == 'post') {
- headers['Content-type'] = this.options.contentType +
- (this.options.encoding ? '; charset=' + this.options.encoding : '');
+ headers['Content-Type'] = this.options.contentType +
+ (this.options.encoding ? '; charset=' + this.options.encoding : '');
+ headerNames.push('Content-Type');
/* Force "Connection: close" for older Mozilla browsers to work
* around a bug where XMLHttpRequest sends an incorrect
* Content-length header. See Mozilla Bugzilla #246651.
*/
if (this.transport.overrideMimeType &&
- (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
+ (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) {
headers['Connection'] = 'close';
+ headerNames.push('Connection');
+ }
}
// user-defined headers
@@ -1273,14 +1159,20 @@
var extras = this.options.requestHeaders;
if (Object.isFunction(extras.push))
- for (var i = 0, length = extras.length; i < length; i += 2)
+ for (var i = 0, length = extras.length; i < length; i += 2) {
headers[extras[i]] = extras[i+1];
+ headerNames.push(extras[i]);
+ }
else
- $H(extras).each(function(pair) { headers[pair.key] = pair.value });
+ $H(extras).each(function(pair) {
+ headers[pair.key] = pair.value
+ headerNames.push(pair.key);
+ });
}
- for (var name in headers)
- this.transport.setRequestHeader(name, headers[name]);
+ for (var i=0; i<headerNames.length; i++) {
+ this.transport.setRequestHeader(headerNames[i], headers[headerNames[i]]);
+ }
},
success: function() {
@@ -2638,10 +2530,10 @@
return window[klass];
}
- if (F.ElementExtensions) {
- copy(Element.Methods, HTMLElement.prototype);
- copy(Element.Methods.Simulated, HTMLElement.prototype, true);
- }
+// if (F.ElementExtensions) {
+// copy(Element.Methods, HTMLElement.prototype);
+// copy(Element.Methods.Simulated, HTMLElement.prototype, true);
+// }
if (F.SpecificElementExtensions) {
for (var tag in Element.Methods.ByTag) {
@@ -3964,8 +3856,6 @@
})();
/*------------------------------- DEPRECATED -------------------------------*/
-Hash.toQueryString = Object.toQueryString;
-
var Toggle = { display: Element.toggle };
Element.Methods.childOf = Element.Methods.descendantOf;
@@ -4145,8 +4035,115 @@
}
};
+var Hash = function(object) {
+ if (object instanceof Hash) this.merge(object);
+ else Object.extend(this, object || {});
+};
+
+Object.extend(Hash, {
+ toQueryString: function(obj) {
+ var parts = [];
+ parts.add = arguments.callee.addPair;
+
+ this.prototype._each.call(obj, function(pair) {
+ if (!pair.key) return;
+ var value = pair.value;
+
+ if (value && typeof value == 'object') {
+ if (value.constructor == Array) value.each(function(value) {
+ parts.add(pair.key, value);
+ });
+ return;
+ }
+ parts.add(pair.key, value);
+ });
+
+ return parts.join('&');
+ },
+
+ toJSON: function(object) {
+ var results = [];
+ this.prototype._each.call(object, function(pair) {
+ var value = Object.toJSON(pair.value);
+ if (value !== undefined) results.push(pair.key.toJSON() + ': ' + value);
+ });
+ return '{' + results.join(', ') + '}';
+ }
+});
+
+Hash.toQueryString.addPair = function(key, value, prefix) {
+ key = encodeURIComponent(key);
+ if (value === undefined) this.push(key);
+ else this.push(key + '=' + (value == null ? '' : encodeURIComponent(value)));
+}
+
+Object.extend(Hash.prototype, Enumerable);
+Object.extend(Hash.prototype, {
+ _each: function(iterator) {
+ for (var key in this) {
+ var value = this[key];
+ if (value && value == Hash.prototype[key]) 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(this, function(mergedHash, pair) {
+ mergedHash[pair.key] = pair.value;
+ return mergedHash;
+ });
+ },
+
+ remove: function() {
+ var result;
+ for(var i = 0, length = arguments.length; i < length; i++) {
+ var value = this[arguments[i]];
+ if (value !== undefined){
+ if (result === undefined) result = value;
+ else {
+ if (result.constructor != Array) result = [result];
+ result.push(value)
+ }
+ }
+ delete this[arguments[i]];
+ }
+ return result;
+ },
+
+ toQueryString: function() {
+ return Hash.toQueryString(this);
+ },
+
+ inspect: function() {
+ return '#<Hash:{' + this.map(function(pair) {
+ return pair.map(Object.inspect).join(': ');
+ }).join(', ') + '}>';
+ },
+
+ toJSON: function() {
+ return Hash.toJSON(this);
+ }
+});
+
+function $H(object) {
+ if (object instanceof Hash) return object;
+ return new Hash(object);
+};
+
Object.extend(Element.ClassNames.prototype, Enumerable);
/*--------------------------------------------------------------------------*/
-Element.addMethods();
\ No newline at end of file
+Element.addMethods();
More information about the Jifty-commit
mailing list