-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsCompatible.js
317 lines (280 loc) · 10.7 KB
/
jsCompatible.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/**********************************************************************************************************************************************************
File: jsCompatible.js
Fixes gaps in various javascript browsers.
Script type:
javascript, global self loading script (Not JSON-Script compliant)
Version:
Alpha 1.2 (05 Nov 2012)
Longer Discription:
Ensures that, as much as possible, the missing functionalities of the client JavaScript browser are "fixed".
This prioritizes mainly function calls, which may be a core of many script, and not the modern HTML5 features.
Main refrences:
https://developer.mozilla.org/en-US/docs/JavaScript
ToDo:
Future suggestion:
- Collect the functionalitiy check results. So that programs can check for dependencies against.
BUGS:
Notes:
***********************************************************************************************************************************************************
Author Details & CopyRight:
author - picoCreator AKA Eugene Cheah
email - [email protected]
website - blog.pic-o.com
copyright - cc by [CreativeCommons Attribution licenses]
http://creativecommons.org/licenses/by/3.0/
CC notes:
+ Crediting me (Eugene Cheah AKA picoCreator) is required for derivatives of this work, UNLESS...
+ An exception is given for using this on a live deployment, (eg, using this for your blog in the background) in which crediting every single page may be impractical (even for commercial sites).
+ However this exception is only given if you drop me an email, with the link to deployment.
+ This exception however does not hold in any source release of which this code is used (Its stated in the cc license btw), hence credit should be given in this case.
+ These license requirments would be applied to all forks / merges / derivatives, of this work.
Additional Copyright Notes:
+ I may update to add an additional open source licenses in the future / on requested =)
+ Remember to drop an email if you are using this for a live site, ty. (for my curiosity, to see where this code goes)
+ This copyright applies only to the file "jsCompatible.js", NOT the whole asac framework
**********************************************************************************************************************************************************/
(function(){
/***************************************************************************
* Function: console
* Console hack, Ensures console functions calls are handled
* gracefully (silent ignore), in event it is not built/enabled client-side.
*
* (console . log/warn/error/info supported)
****************************************************************************/
if(!window.console) window.console = {};
if(!console.log) console.log = function(){};
if(!console.warn) console.warn = function(){};
if(!console.error) console.error = function(){};
if(!console.info) console.info = function(){};
return true; //Ends hacking -> Success / Exists
})();
/***************************************************************************
* Function: getElementByID
* DOM functionality hacking of document.getElementByID
* Returns true / false on hack check success
*
* Modified from: http://www.netlobo.com/javascript_get_element_id.html
***************************************************************************/
(function () {
if (!document.getElementById) {
if (document.all) {
document.getElementById = function getElementById(id) { return document.all[id]; };
} else if (document.layers) {
document.getElementById = function getElementById(id) { return document.layers[id]; };
} else {
return false; //Ends hacking -> Failed
}
return true; //Ends hacking -> Success
}
return true; //Ends hacking -> Exists
})();
/*******************************************************************
* [Removed] This is a non-standard feature in any browser,
* Hence there is a reasonable chance of future potential conflict
* And the consequence of massive code refactoring.
*
* Prototype Object.extend functionality check
* Returns true / false on hack check success
*
* While, this is not part of the offical standard,
* there are dependencies on this framework that relies on it.
********************************************************************/
/*
(function(){
//Ensures Object.extend works / exists
if (!Object.extend) {
Object.extend = function extend(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
return true; //Ends hacking -> Success
//return false; //Ends hacking -> Failed
}
return true; //Ends hacking -> Exists
})();
*/
/***********************************************************
* Function: Object.create
* [For outdated browsers]
* Returns true / false on hack check success
************************************************************/
(function(){
//Ensures Object.create works / exists
//This is done by either the more efficent __proto__ hacking
//OR the new object hacking methods
if (!Object.create) {
//Uses the new object hack method
Object.create = function create(proto, propertiesObject) {
var createFunc = function() {}; //Creates new object
if(proto && Object(proto) === proto ) {
createFunc.prototype = proto;
}
var obj = new createFunc();
if(propertiesObject && Object(propertiesObject) === propertiesObject ) { //its an object
//Object.extend(obj, propertiesObject); //Sets the properties
//nested the extend function, since it was removed
for(var property in propertiesObject) {
obj[property] = propertiesObject[property];
}
}
return obj;
}
return true; //Ends hacking -> Success
//return false; //Ends hacking -> Failed
}
return true; //Ends hacking -> Exists
})();
/***********************************************************
* Function: Object.getPrototypeOf
* [For Opera]
* Returns true / false on hack check success
************************************************************/
(function(){
//Ensures Object.getPrototypeOf works / exists
if ( typeof Object.getPrototypeOf !== "function" ) {
if ( typeof "test".__proto__ === "object" ) {
Object.getPrototypeOf = function(object){
return object.__proto__;
};
} else {
Object.getPrototypeOf = function(object){
// May break if the constructor has been tampered with
return object.constructor.prototype;
};
}
return true; //Ends hacking -> Success
//return false; //Ends hacking -> Failed
}
return true; //Ends hacking -> Exists
})();
/***********************************************************
* Function: Object.keys
* [For outdated browsers]
* Returns true / false on hack check success
************************************************************/
(function(){
//Ensures Object.keys works / exists
if (!Object.keys) {
Object.keys = function keys(o){
if (o !== Object(o))
throw new TypeError('Object.keys called on non-object');
var ret=[],p;
for(p in o) if(Object.prototype.hasOwnProperty.call(o,p)) ret.push(p);
return ret;
}
return true; //Ends hacking -> Success
//return false; //Ends hacking -> Failed
}
return true; //Ends hacking -> Exists
})();
/***********************************************************
* Function: Function.prototype.bind
* [For Old browsers]
* Returns true / false on hack check success
* Note: This is from MDN and not a fully functionality hack
************************************************************/
(function(){
if (!Function.prototype.bind) {
Function.prototype.bind = function bind(oThis) {
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 fBound is not callable");
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP ? this : oThis || window, aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
return true; //Ends hacking -> Success
//return false; //Ends hacking -> Failed
}
return true; //Ends hacking -> Exists
})();
/***********************************************************************************************************
* Function: Array.prototype.indexOf functionality check
* [For Old browsers]
* Returns true / false on hack check success
* Note: This is from MDN (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf)
************************************************************************************************************/
(function(){
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
"use strict";
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (len === 0) {
return -1;
}
var n = 0;
if (arguments.length > 0) {
n = Number(arguments[1]);
if (n !== n) { // shortcut for verifying if it's NaN
n = 0;
} else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
if (n >= len) {
return -1;
}
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
for (; k < len; k++) {
if (k in t && t[k] === searchElement) {
return k;
}
}
return -1;
}
return true; //Ends hacking -> Success
//return false; //Ends hacking -> Failed
}
return true; //Ends hacking -> Exists
})();
/***********************************************************************************************************
* Function: Array.prototype.lastIndexOf
* [For Old browsers]
* Returns true / false on hack check success
* Note: This is from MDN (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
************************************************************************************************************/
(function(){
if (!Array.prototype.lastIndexOf) {
Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) {
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (len === 0)
return -1;
var n = len;
if (arguments.length > 1)
{
n = Number(arguments[1]);
if (n !== n)
n = 0;
else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
var k = n >= 0
? Math.min(n, len - 1)
: len - Math.abs(n);
for (; k >= 0; k--)
{
if (k in t && t[k] === searchElement)
return k;
}
return -1;
};
return true; //Ends hacking -> Success
//return false; //Ends hacking -> Failed
}
return true; //Ends hacking -> Exists
})();