PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 3.1.0
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v3.1.0
3.1.4 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 All 93 releases
ultimate-store-kit / src / vendor / js / jquery.slickmodal.js

jquery.slickmodal.js in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 3.1.0, at src/vendor/js/jquery.slickmodal.js

824 lines 32.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Slick Modals - HTML5 and CSS3 Powered Modal Popups
3 * ---------------------------------------------------
4 * @file Defines main jQuery plugin
5 * @author Capelle @ Codecanyon
6 * @copyright @author
7 * @version 5.0
8 * @url https://codecanyon.net/item/slick-modal-css3-powered-popups/12335988
9 */
10
11 (function ($) {
12 'use strict';
13
14 // Error checking
15 if (!$ || typeof $ === 'undefined') return _log('[Slick Modals] No jQuery library detected. Load SlickModals after jQuery has been loaded on the page.');
16
17 // Defaults
18 var _defaults = {
19
20 // Restrictions
21 restrict_hideOnUrls : [],
22 restrict_cookieSet : false,
23 restrict_cookieName : 'slickModal-1',
24 restrict_cookieScope : 'domain',
25 restrict_cookieDays : '30',
26 restrict_cookieSetClass : 'setSmCookie-1',
27 restrict_dateRange : false,
28 restrict_dateRangeStart : '',
29 restrict_dateRangeEnd : '',
30 restrict_dateRangeServerTime : true,
31 restrict_dateRangeServerTimeFile : '',
32 restrict_dateRangeServerTimeZone : 'Europe/London',
33 restrict_showAfterVisits : 1,
34 restrict_showAfterVisitsResetWhenShown: false,
35
36 // Popup
37 popup_type : 'none',
38 popup_delayedTime : '1s',
39 popup_scrollDistance : '400px',
40 popup_scrollHideOnUp : false,
41 popup_exitShowAlways : false,
42 popup_autoClose : false,
43 popup_autoCloseAfter : '5s',
44 popup_openWithHash : false,
45 popup_redirectOnClose : false,
46 popup_redirectOnCloseUrl : '',
47 popup_redirectOnCloseTarget : '_blank',
48 popup_redirectOnCloseTriggers : 'overlay button',
49 popup_position : 'center',
50 popup_animation : 'fadeIn',
51 popup_closeButtonEnable : true,
52 popup_closeButtonStyle : 'cancel simple',
53 popup_closeButtonAlign : 'right',
54 popup_closeButtonPlace : 'outside',
55 popup_closeButtonText : 'Close',
56 popup_reopenClass : 'open-sm',
57 popup_reopenClassTrigger : 'click',
58 popup_reopenStickyButtonEnable: false,
59 popup_reopenStickyButtonText : 'Open popup',
60 popup_enableESC : true,
61 popup_bodyClass : '',
62 popup_wrapperClass : '',
63 popup_draggableEnable : false,
64 popup_allowMultipleInstances : false,
65 popup_css : {
66 'width' : '480px',
67 'height' : 'auto',
68 'background' : '#fff',
69 'margin' : '24px',
70 'padding' : '24px',
71 'animation-duration': '0.4s'
72 },
73
74 // Overlay
75 overlay_isVisible : true,
76 overlay_closesPopup: true,
77 overlay_animation : 'fadeIn',
78 overlay_css : {
79 'background' : 'rgba(0, 0, 0, .8)',
80 'animation-duration': '0.4s',
81 'animation-delay' : '0s'
82 },
83
84 // Content
85 content_loadViaAjax: false,
86 content_animate : false,
87 content_animation : 'zoomIn',
88 content_css : {
89 'animation-duration': '0.4s',
90 'animation-delay' : '0.4s'
91 },
92
93 // Page
94 page_animate : false,
95 page_animation : 'scale',
96 page_animationDuration: '.4s',
97 page_blurRadius : '1px',
98 page_scaleValue : '.9',
99 page_moveDistance : '30%',
100
101 // Mobile
102 mobile_show : true,
103 mobile_breakpoint: '480px',
104 mobile_position : 'bottomCenter',
105 mobile_css : {
106 'width' : '100%',
107 'height' : 'auto',
108 'background' : '#fff',
109 'margin' : '0',
110 'padding' : '18px',
111 'animation-duration': '0.4s'
112 },
113
114 // Callbacks
115 callback_beforeInit : $.noop,
116 callback_afterInit : $.noop,
117 callback_beforeOpen : $.noop,
118 callback_afterOpen : $.noop,
119 callback_afterVisible: $.noop,
120 callback_beforeClose : $.noop,
121 callback_afterClose : $.noop,
122 callback_afterHidden : $.noop
123
124 };
125
126 // Constants
127 var _PLUGIN_NAME = 'SlickModals';
128 var _PREFIX = 'sm-';
129 var _LOG_START = '[Slick Modals] ';
130 var _LOG_END_1 = ' can be passed into this method.';
131
132 // Helpers
133 function _log(val) {
134 console.log(val);
135 }
136
137 // Main constructor
138 function SlickModals (element, config) {
139 this.$el = $(element);
140 this.$wrapper = '';
141 this.$overlay = '';
142 this.$popup = '';
143 this.settings = $.extend(true, {}, _defaults, config);
144
145 this.autoCloseTimer = null;
146 this.ajaxContentLoaded = 0;
147
148 this._build();
149 };
150
151 // Plugin methods
152 SlickModals.prototype = {
153 constructor: SlickModals,
154
155 // @private
156 _build: function () {
157
158 if (this.$el.attr('data-sm-init') !== 'true') {
159 this.$el.hide();
160 return _log(_LOG_START + 'Element is missing data-sm-init="true" attribute.');
161 }
162
163 this.settings.callback_beforeInit();
164 this._createParent();
165 if (this.settings.overlay_isVisible) this._createOverlay();
166 if (this.settings.popup_reopenStickyButtonEnable) this._createStickyButton();
167
168 this._createPopup();
169 if (this.settings.content_animate) this._contentAnimate();
170
171 this._createEvents();
172 this._checkInitRestrictions();
173 },
174 _createParent: function () {
175 this.$el.wrapAll('<div class="' + _PREFIX + 'wrapper"></div>');
176 this.$wrapper = this.$el.parent();
177
178 var type = this.settings.popup_type;
179 var typeVal = 0;
180
181 switch (true) {
182
183 case (type === 'delayed'):
184 typeVal = this.settings.popup_delayedTime;
185 break;
186
187 case (type === 'scrolled'):
188 typeVal = this.settings.popup_scrollDistance;
189 break;
190 }
191
192 this.$wrapper.attr({
193 'data-sm-type' : type,
194 'data-sm-type-val': typeVal
195 });
196
197 if (this.settings.popup_autoClose) {
198 this.$wrapper.attr({
199 'data-sm-autoClose' : 'enable',
200 'data-sm-autoClose-after': this.settings.popup_autoCloseAfter
201 });
202 }
203 },
204 _createOverlay: function () {
205 this.$wrapper.prepend('<div class="' + _PREFIX + 'overlay"></div>');
206 this.$overlay = this.$wrapper.children('.' + _PREFIX + 'overlay');
207
208 this.$overlay.attr({
209 'data-sm-animated': true,
210 'data-sm-close' : this.settings.overlay_closesPopup,
211 'data-sm-effect' : this.settings.overlay_animation
212 }).css(this.settings.overlay_css);
213 },
214 _createStickyButton: function () {
215 if (this.settings.popup_reopenClass === '') return _log(_LOG_START + 'Sticky button must have defined "popup_reopenClass" within the plugin settings.');
216 $('body').append('<div class="' + _PREFIX + 'sticky-button ' + this.settings.popup_reopenClass + '">' + this.settings.popup_reopenStickyButtonText + '</div>');
217 },
218 _createPopup: function () {
219 this.$el.attr('data-sm-init', 'false').wrapAll('<div class="' + _PREFIX + 'popup"></div>');
220 this.$popup = this.$wrapper.children('.' + _PREFIX + 'popup');
221
222 var isMobile = $(window).width() <= parseInt(this.settings.mobile_breakpoint);
223 var popupCss = null;
224
225 (isMobile) ? popupCss = this.settings.mobile_css : popupCss = this.settings.popup_css;
226 popupCss['animation-delay'] = ((this.settings.overlay_isVisible) ? parseFloat(this.settings.overlay_css['animation-duration']) / 2 : 0) + 's';
227
228 this.$popup
229 .attr({
230 'data-sm-animated': true,
231 'data-sm-position': (isMobile) ? this.settings.mobile_position : this.settings.popup_position,
232 'data-sm-effect' : this.settings.popup_animation
233 })
234 .css(popupCss)
235 .prepend(
236 (this.settings.popup_closeButtonEnable)
237 ?
238 '<div class="sm-button" '+
239 'data-sm-button-style="' + this.settings.popup_closeButtonStyle + '" ' +
240 'data-sm-button-align="' + this.settings.popup_closeButtonAlign + '" ' +
241 'data-sm-button-place="' + this.settings.popup_closeButtonPlace + '" ' +
242 'data-sm-button-text="' + this.settings.popup_closeButtonText + '" ' +
243 'data-sm-close="true"></div>'
244 : '',
245 (this.settings.popup_draggableEnable)
246 ?
247 '<div class="sm-draggable"></div>'
248 : ''
249 );
250
251 this._popupPositionCorrect();
252 },
253 _contentAnimate: function () {
254 this.$el.attr({
255 'data-sm-animated': true,
256 'data-sm-effect' : this.settings.content_animation
257 }).css(this.settings.content_css);
258 },
259 _checkInitRestrictions: function () {
260 var self = this;
261
262 function cookieExist () {
263 if (!self.settings.restrict_cookieSet) return false;
264 return document.cookie.indexOf(self.settings.restrict_cookieName) > -1;
265 }
266
267 function hiddenOnPage () {
268 if (!self.settings.restrict_hideOnUrls.length) return false;
269 var restrictedUrls = self.settings.restrict_hideOnUrls;
270
271 for (var i = 0; i < restrictedUrls.length; i++) {
272 var url = restrictedUrls[i];
273 var path = window.location.pathname;
274 if ((url instanceof RegExp && url.test(path)) ||
275 (typeof url === 'string' && path.indexOf(url) > -1)) {
276 return true;
277 }
278 }
279
280 return false;
281 }
282
283 function hideOnMobile () {
284 if (self.settings.mobile_show) return false;
285 return !self.settings.mobile_show && $(window).width() <= parseInt(self.settings.mobile_breakpoint);
286 }
287
288 function checkDateRange (callback) {
289
290 var compareDates = function (now) {
291 function formatDate (range) {
292 var date = new Date(range.split(',')[0] + 'T' + range.split(',')[1].replace(' ', '')).getTime();
293 if (isNaN(date)) return _log(_LOG_START + 'Invalid date format.');
294
295 return date;
296 }
297
298 var start = formatDate(self.settings.restrict_dateRangeStart);
299 var end = formatDate(self.settings.restrict_dateRangeEnd);
300
301 callback(!(now > start && now < end && start < end));
302 };
303
304 if (self.settings.restrict_dateRangeServerTime && self.settings.restrict_dateRangeServerTimeFile !== '') {
305 $.ajax({
306 url : self.settings.restrict_dateRangeServerTimeFile,
307 type : 'POST',
308 data : {'timezone': self.settings.restrict_dateRangeServerTimeZone},
309 dataType: 'json',
310 success : function (response) {
311 compareDates(new Date(response).getTime());
312 },
313 error : function () {
314 _log(_LOG_START + 'Ajax request error upon retrieving server time.')
315 }
316 });
317 } else {
318 compareDates(new Date().getTime());
319 }
320 }
321
322 function restrictedVisits () {
323 var visitsVal = parseInt(self.settings.restrict_showAfterVisits);
324 if (visitsVal <= 1) return false;
325 var keyName = _PREFIX + 'visits-' + self.$el.attr('class');
326
327 if (visitsVal > 1) {
328 var storageItem = localStorage.getItem(keyName);
329
330 if (storageItem !== null) {
331 if (parseInt(storageItem) === (visitsVal - 1)) {
332 if (self.settings.restrict_showAfterVisitsResetWhenShown) localStorage.removeItem(keyName);
333 return false;
334 } else {
335 localStorage.setItem(keyName, parseInt(storageItem) + 1);
336 return true;
337 }
338 } else {
339 localStorage.setItem(keyName, '1');
340 return true;
341 }
342
343 } else {
344 localStorage.removeItem(keyName);
345 }
346 }
347
348 function triggerOpen (hide) {
349 self.settings.callback_afterInit();
350 if (!hide) self.openPopup();
351 }
352
353 if (self.settings.restrict_dateRange) {
354 checkDateRange(function (outsideDateRange) {
355 triggerOpen(!!(cookieExist() || hiddenOnPage() || hideOnMobile() || self._activeInstanceExist() || restrictedVisits() || outsideDateRange));
356 });
357 } else {
358 triggerOpen(!!(cookieExist() || hiddenOnPage() || hideOnMobile() || self._activeInstanceExist() || restrictedVisits()));
359 }
360
361 },
362 _activeInstanceExist: function () {
363 if (!this.settings.popup_allowMultipleInstances && $('.' + _PREFIX + 'wrapper.' + _PREFIX + 'active').length > 0) {
364 _log(_LOG_START + 'Another Slick Modal instance is already active.');
365 return true;
366 }
367
368 return false;
369 },
370 _popupPositionCorrect: function () {
371 var position = this.$popup.attr('data-sm-position');
372
373 switch (true) {
374
375 case (position === 'center'):
376 this.$popup.css('margin', 'auto');
377 break;
378
379 case ((position === 'bottomCenter') || (position === 'topCenter')):
380 this.$popup.css({
381 'margin-left' : 'auto',
382 'margin-right': 'auto'
383 });
384 break;
385
386 case ((position === 'right') || (position === 'left')):
387 this.$popup.css({
388 'margin-top' : 'auto',
389 'margin-bottom': 'auto'
390 });
391 break;
392 }
393 },
394 _popupCalculateHeight: function () {
395 var innerElemsHeight = 0;
396 this.$popup.children().not('.sm-button').each(function () {
397 innerElemsHeight += $(this).outerHeight(true);
398 });
399
400 this.$popup.height(innerElemsHeight);
401 },
402 _createEvents: function () {
403 var self = this;
404
405 if (self.$wrapper.find('[data-sm-close="true"]').length > 0) {
406 self.$wrapper.find('[data-sm-close="true"]').each(function () {
407 var $this = $(this);
408 $this.on('click', function () {
409 self.closePopup();
410
411 if (self.settings.popup_redirectOnClose &&
412 self.settings.popup_redirectOnCloseTriggers.indexOf($this.attr('class').replace('sm-', '')) > -1 &&
413 self.settings.popup_redirectOnCloseTriggers.indexOf('close') === -1) {
414 self._redirectOnClose();
415 }
416 });
417 });
418 }
419
420 if (self.settings.popup_reopenClass !== '') {
421 $('body').on((self.settings.popup_reopenClassTrigger === 'click') ? 'click' : 'mouseover', '.' + self.settings.popup_reopenClass , function(e) {
422 if ($(e.target).is('a')) e.preventDefault();
423 self.openPopup('instant');
424 });
425 }
426
427 if (self.settings.popup_enableESC) {
428 $(window).on('keydown', function(e) {
429 if (e.keyCode === 27 && self._wrapperActive()) self.closePopup();
430 });
431 }
432
433 if (self.settings.popup_openWithHash) {
434 var userHash = self.settings.popup_openWithHash;
435 var hashValid = (userHash !== false && userHash !== '' && userHash.charAt(0) === '#');
436
437 if (hashValid) {
438 $(window).on('load hashchange', function() {
439 if (hashValid && userHash === window.location.hash) self.openPopup('instant');
440 });
441 }
442 }
443
444 if (this.settings.popup_draggableEnable) {
445 var dragging = dragging || false;
446 var $target = self.$popup;
447 var mrgTop = !isNaN(parseInt($target.css('margin-top'))) ? parseInt($target.css('margin-top')) : 0;
448 var mrgLeft = !isNaN(parseInt($target.css('margin-left'))) ? parseInt($target.css('margin-left')) : 0;
449 var mrgAuto = $target.css('margin') === 'auto';
450 var yPos, xPos, yOff, xOff;
451
452 var moveTarget = function (e) {
453 $target.css({
454 'top': e.clientY - yPos + yOff + 'px',
455 'left': e.clientX - xPos + xOff + 'px'
456 });
457 };
458
459 $target.children('.' + _PREFIX + 'draggable').on('mousedown', function (e) {
460 dragging = true;
461
462 yPos = e.clientY + mrgTop;
463 xPos = e.clientX + mrgLeft;
464 yOff = $target.offset().top;
465 xOff = $target.offset().left;
466
467 if (mrgAuto) {
468 $target.css('margin', '0px');
469 moveTarget(e);
470 mrgAuto = false;
471 }
472
473 $(window).on('mousemove', function (e) {
474 if (dragging) {
475 moveTarget(e);
476 return false;
477 }
478 });
479
480 $(window).on('mouseup', function () {
481 dragging = false;
482 });
483 });
484 }
485 },
486 _setCookie: function () {
487 var days = parseInt(this.settings.restrict_cookieDays);
488 var CookieDate = new Date();
489 var scopeSetting = '/';
490
491 if (this.settings.restrict_cookieScope === 'page') scopeSetting = window.location.href;
492
493 CookieDate.setTime(CookieDate.getTime() + (days * 24 * 60 * 60 * 1000));
494 document.cookie = this.settings.restrict_cookieName + '=1; path=' + scopeSetting + '; expires=' + ((days > 0) ? CookieDate.toGMTString() : 0);
495 },
496 _redirectOnClose: function () {
497 var redirectUrl = this.settings.popup_redirectOnCloseUrl;
498 if (redirectUrl !== '' && redirectUrl.indexOf('http') > -1) {
499 window.open(redirectUrl, this.settings.popup_redirectOnCloseTarget);
500 } else {
501 _log(_LOG_START + 'Redirect URL is empty or not valid.');
502 }
503 },
504 _loadContentViaAjax: function () {
505 if (!this.ajaxContentLoaded && this.settings.content_loadViaAjax !== '') {
506 var self = this;
507 $.ajax({
508 url : self.settings.content_loadViaAjax,
509 type : 'GET',
510 dataType: 'html',
511 success : function (response) {
512 self.$el.html(response);
513 self._popupCalculateHeight();
514 self.ajaxContentLoaded = 1;
515 },
516 error : function () {
517 _log(_LOG_START + 'Ajax request error upon retrieving the content.')
518 }
519 });
520 }
521 },
522 _pageAnimation: function (action) {
523
524 var pageAnimation = this.settings.page_animation;
525 var $bodyChildren = $('body').children().not('.' + _PREFIX + 'wrapper, .' + _PREFIX + 'sticky-button, script, style');
526
527 if (action === 'enable') {
528 switch (true) {
529
530 case (pageAnimation === 'blur'):
531 $bodyChildren
532 .css({
533 'filter' : 'blur(' + this.settings.page_blurRadius + ')',
534 'transition-duration': this.settings.page_animationDuration
535 });
536 break;
537
538 case (pageAnimation === 'scale'):
539 $bodyChildren
540 .css({
541 'transform' : 'scale(' + this.settings.page_scaleValue + ')',
542 'transition-duration': this.settings.page_animationDuration
543 });
544 break;
545
546 case (pageAnimation.indexOf('move') > -1):
547 var axis = '';
548 var sign = '';
549
550 switch (true) {
551 case (pageAnimation === 'moveUp'):
552 axis = 'Y';
553 sign = '-';
554 break;
555 case (pageAnimation === 'moveDown'):
556 axis = 'Y';
557 sign = '';
558 break;
559 case (pageAnimation === 'moveLeft'):
560 axis = 'X';
561 sign = '-';
562 break;
563 case (pageAnimation === 'moveRight'):
564 axis = 'X';
565 sign = '';
566 break;
567 }
568
569 $bodyChildren
570 .css({
571 'transform' : 'translate' + axis + '(' + sign + '' + this.settings.page_moveDistance + ')',
572 'transition-duration': this.settings.page_animationDuration
573 });
574 break;
575 }
576 $('body').addClass(_PREFIX + 'pageAnimated');
577 } else {
578 $bodyChildren.css({
579 'transform': '',
580 'filter' : ''
581 });
582 $('body').removeClass(_PREFIX + 'pageAnimated');
583 }
584 },
585 _wrapperActive: function () {
586 return this.$wrapper.hasClass(_PREFIX + 'active');
587 },
588 _prepareClose: function () {
589 var self = this;
590 var popupAnimationDuration = self.$popup.css('animation-duration');
591 var currentOverlayDelay = (self.settings.overlay_isVisible) ? self.$overlay.css('animation-delay') : 0;
592 var currentContentDelay = self.$el.css('animation-delay') || 0;
593 var currentPopupDelay = self.$popup.css('animation-delay') || 0;
594
595 if (self.settings.overlay_isVisible) self.$overlay.css('animation-delay', popupAnimationDuration);
596 if (self.settings.content_animate) self.$el.css('animation-delay', '0s');
597
598 self.$popup.css('animation-delay', '0s');
599 var finishTime = (((self.settings.overlay_isVisible) ? parseFloat(self.$overlay.css('animation-duration')) : 0) + parseFloat(popupAnimationDuration)) * 1000;
600
601 self._togglePopup('disable', finishTime, currentPopupDelay, currentOverlayDelay, currentContentDelay);
602 },
603 _togglePopup: function (action, timer, currentPopupDelay, currentOverlayDelay, currentContentDelay) {
604 var self = this;
605 var enable = action === 'enable';
606
607 if (enable) {
608 self.settings.callback_beforeOpen();
609 self.$wrapper.addClass(_PREFIX + 'active');
610 if (self.settings.popup_bodyClass !== '') $('body').addClass(self.settings.popup_bodyClass);
611 if (self.settings.popup_wrapperClass !== '') self.$wrapper.addClass(self.settings.popup_wrapperClass);
612 if (self.settings.content_loadViaAjax) self._loadContentViaAjax();
613
614 setTimeout (function () {
615 self.settings.callback_afterVisible();
616 if (self.$wrapper.attr('data-sm-autoClose') === 'enable') self.autoClose();
617 }, (parseFloat(self.$popup.css('animation-delay')) + parseFloat(self.$popup.css('animation-duration'))) * 1000 + timer);
618
619 } else {
620 self.settings.callback_afterClose();
621 self.$wrapper.removeClass(_PREFIX + 'active');
622 if (self.settings.page_animate) self._pageAnimation('disable');
623 }
624
625 setTimeout (function () {
626 if (enable) {
627 self.settings.callback_afterOpen();
628 self.$wrapper.show();
629 if (self.$popup[0].style.height === 'auto') self._popupCalculateHeight();
630 if (self.settings.page_animate) self._pageAnimation('enable');
631 } else {
632 if (self.settings.overlay_isVisible) self.$overlay.css('animation-delay', currentOverlayDelay);
633 if (self.settings.content_animate) self.$el.css('animation-delay', currentContentDelay);
634
635 self.$popup.css('animation-delay', currentPopupDelay);
636 self.$wrapper.hide();
637
638 self.settings.callback_afterHidden();
639 if (self.settings.popup_bodyClass !== '') $('body').removeClass(self.settings.popup_bodyClass);
640 if (self.settings.popup_wrapperClass !== '') self.$wrapper.removeClass(self.settings.popup_wrapperClass);
641 if (self.$wrapper.attr('data-sm-autoClose') === 'enable') clearTimeout(self.autoCloseTimer);
642 }
643
644 }, timer);
645 },
646 _typeController: function (t, v) {
647
648 var self = this;
649 var type = t || self.$wrapper.attr('data-sm-type');
650 var val = v || parseFloat(self.$wrapper.attr('data-sm-type-val'));
651
652 switch (true) {
653
654 case (type === 'delayed'):
655 self._togglePopup('enable', ((typeof val === 'string') ? parseFloat(val) : val) * 1000);
656 break;
657
658 case (type === 'scrolled'):
659 var opened = 0;
660 var closed = 0;
661 $(document).on('scroll', function() {
662 var scrollY = $(this).scrollTop();
663 if ((scrollY > val) && !opened) {
664 self._togglePopup('enable', 0);
665 opened = 1;
666 }
667 if (self.settings.popup_scrollHideOnUp && scrollY < val && opened && !closed) {
668 self.closePopup();
669 closed = 1;
670 $(document).unbind('scroll');
671 }
672 });
673 break;
674
675 case (type === 'exit'):
676 var stop = 0;
677 $(document).on('mouseleave', function () {
678 if (!stop) {
679 if (!self.settings.popup_exitShowAlways) {
680 stop = 1;
681 $(document).unbind('mouseleave');
682 }
683 self._togglePopup('enable', 0);
684 }
685 });
686 break;
687
688 case (type === 'instant'):
689 self._togglePopup('enable', 0);
690 break;
691 }
692
693 },
694
695 // @public
696 openPopup: function (type, val) {
697 if (this._wrapperActive()) return _log(_LOG_START + 'This popup instance is already active.');
698 if (this._activeInstanceExist()) return;
699
700 this._typeController(type, val);
701 },
702 closePopup: function () {
703 if (!this._wrapperActive()) return _log(_LOG_START + 'Popup is already closed.');
704
705 this.settings.callback_beforeClose();
706 this._prepareClose();
707 if (this.settings.restrict_cookieSet) this._setCookie();
708
709 if (this.settings.popup_redirectOnClose &&
710 this.settings.popup_redirectOnCloseTriggers.indexOf('close') > -1) {
711 this._redirectOnClose();
712 }
713 },
714 styleElement: function (scope, props) {
715 if (typeof props !== 'object') return _log(_LOG_START + 'Only object with CSS properties' + _LOG_END_1);
716
717 switch (true) {
718
719 case (scope === 'overlay' && this.settings.overlay_isVisible):
720 this.$overlay.css(props);
721 if (this.$popup.length > 0 && props['animation-duration']) {
722 this.$popup.css('animation-delay', parseFloat(props['animation-duration']) / 2 + 's');
723 }
724 break;
725
726 case ((scope === 'popup')):
727 this.$popup.css(props);
728 this._popupPositionCorrect();
729 break;
730
731 case (scope === 'content'):
732 this.$el.css(props);
733 break;
734 }
735 },
736 popupPosition: function (position) {
737 if (typeof position !== 'string') return _log(_LOG_START + 'Only string' + _LOG_END_1);
738
739 this.$popup.attr('data-sm-position', position);
740 this._popupPositionCorrect();
741 },
742 setEffect: function (scope, effect) {
743 if (typeof scope !== 'string' || typeof effect !== 'string') return _log(_LOG_START + 'Only strings' + _LOG_END_1);
744
745 switch (true) {
746
747 case (scope === 'overlay' && this.settings.overlay_isVisible):
748 this.$overlay.attr('data-sm-effect', effect);
749 break;
750
751 case (scope === 'popup'):
752 this.$popup.attr('data-sm-effect', effect);
753 break;
754
755 case (scope === 'content'):
756 this.$el.attr('data-sm-effect', effect);
757 break;
758 }
759 },
760 setType: function (type, val) {
761 this.$wrapper.attr({
762 'data-sm-type' : type,
763 'data-sm-type-val': val
764 });
765 },
766 autoClose: function (action, timer) {
767 var self = this;
768 self.$wrapper.attr({
769 'data-sm-autoClose' : action,
770 'data-sm-autoClose-after': timer
771 });
772
773 action = action || self.$wrapper.attr('data-sm-autoClose');
774 timer = timer || self.$wrapper.attr('data-sm-autoClose-after');
775
776 if (action === 'enable') {
777 self.autoCloseTimer = setTimeout(function () {
778 self.closePopup();
779 }, parseFloat(timer) * 1000);
780 }
781
782 },
783 destroy: function () {
784 $('.' + this.settings.popup_reopenClass).on((this.settings.popup_reopenClassTrigger === 'click') ? 'click' : 'mouseover', function () {
785 return false;
786 });
787
788 this.$el.remove();
789 this.$wrapper.remove();
790 this.$overlay.remove();
791 this.$popup.remove();
792
793 delete this.$el;
794 delete this.$wrapper;
795 delete this.$overlay;
796 delete this.$popup;
797 delete this;
798 }
799 };
800
801 // Plugin interface
802 $.fn[_PLUGIN_NAME] = function (config) {
803 var args = Array.prototype.slice.call(arguments, 1);
804
805 return this.each(function () {
806 var $el = $(this);
807 var instance = $el.data(_PLUGIN_NAME);
808
809 if (!instance) {
810 $el.data(_PLUGIN_NAME, new SlickModals(this, config));
811 } else {
812 if (typeof config === 'string') {
813 try {
814 instance[config].apply(instance, args);
815 } catch (e) {
816 _log(_LOG_START + 'Method does not exist in Slick Modals.');
817 }
818 }
819 }
820 });
821 }
822
823 }) (jQuery);
824