License MIT license
Lines 131
Keywords
backwards compatibility (2) MooTools (5) MooTools 1.2 (2) upgrade (3)
Permissions
Group Owner: iCapsid
Viewable by Everyone
Editable by All Siafoo Users
Hide
Easily highlight source code for your blog with our Syntax Highlighter. Join Siafoo Now or Learn More

MooTools 1.2 Custom Backwards-Compatibility Library Atom Feed 2

In Brief A backwards compatibility library for Mootools 1.2, in addition to those by MooTools. Should fix most remaining backwards-compatibility problems.... more
# 's
  1/*
2MooTools 1.2 Custom Backwards-Compatibility Library
3By David Isaacson
4Portions from Mootools 1.2 by the MooTools production team (http://mootools.net/developers/)
5Copyright (c) 2006-2007 Valerio Proietti (http://mad4milk.net/)
6Copyright (c) 2008 Siafoo.net
7
8Load after Mootools Core and More and both compatibility files
9
10Blocks that are commented out are not needed if using the 1.2.4 compatibility code from MooTools I (Stou) left them in here in case you are using and older version of MooTools
11*/
12
13// This is the definition from Mootools 1.2, with error handling
14// to prevent an issue in IE where calling .item on an XML (non-HTML)
15// element raises an error.
16//
17// We're using the 1.2 version in the first place because the compat version throws *other* weird errors sometimes
18// Note that this will prevent you from using the $A(iterable, start, length) syntax allowed but undocumented (?) in Mootools 1.1
19function $A(iterable){
20 var item
21 try{
22 item = iterable.item
23 }
24 catch(e){
25 item = true
26 }
27
28 if (item){
29 var array = [];
30 for (var i = 0, l = iterable.length; i < l; i++) array[i] = iterable[i];
31 return array;
32 }
33 return Array.prototype.slice.call(iterable);
34}
35
36
37function $extend(original, extended){
38 if (!extended) {extended=original; original=this;} // This line added
39 for (var key in (extended || {})) original[key] = extended[key];
40 return original;
41}
42
43Drag.Base = Drag
44
45Element.implement({
46/*
47 getValue: function(){
48 return this.get('value')
49 },
50*/
51
52 // Very slightly modified from mootools
53 toQueryString: function(){
54 var queryString = [];
55 this.getElements('input, select, textarea').each(function(el){
56 if (!el.name || el.disabled) return;
57 var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){
58 return opt.value;
59 }) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value;
60 $splat(value).each(function(val){
61 /*if (val)*/ queryString.push(el.name + '=' + encodeURIComponent(val));
62 });
63 });
64 return queryString.join('&');
65 }
66})
67
68Elements.implement({
69 // I would actually consider this a bug
70 // Also I'm sure there's a more consistant way than this to implement it
71 empty: function(){
72 this.each(function(element){
73 element.empty()
74 })
75 },
76/*
77 remove: function(){
78 this.each(function(element){
79 element.remove()
80 })
81 }
82*/
83})
84
85/*
86// Class.prototype.extend in the compat library doesn't actually work for some reason. So...
87// Note that this will hide Function.extend from use in certain cases
88Function.prototype.extend = function(properties){
89 if (this.prototype){
90 // Assume its a class
91 properties.Extends = this;
92 return new Class(properties);
93 }
94 for (var property in properties) this[property] = properties[property];
95 return this;
96}
97
98Hash.implement({
99 remove: function(key){
100 return this.erase(key)
101 }
102})
103*/
104Hash.Cookie.implement({
105
106 remove: function(key){
107 var value = this.hash.erase(key)
108 if (this.options.autoSave) this.save();
109 return value
110 }
111})
112/*
113XHR.implement({
114
115 initialize: function(options){
116 this.parent(options)
117 this.transport = this.xhr
118 }
119})
120
121
122var Ajax = new Class({
123 Extends: XHR,
124
125 initialize: function(url, options){
126 this.url = url
127 this.parent(options)
128 },
129
130 success: function(text, xml){
131 // This version processes scripts *after* the update element is updated, like Mootools 1.1's Ajax class
132 // Partially from Remote.Ajax.success
133 response = this.response;
134 response.html = text.stripScripts(function(script){
135 response.javascript = script;
136 })
137 if (this.options.update) $(this.options.update).empty().set('html', response.html);
138 if (this.options.evalScripts) $exec(response.javascript);
139 this.onSuccess(text, xml);
140 }
141})
142*/
143/* For further information, read http://www.siafoo.net/article/62 */

A backwards compatibility library for Mootools 1.2, in addition to those by MooTools. Should fix most remaining backwards-compatibility problems.

Load it after all four Core and More base files and compatibility files.

For more information about upgrading to Mootools 1.2, including a list of backwards-compatibility problems that this doesn't solve and their solutions, read Upgrading to MooTools 1.2 - Tips, Tricks, and Backwards Compatibility

Changelog

2009-03-23: AJAX class: scripts are now only processed once, after the element has been updated 2010-03-25: Commented out things included in MooTools 1.2.4