1//console.log( "OMNIBOX MAPBOX", "omnibox-search-4372876595664997438-p" ); 2 3;(function( webletId ) { 4 5 var jQuery = window.jQuery || window.$; 6 7 if( window._gmrp && window._gmrp.$ ) { 8 jQuery = window._gmrp.$; 9 } 10 11 var $beds = jQuery( "#" + webletId + " [name=unibox-bedrooms]" ); 12 var $baths = jQuery( "#" + webletId + " [name=unibox-bathrooms]" ); 13 var $propTypes = jQuery( "#" + webletId + " [name=unibox-prop-types]" ); 14 var $transTypes = jQuery( "#" + webletId + " [name=unibox-trans-types]" ); 15 var $priceMin = jQuery( "#" + webletId + " [name=unibox-price-min]" ); 16 var $priceMax = jQuery( "#" + webletId + " [name=unibox-price-max]" ); 17 var $submit = jQuery( "#" + webletId + " [name=unibox-run]" ); 18 19 var $ctx = jQuery( "#" + webletId + " [name=unibox-search-context]" ); 20 var $acct = jQuery( "#" + webletId + " [name=unibox-search-account]" ); 21 var $listingType = jQuery( "#" + webletId + " [name=unibox-search-listing-type]" ); 22 var $mapName = jQuery( "#" + webletId + " [name=unibox-search-map]" ); 23 var $region = jQuery( "#" + webletId + " [name=unibox-search-region]" ); 24 25 var country = "CA" || "CA"; 26 var region = "GV_NEW" || "GV"; 27 var initLat = 49.268 || 49.25; 28 var initLng = -123.155 || -123.088; 29 30 $priceMin.on( "keydown", function(e) { 31 if( e.keyCode == 13 ) { 32 setTimeout( function() { 33 runUnibox(); 34 }, 100 ); 35 } 36 }); 37 $priceMax.on( "keydown", function(e) { 38 if( e.keyCode == 13 ) { 39 setTimeout( function() { 40 runUnibox(); 41 }, 100 ); 42 } 43 }); 44 45 46 function runUnibox() { 47 48 49 var location = jQuery( "#" + webletId + " [name=unibox-field]" ).data(); 50 var locationValue = jQuery( "#" + webletId + " [name=unibox-field]" ).val(); 51 52 var beds = $beds.val() || ""; 53 var baths = $baths.val() || ""; 54 var propType = $propTypes.val() || ""; 55 var transType = $transTypes.val() || ""; 56 var priceMin = $priceMin.val() || ""; 57 var priceMax = $priceMax.val() || ""; 58 var ctx = $ctx.val() || "recip"; 59 var acct = $acct.val() || "-"; 60 var listingType = $listingType.val() || "AUTO"; 61 var region = $region.val() || ""; 62 63 var page = "recip.html"; 64 if( ctx == "vow" ) { 65 page = "vow.html"; 66 } 67 68 var qs = ""; 69 70 if( ( "GV" == region || "EDMONTON" == region ) && findUniboxDropdownLabel( $submit, "unibox-prop-types" ).indexOf( " (Commercial)" ) != -1 ) { 71 qs += "listingType=AUTO_COMM&"; 72 } 73 else if( listingType && listingType != "AUTO" ) { 74 qs += "listingType=" + listingType + "&"; 75 } 76 77 if( location && location.properties && location.properties['mls'] ) { 78 qs += "i_mlsnum=" + escape(location.properties['mls']) + "&"; 79 } 80 else if( locationValue && isMLSNumber( locationValue ) ) { 81 qs += "i_mlsnum=" + escape(locationValue) + "&"; 82 } 83 else { 84 85 if( beds ) { 86 qs += "i_beds=" + escape(beds) + "-" + "&"; 87 } 88 if( baths ) { 89 qs += "i_baths=" + escape(baths) + "-" + "&"; 90 } 91 92 if( priceMin ) { 93 priceMin = priceMin.replace(/[^0-9\.]+/g, '' ); 94 if( !isNaN( parseFloat(priceMin) ) ) { 95 qs += "i_price_from=" + escape( priceMin ) + "&"; 96 } 97 } 98 if( priceMax ) { 99 priceMax = priceMax.replace(/[^0-9\.]+/g, '' ); 100 if( !isNaN( parseFloat(priceMax) ) ) { 101 qs += "i_price_to=" + escape( priceMax ) + "&"; 102 } 103 } 104 105 if( propType ) { 106 if( ( "GV" == region || "EDMONTON" == region ) && findUniboxDropdownLabel( $submit, "unibox-prop-types" ).indexOf( " (Commercial)" ) != -1 ) { 107 qs += "i_prop_type_com=" + escape( propType ) + "&"; 108 } 109 else { 110 qs += "i_prop_type=" + escape( propType ) + "&"; 111 } 112 } 113 114 if( transType ) { 115 qs += "i_trans_type=" + escape( transType ) + "&"; 116 } 117 118 if( location ) { 119 if( location.place_name ) { 120 qs += "i_location=" + escape( location.place_name ) + "&"; 121 } 122 if( location.bbox ) { 123 // we are doing lat,lng,lat,lng for backward compat 124 qs += "i_bounds=" + location.bbox[1] + "," + location.bbox[0] + "," + location.bbox[3] + "," + location.bbox[2] + "&"; 125 } 126 else if( location.center ) { 127 qs += "i_place=" + location.center[1] + "," + location.center[0] + "&"; 128 } 129 } 130 } 131 132 console.log( location, beds, baths, propType, priceMin, priceMax, ctx, acct, listingType, region ); 133 134 //var url = "/wps/-/noframe~true/" + ctx + "/" + acct + "/idx.search?"; 135 //url += qs; 136 137 console.log( page + "?autosearch&" + qs ); 138 window.location = page + "?autosearch&" + qs; 139 } 140 141 function findUniboxDropdownLabel( from, selector ) { 142 143 return jQuery( from ).closest( ".unibox-search" ).find( "[name=" + selector + "] option:selected" ).text() || ""; 144 } 145 146 147 function isMLSNumber( val ) {
148 // mls numbers can be a123456 ab123456 123456 123455a 123456ab ... we allow up to 6 letters and no less 149 // than 6 digits 150 var out = /^\s*[A-Za-z]{0,6}\d{6,}[A-Za-z]{0,6}\s*$/.test(val); 151 152 if( "DDF" == region ) { 153 out = /^\s*[A-Za-z]{0,6}\d{3,}[A-Za-z]{0,6}\s*$/.test(val); 154 } 155 156 return out; 157 } 158 159 function mlsNumberGeocoder( query ) { 160 161 if( query.indexOf( 'Find MLS\xAE # ' ) == 0 ) { 162 query = query.replace( 'Find MLS\xAE # ', '' ).trim(); 163 } 164 165 if( isMLSNumber( query ) ) { 166 return [{ 167 center: [0, 0], 168 geometry: { 169 type: "Point", 170 coordinates: [0, 0] 171 }, 172 place_name: 'Find MLS\xAE # ' + query, 173 place_type: ['coordinate'], 174 properties: { 175 mls : query 176 }, 177 type: 'Feature' 178 }]; 179 } 180 else { 181 return null; 182 } 183 } 184 185 function CustomGeocoder(options) { 186 MapboxGeocoder.call(this, options ); 187 }; 188 CustomGeocoder.prototype = Object.create( MapboxGeocoder.prototype, { 189 // custom class code here 190 onAdd : { 191 value : function( $el ) { 192 193 var out = MapboxGeocoder.prototype.onAdd.apply( this, null ); 194 195 var _this = this; 196 197 this._inputEl.setAttribute('name','unibox-field'); 198 this._inputEl.classList.add('unibox-field'); 199 this._inputEl.setAttribute('autocomplete', 'off' ); 200 this._inputEl.setAttribute('autocorrect', 'off' ); 201 this._inputEl.setAttribute('autocapitalize', 'off' ); 202 this._inputEl.setAttribute('spellcheck','false'); 203 204 this._inputEl.addEventListener('keydown', function(e) { 205 206 if( e.keyCode == 13 ) { 207 setTimeout( function() { 208 runUnibox(); 209 }, 100 ); 210 } 211 setTimeout( function() { 212 if( e.metaKey && _this._inputEl.value ) { 213 // force for copy and pasted MLS® numbers 214 if (_this._inputEl.value.length >= _this.options.minLength) { 215 _this._geocode(_this._inputEl.value); 216 } 217 } 218 },10); 219 }); 220 221 222 this.on( 'result', function( e ) { 223 224 var result = e.result || e; 225 226 //console.log( result ); 227 228 if( result.properties && result.properties['mls'] ) { 229 //page( "/wps/-/tmpl~v2,noframe~true/" + _gmrp.settings["CONTEXT"] + "/" + 230 // _gmrp.settings["ACCOUNT_ID"] + "/mls-" + result.properties['mls'] + "?offmarket=true"); 231 console.log( "mls", result.properties['mls'] ); 232 jQuery( _this._inputEl ).data( result ); 233 } 234 else if( result.bbox ) { 235 //_this.map.fitBounds( result.bbox ); 236 console.log( "bbox", result.bbox ); 237 jQuery( _this._inputEl ).data( result ); 238 } 239 else if( result.center ) { 240 console.log( "center", result.center ); 241 jQuery( _this._inputEl ).data( result ); 242 } 243 }); 244 245 return out; 246 } 247 } 248 }); 249 CustomGeocoder.prototype.constructor = CustomGeocoder; 250 251 var $locField = jQuery( "#" + webletId + " input[name=unibox-field]" ); 252 253window._gmrp_geoFilter = function(item,index,items) { 254 255 var overrides = { 256 "Greenwood, Nova Scotia, Canada" : { // Greenwood, Nova Scotia 257 center: [-64.934722, 44.971944], 258 // sw, ne trigge 'mrp.debug.map.bounds' on document to dump 259 bbox : [-64.98192887852869,44.95217585223236,-64.87687211583203,44.990491318266294] 260 }, 261 "neighborhood.7899298212961420" : { 262 // replacing "Scarborough City Centre, M1P 4P5, Etobicoke, Ontario, Canada" 263 // with more appropriate "Scarborough, Toronto" 264 text: "Scarborough, Toronto", 265 place_name: "Scarborough, Toronto", 266 center: [-79.3128433, 43.7589442 ], 267 bbox: [ -79.36823308452246, 43.707401993492596, -79.09305989726784, 43.81241425080441 ] 268 } 269 }; 270 271 272 if( item.place_name ) { 273 var override = overrides[item.place_name]; 274 if( override ) { 275 item.center = override.center; 276 item.bbox = override.bbox; 277 } 278 override = overrides[item.id]; 279 if( override ) { 280 item.place_name = override.place_name; 281 item.text = override.text || item.text; 282 item.center = override.center; 283 item.bbox = override.bbox; 284 } 285 } 286 return true; 287} 288 289 var geocoder = new CustomGeocoder({ 290 accessToken: "pk.eyJ1IjoibXlyZWFscGFnZSIsImEiOiJjbXB5a2NqdnYwN3EyMnRuM3BjaDk4azZ5In0.jMuTPO0WO6IO5ce3ydzwkw", 291 country : country, 292 trackProximity : false, // no map, no proximity 293 flyTo: false, 294 proximity : { longitude : initLng, latitude : initLat }, 295 placeholder : $locField.attr( "placeholder" ) || "", 296 filter: window._gmrp_geoFilter || null, 297 //types : 'postcode,district,neighborhood,locality,address', 298 localGeocoder : mlsNumberGeocoder 299 }); 300 301 var wrapper = geocoder.onAdd( null ); // no map 302 303 //$locField.parent().addClass( wrapper.className ); 304 305 $locField.parent().html("").append( jQuery(wrapper).children() ); 306 307 $submit.on( "click", function() { 308 runUnibox(); 309 }); 310 311 312 313})( "omnibox-search-4372876595664997438-p" );
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.