Skip to content

Commit

Permalink
Fixes update v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelodolza committed Mar 10, 2018
1 parent e1d9271 commit d5c5751
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 105 deletions.
12 changes: 6 additions & 6 deletions dist/css/iziToast.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
float: left;
margin: 3px -2px;
}
.iziToast > .iziToast-body .iziToast-inputs > input,
.iziToast > .iziToast-body .iziToast-inputs > input:not([type=checkbox]):not([type=radio]),
.iziToast > .iziToast-body .iziToast-inputs > select {
position: relative;
display: inline-block;
Expand All @@ -148,7 +148,7 @@
box-shadow: 0 0 0 1px rgba(0,0,0,0.2);
min-height: 26px;
}
.iziToast > .iziToast-body .iziToast-inputs > input:focus,
.iziToast > .iziToast-body .iziToast-inputs > input:not([type=checkbox]):not([type=radio]):focus,
.iziToast > .iziToast-body .iziToast-inputs > select:focus {
box-shadow: 0 0 0 1px rgba(0,0,0,0.6);
}
Expand All @@ -159,7 +159,7 @@
}
.iziToast > .iziToast-body .iziToast-buttons > a,
.iziToast > .iziToast-body .iziToast-buttons > button,
.iziToast > .iziToast-body .iziToast-buttons > input {
.iziToast > .iziToast-body .iziToast-buttons > input:not([type=checkbox]):not([type=radio]) {
position: relative;
display: inline-block;
margin: 2px;
Expand All @@ -174,17 +174,17 @@
}
.iziToast > .iziToast-body .iziToast-buttons > a:hover,
.iziToast > .iziToast-body .iziToast-buttons > button:hover,
.iziToast > .iziToast-body .iziToast-buttons > input:hover {
.iziToast > .iziToast-body .iziToast-buttons > input:not([type=checkbox]):not([type=radio]):hover {
background: rgba(0,0,0,0.2);
}
.iziToast > .iziToast-body .iziToast-buttons > a:focus,
.iziToast > .iziToast-body .iziToast-buttons > button:focus,
.iziToast > .iziToast-body .iziToast-buttons > input:focus {
.iziToast > .iziToast-body .iziToast-buttons > input:not([type=checkbox]):not([type=radio]):focus {
box-shadow: 0 0 0 1px rgba(0,0,0,0.6);
}
.iziToast > .iziToast-body .iziToast-buttons > a:active,
.iziToast > .iziToast-body .iziToast-buttons > button:active,
.iziToast > .iziToast-body .iziToast-buttons > input:active {
.iziToast > .iziToast-body .iziToast-buttons > input:not([type=checkbox]):not([type=radio]):active {
top: 1px;
}
.iziToast > .iziToast-body .iziToast-icon {
Expand Down
2 changes: 1 addition & 1 deletion dist/css/iziToast.min.css

Large diffs are not rendered by default.

121 changes: 74 additions & 47 deletions dist/js/iziToast.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
MOBILEWIDTH = 568,
CONFIG = {};

$iziToast.childrens = {};

// Default settings
var defaults = {
Expand Down Expand Up @@ -101,7 +102,7 @@
transitionOutMobile: 'fadeOutDown',
buttons: {},
inputs: {},
TIME: {},
time: {},
onOpening: function () {},
onOpened: function () {},
onClosing: function () {},
Expand Down Expand Up @@ -139,7 +140,7 @@
CustomEventPolyfill.prototype = window.Event.prototype;

window.CustomEvent = CustomEventPolyfill;
}
}

/**
* A simple forEach() implementation for Arrays, Objects and NodeLists
Expand Down Expand Up @@ -327,6 +328,23 @@
}();





$iziToast.setSetting = function (ref, option, value) {

$iziToast.childrens[ref][option] = value;

};


$iziToast.getSetting = function (ref, option) {

return $iziToast.childrens[ref][option];

};


/**
* Destroy the current initialization.
* @public
Expand Down Expand Up @@ -391,14 +409,16 @@
*/
$iziToast.progress = function (options, $toast, callback) {


var that = this,
settings = extend(defaults, options || {}),
ref = $toast.getAttribute('data-iziToast-ref'),
settings = extend(this.childrens[ref], options || {}),
$elem = $toast.querySelector('.'+PLUGIN_NAME+'-progressbar div');

return {
start: function() {

if(typeof settings.TIME.REMAINING == 'undefined'){
if(typeof settings.time.REMAINING == 'undefined'){

$toast.classList.remove(PLUGIN_NAME+'-reseted');

Expand All @@ -407,11 +427,11 @@
$elem.style.width = '0%';
}

settings.TIME.START = new Date().getTime();
settings.TIME.END = settings.TIME.START + settings.timeout;
settings.TIME.TIMER = setTimeout(function() {
settings.time.START = new Date().getTime();
settings.time.END = settings.time.START + settings.timeout;
settings.time.TIMER = setTimeout(function() {

clearTimeout(settings.TIME.TIMER);
clearTimeout(settings.time.TIMER);

if(!$toast.classList.contains(PLUGIN_NAME+'-closing')){

Expand All @@ -423,17 +443,20 @@
}

}, settings.timeout);
that.setSetting(ref, 'time', settings.time);
}
},
pause: function() {

if(!$toast.classList.contains(PLUGIN_NAME+'-paused') && !$toast.classList.contains(PLUGIN_NAME+'-reseted')){
if(typeof settings.time.START !== 'undefined' && !$toast.classList.contains(PLUGIN_NAME+'-paused') && !$toast.classList.contains(PLUGIN_NAME+'-reseted')){

$toast.classList.add(PLUGIN_NAME+'-paused');

settings.TIME.REMAINING = settings.TIME.END - new Date().getTime();
settings.time.REMAINING = settings.time.END - new Date().getTime();

clearTimeout(settings.time.TIMER);

clearTimeout(settings.TIME.TIMER);
that.setSetting(ref, 'time', settings.time);

if($elem !== null){
var computedStyle = window.getComputedStyle($elem),
Expand All @@ -452,19 +475,19 @@
},
resume: function() {

if(typeof settings.TIME.REMAINING !== 'undefined'){
if(typeof settings.time.REMAINING !== 'undefined'){

$toast.classList.remove(PLUGIN_NAME+'-paused');

if($elem !== null){
$elem.style.transition = 'width '+ settings.TIME.REMAINING +'ms '+settings.progressBarEasing;
$elem.style.transition = 'width '+ settings.time.REMAINING +'ms '+settings.progressBarEasing;
$elem.style.width = '0%';
}

settings.TIME.END = new Date().getTime() + settings.TIME.REMAINING;
settings.TIME.TIMER = setTimeout(function() {
settings.time.END = new Date().getTime() + settings.time.REMAINING;
settings.time.TIMER = setTimeout(function() {

clearTimeout(settings.TIME.TIMER);
clearTimeout(settings.time.TIMER);

if(!$toast.classList.contains(PLUGIN_NAME+'-closing')){

Expand All @@ -476,16 +499,20 @@
}


}, settings.TIME.REMAINING);
}, settings.time.REMAINING);

that.setSetting(ref, 'time', settings.time);
} else {
this.start();
}
},
reset: function(){

clearTimeout(settings.TIME.TIMER);
clearTimeout(settings.time.TIMER);

delete settings.time.REMAINING;

delete settings.TIME.REMAINING;
that.setSetting(ref, 'time', settings.time);

$toast.classList.add(PLUGIN_NAME+'-reseted');

Expand Down Expand Up @@ -514,28 +541,26 @@
*/
$iziToast.hide = function (options, $toast, closedBy) {

var settings = extend(defaults, options || {});
closedBy = closedBy || null;
var that = this,
settings = extend(this.childrens[$toast.getAttribute('data-iziToast-ref')], options || {});
settings.closedBy = closedBy || null;

delete settings.time.REMAINING;

if(typeof $toast != 'object'){
$toast = document.querySelector($toast);
}

delete settings.TIME.REMAINING;
}

$toast.classList.add(PLUGIN_NAME+'-closing');

settings.closedBy = closedBy;
settings.REF = $toast.getAttribute('data-iziToast-ref');

// Overlay
(function(){

var $overlay = document.querySelector('.'+PLUGIN_NAME+'-overlay');
if($overlay !== null){
var refs = $overlay.getAttribute('data-iziToast-ref');
refs = refs.split(',');
var index = refs.indexOf(settings.REF);
var index = refs.indexOf(String(settings.ref));

if(index !== -1){
refs.splice(index, 1);
Expand Down Expand Up @@ -574,7 +599,6 @@
}

try {
settings.closedBy = closedBy;
var event = new CustomEvent(PLUGIN_NAME+'-closing', {detail: settings, bubbles: true, cancelable: true});
document.dispatchEvent(event);
} catch(ex){
Expand All @@ -588,9 +612,11 @@

setTimeout(function(){

delete that.childrens[settings.ref];

$toast.parentNode.remove();

try {
settings.closedBy = closedBy;
var event = new CustomEvent(PLUGIN_NAME+'-closed', {detail: settings, bubbles: true, cancelable: true});
document.dispatchEvent(event);
} catch(ex){
Expand Down Expand Up @@ -622,12 +648,15 @@
// Merge user options with defaults
var settings = extend(CONFIG, options || {});
settings = extend(defaults, settings);
settings.time = {};

if(settings.toastOnce && settings.id && document.querySelectorAll('.'+PLUGIN_NAME+'#'+settings.id).length > 0){
return false;
}

settings.REF = new Date().getTime() + Math.floor((Math.random() * 10000000) + 1);
settings.ref = new Date().getTime() + Math.floor((Math.random() * 10000000) + 1);

$iziToast.childrens[settings.ref] = settings;

var $DOM = {
body: document.querySelector('body'),
Expand All @@ -643,7 +672,7 @@
wrapper: null
};

$DOM.toast.setAttribute('data-iziToast-ref', settings.REF);
$DOM.toast.setAttribute('data-iziToast-ref', settings.ref);
$DOM.toast.appendChild($DOM.toastBody);
$DOM.toastCapsule.appendChild($DOM.toast);

Expand Down Expand Up @@ -812,7 +841,7 @@
}
})();

// Title
// Title & Message
(function(){
if(settings.title.length > 0) {

Expand All @@ -839,10 +868,7 @@
}
}
}
})();

// Message
(function(){

if(settings.message.length > 0) {

$DOM.p = document.createElement('p');
Expand All @@ -869,15 +895,15 @@
}
}
}
})();

if(settings.title.length > 0 && settings.message.length > 0) {
if(settings.rtl){
$DOM.strong.style.marginLeft = '10px';
} else if(settings.layout !== 2 && !settings.rtl) {
$DOM.strong.style.marginRight = '10px';
if(settings.title.length > 0 && settings.message.length > 0) {
if(settings.rtl){
$DOM.strong.style.marginLeft = '10px';
} else if(settings.layout !== 2 && !settings.rtl) {
$DOM.strong.style.marginRight = '10px';
}
}
}
})();

$DOM.toastBody.appendChild($DOM.toastTexts);

Expand Down Expand Up @@ -958,7 +984,7 @@
}
}

// Target
// Wrap
(function(){
$DOM.toastCapsule.style.visibility = 'hidden';
setTimeout(function() {
Expand Down Expand Up @@ -1052,17 +1078,18 @@
if( document.querySelector('.'+PLUGIN_NAME+'-overlay.fadeIn') !== null ){

$DOM.overlay = document.querySelector('.'+PLUGIN_NAME+'-overlay');
$DOM.overlay.setAttribute('data-iziToast-ref', $DOM.overlay.getAttribute('data-iziToast-ref') + ',' + settings.REF);
$DOM.overlay.setAttribute('data-iziToast-ref', $DOM.overlay.getAttribute('data-iziToast-ref') + ',' + settings.ref);

if(!isNaN(settings.zindex) && settings.zindex !== null) {
$DOM.overlay.style.zIndex = settings.zindex-1;
}

} else {

$DOM.overlay.classList.add(PLUGIN_NAME+'-overlay');
$DOM.overlay.classList.add('fadeIn');
$DOM.overlay.style.background = settings.overlayColor;
$DOM.overlay.setAttribute('data-iziToast-ref', settings.REF);
$DOM.overlay.setAttribute('data-iziToast-ref', settings.ref);
if(!isNaN(settings.zindex) && settings.zindex !== null) {
$DOM.overlay.style.zIndex = settings.zindex-1;
}
Expand Down
Loading

0 comments on commit d5c5751

Please sign in to comment.