![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/aheadworks/module-csblock/view/frontend/web/js/ |
/** * Initialization widget to upload html content by Ajax * * @method ajax(placeholders) * @method replacePlaceholder(placeholder, html) */ define([ 'jquery' ], function($) { "use strict"; $.widget('mage.awCsblockAjax', { options: { url: '/', dataPattern: 'aw-csblock-block-name', bodyClass: 'aw-csblock' }, /** * Initialize widget */ _create: function () { var placeholders = $('[data-' + this.options.dataPattern + ']'); $('body').addClass(this.options.bodyClass); if (placeholders && placeholders.length) { this.ajax(placeholders); } }, /** * Send AJAX request * @param {Object} placeholders */ ajax: function (placeholders) { var self = this, data = { blocks: [] }; placeholders.each(function() { data.blocks.push($(this).data(self.options.dataPattern)); }); data.blocks = JSON.stringify(data.blocks.sort()); $.ajax({ url: this.options.url, data: data, type: 'post', cache: false, dataType: 'json', context: this, /** * Response handler * @param {Object} response */ success: function (response) { placeholders.each(function() { var placeholder = $(this), placeholderName = placeholder.data(self.options.dataPattern); if (response.hasOwnProperty(placeholderName)) { self.replacePlaceholder(placeholder, response[placeholderName]); } }); } }); }, /** * Replace placeholders * @param {Object} placeholder * @param {Object} html */ replacePlaceholder: function (placeholder, html) { if (!placeholder) { return; } var parent = $(placeholder).parent(); // Replace placeholder on html content placeholder.replaceWith(html); // Trigger event to use mage-data-init attribute $(parent).trigger('contentUpdated'); } }); return $.mage.awCsblockAjax; });