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