Skip to content

Commit

Permalink
Merging webpack-umd
Browse files Browse the repository at this point in the history
  • Loading branch information
ten1seven committed Jun 21, 2016
1 parent acff770 commit 032d249
Show file tree
Hide file tree
Showing 12 changed files with 616 additions and 31 deletions.
43 changes: 25 additions & 18 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ var pkg = require('./package.json');
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var uglify = require('gulp-uglify');

var webpackStream = require('webpack-stream');
var webpack = require('webpack');
var cloneDeep = require('lodash.clonedeep');
var webpackConfig = require('./webpack.config');

/*
--------------------
Expand All @@ -36,36 +38,41 @@ gulp.task('clean', function () {
--------------------
*/

gulp.task('scripts:uglify', function() {
return gulp.src(['./what-input.js'])
gulp.task('scripts:dev', function() {
return gulp.src(['./src/what-input.js'])
.pipe(webpackStream(webpackConfig))
.pipe(rename('what-input.js'))
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest('./dist/'))
.pipe(notify('Development build complete'));
});

gulp.task('scripts:build', function() {
var webpackBuildConfig = cloneDeep(webpackConfig);
webpackBuildConfig.plugins = [new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin({minimize: true})];

return gulp.src(['./src/what-input.js'])
.pipe(webpackStream(webpackBuildConfig))
.pipe(plumber({
errorHandler: notify.onError("Error: <%= error.message %>")
}))
.pipe(uglify())
.pipe(rename('what-input.min.js'))
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest('./'))
.pipe(notify('Scripts uglify task complete'));
.pipe(gulp.dest('./dist/'))
.pipe(notify('Minified build complete'));
});

gulp.task('scripts:ie8', function() {
return gulp.src(['./polyfills/ie8/*.js'])
return gulp.src(['./src/polyfills/ie8/*.js'])
.pipe(plumber({
errorHandler: notify.onError("Error: <%= error.message %>")
}))
.pipe(concat('lte-IE8.js'))
.pipe(uglify())
.pipe(gulp.dest('./'))
.pipe(gulp.dest('./dist/'))
.pipe(notify('IE8 scripts task complete'));
});

gulp.task('scripts', function() {
runSequence(
'scripts:uglify',
'scripts:ie8'
);
});

gulp.task('scripts', ['scripts:dev', 'scripts:build', 'scripts:ie8']);

/*
--------------------
Expand Down Expand Up @@ -99,7 +106,7 @@ gulp.task('default', function() {
});

gulp.watch([
'./what-input.js',
'./src/what-input.js',
'./polyfills/*.js'
], ['scripts']).on('change', browserSync.reload);

Expand Down
216 changes: 216 additions & 0 deletions dist/lte-IE8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// EventListener | CC0 | github.com/jonathantneal/EventListener

this.Element && Element.prototype.attachEvent && !Element.prototype.addEventListener && (function () {
function addToPrototype(name, method) {
Window.prototype[name] = HTMLDocument.prototype[name] = Element.prototype[name] = method;
}

// add
addToPrototype("addEventListener", function (type, listener) {
var
target = this,
listeners = target.addEventListener.listeners = target.addEventListener.listeners || {},
typeListeners = listeners[type] = listeners[type] || [];

// if no events exist, attach the listener
if (!typeListeners.length) {
target.attachEvent("on" + type, typeListeners.event = function (event) {
var documentElement = target.document && target.document.documentElement || target.documentElement || { scrollLeft: 0, scrollTop: 0 };

// polyfill w3c properties and methods
event.currentTarget = target;
event.pageX = event.clientX + documentElement.scrollLeft;
event.pageY = event.clientY + documentElement.scrollTop;
event.preventDefault = function () { event.returnValue = false };
event.relatedTarget = event.fromElement || null;
event.stopImmediatePropagation = function () { immediatePropagation = false; event.cancelBubble = true };
event.stopPropagation = function () { event.cancelBubble = true };
event.target = event.srcElement || target;
event.timeStamp = +new Date;

var plainEvt = {};
for (var i in event) {
plainEvt[i] = event[i];
}

// create an cached list of the master events list (to protect this loop from breaking when an event is removed)
for (var i = 0, typeListenersCache = [].concat(typeListeners), typeListenerCache, immediatePropagation = true; immediatePropagation && (typeListenerCache = typeListenersCache[i]); ++i) {
// check to see if the cached event still exists in the master events list
for (var ii = 0, typeListener; typeListener = typeListeners[ii]; ++ii) {
if (typeListener == typeListenerCache) {
typeListener.call(target, plainEvt);

break;
}
}
}
});
}

// add the event to the master event list
typeListeners.push(listener);
});

// remove
addToPrototype("removeEventListener", function (type, listener) {
var
target = this,
listeners = target.addEventListener.listeners = target.addEventListener.listeners || {},
typeListeners = listeners[type] = listeners[type] || [];

// remove the newest matching event from the master event list
for (var i = typeListeners.length - 1, typeListener; typeListener = typeListeners[i]; --i) {
if (typeListener == listener) {
typeListeners.splice(i, 1);

break;
}
}

// if no events exist, detach the listener
if (!typeListeners.length && typeListeners.event) {
target.detachEvent("on" + type, typeListeners.event);
}
});

// dispatch
addToPrototype("dispatchEvent", function (eventObject) {
var
target = this,
type = eventObject.type,
listeners = target.addEventListener.listeners = target.addEventListener.listeners || {},
typeListeners = listeners[type] = listeners[type] || [];

try {
return target.fireEvent("on" + type, eventObject);
} catch (error) {
if (typeListeners.event) {
typeListeners.event(eventObject);
}

return;
}
});

// CustomEvent
Object.defineProperty(Window.prototype, "CustomEvent", {
get: function () {
var self = this;

return function CustomEvent(type, eventInitDict) {
var event = self.document.createEventObject(), key;

event.type = type;
for (key in eventInitDict) {
if (key == 'cancelable'){
event.returnValue = !eventInitDict.cancelable;
} else if (key == 'bubbles'){
event.cancelBubble = !eventInitDict.bubbles;
} else if (key == 'detail'){
event.detail = eventInitDict.detail;
}
}
return event;
};
}
});

// ready
function ready(event) {
if (ready.interval && document.body) {
ready.interval = clearInterval(ready.interval);

document.dispatchEvent(new CustomEvent("DOMContentLoaded"));
}
}

ready.interval = setInterval(ready, 1);

window.addEventListener("load", ready);
})();

(!this.CustomEvent || typeof this.CustomEvent === "object") && (function() {
// CustomEvent for browsers which don't natively support the Constructor method
this.CustomEvent = function CustomEvent(type, eventInitDict) {
var event;
eventInitDict = eventInitDict || {bubbles: false, cancelable: false, detail: undefined};

try {
event = document.createEvent('CustomEvent');
event.initCustomEvent(type, eventInitDict.bubbles, eventInitDict.cancelable, eventInitDict.detail);
} catch (error) {
// for browsers which don't support CustomEvent at all, we use a regular event instead
event = document.createEvent('Event');
event.initEvent(type, eventInitDict.bubbles, eventInitDict.cancelable);
event.detail = eventInitDict.detail;
}

return event;
};
})();

// Production steps of ECMA-262, Edition 5, 15.4.4.14
// Reference: http://es5.github.io/#x15.4.4.14
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(searchElement, fromIndex) {

var k;

// 1. Let O be the result of calling ToObject passing
// the this value as the argument.
if (this == null) {
throw new TypeError('"this" is null or not defined');
}

var O = Object(this);

// 2. Let lenValue be the result of calling the Get
// internal method of O with the argument "length".
// 3. Let len be ToUint32(lenValue).
var len = O.length >>> 0;

// 4. If len is 0, return -1.
if (len === 0) {
return -1;
}

// 5. If argument fromIndex was passed let n be
// ToInteger(fromIndex); else let n be 0.
var n = +fromIndex || 0;

if (Math.abs(n) === Infinity) {
n = 0;
}

// 6. If n >= len, return -1.
if (n >= len) {
return -1;
}

// 7. If n >= 0, then Let k be n.
// 8. Else, n<0, Let k be len - abs(n).
// If k is less than 0, then let k be 0.
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);

// 9. Repeat, while k < len
while (k < len) {
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the
// HasProperty internal method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
// i. Let elementK be the result of calling the Get
// internal method of O with the argument ToString(k).
// ii. Let same be the result of applying the
// Strict Equality Comparison Algorithm to
// searchElement and elementK.
// iii. If same is true, return k.
if (k in O && O[k] === searchElement) {
return k;
}
k++;
}
return -1;
};
}
Loading

0 comments on commit 032d249

Please sign in to comment.