PluginProbe
Survey Maker by AYS / 5.2.3.4
Survey Maker by AYS v5.2.3.4
5.2.4.1 5.2.4.0 5.2.3.9 5.2.3.8 5.2.3.7 5.2.3.6 5.2.3.5 5.2.3.4 5.2.3.3 5.2.3.2 5.2.3.1 5.2.3.0 5.2.2.9 5.2.2.8 5.2.2.7 5.2.2.6 5.2.2.5 5.2.2.4 5.2.2.3 5.2.2.2 5.2.2.1 5.2.2.0 5.2.1.9 5.2.1.8 5.2.0.8 All 154 releases
survey-maker / public / js / survey-maker-public-popups.js

survey-maker-public-popups.js in Survey Maker by AYS 5.2.3.4, at public/js/survey-maker-public-popups.js

209 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2 'use strict';
3
4 function AysSurveyPopupsPlugin(element, options){
5 this.el = element;
6 this.$el = $(element);
7 this.htmlClassPrefix = 'ays-survey-';
8 this.ajaxAction = 'ays_survey_ajax';
9 this.dbOptions = undefined;
10 this.popupId = undefined;
11 this.confirmBeforeUnload = false;
12
13 this.init();
14
15 return this;
16 }
17
18 AysSurveyPopupsPlugin.prototype.init = function() {
19 var _this = this;
20
21 _this.popupId = _this.$el.data('id');
22
23 if( typeof window.aysSurveyPopupsOptions != 'undefined' ){
24 _this.dbOptions = JSON.parse( atob( window.aysSurveyPopupsOptions[ _this.popupId ] ) );
25 }
26
27 _this.setEvents();
28 };
29
30 AysSurveyPopupsPlugin.prototype.setEvents = function(e){
31 var _this = this;
32
33 _this.popupSelectorClick( _this.$el, _this);
34
35 var closeByEsc = typeof _this.dbOptions.popupEnableCloseByEsc != 'undefined' && _this.dbOptions.popupEnableCloseByEsc == 'on' ? true : false;
36 var closePopupOverlayOutsideClick = typeof _this.dbOptions.closePopupOverlayOutsideClick != 'undefined' && _this.dbOptions.closePopupOverlayOutsideClick == 'on' ? true : false;
37
38 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'popup-btn-close', function(e){
39 _this.$el.css('display', 'none');
40
41 var hidePopupAfterClick = typeof _this.dbOptions.hidePopupAfterClose != 'undefined' && _this.dbOptions.hidePopupAfterClose == 'on' ? true : false;
42 if(hidePopupAfterClick){
43 _this.setPopupCookie("ays_survey_popup_hide_after_click_close_"+_this.popupId+"", 1, 365);
44 }
45
46 if (document.fullscreenElement) {
47 _this.aysSurveyFullScreenWindowDeactivator();
48 }
49 });
50
51 _this.$el.on('click', 'input.' + _this.htmlClassPrefix + 'finish-button', function(){
52 var hidePopupAfterSubmit = typeof _this.dbOptions.hidePopup != 'undefined' && _this.dbOptions.hidePopup == 'on' ? true : false;
53 var closePopupAfterFinish = typeof _this.dbOptions.enable_popup_close_after_finish != 'undefined' && _this.dbOptions.enable_popup_close_after_finish ? true : false;
54
55 if(closePopupAfterFinish){
56 var closePopupAfterFinishDelay = typeof _this.dbOptions.popup_close_after_finish_delay != 'undefined' && _this.dbOptions.popup_close_after_finish_delay != '' ? _this.dbOptions.popup_close_after_finish_delay : 0;
57 _this.$el.attr('data-close-popup' , true);
58 _this.$el.attr('data-close-popup-delay' , closePopupAfterFinishDelay);
59 }
60
61 if( hidePopupAfterSubmit ){
62 var aysHasError = $(this).parents('.ays-survey-sections').find('.ays-has-error');
63 if(aysHasError.length == 0){
64 $.ajax({
65 url: aysSurveyMakerPopupsAjaxPublic.ajaxUrl,
66 method: 'post',
67 dataType: 'json',
68 data: {
69 action: _this.ajaxAction,
70 function: 'ays_survey_popup_set_cookie',
71 _ajax_nonce: aysSurveyMakerPopupsAjaxPublic.ajaxNonce,
72 id: _this.popupId,
73 }
74 });
75 }
76 }
77 });
78
79 _this.$el.find('.ays-survey-popup-close-full-screen, .ays-survey-popup-open-full-screen').on('click', function() {
80 _this.toggleFullscreen(_this.el);
81 });
82
83 if(closeByEsc){
84 $(document).on('keydown', function(event) {
85 if (event.keyCode == 27) {
86 _this.$el.find('.' + _this.htmlClassPrefix + 'popup-btn-close').trigger('click');
87 }
88 });
89 }
90
91 if(closePopupOverlayOutsideClick){
92 var return_false = 0;
93 $(document).on('click', function(e) {
94 if(return_false == 0){
95 var target = e.target;
96 if(!$(target).hasClass(_this.htmlClassPrefix + 'popup-survey-window') && $(target).parents('.' + _this.htmlClassPrefix + 'popup-survey-window').length == 0){
97 _this.$el.find('.' + _this.htmlClassPrefix + 'popup-btn-close').trigger('click');
98 return_false = 1;
99 }
100 }
101 });
102 }
103
104 _this.aysSurveyFullScreenDeactivateAll();
105
106 }
107
108 AysSurveyPopupsPlugin.prototype.toggleFullscreen = function (elem) {
109 var _this = this;
110 elem = elem || document.documentElement;
111 if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
112 _this.aysSurveyFullScreenActivate( elem );
113 _this.aysSurveyFullScreenWindowActivator( elem );
114 }else{
115 _this.aysSurveyFullScreenDeactivate( elem );
116 _this.aysSurveyFullScreenWindowDeactivator();
117 }
118 }
119
120 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenActivate = function (elem) {
121 $(elem).find('.ays-survey-popup-full-screen-mode .ays-survey-popup-close-full-screen').css({'display':'inline'});
122 $(elem).find('.ays-survey-popup-full-screen-mode .ays-survey-popup-open-full-screen').css('display','none');
123 $(elem).find('.ays-survey-popup-full-screen-mode').css({'padding-right':'25px'});
124 $(elem).find('.ays-survey-popup-btn-close').css({'top':'0','right' : '0'});
125 $(elem).css({'overflow':'auto'});
126 }
127
128 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenDeactivate = function (elem) {
129 $(elem).find('.ays-survey-popup-full-screen-mode .ays-survey-popup-open-full-screen').css({'display':'inline'});
130 $(elem).find('.ays-survey-popup-full-screen-mode .ays-survey-popup-close-full-screen').css('display','none');
131 $(elem).find('.ays-survey-popup-full-screen-mode').css({'padding-right':'0'});
132 $(elem).find('.ays-survey-popup-btn-close').css({'top':'-16px','right' : '-16px'});
133 $(elem).css({'overflow':'initial'});
134 }
135
136 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenDeactivateAll = function (elem) {
137 var _this = this;
138 document.addEventListener('fullscreenchange', function(event) {
139 if (!document.fullscreenElement) {
140 var eventTarget = event.target;
141 if( $( eventTarget ).hasClass('ays-survey-popup-survey-window') ){
142 _this.aysSurveyFullScreenDeactivate( eventTarget );
143 }
144 }
145 }, false);
146 }
147
148 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenWindowActivator = function (elem) {
149 if (elem.requestFullscreen) {
150 elem.requestFullscreen();
151 }else if (elem.msRequestFullscreen) {
152 elem.msRequestFullscreen();
153 }else if (elem.mozRequestFullScreen) {
154 elem.mozRequestFullScreen();
155 }else if (elem.webkitRequestFullscreen) {
156 elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
157 }
158 }
159
160 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenWindowDeactivator = function () {
161 if(document.exitFullscreen) {
162 document.exitFullscreen();
163 }else if (document.msExitFullscreen) {
164 document.msExitFullscreen();
165 }else if (document.mozCancelFullScreen) {
166 document.mozCancelFullScreen();
167 }else if (document.webkitExitFullscreen) {
168 document.webkitExitFullscreen();
169 }
170 }
171
172 AysSurveyPopupsPlugin.prototype.popupSelectorClick = function (elem, _this) {
173 var popupTriggerType = _this.dbOptions.popup_trigger;
174 var popupSelector = _this.dbOptions.popup_selector;
175
176 if(popupTriggerType == 'on_click'){
177
178 $(document).find(popupSelector).on('click', function(){
179
180 elem.css('display','block');
181
182 });
183 }
184 }
185
186 AysSurveyPopupsPlugin.prototype.setPopupCookie = function (name, value, daysToExpire) {
187 var date = new Date();
188 date.setTime(date.getTime() + (daysToExpire * 24 * 60 * 60 * 1000));
189 var expires = "expires=" + date.toUTCString();
190 document.cookie = name + "=" + value + "; " + expires + "; path=/";
191 }
192
193 $.fn.AysSurveyMakerPopups = function(options) {
194 return this.each(function() {
195 if (!$.data(this, 'AysSurveyMakerPopups')) {
196 $.data(this, 'AysSurveyMakerPopups', new AysSurveyPopupsPlugin(this, options));
197 } else {
198 try {
199 $(this).data('AysSurveyMakerPopups').init();
200 } catch (err) {
201 console.error('AysSurveyMakerPopups has not initiated properly');
202 }
203 }
204 });
205 };
206
207 $(document).find('.ays-survey-popup-survey-window').AysSurveyMakerPopups();
208 })(jQuery);
209