Skip to content

Commit 6e42761

Browse files
committed
Continued working through JSHint warnings, added taxonomyFiltersContainer option, changed order of init and destroy methods
1 parent 61e15e4 commit 6e42761

File tree

4 files changed

+124
-121
lines changed

4 files changed

+124
-121
lines changed

dist/js/jquery.storelocator.js

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-10-11
1+
/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-10-12
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2014 Bjorn Holine; Licensed MIT */
44

@@ -7,7 +7,7 @@
77
;(function ($, window, document, undefined) {
88
'use strict';
99

10-
var pluginName = "storeLocator";
10+
var pluginName = 'storeLocator';
1111

1212
// Only allow for one instantiation of this script
1313
if (typeof $.fn[pluginName] !== 'undefined') {
@@ -76,6 +76,7 @@
7676
'listTemplateID' : null,
7777
'infowindowTemplateID' : null,
7878
'taxonomyFilters' : null,
79+
'taxonomyFiltersContainer' : 'bh-sl-filters-container',
7980
'querystringParams' : false,
8081
'callbackBeforeSend' : null,
8182
'callbackSuccess' : null,
@@ -97,6 +98,7 @@
9798

9899
// Plugin constructor
99100
function Plugin(element, options) {
101+
$this = $(element);
100102
this.element = element;
101103
this.settings = $.extend({}, defaults, options);
102104
this._defaults = defaults;
@@ -106,30 +108,6 @@
106108

107109
// Avoid Plugin.prototype conflicts
108110
$.extend(Plugin.prototype, {
109-
/**
110-
* Reset function
111-
*/
112-
reset: function () {
113-
locationset = [];
114-
featuredset = [];
115-
normalset = [];
116-
markers = [];
117-
$(document).off('click.'+pluginName, '.' + this.settings.locationList + ' li');
118-
},
119-
120-
/**
121-
* Distance calculations
122-
*/
123-
geoCodeCalcToRadian: function (v) {
124-
return v * (Math.PI / 180);
125-
},
126-
geoCodeCalcDiffRadian: function (v1, v2) {
127-
return this.geoCodeCalcToRadian(v2) - this.geoCodeCalcToRadian(v1);
128-
},
129-
geoCodeCalcCalcDistance: function (lat1, lng1, lat2, lng2, radius) {
130-
return radius * 2 * Math.asin(Math.min(1, Math.sqrt(( Math.pow(Math.sin((this.geoCodeCalcDiffRadian(lat1, lat2)) / 2.0), 2.0) + Math.cos(this.geoCodeCalcToRadian(lat1)) * Math.cos(this.geoCodeCalcToRadian(lat2)) * Math.pow(Math.sin((this.geoCodeCalcDiffRadian(lng1, lng2)) / 2.0), 2.0) ))));
131-
},
132-
133111
/**
134112
* Init function
135113
*/
@@ -151,7 +129,7 @@
151129
else {
152130
dataTypeRead = this.settings.dataType;
153131
}
154-
132+
155133
// Set up the directionsService if it's true
156134
if(this.settings.inlineDirections === true) {
157135
directionsDisplay = new google.maps.DirectionsRenderer();
@@ -161,7 +139,7 @@
161139

162140
// Save the original zoom setting so it can be retrieved if taxonomy filtering resets it
163141
originalZoom = this.settings.mapSettings.zoom;
164-
142+
165143
// Add Handlebars helper for handling URL output
166144
Handlebars.registerHelper('niceURL', function(url) {
167145
if(url){
@@ -179,49 +157,49 @@
179157
// Clone the filters if there are any so they can be used in the modal
180158
if (this.settings.taxonomyFilters !== null) {
181159
// Clone the filters
182-
$('.bh-sl-filters-container').clone(true, true).prependTo($this);
160+
$('.' + this.settings.taxonomyFiltersContainer).clone(true, true).prependTo($this);
183161
}
184-
162+
185163
$this.wrap('<div class="' + this.settings.overlay + '"><div class="' + this.settings.modalWindow + '"><div class="' + this.settings.modalContent + '">');
186164
$('.' + this.settings.modalWindow).prepend('<div class="' + this.settings.closeIcon + '"></div>');
187165
$('.' + this.settings.overlay).hide();
188166
}
189-
167+
190168
// Load the templates and continue from there
191169
this.loadTemplates();
192170
},
193171

194172
/**
195173
* Destroy
196-
*
174+
*
197175
* Note: The Google map is not destroyed here because Google recommends using a single instance and reusing it (it's not really supported)
198176
*/
199177
destroy: function () {
200178
// Reset
201179
this.reset();
202-
var mapContainer = $('#' + this.settings.mapID);
180+
var $mapDiv = $('#' + this.settings.mapID);
203181

204182
// Remove marker event listeners
205183
if(markers.length) {
206184
for(var i = 0; i <= markers.length; i++) {
207185
google.maps.event.removeListener(markers[i]);
208186
}
209187
}
210-
188+
211189
// Remove markup
212190
$('.' + this.settings.locationList + ' ul').empty();
213-
if(mapContainer.hasClass('bh-sl-map-open')) {
214-
mapContainer.empty().removeClass('bh-sl-map-open');
191+
if($mapDiv.hasClass('bh-sl-map-open')) {
192+
$mapDiv.empty().removeClass('bh-sl-map-open');
215193
}
216-
194+
217195
// Remove modal markup
218196
if (this.settings.modal === true) {
219197
$('. ' + this.settings.overlay).remove();
220198
}
221-
199+
222200
// Remove map style from cotnainer
223-
mapContainer.attr('style', '');
224-
201+
$mapDiv.attr('style', '');
202+
225203
// Hide map container
226204
$this.hide();
227205
// Remove data
@@ -231,6 +209,30 @@
231209
// Unbind plugin
232210
$this.unbind();
233211
},
212+
213+
/**
214+
* Reset function
215+
*/
216+
reset: function () {
217+
locationset = [];
218+
featuredset = [];
219+
normalset = [];
220+
markers = [];
221+
$(document).off('click.'+pluginName, '.' + this.settings.locationList + ' li');
222+
},
223+
224+
/**
225+
* Distance calculations
226+
*/
227+
geoCodeCalcToRadian: function (v) {
228+
return v * (Math.PI / 180);
229+
},
230+
geoCodeCalcDiffRadian: function (v1, v2) {
231+
return this.geoCodeCalcToRadian(v2) - this.geoCodeCalcToRadian(v1);
232+
},
233+
geoCodeCalcCalcDistance: function (lat1, lng1, lat2, lng2, radius) {
234+
return radius * 2 * Math.asin(Math.min(1, Math.sqrt(( Math.pow(Math.sin((this.geoCodeCalcDiffRadian(lat1, lat2)) / 2.0), 2.0) + Math.cos(this.geoCodeCalcToRadian(lat1)) * Math.cos(this.geoCodeCalcToRadian(lat2)) * Math.pow(Math.sin((this.geoCodeCalcDiffRadian(lng1, lng2)) / 2.0), 2.0) ))));
235+
},
234236

235237
/**
236238
* Check for query string
@@ -700,28 +702,28 @@
700702
paginationSetup: function (currentPage) {
701703
var pagesOutput = '';
702704
var totalPages = locationset.length / this.settings.locationsPerPage;
705+
var $paginationList = $('.bh-sl-pagination-container .bh-sl-pagination');
703706

704707
// Current page check
705708
if (typeof currentPage === 'undefined') {
706709
currentPage = 0;
707710
}
708711

709712
// Initial pagination setup
710-
if ($('.bh-sl-pagination-container .bh-sl-pagination').length === 0) {
713+
if ($paginationList.length === 0) {
711714

712715
pagesOutput = this.paginationOutput(currentPage, totalPages);
713716
}
714717
// Update pagination on page change
715718
else {
716719
// Remove the old pagination
717-
$('.bh-sl-pagination-container .bh-sl-pagination').empty();
720+
$paginationList.empty();
718721

719722
// Add the numbers
720723
pagesOutput = this.paginationOutput(currentPage, totalPages);
721724
}
722725

723-
//TODO: Target this better
724-
$('.bh-sl-pagination-container .bh-sl-pagination').append(pagesOutput);
726+
$paginationList.append(pagesOutput);
725727
},
726728

727729
/**
@@ -928,13 +930,13 @@
928930
// Focus on the list
929931
$('.' + _this.settings.locationList + ' li').removeClass('list-focus');
930932
var markerId = marker.get('id');
931-
var selectedLocation = $('.' + _this.settings.locationList + ' li[data-markerid=' + markerId + ']');
932-
selectedLocation.addClass('list-focus');
933+
var $selectedLocation = $('.' + _this.settings.locationList + ' li[data-markerid=' + markerId + ']');
934+
$selectedLocation.addClass('list-focus');
933935

934936
// Scroll list to selected marker
935-
var container = $('.' + _this.settings.locationList);
936-
container.animate({
937-
scrollTop: selectedLocation.offset().top - container.offset().top + container.scrollTop()
937+
var $container = $('.' + _this.settings.locationList);
938+
$container.animate({
939+
scrollTop: $selectedLocation.offset().top - $container.offset().top + $container.scrollTop()
938940
});
939941
});
940942
}
@@ -1077,7 +1079,7 @@
10771079
/**
10781080
* Process the form values and/or query string
10791081
*
1080-
* @param e {event}
1082+
* @param e {Object} event
10811083
*/
10821084
processForm: function (e) {
10831085
var _this = this;
@@ -1196,22 +1198,24 @@
11961198
* Process the location data
11971199
*/
11981200
originalDataRequest.then(function (data) {
1199-
var mapContainer = $('#' + _this.settings.mapID);
1201+
var $mapDiv = $('#' + _this.settings.mapID);
1202+
// Get the length unit
1203+
var distUnit = (_this.settings.lengthUnit === 'km') ? _this.settings.kilometersLang : _this.settings.milesLang;
12001204

12011205
// Callback
12021206
if (_this.settings.callbackSuccess) {
12031207
_this.settings.callbackSuccess.call(this);
12041208
}
12051209

12061210
// Set a variable for fullMapStart so we can detect the first run
1207-
if (_this.settings.fullMapStart === true && mapContainer.hasClass('bh-sl-map-open') === false) {
1211+
if (_this.settings.fullMapStart === true && $mapDiv.hasClass('bh-sl-map-open') === false) {
12081212
firstRun = true;
12091213
}
12101214
else {
12111215
_this.reset();
12121216
}
12131217

1214-
mapContainer.addClass('bh-sl-map-open');
1218+
$mapDiv.addClass('bh-sl-map-open');
12151219

12161220
// Process the location data depending on the data format type
12171221
if (_this.settings.dataType === 'json' || _this.settings.dataType === 'jsonp') {
@@ -1348,7 +1352,7 @@
13481352

13491353
if (_this.isEmptyObject(locationset)) {
13501354
// Hide the map and locations if they're showing
1351-
if (mapContainer.hasClass('bh-sl-map-open')) {
1355+
if ($mapDiv.hasClass('bh-sl-map-open')) {
13521356
$this.hide();
13531357
}
13541358

@@ -1371,7 +1375,7 @@
13711375
// Featured locations filtering
13721376
if (_this.settings.featuredLocations === true) {
13731377
// Create array for featured locations
1374-
featuredset = $.grep(locationset, function (val, i) {
1378+
featuredset = $.grep(locationset, function (val) {
13751379
return val.featured === 'true';
13761380
});
13771381

@@ -1385,9 +1389,6 @@
13851389
locationset = featuredset.concat(normalset);
13861390
}
13871391

1388-
// Get the length unit
1389-
var distUnit = (_this.settings.lengthUnit === 'km') ? _this.settings.kilometersLang : _this.settings.milesLang;
1390-
13911392
// Check the closest marker
13921393
if (_this.settings.maxDistance === true && firstRun !== true && maxDistance) {
13931394
if (typeof locationset[0] === 'undefined' || locationset[0].distance > maxDistance) {
@@ -1479,6 +1480,7 @@
14791480
myOptions = _this.settings.mapSettings;
14801481
}
14811482

1483+
// Create the map
14821484
var map = new google.maps.Map(document.getElementById(_this.settings.mapID), myOptions);
14831485

14841486
// Re-center the map when the browser is resized
@@ -1633,7 +1635,7 @@
16331635
});
16341636

16351637
// Handle filter updates
1636-
$('.bh-sl-filters-container').on('change.'+pluginName, 'input, select', function (e) {
1638+
$('.' + this.settings.taxonomyFiltersContainer).on('change.'+pluginName, 'input, select', function (e) {
16371639
e.stopPropagation();
16381640

16391641
var filterId, filterContainer, filterKey;
@@ -1736,7 +1738,6 @@
17361738
// preventing against multiple instantiations
17371739
$.fn[ pluginName ] = function (options) {
17381740
this.each(function () {
1739-
$this = $(this);
17401741
if (!$.data(this, "plugin_" + pluginName)) {
17411742
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
17421743
}

0 commit comments

Comments
 (0)