1/** 2 * @namespace WPGMZA 3 * @module MarkerLibraryDialog 4 * @requires WPGMZA 5 */ 6jQuery(function($) { 7 8 var searchTimeoutID, lazyLoaded, currentCallback; 9 10 if(!window.WPGMZA) 11 window.WPGMZA = {}; 12 13 WPGMZA.MarkerLibraryDialog = function(element) 14 { 15 var self = this; 16 17 this.element = element; 18 19 $(element).remodal(); 20 21 window.addEventListener("message", function(event) { 22 23 if(event.data.action != "download_marker") 24 return; 25 26 $.ajax({ 27 28 url: ajaxurl, 29 type: "POST", 30 data: { 31 action: "wpgmza_upload_base64_image", 32 security: wpgmza_legacy_map_edit_page_vars.ajax_nonce, 33 data: event.data.data.replace(/^data:.+?base64,/, ''), 34 mimeType: "image/png" 35 }, 36 success: function(data, status, xhr) { 37 var url = data.url; 38 currentCallback(url); 39 $(self.element).remodal().close(); 40 } 41 42 }); 43 44 }, false); 45 } 46 47 WPGMZA.MarkerLibraryDialog.prototype.open = function(callback) 48 { 49 currentCallback = callback; 50 51 $(this.element).remodal().open(); 52 53 $("iframe#mappity").attr("src", "https://www.mappity.org?wpgmza-embed=1"); 54 } 55 56 WPGMZA.MarkerLibraryDialog.prototype.onSearch = function() 57 { 58 // Escape special regex characters and build regex 59 var string = this.searchInput.val().replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); 60 var regexp = new RegExp(string, "i"); 61 62 $(this.element).find("img").each(function(index, img) { 63 var li = $(img).closest("li"); 64 var filename = $(img).attr("title").replace(/\.png$/, ""); 65 66 if(string.length && !filename.match(regexp)) 67 $(li).addClass("wpgmza-marker-library-no-result"); 68 else 69 $(li).removeClass("wpgmza-marker-library-no-result"); 70 }); 71 } 72 73 WPGMZA.MarkerLibraryDialog.prototype.onIconSelected = function(event) 74 { 75 currentCallback(event.target.src); 76 $(this.element).remodal().close(); 77 } 78 79 $(document).ready(function(event) { 80 81 var el = $(".wpgmza-marker-library-dialog"); 82 83 if(!el.length) 84 return; 85 86 87 $(el).css('display',''); 88 89 WPGMZA.markerLibraryDialog = new WPGMZA.MarkerLibraryDialog(el); 90 91 function bindButtonClickHandler(button) 92 { 93 // NB: This can be simplified once all areas use the new marker icon picker 94 var target = $(button).closest(".wpgmza-marker-icon-picker").find(".wpgmza-marker-icon-url"); 95 var preview = $(button).closest(".wpgmza-marker-icon-picker").find("img, .wpgmza-marker-icon-preview"); 96 97 $(button).on("click", function() { 98 WPGMZA.markerLibraryDialog.open(function(src) { 99 target.val(src); 100 target.change(); 101 102 if(preview.prop("tagName").match(/img/)) 103 preview.attr("src", src); 104 else 105 preview.css({"background-image": "url(" + src + ")"}); 106 107 if(!$(button).hasClass('wpgmza-marker-directions-library')) 108 $("#wpgmza_cmm>img").attr("src", src); 109 }); 110 }); 111 } 112 113 $("input.wpgmza-marker-library, button.wpgmza-marker-library").each(function(index, el) { 114 bindButtonClickHandler(el); 115 }); 116 117 }); 118 119});
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.