Skip to content
Snippets Groups Projects
Commit f69c8b33 authored by Brandon Bergren's avatar Brandon Bergren
Browse files

JSLint whitespace

parent 4522fd59
No related branches found
No related tags found
No related merge requests found
/* $Id$ */ /* $Id$ */
/** /**
* @file
* Drupal to Google Maps API bridge. * Drupal to Google Maps API bridge.
*/ */
/*global $, Drupal, GLatLng, GSmallZoomControl, GLargeMapControl, GMap2 */
/*global GMapTypeControl, GSmallMapControl, G_HYBRID_MAP, G_NORMAL_MAP */
/*global G_PHYSICAL_MAP, G_SATELLITE_MAP, GHierarchicalMapTypeControl */
/*global GKeyboardHandler, GLatLngBounds, GMenuMapTypeControl, GEvent */
/*global GOverviewMapControl, GScaleControl, GUnload */
// GMap overseer singleton // GMap overseer singleton
Drupal.gmap = new function() { Drupal.gmap = new function () {
var _handlers = {}; var _handlers = {};
var _maps = {}; var _maps = {};
...@@ -15,42 +22,44 @@ Drupal.gmap = new function() { ...@@ -15,42 +22,44 @@ Drupal.gmap = new function() {
* which you have the mapid for. * which you have the mapid for.
* Be a good GMap citizen! Remember to send change()s after modifying variables! * Be a good GMap citizen! Remember to send change()s after modifying variables!
*/ */
this.getMap = function(mapid) { this.getMap = function (mapid) {
return _maps[mapid]; return _maps[mapid];
}; };
this.unloadMap = function(mapid) { this.unloadMap = function (mapid) {
delete _maps[mapid]; delete _maps[mapid];
}; };
this.addHandler = function(handler,callback) { this.addHandler = function (handler, callback) {
if (!_handlers[handler]) { if (!_handlers[handler]) {
_handlers[handler] = []; _handlers[handler] = [];
} }
_handlers[handler].push(callback); _handlers[handler].push(callback);
}; };
this.globalChange = function(name,userdata) { this.globalChange = function (name, userdata) {
for (var mapid in Drupal.settings.gmap) { for (var mapid in Drupal.settings.gmap) {
_maps[mapid].change(name,-1,userdata); if (Drupal.settings.gmap.hasOwnProperty(mapid)) {
_maps[mapid].change(name, -1, userdata);
}
} }
}; };
this.setup = function() { this.setup = function () {
var obj = this; var obj = this;
var initcallback = function(mapid) { var initcallback = function (mapid) {
return (function() { return (function () {
_maps[mapid].change("bootstrap_options",-1); _maps[mapid].change("bootstrap_options", -1);
_maps[mapid].change("boot",-1); _maps[mapid].change("boot", -1);
_maps[mapid].change("init",-1); _maps[mapid].change("init", -1);
// Send some changed events to fire up the rest of the initial settings.. // Send some changed events to fire up the rest of the initial settings..
_maps[mapid].change("maptypechange",-1); _maps[mapid].change("maptypechange", -1);
_maps[mapid].change("controltypechange",-1); _maps[mapid].change("controltypechange", -1);
_maps[mapid].change("alignchange",-1); _maps[mapid].change("alignchange", -1);
// Set ready to put the event system into action. // Set ready to put the event system into action.
_maps[mapid].ready = true; _maps[mapid].ready = true;
_maps[mapid].change("ready",-1); _maps[mapid].change("ready", -1);
}); });
}; };
...@@ -70,7 +79,7 @@ Drupal.gmap = new function() { ...@@ -70,7 +79,7 @@ Drupal.gmap = new function() {
} }
if (_handlers[control]) { if (_handlers[control]) {
for (var i=0; i<_handlers[control].length; i++) { for (var i = 0; i < _handlers[control].length; i++) {
_handlers[control][i].call(_maps[mapid], obj); _handlers[control][i].call(_maps[mapid], obj);
} }
} }
...@@ -83,7 +92,7 @@ Drupal.gmap = new function() { ...@@ -83,7 +92,7 @@ Drupal.gmap = new function() {
Drupal.gmap.factory = {}; Drupal.gmap.factory = {};
Drupal.gmap.map = function(v) { Drupal.gmap.map = function (v) {
this.vars = v; this.vars = v;
this.map = undefined; this.map = undefined;
this.ready = false; this.ready = false;
...@@ -92,7 +101,7 @@ Drupal.gmap.map = function(v) { ...@@ -92,7 +101,7 @@ Drupal.gmap.map = function(v) {
/** /**
* Register interest in a change. * Register interest in a change.
*/ */
this.bind = function(name,callback) { this.bind = function (name, callback) {
if (!_bindings[name]) { if (!_bindings[name]) {
_bindings[name] = []; _bindings[name] = [];
} }
...@@ -103,7 +112,7 @@ Drupal.gmap.map = function(v) { ...@@ -103,7 +112,7 @@ Drupal.gmap.map = function(v) {
* Change notification. * Change notification.
* Interested parties can act on changes. * Interested parties can act on changes.
*/ */
this.change = function(name,id,userdata) { this.change = function (name, id, userdata) {
var c; var c;
if (_bindings[name]) { if (_bindings[name]) {
for (c = 0; c < _bindings[name].length; c++) { for (c = 0; c < _bindings[name].length; c++) {
...@@ -113,7 +122,7 @@ Drupal.gmap.map = function(v) { ...@@ -113,7 +122,7 @@ Drupal.gmap.map = function(v) {
} }
} }
if (name != 'all') { if (name != 'all') {
this.change('all',-1,name,userdata); this.change('all', -1, name, userdata);
} }
}; };
...@@ -121,11 +130,11 @@ Drupal.gmap.map = function(v) { ...@@ -121,11 +130,11 @@ Drupal.gmap.map = function(v) {
* Deferred change notification. * Deferred change notification.
* This will cause a change notification to be tacked on to the *end* of the event queue. * This will cause a change notification to be tacked on to the *end* of the event queue.
*/ */
this.deferChange = function(name,id,userdata) { this.deferChange = function (name, id, userdata) {
var obj = this; var obj = this;
// This will move the function call to the end of the event loop. // This will move the function call to the end of the event loop.
setTimeout(function(){ setTimeout(function () {
obj.change(name,id,userdata); obj.change(name, id, userdata);
}, 0); }, 0);
}; };
}; };
...@@ -133,24 +142,24 @@ Drupal.gmap.map = function(v) { ...@@ -133,24 +142,24 @@ Drupal.gmap.map = function(v) {
//////////////////////////////////////// ////////////////////////////////////////
// Map widget // // Map widget //
//////////////////////////////////////// ////////////////////////////////////////
Drupal.gmap.addHandler('gmap',function(elem) { Drupal.gmap.addHandler('gmap', function (elem) {
var obj = this; var obj = this;
var _ib = {}; var _ib = {};
// Respond to incoming zooms // Respond to incoming zooms
_ib.zoom = obj.bind("zoom",function(){ _ib.zoom = obj.bind("zoom", function () {
obj.map.setZoom(obj.vars.zoom); obj.map.setZoom(obj.vars.zoom);
}); });
// Respond to incoming moves // Respond to incoming moves
_ib.move = obj.bind("move", function(){ _ib.move = obj.bind("move", function () {
obj.map.panTo(new GLatLng(obj.vars.latitude,obj.vars.longitude)); obj.map.panTo(new GLatLng(obj.vars.latitude, obj.vars.longitude));
}); });
// Respond to incoming map type changes // Respond to incoming map type changes
_ib.mtc = obj.bind("maptypechange", function() { _ib.mtc = obj.bind("maptypechange", function () {
var i; var i;
for (i = 0; i < obj.opts.mapTypeNames.length; i++) { for (i = 0; i < obj.opts.mapTypeNames.length; i++) {
if (obj.opts.mapTypeNames[i] == obj.vars.maptype) { if (obj.opts.mapTypeNames[i] == obj.vars.maptype) {
...@@ -161,14 +170,14 @@ Drupal.gmap.addHandler('gmap',function(elem) { ...@@ -161,14 +170,14 @@ Drupal.gmap.addHandler('gmap',function(elem) {
}); });
// Respond to incoming width changes. // Respond to incoming width changes.
_ib.width = obj.bind("widthchange",function(w){ _ib.width = obj.bind("widthchange", function (w) {
obj.map.getContainer().style.width = w; obj.map.getContainer().style.width = w;
obj.map.checkResize(); obj.map.checkResize();
}); });
// Send out outgoing width changes. // Send out outgoing width changes.
// N/A // N/A
// Respond to incoming height changes. // Respond to incoming height changes.
_ib.height = obj.bind("heightchange",function(h){ _ib.height = obj.bind("heightchange", function (h) {
obj.map.getContainer().style.height = h; obj.map.getContainer().style.height = h;
obj.map.checkResize(); obj.map.checkResize();
}); });
...@@ -176,18 +185,24 @@ Drupal.gmap.addHandler('gmap',function(elem) { ...@@ -176,18 +185,24 @@ Drupal.gmap.addHandler('gmap',function(elem) {
// N/A // N/A
// Respond to incoming control type changes. // Respond to incoming control type changes.
_ib.ctc = obj.bind("controltypechange",function() { _ib.ctc = obj.bind("controltypechange", function () {
if(obj.currentcontrol) { if (obj.currentcontrol) {
obj.map.removeControl(obj.currentcontrol); obj.map.removeControl(obj.currentcontrol);
} }
if (obj.vars.controltype=='Micro') {obj.map.addControl(obj.currentcontrol = new GSmallZoomControl());} if (obj.vars.controltype == 'Micro') {
if (obj.vars.controltype=='Small') {obj.map.addControl(obj.currentcontrol = new GSmallMapControl());} obj.map.addControl(obj.currentcontrol = new GSmallZoomControl());
if (obj.vars.controltype=='Large') {obj.map.addControl(obj.currentcontrol = new GLargeMapControl());} }
else if (obj.vars.controltype == 'Small') {
obj.map.addControl(obj.currentcontrol = new GSmallMapControl());
}
else if (obj.vars.controltype == 'Large') {
obj.map.addControl(obj.currentcontrol = new GLargeMapControl());
}
}); });
// Send out outgoing control type changes. // Send out outgoing control type changes.
// N/A // N/A
obj.bind("bootstrap_options", function() { obj.bind("bootstrap_options", function () {
// Bootup options. // Bootup options.
var opts = {}; // Object literal GMapOptions var opts = {}; // Object literal GMapOptions
obj.opts = opts; obj.opts = opts;
...@@ -216,11 +231,11 @@ Drupal.gmap.addHandler('gmap',function(elem) { ...@@ -216,11 +231,11 @@ Drupal.gmap.addHandler('gmap',function(elem) {
}); });
obj.bind("boot", function() { obj.bind("boot", function () {
obj.map = new GMap2(elem, obj.opts); obj.map = new GMap2(elem, obj.opts);
}); });
obj.bind("init",function() { obj.bind("init", function () {
var map = obj.map; var map = obj.map;
// Map type control // Map type control
...@@ -257,17 +272,17 @@ Drupal.gmap.addHandler('gmap',function(elem) { ...@@ -257,17 +272,17 @@ Drupal.gmap.addHandler('gmap',function(elem) {
// Modify collapsable fieldsets to make maps check dom state when the resize handle // Modify collapsable fieldsets to make maps check dom state when the resize handle
// is clicked. This may not necessarily be the correct thing to do in all themes, // is clicked. This may not necessarily be the correct thing to do in all themes,
// hence it being a behavior. // hence it being a behavior.
setTimeout(function(){ setTimeout(function () {
var r = function() { var r = function () {
map.checkResize(); map.checkResize();
map.setCenter(new GLatLng(obj.vars.latitude,obj.vars.longitude), obj.vars.zoom); map.setCenter(new GLatLng(obj.vars.latitude, obj.vars.longitude), obj.vars.zoom);
}; };
$(elem).parents('fieldset.collapsible').children('legend').children('a').click(r); $(elem).parents('fieldset.collapsible').children('legend').children('a').click(r);
// Would be nice, but doesn't work. // Would be nice, but doesn't work.
//$(elem).parents('fieldset.collapsible').children('.fieldset-wrapper').scroll(r); //$(elem).parents('fieldset.collapsible').children('.fieldset-wrapper').scroll(r);
},0); }, 0);
} }
map.setCenter(new GLatLng(obj.vars.latitude,obj.vars.longitude), obj.vars.zoom); map.setCenter(new GLatLng(obj.vars.latitude, obj.vars.longitude), obj.vars.zoom);
if (!obj.vars.nocontzoom) { if (!obj.vars.nocontzoom) {
map.enableDoubleClickZoom(); map.enableDoubleClickZoom();
...@@ -278,13 +293,13 @@ Drupal.gmap.addHandler('gmap',function(elem) { ...@@ -278,13 +293,13 @@ Drupal.gmap.addHandler('gmap',function(elem) {
} }
// Send out outgoing zooms // Send out outgoing zooms
GEvent.addListener(map, "zoomend", function(oldzoom,newzoom) { GEvent.addListener(map, "zoomend", function (oldzoom, newzoom) {
obj.vars.zoom = newzoom; obj.vars.zoom = newzoom;
obj.change("zoom", _ib.zoom); obj.change("zoom", _ib.zoom);
}); });
// Send out outgoing moves // Send out outgoing moves
GEvent.addListener(map,"moveend",function() { GEvent.addListener(map, "moveend", function () {
var coord = map.getCenter(); var coord = map.getCenter();
obj.vars.latitude = coord.lat(); obj.vars.latitude = coord.lat();
obj.vars.longitude = coord.lng(); obj.vars.longitude = coord.lng();
...@@ -292,7 +307,7 @@ Drupal.gmap.addHandler('gmap',function(elem) { ...@@ -292,7 +307,7 @@ Drupal.gmap.addHandler('gmap',function(elem) {
}); });
// Send out outgoing map type changes. // Send out outgoing map type changes.
GEvent.addListener(map,"maptypechanged",function() { GEvent.addListener(map, "maptypechanged", function () {
// If the map isn't ready yet, ignore it. // If the map isn't ready yet, ignore it.
if (obj.ready) { if (obj.ready) {
var type = map.getCurrentMapType(); var type = map.getCurrentMapType();
...@@ -312,14 +327,14 @@ Drupal.gmap.addHandler('gmap',function(elem) { ...@@ -312,14 +327,14 @@ Drupal.gmap.addHandler('gmap',function(elem) {
//////////////////////////////////////// ////////////////////////////////////////
// Zoom widget // // Zoom widget //
//////////////////////////////////////// ////////////////////////////////////////
Drupal.gmap.addHandler('zoom', function(elem) { Drupal.gmap.addHandler('zoom', function (elem) {
var obj = this; var obj = this;
// Respond to incoming zooms // Respond to incoming zooms
var binding = obj.bind("zoom", function(){ var binding = obj.bind("zoom", function () {
elem.value = obj.vars.zoom; elem.value = obj.vars.zoom;
}); });
// Send out outgoing zooms // Send out outgoing zooms
$(elem).change(function() { $(elem).change(function () {
obj.vars.zoom = parseInt(elem.value, 10); obj.vars.zoom = parseInt(elem.value, 10);
obj.change("zoom", binding); obj.change("zoom", binding);
}); });
...@@ -328,14 +343,14 @@ Drupal.gmap.addHandler('zoom', function(elem) { ...@@ -328,14 +343,14 @@ Drupal.gmap.addHandler('zoom', function(elem) {
//////////////////////////////////////// ////////////////////////////////////////
// Latitude widget // // Latitude widget //
//////////////////////////////////////// ////////////////////////////////////////
Drupal.gmap.addHandler('latitude', function(elem) { Drupal.gmap.addHandler('latitude', function (elem) {
var obj = this; var obj = this;
// Respond to incoming movements. // Respond to incoming movements.
var binding = obj.bind("move", function(){ var binding = obj.bind("move", function () {
elem.value = '' + obj.vars.latitude; elem.value = '' + obj.vars.latitude;
}); });
// Send out outgoing movements. // Send out outgoing movements.
$(elem).change(function() { $(elem).change(function () {
obj.vars.latitude = Number(this.value); obj.vars.latitude = Number(this.value);
obj.change("move", binding); obj.change("move", binding);
}); });
...@@ -344,14 +359,14 @@ Drupal.gmap.addHandler('latitude', function(elem) { ...@@ -344,14 +359,14 @@ Drupal.gmap.addHandler('latitude', function(elem) {
//////////////////////////////////////// ////////////////////////////////////////
// Longitude widget // // Longitude widget //
//////////////////////////////////////// ////////////////////////////////////////
Drupal.gmap.addHandler('longitude', function(elem) { Drupal.gmap.addHandler('longitude', function (elem) {
var obj = this; var obj = this;
// Respond to incoming movements. // Respond to incoming movements.
var binding = obj.bind("move", function(){ var binding = obj.bind("move", function () {
elem.value = '' + obj.vars.longitude; elem.value = '' + obj.vars.longitude;
}); });
// Send out outgoing movements. // Send out outgoing movements.
$(elem).change(function() { $(elem).change(function () {
obj.vars.longitude = Number(this.value); obj.vars.longitude = Number(this.value);
obj.change("move", binding); obj.change("move", binding);
}); });
...@@ -360,14 +375,14 @@ Drupal.gmap.addHandler('longitude', function(elem) { ...@@ -360,14 +375,14 @@ Drupal.gmap.addHandler('longitude', function(elem) {
//////////////////////////////////////// ////////////////////////////////////////
// Latlon widget // // Latlon widget //
//////////////////////////////////////// ////////////////////////////////////////
Drupal.gmap.addHandler('latlon', function(elem) { Drupal.gmap.addHandler('latlon', function (elem) {
var obj = this; var obj = this;
// Respond to incoming movements. // Respond to incoming movements.
var binding = obj.bind("move", function(){ var binding = obj.bind("move", function () {
elem.value = '' + obj.vars.latitude + ',' + obj.vars.longitude; elem.value = '' + obj.vars.latitude + ',' + obj.vars.longitude;
}); });
// Send out outgoing movements. // Send out outgoing movements.
$(elem).change(function() { $(elem).change(function () {
var t = this.value.split(','); var t = this.value.split(',');
obj.vars.latitude = Number(t[0]); obj.vars.latitude = Number(t[0]);
obj.vars.longitude = Number(t[1]); obj.vars.longitude = Number(t[1]);
...@@ -378,85 +393,85 @@ Drupal.gmap.addHandler('latlon', function(elem) { ...@@ -378,85 +393,85 @@ Drupal.gmap.addHandler('latlon', function(elem) {
//////////////////////////////////////// ////////////////////////////////////////
// Maptype widget // // Maptype widget //
//////////////////////////////////////// ////////////////////////////////////////
Drupal.gmap.addHandler('maptype', function(elem) { Drupal.gmap.addHandler('maptype', function (elem) {
var obj = this; var obj = this;
// Respond to incoming movements. // Respond to incoming movements.
var binding = obj.bind("maptypechange", function(){ var binding = obj.bind("maptypechange", function () {
elem.value = obj.vars.maptype; elem.value = obj.vars.maptype;
}); });
// Send out outgoing movements. // Send out outgoing movements.
$(elem).change(function() { $(elem).change(function () {
obj.vars.maptype = elem.value; obj.vars.maptype = elem.value;
obj.change("maptypechange", binding); obj.change("maptypechange", binding);
}); });
}); });
(function() { // BEGIN CLOSURE (function () { // BEGIN CLOSURE
var re = /([0-9.]+)\s*(em|ex|px|in|cm|mm|pt|pc|%)/; var re = /([0-9.]+)\s*(em|ex|px|in|cm|mm|pt|pc|%)/;
var normalize = function(str) { var normalize = function (str) {
var ar; var ar;
if ((ar = re.exec(str.toLowerCase()))) { if ((ar = re.exec(str.toLowerCase()))) {
return ar[1] + ar[2]; return ar[1] + ar[2];
} }
return null; return null;
}; };
//////////////////////////////////////// ////////////////////////////////////////
// Width widget // // Width widget //
//////////////////////////////////////// ////////////////////////////////////////
Drupal.gmap.addHandler('width', function(elem) { Drupal.gmap.addHandler('width', function (elem) {
var obj = this; var obj = this;
// Respond to incoming width changes. // Respond to incoming width changes.
var binding = obj.bind("widthchange", function(w){ var binding = obj.bind("widthchange", function (w) {
elem.value = normalize(w); elem.value = normalize(w);
}); });
// Send out outgoing width changes. // Send out outgoing width changes.
$(elem).change(function() { $(elem).change(function () {
var n; var n;
if ((n = normalize(elem.value))) { if ((n = normalize(elem.value))) {
elem.value = n; elem.value = n;
obj.change('widthchange', binding, n); obj.change('widthchange', binding, n);
} }
}); });
obj.bind('init',function(){ obj.bind('init', function () {
$(elem).change(); $(elem).change();
});
}); });
});
//////////////////////////////////////// ////////////////////////////////////////
// Height widget // // Height widget //
//////////////////////////////////////// ////////////////////////////////////////
Drupal.gmap.addHandler('height', function(elem) { Drupal.gmap.addHandler('height', function (elem) {
var obj = this; var obj = this;
// Respond to incoming height changes. // Respond to incoming height changes.
var binding = obj.bind("heightchange",function(h){ var binding = obj.bind("heightchange", function (h) {
elem.value = normalize(h); elem.value = normalize(h);
}); });
// Send out outgoing height changes. // Send out outgoing height changes.
$(elem).change(function() { $(elem).change(function () {
var n; var n;
if ((n = normalize(elem.value))) { if ((n = normalize(elem.value))) {
elem.value = n; elem.value = n;
obj.change('heightchange', binding, n); obj.change('heightchange', binding, n);
} }
}); });
obj.bind('init',function(){ obj.bind('init', function () {
$(elem).change(); $(elem).change();
});
}); });
});
})(); // END CLOSURE })(); // END CLOSURE
//////////////////////////////////////// ////////////////////////////////////////
// Control type widget // // Control type widget //
//////////////////////////////////////// ////////////////////////////////////////
Drupal.gmap.addHandler('controltype', function(elem) { Drupal.gmap.addHandler('controltype', function (elem) {
var obj = this; var obj = this;
// Respond to incoming height changes. // Respond to incoming height changes.
var binding = obj.bind("controltypechange", function(){ var binding = obj.bind("controltypechange", function () {
elem.value = obj.vars.controltype; elem.value = obj.vars.controltype;
}); });
// Send out outgoing height changes. // Send out outgoing height changes.
$(elem).change(function() { $(elem).change(function () {
obj.vars.controltype = elem.value; obj.vars.controltype = elem.value;
obj.change("controltypechange", binding); obj.change("controltypechange", binding);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment