vitaliykurganskiy
6/27/2016 - 5:36 PM

ES6 + jQuery popup controll class

<div class="popup" id="registration">
  <div class="popup__inner">
    Тут код для любого поп-апа
  </div>
</div>



class Popup {
	constructor() {
		this.popups = $('.popup');
		this.duration = 500;
		this.popups.hide();
	}

	show(popupId, popupText) {

		let textBlock = this.popups.filter(popupId).find('.popup__thanx');

		if(popupText) {
			textBlock.text(popupText);
		}

		this.popups.filter(popupId).fadeIn().css('display', 'inline-block');
	}
}

$('.registration-trigger').on('click', function(event) {
	event.preventDefault();
	
	let popup = new Popup;

	popup.show('#registration');

});

$('.popup__row-submit').on('click', function(event) {
	event.preventDefault();

	let popup = new Popup;

	popup.show('#thanx', 'этот текст меняется динамически');
});

$('.close').on('click', function(event) {
	event.preventDefault();

	let popup = new Popup;

});