Last active
December 4, 2019 09:54
-
-
Save bologer/9d09b345ea9f1db280232985ee0ad778 to your computer and use it in GitHub Desktop.
anycommnet-popup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Ждем пока в DOM появится элемент с указанным селектором | |
* и вызовем колбек в момент появления. | |
* | |
* @param selector | |
* @param callback | |
*/ | |
function waitForEl( selector, callback ) { | |
var poller = setInterval( | |
function() { | |
var $obj = jQuery( selector ); | |
if ( ! $obj.size() ) { | |
return; | |
} | |
clearInterval( poller ); | |
callback( $obj ) | |
}, | |
200 | |
); | |
} | |
// Включаем подсветку синтаксиса после загрузки элемента . | |
waitForEl( | |
'#anycomment-load-container', | |
handleOpenPopup | |
); | |
/** | |
* Открытие окошка "имя". | |
*/ | |
function handleOpenPopup() { | |
// тут логика по отображения модального окошка | |
var modalName = $(this).attr('data-modal'); | |
var modal = $('.js-modal[data-modal="' + modalName + '"]'); | |
modal.addClass('is-show'); | |
$('.js-modal-overlay').addClass('is-show'); | |
$('.js-modal-close').click(function() { | |
$(this).parent('.js-modal').removeClass('is-show'); | |
$('.js-modal-overlay').removeClass('is-show'); | |
}); | |
$('.js-modal-overlay').click(function() { | |
$('.js-modal.is-show').removeClass('is-show'); | |
$(this).removeClass('is-show'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment