-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshim.js
119 lines (107 loc) · 3.26 KB
/
shim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
define(function(){
// summary:
// A shim to make older browsers behave more like modern browsers.
// While this obviously means IE, it also means not-so-old Webkit
// browsers that did not yet have Function.bind.
// returns: null
// This is not a module. It adds functionality to native JavaScript
// objects.
// description:
// The methods added are:
// Function.bind
// Array.forEach
// Array.some
// Array.indexOf
// Array.isArray
// TODO: Add remaining Array methods.
//
if(!Function.prototype.bind){
Function.prototype.bind = function (oThis) {
// from Mozilla
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var fSlice = Array.prototype.slice,
aArgs = fSlice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP
? this
: oThis || window,
aArgs.concat(fSlice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
}
}
if(!([]).forEach){
// TODO! Add the rest! At least map();!
Array.prototype.forEach = function(fn, ctx){
ctx = ctx || window;
var f = fn.bind(ctx);
for(var i=0;i<this.length;i++){
f(this[i], i, this);
}
}
Array.prototype.some = function(fn, ctx){
ctx = ctx || window;
var f = fn.bind(ctx);
var i, len = this.length;
for(i=0;i<len;i++){
if(f(this[i], i, this)) return true;
}
return false;
}
Array.prototype.indexOf = function(elem){
var i, len = this.length;
for(i=0;i<len;i++){
if(this[i] == elem) return i;
}
return -1;
}
// HTML5 SHIV
// Important note:
// This doesn't load in time for the DOM when using the async loader.
// During devm use dx-alias/html5.js loaded in a script tag.
// For prod, the built JS will load sync, and the following code
// will work in time.
//
var a = document.createElement('a');
a.innerHTML = '<xyz></xyz>';
//if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles
supportsHtml5Styles = ('hidden' in a);
if(!supportsHtml5Styles){
try{
var n = ("abbr,article,aside,audio,canvas,datalist,details," +
"figure,footer,header,hgroup,mark,menu,meter,nav,output," +
"progress,section,time,video").split(',');
for (var i = 0; i < n.length; i++) {
document.createElement(n[i]);
}
}catch(e){
console.error("ERROR:", e);
}
}
}
if(!Array.isArray){
Array.isArray = function(item){
return item && typeof item == 'object' && item instanceof Array;
}
}
require.argsToObject = function(mid){
var module = require.modules[mid];
var name;
var args = {};
//console.dir(module.deps);
for(var i=0; i<module.deps.length; i++){
var m = module.deps[i].mid;
name = m.substring(m.lastIndexOf('/')+1, m.length);
args[name] = module.deps[i].result;
}
return args;
}
return null; // sets environmental helpers, does not return anything
});