Skip to content

Commit c1be901

Browse files
committed
Renamed processFormInput and beginMapping functions, added query string function, added ignore case modifier to Regex
1 parent cb79fb4 commit c1be901

File tree

3 files changed

+121
-49
lines changed

3 files changed

+121
-49
lines changed

dist/js/jquery.storelocator.js

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

@@ -74,6 +74,7 @@
7474
'listTemplateID' : null,
7575
'infowindowTemplateID' : null,
7676
'taxonomyFilters' : null,
77+
'querystringParams' : false,
7778
'callbackBeforeSend' : null,
7879
'callbackSuccess' : null,
7980
'callbackModalOpen' : null,
@@ -180,6 +181,19 @@
180181
this.loadTemplates();
181182
},
182183

184+
/**
185+
* Check for query string
186+
*
187+
* @param param {string} query string parameter to test
188+
* @returns {string}
189+
*/
190+
getQueryString: function(param) {
191+
param = param.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
192+
var regex = new RegExp('[\\?&]' + param + '=([^&#]*)'),
193+
results = regex.exec(location.search);
194+
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
195+
},
196+
183197
/**
184198
* Load templates
185199
*/
@@ -258,7 +272,7 @@
258272
}
259273

260274
this.start();
261-
this.processFormInput();
275+
this.formEventHandler();
262276
},
263277

264278
/**
@@ -273,18 +287,18 @@
273287
if (this.settings.maxDistance === true) {
274288
var maxDistance = $('#' + this.settings.maxDistanceID).val();
275289
// Start the mapping
276-
this.beginMapping(maxDistance);
290+
this.processForm(maxDistance);
277291
}
278292
else {
279293
// Start the mapping
280-
this.beginMapping(null);
294+
this.processForm();
281295
}
282296
},
283297

284298
/**
285-
* Process the form input
299+
* Form event handler setup
286300
*/
287-
processFormInput: function () {
301+
formEventHandler: function () {
288302
var _this = this;
289303
// ASP.net or regular submission?
290304
if (this.settings.noForm === true) {
@@ -425,8 +439,12 @@
425439

426440
// If show full map option is true
427441
if (this.settings.fullMapStart === true) {
428-
// Just do the mapping without an origin
429-
this.mapping();
442+
if(this.settings.querystringParams === true && this.getQueryString(this.settings.addressID) || this.getQueryString(this.settings.nameID)) {
443+
this.processForm();
444+
}
445+
else {
446+
this.mapping();
447+
}
430448
}
431449

432450
// HTML5 geolocation API option
@@ -566,7 +584,7 @@
566584
var filterTest = true;
567585

568586
for (var k in filters) {
569-
if (!(new RegExp(filters[k].join("")).test(data[k]))) {
587+
if (!(new RegExp(filters[k].join(''), 'i').test(data[k]))) {
570588
filterTest = false;
571589
}
572590
}
@@ -884,23 +902,39 @@
884902
else {
885903
this.settings.mapSettings.zoom = 0;
886904
}
887-
this.beginMapping(null);
905+
this.processForm(null);
888906
}
889907

890908
$(document).off('click', '.' + this.settings.listDiv + ' .bh-sl-close-icon');
891909
},
892910

893911
/**
894-
* Set up the normal mapping TODO rename this function and processforminput
912+
* Process the form values and/or query string
895913
*
896914
* @param distance {number} optional maximum distance
897915
*/
898-
beginMapping: function (distance) {
916+
processForm: function (distance) {
899917
var _this = this;
900918
var mappingObj = {};
901-
// Get the user input and use it
902-
addressInput = $('#' + this.settings.addressID).val();
903-
nameInput = $('#' + this.settings.nameID).val();
919+
920+
if(this.settings.querystringParams === true) {
921+
922+
// Check for query string parameters
923+
if(this.getQueryString(this.settings.addressID) || this.getQueryString(this.settings.nameID)){
924+
addressInput = this.getQueryString(this.settings.addressID);
925+
nameInput = this.getQueryString(this.settings.nameID);
926+
}
927+
else{
928+
// Get the user input and use it
929+
addressInput = $('#' + this.settings.addressID).val();
930+
nameInput = $('#' + this.settings.nameID).val();
931+
}
932+
}
933+
else {
934+
// Get the user input and use it
935+
addressInput = $('#' + this.settings.addressID).val();
936+
nameInput = $('#' + this.settings.nameID).val();
937+
}
904938

905939
// Get the region setting if set
906940
var region = $('#' + this.settings.regionID).val();
@@ -1113,11 +1147,13 @@
11131147

11141148
// Name search - using taxonomy filter to handle
11151149
if (_this.settings.nameSearch === true) {
1116-
if (_this.settings.nameAttribute !== null) {
1117-
filters[_this.settings.nameAttribute] = nameInput;
1118-
}
1119-
else {
1120-
filters.name = [nameInput];
1150+
if(typeof nameInput !== 'undefined') {
1151+
if (_this.settings.nameAttribute !== null) {
1152+
filters[_this.settings.nameAttribute] = nameInput;
1153+
}
1154+
else {
1155+
filters.name = [nameInput];
1156+
}
11211157
}
11221158
}
11231159

@@ -1429,7 +1465,7 @@
14291465
_this.reset();
14301466
if ((olat) && (olng)) {
14311467
_this.settings.mapSettings.zoom = 0;
1432-
_this.beginMapping();
1468+
_this.processForm();
14331469
}
14341470
else {
14351471
_this.mapping();
@@ -1450,7 +1486,7 @@
14501486
else {
14511487
_this.settings.mapSettings.zoom = 0;
14521488
}
1453-
_this.beginMapping();
1489+
_this.processForm();
14541490
}
14551491
else {
14561492
_this.mapping();
@@ -1477,7 +1513,7 @@
14771513
_this.reset();
14781514
if ((olat) && (olng)) {
14791515
_this.settings.mapSettings.zoom = 0;
1480-
_this.beginMapping();
1516+
_this.processForm();
14811517
}
14821518
else {
14831519
_this.mapping();
@@ -1493,7 +1529,7 @@
14931529
_this.reset();
14941530
if ((olat) && (olng)) {
14951531
_this.settings.mapSettings.zoom = originalZoom;
1496-
_this.beginMapping();
1532+
_this.processForm();
14971533
}
14981534
else {
14991535
_this.mapping();

0 commit comments

Comments
 (0)