-
Notifications
You must be signed in to change notification settings - Fork 206
Adding event to after callbacks #33
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
(function ($) { | ||
|
||
$.fn.animatedModal = function(options) { | ||
var me = this; | ||
var modal = $(this); | ||
|
||
//Defaults | ||
|
@@ -29,23 +30,57 @@ | |
animationDuration:'.6s', | ||
overflow:'auto', | ||
// Callbacks | ||
beforeOpen: function() {}, | ||
beforeOpen: function(event, callback) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run callbacks after open |
||
callback(); | ||
}, | ||
afterOpen: function() {}, | ||
beforeClose: function() {}, | ||
afterClose: function() {} | ||
|
||
}, options); | ||
|
||
me.openModal = function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extracted this out so it can be called manually this.modalWindow.openModal(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ReferenceError: event is not defined |
||
settings.beforeOpen(event, function(){ | ||
$('body, html').css({'overflow':'hidden'}); | ||
if (id.hasClass(settings.modalTarget+'-off')) { | ||
id.removeClass(settings.animatedOut); | ||
id.removeClass(settings.modalTarget+'-off'); | ||
id.addClass(settings.modalTarget+'-on'); | ||
} | ||
|
||
if (id.hasClass(settings.modalTarget+'-on')) { | ||
id.css({'opacity':settings.opacityIn,'z-index':settings.zIndexIn}); | ||
id.addClass(settings.animatedIn); | ||
id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(event){ | ||
afterOpen(event); | ||
}); | ||
}; | ||
}); | ||
} | ||
|
||
me.closeModal = function(){ | ||
$('body, html').css({'overflow':'initial'}); | ||
|
||
if (id.hasClass(settings.modalTarget+'-on')) { | ||
id.removeClass(settings.modalTarget+'-on'); | ||
id.addClass(settings.modalTarget+'-off'); | ||
}; | ||
|
||
}, options); | ||
if (id.hasClass(settings.modalTarget+'-off')) { | ||
id.removeClass(settings.animatedIn); | ||
id.addClass(settings.animatedOut); | ||
id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(event){ | ||
afterClose(event); | ||
}); | ||
}; | ||
} | ||
|
||
var closeBt = $('.close-'+settings.modalTarget); | ||
|
||
//console.log(closeBt) | ||
|
||
var href = $(modal).attr('href'), | ||
id = $('body').find('#'+settings.modalTarget), | ||
idConc = '#'+id.attr('id'); | ||
//console.log(idConc); | ||
|
||
// Default Classes | ||
id.addClass('animated'); | ||
id.addClass(settings.modalTarget+'-off'); | ||
|
@@ -66,57 +101,39 @@ | |
'-ms-animation-duration':settings.animationDuration, | ||
'animation-duration':settings.animationDuration | ||
}; | ||
|
||
//Apply stles | ||
id.css(initStyles); | ||
|
||
modal.click(function(event) { | ||
event.preventDefault(); | ||
$('body, html').css({'overflow':'hidden'}); | ||
if (href == idConc) { | ||
if (id.hasClass(settings.modalTarget+'-off')) { | ||
id.removeClass(settings.animatedOut); | ||
id.removeClass(settings.modalTarget+'-off'); | ||
id.addClass(settings.modalTarget+'-on'); | ||
} | ||
|
||
if (id.hasClass(settings.modalTarget+'-on')) { | ||
settings.beforeOpen(); | ||
id.css({'opacity':settings.opacityIn,'z-index':settings.zIndexIn}); | ||
id.addClass(settings.animatedIn); | ||
id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', afterOpen); | ||
}; | ||
} | ||
me.openModal(); | ||
}); | ||
|
||
|
||
|
||
closeBt.click(function(event) { | ||
// update so dynamically created close buttons have click handlers | ||
$('body').on('click', '.close-'+settings.modalTarget, function(event){ | ||
event.preventDefault(); | ||
$('body, html').css({'overflow':'auto'}); | ||
|
||
settings.beforeClose(); //beforeClose | ||
if (id.hasClass(settings.modalTarget+'-on')) { | ||
id.removeClass(settings.modalTarget+'-on'); | ||
id.addClass(settings.modalTarget+'-off'); | ||
} | ||
|
||
if (id.hasClass(settings.modalTarget+'-off')) { | ||
id.removeClass(settings.animatedIn); | ||
id.addClass(settings.animatedOut); | ||
id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', afterClose); | ||
}; | ||
settings.beforeClose(event); //beforeClose | ||
|
||
me.closeModal(); | ||
}); | ||
|
||
function afterClose () { | ||
id.css({'z-index':settings.zIndexOut}); | ||
settings.afterClose(); //afterClose | ||
function afterClose (event) { | ||
// make sure it's really the modal that is triggering the close event | ||
if (event.target === event.currentTarget) { | ||
id.css({'z-index':settings.zIndexOut}); | ||
settings.afterClose(event); //afterClose | ||
} | ||
} | ||
|
||
function afterOpen () { | ||
settings.afterOpen(); //afterOpen | ||
function afterOpen (event) { | ||
settings.afterOpen(event); //afterOpen | ||
} | ||
|
||
// it is customary to return "this", but I assigned "this" to "me" | ||
return me; | ||
|
||
}; // End animatedModal.js | ||
|
||
}(jQuery)); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
holding variable so we can return "this" at the end as is customary (with added openModal and closeModal methods).