Skip to content

Instantly share code, notes, and snippets.

@danieliser
Created August 14, 2017 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieliser/553fdfd8e15612cd2c05c543a4fd5e26 to your computer and use it in GitHub Desktop.
Save danieliser/553fdfd8e15612cd2c05c543a4fd5e26 to your computer and use it in GitHub Desktop.
Override the popup close method with one that doesn't fade out.
jQuery(document).ready(function () {
setTimeout(function () {
jQuery.fn.popmake.close = function (callback) {
return this.each(function () {
var $popup = PUM.getPopup(this),
$container = $popup.popmake('getContainer'),
$close = $popup.popmake('getClose').add($('.popmake-close', $popup).not($popup.popmake('getClose')));
$popup.trigger('pumBeforeClose');
if ($popup.hasClass('preventClose') || $container.hasClass('preventClose')) {
$popup
.removeClass('preventClose')
.trigger('pumClosePrevented');
return this;
}
$container
.fadeOut(0, function () {
if ($popup.is(":visible")) {
$popup.fadeOut(0);
}
$(window).off('keyup.popmake');
$popup.off('click.popmake');
$close.off('click.popmake');
// Only re-enable scrolling for the document when the last popup has closed.
if ($('.pum-active').length === 1) {
$('html')
.removeClass('pum-open')
.removeClass('pum-open-scrollable')
.removeClass('pum-open-overlay')
.removeClass('pum-open-overlay-disabled')
.removeClass('pum-open-fixed');
}
$popup
.removeClass('pum-active')
.trigger('pumAfterClose');
// TODO: Move this to its own event binding to keep this method clean and simple.
$container.find('iframe').filter('[src*="youtube"],[src*="vimeo"]').each(function () {
var $iframe = $(this),
src = $iframe.attr('src'),
// Remove autoplay so video doesn't start playing again.
new_src = src.replace('autoplay=1', '1=1');
if (new_src !== src) {
src = new_src;
}
$iframe.prop('src', src);
});
// TODO: Move this to its own event binding to keep this method clean and simple.
$container.find('video').each(function () {
this.pause();
});
// Fire user passed callback.
if (callback !== undefined) {
callback();
// TODO Test this new method. Then remove the above.
//callback.apply(this);
}
});
return this;
});
};
}, 1000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment