1jQuery(document).ready(function(){ 2 /* Colorbox Init */ 3 if(jQuery('.button-plan-my-route').hasClass('button-disabled') == false){ 4 // init the colorbox only if the button hasnt been disabled 5 jQuery('.button-plan-my-route').colorbox({ 6 inline:true, 7 href: jQuery('.button-plan-my-route').parent().find('.directions-popup').clone(true).removeAttr('style'), 8 maxWidth: "95%", 9 overlayClose: true, 10 className: 'directions-colorbox', 11 }); 12 } else { 13 jQuery('.button-plan-my-route').on('click', function(e){ 14 e.preventDefault(); 15 }); 16 } 17 /* Colorbox Init */ 18 19 // this is triggered for the element 20 jQuery(document).trigger('get_directions_form_init', {inColorbox: false}); 21}); 22 23jQuery(document).bind('get_directions_form_init', function(e, callerParams){ 24 jQuery('.directions-form-container').attr('data-incolorbox', callerParams.inColorbox); 25 26 jQuery('.directions-form-container .button-turn-by-turn').on('click', function(e){ 27 e.preventDefault(); 28 // get the buttons parent container .. usual way would be .parent().parent() etc 29 // this gets the parents to the top of tree untill directions-form-container (we need this to stop somewhere) 30 // and because we need the mentioned container we get the last known parent (top) and do .parent() to retrieve the wanted container 31 var $formContainer = jQuery(this).parentsUntil('.directions-form-container').last().parent(); 32 33 var start = $formContainer.find('input[name=directions_address_start]').val(); 34 var end = $formContainer.find('input[name=directions_address_end]').val(); 35 36 var start_geo_lat = $formContainer.find('input[name=directions_address_geolocation_lat]').length > 0 ? $formContainer.find('input[name=directions_address_geolocation_lat]').val() : ""; 37 var start_geo_lng = $formContainer.find('input[name=directions_address_geolocation_lng]').length > 0 ? $formContainer.find('input[name=directions_address_geolocation_lng]').val() : ""; 38 39 if(end !== ""){ 40 // geo preference 41 if(start_geo_lat !== "" && start_geo_lng !== ""){ 42 start = start_geo_lat+","+start_geo_lng; 43 var url = "https://www.google.com/maps/dir/"+start+"/"+end; 44 window.open(url); 45 } else { 46 if(start !== ""){ 47 var url = "https://www.google.com/maps/dir/"+start+"/"+end; 48 window.open(url); 49 } else { 50 jQuery(document).trigger('get_directions_form_message', {container: $formContainer, msgid: 'directions-form-start-address-missing'}); 51 } 52 } 53 } else { 54 jQuery(document).trigger('get_directions_form_message', {container: $formContainer, msgid: 'directions-form-end-address-missing'}); 55 } 56 }); 57 58 jQuery('.directions-form-container .button-get-directions').on('click', function(e){ 59 e.preventDefault(); 60 var $formContainer = jQuery(this).parentsUntil('.directions-form-container').last().parent(); 61 var $displayContainer = $formContainer.parent().find('.directions-display-container'); 62 63 var settings = {}; 64 settings.map = JSON.parse($formContainer.find('.directions-form').attr('data-ait-map-settings')); 65 settings.directions = JSON.parse($formContainer.find('.directions-form').attr('data-ait-directions-settings')); 66 settings.directionsVisual = JSON.parse($formContainer.find('.directions-form').attr('data-ait-directions-visual')); 67 68 var start = $formContainer.find('input[name=directions_address_start]').val(); 69 var end = $formContainer.find('input[name=directions_address_end]').val(); 70 var start_geo_lat = $formContainer.find('input[name=directions_address_geolocation_lat]').length > 0 ? $formContainer.find('input[name=directions_address_geolocation_lat]').val() : ""; 71 var start_geo_lng = $formContainer.find('input[name=directions_address_geolocation_lng]').length > 0 ? $formContainer.find('input[name=directions_address_geolocation_lng]').val() : ""; 72 var runrequest = true; 73 74 if(end == ""){ 75 jQuery(document).trigger('get_directions_form_message', {container: $formContainer, msgid: 'directions-form-end-address-missing'}); 76 runrequest = false; 77 } else { 78 // geo preference 79 if(start_geo_lat !== "" && start_geo_lng !== ""){ 80 start = new google.maps.LatLng(start_geo_lat, start_geo_lng); 81 } else { 82 if(start == ""){ 83 jQuery(document).trigger('get_directions_form_message', {container: $formContainer, msgid: 'directions-form-start-address-missing'}); 84 runrequest = false; 85 } 86 } 87 } 88 89 if(runrequest){ 90 var directionsRequest = {}; 91 directionsRequest.origin = start; 92 directionsRequest.destination = end; 93 directionsRequest.travelMode = $formContainer.find('select[name=directions_settings_travelMode]').val(); 94 directionsRequest.avoidHighways = $formContainer.find('input[name=directions_settings_avoidHighways]').is(':checked'); 95 directionsRequest.avoidTolls = $formContainer.find('input[name=directions_settings_avoidTolls]').is(':checked'); 96 97 var routeBoxerRequest = {}; 98 /* fix for decimal numbers entered into the input */ 99 routeBoxerRequest.radius = false; 100 if($formContainer.find('input[name=directions_settings_category_radius]').length > 0){ 101 var inputval = parseFloat($formContainer.find('input[name=directions_settings_category_radius]').val()); 102 var inputmin = parseFloat($formContainer.find('input[name=directions_settings_category_radius]').attr('min')); 103 // here parse the inputunittype .. always convert into km 104 var inputunits = $formContainer.find('input[name=directions_settings_category_radius]').attr('data-units'); 105 106 routeBoxerRequest.radius = inputval <= 0 ? inputmin : inputval; 107 routeBoxerRequest.radius = inputunits === 'mi' ? routeBoxerRequest.radius * 1.609344 : routeBoxerRequest.radius; 108 } 109 /* fix for decimal numbers entered into the input */ 110 routeBoxerRequest.category = $formContainer.find('select[name=directions_settings_categories]').length > 0 ? $formContainer.find('select[name=directions_settings_categories]').val() : false; 111 routeBoxerRequest.runrequest = routeBoxerRequest.radius !== false && routeBoxerRequest.category !== false ? true : false; 112 113 jQuery(document).trigger('get_directions_directions_init', {formContainer: $formContainer, displayContainer: $displayContainer, directionsRequest: directionsRequest, routeBoxerRequest: routeBoxerRequest, settings: settings}); 114 } 115 }); 116 117 jQuery('.directions-form-container input[name=directions_address_geolocation]').on('click', function(){ 118 var $formContainer = jQuery(this).parentsUntil('.directions-form-container').last().parent(); 119 120 if(jQuery(this).is(':checked')){ 121 if(navigator.geolocation) { 122 $formContainer.find('.address').addClass('loader'); 123 124 navigator.geolocation.getCurrentPosition(function(position){ 125 $formContainer.find('input[name=directions_address_geolocation_lat]').val(position.coords.latitude); 126 $formContainer.find('input[name=directions_address_geolocation_lng]').val(position.coords.longitude); 127 // hide the address input 128 //$formContainer.find('input[name="directions_address_start"]').parent().parent().hide(); 129 $startAddress = $formContainer.find('input[name="directions_address_start"]'); 130 $startAddress.attr('disabled', 'disabled'); 131 132 // try google reverse geocode 133 var geocoder = new google.maps.Geocoder; 134 geocoder.geocode({'location': {lat: position.coords.latitude, lng: position.coords.longitude} }, function(results, status) { 135 if (status === google.maps.GeocoderStatus.OK) { 136 if (results[1]) { 137 $startAddress.val(results[1].formatted_address); 138 } else { 139 // no results = use default text 140 $startAddress.val($startAddress.attr('data-geolocation-text'));
141 } 142 } else { 143 // geocoder failed = use default text 144 $startAddress.val($startAddress.attr('data-geolocation-text')); 145 } 146 147 // hide loader 148 $formContainer.find('.address').removeClass('loader'); 149 }); 150 }, function(positionError){ 151 jQuery(document).trigger('get_directions_form_message', {container: $formContainer, msgid: 'directions-geolocation-error'}); 152 $formContainer.find("input[name=directions_address_geolocation]").get(0).checked = false; 153 // hide loader 154 $formContainer.find('.address').removeClass('loader'); 155 }); 156 } else { 157 jQuery(document).trigger('get_directions_form_message', {container: $formContainer, msgid: 'directions-no-geolocation-support'}); 158 $formContainer.find("input[name=directions_address_geolocation]").get(0).checked = false; 159 } 160 } else { 161 // show the address input 162 //$formContainer.find('input[name="directions_address_start"]').parent().parent().show(); 163 $formContainer.find('input[name="directions_address_start"]').val(""); 164 $formContainer.find('input[name="directions_address_start"]').removeAttr('disabled'); 165 // clear the lat lng fields 166 $formContainer.find('input[name=directions_address_geolocation_lat]').val(""); 167 $formContainer.find('input[name=directions_address_geolocation_lng]').val(""); 168 } 169 }); 170}); 171 172/* Form Messages */ 173jQuery(document).bind('get_directions_form_message', function(e, callerParams){ 174 var $messageContainer = callerParams.container.find('.'+callerParams.msgid); 175 $messageContainer.fadeIn(0, function(){ 176 if(callerParams.container.attr('data-incolorbox') === "true"){ 177 jQuery.colorbox.resize(); 178 } 179 }).delay(3000).fadeOut(250, function(){ 180 if(callerParams.container.attr('data-incolorbox') === "true"){ 181 jQuery.colorbox.resize(); 182 } 183 }); 184}); 185/* Form Messages */ 186 187jQuery(document).bind('get_directions_form_reset', function(e, callerParams){ 188 var $formContainer = callerParams.formContainer; 189 // text inputs 190 $formContainer.find('input[type="text"]').val(""); 191 // selects 192 $formContainer.find('select').prop('selectedIndex',0); 193 // checkboxes 194 $formContainer.find('input[type="checkbox"]').each(function(){ 195 if(jQuery(this).parentsUntil('.form-input-container').last().attr('data-default-checked')){ 196 jQuery(this).attr('checked', "checked"); 197 } else { 198 jQuery(this).removeAttr('checked'); 199 } 200 }); 201}); 202 203/* Colorbox */ 204jQuery(document).bind('cbox_complete', function(){ 205 // set up pretty selectbox 206 if(typeof jQuery.selectbox !== "undefined"){ 207 jQuery('.directions-form-container select').selectbox(); 208 } 209 210 // this is triggered for the colorbox 211 jQuery(document).trigger('get_directions_form_init', {inColorbox: true}); 212 213 jQuery.colorbox.resize(); 214}); 215/* Colorbox */ 216 217jQuery(document).bind('get_directions_map_init', function(e, callerParams){ 218 var $formContainer = callerParams.formContainer; 219 var $displayContainer = callerParams.displayContainer; // jQuery object 220 221 if($formContainer.attr('data-incolorbox') === "true"){ 222 // create new dom to store the map and panel 223 // check if the item detail has .map-container .. if hasnt ... create the container near the button 224 if(jQuery('.item-content-wrap .map-container').length != 0){ 225 // map exist .. use this 226 var $oldMapContainer = jQuery('.item-content-wrap .map-container'); 227 $oldMapContainer.html(""); 228 $oldMapContainer.addClass('directions-display-container'); 229 $oldMapContainer.append('<div class="content"><div class="directions-map"><div class="content"></div></div><div class="directions-panel"><div class="content"></div></div></div>'); 230 $displayContainer = $oldMapContainer; 231 } else { 232 if(jQuery('.single-ait-item .directions-display-container').length != 0){ 233 // element is present 234 $displayContainer = jQuery('.single-ait-item .directions-display-container'); 235 } else { 236 // create new dom node 237 // or dont render the data 238 } 239 } 240 } 241 242 var $mapContainer = $displayContainer.find('.directions-map'); 243 var $mapContent = $mapContainer.find('.content'); 244 var $panelContainer = $displayContainer.find('.directions-panel'); 245 var $panelContent = $panelContainer.find('.content'); 246 247 $displayContainer.show(); 248 $mapContent.height(500); 249 250 var mapSettings = callerParams.settings.map; 251 mapSettings.center = {lat: 40.771, lng: -73.974}; 252 var map = new google.maps.Map($mapContent.get(0), mapSettings); 253 254 /* icon setup */ 255 var directionsVisual = callerParams.settings.directionsVisual; 256 var markerLegs = callerParams.directionsResponse.routes[0].legs[0]; 257 258 var markerStart = new google.maps.Marker({ 259 position: markerLegs.start_location, 260 map: map 261 }); 262 263 var markerEnd = new google.maps.Marker({ 264 position: markerLegs.end_location, 265 map: map 266 }); 267 268 if(directionsVisual.markerStart !== ""){ 269 markerStart.setIcon({ 270 url: directionsVisual.markerStart, 271 size: new google.maps.Size( 100, 100 ), 272 origin: new google.maps.Point( 0, 0 ), 273 anchor: new google.maps.Point( 33, 60 ) 274 }); 275 } else { 276 markerStart.setIcon({
277 url: "http://mt.googleapis.com/maps/vt/icon/name=icons/spotlight/spotlight-waypoint-a.png&text=A&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48&scale=1", 278 }); 279 } 280 281 if(directionsVisual.markerEnd !== ""){ 282 markerEnd.setIcon({ 283 url: directionsVisual.markerEnd, 284 size: new google.maps.Size( 100, 100 ), 285 origin: new google.maps.Point( 0, 0 ), 286 anchor: new google.maps.Point( 33, 60 ) 287 }); 288 } else { 289 markerEnd.setIcon({ 290 url: "http://mt.googleapis.com/maps/vt/icon/name=icons/spotlight/spotlight-waypoint-b.png&text=B&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48&scale=1", 291 }); 292 } 293 /* icon setup */ 294 295 /* route markers */ 296 if(callerParams.routeBoxerRequest.runrequest){ 297 var routeBoxer = new RouteBoxer(); 298 var routeBoxes = routeBoxer.box(callerParams.directionsResponse.routes[0].overview_path, callerParams.routeBoxerRequest.radius); 299 300 var routeBounds = {}; 301 routeBounds.northEast = []; 302 routeBounds.southWest = []; 303 304 for (var i = 0; i < routeBoxes.length; i++){ 305 routeBounds.northEast[i] = routeBoxes[i].getNorthEast().lat()+","+routeBoxes[i].getNorthEast().lng();
306 routeBounds.southWest[i] = routeBoxes[i].getSouthWest().lat()+","+routeBoxes[i].getSouthWest().lng(); 307 } 308 309 jQuery.ajax(ait.ajax.url, { 310 data: { 311 'action': 'getRouteItems', 312 'data': { 313 'category': callerParams.routeBoxerRequest.category, 314 'bounds': routeBounds, 315 } 316 }, 317 method: 'POST', 318 cache: false, 319 dataType: 'json', 320 success: function(json){ 321 for(index in json.data){ 322 jQuery(document).trigger('get_directions_map_attach_marker', {displayContainer: $displayContainer, map: map, item: json.data[index]}); 323 } 324 }, 325 error: function(xhr){ 326 console.error('AIT Get Directions: Ajax failed to retrieve route items'); 327 }, 328 }); 329 } 330 /* route markers */ 331 332 callerParams.directionsDisplay.setMap(map); 333 $panelContent.html(""); 334 callerParams.directionsDisplay.setPanel($panelContent.get(0)); 335 336 /* attach checker for a dom change */ 337 jQuery(document).trigger('get_directions_panel_change', {panel: $panelContent, directionsVisual: directionsVisual}); 338 /* attach checker for a dom change */ 339 340 /* scroll to container */ 341 var mapOffset = $mapContent.offset().top; 342 if(jQuery('body').hasClass('sticky-menu-enabled')){ 343 mapOffset = mapOffset - parseInt(jQuery('body').find('.sticky-menu').outerHeight(true)); 344 } 345 if(jQuery('body').hasClass('admin-bar')){ 346 mapOffset = mapOffset - parseInt(jQuery('body').find('#wpadminbar').outerHeight(true)); 347 } 348 jQuery('html, body').animate({ 349 scrollTop: mapOffset 350 }, 1000); 351 /* scroll to container */ 352 353 /* map activation button */ 354 if(Modernizr.touchevents){ 355 map.setOptions({ draggable : false }); 356 jQuery(document).trigger('get_directions_map_attach_button', {map: map}); 357 } 358 /* map activation button */ 359}); 360 361jQuery(document).bind('get_directions_directions_init', function(e, callerParams){ 362 var $formContainer = callerParams.formContainer; // jQuery object 363 364 var directionsSettings = callerParams.settings.directions; 365 366 var directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true}); 367 var directionsService = new google.maps.DirectionsService; 368 369 var directionsRequest = directionsSettings; 370 jQuery.extend( directionsRequest, callerParams.directionsRequest ); 371 372 directionsService.route(directionsRequest, function(response, status) { 373 switch(status){ 374 case google.maps.DirectionsStatus.OK: 375 // trigger map init 376 directionsDisplay.setDirections(response); 377 jQuery(document).trigger('get_directions_map_init', {formContainer: callerParams.formContainer, displayContainer: callerParams.displayContainer, directionsDisplay: directionsDisplay, directionsResponse: response, routeBoxerRequest: callerParams.routeBoxerRequest, settings: callerParams.settings}); 378 379 if($formContainer.attr('data-incolorbox') === "true"){ 380 /* reset the form */ 381 jQuery(document).trigger('get_directions_form_reset', {formContainer: $formContainer}); 382 /* reset the form */ 383 384 jQuery.colorbox.close(); 385 } 386 break; 387 case google.maps.DirectionsStatus.NOT_FOUND: 388 // address not found error 389 jQuery(document).trigger('get_directions_form_message', {container: $formContainer, msgid: 'directions-address-not-found'}); 390 break; 391 case google.maps.DirectionsStatus.ZERO_RESULTS: 392 // route not found error 393 jQuery(document).trigger('get_directions_form_message', {container: $formContainer, msgid: 'directions-route-not-found'}); 394 break; 395 default: 396 // all other error => google.maps.DirectionsStatus.UNKNOWN_ERROR 397 jQuery(document).trigger('get_directions_form_message', {container: $formContainer, msgid: 'directions-undefined-error'}); 398 break; 399 } 400 }); 401}); 402 403jQuery(document).bind('get_directions_map_attach_marker', function(e, callerParams){ 404 var $displayContainer = callerParams.displayContainer; 405 406 var map = callerParams.map; 407 var item = callerParams.item; 408 409 var marker = new google.maps.Marker({ 410 position: new google.maps.LatLng(item.marker.position.lat, item.marker.position.lng), 411 title: item.marker.title, 412 icon: item.marker.icon, 413 map: map, 414 }); 415 marker.addListener('click', function(){ 416 $displayContainer.find('.infoBox').remove(); 417 418 var infoWindow = new InfoBox({ 419 pixelOffset: new google.maps.Size(-145, -203), 420 closeBoxURL: item.close_image, 421 enableEventPropagation: true, 422 zIndex: 99, 423 disableAutoPan: false, 424 maxWidth: 150, 425 infoBoxClearance: new google.maps.Size(1, 1), 426 boxStyle: { 427 background: "white", 428 opacity: 1, 429 width: "290px" 430 } 431 }); 432 433 infoWindow.setContent(item.infobox); 434 infoWindow.open(map, marker); 435 map.panTo(marker.getPosition()); 436 }); 437}); 438 439jQuery(document).bind('get_directions_panel_change', function(e,
439callerParams){ 440 var checkInterval = setInterval(function(){ 441 // check for dom change 442 if(callerParams.panel.html() != ""){ 443 var $markerStart = callerParams.panel.find('img:first'); 444 var $markerEnd = callerParams.panel.find('img:last'); 445 446 if(callerParams.directionsVisual.markerStart !== ""){ 447 $markerStart.attr('src', callerParams.directionsVisual.markerStart); 448 $markerStart.css({'width': '40px'}); 449 } 450 if(callerParams.directionsVisual.markerEnd !== ""){ 451 $markerEnd.attr('src', callerParams.directionsVisual.markerEnd); 452 $markerEnd.css({'width': '40px'}); 453 } 454 455 clearInterval(checkInterval); 456 } 457 }, 100); 458}); 459 460jQuery(document).bind('get_directions_map_attach_button', function(e, callerParams){ 461 var map = callerParams.map; 462 463 var button = document.createElement('div'); 464 button.className = "draggable-toggle-button"; 465 466 var innerhtmlstyle = 'style="font-size: 14px"' 467 button.innerHTML = '<i class="fa fa-lock" '+innerhtmlstyle+'></i>'; 468 469 button.style.margin = "10px"; 470 button.style.borderRadius = "2px"; 471 472 button.onclick = function(e){ 473 if(jQuery(this).hasClass('active')){ 474 jQuery(this).removeClass('active').html('<i class="fa fa-lock" '+innerhtmlstyle+'></i>'); 475 map.setOptions({ draggable : false }); 476 } else { 477 jQuery(this).addClass('active').html('<i class="fa fa-unlock" '+innerhtmlstyle+'></i>'); 478 map.setOptions({ draggable : true }); 479 } 480 }; 481 map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(button); 482}); 483 484/* functionality to get directions to the marker displayed on map */ 485/* beta for now */ 486/*jQuery(document).bind('get_directions_map_infobox_directions', function(e, callerParams){ 487 var $caller = jQuery(callerParams.caller.srcElement); // this is the span on which the user clicked 488 var $parent = $caller.parent(); // this should be a 489 490 var lat = parseFloat($parent.attr('data-position-lat')); 491 var lng = parseFloat($parent.attr('data-position-lng')); 492 493 var $displayContainer = $caller.parentsUntil('.directions-display-container').last().parent(); 494 var $formContainer = $displayContainer.parent().find('.directions-form-container'); // only in element .. try the length 495 496 var settings = {}; 497 settings.map = JSON.parse($formContainer.find('.directions-form').attr('data-ait-map-settings')); 498 settings.directions = JSON.parse($formContainer.find('.directions-form').attr('data-ait-directions-settings')); 499 settings.directionsVisual = JSON.parse($formContainer.find('.directions-form').attr('data-ait-directions-visual')); 500 501 var start = $formContainer.find('input[name=directions_address_start]').val(); 502 var start_geo_lat = $formContainer.find('input[name=directions_address_geolocation_lat]').length > 0 ? $formContainer.find('input[name=directions_address_geolocation_lat]').val() : ""; 503 var start_geo_lng = $formContainer.find('input[name=directions_address_geolocation_lng]').length > 0 ? $formContainer.find('input[name=directions_address_geolocation_lng]').val() : ""; 504 if(start_geo_lat !== "" && start_geo_lng !== ""){ 505 start = new google.maps.LatLng(start_geo_lat, start_geo_lng); 506 } 507 508 var directionsRequest = {}; 509 directionsRequest.origin = start; // this should be the the original requests place 510 directionsRequest.destination = lat+", "+lng; 511 directionsRequest.travelMode = $formContainer.find('select[name=directions_settings_travelMode]').val(); 512 directionsRequest.avoidHighways = $formContainer.find('input[name=directions_settings_avoidHighways]').is(':checked'); 513 directionsRequest.avoidTolls = $formContainer.find('input[name=directions_settings_avoidTolls]').is(':checked'); 514 515 var routeBoxerRequest = {}; 516 routeBoxerRequest.radius = $formContainer.find('input[name=directions_settings_category_radius]').length > 0 ? parseInt($formContainer.find('input[name=directions_settings_category_radius]').val()) : false; 517 routeBoxerRequest.category = $formContainer.find('select[name=directions_settings_categories]').length > 0 ? $formContainer.find('select[name=directions_settings_categories]').val() : false; 518 routeBoxerRequest.runrequest = routeBoxerRequest.radius !== false && routeBoxerRequest.category !== false ? true : false; 519 520 jQuery(document).trigger('get_directions_directions_init', { 521 formContainer: $formContainer, 522 displayContainer: $displayContainer, 523 directionsRequest: directionsRequest, 524 routeBoxerRequest: routeBoxerRequest, 525 settings: settings 526 }); 527});*/ 528/* beta for now */ 529/* function to get directions to the marker displayed on map */
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.