Skip to content

Commit 2bef9c4

Browse files
committed
Added destroy method, namespaced events, started tests
1 parent 31b04f3 commit 2bef9c4

File tree

5 files changed

+156
-37
lines changed

5 files changed

+156
-37
lines changed

dist/js/jquery.storelocator.js

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

@@ -113,7 +113,7 @@
113113
featuredset = [];
114114
normalset = [];
115115
markers = [];
116-
$(document).off('click', '.' + this.settings.locationList + ' li');
116+
$(document).off('click.'+pluginName, '.' + this.settings.locationList + ' li');
117117
},
118118

119119
/**
@@ -190,6 +190,45 @@
190190
this.loadTemplates();
191191
},
192192

193+
/**
194+
* Destroy
195+
*/
196+
destroy: function () {
197+
// Reset
198+
this.reset();
199+
200+
// Remove marker event listeners
201+
if(markers.length) {
202+
for(var i = 0; i <= markers.length; i++) {
203+
google.maps.event.removeListener(markers[i]);
204+
}
205+
}
206+
207+
// Remove markup
208+
$('.' + this.settings.locationList + ' ul').empty();
209+
if($('#' + this.settings.mapID).hasClass('bh-sl-map-open')) {
210+
$('#' + this.settings.mapID).empty();
211+
$('#' + this.settings.mapID).removeClass('bh-sl-map-open');
212+
}
213+
214+
// Remove modal markup
215+
if (this.settings.modal === true) {
216+
$('. ' + this.settings.overlay).remove();
217+
}
218+
219+
// Remove map style from cotnainer
220+
$('#' + this.settings.mapID).attr('style', '');
221+
222+
// Hide map container
223+
$this.hide();
224+
// Remove data
225+
$.removeData($this.get(0));
226+
// Remove namespached events
227+
$(document).off(pluginName);
228+
// Unbind plugin
229+
$this.unbind();
230+
},
231+
193232
/**
194233
* Check for query string
195234
*
@@ -291,17 +330,17 @@
291330
var _this = this;
292331
// ASP.net or regular submission?
293332
if (this.settings.noForm === true) {
294-
$(document).on('click', '.' + this.settings.formContainer + ' button', function (e) {
333+
$(document).on('click.'+pluginName, '.' + this.settings.formContainer + ' button', function (e) {
295334
_this.processForm(e);
296335
});
297-
$(document).on('keyup', function (e) {
336+
$(document).on('keyup.'+pluginName, function (e) {
298337
if (e.keyCode === 13 && $('#' + _this.settings.addressID).is(':focus')) {
299338
_this.processForm(e);
300339
}
301340
});
302341
}
303342
else {
304-
$(document).on('submit', '#' + this.settings.formID, function (e) {
343+
$(document).on('submit.'+pluginName, '#' + this.settings.formID, function (e) {
305344
_this.processForm(e);
306345
});
307346
}
@@ -941,7 +980,7 @@
941980
this.processForm(null);
942981
}
943982

944-
$(document).off('click', '.' + this.settings.locationList + ' .bh-sl-close-icon');
983+
$(document).off('click.'+pluginName, '.' + this.settings.locationList + ' .bh-sl-close-icon');
945984
},
946985

947986
/**
@@ -1294,15 +1333,15 @@
12941333
// Pop up the modal window
12951334
$('.' + _this.settings.overlay).fadeIn();
12961335
// Close modal when close icon is clicked and when background overlay is clicked
1297-
$(document).on('click', '.' + _this.settings.closeIcon + ', .' + _this.settings.overlay, function () {
1336+
$(document).on('click.'+pluginName, '.' + _this.settings.closeIcon + ', .' + _this.settings.overlay, function () {
12981337
_this.modalClose();
12991338
});
13001339
// Prevent clicks within the modal window from closing the entire thing
1301-
$(document).on('click', '.' + _this.settings.modalWindow, function (e) {
1340+
$(document).on('click.'+pluginName, '.' + _this.settings.modalWindow, function (e) {
13021341
e.stopPropagation();
13031342
});
13041343
// Close modal when escape key is pressed
1305-
$(document).on('keyup', function (e) {
1344+
$(document).on('keyup.'+pluginName, function (e) {
13061345
if (e.keyCode === 27) {
13071346
_this.modalClose();
13081347
}
@@ -1391,22 +1430,22 @@
13911430
}
13921431

13931432
// Handle pagination
1394-
$(document).on('click', '.bh-sl-pagination li', function () {
1433+
$(document).on('click.'+pluginName, '.bh-sl-pagination li', function () {
13951434
// Run paginationChange
13961435
_this.paginationChange($(this).attr('data-page'));
13971436
});
13981437

13991438
// Inline directions
14001439
if(_this.settings.inlineDirections === true){
14011440
// Open directions
1402-
$(document).on('click', '.' + _this.settings.locationList + ' li .loc-directions a', function (e) {
1441+
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li .loc-directions a', function (e) {
14031442
e.preventDefault();
14041443
var locID = $(this).closest('li').attr('data-markerid');
14051444
_this.directionsRequest(origin, locID, map);
14061445
});
14071446

14081447
// Close directions
1409-
$(document).on('click', '.' + _this.settings.locationList + ' .bh-sl-close-icon', function () {
1448+
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' .bh-sl-close-icon', function () {
14101449
_this.closeDirections();
14111450
});
14121451
}
@@ -1453,7 +1492,7 @@
14531492
}
14541493

14551494
// Handle clicks from the list
1456-
$(document).on('click', '.' + _this.settings.locationList + ' li', function () {
1495+
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li', function () {
14571496
var markerId = $(this).data('markerid');
14581497

14591498
var selectedMarker = markers[markerId];
@@ -1478,7 +1517,7 @@
14781517
});
14791518

14801519
// Prevent bubbling from list content links
1481-
$(document).on('click', '.' + _this.settings.locationList + ' li a', function (e) {
1520+
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li a', function (e) {
14821521
e.stopPropagation();
14831522
});
14841523

@@ -1501,7 +1540,7 @@
15011540
});
15021541

15031542
// Handle filter updates
1504-
$('.bh-sl-filters-container').on('change', 'input, select', function (e) {
1543+
$('.bh-sl-filters-container').on('change.'+pluginName, 'input, select', function (e) {
15051544
e.stopPropagation();
15061545

15071546
var filterId, filterContainer, filterKey;

0 commit comments

Comments
 (0)