/** * ecma5schims.js - Shim for ECMA5 compatibility * (http://en.wikipedia.org/wiki/Shim_%28computing%29) * * A shim library that implements common functions that are missing on some * environments in order to complete ECMA5 compatibility across all major * browsers. * * TODO: This code needs to be refactored so as to conform to Aloha coding * standards. It is also severly lacking in documentation. Please take * note of: https://github.com/alohaeditor/Aloha-Editor/wiki/Commit-Checklist . */ define([], function(){ var shims = { // Function bind bind: function(owner){ var obj = this.obj || this; var native_method = Function.prototype.bind; var args= Array.prototype.slice.call(arguments, 1); if(native_method){ return native_method.apply(obj, arguments); } else{ return function() { return obj.apply(owner, arguments.length===0? args : args.concat(Array.prototype.slice.call(arguments))); } } }, // String trim trim: function(){ var obj = this.obj || this; var native_method = String.prototype.trim; if(native_method){ return native_method.call(obj); } else { return obj.replace(/^\s+/, '').replace(/\s+$/, ''); } }, // Array methods indexOf: function(find, i /*opt*/){ var obj = this.obj || this; var native_method = Array.prototype.indexOf; if(native_method){ return native_method.call(obj, find, i); } else { if (i===undefined) i= 0; if (i<0) i+= obj.length; if (i<0) i= 0; for (var n = obj.length; i= 0 && node2.sourceIndex >= 0 ? (node1.sourceIndex < node2.sourceIndex && 4) + (node1.sourceIndex > node2.sourceIndex && 2) : 1); } //get a node with a sourceIndex to use function getUseNode(node) { //if the node already has a sourceIndex, use that node if ("sourceIndex" in node) return node; //otherwise, insert a comment (which has a sourceIndex but minimal DOM impact) before the node and use that return node.parentNode.insertBefore(document.createComment(""), node); } }; $_.getComputedStyle = function(node, style){ if('getComputedStyle' in window) { return window.getComputedStyle(node, style); } else { if( node.currentStyle ) { return node.currentStyle; } return null; } }; return $_; });