Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit f7c5d80

Browse files
author
Chris Ferdinandi
committed
Added classlist and bind polyfills
1 parent ceaf595 commit f7c5d80

12 files changed

+415
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ Gulp Boilerplate is licensed under the [MIT License](http://gomakethings.com/mit
120120

121121
## Changelog
122122

123+
* v0.2.2 - August 8, 2014
124+
* Added polyfills for `Functions.prototype.bind` and `element.classList`.
123125
* v0.2.1 - July 21, 2014
124126
* Updated `getDataOptions` method to use JSON.
125127
* Removed auto-dating from minified files.

dist/css/myplugin.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.2.1
2+
* gulp-boilerplate v0.2.2
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*

dist/css/myplugin.min.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/** gulp-boilerplate v0.2.1, by Chris Ferdinandi | http://github.com/cferdinandi/Plugin | Licensed under MIT: http://gomakethings.com/mit/ */
1+
/** gulp-boilerplate v0.2.2, by Chris Ferdinandi | http://github.com/cferdinandi/Plugin | Licensed under MIT: http://gomakethings.com/mit/ */

dist/js/bind-polyfill.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* gulp-boilerplate v0.2.2
3+
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
4+
* http://github.com/cferdinandi/Plugin
5+
*
6+
* Free to use under the MIT License.
7+
* http://gomakethings.com/mit/
8+
*/
9+
10+
/*
11+
* Polyfill Function.prototype.bind support for otherwise ECMA Script 5 compliant browsers
12+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Compatibility
13+
*/
14+
15+
if (!Function.prototype.bind) {
16+
Function.prototype.bind = function (oThis) {
17+
if (typeof this !== "function") {
18+
// closest thing possible to the ECMAScript 5
19+
// internal IsCallable function
20+
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
21+
}
22+
23+
var aArgs = Array.prototype.slice.call(arguments, 1);
24+
var fToBind = this;
25+
fNOP = function () {};
26+
fBound = function () {
27+
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
28+
};
29+
30+
fNOP.prototype = this.prototype;
31+
fBound.prototype = new fNOP();
32+
33+
return fBound;
34+
};
35+
}

dist/js/bind-polyfill.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/classList.js

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/**
2+
* gulp-boilerplate v0.2.2
3+
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
4+
* http://github.com/cferdinandi/Plugin
5+
*
6+
* Free to use under the MIT License.
7+
* http://gomakethings.com/mit/
8+
*/
9+
10+
/*
11+
* classList.js: Cross-browser full element.classList implementation.
12+
* 2014-01-31
13+
*
14+
* By Eli Grey, http://eligrey.com
15+
* Public Domain.
16+
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
17+
*/
18+
19+
/*global self, document, DOMException */
20+
21+
/*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js*/
22+
23+
if ("document" in self && !("classList" in document.createElement("_"))) {
24+
25+
(function (view) {
26+
27+
"use strict";
28+
29+
if (!('Element' in view)) return;
30+
31+
var
32+
classListProp = "classList",
33+
protoProp = "prototype",
34+
elemCtrProto = view.Element[protoProp],
35+
objCtr = Object,
36+
strTrim = String[protoProp].trim || function () {
37+
return this.replace(/^\s+|\s+$/g, "");
38+
},
39+
arrIndexOf = Array[protoProp].indexOf || function (item) {
40+
var
41+
i = 0,
42+
len = this.length;
43+
for (; i < len; i++) {
44+
if (i in this && this[i] === item) {
45+
return i;
46+
}
47+
}
48+
return -1;
49+
},
50+
// Vendors: please allow content code to instantiate DOMExceptions
51+
DOMEx = function (type, message) {
52+
this.name = type;
53+
this.code = DOMException[type];
54+
this.message = message;
55+
},
56+
checkTokenAndGetIndex = function (classList, token) {
57+
if (token === "") {
58+
throw new DOMEx(
59+
"SYNTAX_ERR",
60+
"An invalid or illegal string was specified"
61+
);
62+
}
63+
if (/\s/.test(token)) {
64+
throw new DOMEx(
65+
"INVALID_CHARACTER_ERR",
66+
"String contains an invalid character"
67+
);
68+
}
69+
return arrIndexOf.call(classList, token);
70+
},
71+
ClassList = function (elem) {
72+
var
73+
trimmedClasses = strTrim.call(elem.getAttribute("class") || ""),
74+
classes = trimmedClasses ? trimmedClasses.split(/\s+/) : [],
75+
i = 0,
76+
len = classes.length;
77+
for (; i < len; i++) {
78+
this.push(classes[i]);
79+
}
80+
this._updateClassName = function () {
81+
elem.setAttribute("class", this.toString());
82+
};
83+
},
84+
classListProto = ClassList[protoProp] = [],
85+
classListGetter = function () {
86+
return new ClassList(this);
87+
};
88+
// Most DOMException implementations don't allow calling DOMException's toString()
89+
// on non-DOMExceptions. Error's toString() is sufficient here.
90+
DOMEx[protoProp] = Error[protoProp];
91+
classListProto.item = function (i) {
92+
return this[i] || null;
93+
};
94+
classListProto.contains = function (token) {
95+
token += "";
96+
return checkTokenAndGetIndex(this, token) !== -1;
97+
};
98+
classListProto.add = function () {
99+
var
100+
tokens = arguments,
101+
i = 0,
102+
l = tokens.length,
103+
token,
104+
updated = false;
105+
do {
106+
token = tokens[i] + "";
107+
if (checkTokenAndGetIndex(this, token) === -1) {
108+
this.push(token);
109+
updated = true;
110+
}
111+
}
112+
while (++i < l);
113+
114+
if (updated) {
115+
this._updateClassName();
116+
}
117+
};
118+
classListProto.remove = function () {
119+
var
120+
tokens = arguments,
121+
i = 0,
122+
l = tokens.length,
123+
token,
124+
updated = false;
125+
do {
126+
token = tokens[i] + "";
127+
var index = checkTokenAndGetIndex(this, token);
128+
if (index !== -1) {
129+
this.splice(index, 1);
130+
updated = true;
131+
}
132+
}
133+
while (++i < l);
134+
135+
if (updated) {
136+
this._updateClassName();
137+
}
138+
};
139+
classListProto.toggle = function (token, force) {
140+
token += "";
141+
142+
var
143+
result = this.contains(token),
144+
method = result ? force !== true && "remove" : force !== false && "add";
145+
146+
if (method) {
147+
this[method](token);
148+
}
149+
150+
return !result;
151+
};
152+
classListProto.toString = function () {
153+
return this.join(" ");
154+
};
155+
156+
if (objCtr.defineProperty) {
157+
var classListPropDesc = {
158+
get: classListGetter,
159+
enumerable: true,
160+
configurable: true
161+
};
162+
try {
163+
objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
164+
} catch (ex) { // IE 8 doesn't support enumerable:true
165+
if (ex.number === -0x7FF5EC54) {
166+
classListPropDesc.enumerable = false;
167+
objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
168+
}
169+
}
170+
} else if (objCtr[protoProp].__defineGetter__) {
171+
elemCtrProto.__defineGetter__(classListProp, classListGetter);
172+
}
173+
174+
}(self));
175+
176+
}

dist/js/classList.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/myplugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.2.1
2+
* gulp-boilerplate v0.2.2
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*

dist/js/myplugin.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-boilerplate",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "My Gulp.js boilerplate for creating new web projects",
55
"author": {
66
"name": "Chris Ferdinandi",

src/js/bind-polyfill.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Polyfill Function.prototype.bind support for otherwise ECMA Script 5 compliant browsers
3+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Compatibility
4+
*/
5+
6+
if (!Function.prototype.bind) {
7+
Function.prototype.bind = function (oThis) {
8+
if (typeof this !== "function") {
9+
// closest thing possible to the ECMAScript 5
10+
// internal IsCallable function
11+
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
12+
}
13+
14+
var aArgs = Array.prototype.slice.call(arguments, 1);
15+
var fToBind = this;
16+
fNOP = function () {};
17+
fBound = function () {
18+
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
19+
};
20+
21+
fNOP.prototype = this.prototype;
22+
fBound.prototype = new fNOP();
23+
24+
return fBound;
25+
};
26+
}

0 commit comments

Comments
 (0)