1 2jQuery(function ($) { 3 4 var all_original = {}; 5 var debouncers = {}; 6 7 if (window.self === window.parent && window.location.hostname !== 'localhost') { 8 console.log('top'); 9 return; 10 } 11 12 console.log('iframe'); 13 14 $("body").addClass("iframe"); 15 $("body").append('<input type="checkbox" id="enable-edit-checkbox" style="position: fixed; top: 5px; right: 5px;">'); 16 17 $("#enable-edit-checkbox").change(function() { 18 var $t = $(this); 19 20 if ($t.prop('checked')) { 21 $("body").addClass("enabled-edit"); 22 $(".live-edit").each(function() { 23 var $t = $(this); 24 25 if ($t[0].tagName === 'A') { 26 $t.data('href', $t.attr('href')); 27 $t.removeAttr('href'); 28 } 29 30 $t.attr('title', $t.data('title')); 31 32 $t.attr('contenteditable', true); 33 }); 34 } 35 else { 36 $("body").removeClass("enabled-edit"); 37 $(".live-edit").each(function() { 38 var $t = $(this); 39 40 if ($t[0].tagName === 'A') { 41 $t.attr('href', $t.data('href')); 42 } 43 44 $t.removeAttr('title'); 45 46 $t.attr('contenteditable', false); 47 }); 48 } 49 }); 50 51 $(".article-edit").click(function() { 52 var $t = $(this); 53 54 var message = { 55 action: "editArticle", 56 articleId: $t.data("article_id"), 57 scroll: window.scrollY 58 }; 59 60 window.parent.postMessage(message, "*"); 61 }); 62 63// var editor = ContentTools.EditorApp.get(); 64// editor.init('.live-edit', 'data-id'); 65 66 function debounced_update($t) { 67 var id = $t.data('id'); 68 if (!debouncers[id]) { 69 debouncers[id] = _.debounce(function() { 70 var text = $t.text().trim(); 71 72 if (all_original[id] === text) 73 return; 74 75 var a = id.split('|'); 76 var message = { 77 action: "liveEdit", 78 model: a[0], 79 attribute: a[1], 80 pk: a[2], 81 value: text 82 }; 83 84 window.parent.postMessage(message, "*"); 85 86 //console.log(`updated ${id}`); 87 all_original[id] = text; 88 }, 1000); 89 } 90 91 debouncers[id](); 92 } 93 94 $(document).on("focus", "body.enabled-edit .live-edit", function() { 95 var $t = $(this); 96 var id = $t.data('id'); 97 //console.log(`focused ${id}`); 98 var text = $t.text().trim() 99 100 all_original[id] = text; 101 }); 102 103 // $(document).on("blur", ".live-edit", function() { 104 // var $t = $(this); 105 // if ($t.text() === '') 106 // $t.text('(empty)'); 107 // }); 108 109 $(document).on("input", "body.enabled-edit .live-edit", function(e) { 110 var $t = $(this); 111 112 if ($t.text().trim() === '') { 113 $t.parent('.if-not-empty').addClass('is-empty'); 114 $t.addClass('is-empty'); 115 } 116 else { 117 $t.parent('.if-not-empty').removeClass('is-empty'); 118 $t.removeClass('is-empty'); 119 } 120 121 debounced_update($(this)); 122 }); 123 124}); 125
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.