Skip to content

Commit

Permalink
Merge pull request marcelodolza#160 from macroplant/modalHash-fix
Browse files Browse the repository at this point in the history
fixes jquery bug marcelodolza#155
  • Loading branch information
marcelodolza authored Jan 5, 2018
2 parents 5019178 + 6ddacd9 commit 3b13d00
Showing 1 changed file with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions js/iziModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
this.$element = $(element);

if(this.$element[0].id !== undefined && this.$element[0].id !== ''){
this.id = this.$element[0].id;
this.id = this.$element[0].id;
} else {
this.id = PLUGIN_NAME+Math.floor((Math.random() * 10000000) + 1);
this.$element.attr('id', this.id);
Expand Down Expand Up @@ -145,12 +145,12 @@
});

if(options.appendTo !== false){
this.$element.appendTo(options.appendTo);
this.$element.appendTo(options.appendTo);
}

if (options.iframe === true) {
this.$element.html('<div class="'+PLUGIN_NAME+'-wrap"><div class="'+PLUGIN_NAME+'-content"><iframe class="'+PLUGIN_NAME+'-iframe"></iframe>' + this.content + "</div></div>");

if (options.iframeHeight !== null) {
this.$element.find('.'+PLUGIN_NAME+'-iframe').css('height', options.iframeHeight);
}
Expand Down Expand Up @@ -212,7 +212,7 @@
if (this.options.closeButton === true) {
this.$header.find('.'+PLUGIN_NAME+'-header-buttons').append('<a href="javascript:void(0)" class="'+PLUGIN_NAME+'-button '+PLUGIN_NAME+'-button-close" data-'+PLUGIN_NAME+'-close></a>');
}

if (this.options.fullscreen === true) {
this.$header.find('.'+PLUGIN_NAME+'-header-buttons').append('<a href="javascript:void(0)" class="'+PLUGIN_NAME+'-button '+PLUGIN_NAME+'-button-fullscreen" data-'+PLUGIN_NAME+'-fullscreen></a>');
}
Expand All @@ -229,7 +229,7 @@

if (this.options.headerColor !== null) {
if(this.options.borderBottom === true){
this.$element.css('border-bottom', '3px solid ' + this.options.headerColor + '');
this.$element.css('border-bottom', '3px solid ' + this.options.headerColor + '');
}
this.$header.css('background', this.options.headerColor);
}
Expand Down Expand Up @@ -257,7 +257,7 @@
if( groupName !== undefined && groupName !== this.group.name){
group = groupName;
this.group.name = group;
this.$element.attr('data-'+PLUGIN_NAME+'-group', group);
this.$element.attr('data-'+PLUGIN_NAME+'-group', group);
}
if(group !== undefined && group !== ''){

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

function opened(){

// console.info('[ '+PLUGIN_NAME+' | '+that.id+' ] Opened.');

that.state = STATES.OPENED;
Expand Down Expand Up @@ -382,7 +382,7 @@
// console.info('[ '+PLUGIN_NAME+' | '+this.id+' ] Opening...');

if(this.options.iframe === true){

this.$element.find('.'+PLUGIN_NAME+'-content').addClass(PLUGIN_NAME+'-content-loader');

this.$element.find('.'+PLUGIN_NAME+'-iframe').on('load', function(){
Expand Down Expand Up @@ -414,7 +414,7 @@

if (this.options.onOpening && typeof(this.options.onOpening) === 'function') {
this.options.onOpening(this);
}
}
(function open(){

if(that.group.ids.length > 1 ){
Expand All @@ -433,13 +433,13 @@
that.$navigate.find('.'+PLUGIN_NAME+'-navigate-next').css('right', 0).show();
} else {
that.$navigate.find('.'+PLUGIN_NAME+'-navigate-prev').css('margin-left', -((modalWidth/2)+84)).show();
that.$navigate.find('.'+PLUGIN_NAME+'-navigate-next').css('margin-right', -((modalWidth/2)+84)).show();
that.$navigate.find('.'+PLUGIN_NAME+'-navigate-next').css('margin-right', -((modalWidth/2)+84)).show();
}
} else {
that.$navigate.find('.'+PLUGIN_NAME+'-navigate-prev').hide();
that.$navigate.find('.'+PLUGIN_NAME+'-navigate-next').hide();
}

var loop;
if(that.group.index === 0){

Expand All @@ -462,7 +462,7 @@
if(that.options.appendToOverlay === false){
that.$overlay.appendTo('body');
} else {
that.$overlay.appendTo( that.options.appendToOverlay );
that.$overlay.appendTo( that.options.appendToOverlay );
}
}

Expand Down Expand Up @@ -522,7 +522,7 @@
updateProgress: function()
{
if(!that.isPaused){

that.progressBar.currentTime = that.progressBar.currentTime+10;

var percentage = ((that.progressBar.hideEta - (that.progressBar.currentTime)) / that.progressBar.maxHideTime) * 100;
Expand Down Expand Up @@ -558,7 +558,7 @@
if (this.options.focusInput){
this.$element.find(':input:not(button):enabled:visible:first').focus(); // Focus on the first field
}

(function updateTimer(){
that.recalcLayout();
that.timer = setTimeout(updateTimer, 300);
Expand All @@ -580,7 +580,7 @@
var that = this;

function closed(){

// console.info('[ '+PLUGIN_NAME+' | '+that.id+' ] Closed.');

that.state = STATES.CLOSED;
Expand All @@ -595,11 +595,11 @@
if(isMobile){
$('body').css('overflow','auto');
}
}
}

if (that.options.onClosed && typeof(that.options.onClosed) === 'function') {
that.options.onClosed(that);
}
that.options.onClosed(that);
}

if(that.options.restoreDefaultContent === true){
that.$element.find('.'+PLUGIN_NAME+'-content').html( that.content );
Expand Down Expand Up @@ -632,7 +632,7 @@
if( typeof param == 'object' ){
if(param.transition !== undefined || param.transitionOut !== undefined){
transitionOut = param.transition || param.transitionOut;
}
}
}

if( (transitionOut === false || transitionOut === '' ) || animationEvent === undefined){
Expand All @@ -652,15 +652,15 @@
this.isFullscreen === true ? 'isFullscreen' : '',
this.options.rtl ? PLUGIN_NAME+'-rtl' : ''
].join(' '));

this.$overlay.attr('class', PLUGIN_NAME + '-overlay ' + this.options.transitionOutOverlay);

if(that.options.navigateArrows !== false){
this.$navigate.attr('class', PLUGIN_NAME + '-navigate fadeOut');
}

this.$element.one(animationEvent, function () {

if( that.$element.hasClass(transitionOut) ){
that.$element.removeClass(transitionOut + ' transitionOut').hide();
}
Expand Down Expand Up @@ -698,7 +698,7 @@
}

this.close({transition:transitionOut});

setTimeout(function(){

var loop = $('.'+PLUGIN_NAME+'[data-'+PLUGIN_NAME+'-group="'+that.group.name+'"][data-'+PLUGIN_NAME+'-loop]').length;
Expand All @@ -722,7 +722,9 @@

modals.in = $('#'+that.group.ids[index]).data().iziModal;
if(typeof modals.in !== 'undefined'){
$('#'+that.group.ids[index]).iziModal('open', { transition: transitionIn });

$('#'+that.group.ids[index]).iziModal('open', { transition: transitionIn });

break;
}
}
Expand All @@ -748,7 +750,7 @@
modal = $(e.currentTarget);
transitionIn = modal.attr('data-'+PLUGIN_NAME+'-transitionIn');
transitionOut = modal.attr('data-'+PLUGIN_NAME+'-transitionOut');

} else if(e !== undefined){

if(e.transitionIn !== undefined){
Expand Down Expand Up @@ -785,7 +787,9 @@

modals.in = $('#'+that.group.ids[index]).data().iziModal;
if(typeof modals.in !== 'undefined'){
$('#'+that.group.ids[index]).iziModal('open', { transition: transitionIn });

$('#'+that.group.ids[index]).iziModal('open', { transition: transitionIn });

break;
}
}
Expand Down Expand Up @@ -820,7 +824,7 @@
.off('.'+PLUGIN_NAME)
.removeData(PLUGIN_NAME)
.attr('style', '');

this.$overlay.remove();
this.$navigate.remove();
this.$element.trigger(STATES.DESTROYED);
Expand All @@ -846,7 +850,7 @@
var modalWidth = this.$element.outerWidth();
if(this.options.navigateArrows === true || this.options.navigateArrows == 'closeToModal'){
this.$navigate.find('.'+PLUGIN_NAME+'-navigate-prev').css('margin-left', -((modalWidth/2)+84)).show();
this.$navigate.find('.'+PLUGIN_NAME+'-navigate-next').css('margin-right', -((modalWidth/2)+84)).show();
this.$navigate.find('.'+PLUGIN_NAME+'-navigate-next').css('margin-right', -((modalWidth/2)+84)).show();
}

},
Expand Down Expand Up @@ -894,7 +898,7 @@
setSubtitle: function(subtitle){

if(subtitle === ''){

this.$header.find('.'+PLUGIN_NAME+'-header-subtitle').remove();
this.$header.addClass(PLUGIN_NAME+'-noSubtitle');

Expand Down Expand Up @@ -940,7 +944,7 @@
this.$element.css('background', '');
} else{
this.$element.css('background', background);
this.options.background = background;
this.options.background = background;
}
},

Expand Down Expand Up @@ -982,7 +986,7 @@
},

setTransitionIn: function(transition){

this.options.transitionIn = transition;
},

Expand All @@ -1009,7 +1013,7 @@
},

stopLoading: function(){

var $loader = this.$element.find('.'+PLUGIN_NAME+'-loader');

if( !$loader.length ){
Expand Down Expand Up @@ -1228,10 +1232,10 @@
$window.off('hashchange.'+PLUGIN_NAME).on('hashchange.'+PLUGIN_NAME, function(e) {

var modalHash = document.location.hash;
var data = $(modalHash).data();

if(modalHash !== ''){
try {
var data = $(modalHash).data();
if(typeof data !== 'undefined' && $(modalHash).iziModal('getState') !== 'opening'){

setTimeout(function(){
Expand Down Expand Up @@ -1318,7 +1322,7 @@
id: this.selector.split('#'),
class: this.selector.split('.')
};

if(newEL.id.length > 1){
try{
newEL.$el = document.createElement(id[0]);
Expand All @@ -1342,7 +1346,7 @@
var objs = this;

for (var i=0; i<objs.length; i++) {

var $this = $(objs[i]);
var data = $this.data(PLUGIN_NAME);
var options = $.extend({}, $.fn[PLUGIN_NAME].defaults, $this.data(), typeof option == 'object' && option);
Expand All @@ -1358,13 +1362,13 @@
if (options.autoOpen){ // Automatically open the modal if autoOpen setted true or ms

if( !isNaN(parseInt(options.autoOpen)) ){

setTimeout(function(){
data.open();
}, options.autoOpen);

} else if(options.autoOpen === true ) {

data.open();
}
window.$iziModal.autoOpen++;
Expand Down Expand Up @@ -1433,4 +1437,4 @@

return $.fn.iziModal;

}));
}));

0 comments on commit 3b13d00

Please sign in to comment.