?? prototype_mini.js
字號(hào):
var Prototype = {
Version: '1.5.1',
Browser: {
IE: !!(window.attachEvent && !window.opera)
},
emptyFunction: function() {},
K: function(x) { return x; }
};
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
};
}
};
Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
};
Object.extend(Object, {
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)));
};
};
var Try = {
these: function() {
var returnValue;
for (var i = 0, length = arguments.length; i < length; i++) {
var lambda = arguments[i];
try {
returnValue = lambda();
break;
} catch (e) {}
}
return returnValue;
}
};
Object.extend(String, {
interpret: function(value) {
return value == null ? '' : String(value);
},
specialChar: {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'\\': '\\\\'
}
});
Object.extend(String.prototype, {
strip: function() {
return this.replace(/^\s+/, '').replace(/\s+$/, '');
},
toQueryParams: function(separator) {
var match = this.strip().match(/([^?#]*)(#.*)?$/);
if (!match) return {};
return match[1].split(separator || '&').inject({}, function(hash, pair) {
if ((pair = pair.split('='))[0]) {
var key = decodeURIComponent(pair.shift());
var value = pair.length > 1 ? pair.join('=') : pair[0];
if (value != undefined) value = decodeURIComponent(value);
if (key in hash) {
if (hash[key].constructor != Array) hash[key] = [hash[key]];
hash[key].push(value);
}
else hash[key] = value;
}
return hash;
});
}
});
var $break = new Object();
var Enumerable = {
each: function(iterator) {
var index = 0;
try {
this._each(function(value) {
iterator(value, index++);
});
} catch (e) {
if (e != $break) { throw e; }
}
return this;
},
collect: function(iterator) {
var results = [];
this.each(function(value, index) {
results.push((iterator || Prototype.K)(value, index));
});
return results;
},
findAll: function(iterator) {
var results = [];
this.each(function(value, index) {
if (iterator(value, index)) {
results.push(value);
}
});
return results;
},
include: function(object) {
var found = false;
this.each(function(value) {
if (value == object) {
found = true;
throw $break;
}
});
return found;
},
inject: function(memo, iterator) {
this.each(function(value, index) {
memo = iterator(memo, value, index);
});
return memo;
},
pluck: function(property) {
var results = [];
this.each(function(value, index) {
results.push(value[property]);
});
return results;
},
toArray: function() {
return this.map();
}
};
Object.extend(Enumerable, {
map: Enumerable.collect,
select: Enumerable.findAll,
member: Enumerable.include
});
Array.from = function(iterable) {
if (!iterable) { return []; }
if (iterable.toArray) {
return iterable.toArray();
} else {
var results = [];
for (var i = 0, length = iterable.length; i < length; i++) {
results.push(iterable[i]);
}
return results;
}
};
var $A = Array.from;
Object.extend(Array.prototype, Enumerable);
Object.extend(Array.prototype, {
_each: function(iterator) {
for (var i = 0, length = this.length; i < length; i++){
iterator(this[i]);
}
},
without: function() {
var values = $A(arguments);
return this.select(function(value) {
return !values.include(value);
});
},
clone: function() {
return [].concat(this);
}
});
Array.prototype.toArray = Array.prototype.clone;
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('&');
}
});
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);
}
},
merge: function(hash) {
return $H(hash).inject(this, function(mergedHash, pair) {
mergedHash[pair.key] = pair.value;
return mergedHash;
});
},
toQueryString: function() {
return Hash.toQueryString(this);
}
});
function $H(object) {
if (object instanceof Hash) {return object;}
return new Hash(object);
}
/* =================================================================== */
var Ajax = {
getTransport: function() {
return Try.these(
function() {return new XMLHttpRequest();},
function() {return new ActiveXObject('Msxml2.XMLHTTP');},
function() {return new ActiveXObject('Microsoft.XMLHTTP');}
) || false;
},
activeRequestCount: 0
};
Ajax.Responders = {
responders: [],
_each: function(iterator) {
this.responders._each(iterator);
},
register: function(responder) {
if (!this.include(responder)){
this.responders.push(responder);
}
},
dispatch: function(callback, request, transport, json) {
this.each(function(responder) {
if (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--;
}
});
Ajax.Base = function() {};
Ajax.Base.prototype = {
setOptions: function(options) {
this.options = {
method: 'post',
asynchronous: true,
contentType: 'application/x-www-form-urlencoded',
encoding: 'UTF-8',
parameters: '',
nocache: true
};
Object.extend(this.options, options || {});
this.options.method = this.options.method.toLowerCase();
if (typeof this.options.parameters == 'string') {
this.options.parameters = this.options.parameters.toQueryParams();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -