row-list-control.js (7065B)
1 (function ($) { 2 var $preview; 3 4 function showPreview($item) { 5 $preview = jQuery('#ope_section_preview'); 6 if (!$preview.length) { 7 jQuery('body').append('<div id="ope_section_preview"></div>'); 8 $preview = jQuery('#ope_section_preview'); 9 } 10 var bounds = $item[0].getBoundingClientRect(); 11 var scrollTop = 0; 12 var scrollLeft = 0; 13 $preview.css({ 14 left: (parseInt(bounds.right) + 10 + scrollLeft) + "px", 15 top: Math.max(10, (parseInt(bounds.top) + scrollTop)) + "px", 16 'background-image': 'url("' + $item.data('preview') + '")' 17 }); 18 $preview.show(); 19 20 if ($preview.offset().top + $preview.height() + 10 > window.innerHeight) { 21 $preview.css({ 22 top: window.innerHeight - ($preview.height() + 10) 23 }) 24 } 25 } 26 27 function hidePreview() { 28 $preview = jQuery('#ope_section_preview'); 29 $preview.hide(); 30 } 31 32 function selectItem(id, $list, selectionType) { 33 var $currentItem = $list.find('li[data-id="' + id + '"]'); 34 var response = false 35 switch (selectionType) { 36 case 'toggle': 37 $currentItem.toggleClass('already-in-page'); 38 response = $currentItem.hasClass('already-in-page'); 39 break; 40 41 case 'multiple': 42 response = true; 43 break; 44 45 case 'check': 46 $currentItem.addClass('already-in-page'); 47 response = true; 48 break; 49 50 default: // radio 51 $currentItem.addClass('already-in-page'); 52 $currentItem.siblings().removeClass('already-in-page'); 53 response = true; 54 break; 55 } 56 57 return response; 58 59 } 60 61 wp.customize.controlConstructor["mod_changer"] = wp.customize.Control.extend({ 62 ready: function () { 63 64 'use strict'; 65 var control = this; 66 67 this.container.on('mouseover.mod_changer', '[data-apply="mod_changer"] .item-preview', function (event) { 68 event.preventDefault(); 69 showPreview($(this)); 70 }); 71 72 this.container.on('mouseout.mod_changer', '[data-apply="mod_changer"] .item-preview', function (event) { 73 event.preventDefault(); 74 hidePreview($(this)); 75 }); 76 77 this.container.on('click.mod_changer', '[data-apply="mod_changer"] .available-item-hover-button', function (event) { 78 event.preventDefault(); 79 event.stopPropagation(); 80 var setting = $(this).data('setting-link'), 81 itemId = $(this).data('id'), 82 $list = $(this).closest('[data-type="row-list-control"]'), 83 selectionType = $list.attr('data-selection') || "radio"; 84 85 86 if ($list.is('[data-apply="mod_changer"]')) { 87 88 var selected = selectItem(itemId, $list, selectionType); 89 90 if (selectionType === "radio") { 91 wp.customize(setting).set(itemId); 92 } else { 93 $list.trigger('cp.item.click', [itemId, selected]); 94 } 95 } 96 }); 97 } 98 }); 99 100 wp.customize.controlConstructor["presets_changer"] = wp.customize.Control.extend({ 101 102 ready: function () { 103 104 'use strict'; 105 var control = this; 106 107 108 this.container.on('mouseover.presets_changer', '[data-apply="presets_changer"] .item-preview', function (event) { 109 event.preventDefault(); 110 showPreview($(this)); 111 }); 112 113 this.container.on('mouseout.presets_changer', '[data-apply="presets_changer"] .item-preview', function (event) { 114 event.preventDefault(); 115 hidePreview($(this)); 116 }); 117 118 this.container.on('click.presets_changer', '[data-apply="presets_changer"] .available-item-hover-button', function (event) { 119 event.preventDefault(); 120 event.stopPropagation(); 121 var setting = $(this).data('setting-link'), 122 itemId = $(this).data('id'), 123 $list = $(this).closest('[data-type="row-list-control"]'), 124 selectionType = $list.attr('data-selection') || "radio"; 125 126 var varName = $(this).closest('li').data('varname'); 127 var presetsValues = window[varName][itemId]; 128 129 if (window.CP_Customizer) { 130 CP_Customizer.showLoader(); 131 CP_Customizer.setMultipleMods(presetsValues, 'postMessage', function () { 132 CP_Customizer.preview.refresh(); 133 }); 134 return; 135 } 136 137 var refreshPreview = _.debounce(function () { 138 wp.customize.previewer.refresh(); 139 }, 100); 140 Materialis.disableLinkedOptionsUpdater(); 141 _.each(presetsValues, function (value, name) { 142 var control = wp.customize.settings.controls[name]; 143 if (control) { 144 var oldTransport = wp.customize(name).transport; 145 wp.customize(name).transport = 'postMessage'; 146 var type = control.type; 147 148 if (type === "radio-html") { 149 jQuery(wp.customize.control(name).container.find('input[value="' + value + '"]')).prop('checked', true); 150 wp.customize.instance(name).set(value); 151 } else { 152 if (type === "kirki-spacing") { 153 for (var prop in value) { 154 if (value.hasOwnProperty(prop)) { 155 jQuery(wp.customize.control(name).container.find('.' + prop + ' input')).prop('value', value[prop]); 156 } 157 } 158 wp.customize.instance(name).set(value); 159 } else { 160 if (type.match('kirki')) { 161 kirkiSetSettingValue(name, value); 162 } else { 163 wp.customize.instance(name).set(value); 164 } 165 } 166 } 167 // wp.customize(name)._value = ""; 168 // wp.customize(name).set(value); 169 wp.customize(name).transport = oldTransport; 170 } 171 }); 172 wp.customize.requestChangesetUpdate().then(function () { 173 refreshPreview(); 174 Materialis.enableLinkedOptionsUpdater(); 175 }); 176 177 }); 178 } 179 }); 180 })(jQuery);