PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / resources / scripts / admin / index.js

index.js in Depicter — Popup & Slider Builder trunk, at resources/scripts/admin/index.js

191 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // eslint-disable-next-line no-unused-vars
2 // import config from '@config';
3 // import '@styles/admin';
4 // Uncomment the following line if needed:
5 // import 'airbnb-browser-shims';
6
7 // Your code goes here ...
8
9 // enable submit and deactivate button while clicking on survey list items
10 (function ($) {
11
12 var publishSliderButtonFunc = function (view = false) {
13 $('.depicter-publish-slider:not([disabled])').off('click');
14 $('.depicter-publish-slider:not([disabled])').on('click', function () {
15 var $this = $(this);
16 $this.find('.btn-label').hide();
17 $this.find('.depicter-state-icon').show();
18 var sliderID = $this.data('document-id') || $this.parents('tbody,#elementor-controls').find('select').val().replace( '#', '');
19 var data = {
20 action: 'depicter-document-store',
21 ID: sliderID,
22 status: 'published'
23 };
24
25 $.ajax({
26 url: depicterParams.ajaxUrl,
27 type: 'POST',
28 data: data,
29 headers: {
30 'X-DEPICTER-CSRF': depicterParams.token
31 }
32 }).done(function (response) {
33 if (response.hits) {
34 $this.attr('disabled', true);
35 $this.parents('.depicter-notice-btns').siblings('.depicter-notice-txts').hide();
36 $this.find('.btn-label').html(depicterParams.publishedText);
37 $this.find('.btn-label').show();
38 $this.find('.depicter-state-icon').hide();
39 if (view) {
40 view.$el.find('.depicter-notice-wrapper').remove();
41 } else {
42 $('.fl-module-module').find('.depicter-notice-wrapper').remove();
43 }
44 } else {
45 $this.find('.btn-label').show();
46 $this.find('.depicter-state-icon').hide();
47 }
48 });
49
50 });
51 }
52
53 var editSliderButtonFunc = function () {
54 $('.depicter-edit-slider').off('click');
55 $('.depicter-edit-slider').on('click', function () {
56 var sliderID = $(this).data('document-id') || $(this).parents('tbody, #elementor-controls').find('select').val().replace('#', '');
57 var editorUrl = depicterParams.editorUrl.replace( 'document=1', 'document=' + sliderID );
58 window.open( editorUrl );
59 });
60 }
61
62 $(document).ready(function () {
63
64 var $feedbackContainer = $('.depicter-survey-container');
65 // show the popup survey
66 $('#deactivate-depicter').on('click', function (e) {
67 e.preventDefault();
68 $feedbackContainer.addClass('show');
69 });
70
71 // close the popup survey
72 $feedbackContainer.on('click', function(e) {
73 if ((!$(e.target).parents('.depicter-survey-list').length && !$(e.target).is('.depicter-survey-list')) || $(e.target).is('.depicter-close')) {
74 $feedbackContainer.removeClass('show');
75 }
76 });
77
78 // enable submit button if one reason clicked
79 $feedbackContainer.find('input[name="dep_deactivation_reason"]').each(function () {
80 $(this).on('click', function () {
81 $feedbackContainer.find('.depicter-submit').attr('disabled', false);
82 });
83 });
84
85 var ajaxDeactivationRequest = function (reason, userDescriptionText) {
86 $.ajax({
87 url: depDeactivationParams.ajaxUrl,
88 method: 'POST',
89 data: {
90 _wpnonce: $feedbackContainer.find('#_wpnonce').val(),
91 action: 'depicter-deactivate-feedback',
92 issueRelatesTo: reason,
93 userDescription: userDescriptionText,
94 },
95 }).done(function (res) {
96 location.href = $('#deactivate-depicter').attr('href');
97 });
98 };
99
100 // send deactivation feedback
101 $feedbackContainer.find('.depicter-submit').on('click', function () {
102 var $selectedRadioInput = $feedbackContainer.find('input[name="dep_deactivation_reason"]:checked'),
103 reason = $selectedRadioInput.val(),
104 userDescriptionText = $selectedRadioInput.parent('div').find('input[type="text"').length ? $selectedRadioInput.parent('div').find('input[type="text"').val() : '';
105 ajaxDeactivationRequest(reason, userDescriptionText);
106 $(this).parent('.depicter-button-wrapper').addClass('loading');
107 });
108
109 // deactivate plugin if click on skip
110 $feedbackContainer.find('.depicter-skip').on('click', function() {
111 ajaxDeactivationRequest('skip', '');
112 $(this).parent('.depicter-button-wrapper').addClass('loading skipped');
113 location.href = $('#deactivate-depicter').attr('href');
114 });
115
116 // ─── Beaver Builder Js ───────────────────────────────────────────
117
118 var beaverBuilderControls = function () {
119 var $tbody = $('.fl-field-control-wrapper select[name="document_id"]').parents('tbody');
120
121 $tbody.find(' > tr:not(#fl-field-document_id)').hide();
122 var sliderID = $('.fl-field-control-wrapper select[name="document_id"]').val();
123 if (sliderID) {
124 $('#fl-field-slider_control_buttons_' + sliderID.replace( '#', '')).show();
125 }
126
127 editSliderButtonFunc();
128
129 publishSliderButtonFunc();
130 }
131
132 if (typeof FLBuilder != 'undefined') {
133 $('body').on('fl-builder.settings-form-init', function () {
134 $('.fl-field-control-wrapper select[name="document_id"]').on('change', function () {
135 beaverBuilderControls();
136 });
137 beaverBuilderControls();
138 });
139 }
140
141 if (typeof CtBuilderAjax != 'undefined') {
142 $('#oxygen-sidebar-control-panel-basic-styles').bind('DOMSubtreeModified', function(){
143 if ( $(this).find('.depicter-edit-slider').length ) {
144 editSliderButtonFunc();
145 publishSliderButtonFunc();
146 }
147 });
148 }
149
150 // ─── Depicter Settings Page ───────────────────────────────────────────
151
152 $('.depicter-flush-cache').on('click', function (e) {
153 e.preventDefault();
154
155 var $button = $(this);
156 var $icon = $button.find('span.dashicons');
157 $button.removeClass('success');
158 $button.addClass('loading');
159
160 var data = {
161 action: 'depicter-document-flush-cache'
162 };
163
164 $.ajax({
165 url: depicterParams.ajaxUrl,
166 type: 'POST',
167 data: data,
168 headers: {
169 'X-DEPICTER-CSRF': depicterParams.token
170 }
171 }).done(function (response) {
172 $button.removeClass('loading');
173 if (response.success) {
174 $button.addClass('success');
175 } else {
176 console.log( response.errors[0] )
177 }
178 });
179 });
180
181 });
182
183 if ( window.elementor ) {
184 elementor.hooks.addAction( 'panel/open_editor/widget', function( panel, model, view ) {
185 editSliderButtonFunc();
186 publishSliderButtonFunc(view);
187 });
188 }
189
190 })(jQuery);
191