Skip to content

Commit

Permalink
Performance improvements for progressbar flow
Browse files Browse the repository at this point in the history
  • Loading branch information
needim committed Feb 16, 2017
1 parent 5a558f5 commit ebb543e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ child/
.idea/

node_modules/
_SpecRunner.html
_SpecRunner.html
/.vscode/
47 changes: 21 additions & 26 deletions js/noty/jquery.noty.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
@package noty - jQuery Notification Plugin
@version version: 2.4.0
@version version: 2.4.1
@contributors https://github.com/needim/noty/graphs/contributors
@documentation Examples and Documentation - http://needim.github.com/noty/
Expand Down Expand Up @@ -218,21 +218,17 @@ var NotyObject = {

}, // end show

bindTimeout: function() {
bindTimeout: function () {
var self = this;

// If noty is have a timeout option
if (self.options.timeout) {

if (self.options.progressBar && self.$progressBar) {
self.$progressBar.css({
transition: 'all 100ms linear'
transition: 'all ' + self.options.timeout + 'ms linear',
width: '0%'
});

self.progressPercentage = (self.$progressBar.width() / (self.options.timeout / 100));

self.intervalId = setInterval(function() {
self.$progressBar.width((self.$progressBar.width() - self.progressPercentage));
}, 100);
}

self.queueClose(self.options.timeout);
Expand All @@ -243,10 +239,13 @@ var NotyObject = {
},

dequeueClose: function () {
if (this.intervalId) {
clearInterval(this.intervalId);
this.$progressBar.css('width', '100%');
this.intervalId = null;
var self = this;

if (self.options.progressBar) {
this.$progressBar.css({
transition: 'none',
width: '100%'
});
}

if (!this.closeTimer) return;
Expand All @@ -257,27 +256,23 @@ var NotyObject = {
queueClose: function (timeout) {
var self = this;

if (!self.intervalId && self.options.progressBar) {
self.intervalId = setInterval(function() {
self.$progressBar.width((self.$progressBar.width() - self.progressPercentage));
}, 100);
if (self.options.progressBar) {
self.$progressBar.css({
transition: 'all ' + self.options.timeout + 'ms linear',
width: '0%'
});
}

if (this.closeTimer) return;
self.closeTimer = window.setTimeout(function () {
self.close();
}, timeout);
return self.closeTimer
return self.closeTimer;
},

close: function () {
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = null;

if (this.$progressBar) {
this.$progressBar.css('width', '0%');
}
if (this.$progressBar) {
this.$progressBar.remove();
}

if (this.closeTimer) this.dequeueClose();
Expand Down Expand Up @@ -324,7 +319,7 @@ var NotyObject = {
});

} else if (typeof self.options.animation.close == 'object' && self.options.animation.close == null) {
self.$bar.dequeue().hide(0, function() {
self.$bar.dequeue().hide(0, function () {
if (self.options.callback.afterClose) self.options.callback.afterClose.apply(self);
self.closeCleanUp();
});
Expand Down
47 changes: 21 additions & 26 deletions js/noty/packaged/jquery.noty.packaged.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/*!
@package noty - jQuery Notification Plugin
@version version: 2.4.0
@version version: 2.4.1
@contributors https://github.com/needim/noty/graphs/contributors
@documentation Examples and Documentation - http://needim.github.com/noty/
Expand Down Expand Up @@ -228,21 +228,17 @@ var NotyObject = {

}, // end show

bindTimeout: function() {
bindTimeout: function () {
var self = this;

// If noty is have a timeout option
if (self.options.timeout) {

if (self.options.progressBar && self.$progressBar) {
self.$progressBar.css({
transition: 'all 100ms linear'
transition: 'all ' + self.options.timeout + 'ms linear',
width: '0%'
});

self.progressPercentage = (self.$progressBar.width() / (self.options.timeout / 100));

self.intervalId = setInterval(function() {
self.$progressBar.width((self.$progressBar.width() - self.progressPercentage));
}, 100);
}

self.queueClose(self.options.timeout);
Expand All @@ -253,10 +249,13 @@ var NotyObject = {
},

dequeueClose: function () {
if (this.intervalId) {
clearInterval(this.intervalId);
this.$progressBar.css('width', '100%');
this.intervalId = null;
var self = this;

if (self.options.progressBar) {
this.$progressBar.css({
transition: 'none',
width: '100%'
});
}

if (!this.closeTimer) return;
Expand All @@ -267,27 +266,23 @@ var NotyObject = {
queueClose: function (timeout) {
var self = this;

if (!self.intervalId && self.options.progressBar) {
self.intervalId = setInterval(function() {
self.$progressBar.width((self.$progressBar.width() - self.progressPercentage));
}, 100);
if (self.options.progressBar) {
self.$progressBar.css({
transition: 'all ' + self.options.timeout + 'ms linear',
width: '0%'
});
}

if (this.closeTimer) return;
self.closeTimer = window.setTimeout(function () {
self.close();
}, timeout);
return self.closeTimer
return self.closeTimer;
},

close: function () {
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = null;

if (this.$progressBar) {
this.$progressBar.css('width', '0%');
}
if (this.$progressBar) {
this.$progressBar.remove();
}

if (this.closeTimer) this.dequeueClose();
Expand Down Expand Up @@ -334,7 +329,7 @@ var NotyObject = {
});

} else if (typeof self.options.animation.close == 'object' && self.options.animation.close == null) {
self.$bar.dequeue().hide(0, function() {
self.$bar.dequeue().hide(0, function () {
if (self.options.callback.afterClose) self.options.callback.afterClose.apply(self);
self.closeCleanUp();
});
Expand Down
4 changes: 2 additions & 2 deletions js/noty/packaged/jquery.noty.packaged.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion noty.jquery.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "noty",
"version" : "2.4.0",
"version" : "2.4.1",
"title" : "noty - a jquery notification plugin",
"description" : "noty is a jQuery plugin that makes it easy to create alert - success - error - warning - information - confirmation messages as an alternative the standard alert dialog. Each notification is added to a queue. (Optional)",
"keywords" : ["noty", "notification", "plugin", "jquery", "javascript", "alert", "error", "warning", "information", "confirmation"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "noty",
"version": "2.4.0",
"version": "2.4.1",
"title": "noty - a jquery notification plugin",
"description": "noty is a jQuery plugin that makes it easy to create alert - success - error - warning - information - confirmation messages as an alternative the standard alert dialog. Each notification is added to a queue. (Optional)",
"homepage": "http://needim.github.com/noty",
Expand Down

0 comments on commit ebb543e

Please sign in to comment.