1;(function($, window, document) { 2 var $win = $(window); 3 var $doc = $(document); 4 var markers = []; 5 6 $doc.ready(function () { 7 /** 8 * Custom Placeholder 9 */ 10 $('.ghmi-field').on('focusin', function () { 11 var $current_field = $(this); 12 13 if ($current_field.val() == $current_field.attr('title')) { 14 $current_field.val(''); 15 } 16 }).on('focusout', function () { 17 var $current_field = $(this); 18 19 if ($current_field.val() == '') { 20 $current_field.val($current_field.attr('title')); 21 } 22 }); 23 24 /** 25 * Checkboxes 26 */ 27 custom_checkboxes(); 28 function custom_checkboxes() { 29 var $result_form = $('.ghmi-search-results') 30 var $result_form_checkboxes = $result_form.find('input[type="checkbox"]'); 31 32 $result_form_checkboxes.each(function () { 33 var $current_checkbox = $(this); 34 35 $current_checkbox.addClass('hidden'); 36 $current_checkbox.after('<i class="ghmi-icon-checkbox"></i>'); 37 38 $current_checkbox.on('click', function () { 39 toggle_marker_in_route_plan($current_checkbox.closest('.ghmi-form-set-row').data('marker-id'), $current_checkbox.attr('checked')); 40 }); 41 }); 42 43 var $result_form_custom_checkboxes = $result_form.find('.ghmi-icon-checkbox'); 44 $result_form_custom_checkboxes.on('click', function () { 45 var $current_checkbox = $(this); 46 47 $current_checkbox.toggleClass('ghmi-checked'); 48 49 if ($current_checkbox.is('.ghmi-checked')) { 50 $current_checkbox.siblings('input[type="checkbox"]').attr('checked', true); 51 } else { 52 $current_checkbox.siblings('input[type="checkbox"]').attr('checked', false); 53 } 54 55 toggle_marker_in_route_plan($current_checkbox.closest('.ghmi-form-set-row').data('marker-id'), $current_checkbox.siblings('input[type="checkbox"]').attr('checked')); 56 }); 57 58 var $result_form_set_labels = $result_form.find('label'); 59 $result_form_set_labels.on('click', function () { 60 var $current_label = $(this); 61 62 $current_label.siblings('.ghmi-icon-checkbox').toggleClass('ghmi-checked'); 63 }); 64 } 65 66 /** 67 * Toggle the visibility of a single marker in the route plan 68 */ 69 function toggle_marker_in_route_plan(markerID, checked) { 70 var $markers = $('.ghmi-form-markers-set'); 71 72 if ( checked != 'checked' ) { 73 $markers.find('.ghmi-form-marker-set-row[data-marker-id="' + markerID + '"]').remove(); 74 markers[markerID]['marker'].setIcon(ghmi_details.plugin_dir + '/css/images/map-marker.png'); 75 } else { 76 /* HTML */ 77 var $form_point_row = $('<li/>', { 78 'class': 'ghmi-form-marker-set-row', 79 'data-marker-id': markerID 80 }).append( 81 $('<i/>', { 82 'class': 'ghmi-icon-drag' 83 }) 84 ).append( 85 $('<div/>', { 86 'class': 'ghmi-form-point-label' 87 }).text(markers[markerID]['title'].substr(0, 20) + '...') 88 ); 89 90 $form_point_row.appendTo($markers); 91 markers[markerID]['marker'].setIcon('https://maps.gstatic.com/mapfiles/ms2/micons/red-dot.png'); 92 } 93 94 $markers.sortable(); 95 } 96 97 /** 98 * Search Form 99 */ 100 101 /* Handles the form submit */ 102 var $searchForm = $('.ghmi-search-form form'); 103 $searchForm.on('submit', function (event) { 104 event.preventDefault(); 105 106 $('.ghmi-ajax-loader').addClass('visible'); 107 108 $('.ghmi-form-marker-set-row').remove(); 109 110 $.ajax({ 111 url: $searchForm.attr('action'), 112 type: $searchForm.attr('method'), 113 data: $searchForm.serialize(), 114 dataType: 'json', 115 success: function (data, textStatus, jqXHR ) { 116 markers = data; 117 render_results(); 118 prepare_map(); 119 }, 120 complete: function () { 121 $('.ghmi-ajax-loader').removeClass('visible'); 122 } 123 }); 124 }); 125 $searchForm.trigger('submit'); 126 127 /* Triggers form submit on search form fields change */ 128 var $searchFormFields = $searchForm.find('.ghmi-select, .ghmi-field'); 129 $searchFormFields.on('change', function () { 130 $searchForm.trigger('submit'); 131 }); 132 133 $('.ghmi-reset', $searchForm).on('click', function (event) { 134 event.preventDefault(); 135 136 $('input[name="ghmi-search-query"]').attr('value', 'Search Terms...'); 137 $('select[name="ghmi-county"]').attr('value', 'all'); 138 $('select[name="ghmi-marker-program"]').attr('value', 'all'); 139 $('select[name="ghmi-marker-time-period"]').attr('value', 'all'); 140 $('select[name="ghmi-region"]').attr('value', 'all'); 141 $searchForm.trigger('submit'); 142 }); 143 144 /** 145 * Renders the Results Box 146 */ 147 function render_results() { 148 var $results_wrapper = $('.ghmi-search-results'); 149 150 /* Clear old markers */ 151 $results_wrapper.find('.ghmi-form-set-row').remove(); 152 153 if ( markers ) { 154 var markersLength = Object.keys(markers).length; 155 if ( !markersLength ) { 156 $results_wrapper.find('h6').text('No markers have been found. Try a different search.'); 157 return false;
158 } 159 } 160 161 /* Display hint text */ 162 $results_wrapper.find('h6').text('Check to add boxes to your route.'); 163 164 /* Filling Markers */ 165 $results_wrapper.removeClass('ghmi-hidden').addClass('ghmi-visible'); 166 167 for (var markerID in markers) { 168 /* Marker Wrapper */ 169 var $marker = $('<div/>', { 170 'class': 'ghmi-form-set-row', 171 'data-marker-id': markerID 172 }).append( 173 /* Marker Checkbox */ 174 $('<input/>', { 175 'type': 'checkbox', 176 'name': 'ghmi-row-' + markerID, 177 'class': 'ghmi-form-checkbox', 178 'id': 'ghmi-row-' + markerID 179 }) 180 ).append( 181 /* Marker Label */ 182 $('<label/>', { 183 'for': 'ghmi-row-' + markerID 184 }).text(markers[markerID]['title'].substr(0, 100) + ' -- ' + markers[markerID]['county'] + ' >> ') 185 ).append( 186 /* Marker Permalink */ 187 $('<a/>', { 188 'href': markers[markerID]['permalink'], 189 'target': '_blank', 190 'class': 'ghmi-more-info' 191 }).text(markers[markerID]['permalink_label']) 192 ); 193 194 $marker.appendTo($results_wrapper.find('.ghmi-form-set')); 195 } 196 197 custom_checkboxes(); 198 199 $('.ghmi-bottom').removeClass('ghmi-hidden').addClass('ghmi-visible'); 200 } 201 202 /** 203 * Google Map 204 */ 205 var directionsDisplay; 206 var directionsService = new google.maps.DirectionsService(); 207 var infoWindow = new google.maps.InfoWindow({ 208 maxWidth: 200 209 }); 210 211 prepare_map(); 212 function prepare_map() { 213 var $map = $doc.find('.ghmi-map'); 214 if ( $map.length ) { 215 $map.each(function () { 216 var $currentMap = $(this); 217 218 render_map($currentMap.attr('id')); 219 }); 220 } 221 } 222 223 /* Renders the map */ 224 function render_map(mapID) { 225 directionsDisplay = new google.maps.DirectionsRenderer(); 226 227 var mapElement = document.getElementById(mapID); 228 var $mapElement = $('#' + mapID); 229 230 var mapLat = parseFloat($mapElement.data('lat')); 231 var mapLng = parseFloat($mapElement.data('lng')); 232 var mapAddress = $mapElement.data('address'); 233 234 var mapLatLng = new google.maps.LatLng(mapLat, mapLng); 235 236 /* Map Options */ 237 var mapOptions = { 238 zoom: $mapElement.data('zoom-level'), 239 center: mapLatLng 240 }; 241 242 /* Render Google Map */ 243 var map = new google.maps.Map( 244 mapElement, 245 mapOptions 246 ); 247 248 set_markers(map); 249 directionsDisplay.setMap(map); 250 directionsDisplay.setPanel(document.getElementById('ghmi-driving-directions-content')); 251 } 252 253 /* Renders the Markers */ 254 function set_markers(map) { 255 /* Markers */ 256 for (var markerID in markers) { 257 /* Marker Latitude and Longitude */ 258 var markerLat = markers[markerID]['location']['lat']; 259 var markerLng = markers[markerID]['location']['lng']; 260 261 /* Google Map LatLng */ 262 var markerLatLng = new google.maps.LatLng(markerLat, markerLng); 263 264 markers[markerID]['marker'] = new google.maps.Marker({ 265 ghmi_id: markerID, 266 position: markerLatLng, 267 icon: ghmi_details.plugin_dir + '/css/images/map-marker.png', 268 draggable: false, 269 map: map, 270 title: markers[markerID]['title'] 271 }); 272 273 /* Marker Click */ 274 google.maps.event.addListener(markers[markerID]['marker'], 'click', function() { 275 var markerContent = markers[this['ghmi_id']]['title']; 276 if ( markers[markerID]['permalink'] ) { 277 markerContent += ' <a href="' + markers[this['ghmi_id']]['permalink'] + '" target="_blank">' + markers[this['ghmi_id']]['permalink_label'] + '</a>'; 278 } 279 280 infoWindow.setContent(markerContent); 281 infoWindow.open(map, markers[this['ghmi_id']]['marker']); 282 }); 283 } 284 } 285 286 /* Draws the directions on the map */ 287 $('.ghmi-route-plan form').on('submit', function (event) { 288 event.preventDefault(); 289 prepare_map(); 290 291 var $form = $(this); 292 var $fields = $form.find('.ghmi-field'); 293 294 var form_error = false; 295 296 /* Clearing error states */ 297 $fields.removeClass('ghmi-error-field'); 298 299 /* Check for valid input */ 300 $fields.each(function () { 301 var $field = $(this); 302 303 if ($field.val().trim() == '' || $field.val() == $field.attr('title')) { 304 $field.addClass('ghmi-error-field'); 305 form_error = true; 306 } 307 }); 308 309 /* Proceed with the directions request */ 310 if ( !form_error ) { 311 var origin; 312 var destination; 313 var wayPoints = []; 314 var stringLocations = []; 315 316 /* Way Points */ 317 var $way_points = $('.ghmi-form-marker-set-row'); 318 var count_way_points = $way_points.length; 319 320 if (count_way_points) { 321 $way_points.each(function () { 322 var $current_way_point = $(this); 323 var markerID = $current_way_point.data('marker-id'); 324 var lat = markers[markerID]['location']['lat']; 325 var lng = markers[markerID]['location']['lng']; 326 var markerLocation = new google.maps.LatLng(lat, lng); 327 328 wayPoints.push({
329 location: markerLocation, 330 stopover: true 331 }); 332 333 stringLocations.push( lat + ' ' + lng ); 334 }); 335 } /* End Way Points */ 336 337 /* Define origin point */ 338 var $origin = $('#ghmi-origin'); 339 if ($origin.val().trim() != '') { 340 origin = $origin.val(); 341 } 342 343 /* Define destination point */ 344 var $destination = $('#ghmi-destination'); 345 if ($destination.val().trim() != '') { 346 destination = $destination.val(); 347 } 348 349 /* Create Route */ 350 var route_request = { 351 origin: origin, 352 destination: destination, 353 waypoints: wayPoints, 354 optimizeWaypoints: false, 355 travelMode: google.maps.TravelMode.DRIVING 356 }; 357 358 /* Render Directions */ 359 directionsService.route(route_request, function(response, status) { 360 $('.ghmi-driving-directions h6').remove(); 361 $('.ghmi-driving-directions-content').find('*').remove(); 362 $('.ghmi-print-directions').remove(); 363 364 if (status == google.maps.DirectionsStatus.OK) { 365 directionsDisplay.setDirections(response); 366 set_print_directions_href(origin, wayPoints, destination, stringLocations); 367 } else { 368 $('.ghmi-driving-directions h5').after($('<h6/>').text("Google Maps couldn't create directions route. Try setting different origin, waypoints or destination.")); 369 } 370 }); 371 372 $('.ghmi-driving-directions').removeClass('ghmi-hidden').addClass('ghmi-visible'); 373 } 374 }); 375 376 /** 377 * Print Directions Button 378 */ 379 function set_print_directions_href(origin, wayPoints, destination, stringLocations) { 380 var href = 'https://www.google.com/maps/dir/?api=1'; 381 382 /* Assign Origin Address */ 383 href += '&origin=' + origin.replace(' ', '+'); 384 385 /* Assign Destination Address */ 386 href += '&destination=' + destination; 387 388 /* Assign Way Points Addresses */ 389 href += '&waypoints='; 390 if (wayPoints.length) { 391 for (var i = 0; i < stringLocations.length; i++) { 392 var location = stringLocations[i].replace(' ', ','); 393 href += location + '|'; 394 } 395 } 396 397 /* Assign Meta */ 398 // href += '&ie=UTF8&z=8&pw=2'; 399 400 var $printDirectionsButton = $('<a/>', { 401 'class': 'ghmi-print-directions', 402 'href': href, 403 'target': '_blank' 404 }).text('View on Google Maps to Print Directions'); 405 406 $printDirectionsButton.insertAfter($('.ghmi-driving-directions h5')); 407 } 408 409 /** 410 * Single Marker Map 411 */ 412 var $singleMarkerMap = $('#ghmi-map-marker'); 413 if ($singleMarkerMap.length) { 414 var singleMarkerMap = document.getElementById('ghmi-map-marker'); 415 416 var singleMarkerMapLat = parseFloat( $singleMarkerMap.data('lat') ); 417 var singleMarkerMapLng = parseFloat( $singleMarkerMap.data('lng') ); 418 419 var singleMapLatLng = new google.maps.LatLng(singleMarkerMapLat, singleMarkerMapLng); 420 421 var singleMapOptions = { 422 zoom: $singleMarkerMap.data('zoom-level'), 423 center: singleMapLatLng 424 }; 425 426 var singleMap = new google.maps.Map( 427 singleMarkerMap, 428 singleMapOptions 429 ); 430 431 432 var singleMapGoogleMarker = new google.maps.Marker({ 433 position: singleMapLatLng, 434 icon: ghmi_details.plugin_dir + '/css/images/map-marker.png', 435 draggable: false, 436 map: singleMap, 437 title: $singleMarkerMap.data('marker-title') 438 }); 439 440 441 var singleInfoWindow = new google.maps.InfoWindow({ 442 content: '<strong>' + $singleMarkerMap.data('marker-title') + '</strong>' 443 }); 444 445 singleInfoWindow.open(singleMap, singleMapGoogleMarker); 446 } 447 }); 448})(jQuery, window, document);
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.