From 2babcfc2b2046edf2518a77ffe86ea44167be41b Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Wed, 13 Nov 2013 21:33:31 -0600 Subject: [PATCH 1/3] Add old IE file which contains a number of necessary polyfills from https://github.com/jonathantneal/polyfill --- src/old-ie.js | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/old-ie.js diff --git a/src/old-ie.js b/src/old-ie.js new file mode 100644 index 0000000..6fc5f9a --- /dev/null +++ b/src/old-ie.js @@ -0,0 +1,132 @@ +if (!Array.prototype.filter) { + Array.prototype.filter = function filter(callback, scope) { + for (var array = this, arrayB = [], index = 0, length = array.length, element; index < length; ++index) { + element = array[index]; + + if (callback.call(scope || window, element, index, array)) { + arrayB.push(element); + } + } + + return arrayB; + }; +} + +if (!Array.prototype.forEach) { + Array.prototype.forEach = function forEach(callback, scope) { + for (var array = this, index = 0, length = array.length; index < length; ++index) { + callback.call(scope || window, array[index], index, array); + } + }; +} + +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function indexOf(searchElement) { + for (var array = this, index = 0, length = array.length; index < length; ++index) { + if (array[index] === searchElement) { + return index; + } + } + + return -1; + }; +} + +if (!Array.prototype.map) { + Array.prototype.map = function map(callback, scope) { + for (var array = this, arrayB = [], index = 0, length = array.length, element; index < length; ++index) { + element = array[index]; + + arrayB.push(callback.call(scope || window, array[index], index, array)); + } + + return arrayB; + }; +} + +if (!Function.prototype.bind) { + Function.prototype.bind = function bind(scope) { + var callback = this, prepend = Array.prototype.slice.call(arguments, 1), Constructor = function () {}, bound = function () { + return callback.apply(this instanceof Constructor && scope ? this : scope, Array.prototype.concat.apply(prepend, arguments)); + }; + + Constructor.prototype = bound.prototype = callback.prototype; + + return bound; + }; +} + +if (!Object.keys) { + Object.keys = function keys(object) { + var buffer = [], key; + + for (key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + buffer.push(key); + } + } + + return buffer; + }; +} + +if (!Object.defineProperty) { + Object.defineProperty = function (object, property, descriptor) { + var propertyValue = object[property]; + + function onPropertyChange(event) { + if (event.propertyName === property) { + // temporarily remove the event so it doesn't fire again and create a loop + object.detachEvent("onpropertychange", onPropertyChange); + + // set the value using the setter + if (descriptor.set) { + propertyValue = descriptor.set.call(object, object[property]); + } + + // restore the getter + object[property] = String(propertyValue); + + object[property].toString = function () { + return descriptor.get.call(object); + }; + + // restore the event + object.attachEvent("onpropertychange", onPropertyChange); + } + } + + // assign the getter + object[property] = String(propertyValue); + + object[property].toString = function () { + return descriptor.get.call(object); + }; + + // assign the event + object.attachEvent("onpropertychange", onPropertyChange); + + // return the object + return object; + }; +} + +if (!Object.defineProperties) { + Object.defineProperties = function defineProperties(object, descriptors) { + for (var property in descriptors) { + Object.defineProperty(object, property, descriptors[property]); + } + + return object; + }; +} + +if (!Date.now) { + Date.now = function() { + return new Date().getTime(); + }; +} + +if ( !document.head ) { + document.head = document.getElementsByTagName("head")[0]; +} From 5be24e0de8733b1e8afa53ff541899acd0085d30 Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Wed, 13 Nov 2013 22:03:02 -0600 Subject: [PATCH 2/3] Properly define the PointerEvent function --- src/pointer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pointer.js b/src/pointer.js index 9f30fa5..6f579d5 100644 --- a/src/pointer.js +++ b/src/pointer.js @@ -9,12 +9,12 @@ (function( $ ) { if ( !Object.keys ) { - function PointerEvent( type, event ) { + window.PointerEvent = function( type, event ) { event.type = type; var nevent = $.Event( event ); $.extend( nevent, event ); return nevent; - } + }; } window.PointerEventsPolyfill = window.PointerEventsPolyfill || {}; From 3d0aec0c79089d1b1960c8db19c5cd67315b18c3 Mon Sep 17 00:00:00 2001 From: Kris Borchers Date: Wed, 13 Nov 2013 22:04:07 -0600 Subject: [PATCH 3/3] Update and add new build options to build individual polyfills for both modern and older browsers --- .gitignore | 1 + Gruntfile.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 5 ++++- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3c3629e..bd07d4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +/dist diff --git a/Gruntfile.js b/Gruntfile.js index 437c125..8f4c818 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,10 +2,61 @@ module.exports = function( grunt ) { "use strict"; +var banner = "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " + + "<%= grunt.template.today('isoDate') %>\n" + + "<%= pkg.homepage ? '* ' + pkg.homepage + '\\n' : '' %>" + + "* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" + + " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n"; + grunt.loadNpmTasks( "grunt-contrib-jshint" ); grunt.loadNpmTasks( "grunt-git-authors" ); +grunt.loadNpmTasks( "grunt-contrib-uglify" ); +grunt.loadNpmTasks( "grunt-contrib-concat" ); +grunt.loadNpmTasks( "grunt-contrib-copy" ); grunt.initConfig({ + pkg: grunt.file.readJSON("package.json"), + concat: { + oldIE: { + options: { + banner: banner, + stripBanners: { + block: true + } + }, + src: [ "src/old-ie.js", "src/pointer.js" ], + dest: "dist/jquery.pointer.js" + } + }, + copy: { + modern: { + files: [{ + src: "src/pointer.js", + dest: "dist/jquery.pointer.modern.js" + }] + } + }, + uglify: { + options: { + preserveComments: false + }, + oldIE: { + options: { + banner: banner + }, + files: { + "dist/jquery.pointer.min.js": "dist/jquery.pointer.js" + } + }, + modern: { + options: { + banner: banner + }, + files: { + "dist/jquery.pointer.modern.min.js": "dist/jquery.pointer.modern.js" + } + } + }, jshint: { src: { options: { @@ -26,7 +77,8 @@ grunt.initConfig({ } }); -grunt.registerTask( "default", [ "lint" ] ); +grunt.registerTask( "default", [ "lint", "concat:oldIE", "uglify:oldIE" ] ); +grunt.registerTask( "modern", [ "lint", "copy:modern", "uglify:modern" ] ); grunt.registerTask( "lint", [ "jshint" ] ); }; diff --git a/package.json b/package.json index e286b30..990ba85 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,9 @@ "devDependencies": { "grunt": "0.4.1", "grunt-git-authors": "1.2.0", - "grunt-contrib-jshint": "0.4.3" + "grunt-contrib-jshint": "0.4.3", + "grunt-contrib-concat": "0.3.0", + "grunt-contrib-uglify": "0.2.7", + "grunt-contrib-copy": "0.4.1" } }