From 4b21faa2ffdc4616c648cd45bd7adb4ad6982565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Thu, 25 Jan 2018 21:15:24 +0100 Subject: [PATCH] CategoryOverpass: move updateAssets to separate function; also update info --- src/CategoryOverpass.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/CategoryOverpass.js b/src/CategoryOverpass.js index 3a7022a1..c5b31877 100644 --- a/src/CategoryOverpass.js +++ b/src/CategoryOverpass.js @@ -75,25 +75,7 @@ function CategoryOverpass (options, data) { data.feature.appUrl = '#' + this.id + '/{{ id }}' data.styleNoBindPopup = [ 'hover', 'selected' ] data.stylesNoAutoShow = [ 'hover', 'selected' ] - data.updateAssets = div => { - var imgs = div.getElementsByTagName('img') - for (var i = 0; i < imgs.length; i++) { - let img = imgs[i] - - var src = img.getAttribute('src') - if (src === null) { - } else if (src.match(/^maki:.*/)) { - let m = src.match(/^maki:([a-z0-9\-]*)(?:\?(.*))?$/) - img.removeAttribute('src') - maki(m[1], m[2] ? qs(m[2]) : {}, function (img, err, result) { - img.setAttribute('src', result) - }.bind(this, img)) - } else if (!src.match(/^(https?:|data:|\.|\/)/)) { - img.setAttribute('src', (typeof openstreetbrowserPrefix === 'undefined' ? './' : openstreetbrowserPrefix) + - 'asset.php?repo=' + this.options.repositoryId + '&file=' + encodeURIComponent(img.getAttribute('src'))) - } - } - } + data.updateAssets = this.updateAssets.bind(this) this.layer = new OverpassLayer(data) @@ -184,6 +166,26 @@ function CategoryOverpass (options, data) { }.bind(this)) } +CategoryOverpass.prototype.updateAssets = function (div) { + var imgs = div.getElementsByTagName('img') + for (var i = 0; i < imgs.length; i++) { + let img = imgs[i] + + var src = img.getAttribute('src') + if (src === null) { + } else if (src.match(/^maki:.*/)) { + let m = src.match(/^maki:([a-z0-9\-]*)(?:\?(.*))?$/) + img.removeAttribute('src') + maki(m[1], m[2] ? qs(m[2]) : {}, function (img, err, result) { + img.setAttribute('src', result) + }.bind(this, img)) + } else if (!src.match(/^(https?:|data:|\.|\/)/)) { + img.setAttribute('src', (typeof openstreetbrowserPrefix === 'undefined' ? './' : openstreetbrowserPrefix) + + 'asset.php?repo=' + this.options.repositoryId + '&file=' + encodeURIComponent(img.getAttribute('src'))) + } + } +} + CategoryOverpass.prototype.load = function (callback) { OpenStreetBrowserLoader.getTemplate('popupBody', this.options, function (err, template) { if (err) { @@ -293,6 +295,7 @@ CategoryOverpass.prototype.updateInfo = function () { data.map = { zoom: map.getZoom() } } this.domInfo.innerHTML = this.templateInfo.render(data) + this.updateAssets(this.domInfo) global.currentCategory = null }