Skip to content

Instantly share code, notes, and snippets.

@ShirtlessKirk
ShirtlessKirk / object.js
Created October 30, 2015 16:09
Object methods polyfill (partial)
/*global define: false, module: false */
/*jslint forin: true, nomen: true, unparam: true */
(function objectModule(definition) { // non-exporting module magic dance
'use strict';
var
amd = 'amd',
exports = 'exports'; // keeps the method names for CommonJS / AMD from being compiled to single character variable
if (typeof define === 'function' && define[amd]) {
@ShirtlessKirk
ShirtlessKirk / string.js
Created October 30, 2015 16:06
String.endsWith / String.includes / String.startsWith / String.trim polyfill for IE, Opera, Safari
/**
* String.endsWith / String.startsWith polyfills for IE, Opera and Safari
*/
/*global define: false, module: false */
(function stringModule(definition) { // non-exporting module magic dance
'use strict';
var
amd = 'amd',
exports = 'exports'; // keeps the method names for CommonJS / AMD from being compiled to single character variable
@ShirtlessKirk
ShirtlessKirk / settimeout.js
Created October 30, 2015 16:04
setInterval / setTimeout / setImmediate / requestAnimationFrame polyfill for IE < 10
/*jslint regexp: true */
/**
* window.setInterval and window.setTimeout polyfill to allow extra parameters (passed to called function) for IE < 10
*/
(function setTimeoutModule(global, partial, setInterval, setTimeout, slice) {
'use strict';
function dogfooder() {
if (arguments.length) { // no need to polyfill
return;
@ShirtlessKirk
ShirtlessKirk / function.js
Created October 30, 2015 16:02
Function.bind polyfill for IE8
/**
* @preserve Function.bind polyfill for IE8
*/
/*global define: false, module: false */
(function functionModule(definition) { // non-exporting module magic dance
'use strict';
var
amd = 'amd',
exports = 'exports'; // keeps the method names for CommonJS / AMD from being compiled to single character variable
@ShirtlessKirk
ShirtlessKirk / document.js
Created October 30, 2015 16:01
DOM4 methods polyfill
/**
* Polyfill of DOM4 methods
*/
/*global define: false, module: false, console: false */
/*jslint bitwise: true, forin: true */
(function documentModule(global, definition) { // non-exporting module magic dance
'use strict';
var
amd = 'amd',
@ShirtlessKirk
ShirtlessKirk / event.js
Created October 30, 2015 15:31
Event polyfill for IE < 9 plus DOMContentLoaded, Custom Events (with fix for IE9 - 11)
/**
* Polyfill of .addEventListener, .removeEventListener, DOMContentLoaded for IE < 9
* CustomEvent for IE < 9
* Monkey patch custom event for IE9 - 11
*/
/*global define: false, module: false */
/*jslint bitwise: true, forin: true, sloppy: true */
(function eventModule(global, definition) { // non-exporting module magic dance
'use strict';
@ShirtlessKirk
ShirtlessKirk / domtokenlist.js
Last active October 22, 2021 19:17
DOMTokenList polyfill for IE < 9; implements element.classList
/**
* Polyfill of DOMTokenList for IE < 9
* Monkey patch of .add, .remove for IE 10 / 11, Firefox < 26 to support multiple arguments
* Monkey patch of .toggle for IE 10 / 11, Firefox < 24 to support second argument
*/
/*global define: false, module: false */
/*jslint nomen: true */
(function domTokenListModule(global, definition) { // non-exporting module magic dance
'use strict';
@ShirtlessKirk
ShirtlessKirk / array.js
Last active October 30, 2015 15:18
EcmaScript 5 Array methods polyfill for IE < 9
/**
* Polyfill of ES5 Array methods for IE < 9
*/
/*global define: false, module: false */
/*jslint bitwise: true, forin: true */
(function arrayModule(definition) { // non-exporting module magic dance
'use strict';
var
amd = 'amd',
@ShirtlessKirk
ShirtlessKirk / dataset.js
Last active February 11, 2024 23:00
Dataset polyfill for IE < 11
/*
* @preserve dataset polyfill for IE < 11. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset and http://caniuse.com/#search=dataset
*
* @author ShirtlessKirk copyright 2015
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
/*global define: false, module: false */
/*jslint nomen: true, regexp: true, unparam: true */
(function datasetModule(global, definition) { // non-exporting module magic dance
'use strict';
@ShirtlessKirk
ShirtlessKirk / FormData.js
Last active February 12, 2024 00:02
FormData partial polyfill for IE < 10 (<input type="file"> not supported)
/*
* @preserve FormData polyfill for IE < 10. See https://developer.mozilla.org/en/docs/Web/API/FormData and http://caniuse.com/#search=formdata
*
* @author ShirtlessKirk copyright 2015
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
/*global define: false, module: false */
/*jslint bitwise: true, continue: true, nomen: true */
(function formDataModule(global, definition) { // non-exporting module magic dance
'use strict';