Removed unused code from JavaScript files

This commit is contained in:
djmaze 2020-07-27 14:52:18 +02:00
parent dc233bfc90
commit 1b331aca32
12 changed files with 140 additions and 427 deletions

View file

@ -1,11 +1 @@
(function(l,e){"object"===typeof exports?e(exports):"function"===typeof define&&define.amd?define(["exports"],e):e(l)})(this,function(l){function e(a){this._targetElement="undefined"!=typeof a.length?a:[a];"undefined"===typeof window._progressjsId&&(window._progressjsId=1);"undefined"===typeof window._progressjsIntervals&&(window._progressjsIntervals={});this._options={theme:"blue",overlayMode:!1,considerTransition:!0}}function m(a,c){var d=this;100<=c&&(c=100);a.hasAttribute("data-progressjs")&&
setTimeout(function(){"undefined"!=typeof d._onProgressCallback&&d._onProgressCallback.call(d,a,c);var b=h(a);b.style.width=parseInt(c)+"%";var b=b.querySelector(".progressjs-percent"),g=parseInt(b.innerHTML.replace("%","")),e=parseInt(c),j=function(a,b,c){var d=Math.abs(b-c);3>d?k=30:20>d?k=20:intervanIn=1;0!=b-c&&(a.innerHTML=(f?++b:--b)+"%",setTimeout(function(){j(a,b,c)},k))},f=!0;g>e&&(f=!1);var k=10;j(b,g,e)},50)}function h(a){a=parseInt(a.getAttribute("data-progressjs"));return document.querySelector('.progressjs-container > .progressjs-progress[data-progressjs="'+
a+'"] > .progressjs-inner')}function p(a){for(var c=0,d=this._targetElement.length;c<d;c++){var b=this._targetElement[c];if(b.hasAttribute("data-progressjs")){var g=h(b);(g=parseInt(g.style.width.replace("%","")))&&m.call(this,b,g+(a||1))}}}function q(){var a,c=document.createElement("fakeelement"),d={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(a in d)if(void 0!==c.style[a])return d[a]}var n=function(a){if("object"===
typeof a)return new e(a);if("string"===typeof a){if(a=document.querySelectorAll(a))return new e(a);throw Error("There is no element with given selector.");}return new e(document.body)};n.version="0.1.0";n.fn=e.prototype={clone:function(){return new e(this)},setOption:function(a,c){this._options[a]=c;return this},setOptions:function(a){var c=this._options,d={},b;for(b in c)d[b]=c[b];for(b in a)d[b]=a[b];this._options=d;return this},start:function(){"undefined"!=typeof this._onBeforeStartCallback&&
this._onBeforeStartCallback.call(this);if(!document.querySelector(".progressjs-container")){var a=document.createElement("div");a.className="progressjs-container";document.body.appendChild(a)}for(var a=0,c=this._targetElement.length;a<c;a++){var d=this._targetElement[a];if(!d.hasAttribute("data-progressjs")){var b=d,g,e,j;"body"===b.tagName.toLowerCase()?(g=b.clientWidth,e=b.clientHeight):(g=b.offsetWidth,e=b.offsetHeight);for(var f=j=0;b&&!isNaN(b.offsetLeft)&&!isNaN(b.offsetTop);)j+=b.offsetLeft,
f+=b.offsetTop,b=b.offsetParent;b=f;d.setAttribute("data-progressjs",window._progressjsId);f=document.createElement("div");f.className="progressjs-progress progressjs-theme-"+this._options.theme;f.style.position="body"===d.tagName.toLowerCase()?"fixed":"absolute";f.setAttribute("data-progressjs",window._progressjsId);var k=document.createElement("div");k.className="progressjs-inner";var h=document.createElement("div");h.className="progressjs-percent";h.innerHTML="1%";k.appendChild(h);this._options.overlayMode&&
"body"===d.tagName.toLowerCase()?(f.style.left=0,f.style.right=0,f.style.top=0,f.style.bottom=0):(f.style.left=j+"px",f.style.top=b+"px",f.style.width=g+"px",this._options.overlayMode&&(f.style.height=e+"px"));f.appendChild(k);document.querySelector(".progressjs-container").appendChild(f);m(d,1);++window._progressjsId}}return this},set:function(a){for(var c=0,d=this._targetElement.length;c<d;c++)m.call(this,this._targetElement[c],a);return this},increase:function(a){p.call(this,a);return this},autoIncrease:function(a,
c){var d=this,b=parseInt(this._targetElement[0].getAttribute("data-progressjs"));"undefined"!=typeof window._progressjsIntervals[b]&&clearInterval(window._progressjsIntervals[b]);window._progressjsIntervals[b]=setInterval(function(){p.call(d,a)},c);return this},end:function(){a:{"undefined"!=typeof this._onBeforeEndCallback&&(!0===this._options.considerTransition?h(this._targetElement[0]).addEventListener(q(),this._onBeforeEndCallback,!1):this._onBeforeEndCallback.call(this));for(var a=parseInt(this._targetElement[0].getAttribute("data-progressjs")),
c=0,d=this._targetElement.length;c<d;c++){var b=this._targetElement[c],e=h(b);if(!e)break a;var l=1;100>parseInt(e.style.width.replace("%",""))&&(m.call(this,b,100),l=500);(function(a,b){setTimeout(function(){a.parentNode.className+=" progressjs-end";setTimeout(function(){a.parentNode.parentNode.removeChild(a.parentNode);b.removeAttribute("data-progressjs")},1E3)},l)})(e,b)}if(window._progressjsIntervals[a])try{clearInterval(window._progressjsIntervals[a]),window._progressjsIntervals[a]=null,delete window._progressjsIntervals[a]}catch(j){}}return this},
onbeforeend:function(a){if("function"===typeof a)this._onBeforeEndCallback=a;else throw Error("Provided callback for onbeforeend was not a function");return this},onbeforestart:function(a){if("function"===typeof a)this._onBeforeStartCallback=a;else throw Error("Provided callback for onbeforestart was not a function");return this},onprogress:function(a){if("function"===typeof a)this._onProgressCallback=a;else throw Error("Provided callback for onprogress was not a function");return this}};return l.progressJs=
n});
(e=>{function t(e){void 0!==e.length?this._targetElement=e:this._targetElement=[e],void 0===window._progressjsId&&(window._progressjsId=1),void 0===window._progressjsIntervals&&(window._progressjsIntervals={}),this._options={theme:"rainloop",overlayMode:!1,considerTransition:!0}}function r(){void 0!==this._onBeforeStartCallback&&this._onBeforeStartCallback.call(this),function(){if(!document.querySelector(".progressjs-container")){var e=document.createElement("div");e.className="progressjs-container",document.body.appendChild(e)}}.call(this);for(var e=0,t=this._targetElement.length;e<t;e++)s.call(this,this._targetElement[e])}function s(e){if(!e.hasAttribute("data-progressjs")){var t=function(e){var t={};"body"===e.tagName.toLowerCase()?(t.width=e.clientWidth,t.height=e.clientHeight):(t.width=e.offsetWidth,t.height=e.offsetHeight);var r=0,s=0;for(;e&&!isNaN(e.offsetLeft)&&!isNaN(e.offsetTop);)r+=e.offsetLeft,s+=e.offsetTop,e=e.offsetParent;return t.top=s,t.left=r,t}.call(this,e);e.setAttribute("data-progressjs",window._progressjsId);var r=document.createElement("div");r.className="progressjs-progress progressjs-theme-"+this._options.theme,"body"===e.tagName.toLowerCase()?r.style.position="fixed":r.style.position="absolute",r.setAttribute("data-progressjs",window._progressjsId);var s=document.createElement("div");s.className="progressjs-inner";var o=document.createElement("div");o.className="progressjs-percent",o.innerHTML="1%",s.appendChild(o),this._options.overlayMode&&"body"===e.tagName.toLowerCase()?(r.style.left=0,r.style.right=0,r.style.top=0,r.style.bottom=0):(r.style.left=t.left+"px",r.style.top=t.top+"px",r.style.width=t.width+"px",this._options.overlayMode&&(r.style.height=t.height+"px")),r.appendChild(s),document.querySelector(".progressjs-container").appendChild(r),n(e,1),++window._progressjsId}}function n(e,t){t>=100&&(t=100),e.hasAttribute("data-progressjs")&&setTimeout(function(){var r=o(e);r.style.width=parseInt(t)+"%",r=r.querySelector(".progressjs-percent");var s=parseInt(r.innerHTML.replace("%",""));!function(e,t,r){var s=!0;t>r&&(s=!1);var n=10;!function e(t,r,o){var i=Math.abs(r-o);n=i<3?30:i<20?20:1,r-o!=0&&(t.innerHTML=(s?++r:--r)+"%",setTimeout(function(){e(t,r,o)},n))}(e,t,r)}(r,s,parseInt(t))},50)}function o(e){var t=parseInt(e.getAttribute("data-progressjs"));return document.querySelector('.progressjs-container > .progressjs-progress[data-progressjs="'+t+'"] > .progressjs-inner')}function i(){void 0!==this._onBeforeEndCallback&&(!0===this._options.considerTransition?o(this._targetElement[0]).addEventListener(function(){var e,t=document.createElement("fakeelement"),r={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in r)if(void 0!==t.style[e])return r[e]}(),this._onBeforeEndCallback,!1):this._onBeforeEndCallback.call(this));for(var e=parseInt(this._targetElement[0].getAttribute("data-progressjs")),t=0,r=this._targetElement.length;t<r;t++){var s=this._targetElement[t],i=o(s);if(!i)return;var a=parseInt(i.style.width.replace("%","")),l=1;a<100&&(n.call(this,s,100),l=500),function(e,t){setTimeout(function(){e.parentNode.className+=" progressjs-end",setTimeout(function(){e.parentNode.parentNode.removeChild(e.parentNode),t.removeAttribute("data-progressjs")},1e3)},l)}(i,s)}if(window._progressjsIntervals[e])try{clearInterval(window._progressjsIntervals[e]),window._progressjsIntervals[e]=null,delete window._progressjsIntervals[e]}catch(e){}}var a=function(e){if("object"==typeof e)return new t(e);if("string"==typeof e){var r=document.querySelectorAll(e);if(r)return new t(r);throw new Error("There is no element with given selector.")}return new t(document.body)};a.version="0.1.0",a.fn=t.prototype={start:function(){return r.call(this),this},set:function(e){return function(e){for(var t=0,r=this._targetElement.length;t<r;t++)n.call(this,this._targetElement[t],e)}.call(this,e),this},end:function(){return i.call(this),this},onbeforeend:function(e){if("function"!=typeof e)throw new Error("Provided callback for onbeforeend was not a function");return this._onBeforeEndCallback=e,this}},e.progressJs=a})(this);

View file

@ -6,18 +6,7 @@
* Copyright (C) 2013 usabli.ca - Afshin Mehrabani (@afshinmeh)
*/
(function (root, factory) {
if (typeof exports === 'object') {
// CommonJS
factory(exports);
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports'], factory);
} else {
// Browser globals
factory(root);
}
} (this, function (exports) {
(exports => {
//Default config/variables
var VERSION = '0.1.0';
@ -42,7 +31,7 @@
this._options = {
//progress bar theme
theme: 'blue',
theme: 'rainloop',
//overlay mode makes an overlay layer in the target element
overlayMode: false,
//to consider CSS3 transitions in events
@ -163,8 +152,6 @@
* @param {Number} percent
*/
function _setPercentFor(targetElement, percent) {
var self = this;
//prevent overflow!
if (percent >= 100)
percent = 100;
@ -173,15 +160,10 @@
//setTimeout for better CSS3 animation applying in some cases
setTimeout(function() {
//call the onprogress callback
if (typeof self._onProgressCallback != 'undefined') {
self._onProgressCallback.call(self, targetElement, percent);
}
var percentElement = _getPercentElement(targetElement);
percentElement.style.width = parseInt(percent) + '%';
var percentElement = percentElement.querySelector(".progressjs-percent");
percentElement = percentElement.querySelector(".progressjs-percent");
var existingPercent = parseInt(percentElement.innerHTML.replace('%', ''));
//start increase/decrease the percent element with animation
@ -201,7 +183,7 @@
} else if (distance < 20) {
intervalIn = 20;
} else {
intervanIn = 1;
intervalIn = 1;
}
if ((existingPercent - currentPercent) != 0) {
@ -231,47 +213,6 @@
return document.querySelector('.progressjs-container > .progressjs-progress[data-progressjs="' + progressjsId + '"] > .progressjs-inner');
}
/**
* Auto increase the progress bar every X milliseconds
*
* @api private
* @method _autoIncrease
* @param {Number} size
* @param {Number} millisecond
*/
function _autoIncrease(size, millisecond) {
var self = this;
var progressjsId = parseInt(this._targetElement[0].getAttribute('data-progressjs'));
if (typeof window._progressjsIntervals[progressjsId] != 'undefined') {
clearInterval(window._progressjsIntervals[progressjsId]);
}
window._progressjsIntervals[progressjsId] = setInterval(function() {
_increasePercent.call(self, size);
}, millisecond);
}
/**
* Increase the size of progress bar
*
* @api private
* @method _increasePercent
* @param {Number} size
*/
function _increasePercent(size) {
for (var i = 0, elmsLength = this._targetElement.length; i < elmsLength; i++) {
var currentElement = this._targetElement[i];
if (currentElement.hasAttribute('data-progressjs')) {
var percentElement = _getPercentElement(currentElement);
var existingPercent = parseInt(percentElement.style.width.replace('%', ''));
if (existingPercent) {
_setPercentFor.call(this, currentElement, existingPercent + (size || 1));
}
}
}
}
/**
* Close and remove progress bar
*
@ -389,27 +330,12 @@
return elementPosition;
}
/**
* Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
* via: http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
*
* @param obj1
* @param obj2
* @returns obj3 a new object based on obj1 and obj2
*/
function _mergeOptions(obj1, obj2) {
var obj3 = {};
for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
return obj3;
}
var progressJs = function (targetElm) {
if (typeof (targetElm) === 'object') {
//Ok, create a new instance
return new ProgressJs(targetElm);
} else if (typeof (targetElm) === 'string') {
}
if (typeof (targetElm) === 'string') {
//select the target element with query selector
var targetElement = document.querySelectorAll(targetElm);
@ -418,9 +344,8 @@
} else {
throw new Error('There is no element with given selector.');
}
} else {
return new ProgressJs(document.body);
}
return new ProgressJs(document.body);
};
/**
@ -430,9 +355,9 @@
* @returns transition name
*/
function whichTransitionEvent() {
var t;
var el = document.createElement('fakeelement');
var transitions = {
var t,
el = document.createElement('fakeelement'),
transitions = {
'transition': 'transitionend',
'OTransition': 'oTransitionEnd',
'MozTransition': 'transitionend',
@ -456,17 +381,6 @@
//Prototype
progressJs.fn = ProgressJs.prototype = {
clone: function () {
return new ProgressJs(this);
},
setOption: function(option, value) {
this._options[option] = value;
return this;
},
setOptions: function(options) {
this._options = _mergeOptions(this._options, options);
return this;
},
start: function() {
_startProgress.call(this);
return this;
@ -475,14 +389,6 @@
_setPercent.call(this, percent);
return this;
},
increase: function(size) {
_increasePercent.call(this, size);
return this;
},
autoIncrease: function(size, millisecond) {
_autoIncrease.call(this, size, millisecond);
return this;
},
end: function() {
_end.call(this);
return this;
@ -494,25 +400,9 @@
throw new Error('Provided callback for onbeforeend was not a function');
}
return this;
},
onbeforestart: function(providedCallback) {
if (typeof (providedCallback) === 'function') {
this._onBeforeStartCallback = providedCallback;
} else {
throw new Error('Provided callback for onbeforestart was not a function');
}
return this;
},
onprogress: function(providedCallback) {
if (typeof (providedCallback) === 'function') {
this._onProgressCallback = providedCallback;
} else {
throw new Error('Provided callback for onprogress was not a function');
}
return this;
}
};
exports.progressJs = progressJs;
return progressJs;
}));
})(this);