PluginProbe ʕ •ᴥ•ʔ
Flex Import / 2.5
Flex Import v2.5
2.9 trunk 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
flex-import / assets / js / admin-script.js
flex-import / assets / js Last commit date
admin-script.js 10 months ago dashboard-posts.js 10 months ago front-script.js 10 months ago jquery.notify.min.js 10 months ago license_script.js 10 months ago plugin-admin.js 10 months ago template-admin.js 10 months ago
admin-script.js
369 lines
1 jQuery(document).ready(function ($) {
2 document.getElementById('flex-cancel-import').addEventListener('click', function () {
3 document.getElementById('import-modal').style.display = 'none';
4 });
5
6 document.getElementById('import-modal').addEventListener('click', function (event) {
7 if (event.target === this) {
8 this.style.display = 'none';
9 }
10 });
11 });
12
13 // for required plugins
14 jQuery(document).ready(function ($) {
15 // Plugin installation logic
16 $('#fleximp-install-plugins').on('click', function () {
17 this.disabled = true;
18 this.innerText = 'Installing...';
19
20 // Fetch plugins again for installation
21 $.ajax({
22 url: fleximp_admin_ajax_object.ajax_url,
23 method: 'POST',
24 data: {
25 action: 'fleximp_get_required_plugins',
26 _ajax_nonce: fleximp_admin_ajax_object.fleximp_nonce
27 },
28 success: function (response) {
29 if (response.success) {
30 const plugins = response.data;
31 installPlugin(plugins, 0);
32 } else {
33 const errorMessage = response.data ? response.data : 'An unexpected error occurred while fetching plugins.';
34 alert(errorMessage);
35 }
36 },
37 error: function () {
38 alert('An error occurred while fetching the plugins.');
39 }
40 });
41
42 function installPlugin(plugins, index) {
43 if (index >= plugins.length) {
44 $('#fleximp-install-plugins').text('All plugins installed successfully.');
45 return;
46 }
47
48 const plugin = plugins[index];
49 const statusElement = $(`#plugin-status-${plugin.slug}`);
50 statusElement.html('<span class="spinner is-active"></span> Installing...');
51
52 $.ajax({
53 url: fleximp_admin_ajax_object.ajax_url,
54 method: 'POST',
55 data: {
56 action: 'fleximp_install_single_plugin',
57 plugin_slug: plugin.slug,
58 _ajax_nonce: fleximp_admin_ajax_object.fleximp_nonce
59 },
60 success: function (response) {
61 const statusElement = $(`#plugin-status-${plugin.slug}`);
62
63 if (typeof response === 'string') {
64 const jsonResponseMatch = response.match(/(\{.*\})$/);
65
66 if (jsonResponseMatch) {
67 try {
68 const jsonResponse = JSON.parse(jsonResponseMatch[0]);
69
70 if (jsonResponse.success) {
71 statusElement.html('<span class="dashicons dashicons-yes"></span> ' + (jsonResponse.data.message || 'success.'));
72 } else {
73 const errorMessage = jsonResponse.data.message || 'fail.';
74 statusElement.html(`<span class="dashicons dashicons-no-alt"></span> ${errorMessage}`);
75 }
76 } catch (e) {
77 statusElement.html('<span class="dashicons dashicons-no-alt"></span> Fail.');
78 }
79 } else {
80 statusElement.html('<span class="dashicons dashicons-no-alt"></span> Fail.');
81 }
82 } else if (typeof response === 'object' && response !== null) {
83 if (response.success) {
84 statusElement.html('<span class="dashicons dashicons-yes"></span> ' + (response.data.message || 'success.'));
85 } else {
86 const errorMessage = response.data.message || 'An unknown error occurred during installation.';
87 statusElement.html(`<span class="dashicons dashicons-no-alt"></span> ${errorMessage}`);
88 }
89 } else {
90 statusElement.html('<span class="dashicons dashicons-no-alt"></span> Fail.');
91 }
92
93 installPlugin(plugins, index + 1); // Proceed to the next plugin
94 },
95
96
97 error: function () {
98 const statusElement = $(`#plugin-status-${plugin.slug}`);
99 statusElement.html('<span class="dashicons dashicons-no-alt"></span> Installation failed.');
100 installPlugin(plugins, index + 1); // Continue with the next plugin
101 }
102 });
103 }
104 });
105 });
106
107
108
109 jQuery(document).ready(function ($) {
110 // Existing functionality (already working)
111 $(document).on('click', '.download-btn', function (e) {
112 e.preventDefault();
113
114 const $button = $(this);
115 const pluginSlug = $button.data('plugin-url').split('/').pop().replace('.latest-stable.zip', '');
116 const pluginName = $button.data('plugin-name');
117 const pluginMainFile = $button.data('plugin-main-file');
118
119 $button.text('Installing...').prop('disabled', true);
120
121 // AJAX call to install the plugin
122 $.ajax({
123 url: fleximp_admin_ajax_object.ajax_url,
124 type: 'POST',
125 dataType: 'json',
126 data: {
127 action: 'fleximp_install_plugin',
128 security: fleximp_admin_ajax_object.fleximp_nonce,
129 plugin_slug: pluginSlug,
130 plugin_name: pluginName,
131 plugin_main_file: pluginMainFile,
132 },
133 success: function (response) {
134 const $status = $(`#plugin-status-${pluginSlug}`);
135 if (response.success) {
136 // Disable the button and set its text to 'Activated'
137 $button.text('Activated').addClass('activated').prop('disabled', true);
138 // Update the status column text for the installed plugin
139 $status.text('Activated');
140 } else {
141 alert(response.data.message || 'Failed to install the plugin.');
142 $button.text('Install/Activate').prop('disabled', false);
143 $status.text('Failed to install');
144 }
145 },
146 error: function () {
147 $button.text('Activated').addClass('activated').prop('disabled', true);
148 const $status = $(`#plugin-status-${pluginSlug}`);
149 $status.text('');
150
151 },
152 });
153 });
154
155 $('#install-all-btn').on('click', function () {
156 const selectedPlugins = [];
157
158 $('.plugin-checkbox:checked').each(function () {
159 const $checkbox = $(this);
160 selectedPlugins.push({
161 pluginSlug: $checkbox.data('plugin-url').split('/').pop().replace('.latest-stable.zip', ''),
162 pluginName: $checkbox.data('plugin-name'),
163 pluginMainFile: $checkbox.data('plugin-main-file')
164 });
165 });
166
167 if (selectedPlugins.length === 0) {
168 alert('Please select at least one plugin to install.');
169 return;
170 }
171
172 installPluginsInSequence(selectedPlugins);
173
174 $('#install-all-btn').text('Installing All...').prop('disabled', true);
175
176 $('#install-all-btn').text('Install All Selected').prop('disabled', false);
177 });
178
179
180 // Function to install plugins sequentially
181 function installPluginsInSequence(plugins) {
182 // if (plugins.length === 0) return;
183
184 if (plugins.length === 0) {
185 $('#install-all-btn').text('Install All Selected').prop('disabled', false);
186 return;
187 }
188
189 const currentPlugin = plugins.shift();
190 const $status = $(`#plugin-status-${currentPlugin.pluginSlug}`);
191 //new const $button = $(`.download-btn[data-plugin-url*="${currentPlugin.pluginSlug}"]`);
192 const $button = $(`.download-btn[data-plugin-url*="${currentPlugin.pluginSlug}"]`);
193
194 $status.text('Installing...');
195
196 //new
197 $button.text('Installing...').prop('disabled', true);
198
199 fetch(fleximp_admin_ajax_object.ajax_url, {
200 method: 'POST',
201 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
202 body: `action=fleximp_install_plugin&security=${fleximp_admin_ajax_object.fleximp_nonce}&plugin_slug=${currentPlugin.pluginSlug}&plugin_name=${currentPlugin.pluginName}&plugin_main_file=${currentPlugin.pluginMainFile}`
203 })
204 .then(response => {
205 // Check if the response is JSON
206 const contentType = response.headers.get('content-type');
207 if (contentType && contentType.includes('application/json')) {
208 return response.json();
209 } else {
210 return response.text(); // Handle plain text responses
211 }
212 })
213 .then(data => {
214 if (typeof data === 'object' && data.success) {
215 $status.text('Activated');
216 $button.text('Activated').addClass('activated').prop('disabled', true);
217
218 } else if (typeof data === 'string') {
219 console.log('Plugin installation message:', data);
220 $status.text('Check console for details'); // Optional for plain text
221 $button.text('Activated').addClass('activated').prop('disabled', true);
222 } else {
223 $status.text('Failed to install/activate');
224 }
225 installPluginsInSequence(plugins); // Continue with the next plugin
226 })
227 .catch(error => {
228 console.error('Error installing plugin:', error);
229 $status.text('Error occurred');
230 installPluginsInSequence(plugins); // Continue with the next plugin
231 });
232 }
233 });
234
235 // code for metafield in theme
236
237 jQuery(document).ready(function ($) {
238 var mediaUploader;
239 $('.custom_media_button').click(function (e) {
240 e.preventDefault();
241 if (mediaUploader) {
242 mediaUploader.open();
243 return;
244 }
245 mediaUploader = wp.media.frames.file_frame = wp.media({
246 title: 'Select Image',
247 button: { text: 'Use this image' },
248 multiple: false
249 });
250 mediaUploader.on('select', function () {
251 var attachment = mediaUploader.state().get('selection').first().toJSON();
252 $('#service_category_image').val(attachment.id);
253 $('#service_category_image_preview').html('<img src="' + attachment.url + '" style="max-width:100px;" />');
254 });
255 mediaUploader.open();
256 });
257 });
258
259
260 jQuery(document).ready(function ($) {
261 var mediaUploader;
262 $('.custom_media_button').click(function (e) {
263 e.preventDefault();
264 if (mediaUploader) {
265 mediaUploader.open();
266 return;
267 }
268 mediaUploader = wp.media.frames.file_frame = wp.media({
269 title: 'Select Image',
270 button: { text: 'Use this image' },
271 multiple: false
272 });
273 mediaUploader.on('select', function () {
274 var attachment = mediaUploader.state().get('selection').first().toJSON();
275 $('#service_category_image').val(attachment.id);
276 $('#service_category_image_preview').html('<img src="' + attachment.url + '" style="max-width:100px;" />');
277 });
278 mediaUploader.open();
279 });
280 });
281
282
283
284 // new added for dashboard post
285
286 jQuery(document).ready(function ($) {
287 var swiper = new Swiper('.swiper-container-2', {
288 loop: true,
289 slidesPerView: 3,
290 spaceBetween: 30,
291 slidesPerGroup: 1,
292 navigation: {
293 nextEl: '.swiper-button-next',
294 prevEl: '.swiper-button-prev'
295 },
296 breakpoints: {
297 0: {
298 slidesPerView: 4,
299 spaceBetween: 20
300 },
301 768: {
302 slidesPerView: 3,
303 spaceBetween: 25
304 },
305 1024: {
306 slidesPerView: 3,
307 spaceBetween: 30
308 }
309 }
310 });
311
312 $('.swiper-container-2').on('click', '.video-slide:not(.swiper-slide-duplicate) .play-icon', function (e) {
313 e.stopPropagation();
314
315 var $slide = $(this).closest('.video-slide');
316 var videoUrl = $slide.attr('data-video');
317
318 // Stop and remove all existing videos
319 $('.video-container').empty().css('position', 'static');
320 $('.video-slide').removeClass('video-playing')
321 .find('.video-overlay').show()
322 .end().find('.thumbnail-image').show();
323
324 let embedElement;
325
326 if (videoUrl.includes('youtube.com') || videoUrl.includes('youtu.be')) {
327 let youtubeId = '';
328 if (videoUrl.includes('youtu.be')) {
329 youtubeId = videoUrl.split('youtu.be/')[1];
330 } else {
331 const params = new URLSearchParams(videoUrl.split('?')[1]);
332 youtubeId = params.get('v');
333 }
334
335 embedElement = $('<div class="video-iframe-wrapper"></div>').append(
336 $('<iframe>', {
337 src: `https://www.youtube.com/embed/${youtubeId}?autoplay=1&mute=1`,
338 frameborder: 0,
339 allow: 'autoplay; encrypted-media',
340 allowfullscreen: true
341 }).css({
342 width: '100%',
343 height: '100%',
344 borderRadius: '10px'
345 })
346 );
347 } else {
348 embedElement = $('<video />', {
349 src: videoUrl,
350 controls: true,
351 autoplay: true,
352 muted: true,
353 playsinline: true
354 }).css({
355 width: '100%',
356 height: '250px',
357 borderRadius: '10px',
358 objectFit: 'cover'
359 });
360 }
361 $slide.addClass('video-playing');
362 const $container = $slide.find('.video-container');
363 $container.css('position', 'absolute').html(embedElement);
364 });
365 });
366
367 // end
368
369