Created
December 27, 2009 10:59
-
-
Save fakedarren/264243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!window.console) var console = {}; | |
if(!console.warn) console.warn = function(){}; | |
(function(){ | |
oldA = $A; | |
window.$A = function(iterable, start, length){ | |
if (start != undefined && length != undefined) { | |
console.warn('1.1 > 1.2: $A no longer takes start and length arguments.'); | |
if (Browser.Engine.trident && $type(iterable) == 'collection'){ | |
start = start || 0; | |
if (start < 0) start = iterable.length + start; | |
length = length || (iterable.length - start); | |
var array = []; | |
for (var i = 0; i < length; i++) array[i] = iterable[start++]; | |
return array; | |
} | |
start = (start || 0) + ((start < 0) ? iterable.length : 0); | |
var end = ((!$chk(length)) ? iterable.length : length) + start; | |
return Array.prototype.slice.call(iterable, start, end); | |
} | |
return oldA(iterable); | |
}; | |
var natives = [Array, Function, String, RegExp, Number]; | |
for (var i = 0, l = natives.length; i < l; i++) { | |
var extend = natives[i].extend; | |
natives[i].extend = function(props){ | |
console.warn('1.1 > 1.2: native types no longer use .extend to add methods to prototypes but instead use .implement.'); | |
for (var prop in props){ | |
if (!this.prototype[prop]) this.prototype[prop] = props[prop]; | |
} | |
return extend.apply(this, arguments); | |
}; | |
} | |
})(); | |
var $native = function(){ | |
for (var i = 0, l = arguments.length; i < l; i++){ | |
arguments[i].extend = function(props){ | |
console.warn('1.1 > 1.2: native types no longer have an .extend method; use .implement instead.'); | |
for (var prop in props){ | |
if (!this.prototype[prop]) this.prototype[prop] = props[prop]; | |
if (!this[prop]) this[prop] = $native.generic(prop); | |
} | |
}; | |
} | |
}; | |
$native.generic = function(prop){ | |
return function(bind){ | |
return this.prototype[prop].apply(bind, Array.prototype.slice.call(arguments, 1)); | |
}; | |
}; | |
window.extend = document.extend = function(properties){ | |
console.warn('1.1 > 1.2: window no longer has an .extend method; use .implement instead.'); | |
for (var property in properties) this[property] = properties[property]; | |
}; | |
if (window.__defineGetter__){ | |
window.__defineGetter__('ie',function(){ | |
console.warn('1.1 > 1.2: window.ie is deprecated. Use Browser.Engine.trident'); | |
return (Browser.Engine.name == 'trident') ? true : false; | |
}); | |
window.__defineGetter__('ie6',function(){ | |
console.warn('1.1 > 1.2: window.ie6 is deprecated. Use Browser.Engine.trident and Browser.Engine.version'); | |
return (Browser.Engine.name == 'trident' && Browser.Engine.version == 4) ? true : false; | |
}); | |
window.__defineGetter__('ie7',function(){ | |
console.warn('1.1 > 1.2: window.ie7 is deprecated. Use Browser.Engine.trident and Browser.Engine.version'); | |
return (Browser.Engine.name == 'trident' && Browser.Engine.version == 5) ? true : false; | |
}); | |
window.__defineGetter__('gecko',function(){ | |
console.warn('1.1 > 1.2: window.gecko is deprecated. Use Browser.Engine.gecko'); | |
return (Browser.Engine.name == 'gecko') ? true : false; | |
}); | |
window.__defineGetter__('webkit',function(){ | |
console.warn('1.1 > 1.2: window.webkit is deprecated. Use Browser.Engine.webkit'); | |
return (Browser.Engine.name == 'webkit') ? true : false; | |
}); | |
window.__defineGetter__('webkit419',function(){ | |
console.warn('1.1 > 1.2: window.webkit is deprecated. Use Browser.Engine.webkit and Browser.Engine.version'); | |
return (Browser.Engine.name == 'webkit' && Browser.Engine.version == 419) ? true : false; | |
}); | |
window.__defineGetter__('webkit420',function(){ | |
console.warn('1.1 > 1.2: window.webkit is deprecated. Use Browser.Engine.webkit and Browser.Engine.version'); | |
return (Browser.Engine.name == 'webkit' && Browser.Engine.version == 420) ? true : false; | |
}); | |
window.__defineGetter__('opera',function(){ | |
console.warn('1.1 > 1.2: window.opera is deprecated. Use Browser.Engine.presto'); | |
return (Browser.Engine.name == 'presto') ? true : false; | |
}); | |
} else { | |
window[Browser.Engine.name] = window[Browser.Engine.name + Browser.Engine.version] = true; | |
window.ie = window.trident; | |
window.ie6 = window.trident4; | |
window.ie7 = window.trident5; | |
} | |
Array.implement({ | |
copy: function(start, length){ | |
console.warn('1.1 > 1.2: Array.copy is deprecated. Use Array.slice'); | |
return $A(this, start, length); | |
}, | |
remove : function(item){ | |
console.warn('1.1 > 1.2: Array.remove is deprecated. Use Array.erase'); | |
return this.erase(item); | |
}, | |
merge : function(array){ | |
console.warn('1.1 > 1.2: Array.merge is deprecated. Use Array.combine'); | |
return this.combine(array); | |
} | |
}); | |
Function.extend({ | |
bindAsEventListener: function(bind, args){ | |
console.warn('1.1 > 1.2: Function.bindAsEventListener is deprecated.'); | |
return this.create({'bind': bind, 'event': true, 'arguments': args}); | |
} | |
}); | |
Function.empty = function(){ | |
console.warn('1.1 > 1.2: Function.empty is now just $empty.'); | |
}; | |
Hash.implement({ | |
keys : function(){ | |
console.warn('1.1 > 1.2: Hash.keys is deprecated. Use Hash.getKeys'); | |
return this.getKeys(); | |
}, | |
values : function(){ | |
console.warn('1.1 > 1.2: Hash.values is deprecated. Use Hash.getValues'); | |
return this.getValues(); | |
}, | |
hasKey : function(item){ | |
console.warn('1.1 > 1.2: Hash.hasKey is deprecated. Use Hash.has'); | |
return this.has(item); | |
}, | |
merge : function(properties){ | |
console.warn('1.1 > 1.2: Hash.merge is deprecated. Use Hash.combine'); | |
return this.extend(properties); | |
}, | |
remove: function(key){ | |
console.warn('1.1 > 1.2: Hash.remove is deprecated. use Hash.erase'); | |
return this.erase(key); | |
} | |
}); | |
Object.toQueryString = function(obj){ | |
console.warn('1.1 > 1.2: Object.toQueryString() is deprecated. use Hash.toQueryString() instead'); | |
$H(obj).each(function(item, key){ | |
if ($type(item) == 'object' || $type(item) == 'array'){ | |
obj[key] = item.toString(); | |
} | |
}); | |
return Hash.toQueryString(obj); | |
}; | |
var Abstract = function(obj){ | |
console.warn('1.1 > 1.2: Abstract is deprecated. Use Hash'); | |
return new Hash(obj); | |
}; | |
Class.empty = function(){ | |
console.warn('1.1 > 1.2: replace Class.empty with $empty'); | |
return $empty; | |
}; | |
//legacy .extend support | |
(function(){ | |
var proto = function(obj) { | |
var f = function(){ | |
return this; | |
}; | |
f.prototype = obj; | |
return f; | |
}; | |
Class.prototype.extend = function(properties){ | |
console.warn('1.1 > 1.2: Class.extend is deprecated. See the class Extend mutator.'); | |
var maker = proto(properties); | |
var made = new maker(); | |
made.Extends = this; | |
return new Class(made); | |
}; | |
var __implement = Class.prototype.implement; | |
Class.prototype.implement = function(){ | |
if (arguments.length > 1 && Array.every(arguments, Object.type)){ | |
console.warn('1.1 > 1.2: Class.implement no longer takes more than one thing at a time, either MyClass.implement(key, value) or MyClass.implement(object) but NOT MyClass.implement(new Foo, new Bar, new Baz). See also: the class Implements mutator.'); | |
Array.each(arguments, function(argument){ | |
__implement.call(this, argument); | |
}, this); | |
return this; | |
} | |
return __implement.apply(this, arguments); | |
}; | |
})(); | |
Element.extend = function(obj){ | |
console.warn('1.1 > 1.2: Element.extend is deprecated. Use Element.implement'); | |
Element.implement(obj); | |
}; | |
Elements.extend = function(obj){ | |
console.warn('1.1 > 1.2: Elements.extend is deprecated. Use Elements.implement'); | |
Elements.implement(obj); | |
}; | |
(function(){ | |
var toQueryString = Element.prototype.toQueryString; | |
Element.implement({ | |
getFormElements: function(){ | |
console.warn('1.1 > 1.2: Element.getFormElements is deprecated, use Element.getElements("input, textarea, select");'); | |
return this.getElements('input, textarea, select'); | |
}, | |
replaceWith: function(el){ | |
console.warn('1.1 > 1.2: Element.replaceWith is deprecated, use Element.replaces instead.'); | |
el = $(el); | |
this.parentNode.replaceChild(el, this); | |
return el; | |
}, | |
remove: function() { | |
console.warn('1.1 > 1.2: Element.remove is deprecated - use Element.dispose.'); | |
return this.dispose.apply(this, arguments); | |
}, | |
getText: function(){ | |
console.warn('1.1 > 1.2: Element.getText is deprecated - use Element.get("text").'); | |
return this.get('text'); | |
}, | |
setText: function(text){ | |
console.warn('1.1 > 1.2: Element.setText is deprecated - use Element.set("text", text).'); | |
return this.set('text', text); | |
}, | |
setHTML: function(){ | |
console.warn('1.1 > 1.2: Element.setHTML is deprecated - use Element.set("html", HTML).'); | |
return this.set('html', arguments); | |
}, | |
getHTML: function(){ | |
console.warn('1.1 > 1.2: Element.getHTML is deprecated - use Element.get("html").'); | |
return this.get('html'); | |
}, | |
getTag: function(){ | |
console.warn('1.1 > 1.2: Element.getTag is deprecated - use Element.get("tag").'); | |
return this.get('tag'); | |
}, | |
getValue: function(){ | |
console.warn('1.1 > 1.2: Element.getValue is deprecated - use Element.get("value").'); | |
switch(this.getTag()){ | |
case 'select': | |
var values = []; | |
$each(this.options, function(option){ | |
if (option.selected) values.push($pick(option.value, option.text)); | |
}); | |
return (this.multiple) ? values : values[0]; | |
case 'input': if (!(this.checked && ['checkbox', 'radio'].contains(this.type)) && !['hidden', 'text', 'password'].contains(this.type)) break; | |
case 'textarea': return this.value; | |
} | |
return false; | |
}, | |
toQueryString: function(){ | |
console.warn('1.1 > 1.2: warning Element.toQueryString is slightly different; inputs without names are excluded, inputs with type == submit, reset, and file are excluded, and inputs with undefined values are excluded.'); | |
return toQueryString.apply(this, arguments); | |
} | |
}); | |
})(); | |
window.extend = document.extend = function(properties){ | |
console.warn('1.1 > 1.2: (window||document).extend is deprecated'); | |
for (var property in properties) this[property] = properties[property]; | |
}; | |
Element.Properties.properties = { | |
set: function(props){ | |
console.warn('1.1 > 1.2: Element.set({properties: {}}) is deprecated; instead of properties, just name the values at the root of the object (Element.set({src: url})).'); | |
$H(props).each(function(value, property){ | |
this.set(property, value); | |
}, this); | |
} | |
}; | |
Event.keys = Event.Keys; // TODO | |
Element.implement({ | |
setOpacity: function(op){ | |
console.warn('1.1 > 1.2: Element.setOpacity is deprecated; use Element.setStyle("opacity", value).'); | |
return this.set('opacity', op); | |
} | |
}); | |
Element.Properties.styles = { | |
set: function(styles){ | |
console.warn('1.1 > 1.2: Element.set("styles") no longer accepts a string as an argument. Pass an object instead.'); | |
if ($type(styles) == 'string'){ | |
styles.split(";").each(function(style){ | |
this.setStyle(style.split(":")[0], style.split(":")[1]); | |
}, this); | |
} else { | |
this.setStyles(styles); | |
} | |
} | |
}; | |
(function(){ | |
var getPosition = Element.prototype.getPosition; | |
var getCoordinates = Element.prototype.getCoordinates; | |
function isBody(element){ | |
return (/^(?:body|html)$/i).test(element.tagName); | |
}; | |
var getSize = Element.prototype.getSize; | |
Element.implement({ | |
getSize: function(){ | |
console.warn('1.1 > 1.2: NOTE: getSize is different in 1.2; it no longer returns values for size, scroll, and scrollSize, but instead just returns x/y values for the dimensions of the element.'); | |
var size = getSize.apply(this, arguments); | |
return $merge(size, { | |
size: size, | |
scroll: this.getScroll(), | |
scrollSize: this.getScrollSize() | |
}); | |
}, | |
getPosition: function(relative){ | |
if (relative && $type(relative) == "array") { | |
console.warn('1.1 > 1.2: Element.getPosition no longer accepts an array of overflown elements but rather, optionally, a single element to get relative coordinates.'); | |
} | |
return getPosition.apply(this, arguments); | |
}, | |
getCoordinates: function(relative){ | |
if (relative && $type(relative) == "array") { | |
console.warn('1.1 > 1.2: Element.getCoordinates no longer accepts an array of overflown elements but rather, optionally, a single element to get relative coordinates.'); | |
} | |
return getCoordinates.apply(this, arguments); | |
} | |
}); | |
Native.implement([Document, Window], { | |
getSize: function(){ | |
console.warn('1.1 > 1.2: NOTE: getSize is different in 1.2; it no longer returns values for size, scroll, and scrollSize, but instead just returns x/y values for the dimensions of the element.'); | |
var size; | |
var win = this.getWindow(); | |
var doc = this.getDocument(); | |
doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body; | |
if (Browser.Engine.presto || Browser.Engine.webkit){ | |
size = {x: win.innerWidth, y: win.innerHeight}; | |
} else { | |
size = {x: doc.clientWidth, y: doc.clientHeight}; | |
} | |
return $extend(size, { | |
size: size, | |
scroll: {x: win.pageXOffset || doc.scrollLeft, y: win.pageYOffset || doc.scrollTop}, | |
scrollSize: {x: Math.max(doc.scrollWidth, size.x), y: Math.max(doc.scrollHeight, size.y)} | |
}); | |
} | |
}); | |
})(); | |
Native.implement([Element, Document], { | |
getElementsByClassName: function(className){ | |
console.warn('1.1 > 1.2: Element.getElementsByClassName is deprecated. Use getElements()'); | |
return this.getElements('.' + className); | |
}, | |
getElementsBySelector: function(selector){ | |
console.warn('1.1 > 1.2: Element.getElementsBySelector is deprecated. Use getElements()'); | |
return this.getElements(selector); | |
} | |
}); | |
Elements.implement({ | |
filterByTag: function(tag){ | |
console.warn('1.1 > 1.2: Elements.filterByTag is deprecated. Use Elements.filter.'); | |
return this.filter(tag); | |
}, | |
filterByClass: function(className){ | |
console.warn('1.1 > 1.2: Elements.filterByClass is deprecated. Use Elements.filter.'); | |
return this.filter('.' + className); | |
}, | |
filterById: function(id){ | |
console.warn('1.1 > 1.2: Elements.filterById is deprecated. Use Elements.filter.'); | |
return this.filter('#' + id); | |
}, | |
filterByAttribute: function(name, operator, value){ | |
console.warn('1.1 > 1.2: Elements.filterByAttribute is deprecated. Use Elements.filter.'); | |
var filtered = this.filter('[' + name + (operator || '') + (value || '') + ']'); | |
if (value) filtered = filtered.filter('[' + name + ']'); | |
return filtered; | |
} | |
}); | |
var $E = function(selector, filter){ | |
console.warn('1.1 > 1.2: $E is deprecated, use document.getElement.'); | |
return ($(filter) || document).getElement(selector); | |
}; | |
var $ES = function(selector, filter){ | |
console.warn('1.1 > 1.2: $ES is deprecated. Use $$.'); | |
return ($(filter) || document).getElements(selector); | |
}; | |
Cookie.set = function(key, value, options){ | |
console.warn('1.1 > 1.2: Cookie.set is deprecated. Use Cookie.write'); | |
return new Cookie(key, options).write(value); | |
}; | |
Cookie.get = function(key){ | |
console.warn('1.1 > 1.2: Cookie.get is deprecated. Use Cookie.read'); | |
return new Cookie(key).read(); | |
}; | |
Cookie.remove = function(key, options){ | |
console.warn('1.1 > 1.2: Cookie.remove is deprecated. Use Cookie.dispose'); | |
return new Cookie(key, options).dispose(); | |
}; | |
JSON.toString = function(obj){ | |
console.warn('1.1 > 1.2: JSON.toString is deprecated. Use JSON.encode'); | |
return JSON.encode(obj); | |
} | |
JSON.evaluate = function(str){ | |
console.warn('1.1 > 1.2: JSON.evaluate is deprecated. Use JSON.decode'); | |
return JSON.decode(str); | |
} | |
var Json = JSON; | |
Fx.implement({ | |
custom: function(from, to){ | |
console.warn('1.1 > 1.2: Fx.custom is deprecated. use Fx.start.'); | |
return this.start(from, to); | |
}, | |
clearTimer: function(){ | |
console.warn('1.1 > 1.2: Fx.clearTimer is deprecated. use Fx.cancel.'); | |
return this.cancel(); | |
}, | |
stop: function(){ | |
console.warn('1.1 > 1.2: Fx.stop is deprecated. use Fx.cancel.'); | |
return this.cancel(); | |
} | |
}); | |
Fx.Base = new Class({ | |
Extends: Fx, | |
initialize: function(){ | |
console.warn('1.1 > 1.2: Fx.Base is deprecated. use Fx.'); | |
this.parent.apply(this, arguments); | |
} | |
}); | |
Fx.Style = new Class({ | |
Extends: Fx.Tween, | |
initialize: function(){ | |
console.warn('1.1 > 1.2: Fx.Style is deprecated. use Fx.Tween.'); | |
this.parent.apply(this, arguments); | |
} | |
}); | |
Element.implement({ | |
effect: function(options){ | |
console.warn('1.1 > 1.2: Element.effect is deprecated; use Fx.Tween or Element.tween.'); | |
return new Fx.Tween(this, options); | |
} | |
}); | |
Fx.Tween.implement({ | |
hide: function(){ | |
console.warn('1.1 > 1.2: Fx.Style .hide() is deprecated; use Fx.Tween .set(0) instead'); | |
return this.set(0); | |
} | |
}); | |
Fx.Styles = new Class({ | |
Extends: Fx.Morph, | |
initialize: function(){ | |
console.warn('1.1 > 1.2: Fx.Styles is deprecated. use Fx.Morph.'); | |
this.parent.apply(this, arguments); | |
} | |
}); | |
Element.implement({ | |
effects: function(options){ | |
console.warn('1.1 > 1.2: Element.effects is deprecated; use Fx.Morph or Element.morph.'); | |
return new Fx.Morph(this, options); | |
} | |
}); | |
Fx.Scroll.implement({ | |
scrollTo: function(y, x){ | |
console.warn('1.1 > 1.2: Fx.Scroll\'s .scrollTo is deprecated; use .start.'); | |
return this.start(y, x); | |
} | |
}); | |
var XHR = new Class({ | |
Extends: Request, | |
options: { | |
update: false | |
}, | |
initialize: function(options){ | |
console.warn('1.1 > 1.2: XHR is deprecated. Use Request.'); | |
this.parent(options); | |
this.transport = this.xhr; | |
}, | |
request: function(data){ | |
console.warn('1.1 > 1.2: XHR.request() is deprecated. Use Request.send() instead.'); | |
return this.send(this.url, data || this.options.data); | |
}, | |
send: function(url, data){ | |
if (!this.check(arguments.callee, url, data)) return this; | |
return this.parent({url: url, data: data}); | |
}, | |
success: function(text, xml){ | |
text = this.processScripts(text); | |
if (this.options.update) $(this.options.update).empty().set('html', text); | |
this.onSuccess(text, xml); | |
}, | |
failure: function(){ | |
this.fireEvent('failure', this.xhr); | |
} | |
}); | |
var Ajax = new Class({ | |
Extends: XHR, | |
initialize: function(url, options){ | |
console.warn('1.1 > 1.2: Ajax is deprecated. Use Request.'); | |
this.url = url; | |
this.parent(options); | |
}, | |
success: function(text, xml){ | |
// This version processes scripts *after* the update element is updated, like Mootools 1.1's Ajax class | |
// Partially from Remote.Ajax.success | |
response = this.response; | |
response.html = text.stripScripts(function(script){ | |
response.javascript = script; | |
}); | |
if (this.options.update) $(this.options.update).empty().set('html', response.html); | |
if (this.options.evalScripts) $exec(response.javascript); | |
this.onSuccess(text, xml); | |
} | |
}); | |
JSON.Remote = new Class({ | |
options: { | |
key: 'json' | |
}, | |
Extends: Request.JSON, | |
initialize: function(url, options){ | |
console.warn('1.1 > 1.2: JSON.Remote is deprecated. Use Request.JSON'); | |
this.parent(options); | |
this.onComplete = $empty; | |
this.url = url; | |
}, | |
send: function(data){ | |
if (!this.check(arguments.callee, data)) return this; | |
return this.parent({url: this.url, data: {json: Json.encode(data)}}); | |
}, | |
failure: function(){ | |
this.fireEvent('failure', this.xhr); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment