-
Notifications
You must be signed in to change notification settings - Fork 5
Add old IE polyfills and add build tasks #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
/dist | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spacing |
||
concat: { | ||
oldIE: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't call this oldIE. There are likely other browsers that we support which need at least one polyfill. |
||
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: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the options for both targets are the same, why not just merge them? |
||
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" ] ); | ||
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
if (!Array.prototype.filter) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above, let's rename this file. |
||
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]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,12 @@ | |
(function( $ ) { | ||
|
||
if ( !Object.keys ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't a legitimate test. |
||
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 || {}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No leading slash.