1jQuery(document).ready(function($){ 2 window['flask'] = []; 3 4 var mediaFrame = []; 5 var currentThis; 6 7 if(typeof $.fn.wpColorPicker !== 'undefined'){ 8 $( '.widget-color-picker' ).wpColorPicker(); 9 } 10 11 $(document).on('click.mojoOpenMediaManager', '.widget-choose-image', function (e) { 12 e.preventDefault(); 13 14 currentThis = $(this); 15 16 if (mediaFrame[0]) { 17 mediaFrame[0].open(); 18 return; 19 } 20 21 mediaFrame[0] = wp.media.frames.media_frame = wp.media({ 22 className: 'media-frame add-image-gallery', 23 frame: 'select', 24 multiple: false, 25 library: { 26 type: 'image' 27 } 28 }); 29 30 mediaFrame[0].on('select', function () { 31 var mediaAttachment = mediaFrame[0].state().get('selection').toJSON(); 32 33 var $container = currentThis.closest('.widget-select-image-container'); 34 35 $container.addClass('has-image'); 36 37 $container.find('img').attr('src', mediaAttachment[0].url); 38 $container.find('input.image-value').val(mediaAttachment[0].id); 39 }); 40 41 mediaFrame[0].open(); 42 }); 43 44 $(document).on('click', '.widget-remove-image', function(e){ 45 e.preventDefault(); 46 47 var $container = currentThis.closest('.widget-select-image-container'); 48 49 $container.removeClass('has-image'); 50 51 $container.find('img').attr('src', ''); 52 $container.find('input.image-value').val(''); 53 }); 54 55 $(document).on('click', '.widget-add-repeater-field', function(e){ 56 e.preventDefault(); 57 58 var $container = $(this).closest('.widget-repeater-container'); 59 var template = wp.template('repeater-' + $(this).data('shortcode')); 60 var fieldName = $(this).data('field-name'); 61 62 $container.find('.single-repeater-row:last-of-type').after("<div class='single-repeater-row'>" + template({newID: '_' + Math.random().toString(36).substr(2, 9) }) + "</div>"); 63 64 $container.find('.single-repeater-row:last-of-type :input').each(function(){ 65 $(this).attr('name', fieldName.replace('__NAME__', $(this).data('name'))); 66 }); 67 68 initWidgetControls(); 69 }); 70 71 var wysiwygTimers = []; 72 function initWidgetControls(){ 73 if(typeof $.fn.wpColorPicker !== 'undefined'){ 74 $( '.widget-color-picker' ).wpColorPicker(); 75 } 76 // wp.editor.initialize('wysiwyg_test', true); 77 78 // clear any previous timers 79 if(wysiwygTimers.length){ 80 for (var i = 0; i < wysiwygTimers.length; i++) { 81 clearInterval(wysiwygTimers[i]); 82 } 83 84 wysiwygTimers = []; 85 } 86 87 $(".widget.open .widget-wp-editor, .so-content .widget-wp-editor").each(function(){ 88 // if($(this).is(':visible')){ 89 var id = $(this).attr('id'); 90 91 wp.editor.remove(id); 92 wp.editor.initialize(id); 93 94 wysiwygTimers.push(setInterval(function(){ 95 // can we check if dirty? 96 // console.log(wp.editor.getContent(id) != $('textarea#' + id).val()); 97 $('textarea#' + id).val(wp.editor.getContent(id)); 98 99 if(wp.editor.getContent(id) != $('textarea#' + id).val()){ 100 // // console.log('trigger', id, wp.editor.getContent(id), $('textarea#' + id).val()) 101 // $('textarea#' + id).trigger('change'); 102 // $('textarea#' + id).trigger('input'); 103 } 104 }, 250)); 105 106 // wp.editor.setContent(id, $(this).val()); 107 // } 108 }); 109 110 $(".widget-html-field").each(function(){ 111 var id = $(this).attr('id'); 112 113 const flask = new CodeFlask('#' + id, { 114 language: 'html', 115 lineNumbers: true, 116 areaId: 'thing1', 117 ariaLabelledby: 'header1', 118 handleTabs: true 119 }); 120 121 flask.updateCode($(this).data('value')); 122 123 flask.onUpdate(function(code){ 124 // console.log('id', id, code) 125 126 $('textarea.widget-html-field-code[data-id="' + id + '"]').val(code); 127 }); 128 129 window['flask'].push(flask); 130 131 // console.log('#' + id, $('#' + id).parent()); 132 }); 133 134 // todo: since flask doesn't set name attributes on textareas lets set this using JS 135 // but lets do a pull request and add this functionality ourselves 136 137 } 138 139 initWidgetControls(); 140 141 // widget-updated/widget-synced 142 $(document).on('widget-updated', function(e, widget){ 143 console.log('widget-updated', widget); 144 145 initWidgetControls(); 146 }); 147 148 $(document).on('widget-added', function(e, widget){ 149 initWidgetControls(); 150 }); 151 152 $(document).on('panelsopen', function(e){
153 console.log('page builder panelsopen'); 154 155 initWidgetControls(); 156 }); 157 158 $(document).on('click', '.widget-top', function(e){ 159 console.log('widget-open'); 160 161 setTimeout(function(){ 162 console.log('widget-open'); 163 164 initWidgetControls(); 165 },500); 166 }); 167 168 // for some reason the wp.editor isn't updating the textarea so we do this manually when the widget gets saved 169 $(document).on('click', '.widget-control-save', function(e) { 170 var $wpEditors = $(this).closest('form').find('.widget-wp-editor'); 171 172 if($wpEditors.length){ 173 $wpEditors.each(function(){ 174 var wpEditorID = $(this).attr('id'); 175 176 $('textarea#' + wpEditorID).val(wp.editor.getContent(wpEditorID)); 177 }) 178 } 179 }); 180 181 $(document).on('click', '.widget-choose-url', function(e){ 182 e.preventDefault(); 183 184 wpLink.open($(this).data('editor-id')); 185 186 return false; 187 }); 188 189 $(document).on('change', '.widget-url-textarea', function(e){ 190 // console.log($(this).val()); 191 // console.log(wpLink.getUrlFromSelection($(this).val())) 192 193 194 // console.log('test', wpLink.getAttrs()); 195 196 // console.log(); 197 if(wpLink.getAttrs().href){ 198 $(this).val(wpLink.getAttrs().href + "," + (typeof wpLink.getAttrs().target !== 'undefined' ? wpLink.getAttrs().target : '_self')); 199 200 $(this).closest('div').find('.widget-url-text').text(wpLink.getAttrs().href); 201 202 wpLink.getAttrs().href = false; 203 wpLink.getAttrs().target = false; 204 } 205 }); 206 207});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.