Skip to content

Commit 5325c4d

Browse files
committed
Add hello.polyfill.js abstracting the older-browser polyfills out of the core file for better focus on logic rather than shims
1 parent 317b802 commit 5325c4d

23 files changed

+112
-92
lines changed

Gruntfile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ module.exports = function(grunt) {
4848
},
4949
// Combine the src files, create minified versions
5050
build : {
51-
'dist/hello.js' : ['src/hello.js', 'src/hello.legacy.js', 'src/hello.amd.js', 'src/hello.commonjs.js'],
52-
'dist/hello.all.js' : ['src/hello.js', 'src/hello.legacy.js', 'src/modules/', 'src/hello.amd.js', 'src/hello.commonjs.js']
51+
'dist/hello.js' : ['src/hello.polyfill.js', 'src/hello.js', 'src/hello.legacy.js', 'src/hello.amd.js', 'src/hello.commonjs.js'],
52+
'dist/hello.all.js' : ['src/hello.polyfill.js', 'src/hello.js', 'src/hello.legacy.js', 'src/modules/', 'src/hello.amd.js', 'src/hello.commonjs.js']
5353
},
5454
minify : {
5555
'dist/hello.min.js' : 'dist/hello.js',

demos/bikeindex.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<script src="/adorn/adorn.js" async></script>
66

77
<script src="client_ids.js"></script>
8+
<script src="../src/hello.polyfill.js"></script>
89
<script src="../src/hello.js"></script>
910
<script src="../src/modules/bikeindex.js"></script>
1011

demos/dropbox.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<link rel="stylesheet" href="/adorn/adorn.css"/>
44
<script src="/adorn/adorn.js" async></script>
55

6+
<script src="../src/hello.polyfill.js"></script>
67
<script src="../src/hello.js"></script>
78
<script src="./client_ids.js"></script>
89
<script src="../src/modules/dropbox.js"></script>

demos/flickr.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<script src="/adorn/adorn.js" async></script>
44

55
<script src="client_ids.js"></script>
6+
<script src="../src/hello.polyfill.js"></script>
67
<script src="../src/hello.js"></script>
78
<script src="../src/modules/flickr.js"></script>
89

demos/foursquare.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<link rel="stylesheet" href="/adorn/adorn.css"/>
44
<script src="/adorn/adorn.js" async></script>
55

6+
<script src="../src/hello.polyfill.js"></script>
67
<script src="../src/hello.js"></script>
78
<script src="../src/modules/foursquare.js"></script>
89

demos/github.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script src="/adorn/adorn.js" async></script>
55

66
<script src="client_ids.js"></script>
7+
<script src="../src/hello.polyfill.js"></script>
78
<script src="../src/hello.js"></script>
89
<script src="../src/modules/github.js"></script>
910

demos/instagram.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script src="/adorn/adorn.js" async></script>
55

66
<script src="client_ids.js"></script>
7+
<script src="../src/hello.polyfill.js"></script>
78
<script src="../src/hello.js"></script>
89
<script src="../src/modules/instagram.js"></script>
910

demos/linkedin.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script src="/adorn/adorn.js" async></script>
55

66
<script src="client_ids.js"></script>
7+
<script src="../src/hello.polyfill.js"></script>
78
<script src="../src/hello.js"></script>
89
<script src="../src/modules/linkedin.js"></script>
910

demos/login-modal.html

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</style>
1717

1818
<script src="client_ids.js"></script>
19+
<script src="../src/hello.polyfill.js"></script>
1920
<script src="../src/hello.js"></script>
2021
<script src="../src/modules/windows.js"></script>
2122
<script src="../src/modules/facebook.js"></script>

demos/paypal.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<link rel="stylesheet" href="/adorn/adorn.css"/>
44
<script src="/adorn/adorn.js" async></script>
55

6+
<script src="../src/hello.polyfill.js"></script>
67
<script src="../src/hello.js"></script>
78

89
<title>hello( paypal )</title>

demos/profile.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script src="/adorn/adorn.js" async></script>
55

66
<script src="client_ids.js"></script>
7+
<script src="../src/hello.polyfill.js"></script>
78
<script src="../src/hello.js"></script>
89
<script src="../src/modules/windows.js"></script>
910
<script src="../src/modules/facebook.js"></script>

demos/promises.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script src="/adorn/adorn.js" async></script>
55

66
<script src="client_ids.js"></script>
7+
<script src="../src/hello.polyfill.js"></script>
78
<script src="../src/hello.js"></script>
89
<script src="../src/modules/google.js"></script>
910

demos/share.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script src="/adorn/adorn.js" async></script>
55

66
<script src="client_ids.js"></script>
7+
<script src="../src/hello.polyfill.js"></script>
78
<script src="../src/hello.js"></script>
89
<script src="../src/modules/windows.js"></script>
910
<script src="../src/modules/facebook.js"></script>

demos/signin-oauth1.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script src="/adorn/adorn.js" async></script>
55

66
<script src="client_ids.js"></script>
7+
<script src="../src/hello.polyfill.js"></script>
78
<script src="../src/hello.js"></script>
89
<script src="../src/modules/dropbox.js"></script>
910
<script src="../src/modules/yahoo.js"></script>

demos/soundcloud.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script src="/adorn/adorn.js" async></script>
55

66
<script src="client_ids.js"></script>
7+
<script src="../src/hello.polyfill.js"></script>
78
<script src="../src/hello.js"></script>
89
<script src="../src/modules/soundcloud.js"></script>
910

demos/tumblr.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<script src="/adorn/adorn.js" async></script>
44

55
<script src="client_ids.js"></script>
6+
<script src="../src/hello.polyfill.js"></script>
67
<script src="../src/hello.js"></script>
78
<script src="../src/modules/tumblr.js"></script>
89

demos/twitter.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<script src="/adorn/adorn.js" async></script>
44

55
<script src="client_ids.js"></script>
6+
<script src="../src/hello.polyfill.js"></script>
67
<script src="../src/hello.js"></script>
78
<script src="../src/modules/twitter.js"></script>
89

demos/windows.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<script src="/adorn/adorn.js" async></script>
44

55
<script src="client_ids.js"></script>
6+
<script src="../src/hello.polyfill.js"></script>
67
<script src="../src/hello.js"></script>
78
<script src="../src/modules/windows.js"></script>
89

demos/yahoo.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<script src="/adorn/adorn.js" async></script>
44

55
<script src="client_ids.js"></script>
6+
<script src="../src/hello.polyfill.js"></script>
67
<script src="../src/hello.js"></script>
78
<script src="../src/modules/yahoo.js"></script>
89

redirect.html

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ <h2>Please close this window to continue.</h2>
2525
document.getElementsByTagName('h2')[0].innerHTML="Redirecting, please wait";
2626
}
2727
</script>
28+
<script src="./src/hello.polyfill.js"></script>
2829
<script src="./src/hello.js"></script>
2930
</body>
3031
</html>

src/hello.js

+12-90
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ hello.utils.extend( hello, {
129129
use : function(service){
130130

131131
// Create self, which inherits from its parent
132-
var self = this.utils.objectCreate(this);
132+
var self = Object.create(this);
133133

134134
// Inherit the prototype from its parent
135-
self.settings = this.utils.objectCreate(this.settings);
135+
self.settings = Object.create(this.settings);
136136

137137
// Define the default service
138138
if(service){
@@ -962,31 +962,13 @@ hello.utils.extend( hello.utils, {
962962
diff : function(a,b){
963963
var r = [];
964964
for(var i=0;i<b.length;i++){
965-
if(this.indexOf(a,b[i])===-1){
965+
if(a.indexOf(b[i])===-1){
966966
r.push(b[i]);
967967
}
968968
}
969969
return r;
970970
},
971971

972-
//
973-
// indexOf
974-
// IE hack Array.indexOf doesn't exist prior to IE9
975-
indexOf : function(a,s){
976-
// Do we need the hack?
977-
if(a.indexOf){
978-
return a.indexOf(s);
979-
}
980-
981-
for(var j=0;j<a.length;j++){
982-
if(a[j]===s){
983-
return j;
984-
}
985-
}
986-
return -1;
987-
},
988-
989-
990972
//
991973
// unique
992974
// remove duplicate and null values from an array
@@ -997,7 +979,7 @@ hello.utils.extend( hello.utils, {
997979
var r = [];
998980
for(var i=0;i<a.length;i++){
999981

1000-
if(!a[i]||a[i].length===0||this.indexOf(r, a[i])!==-1){
982+
if(!a[i]||a[i].length===0||r.indexOf(a[i])!==-1){
1001983
continue;
1002984
}
1003985
else{
@@ -1016,8 +998,9 @@ hello.utils.extend( hello.utils, {
1016998
}
1017999

10181000
// Array?
1019-
if(obj && obj.length>0) return false;
1020-
if(obj && obj.length===0) return true;
1001+
if( Array.isArray(obj) ){
1002+
return !obj.length;
1003+
}
10211004

10221005
// object?
10231006
for (var key in obj) {
@@ -1028,22 +1011,6 @@ hello.utils.extend( hello.utils, {
10281011
return true;
10291012
},
10301013

1031-
// Shim, Object create
1032-
// A shim for Object.create(), it adds a prototype to a new object
1033-
objectCreate : (function(){
1034-
if (Object.create) {
1035-
return Object.create;
1036-
}
1037-
function F(){}
1038-
return function(o){
1039-
if (arguments.length != 1) {
1040-
throw new Error('Object.create implementation only accepts one parameter.');
1041-
}
1042-
F.prototype = o;
1043-
return new F();
1044-
};
1045-
})(),
1046-
10471014
/*
10481015
//
10491016
// getProtoTypeOf
@@ -1352,7 +1319,7 @@ hello.utils.extend( hello.utils, {
13521319

13531320
for(var name in this.events){if(this.events.hasOwnProperty(name)){
13541321

1355-
if( hello.utils.indexOf(a,name) > -1 ){
1322+
if( a.indexOf(name) > -1 ){
13561323

13571324
for(var i=0;i<this.events[name].length;i++){
13581325

@@ -1550,17 +1517,6 @@ hello.utils.extend( hello.utils, {
15501517
//
15511518
var location = window.location;
15521519

1553-
//
1554-
// Add a helper for relocating, instead of window.location = url;
1555-
//
1556-
var relocate = function(path){
1557-
if(location.assign){
1558-
location.assign(path);
1559-
}
1560-
else{
1561-
window.location = path;
1562-
}
1563-
};
15641520

15651521
//
15661522
// Is this an auth relay message which needs to call the proxy?
@@ -1577,7 +1533,7 @@ hello.utils.extend( hello.utils, {
15771533
// redirect to the host
15781534
var path = (state.oauth_proxy || p.proxy_url) + "?" + utils.param(p);
15791535

1580-
relocate( path );
1536+
location.assign( path );
15811537
return;
15821538
}
15831539

@@ -1647,7 +1603,7 @@ hello.utils.extend( hello.utils, {
16471603

16481604
// If this page is still open
16491605
if( p.page_uri ){
1650-
window.location = p.page_uri;
1606+
location.assign( p.page_uri );
16511607
}
16521608

16531609

@@ -1658,7 +1614,7 @@ hello.utils.extend( hello.utils, {
16581614
// Loading the redirect.html before triggering the OAuth Flow seems to fix it.
16591615
else if("oauth_redirect" in p){
16601616

1661-
relocate( decodeURIComponent(p.oauth_redirect) );
1617+
location.assign( decodeURIComponent(p.oauth_redirect) );
16621618
return;
16631619
}
16641620

@@ -2419,14 +2375,6 @@ hello.utils.extend( hello.utils, {
24192375

24202376

24212377

2422-
2423-
//
2424-
// isArray
2425-
isArray : function (o){
2426-
return Object.prototype.toString.call(o) === '[object Array]';
2427-
},
2428-
2429-
24302378
// _DOM
24312379
// return the type of DOM object
24322380
domInstance : function(type,data){
@@ -2452,7 +2400,7 @@ hello.utils.extend( hello.utils, {
24522400
return obj;
24532401
}
24542402
var clone;
2455-
if(this.isArray(obj)){
2403+
if(Array.isArray(obj)){
24562404
clone = [];
24572405
for(var i=0;i<obj.length;i++){
24582406
clone.push(this.clone(obj[i]));
@@ -3084,29 +3032,3 @@ utils.extend(utils, {
30843032
};
30853033

30863034
})(hello);
3087-
3088-
3089-
3090-
3091-
3092-
3093-
// MDN
3094-
// Polyfill IE8, does not support native Function.bind
3095-
3096-
if (!Function.prototype.bind) {
3097-
Function.prototype.bind=function(b){
3098-
if(typeof this!=="function"){
3099-
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
3100-
}
3101-
function c(){}
3102-
var a=[].slice,
3103-
f=a.call(arguments,1),
3104-
e=this,
3105-
d=function(){
3106-
return e.apply(this instanceof c?this:b||window,f.concat(a.call(arguments)));
3107-
};
3108-
c.prototype=this.prototype;
3109-
d.prototype=new c();
3110-
return d;
3111-
};
3112-
}

0 commit comments

Comments
 (0)