1/** 2 * @namespace WPGMZA 3 * @module BoundaryInput 4 * @requires WPGMZA.EventDispatcher 5 */ 6jQuery(function($) { 7 WPGMZA.BoundaryInput = function(element, options){ 8 this.element = $(element); 9 this.dataAttributes = this.element.data(); 10 11 this.bounds = false; 12 13 this.options = {}; 14 this.parseOptions(options); 15 16 this.state = { 17 initialized : false 18 } 19 20 this.bind(); 21 } 22 23 WPGMZA.extend(WPGMZA.BoundaryInput, WPGMZA.EventDispatcher); 24 25 WPGMZA.BoundaryInput.COORD_PATTERN = /^-?\d+(?:\.\d+)?$/; 26 27 WPGMZA.BoundaryInput.createInstance = function(element, options) { 28 return new WPGMZA.BoundaryInput(element, options); 29 } 30 31 WPGMZA.BoundaryInput.prototype.parseOptions = function(options){ 32 if(options){ 33 for(var i in options){ 34 this.options[i] = options[i]; 35 } 36 } 37 38 if(this.dataAttributes){ 39 for(var i in this.dataAttributes){ 40 this.options[i] = this.dataAttributes[i]; 41 } 42 } 43 } 44 45 WPGMZA.BoundaryInput.prototype.bind = function(){ 46 this.element.find('.wpgmza-boundary-input-corner').each((index, component) => { 47 $(component).find('.wpgmza-boundary-component-input').on('input', (event) => { 48 event.preventDefault(); 49 event.stopPropagation(); 50 event.stopImmediatePropagation(); 51 }); 52 53 $(component).find('.wpgmza-boundary-component-input').on('change', (event) => { 54 event.preventDefault(); 55 event.stopPropagation(); 56 event.stopImmediatePropagation(); 57 58 this.commit(); 59 }); 60 }) 61 } 62 63 WPGMZA.BoundaryInput.prototype.receive = function(southWest, northEast){ 64 const corners = { 65 southWest : southWest ? southWest : false, 66 northEast : northEast ? northEast : false 67 }; 68 69 for(let corner in corners){ 70 let data = corners[corner]; 71 if(data){ 72 if(typeof data === 'string'){ 73 let coord = data.split(','); 74 if(coord && coord.length >= 2){ 75 let [lat, lng] = coord; 76 if(lat && lng){ 77 data = { 78 lat : lat.trim(), 79 lng : lng.trim() 80 }; 81 } else { 82 data = false; 83 } 84 } else { 85 data = false; 86 } 87 } 88 89 if(data && data instanceof Object && data.lat && data.lng){ 90 this.element.find(`.wpgmza-boundary-input-corner[data-corner="${corner}"] .wpgmza-boundary-component-input[data-boundary-component="lat"]`).val(data.lat); 91 this.element.find(`.wpgmza-boundary-input-corner[data-corner="${corner}"] .wpgmza-boundary-component-input[data-boundary-component="lng"]`).val(data.lng); 92 93 corners[corner] = data; 94 } 95 } 96 } 97 98 this.setBounds(corners); 99 } 100 101 WPGMZA.BoundaryInput.prototype.commit = function(){ 102 const corners = { 103 southWest : { 104 lat : false, 105 lng : false 106 }, 107 northEast : { 108 lat : false, 109 lng : false 110 } 111 }; 112 113 for(let corner in corners){ 114 for(let coord in corners[corner]){ 115 corners[corner][coord] = this.element.find(`.wpgmza-boundary-input-corner[data-corner="${corner}"] .wpgmza-boundary-component-input[data-boundary-component="${coord}"]`).val().trim(); 116 } 117 } 118 119 this.setBounds(corners); 120 if(this.options.update && typeof this.options.update === 'function'){ 121 const bounds = this.getBounds(); 122 if(bounds){ 123 this.options.update(this.getBounds()); 124 } 125 } 126 } 127 128 WPGMZA.BoundaryInput.prototype.reset = function(){ 129 if(this.element.find(`.wpgmza-boundary-input-corner .wpgmza-boundary-component-input[data-boundary-component]`).length){ 130 this.element.find(`.wpgmza-boundary-input-corner .wpgmza-boundary-component-input[data-boundary-component]`).val(""); 131 } 132 } 133 134 WPGMZA.BoundaryInput.prototype.getBounds = function(){ 135 return this.bounds ? this.bounds : false; 136 } 137 138 WPGMZA.BoundaryInput.prototype.setBounds = function(corners){ 139 if(this.validateCorners(corners)){ 140 this.bounds = new WPGMZA.LatLngBounds(new WPGMZA.LatLng(corners.southWest), new WPGMZA.LatLng(corners.northEast)); 141 } else { 142 this.bounds = false; 143 } 144 } 145 146 WPGMZA.BoundaryInput.prototype.validateCorners = function(corners){ 147 if(corners && corners instanceof Object && corners.southWest && corners.northEast){ 148 if(corners.northEast.lat && corners.northEast.lng && corners.southWest.lat && corners.southWest.lng){ 149 let coords = [corners.northEast.lat, corners.northEast.lng, corners.southWest.lat, corners.southWest.lng]; 150 151 for(let coord of coords){ 152 if(!WPGMZA.BoundaryInput.COORD_PATTERN.test(`${coord}`)) { 153 return false; 154 } 155 } 156 return true; 157 } 158 } 159 return false; 160 } 161});
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.