From a9938df45f61133f2c0ac6cc55106ffd04f0c0e9 Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Tue, 12 Jan 2016 15:34:48 -0600 Subject: [PATCH] Don't attempt to download maps without a url Allowing implementors to return a falsey value in the case where there's no appropriate map to be downloaded. --- src/multimap.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/multimap.js b/src/multimap.js index fb91201a..82d94965 100644 --- a/src/multimap.js +++ b/src/multimap.js @@ -69,27 +69,21 @@ jvm.MultiMap.prototype = { }, downloadMap: function(code){ - var that = this, - deferred = jvm.$.Deferred(); - - if (!this.mapsLoaded[code]) { - jvm.$.get(this.params.mapUrlByCode(code, this)).then(function(){ - that.mapsLoaded[code] = true; - deferred.resolve(); - }, function(){ - deferred.reject(); - }); - } else { - deferred.resolve(); - } - return deferred; + return jvm.$.get(this.params.mapUrlByCode(code, this)); }, - drillDown: function(name, code){ + drillDown: function(name, code, config){ + var mapIsHereAlready = !!jvm.Map.maps[this.params.mapNameByCode(code, this)] + var mapCanBeDownloaded = !!this.params.mapUrlByCode(code, this) + + if (!mapIsHereAlready && !mapCanBeDownloaded) { + return; + } + var currentMap = this.history[this.history.length - 1], that = this, focusPromise = currentMap.setFocus({region: code, animate: true}), - downloadPromise = this.downloadMap(code); + downloadPromise = mapIsHereAlready ? jvm.$.Deferred().resolve() : this.downloadMap(code); focusPromise.then(function(){ if (downloadPromise.state() === 'pending') {