PluginProbe
Survey Maker by AYS / 5.2.2.0
Survey Maker by AYS v5.2.2.0
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.2.0, at public/js/survey-maker-public-popups.js

194 lines 8.0 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
37 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'popup-btn-close', function(e){
38 _this.$el.css('display', 'none');
39
40 var hidePopupAfterClick = typeof _this.dbOptions.hidePopupAfterClose != 'undefined' && _this.dbOptions.hidePopupAfterClose == 'on' ? true : false;
41 if(hidePopupAfterClick){
42 _this.setPopupCookie("ays_survey_popup_hide_after_click_close_"+_this.popupId+"", 1, 365);
43 }
44
45 if (document.fullscreenElement) {
46 _this.aysSurveyFullScreenWindowDeactivator();
47 }
48 });
49
50 _this.$el.on('click', 'input.' + _this.htmlClassPrefix + 'finish-button', function(){
51 var hidePopupAfterSubmit = typeof _this.dbOptions.hidePopup != 'undefined' && _this.dbOptions.hidePopup == 'on' ? true : false;
52 var closePopupAfterFinish = typeof _this.dbOptions.enable_popup_close_after_finish != 'undefined' && _this.dbOptions.enable_popup_close_after_finish ? true : false;
53
54 if(closePopupAfterFinish){
55 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;
56 _this.$el.attr('data-close-popup' , true);
57 _this.$el.attr('data-close-popup-delay' , closePopupAfterFinishDelay);
58 }
59
60 if( hidePopupAfterSubmit ){
61 var aysHasError = $(this).parents('.ays-survey-sections').find('.ays-has-error');
62 if(aysHasError.length == 0){
63 $.ajax({
64 url: aysSurveyMakerPopupsAjaxPublic.ajaxUrl,
65 method: 'post',
66 dataType: 'json',
67 data: {
68 action: _this.ajaxAction,
69 function: 'ays_survey_popup_set_cookie',
70 id: _this.popupId,
71 }
72 });
73 }
74 }
75 });
76
77 _this.$el.find('.ays-survey-popup-close-full-screen, .ays-survey-popup-open-full-screen').on('click', function() {
78 _this.toggleFullscreen(_this.el);
79 });
80
81 if(closeByEsc){
82 $(document).on('keydown', function(event) {
83 if (event.keyCode == 27) {
84 _this.$el.find('.' + _this.htmlClassPrefix + 'popup-btn-close').trigger('click');
85 }
86 });
87 }
88
89 _this.aysSurveyFullScreenDeactivateAll();
90
91 }
92
93 AysSurveyPopupsPlugin.prototype.toggleFullscreen = function (elem) {
94 var _this = this;
95 elem = elem || document.documentElement;
96 if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
97 _this.aysSurveyFullScreenActivate( elem );
98 _this.aysSurveyFullScreenWindowActivator( elem );
99 }else{
100 _this.aysSurveyFullScreenDeactivate( elem );
101 _this.aysSurveyFullScreenWindowDeactivator();
102 }
103 }
104
105 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenActivate = function (elem) {
106 $(elem).find('.ays-survey-popup-full-screen-mode .ays-survey-popup-close-full-screen').css({'display':'inline'});
107 $(elem).find('.ays-survey-popup-full-screen-mode .ays-survey-popup-open-full-screen').css('display','none');
108 $(elem).find('.ays-survey-popup-full-screen-mode').css({'padding-right':'25px'});
109 $(elem).find('.ays-survey-popup-btn-close').css({'top':'0','right' : '0'});
110 $(elem).css({'overflow':'auto'});
111 }
112
113 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenDeactivate = function (elem) {
114 $(elem).find('.ays-survey-popup-full-screen-mode .ays-survey-popup-open-full-screen').css({'display':'inline'});
115 $(elem).find('.ays-survey-popup-full-screen-mode .ays-survey-popup-close-full-screen').css('display','none');
116 $(elem).find('.ays-survey-popup-full-screen-mode').css({'padding-right':'0'});
117 $(elem).find('.ays-survey-popup-btn-close').css({'top':'-16px','right' : '-16px'});
118 $(elem).css({'overflow':'initial'});
119 }
120
121 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenDeactivateAll = function (elem) {
122 var _this = this;
123 document.addEventListener('fullscreenchange', function(event) {
124 if (!document.fullscreenElement) {
125 var eventTarget = event.target;
126 if( $( eventTarget ).hasClass('ays-survey-popup-survey-window') ){
127 _this.aysSurveyFullScreenDeactivate( eventTarget );
128 }
129 }
130 }, false);
131 }
132
133 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenWindowActivator = function (elem) {
134 if (elem.requestFullscreen) {
135 elem.requestFullscreen();
136 }else if (elem.msRequestFullscreen) {
137 elem.msRequestFullscreen();
138 }else if (elem.mozRequestFullScreen) {
139 elem.mozRequestFullScreen();
140 }else if (elem.webkitRequestFullscreen) {
141 elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
142 }
143 }
144
145 AysSurveyPopupsPlugin.prototype.aysSurveyFullScreenWindowDeactivator = function () {
146 if(document.exitFullscreen) {
147 document.exitFullscreen();
148 }else if (document.msExitFullscreen) {
149 document.msExitFullscreen();
150 }else if (document.mozCancelFullScreen) {
151 document.mozCancelFullScreen();
152 }else if (document.webkitExitFullscreen) {
153 document.webkitExitFullscreen();
154 }
155 }
156
157 AysSurveyPopupsPlugin.prototype.popupSelectorClick = function (elem, _this) {
158 var popupTriggerType = _this.dbOptions.popup_trigger;
159 var popupSelector = _this.dbOptions.popup_selector;
160
161 if(popupTriggerType == 'on_click'){
162
163 $(document).find(popupSelector).on('click', function(){
164
165 elem.css('display','block');
166
167 });
168 }
169 }
170
171 AysSurveyPopupsPlugin.prototype.setPopupCookie = function (name, value, daysToExpire) {
172 var date = new Date();
173 date.setTime(date.getTime() + (daysToExpire * 24 * 60 * 60 * 1000));
174 var expires = "expires=" + date.toUTCString();
175 document.cookie = name + "=" + value + "; " + expires + "; path=/";
176 }
177
178 $.fn.AysSurveyMakerPopups = function(options) {
179 return this.each(function() {
180 if (!$.data(this, 'AysSurveyMakerPopups')) {
181 $.data(this, 'AysSurveyMakerPopups', new AysSurveyPopupsPlugin(this, options));
182 } else {
183 try {
184 $(this).data('AysSurveyMakerPopups').init();
185 } catch (err) {
186 console.error('AysSurveyMakerPopups has not initiated properly');
187 }
188 }
189 });
190 };
191
192 $(document).find('.ays-survey-popup-survey-window').AysSurveyMakerPopups();
193 })(jQuery);
194