Skip to content

Commit 361b032

Browse files
committed
Merge pull request usablica#13 from bramgg/kill
Kill
2 parents ce8a200 + f9c9895 commit 361b032

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/progress.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,49 @@
338338
}
339339
}
340340

341+
/**
342+
* Remove progress bar without finishing
343+
*
344+
* @api private
345+
* @method _kill
346+
*/
347+
function _kill() {
348+
var target = this._targetElement[0];
349+
if(!target) return;
350+
var progressjsId = parseInt(target.getAttribute('data-progressjs'));
351+
352+
for (var i = 0, elmsLength = this._targetElement.length; i < elmsLength; i++) {
353+
var currentElement = this._targetElement[i];
354+
var percentElement = _getPercentElement(currentElement);
355+
356+
if (!percentElement)
357+
return;
358+
359+
//I believe I should handle this situation with eventListener and `transitionend` event but I'm not sure
360+
//about compatibility with IEs. Should be fixed in further versions.
361+
(function(percentElement, currentElement) {
362+
percentElement.parentNode.className += " progressjs-end";
363+
364+
setTimeout(function() {
365+
//remove the percent element from page
366+
percentElement.parentNode.parentNode.removeChild(percentElement.parentNode);
367+
//and remove the attribute
368+
currentElement.removeAttribute("data-progressjs");
369+
}, 1000);
370+
})(percentElement, currentElement);
371+
}
372+
373+
//clean the setInterval for autoIncrease function
374+
if (window._progressjsIntervals[progressjsId]) {
375+
//`delete` keyword has some problems in IE
376+
try {
377+
clearInterval(window._progressjsIntervals[progressjsId]);
378+
window._progressjsIntervals[progressjsId] = null;
379+
delete window._progressjsIntervals[progressjsId];
380+
} catch(ex) { }
381+
}
382+
}
383+
341384
/**
342385
* Create the progress bar container
343386
*
@@ -491,6 +534,10 @@
491534
_end.call(this);
492535
return this;
493536
},
537+
kill: function() {
538+
_kill.call(this);
539+
return this;
540+
},
494541
onbeforeend: function(providedCallback) {
495542
if (typeof (providedCallback) === 'function') {
496543
this._onBeforeEndCallback = providedCallback;

0 commit comments

Comments
 (0)