Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Created February 14, 2010 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmarkbage/304105 to your computer and use it in GitHub Desktop.
Save sebmarkbage/304105 to your computer and use it in GitHub Desktop.
More MooTools
/*
---
script: Array.Reduce.js
description: Extends Array with reduce and reduceRight methods in browsers that don't support them.
license: MIT-style license.
requires:
- /Array
provides: [Array.Reduce]
...
*/
Array.implement({
reduce: function(fn, value){
for (var i = 0, l = this.length; i < l; i++)
if (i in this)
value = value === undefined ? this[i] : fn.call(null, value, this[i], i, this);
return value;
},
reduceRight: function(fn, value){
var i = this.length;
while (i--)
if (i in this)
value = value === undefined ? this[i] : fn.call(null, value, this[i], i, this);
return value;
}
});
/*
---
script: Request.XML.js
description: Extends the basic Request Class by forcing a XML parsing even for unknown mime types.
license: MIT-style license.
requires:
- /Request
provides: [Request.XML]
...
*/
Request.XML = new Class({
Extends: Request,
success: function(text, xml){
try {
if (!xml || !xml.documentElement){
if (window.DOMParser){
xml = new DOMParser().parseFromString(text, 'text/xml');
} else {
try { xml = new ActiveXObject('MSXML2.DOMDocument'); }
catch (e){ xml = new ActiveXObject('Microsoft.XMLDOM'); }
xml.async = 'false';
xml.loadXML(text);
}
}
} catch (e){
xml = null;
}
this.response.xml = xml;
this.parent(text, xml);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment