(function ($) { "use strict"; var $window = $(window); var $body = $('body'); var $document = $(document); var $$ = $; var $dialog_body = $body; var $dialog_document = $document; var $dialog_window = $window; var dialog_window = window; window.azh = $.extend({}, window.azh); azh.parse_query_string = function (a) { if (a == "") { return {}; } var b = {}; for (var i = 0; i < a.length; ++i) { var p = a[i].split('='); if (p.length != 2) { continue; } b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); } return b; }; azh.elements_cache = {}; $.QueryString = azh.parse_query_string(window.location.search.substr(1).split('&')); $.fn.azhSerializeObject = function () { var serializedArray = this.serializeArray(), data = {}; var parseObject = function (dataContainer, key, value) { var isArrayKey = /^[^\[\]]+\[]/.test(key), isObjectKey = /^[^\[\]]+\[[^\[\]]+]/.test(key), keyName = key.replace(/\[.*/, ''); if (isArrayKey) { if (!dataContainer[ keyName ]) { dataContainer[ keyName ] = []; } } else { if (!isObjectKey) { if (dataContainer.push) { dataContainer.push(value); } else { dataContainer[ keyName ] = value; } return; } if (!dataContainer[ keyName ]) { dataContainer[ keyName ] = {}; } } var nextKeys = key.match(/\[[^\[\]]*]/g); nextKeys[ 0 ] = nextKeys[ 0 ].replace(/\[|]/g, ''); return parseObject(dataContainer[ keyName ], nextKeys.join(''), value); }; $.each(serializedArray, function () { parseObject(data, this.name, this.value); }); return data; }; var no_image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAB8lBMVEUAAABcXFxmZmZnZ2eZmZmampqrq6uwsLC9vb2+vr7AwMDBwcHCwsLExMTFxcXGxsbJycnS0tLT09PZ2dna2trb29vd3d3f39/g4ODl5eXp6enq6urr6+vw8PDy8vLz8/P19fX4+Pj6+vr9/f3////V1dX////////S0tLT09PT09PU1NTAwMDCwsLCwsLOzs7h4eHi4uLk5OTl5eXm5ubPz8/a2trb29ve3t6+vr7R0dHQ0NDU1NTS0tLT09PU1NTDw8PAwMDBwcHR0dHR0dHU1NSoqKjS0tLR0dHS0tLT09POzs7Pz8/Q0NDOzs7Pz8/Ozs7Pz8/Q0NDOzs7Pz8+oqKioqKjPz8+mpqanp6fOzs7Pz8/Q0NDOzs7Pz8+jo6Ojo6OioqLR0dHS0tKjo6PNzc3Ozs6hoaHOzs7Ozs6ioqLNzc3Nzc3Nzc3Nzc3Nzc3Nzc3MzMzNzc2goKDNzc2goKDNzc3Ozs7Nzc3Nzc3Nzc2enp6fn5/Nzc3MzMzNzc3Nzc2enp6enp6enp7Nzc3Nzc3Nzc2dnZ2enp6cnJycnJzMzMzMzMzMzMzNzc3MzMzNzc3Nzc2dnZ2bm5ucnJzNzc3Nzc2bm5ucnJycnJzMzMzMzMzMzMzMzMzMzMzMzMyamprMzMyYmJiZmZmamprMzMyJ6HxFAAAAonRSTlMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgIDBgYLCwwMDQ4ODg4ODg8PDw8RFBUVFhYWGhsbGxwcJiYnJyc2NjY3Nzg4OTo6P0BAQkJGRkxOTlVWV1dXWFpaXmJjcHd4eXt9foODhYWGhoaeoKGoqKiqqquwsbKyubq7u8HCxs3Oz9DQ0dTh4u3v8PDy9Pb4+fr7/f5KuRpkAAAEXUlEQVR4Ae2Z6VcUVxDFr1kUYaKORjQuiQpxXDRmiUlQY3DBRaMCmowLjLssw4IiKigusqhxj9EkgCwN9X/mve4+3V1Mk65uOPOpf2c+zXnn3HNfvXqvqhp5JSYmJiYm5nMoKqprLl6sqa6w/5hZPgWOtPW/I4d3/W1H9N8zyZl75MO9M5ghvsDa1gGagoHWtWrBDHCTXN6+6uvt7Xv1llxuYrosxJVhsnjf3XAIDvvru9+TxfAVtWw6bHhKFl1VwGx4mA8c7SSLpxswDdJjpBlpKkUxcigGspbPsTQi8hmyZHID/8M1Msmq5RFYjFukebETqzAly7HjGWluYXEUH3dJ0xIU1YVoJs3dKF5MH0MnIKDK9hIaOx61kLB30IpLSNKkkaoUbDdV0ghDcuOY3ivSZEQqe8yTvDGJEJg5eLxW7gWVZlYiBJetc4WM3It1xi5DymroPH4JRRgvz/U9htUQcoMUvyShyIhVktvc20FAihTXYVEr37GrpEhBRqu+E7GGqdSi9O9xzm8fg2Pucitk6HewCTZu9FNvuMifvgk8AAmLTpMCGu5lsorx+0fggBSnF0HAff1GwUvGo2Lo31RW9Ct2HxJIUbkENhPjf6Wc6Kdun98FlJ99wCxNwGbpYVIgmJJj+j0HXJHxNyk3XwqLgWVzUfbYtmMYrohCv/vHShBIm1rXzUSUipv7J9s76rYggUZT48k33z7xinSrRW0Ipl+ta5jjFWFe1uvo92yehUYdne8SRV8brsiCBrWmH8HoWvQgc+J6cc7Y6L4P8EiJfF/4yU8eERzQFaww7mAizEvGVtlUVKa364cf//BuF2SRr9B1IhcxuQOeLz3Aw9zAQ9eWFQiiWq167SNyKQGe+1vnneNH2OS1WlCNIGrUqr5cEWP3ilPrmJe6leVGrkgfEdUgiAtqVa+PE6CdR78D8HHSS0QXpiHSwaPfLhcRb1f5yjqWL+tOrdgt3y5h4M/N28pzH4lLwsDLj/BDoIfnPu5wEX6Ewyejpqxo02hu7mvEycivlQM+Io/w4b7R3NznIgf1tSK8IOsX5IoYjZi12dyx9Z584SJz2AUZ7qq3aUQCW+o62k/y3A+46mWPloPxuAxzlwHFhWBeJj1av5YIr+HDS5mIw4Oz5cCu87dZ9B2RJZWkgLSQ6IS/iF1I8Oi7TrpYISEviSb8+ecrd8f+jVASYUDSNX3pU/M3mcWdvEwdhgBe86/BiKBMZQX3VQjgNf91ScHNW4dtSQTBav7kz7x1EDVBzxFyx17yJkjWzjVDgBv9Ft7OSRvTyjBejvPGVNxi054CuZch3mLLhwWD2wvEXjTpSGOPwb0IoZKNOMChKgg4MRR+gMNGUc3Bo6iWSKMoNlR7tgPLMSWrsPNF1KEaGw9eC7gdBONBwaBzOAv/QWdp04hg0Cke2XYeBebDw2ygqks8spUPn+v3w+FQAx8+52uMnv8PAvn/tJH/jzT5/9wkJyYmJiYm5j/qBxqDoN+AlgAAAABJRU5ErkJggg=='; function open_alert(title, desc, callback, ok_callback) { var $modal = $('
'); if (title) { $('
' + title + '
').appendTo($modal); } if (desc) { $('
' + desc + '
').appendTo($modal); } var $actions = $('
').appendTo($modal); $('
' + azh.i18n.ok + '
').appendTo($actions).on('click', function () { $.simplemodal.close(); if (ok_callback) { ok_callback(); } return false; }); $modal.simplemodal({ autoResize: true, overlayClose: true, opacity: 0, overlayCss: { "background-color": "black" }, closeClass: "azh-close", onClose: function () { $.simplemodal.close(); if (callback) { callback(); } } }); } function open_simple_modal(options, value, callback, cancel) { var $modal = $('
'); $('
' + options['title'] + '
').appendTo($modal); $('
' + options['desc'] + '
').appendTo($modal); $('
' + options['label'] + '
').appendTo($modal); if ('options' in options) { var $select = $('').appendTo($modal).on('change', function () { value = $(this).find('option:selected').attr('value'); }); for (var v in options['options']) { if (v === value) { $('').appendTo($select); } else { $('').appendTo($select); } } $select.trigger('change'); } else { $('').appendTo($modal).on('change', function () { value = $(this).val(); }); } var $actions = $('
').appendTo($modal); $('
' + azh.i18n.ok + '
').appendTo($actions).on('click', function () { $.simplemodal.close(); setTimeout(function () { callback(value); }, 0); return false; }); if (cancel) { $('
' + azh.i18n.cancel + '
').appendTo($actions).on('click', function () { $.simplemodal.close(); return false; }); } $modal.simplemodal({ autoResize: true, overlayClose: true, opacity: 0, overlayCss: { "background-color": "black" }, closeClass: "azh-close", onClose: function () { $.simplemodal.close(); } }); } function builder_init() { function library_show() { if (azh.default_category) { var $categories_select = $('#azexo-html-library .azh-library-filters .azh-categories'); if ($categories_select.find('[value="' + azh.default_category + '"]').length) { $categories_select.val(azh.default_category).trigger('change'); if (!$('#azexo-html-library .azh-panel.azh-builder').is('.azh-empty')) { $('#azexo-html-library .azh-section-operations .azh-add-section:first-child').trigger('click'); } $('#azexo-html-library').addClass('azh-hover'); } } } function open_utility_panel() { azh.set_minimum_device_left(azh.panel_width + azh.toolbar_width); $('.azh-section-controls.azh-active .azh-utility-wrapper .azh-utility, .azh-column-controls.azh-active .azh-utility-wrapper .azh-utility, .azh-element-controls.azh-active .azh-utility-wrapper .azh-utility').css('display', ''); $('.azh-section-controls.azh-active, .azh-column-controls.azh-active, .azh-element-controls.azh-active').css('display', ''); $('.azh-section-controls.azh-active .azh-utility-wrapper .azh-utility, .azh-column-controls.azh-active .azh-utility-wrapper .azh-utility, .azh-element-controls.azh-active .azh-utility-wrapper .azh-utility').animate({ left: azh.toolbar_width + 'px' }); $('.azh-elements-hierarchy').show(); $('.azh-elements-hierarchy').animate({ left: azh.toolbar_width + 'px' }); $('.azh-utility-panel').animate({ width: (azh.panel_width + azh.toolbar_width) + 'px' }); } function close_utility_panel() { azh.set_minimum_device_left(azh.toolbar_width); $('.azh-section-controls.azh-active .azh-utility-wrapper .azh-utility, .azh-column-controls.azh-active .azh-utility-wrapper .azh-utility, .azh-element-controls.azh-active .azh-utility-wrapper .azh-utility').animate({ left: (azh.toolbar_width - azh.panel_width) + 'px' }, 400, function () { $('.azh-section-controls.azh-active .azh-utility-wrapper .azh-utility, .azh-column-controls.azh-active .azh-utility-wrapper .azh-utility, .azh-element-controls.azh-active .azh-utility-wrapper .azh-utility').hide(); $('.azh-section-controls.azh-active, .azh-column-controls.azh-active, .azh-element-controls.azh-active').css('display', 'none'); }); $('.azh-elements-hierarchy').animate({ left: (azh.toolbar_width - azh.panel_width) + 'px' }, 400, function () { $('.azh-elements-hierarchy').hide(); }); $('.azh-utility-panel').animate({ width: azh.toolbar_width + 'px' }); } azh.prepare(); azh.customizer_init(); azh.window.on("azh-customization-after-init", function (event, data) { function check_tooltip(tutorial) { if (!(tutorial in azh.tutorials) || !azh.tutorials[tutorial]) { var tooltip = true; open_alert(azh.i18n[tutorial + '_title'], azh.i18n[tutorial + '_desc'], function(){ tooltip = false; }, function(){ azh.tutorials[tutorial] = 1; $.post(azh.ajaxurl + '?action=set_tutorial_status', { tutorial: tutorial, status: 1 }, function (data) { }); }); } } var $wrapper = data.wrapper; azh.shopify_init($wrapper); var tooltip = false; if(!window.azexo_tutorial) { if(!tooltip && $wrapper.find('.az-no-utility .az-icon-element').length) { check_tooltip('icon_right_mouse'); } if(!tooltip && $wrapper.find('.az-no-utility .az-image').length) { check_tooltip('image_right_mouse'); } // if(!tooltip && $wrapper.find('.az-no-utility .az-hyperlink').length) { // var tooltip = true; // check_tooltip('link_right_mouse'); // } if(!tooltip && $wrapper.find('[data-cloneable] > .az-pack').length) { check_tooltip('clone_right_mouse'); } if(!tooltip && $wrapper.find('.az-slide.az-pack').length) { check_tooltip('slide_right_mouse'); } } }); azh.document.on('mousemove mouseup mousedown', function (event, data) { event.clientX = event.clientX + (azh.device_left ? azh.device_left : 0); event.pageX = event.pageX + (azh.device_left ? azh.device_left : 0); event.pageY = event.pageY - azh.window.scrollTop(); $document.trigger(event, data); }); azh.document.on('click', function (event, data) { window.parent.jQuery(window.parent.document).trigger(event, data); }); $('html').css('background', 'darkgray'); if ($('.azh-devices').length === 0) { var $devices = $('
').appendTo('#azexo-html-library'); for (var prefix in azh.device_prefixes) { $('
').appendTo($devices); } $devices.children().first().addClass('azh-active'); $devices.find('[data-prefix]').on('click', function () { $devices.find('.azh-active').removeClass('azh-active'); $(this).addClass('azh-active'); azh.set_device_width($(this).data('prefix')); }); } azh.minimum_device_left = 0; azh.set_minimum_device_left = function (left) { azh.minimum_device_left = left; azh.set_device_width(azh.device_prefix); }; azh.set_device_width = function (prefix) { if (azh.post_frontend_frame) { var $controls_container = $('.azh-controls-container'); if (prefix === 'lg') { azh.$('[name="viewport"]').attr('content', 'width=device-width,initial-scale=1'); var left = 0; if (left < azh.minimum_device_left) { left = azh.minimum_device_left; } azh.device_left = left; var width = $body.prop("clientWidth") - left; azh.post_frontend_frame.css({ transform: 'none' }); azh.post_frontend_frame.animate({ left: left + 'px', width: width + 'px', height: '100%' }, function () { $window.trigger('azh-set-device-width'); }); $controls_container.animate({ left: left + 'px', width: width + 'px' }); } else { azh.$('[name="viewport"]').attr('content', 'width=' + azh.device_prefixes[prefix].width + (azh.device_prefixes[prefix].height ? ',height=' + azh.device_prefixes[prefix].height : '') + ',initial-scale=1'); var left = $body.prop("clientWidth") / 2 - azh.device_prefixes[prefix].width / 2; var width = azh.device_prefixes[prefix].width; if (left < azh.minimum_device_left) { left = azh.minimum_device_left; } azh.device_left = left; azh.post_frontend_frame.css({ transform: 'none' }); azh.post_frontend_frame.animate({ left: left + 'px', width: (width + 1) + 'px', height: '100%' }, function () { $window.trigger('azh-set-device-width'); }); $controls_container.animate({ left: left + 'px', width: width + 'px' }); } azh.$('body').removeClass(Object.keys(azh.device_prefixes).map(function (item) { return 'azh-' + item }).join(' ')).addClass('azh-' + prefix); } $('.azh-controls-container > .azh-active .azh-responsive [data-prefix="' + prefix + '"]').trigger('click'); $('.azh-context-menu .azh-responsive [data-prefix="' + prefix + '"]').trigger('click'); $('.azh-context-menu').off('azh-showed').on('azh-showed', function () { $(this).find('.azh-responsive [data-prefix="' + prefix + '"]').trigger('click'); }); azh.device_prefix = prefix; }; azh.toolbar_width = 45; azh.panel_width = 300; azh.hierarhy_height = 300; azh.utility_top = 0; azh.utility_left = 45; $document.off('azh-show-utility').on('azh-show-utility', function (event, data) { $('.azh-section-controls:not(.azh-active) .azh-utility-wrapper .azh-utility, .azh-column-controls:not(.azh-active) .azh-utility-wrapper .azh-utility, .azh-element-controls:not(.azh-active) .azh-utility-wrapper .azh-utility').hide(); $('.azh-controls-container').off('mouseup.azh-show-utility').on('mouseup.azh-show-utility', function () { $('.azh-section-controls:not(.azh-active) .azh-utility-wrapper .azh-utility, .azh-column-controls:not(.azh-active) .azh-utility-wrapper .azh-utility, .azh-element-controls:not(.azh-active) .azh-utility-wrapper .azh-utility').hide(); }); $(event.target).css({ top: '0', width: azh.panel_width + 'px', height: 'calc(100vh - ' + azh.hierarhy_height + 'px)', left: azh.toolbar_width + 'px' }); $('.azh-elements-hierarchy').css({ top: 'auto', bottom: '0px', height: azh.hierarhy_height + 'px', width: azh.panel_width + 'px', left: azh.toolbar_width + 'px' }); if (data.which) { if ($('.azh-utility-panel').data('closed')) { $('.azh-utility-panel').data('closed', false); open_utility_panel(); } $(event.target).show(); } else { if ($('.azh-utility-panel').data('closed')) { $(event.target).hide(); } else { $(event.target).show(); } } $('#azexo-html-library').removeClass('azh-hover'); }); if ($('.azh-utility-panel').length === 0) { $('
').appendTo($body).on('click', function () { var $this = $(this); if ($this.data('closed')) { $this.data('closed', false); open_utility_panel(); } else { $this.data('closed', true); close_utility_panel(); } $('.azh-section-controls:not(.azh-active) .azh-utility-wrapper .azh-utility, .azh-column-controls:not(.azh-active) .azh-utility-wrapper .azh-utility, .azh-element-controls:not(.azh-active) .azh-utility-wrapper .azh-utility').hide(); return false; }).css({ top: '0', bottom: '0', width: (azh.panel_width + azh.toolbar_width) + 'px', left: '0' }).show(); } setTimeout(function () { azh.set_minimum_device_left(azh.panel_width + azh.toolbar_width); }); if (!('builder' in azh.tutorials) || !azh.tutorials['builder']) { window.azexo_tutorial = 'builder'; window.azexo_tutorial_proceed(); } else { library_show(); } window.azexo_tutorial_complete = function () { $.post(azh.ajaxurl + '?action=set_tutorial_status', { tutorial: window.azexo_tutorial, status: 1 }, function (data) { }); if(window.azexo_tutorial === 'builder') { library_show(); } window.azexo_tutorial = false; }; } function get_full_width() { var full_width = azh.body.prop("clientWidth"); if ($window.get(0) != azh.window.get(0)) { full_width = azh.window.prop("innerWidth"); } return full_width; } function post_frontend_frame_init() { function check_storefront_password_failed_attempts() { var d = new Date(); var d = d.getTime() / 1000 - 10 * 60; var n = 0; azh.storefront_password_attempts.forEach(function (t, i) { if (t > d) { n++; } }); return n > 3; } if (check_storefront_password_failed_attempts()) { open_alert(azh.i18n.storefront_password, azh.i18n.too_many_failed_attempts + '
' + azh.i18n.where_to_get_storefront_password, function(){ post_frontend_frame_init(); }); return; } $body = $('body'); azh.post_frontend_frame = $('').appendTo($body); azh.post_frontend_frame.css({ 'border': '0', 'position': 'fixed', 'left': '0', 'top': '0', 'z-index': '0', 'height': '100%', 'width': '100%', 'transform-origin': 'left top' }); $body.css({ 'overflow': 'hidden', 'background-color': 'transparent' }); azh.post_frontend_frame.show(); var win = azh.post_frontend_frame.get(0).contentWindow; var doc = azh.post_frontend_frame.get(0).contentDocument || azh.post_edit_frame.get(0).contentWindow.document; win.addEventListener("DOMContentLoaded", function () { var win = azh.post_frontend_frame.get(0).contentWindow; var doc = azh.post_frontend_frame.get(0).contentDocument || azh.post_edit_frame.get(0).contentWindow.document; if (doc.body.getAttribute('data-azexo-status') === 'wrong-password') { azh.post_frontend_frame.remove(); open_simple_modal({ title: azh.i18n.storefront_password, desc: azh.i18n.where_to_get_storefront_password, label: azh.i18n.password }, '', function (password) { $.post(azh.ajaxurl + '?action=save_storefront_password', { password: password }, function (data) { azh.storefront_password_attempts = JSON.parse(data); if (check_storefront_password_failed_attempts()) { open_alert(azh.i18n.storefront_password, azh.i18n.too_many_failed_attempts + '
' + azh.i18n.where_to_get_storefront_password, function(){ post_frontend_frame_init(); }); } else { post_frontend_frame_init(); } }); }); return; } var query_string = azh.parse_query_string(win.location.search.substr(1).split('&')); azh.$ = azh.post_frontend_frame.get(0).contentWindow.jQuery; if ('azh' in azh.post_frontend_frame.get(0).contentWindow && '$' in azh.post_frontend_frame.get(0).contentWindow.azh) { azh.$ = azh.post_frontend_frame.get(0).contentWindow.azh.$; } azh.body = azh.post_frontend_frame.contents().find('body'); azh.window = azh.$(azh.post_frontend_frame.get(0).contentWindow); azh.document = azh.$(azh.post_frontend_frame.get(0).contentDocument || azh.post_frontend_frame.get(0).contentWindow.document); if ('mode' in $.QueryString && $.QueryString['mode'] === 'sections' && azh.post_id.indexOf('sections/') !== 0 && !('section' in $.QueryString)) { azh.body.find('a[href]').on('click', function (event) { event.preventDefault(); }); azh.controls_container = false; if ($('.azh-controls-container').length) { azh.controls_container = $('.azh-controls-container'); azh.controls_container.detach(); } else { azh.controls_container = $('
'); } azh.controls_container.find('.shopify-page-selection').remove(); var $page_selection = $('
').appendTo(azh.controls_container); var $paths_dropdown = false; var $pages_dropdown = $('').appendTo($page_selection).on('change', function (event, data) { function create_select(type, path) { $paths_dropdown = $('').appendTo($page_selection); $paths_dropdown.select2({ placeholder: azh.i18n.select_page, ajax: { url: azh.ajaxurl + '?action=links-dropdown&type=' + type, dataType: 'json' }, width: '100%' }); if (path) { $$.post(azh.ajaxurl + '?action=links-dropdown&type=' + type, { 'values': [path] }, function (data) { for (var v in data) { $$('').appendTo($paths_dropdown); } }, 'json'); } $paths_dropdown.on('change', function () { $('#azexo-html-library .azh-library-actions .azh-live').attr('href', win.location.protocol + '//' + $.QueryString['shop'] + $paths_dropdown.val()); azh.edit_post_frontend_link = win.location.origin + win.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent($paths_dropdown.val()); azh.post_frontend_frame.remove(); azh.controls_container.empty(); post_frontend_frame_init(); }); } var front_path = $(this).val(); $page_selection.children().not($pages_dropdown).remove(); $paths_dropdown = false; switch (front_path) { case '/pages/': create_select('pages', (data ? data.path : false)); break; case '/products/': create_select('products', (data ? data.path : false)); break; case '/collections/': create_select('collections', (data ? data.path : false)); break; case (front_path.match(/^\/blogs\/[\w\d\-\_]+\//) ? front_path.match(/^\/blogs\/[\w\d\-\_]+\//)[0] : ''): for (var blog_id in azh.blogs) { if (front_path === '/blogs/' + azh.blogs[blog_id].handle + '/') { create_select('articles', (data ? data.path : false)); break; } } break; default: $('#azexo-html-library .azh-library-actions .azh-live').attr('href', win.location.protocol + '//' + $.QueryString['shop'] + front_path); azh.edit_post_frontend_link = win.location.origin + win.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent(front_path); azh.post_frontend_frame.remove(); azh.controls_container.empty(); post_frontend_frame_init(); break; } if (data) { switch (front_path) { case '/pages/': case '/products/': case '/collections/': case (front_path.match(/^\/blogs\/[\w\d\-\_]+\//) ? front_path.match(/^\/blogs\/[\w\d\-\_]+\//)[0] : ''): $('
' + azh.i18n.add_azexo_section + '
').appendTo($page_selection).on('click', function () { azh.controls_container.empty(); $.post(azh.ajaxurl + '?action=add_section', { sid: win.azexo_handle_id, }, function (data) { setTimeout(function () { azh.post_frontend_frame.remove(); window.location.href = window.location.origin + window.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent($paths_dropdown ? $paths_dropdown.val() : $pages_dropdown.val()); }, 500); }); }); $('
' + azh.i18n.empty_original_template + '
').appendTo($page_selection).on('click', function () { azh.controls_container.empty(); $.post(azh.ajaxurl + '?action=switch_template', { sid: win.azexo_handle_id, path: $paths_dropdown ? $paths_dropdown.val() : $pages_dropdown.val() }, function (data) { setTimeout(function () { azh.post_frontend_frame.remove(); window.location.href = window.location.origin + window.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent($paths_dropdown ? $paths_dropdown.val() : $pages_dropdown.val()); }, 2000); }); }); break; } } }); $('').appendTo($pages_dropdown); $('').appendTo($pages_dropdown); $('').appendTo($pages_dropdown); $('').appendTo($pages_dropdown); for (var blog_id in azh.blogs) { $('').appendTo($pages_dropdown); } $('').appendTo($pages_dropdown); $('').appendTo($pages_dropdown); $('').appendTo($pages_dropdown); $('').appendTo($pages_dropdown); $('').appendTo($pages_dropdown); $('').appendTo($pages_dropdown); $('').appendTo($pages_dropdown); switch (query_string['front_path']) { case (query_string['front_path'].match(/^\/pages\/[\w\d\-\_]+/) ? query_string['front_path'].match(/^\/pages\/[\w\d\-\_]+/)[0] : ''): $pages_dropdown.val('/pages/').trigger('change', {path: query_string['front_path']}); break; case (query_string['front_path'].match(/^\/products\/[\w\d\-\_]+/) ? query_string['front_path'].match(/^\/products\/[\w\d\-\_]+/)[0] : ''): $pages_dropdown.val('/products/').trigger('change', {path: query_string['front_path']}); break; case (query_string['front_path'].match(/^\/collections\/[\w\d\-\_]+/) ? query_string['front_path'].match(/^\/collections\/[\w\d\-\_]+/)[0] : ''): $pages_dropdown.val('/collections/').trigger('change', {path: query_string['front_path']}); break; case (query_string['front_path'].match(/^\/blogs\/[\w\d\-\_]+\/[\w\d\-\_]+/) ? query_string['front_path'].match(/^(\/blogs\/[\w\d\-\_]+\/)[\w\d\-\_]+/)[0] : ''): $pages_dropdown.val(query_string['front_path'].match(/^(\/blogs\/[\w\d\-\_]+\/)[\w\d\-\_]+/)[1]).trigger('change', {path: query_string['front_path']}); break; default: $pages_dropdown.val(query_string['front_path']); break; } azh.controls_container.find('.shopify-section-controls').remove(); azh.body.find('[data-azexo-section]').each(function () { var $wrapper = azh.$(this); var match = $wrapper.data('azexo-section').match(/sections\/(azexo-[\d]+)\.liquid/); var $section_controls = $('
').appendTo(azh.controls_container).on('mouseenter', function () { $wrapper.addClass('shopify-hover'); }).on('mouseleave', function () { $wrapper.removeClass('shopify-hover'); }); $section_controls.data('shopify-section', $wrapper); $section_controls.css('right', (get_full_width() - $wrapper.offset().left - $wrapper.outerWidth()) + 'px'); $section_controls.css('top', $wrapper.offset().top + 'px'); $('
' + (match ? azh.i18n.edit_section : azh.i18n.override_and_edit) + '
').appendTo($section_controls).on('click', function () { azh.post_id = $wrapper.data('azexo-section'); azh.edit_post_frontend_link = win.location.origin + win.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent($paths_dropdown ? $paths_dropdown.val() : $pages_dropdown.val()) + '§ion=' + azh.post_id; azh.post_frontend_frame.remove(); azh.controls_container.empty(); post_frontend_frame_init(); }); if (match) { $('
' + azh.i18n.delete_section + '
').appendTo($section_controls).on('click', function () { azh.controls_container.empty(); $.post(azh.ajaxurl + '?action=delete_section', { sid: win.azexo_handle_id, section_id: match[1] }, function (data) { azh.post_frontend_frame.remove(); window.location.href = window.location.origin + window.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent($paths_dropdown ? $paths_dropdown.val() : $pages_dropdown.val()); }); }); $('
').appendTo($section_controls).on('click', function () { azh.controls_container.empty(); $.post(azh.ajaxurl + '?action=section_up', { sid: win.azexo_handle_id, section_id: match[1] }, function (data) { azh.post_frontend_frame.remove(); window.location.href = window.location.origin + window.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent($paths_dropdown ? $paths_dropdown.val() : $pages_dropdown.val()); }); }); $('
').appendTo($section_controls).on('click', function () { azh.controls_container.empty(); $.post(azh.ajaxurl + '?action=section_down', { sid: win.azexo_handle_id, section_id: match[1] }, function (data) { azh.post_frontend_frame.remove(); window.location.href = window.location.origin + window.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent($paths_dropdown ? $paths_dropdown.val() : $pages_dropdown.val()); }); }); } else { $('
' + azh.i18n.revert_to_original + '
').appendTo($section_controls).on('click', function () { azh.post_frontend_frame.remove(); azh.controls_container.empty(); $.post(azh.ajaxurl + '?action=revert_original', { key: $wrapper.data('azexo-section') }, function (data) { window.location.href = window.location.origin + window.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent($paths_dropdown ? $paths_dropdown.val() : $pages_dropdown.val()); }); }); } }); azh.window.off('scroll.shopify-section-controls').on('scroll.shopify-section-controls', _.throttle(function () { azh.controls_container.find('.shopify-section-controls').each(function () { var $section_controls = $(this); $section_controls.css('right', (get_full_width() - $section_controls.data('shopify-section').offset().left - $section_controls.data('shopify-section').outerWidth()) + 'px'); $section_controls.css('top', $section_controls.data('shopify-section').offset().top + 'px'); }); }, 500)); azh.controls_container.appendTo($body); } else { $('#azexo-html-library').show(); var $edit = $('#azexo-html-library .azh-library-actions .azh-edit-page'); if ('section' in $.QueryString) { azh.post_id = $.QueryString['section']; $edit.remove(); } else { if ('section' in query_string) { $('').insertAfter($edit).on('click', function () { window.location.href = window.location.origin + window.location.pathname + '?azh=customize&mode=sections&shop=' + $.QueryString['shop'] + '&front_path=' + encodeURIComponent(query_string['front_path']); return false; }); $edit.remove(); } } builder_init(); } azh.frontend_init = azh.window.get(0).azh.frontend_init; azh.frontend_init(azh.$(azh.body)); }, true); azh.post_frontend_frame.on('load', function () { azh.frontend_init = azh.window.get(0).azh.frontend_init; azh.post_frontend_frame.show(); azh.body.find('.azexo-edit-links').remove(); var $controls_container = $('.azh-controls-container'); if (!('mode' in $.QueryString && $.QueryString['mode'] === 'sections') || azh.post_id.indexOf('sections/') === 0) { if ($('.azh-editor-toolbar').length) { var $toolbar = $('.azh-editor-toolbar').detach(); $controls_container.append($toolbar); } } azh.window.off('scroll.controls-container').on('scroll.controls-container', function () { azh.scroll_top = azh.window.scrollTop(); $controls_container.css('top', (-azh.window.scrollTop()) + 'px'); }); azh.window.trigger('scroll'); }); } function frontend_editor_frame_init() { if ('mode' in $.QueryString && $.QueryString['mode'] == 'sections') { $('#azexo-html-library').hide(); } if ('azh' in $.QueryString && $.QueryString['azh'] == 'customize') { if (azh.edit_post_frontend_link) { azh.post_frontend_frame = false; $window.on('load', function () { post_frontend_frame_init(); }); } } } function tabs_init($wrapper) { $wrapper.each(function () { var $tabs = $$(this); if (!$tabs.data('azh-tabs')) { $tabs.find('> div:first-child > span > a[href^="#"]').on('click', function (event) { var $this = $$(this); event.preventDefault(); event.stopPropagation(); $this.parent().addClass("azh-active"); $this.parent().siblings().removeClass("azh-active"); var tab = $this.attr("href"); $tabs.find('> div:last-child > div').not(tab).css("display", "none"); $$(tab).fadeIn(); $$.simplemodal.update($$('.azh-dialog').outerHeight()); }); $tabs.find('> div:first-child > span:first-child > a[href^="#"]').click(); $tabs.data('azh-tabs', true); } }); } $(function () { function dialog_init() { $dialog_body = $body; $dialog_document = $document; $dialog_window = $window; if ('post_edit_frame' in azh) { if (azh.post_edit_frame) { if (!azh.post_edit_frame_loaded) { return false; } $dialog_body = azh.post_edit_frame.contents().find('body'); $dialog_window = $(azh.post_edit_frame.get(0).contentWindow); $dialog_document = $(azh.post_edit_frame.get(0).contentDocument || azh.post_edit_frame.get(0).contentWindow.document); $dialog_body.find('> *').hide(); $dialog_body.find('#wpwrap > *').hide(); $dialog_body.find('#wpwrap').show(); $dialog_body.css('background-color', 'transparent'); azh.post_edit_frame.show(); } else { return false; } } dialog_window = $dialog_window.get(0); $$ = dialog_window.jQuery; return true; } function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } function get_form_atts(form) { var attrs = {}; $$(form).find('.azh-tabs [data-param-name]').each(function () { if ($$(this).data('get_value')) { attrs[$$(this).data('param-name')] = $$(this).data('get_value').call(this); } }); return attrs; } function create_field(settings, value) { function set_image(field, url, id) { var preview = $$(field).find('.azh-image-preview'); $$(preview).empty(); $$('').appendTo(preview); $$(preview).data('id', id); $$(field).trigger('change'); $$('').appendTo(preview).on('click', function (event) { $$(preview).empty(); $$(preview).data('id', ''); $$(field).trigger('change'); return false; }); } function add_images(field, images) { var previews = $$(field).find('.azh-images-preview'); for (var i = 0; i < images.length; i++) { var preview = $$('
').appendTo(previews); $$('').appendTo(preview); $$(preview).data('id', images[i]['id']); (function (preview) { $$('').appendTo(preview).on('click', function (event) { $$(preview).remove(); $$(field).trigger('change'); return false; }); })(preview); } $$(previews).sortable(); $$(field).trigger('change'); } var field = $$('

'); $$(field).data('settings', settings); settings['heading'] = (typeof settings['heading'] == 'undefined' ? '' : settings['heading']); if ('dependency' in settings) { setTimeout(function () { $$('[data-param-name="' + settings['dependency']['element'] + '"]').on('change', function () { if ($$(this).css('display') == 'none') { $$(field).hide(); $$(field).trigger('change'); return; } var value = $$(this).data('get_value').call(this); if ('is_empty' in settings['dependency']) { if (value == '') { $$(field).show(); } else { $$(field).hide(); } } if ('not_empty' in settings['dependency']) { if (value == '') { $$(field).hide(); } else { $$(field).show(); } } if ('value' in settings['dependency']) { var variants = settings['dependency']['value']; if (typeof variants == 'string') { variants = [variants]; } if (variants.indexOf(value) >= 0) { $$(field).show(); } else { $$(field).hide(); } } if ('value_not_equal_to' in settings['dependency']) { var variants = settings['dependency']['value_not_equal_to']; if (typeof variants == 'string') { variants = [variants]; } if (variants.indexOf(value) >= 0) { $$(field).hide(); } else { $$(field).show(); } } $$(field).trigger('change'); }); }, 0); } switch (settings['type']) { case 'textfield': $$(field).append(''); var textfield = $$('').appendTo(field); if (value != '') { $$(textfield).val(value); } else { $$(textfield).val(settings['value']); } $$(textfield).on('change', function () { $$(field).trigger('change'); }); $$(field).data('get_value', function () { return $$(this).find('input[type="text"]').val(); }); break; case 'ajax_settings': $$(field).append(''); var $form_settings = $$('
').appendTo(field); var id = 0; $form_settings.on('change', function () { $$(field).trigger('change'); }); $$(field).data('get_value', function () { function htmlEncode(value) { return $('
').text(value).html(); } var settings = $form_settings.azhSerializeObject(); return btoa(unescape(encodeURIComponent(JSON.stringify(settings)))); }); $$.post(azh.ajaxurl, { 'action': settings['action'], 'settings': value }, function (data) { $form_settings.empty(); $form_settings.html(data); $$.simplemodal.update($$('.azh-dialog').outerHeight()); }); break; case 'widget_settings': $$(field).append(''); var $widget_settings = $$('
').appendTo(field); var id = 0; $widget_settings.on('change', function () { $$(field).trigger('change'); }); $$(field).data('get_value', function () { function htmlEncode(value) { return $('
').text(value).html(); } var settings = $widget_settings.azhSerializeObject(); if (settings['widgets']) { return btoa(unescape(encodeURIComponent(JSON.stringify(settings['widgets'][id])))); } else { return btoa(unescape(encodeURIComponent(JSON.stringify(settings)))); } }); $$(field).on('change', function () { function wp_widget_form(widget, instance) { if (!loading) { loading = true; $$.post(azh.ajaxurl, { 'action': 'wp_widget_form', 'widget': widget, 'instance': instance }, function (data) { loading = false; id = Math.floor(Math.random() * 1000000); var html = data.replace(/{\$id}/g, id); $widget_settings.empty(); $widget_settings.html(html); $widget_settings.addClass('open'); if (dialog_window.wp.textWidgets) { var event = new dialog_window.jQuery.Event('widget-added'); dialog_window.wp.textWidgets.handleWidgetAdded(event, $widget_settings); dialog_window.wp.mediaWidgets.handleWidgetAdded(event, $widget_settings); if (dialog_window.wp.customHtmlWidgets) { dialog_window.wp.customHtmlWidgets.handleWidgetAdded(event, $widget_settings); } } $$.simplemodal.update($$('.azh-dialog').outerHeight()); }); } } var loading = false; if (!$widget_settings.children().length) { var $from = $$(field).closest('.azh-form'); var $class = $from.find('[data-param-name="class"]'); if ($class.length) { $class.on('change', function () { wp_widget_form($class.data('get_value').call($class), ''); }); wp_widget_form($class.data('get_value').call($class), value); } } }); break; case 'textarea': case 'textarea_html': case 'textarea_raw_html': $$(field).append(''); var textarea = $$('').appendTo(field); if (value != '') { if (settings['type'] == 'textarea_raw_html') { try { $$(textarea).val(decodeURIComponent(escape(atob(value)))); } catch (e) { } } else { $$(textarea).val(value); } } else { $$(textarea).val(settings['value']); } if (settings['type'] == 'textarea_html') { azh.get_rich_text_editor(textarea); } $$(textarea).on('change', function () { $$(field).trigger('change'); }); $$(field).data('get_value', function () { if (settings['type'] == 'textarea_raw_html') { return btoa(unescape(encodeURIComponent($$(this).find('textarea').val()))); } else { return $$(this).find('textarea').val(); } }); break; case 'dropdown': $$(field).append(''); var select = $$(''); if ($$.isArray(settings['value'])) { for (var i = 0; i < settings['value'].length; i++) { $$(select).append(''); } } else { for (var label in settings['value']) { $$(select).append(''); } } $$(select).on('change', function () { $$(field).trigger('change'); }); $$(field).data('get_value', function () { return $$(this).find('select option:selected').attr('value'); }); $$(select).appendTo(field); break; case 'checkbox': var checkbox = $$('
' + settings['heading'] + '
').appendTo(field); var values = value.split(','); for (var label in settings['value']) { var id = makeid(); $$(checkbox).append('= 0 ? 'checked' : '') + ' value="' + settings['value'][label] + '">'); $$(checkbox).on('change', function () { $$(field).trigger('change'); }); $$(checkbox).append(''); } $$(field).data('get_value', function () { var values = $$.makeArray($$(this).find('input[type="checkbox"]:checked')).map(function (item) { return $$(item).attr('value') }); return values.join(','); }); break; case 'param_group': var param_group = $$('
' + settings['heading'] + '
').appendTo(field); var table = $$('
').appendTo(param_group); var values = JSON.parse(decodeURIComponent(settings['value'])); if (value != '') { values = JSON.parse(decodeURIComponent(value)); } for (var i = 0; i < values.length; i++) { var row = $$('').appendTo(table); for (var j = 0; j < settings['params'].length; j++) { var column = $$(''); $$(column).append(create_field(settings['params'][j], (settings['params'][j]['param_name'] in values[i] ? values[i][settings['params'][j]['param_name']] : ''))); row.append(column); } $$('' + azh.i18n.remove + '').appendTo($$('').appendTo(row)).on('click', function () { $$(this).closest('tr').remove(); return false; }); } $$('' + azh.i18n.add + '').appendTo(param_group).on('click', function () { var row = $$('').appendTo(table); for (var j = 0; j < settings['params'].length; j++) { var column = $$(''); $$(column).append(create_field(settings['params'][j], '')); row.append(column); } $$('' + azh.i18n.remove + '').appendTo($$('').appendTo(row)).on('click', function () { $$(this).closest('tr').remove(); return false; }); return false; }); $$(field).data('get_value', function () { var values = $$.makeArray($$(this).find('tr')).map(function (item) { var params = {}; $$(item).find('[data-param-name]').each(function () { if ($$(this).data('get_value')) { params[$$(this).data('param-name')] = $$(this).data('get_value').call(this); } }) return(params); }); return encodeURIComponent(JSON.stringify(values)); }); break; case 'attach_image': $$(field).append(''); var preview = $$('
').appendTo(field); $$('' + azh.i18n.set + '').appendTo(field).on('click', function (event) { azh.open_image_select_dialog.call(field, event, function (url, id) { set_image(this, url, id); }); return false; }); $$(field).data('get_value', function () { return $$(this).find('.azh-image-preview').data('id'); }); if (value != '') { azh.get_image_url(value, function (url) { set_image(field, url, value); }); } break; case 'attach_images': $$(field).append(''); var previews = $$('
').appendTo(field); $$('' + azh.i18n.add + '').appendTo(field).on('click', function (event) { azh.open_image_select_dialog.call(field, event, function (images) { add_images(this, images); }, true); return false; }); $$(field).data('get_value', function () { return $$.makeArray($$(this).find('.azh-images-preview .azh-image-preview')).map(function (item) { return $$(item).data('id'); }).join(','); }); if (value != '') { var images = value.split(',').map(function (item) { return {id: item}; }); for (var i = 0; i < images.length; i++) { (function (i) { azh.get_image_url(images[i]['id'], function (url) { images[i]['url'] = url; var all = true; for (var j = 0; j < images.length; j++) { if (!('url' in images[j])) { all = false; break; } } if (all) { add_images(field, images); } }); })(i); } } break; case 'url': $$(field).append(''); var wrapper = $$('').appendTo(field).on('contextmenu', function (event) { event.preventDefault(); $$(field).data('url', ''); $$(url_span).text(''); }); $$(field).data('url', value); var button = $$('' + azh.i18n.select_url + '').appendTo(wrapper).on('click', function (event) { var url = $$(field).data('url'); azh.open_link_select_dialog.call(this, event, function (url, target, title) { $$(field).data('url', url); $$(url_span).text(url); }, url, '', ''); return false; }); var url_span = $$('' + value + '').appendTo(wrapper); $$(field).data('get_value', function () { return $$(field).data('url'); }); break; case 'vc_link': $$(field).append(''); var wrapper = $$('').appendTo(field); var link = {}; if (value != '') { value.split('|').map(function (item) { link[item.split(':')[0]] = decodeURIComponent(item.split(':')[1]); }); } $$(field).data('link', link); var button = $$('' + azh.i18n.select_url + '').appendTo(wrapper).on('click', function (event) { var link = $$(field).data('link'); azh.open_link_select_dialog.call(this, event, function (url, target, title) { var link = { url: url, target: target, title: title, rel: 'nofollow' }; $$(field).data('link', link); $$(title_span).text(title); $$(url_span).text(url); }, ('url' in link ? link['url'] : ''), ('target' in link ? link['target'] : ''), ('title' in link ? link['title'] : '')); return false; }); $$(wrapper).append(''); var title_span = $$('' + ('title' in link ? link['title'] : '') + '').appendTo(wrapper); $$(wrapper).append(''); var url_span = $$('' + ('url' in link ? link['url'] : '') + '').appendTo(wrapper); $$(field).data('get_value', function () { return $$.map($$(this).data('link'), function (value, index) { return [index + ':' + encodeURIComponent(value)]; }).join('|'); }); break; case 'iconpicker': $$(field).append(''); var textfield = $$('').appendTo(field); $$(textfield).val(value); azh.icon_select_dialog(function (icon) { $$(textfield).val(icon); }, settings['settings']['type']).appendTo(field); $$(field).data('get_value', function () { return $$(this).find('input[type="text"]').val(); }); break; case 'ajax_dropdown': $$(field).append(''); var $$select = $$(''); $$select.on('change', function () { $$(field).trigger('change'); }); $$(field).data('get_value', function () { return $$select.val() ? $$select.val() : ''; }); $$select.appendTo(field); $$select.select2({ ajax: { url: settings['url'], dataType: 'json' }, dropdownAutoWidth: 'true' }); if (value) { $$.post(settings['url'], { 'values': [value] }, function (data) { for (var v in data) { $$('').appendTo($$select); } $$select.val(value).trigger('change'); }, 'json'); } break; case 'ajax_multiselect': $$(field).append(''); var $$select = $$(''); $$select.on('change', function () { $$(field).trigger('change'); }); $$(field).data('get_value', function () { return $$select.val() ? $$select.val().join(',') : ''; }); $$select.appendTo(field); $$select.select2({ ajax: { url: settings['url'], dataType: 'json' }, dropdownAutoWidth: 'true' }); if (value) { $$.post(settings['url'], { 'values': value.split(',') }, function (data) { for (var v in data) { $$('').appendTo($$select); } $$select.val(value.split(',')).trigger('change'); }, 'json'); } break; case 'autocomplete': $$(field).append(''); var textfield = $$('').appendTo(field); $$(field).data('value', value); var shortcode_settings = {}; setTimeout(function () { shortcode_settings = $$(field).closest('.azh-form').data('settings'); if ($$.trim(value) != '') { var attrs = get_form_atts($$(field).closest('.azh-form')); $$.post(azh.ajaxurl, { action: 'azh_autocomplete_labels', shortcode: shortcode_settings['base'], attrs: attrs, param_name: settings['param_name'], values: value }, function (data) { $$(textfield).val(Object.keys(data).map(function (item) { return data[item]; }).join(', ')); if ('multiple' in settings && !settings['multiple']) { if (Object.keys(data).length > 0) { $$(field).data('value', Object.keys(data)[0]); } else { $$(field).data('value', ''); } } else { $$(field).data('value', Object.keys(data).join(',')); } }, 'json'); } }); $$(textfield).on("keydown", function (event) { if (event.keyCode === $$.ui.keyCode.TAB && $$(this).autocomplete("instance").menu.active) { event.preventDefault(); } }).autocomplete({ minLength: 0, source: function (request, response) { if (request.term.split(/,\s*/).pop() != '') { var attrs = get_form_atts($$(field).closest('.azh-form')); $$.post(azh.ajaxurl, { action: 'azh_autocomplete', shortcode: shortcode_settings['base'], attrs: attrs, param_name: settings['param_name'], exclude: $$(field).data('value'), search: request.term.split(/,\s*/).pop() }, function (data) { response(data); }, 'json'); } else { response(); } }, focus: function (event, ui) { return false; }, select: function (event, ui) { if (ui.item) { var labels = this.value.split(/,\s*/); labels.pop(); labels.push(ui.item.label); if ('multiple' in settings && !settings['multiple']) { if (labels.length > 0) { this.value = labels[0]; } else { this.value = ''; } } else { labels.push(''); this.value = labels.join(', '); } var values = $$(field).data('value').split(/,\s*/); if (!$$(field).data('value')) { values = []; } values.push(ui.item.value.toString()); if ('multiple' in settings && !settings['multiple']) { if (values.length > 0) { $$(field).data('value', values[0]); } else { $$(field).data('value', ''); } } else { $$(field).data('value', values.join(',').replace(/,\s*$/, '').replace(/^\s*,/, '')); } $$(field).trigger('change'); } return false; } }).on("keydown keyup blur", function (event) { if ($$(textfield).val() == '') { $$(field).data('value', ''); $$(field).trigger('change'); } }).on("focus", function (event) { var values = $$(field).data('value').split(/,\s*/); if ($$(field).data('value') && values.length) { var labels = $$(textfield).val().split(/,\s*/); if (values.length < labels.length) { labels.pop(); } if ('multiple' in settings && !settings['multiple']) { if (labels.length > 0) { $$(textfield).val(labels[0]); } else { $$(textfield).val(''); } } else { $$(textfield).val(labels.join(', ') + ', '); } } }); $$(textfield).autocomplete('instance')._create = function () { this._super(); this.widget().menu('option', 'items', '> :not(.ui-autocomplete-group)'); }; $$(textfield).autocomplete('instance')._renderMenu = function (ul, items) { var that = this, currentGroup = ''; $$.each(items, function (index, item) { var li; if ('group' in item && item.group != currentGroup) { ul.append('
' + item.group + '
'); currentGroup = item.group; } li = that._renderItemData(ul, item); if ('group' in item && item.group) { li.attr('aria-label', item.group + ' : ' + item.label); } }); }; $$(field).data('get_value', function () { return $$(this).data('value'); }); break; } if ($$(field).data('get_value')) { if ('description' in settings) { $$(field).append('' + settings['description'] + ''); } } return field; } function create_form(settings, values) { var form = $$('
'); $$(form).data('settings', settings); if ('params' in settings) { var groups = {}; groups[azh.i18n.general] = []; for (var i = 0; i < settings['params'].length; i++) { if ('group' in settings['params'][i]) { groups[settings['params'][i]['group']] = []; } } for (var i = 0; i < settings['params'].length; i++) { if ('group' in settings['params'][i]) { groups[settings['params'][i]['group']].push(settings['params'][i]); } else { groups[azh.i18n.general].push(settings['params'][i]); } } var $$tabs = $$('
').appendTo(form); var $$tabs_buttons = $$('
').appendTo($$tabs); var $$tabs_content = $$('
').appendTo($$tabs); var ids = {}; for (var group in groups) { var id = makeid(); ids[group] = id; if (groups[group].length) { $$('' + group + '').appendTo($$tabs_buttons); } } for (var group in groups) { if (groups[group].length) { var tab = $$('
').appendTo($$tabs_content); for (var i = 0; i < groups[group].length; i++) { create_field(groups[group][i], (groups[group][i]['param_name'] in values ? values[groups[group][i]['param_name']] : '')).appendTo(tab); } } } tabs_init($$tabs); setTimeout(function () { $$(form).find('.azh-tabs [data-param-name]').trigger('change'); }, 0); } return form; } function make_shortcode(settings, attrs) { var shortcode = '[' + settings['base']; var content = false; if ('content' in attrs) { content = attrs['content']; } shortcode += Object.keys(attrs).map(function (item) { if (item == 'content') { return ''; } else { return ' ' + item + '="' + attrs[item] + '"'; } }).join(''); shortcode += ']'; if (content) { shortcode += content + '[/' + settings['base'] + ']'; } return shortcode; } function create_dialog(form, title, callback) { var $$modal = $$('
'); $$('
' + title + '
').appendTo($$modal); form.appendTo($$modal); var $actions = $$('
').appendTo($$modal); $$('
' + azh.i18n.ok + '
').appendTo($actions).on('click', function () { var attrs = get_form_atts(form); var settings = $$(form).data('settings'); var shortcode = make_shortcode(settings, attrs); callback(shortcode, attrs); $$.simplemodal.close(); return false; }); $$('
' + azh.i18n.cancel + '
').appendTo($actions).on('click', function () { $$.simplemodal.close(); return false; }); $$modal.simplemodal({ autoResize: true, overlayClose: true, opacity: 0, overlayCss: { "background-color": "black" }, closeClass: "azh-close", onShow: function () { $$.simplemodal.update($$('.azh-dialog').outerHeight()); }, onClose: function () { if ('post_edit_frame' in azh) { azh.post_edit_frame.hide(); } $$.simplemodal.close(); } }); return $$modal; } function create_shortcode(settings) { var shortcode = $$('
' + settings.name + '
' + ('description' in settings ? settings.description : '') + '
').data('settings', settings); return shortcode; } function html_beautify(html) { var results = ''; var level = 0; var ignore = false; var ignore_tags = { // "script": true, // "style": true }; azh.indent_size = 1; AZHParser(html, { start: function (tag, attrs, unary) { if (ignore_tags[tag]) { ignore = true; return; } results += Array(level * azh.indent_size + 1).join("\t") + "<" + tag; for (var i = 0; i < attrs.length; i++) { if (attrs[i].value.indexOf('"') >= 0 && attrs[i].value.indexOf("'") < 0) { results += " " + attrs[i].name + "='" + attrs[i].value + "'"; } else { results += " " + attrs[i].name + '="' + attrs[i].escaped + '"'; } } results += (unary ? "/" : "") + ">\n"; if (!unary) { level++; } }, end: function (tag) { if (ignore_tags[tag]) { ignore = false; return; } level--; results += Array(level * azh.indent_size + 1).join("\t") + "\n"; }, chars: function (text) { if ($$.trim(text) && !ignore) { results += Array(level * azh.indent_size + 1).join("\t") + text.replace(/[\t\r\n]*/g, '') + "\n"; } }, comment: function (text) { results += Array(level * azh.indent_size + 1).join("\t") + '\n"; } }); return results; } function auto_focus() { $document.one('azh-store', function () { setTimeout(function () { var occurrence = 0; if ('section' in $.QueryString) { $('.azh-group-title:contains("' + $.QueryString['section'] + '")').each(function () { if ($(this).text() == $.QueryString['section'] && $.QueryString['occurrence'] == occurrence.toString()) { var section = $(this).closest('.azh-section'); if ($(section).length) { $('body, html').stop().animate({ 'scrollTop': $(section).offset().top - $window.height() / 2 + $(section).height() / 2 }, 300); setTimeout(function () { $('
').appendTo('body'); azh.focus('.azh-overlay', 0); setTimeout(function () { $('.azh-overlay').remove(); azh.focus(section, 300); }, 0); }, 300); } } occurrence++; }); } if ('element' in $.QueryString) { $('.azh-element-title:contains("' + $.QueryString['element'] + '")').each(function () { if ($(this).text() == $.QueryString['element'] && $.QueryString['occurrence'] == occurrence.toString()) { var element = $(this).closest('.azh-element-wrapper'); $(element).parents('.azh-section-collapsed').each(function () { $(this).find('> .azh-controls .azh-section-expand').click(); }); $(element).parents('.azh-element-collapsed').each(function () { $(this).find('> .azh-controls .azh-element-expand').click(); }); if ($(element).length) { $('body, html').stop().animate({ 'scrollTop': $(element).offset().top - $window.height() / 2 + $(element).height() / 2 }, 300); setTimeout(function () { $('
').appendTo('body'); azh.focus('.azh-overlay', 0); setTimeout(function () { $('.azh-overlay').remove(); azh.focus(element, 300); }, 0); }, 300); } } occurrence++; }); } }, 100); }); } azh.open_element_settings_dialog = function (settings, values, callback) { if (dialog_init()) { $$.simplemodal.close(); if ('base' in settings && settings.base.indexOf('component') == 0) { var name = false; if ('name' in values) { name = values['name']; } else { name = settings.base.split('component-'); if (name.length == 2) { name = name[1]; } else { name = false; } } if (name) { if (!azh.bx_editor) { azh.bx_editor = new BXEditor(BXHtmlEditor.configs['azh']); azh.bx_editor.Hide(); } var template = values['template'] ? values['template'] : ''; var params = {}; try { params = JSON.parse(values['content']); } catch (e) { params = {}; } var code = azh.bx_editor.components.GetSource({name: name, template: template, params: params}); var component = azh.bx_editor.components.IsComponent(code); var id = azh.bx_editor.SetBxTag(false, {tag: 'component', name: name, params: component}); var surrogate_id = azh.bx_editor.SetBxTag(false, {tag: "surrogate_dd", params: {origParams: component, origId: id}}); azh.bx_editor.components.ShowPropertiesDialog(component, azh.bx_editor.GetBxTag(surrogate_id)); azh.bx_editor.synchro.FullSyncFromIframe = function () { var attrs = { name: component.name, template: component.template, content: JSON.stringify(component.params) }; var cloned_settings = $.extend({}, settings); cloned_settings.base = 'component'; var shortcode = make_shortcode(cloned_settings, attrs); callback(shortcode, attrs); }; } } else { return create_dialog(create_form(settings, values), settings['name'], callback); } } }; azh.elements_dialog = false; azh.open_elements_dialog = function (callback) { if (dialog_init() && $$('#simplemodal-container').length === 0) { $$.simplemodal.close(); var $$modal = false; var ids = {}; azh.elements_dialog_callback = callback; if (azh.elements_dialog && (JSON.stringify(azh.elements_dialog.data('child-suggestions')) === JSON.stringify(azh.child_suggestions))) { $$modal = azh.elements_dialog; } else { function filters_change() { function tags_select_refresh() { $tags_select.children().attr('hidden', 'hidden'); for (var tag in azh.tags) { if (tag && $$('.azh-elements-form .azh-elements-filters ~ .azh-element[data-tags*="' + tag + '"]:visible').length) { $tags_select.children('[value="' + tag + '"]').removeAttr('hidden'); } } $tags_select.children('[value=""]').removeAttr('hidden'); if ($tags_select.children('[value="' + $tags_select.val() + '"][hidden]').length) { $tags_select.val(''); setTimeout(function () { filters_change(); }); } } var category = $categories_select.find('option:selected').val(); azh.default_category = category; var tag = $tags_select.find('option:selected').val(); if (category == '' && tag == '') { $$('.azh-elements-form .azh-elements-filters ~ .azh-element').css('display', 'inline-block'); } else { if (category != '' && tag == '') { $$('.azh-elements-form .azh-elements-filters ~ .azh-element').css('display', 'none'); $$('.azh-elements-form .azh-elements-filters ~ .azh-element[data-path^="' + category + '"]').css('display', 'inline-block'); tags_select_refresh(); } if (category == '' && tag != '') { $$('.azh-elements-form .azh-elements-filters ~ .azh-element').css('display', 'none'); $$('.azh-elements-form .azh-elements-filters ~ .azh-element[data-tags*="' + tag + '"]').css('display', 'inline-block'); } if (category != '' && tag != '') { $$('.azh-elements-form .azh-elements-filters ~ .azh-element').css('display', 'inline-block'); $$('.azh-elements-form .azh-elements-filters ~ .azh-element:not([data-path^="' + category + '"])').css('display', 'none'); tags_select_refresh(); $$('.azh-elements-form .azh-elements-filters ~ .azh-element:not([data-tags*="' + tag + '"])').css('display', 'none'); } } } function button_click(button) { function click_process(data) { data = data.replace(/{{azh-uri}}/g, $$(button).data('dir-uri')); if (azh.any_blog) { data = data.replace(/{{any-blog-id}}/g, azh.any_blog.id); } if (azh.any_collection) { data = data.replace(/{{any-products-collection-id}}/g, azh.any_collection.id); } if (azh.any_article) { data = data.replace(/{{any-article-handle}}/g, azh.any_article.handle); } if (azh.any_product) { data = data.replace(/{{any-product-handle}}/g, azh.any_product.handle); } if (azh.any_menu_handle) { data = data.replace(/{{any-menu-handle}}/g, azh.any_menu_handle); } data = azh.do_replaces(data); data = html_beautify(data); azh.elements_dialog_callback($$(button).data('path'), data, !$$(button).is('.general')); $$.simplemodal.close(); } if ($$(button).data('url') in azh.elements_cache) { click_process(azh.elements_cache[$$(button).data('url')]); } else { $$.get($$(button).data('url'), function (data) { azh.elements_cache[$$(button).data('url')] = data; click_process(data); }); } } $$modal = $$('
'); azh.elements_dialog = $$modal; $$('
' + azh.i18n.select_element + '
').appendTo($$modal); var form = $$('
').appendTo($$modal); var $categories_select = null; var $tags_select = null; var categories = {}; //categories['general'] = []; $$('.azh-library .azh-elements .azh-element').each(function () { if (!$$(this).is('.general')) { var path = $$(this).data('path'); var category = path.split('/')[0]; categories[category] = []; $$(this).attr('data-category', category); } }); // if ($$('.azh-library .azh-elements .azh-element').length) { // categories['elements'] = []; // } var $$tabs = $$('
').appendTo(form); var $$tabs_buttons = $$('
').appendTo($$tabs); var $$tabs_content = $$('
').appendTo($$tabs); var general_tab = false; if ('categories_order' in azh) { $$(azh.categories_order).each(function () { if (this in categories) { var category = this; var id = makeid(); ids[category] = id; $$('' + (category in azh.i18n ? azh.i18n[category] : (category[0].toUpperCase() + category.slice(1))) + '').appendTo($$tabs_buttons); } }); } else { for (var category in categories) { var id = makeid(); ids[category] = id; $$('' + (category in azh.i18n ? azh.i18n[category] : (category[0].toUpperCase() + category.slice(1))) + '').appendTo($$tabs_buttons); } } var child_suggestions = []; for (var category in categories) { var tab = $$('
').appendTo($$tabs_content); if (category === 'general') { general_tab = tab; } else if (category === 'elements') { var filters = $$('.azh-library .azh-elements .azh-elements-filters').clone(); $$(filters).appendTo(tab); $categories_select = $$(filters).find('.azh-categories').on('change', filters_change); $tags_select = $$('').appendTo(filters).on('change', filters_change); $$('').appendTo($tags_select); Object.keys(azh.tags).sort().forEach(function (tag, i) { $('').appendTo($tags_select); }); $$('.azh-library .azh-elements .azh-element').each(function () { var button = $$(this).clone(); button.appendTo(tab).on('click', function () { button_click(this); }); if (general_tab && $$(button).is('.general')) { var general_button = $$(button).clone(true); general_button.appendTo(general_tab); } if (azh.child_suggestions.length) { if (azh.child_suggestions.indexOf($$(this).data('path')) >= 0) { child_suggestions.push(button); } } }); } else { $$('.azh-library .azh-elements .azh-element[data-category="' + category + '"]').each(function () { var button = $$(this).clone(); button.appendTo(tab).on('click', function () { button_click(this); }); if (button.find('.azh-premium').length) { button.off('click'); } if ('active_plan' in azh && !azh.active_plan) { if ('premium_elements' in azh && azh.premium_elements.indexOf(button.attr('data-path')) >= 0) { button.append('
' + azh.i18n.available_only_in_premium_plan + '
'); button.off('click'); } } }); } var elements = tab.children(); elements.detach(); elements.sort(function (element1, element2) { var order1 = parseInt($$(element1).attr('data-order'), 10); var order2 = parseInt($$(element2).attr('data-order'), 10); return (order1 < order2) ? -1 : (order1 > order2) ? 1 : 0; }); tab.append(elements); // if ('active_plan' in azh && !azh.active_plan) { // if ('premium_categories' in azh && azh.premium_categories.indexOf(category) >= 0) { // tab.append('
' + azh.i18n.available_only_in_premium_plan + '
'); // } // } } if (general_tab && child_suggestions.length) { $$('
').prependTo(general_tab); $$(child_suggestions).each(function () { var general_button = $$(this).clone(true); general_button.prependTo(general_tab); }); } tabs_init($$tabs); azh.elements_dialog.data('child-suggestions', $$.merge([], azh.child_suggestions)); var $actions = $$('
').appendTo($$modal); $$('
' + azh.i18n.paste_from_clipboard + '
').appendTo($actions).on('click', function () { if (azh.clipboard) { azh.elements_dialog_callback(azh.clipboard['path'], azh.clipboard['code']); $$.simplemodal.close(); } else { $.post(azh.ajaxurl, { 'action': 'azh_paste', dataType: 'text', }, function (data) { data = JSON.parse(data); if ('code' in data && 'path' in data) { azh.elements_dialog_callback(data['path'], data['code']); } $$.simplemodal.close(); }); } return false; }); $$('
' + azh.i18n.cancel + '
').appendTo($actions).on('click', function () { $$.simplemodal.close(); return false; }); } $$modal.simplemodal({ autoResize: true, overlayClose: true, opacity: 0, overlayCss: { "background-color": "black" }, closeClass: "azh-close", onShow: function () { if (azh.default_category) { var $categories_select = $$modal.find('.azh-elements-filters .azh-categories'); if ($categories_select.find('[value="' + azh.default_category + '"]').length) { $categories_select.val(azh.default_category); $$modal.find('.azh-left-tabs .azh-tabs-buttons').find('[href="#' + ids['elements'] + '"]').trigger('click'); $categories_select.trigger('change'); } if (azh.default_category in ids) { $$modal.find('.azh-left-tabs .azh-tabs-buttons').find('[href="#' + ids[azh.default_category] + '"]').trigger('click'); } } }, onClose: function () { azh.elements_dialog.detach(); if ('post_edit_frame' in azh) { azh.post_edit_frame.hide(); } $.simplemodal.impl.d.data = $(); $$.simplemodal.close(); } }); return $$modal; } }; azh.icon_select_dialog = function (callback, type) { function show_icons() { var keyword = $search.val().toLowerCase(); $icons.empty(); for (var key in azh.icons[type]) { if (azh.icons[type][key].toLowerCase().indexOf(keyword) >= 0) { $$('').appendTo($icons).on('click', {icon: icon}, function (event) { callback.call(event.data.icon, $$(this).attr('class')); }); } } } var icon = this; var icon_class = ''; var $dialog = $$('
').appendTo('body'); var $controls = $$('').appendTo($dialog); var $search = $$('').appendTo($controls).on('change keyup', function () { show_icons(); }); var $icons = $$('
').appendTo($dialog); show_icons(); return $dialog; }; azh.open_icon_select_dialog = function (event, icon_class, callback) { function show_icons() { var type = $types.find('option:selected').val(); var keyword = $$(search).val().toLowerCase(); $icons.empty(); for (var key in azh.icons[type]) { if (azh.icons[type][key].toLowerCase().indexOf(keyword) >= 0) { $$('').appendTo($icons).on('click', {icon: icon}, function (event) { $dialog.remove(); $backdrop.remove(); $document.off('click.azh-dialog'); if ('post_edit_frame' in azh) { azh.post_edit_frame.hide(); } callback.call(event.data.icon, $$(this).attr('class')); }); } } } if (dialog_init()) { var current_type = false; for (var type in azh.icons) { var pattern = new RegExp('(' + Object.keys(azh.icons[type]).join('|') + ')', 'i'); var match = pattern.exec(icon_class); if (match) { current_type = type; break; } } var icon = this; $dialog_body.find('.azh-icon-select-dialog').remove(); $dialog_body.find('.azh-backdrop').remove(); var $backdrop = $$('
').appendTo($dialog_body); var $dialog = $$('
').appendTo($dialog_body); var $controls = $$('').appendTo($dialog); var $types = $$('').appendTo($controls).on('change', function () { show_icons(); }); var search = $$('').appendTo($controls).on('change keyup', function () { show_icons(); }); for (var type in azh.icons) { var option = $$('').appendTo($types); } var $icons = $$('
').appendTo($dialog); $types.val(current_type); show_icons(); $document.on('click.azh-dialog', {icon: icon}, function (event) { if (!$$(event.target).closest('.azh-icon-select-dialog').length) { $dialog.remove(); $backdrop.remove(); $document.off('click.azh-dialog'); if ('post_edit_frame' in azh) { azh.post_edit_frame.hide(); } callback.call(event.data.icon, icon_class); } }); event.stopPropagation(); } }; azh.get_image_url = function (id, callback) { var attachment = wp.media.model.Attachment.get(id); attachment.fetch().done(function () { callback(attachment.attributes.url); }); }; azh.open_image_select_dialog = function (event, callback, multiple, type) { if (dialog_init()) { var image = this; $dialog_body.find('.azh-file-input').remove(); $dialog_body.find('.azh-progress').remove(); var $input = $$('').insertBefore(event.target).css({ position: 'fixed', left: '-1000px', top: '-1000px' }).on('click', function (event) { event.stopPropagation(); }); var $progress = $$(''); if ($$(event.target).is('img')) { $progress.appendTo($$(event.target).parent()); } else { $progress.appendTo($$(event.target)); } $input.on('change', function () { var file = $input.get(0).files[0]; var xhr = new XMLHttpRequest(); if (xhr.upload) { xhr.upload.addEventListener("progress", function (e) { $progress.find('.azh-status').width((e.loaded / e.total * 100) + '%'); }, false); xhr.onreadystatechange = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) { $progress.remove(); $input.remove; if (xhr.response) { callback.call(image, xhr.response, false); } } } }; xhr.open("POST", azh.ajaxurl + '?action=upload_file', true); xhr.setRequestHeader("X-FILENAME", file.name); xhr.send(file); $progress.find('.azh-status').width('0%'); $progress.fadeIn("slow"); } }); $input.trigger('click'); event.stopPropagation(); } }; azh.open_link_select_dialog = function (event, callback, url, target, text) { function create_select($$tab, type) { var $$select = $$('').appendTo($$tab); $$select.select2({ ajax: { url: azh.ajaxurl + '?action=links-dropdown&type=' + type, dataType: 'json' }, width: '100%' //dropdownAutoWidth: 'true' }); if (url) { $$.post(azh.ajaxurl + '?action=links-dropdown&type=' + type, { 'values': [url] }, function (data) { for (var v in data) { $$('').appendTo($$select); } $$select.trigger('change'); }, 'json'); } } if (dialog_init()) { var link = this; var $$form = $$('
'); var $$tabs = $$('
').appendTo($$form); var $$tabs_buttons = $$('
').appendTo($$tabs); var $$tabs_content = $$('
').appendTo($$tabs); $$('' + azh.i18n.external + '').appendTo($$tabs_buttons); var $$external_tab = $$('
').appendTo($$tabs_content); var $$external_input = $$('').appendTo($$external_tab).css('width', '100%').val(url); $$('' + azh.i18n.pages + '').appendTo($$tabs_buttons); var $$pages_tab = $$('
').appendTo($$tabs_content); create_select($$pages_tab, 'pages'); $$('' + azh.i18n.collections + '').appendTo($$tabs_buttons); var $$collections_tab = $$('
').appendTo($$tabs_content); create_select($$collections_tab, 'collections'); $$('' + azh.i18n.products + '').appendTo($$tabs_buttons); var $$products_tab = $$('
').appendTo($$tabs_content); create_select($$products_tab, 'products'); $$('' + azh.i18n.articles + '').appendTo($$tabs_buttons); var $$articles_tab = $$('
').appendTo($$tabs_content); create_select($$articles_tab, 'articles'); tabs_init($$tabs); if (url.indexOf('/pages/') >= 0) { setTimeout(function () { $$tabs_buttons.find('[href="#pages"]').trigger('click'); }); } if (url.indexOf('/collections/') >= 0) { setTimeout(function () { $$tabs_buttons.find('[href="#collections"]').trigger('click'); }); } if (url.indexOf('/products/') >= 0) { setTimeout(function () { $$tabs_buttons.find('[href="#products"]').trigger('click'); }); } if (url.indexOf('/articles/') >= 0) { setTimeout(function () { $$tabs_buttons.find('[href="#articles"]').trigger('click'); }); } var $$modal = $$('
').css('width', '550px'); $$('
' + azh.i18n.select_link + '
').appendTo($$modal); $$form.appendTo($$modal); var $$actions = $$('
').appendTo($$modal); $$('
' + azh.i18n.ok + '
').appendTo($$actions).on('click', function () { var href = $$tabs_buttons.find('.azh-active a').attr('href'); var selected_url = $$tabs_content.find(href).find('input, select').val(); callback.call(link, selected_url, target, text); $$.simplemodal.close(); return false; }); $$('
' + azh.i18n.cancel + '
').appendTo($$actions).on('click', function () { $$.simplemodal.close(); return false; }); $$modal.simplemodal({ autoResize: true, overlayClose: true, opacity: 0, overlayCss: { "background-color": "black" }, closeClass: "azh-close", onShow: function () { $$.simplemodal.update($$('.azh-dialog').outerHeight()); }, onClose: function () { $$.simplemodal.close(); } }); } }; azh.get_rich_text_editor = function (textarea) { var textfield_id = makeid(); }; $body = $('body'); if ('wpColorPicker' in $.fn) { $('input.azh-wp-color-picker').wpColorPicker(); } azh.shopify = { all_products: {}, collections: {}, blogs: {} }; var shopify_context_selector = '.az-no-liquid-context, [data-shopify-blog-id], [data-shopify-products-collection-id], [data-shopify-product-handle], [data-shopify-article-handle]'; azh.shopify_process = function ($liquid) { function fix_product(product) { //selected if (product.variants && product.variants.length) { product.selected_or_first_available_variant = product.variants[0]; $.each(product.variants, function () { parseInt(this.inventory_quantity, 10) > 0 || "shopify" != this.inventory_management ? this.available = true : this.available = false; }); } if (product.image) { product.image.aspect_ratio = product.image.width / product.image.height; } if (product.images && product.images.length) { $.each(product.images, function () { this.aspect_ratio = this.width / this.height; }); } if (product.image) { product.featured_image = product.image; } else { if (product.images && product.images.length) { product.featured_image = product.images[0]; } } product.options_with_values = product.options; return product; } function fix_article(article) { article.content = article.body_html; if (typeof article.tags === 'string') { article.tags = $.map(article.tags.split(','), $.trim); } } var context = { current_tags: ['current tag'], linklists: azh.menus, page: { title: 'page title' }, search: { performed: true, results_count: 10, results: [ { object_type: 'article', url: '/', title: 'article title', content: 'article content' }, { object_type: 'article', url: '/', title: 'article title', content: 'article content' }, ] }, paginate: { pages: 3, previous: { is_link: true, url: '/' }, parts: [ { is_link: true, title: '2', url: '/' }, { is_link: false, title: '3', url: '/' } ], next: { is_link: false, url: '/' } }, collection: { title: 'collection title', handle: 'all', default_sort_by: 'manual', sort_options: [ { value: 'manual', name: 'Featured' }, { value: 'best-selling', name: 'Best selling' }, { value: 'title-ascending', name: 'Alphabetically, A-Z' }, { value: 'title-descending', name: 'Alphabetically, Z-A' }, { value: 'price-ascending', name: 'Price, low to high' }, { value: 'price-descending', name: 'Price, high to low' }, { value: 'created-ascending', name: 'Date, old to new' }, { value: 'created-descending', name: 'Date, new to old' }, ], all_tags: ['tag1', 'tag2', 'tag3'], products_count: 0, products: [] }, collections: azh.collections, article: { title: 'article title', content: 'article content', author: 'article author', published_at: 'July 4, 2019' }, blog: { handle: 'news', url: '/blogs/news', tags: ['tag1', 'tag2', 'tag3'], comments_enabled: true, articles: [] }, customer: {}, cart: { cart_level_discount_applications: [ { title: 'Discount', total_allocated_amount: '123' } ], items: [ { line_level_discount_allocations: [ { discount_allocation: { discount_application: { title: 'Discount' } }, amount: 3 } ], original_line_price: 12, final_line_price: 13, key: 'key', original_price: 12, final_price: 13, quantity: 1, properties: [ { first: 'label', last: 'value' } ], variant: { title: 'Default variant', options: ['456', 'Red'] }, product: { title: 'Product title', options: ['Size', 'Color'] }, image: azh.any_product.image, url: '/' } ], currency: 'USD', total_price: 321, item_count: 3 }, shop: { enabled_currencies: [{ iso_code: 'USD' }], customer_accounts_enabled: true, url: azh.site_url } }; if (context.collections.length && azh.any_product && 'image' in azh.any_product) { for (var i in context.collections) { if (!('image' in context.collections[i])) { context.collections[i].image = azh.any_product.image; } } } if ($liquid.is('[data-shopify-limit]')) { context.limit = parseInt($liquid.attr('data-shopify-limit'), 10); } if ($liquid.is('[data-shopify-blog-id]')) { var blog_id = $liquid.attr('data-shopify-blog-id'); if (!blog_id && azh.any_blog) { blog_id = azh.any_blog.id; } if (!blog_id) { $liquid.find('.az-liquid-container').prepend('
' + azh.i18n.please_select_blog_in_element_settings + '
'); return; } var limit = 10; if (context.limit) { limit = context.limit; } if (azh.shopify.blogs[blog_id] && $liquid.data('shopify-limit') == limit) { context.blog.articles = azh.shopify.blogs[blog_id]; azh.liquid_process($liquid.closest('[data-element]'), context); } else { $liquid.data('shopify-limit', limit); $.get(azh.ajaxurl + '?action=get_articles&limit=' + limit + '&blog_id=' + blog_id, function (data) { azh.shopify.blogs[blog_id] = JSON.parse(data); if (azh.shopify.blogs[blog_id] && azh.shopify.blogs[blog_id].length) { context.blog.articles = azh.shopify.blogs[blog_id]; $.each(context.blog.articles, function () { fix_article(this); }); azh.liquid_process($liquid.closest('[data-element]'), context); } else { $liquid.find('.az-liquid-container').prepend('
' + azh.i18n.please_select_blog_in_element_settings + '
'); return; } }); } } if ($liquid.is('[data-shopify-products-collection-id]')) { var collection_id = $liquid.attr('data-shopify-products-collection-id'); if (!collection_id && azh.any_collection) { collection_id = azh.any_collection.id; } for (var i in azh.collections) { if (azh.collections[i].id == collection_id) { context.collection.title = azh.collections[i].title; context.collection.handle = azh.collections[i].handle; context.collection.image = azh.collections[i].image; break; } } if (!collection_id) { $liquid.find('.az-liquid-container').prepend('
' + azh.i18n.please_select_products_collection_in_element_settings + '
'); return; } var limit = 10; if (context.limit) { limit = context.limit; } if (!$liquid.data('shopify-limit')) { context.collection.products = []; azh.liquid_process($liquid.closest('[data-element]'), context); } else { if (azh.shopify.collections[collection_id] && $liquid.data('shopify-limit') == limit) { context.collection.products = azh.shopify.collections[collection_id]; azh.liquid_process($liquid.closest('[data-element]'), context); } else { $liquid.data('shopify-limit', limit); $.get(azh.ajaxurl + '?action=get_products&field=collection_id&limit=' + limit + '&value=' + collection_id, function (data) { azh.shopify.collections[collection_id] = JSON.parse(data); if (azh.shopify.collections[collection_id] && azh.shopify.collections[collection_id].length) { context.collection.products = azh.shopify.collections[collection_id]; $.each(context.collection.products, function () { fix_product(this); }); azh.liquid_process($liquid.closest('[data-element]'), context); } else { $liquid.find('.az-liquid-container').prepend('
' + azh.i18n.please_select_products_collection_in_element_settings + '
'); return; } }); } } } if ($liquid.is('[data-shopify-article-handle]')) { context.article = {}; var handle = $liquid.attr('data-shopify-article-handle'); if (!handle && azh.any_article) { handle = azh.any_article.handle; } fix_article(azh.any_article); context.article = azh.any_article; azh.liquid_process($liquid.closest('[data-element]'), context); } if ($liquid.is('[data-shopify-product-handle]')) { context.product = {}; var handle = $liquid.attr('data-shopify-product-handle'); if (!handle && azh.any_product) { handle = azh.any_product.handle; } if (!handle) { $liquid.find('.az-liquid-container').prepend('
' + azh.i18n.please_select_product_in_element_settings + '
'); return; } if (azh.shopify.all_products[handle]) { context.product = azh.shopify.all_products[handle]; azh.liquid_process($liquid.closest('[data-element]'), context); } else { $.get(azh.ajaxurl + '?action=get_products&limit=1&field=handle&value=' + handle, function (data) { azh.shopify.all_products[handle] = JSON.parse(data); if (!azh.shopify.all_products[handle] || !azh.shopify.all_products[handle].length) { if (azh.any_product) { azh.shopify.all_products[handle] = [azh.any_product]; } } if (azh.shopify.all_products[handle] && azh.shopify.all_products[handle].length) { azh.shopify.all_products[handle] = azh.shopify.all_products[handle][0]; fix_product(azh.shopify.all_products[handle]); context.product = azh.shopify.all_products[handle]; azh.liquid_process($liquid.closest('[data-element]'), context); } else { $liquid.find('.az-liquid-container').prepend('
' + azh.i18n.please_select_product_in_element_settings + '
'); return; } }); } } if ($liquid.is('.az-no-liquid-context')) { azh.liquid_process($liquid.closest('[data-element]'), context); } }; azh.shopify_init = function ($wrapper) { azh.frontend_init = azh.window.get(0).azh.frontend_init; function list_refresh($liquid_child) { var $liquid = $liquid_child.closest(shopify_context_selector); azh.liquid_prepare($liquid, $liquid_child); azh.shopify_process($liquid); } $wrapper.find(shopify_context_selector).each(function () { var $liquid = azh.$(this); if (!$liquid.parents(shopify_context_selector).length) { // azh.liquid_prepare($liquid); azh.shopify_process($liquid); } }); if ($wrapper.is('script[data-liquid], .az-liquid-element.az-editable-html')) { var $liquid = $wrapper.closest(shopify_context_selector); if (!$liquid.parents(shopify_context_selector).length) { azh.liquid_prepare($liquid); azh.shopify_process($liquid); } } //az-liquid-container контейнер при редактировании любого из детей - удаляет остальных детей и запускает новый рендеринг по новому шаблону var list_refreshing = false; $wrapper.find('.az-liquid-container').children().off('azh-refresh.liquid').on('azh-refresh.liquid', function () { list_refreshing = true; list_refresh(azh.$(this)); list_refreshing = false; }); var list_child_refreshing = false; $wrapper.find('.az-liquid-container').children().off('azh-change.liquid').on('azh-change.liquid', function () { var $liquid_child = azh.$(this); list_child_refreshing = true; azh.controls_container.off('mouseleave.liquid').one('mouseleave.liquid', function (event) { if (!event.which) { if (azh.controls_container.find('.select2-container--open').length) { var $dropdown = azh.controls_container.find('.select2-container--open').prev('select'); $dropdown.one('select2:close', function (e) { list_refresh($liquid_child); list_child_refreshing = false; }); } else { list_refresh($liquid_child); list_child_refreshing = false; } } }); }); $wrapper.find(shopify_context_selector).off('azh-refresh.liquid').on('azh-refresh.liquid', function () { if (!list_refreshing) { var $liquid = $wrapper.closest(shopify_context_selector); if (!$liquid.parents(shopify_context_selector).length) { azh.liquid_prepare($liquid); azh.shopify_process($liquid); } } }); $wrapper.find(shopify_context_selector).off('azh-change.liquid').on('azh-change.liquid', function () { if (!list_child_refreshing) { var $liquid = azh.$(this).closest(shopify_context_selector); azh.controls_container.off('mouseleave.liquid').one('mouseleave.liquid', function (event) { if (!event.which) { if (azh.controls_container.find('.select2-container--open').length) { var $dropdown = azh.controls_container.find('.select2-container--open').prev('select'); $dropdown.one('select2:close', function (e) { azh.liquid_prepare($liquid); azh.shopify_process($liquid); }); } else { azh.liquid_prepare($liquid); azh.shopify_process($liquid); } } }); } }); }; }); frontend_editor_frame_init(); function formatMoney(cents, format) { var moneyFormat = '${{amount}}'; if (typeof cents === 'string') { cents = cents.replace('.', ''); } var value = ''; var placeholderRegex = /\{\{\s*(\w+)\s*\}\}/; var formatString = format || moneyFormat; function formatWithDelimiters(number, precision, thousands, decimal) { thousands = thousands || ','; decimal = decimal || '.'; if (isNaN(number) || number === null) { return 0; } number = (number / 100.0).toFixed(precision); var parts = number.split('.'); var dollarsAmount = parts[0].replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + thousands ); var centsAmount = parts[1] ? decimal + parts[1] : ''; return dollarsAmount + centsAmount; } switch (formatString.match(placeholderRegex)[1]) { case 'amount': value = formatWithDelimiters(cents, 2); break; case 'amount_no_decimals': value = formatWithDelimiters(cents, 0); break; case 'amount_with_comma_separator': value = formatWithDelimiters(cents, 2, '.', ','); break; case 'amount_no_decimals_with_comma_separator': value = formatWithDelimiters(cents, 0, '.', ','); break; case 'amount_no_decimals_with_space_separator': value = formatWithDelimiters(cents, 0, ' '); break; case 'amount_with_apostrophe_separator': value = formatWithDelimiters(cents, 2, "'"); break; } return formatString.replace(placeholderRegex, value); } Liquid.readTemplateFile = function (path) { return path; }; Liquid.Template.registerTag('section', Liquid.Tag.extend({ render: function (context) { return this.tagName + ': ' + this.markup; } })); Liquid.Template.registerTag('form', Liquid.Block.extend({ render: function (context) { var self = this; var output = ''; context.stack(function () { output = self.renderAll(self.nodelist, context).join(''); }); output = '
' + output + '
'; return output; } })); Liquid.Template.registerTag('paginate', Liquid.Block.extend({ render: function (context) { var self = this; var output = ''; context.stack(function () { output = self.renderAll(self.nodelist, context).join(''); }); return output; } })); function hashCode(str) { var hash = 0, i, chr; if (str.length === 0) return hash; for (i = 0; i < str.length; i++) { chr = str.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } return Math.abs(hash); } Liquid.Template.registerFilter({ t: function (input) { var path = input.split('.'); var current = azh.translations; for (var i in path) { if (path[i] in current) { current = current[path[i]]; } else { return input; } } if (typeof current === 'string') { return current; } else { return input; } }, time_tag: function (input) { return input; }, md5: function (input) { return hashCode(input).toString(); }, slice: function (input, begin, end) { return input.slice(begin, end); }, round: function (input, precision) { return Math.round(input).toFixed(precision); }, payment_button: function (a) { return ''; }, json: function (a) { return JSON.stringify(a); }, escape: function (input) { return input; }, url_param_escape: function (a) { return encodeURIComponent(a); }, url_escape: function (a) { return encodeURI(a); }, url_for_type: function (a) { return '/collections/types?q=' + a; }, url_for_vendor: function (a) { return '/collections/vendors?q=' + a; }, handleize: function (a) { return a; }, link_to: function (title, url) { return '' + title + ''; }, money: function (a) { return azh.window.get(0).azexo.Currency.formatMoney(a, azh.window.get(0).azexo.moneyFormat); }, money_with_currency: function (a) { return azh.window.get(0).azexo.Currency.formatMoney(a, "{{amount}}"); }, img_url: function (image_src, size) { var c = ""; if (image_src) { if (typeof image_src == 'object' && 'image' in image_src) { image_src = image_src.image; } if (typeof image_src == 'object' && 'src' in image_src) { image_src = image_src.src; } switch (size) { case "pico": c = "_16x16"; break; case "icon": c = "_32x32"; break; case "thumb": c = "_50x50"; break; case "small": c = "_100x100"; break; case "compact": c = "_160x160"; break; case "medium": c = "_240x240"; break; case "large": c = "_480x480"; break; case "grande": c = "_600x600"; break; case "original": c = "_1024x1024"; break; case "master": c = ""; break; default: c = "_" + size } var d = "." + image_src.substring(image_src.lastIndexOf(".") + 1); var e = image_src.replace(d, ""); return e += c + d; } else { return no_image; } }, }); })(window.jQuery);