Skip to content

Commit dbfc12e

Browse files
committed
Added ability to feature locations
1 parent 0e0c7e3 commit dbfc12e

File tree

5 files changed

+125
-88
lines changed

5 files changed

+125
-88
lines changed

js/jquery.storelocator.js

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* storeLocator v1.4.6 - jQuery Google Maps Store Locator Plugin
2+
* storeLocator v1.4.7 - jQuery Google Maps Store Locator Plugin
33
* (c) Copyright 2013, Bjorn Holine (http://www.bjornblog.com)
44
* Released under the MIT license
55
* Distance calculation function by Chris Pietschmann: http://pietschsoft.com/post/2008/02/01/Calculate-Distance-Between-Geocodes-in-C-and-JavaScript.aspx
@@ -43,6 +43,7 @@ $.fn.storeLocator = function(options) {
4343
'noForm': false,
4444
'loading': false,
4545
'loadingDiv': 'loading-map',
46+
'featuredLocations': false,
4647
'infowindowTemplatePath': 'templates/infowindow-description.html',
4748
'listTemplatePath': 'templates/location-list-description.html',
4849
'KMLinfowindowTemplatePath': 'templates/kml-infowindow-description.html',
@@ -112,12 +113,16 @@ $.fn.storeLocator = function(options) {
112113

113114
var userinput, olat, olng, marker, letter, storenum;
114115
var locationset = [];
116+
var featuredset = [];
117+
var normalset = [];
115118
var markers = [];
116119
var prefix = 'storeLocator';
117120

118121
//Resets for multiple re-submissions
119122
function reset(){
120123
locationset = [];
124+
featuredset = [];
125+
normalset = [];
121126
markers = [];
122127
$(document).off('click.'+prefix, '#' + settings.listDiv + ' li');
123128
}
@@ -389,20 +394,21 @@ $.fn.storeLocator = function(options) {
389394
var hours2 = this.hours2;
390395
var hours3 = this.hours3;
391396
var category = this.category;
397+
var featured = this.featured;
392398

393399
var distance = GeoCodeCalc.CalcDistance(orig_lat,orig_lng,lat,lng, GeoCodeCalc.EarthRadius);
394400

395401
//Create the array
396402
if(settings.maxDistance === true && firstRun !== true){
397403
if(distance < maxDistance){
398-
locationset[i] = [distance, name, lat, lng, address, address2, city, state, postal, country, phone, email, web, hours1, hours2, hours3, category];
404+
locationset[i] = [distance, name, lat, lng, address, address2, city, state, postal, country, phone, email, web, hours1, hours2, hours3, category, featured];
399405
}
400406
else{
401407
return;
402408
}
403409
}
404410
else{
405-
locationset[i] = [distance, name, lat, lng, address, address2, city, state, postal, country, phone, email, web, hours1, hours2, hours3, category];
411+
locationset[i] = [distance, name, lat, lng, address, address2, city, state, postal, country, phone, email, web, hours1, hours2, hours3, category, featured];
406412
}
407413

408414
i++;
@@ -454,32 +460,55 @@ $.fn.storeLocator = function(options) {
454460
var hours2 = $(this).attr('hours2');
455461
var hours3 = $(this).attr('hours3');
456462
var category = $(this).attr('category');
463+
var featured = $(this).attr('featured');
457464

458465
var distance = GeoCodeCalc.CalcDistance(orig_lat,orig_lng,lat,lng, GeoCodeCalc.EarthRadius);
459466

460467
//Create the array
461468
if(settings.maxDistance === true && firstRun !== true){
462469
if(distance < maxDistance){
463-
locationset[i] = [distance, name, lat, lng, address, address2, city, state, postal, country, phone, email, web, hours1, hours2, hours3, category];
470+
locationset[i] = [distance, name, lat, lng, address, address2, city, state, postal, country, phone, email, web, hours1, hours2, hours3, category, featured];
464471
}
465472
else{
466473
return;
467474
}
468475
}
469476
else{
470-
locationset[i] = [distance, name, lat, lng, address, address2, city, state, postal, country, phone, email, web, hours1, hours2, hours3, category];
477+
locationset[i] = [distance, name, lat, lng, address, address2, city, state, postal, country, phone, email, web, hours1, hours2, hours3, category, featured];
471478
}
472479

473480
i++;
474481
});
475482
}
476483

477-
//Sort the multi-dimensional array numerically by distance
478-
locationset.sort(function(a, b){
479-
var x = a[0];
480-
var y = b[0];
481-
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
482-
});
484+
//Distance sorting function
485+
function sort_numerically(locationsarray){
486+
locationsarray.sort(function(a, b){
487+
var x = a[0];
488+
var y = b[0];
489+
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
490+
});
491+
}
492+
493+
//Sort the multi-dimensional array by distance
494+
sort_numerically(locationset);
495+
496+
//Featured locations filtering
497+
if(settings.featuredLocations === true){
498+
//Create array for featured locations
499+
featuredset = $.grep(locationset, function(val, i){
500+
return val[17] === "true";
501+
});
502+
503+
//Create array for normal locations
504+
normalset = $.grep(locationset, function(val, i){
505+
return val[17] !== "true";
506+
});
507+
508+
//Combine the arrays
509+
locationset = [];
510+
locationset = featuredset.concat(normalset);
511+
}
483512

484513
//Get the length unit
485514
var distUnit = (settings.lengthUnit === "km") ? settings.kilometersLang : settings.milesLang ;
@@ -500,7 +529,7 @@ $.fn.storeLocator = function(options) {
500529
//Create the map with jQuery
501530
$(function(){
502531

503-
var storeDistance, storeName, storeAddress1, storeAddress2, storeCity, storeState, storeCountry, storeZip, storePhone, storeEmail, storeWeb, storeHours1, storeHours2, storeHours3, storeDescription, storeCat;
532+
var storeDistance, storeName, storeAddress1, storeAddress2, storeCity, storeState, storeCountry, storeZip, storePhone, storeEmail, storeWeb, storeHours1, storeHours2, storeHours3, storeDescription, storeCat, storeFeatured;
504533

505534
//Instead of repeating the same thing twice below
506535
function create_location_variables(loopcount){
@@ -520,6 +549,7 @@ $.fn.storeLocator = function(options) {
520549
storeHours2 = locationset[loopcount][14];
521550
storeHours3 = locationset[loopcount][15];
522551
storeCat = locationset[loopcount][16];
552+
storeFeatured = locationset[loopcount][17];
523553
}
524554

525555
//There are less variables for KML files
@@ -605,7 +635,8 @@ $.fn.storeLocator = function(options) {
605635
"hours3": storeHours3,
606636
"length": distLength,
607637
"origin": origin,
608-
"category": storeCat
638+
"category": storeCat,
639+
"featured": storeFeatured
609640
}
610641
]
611642
};

0 commit comments

Comments
 (0)