From 1f56efe37ca85e79e3872cbb20a2685c56fefa89 Mon Sep 17 00:00:00 2001 From: josdejong Date: Fri, 31 Jan 2014 13:45:02 +0100 Subject: [PATCH] Tweaked the script to get icon path --- src/graph/Graph.js | 25 ++++++++++++------------- src/graph/NavigationMixin.js | 14 +++++++------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/graph/Graph.js b/src/graph/Graph.js index eb3aae14..d86384ec 100644 --- a/src/graph/Graph.js +++ b/src/graph/Graph.js @@ -88,7 +88,7 @@ function Graph (container, data, options) { }, navigation: { enabled: false, - iconPath: this._getIconURL() + iconPath: this._getScriptPath() + '/img' }, keyboard: { enabled: false, @@ -195,23 +195,22 @@ function Graph (container, data, options) { } /** - * get the URL where the navigation icons are located + * Get the script path where the vis.js library is located * - * @returns {string} + * @returns {string | null} path Path or null when not found. Path does not + * end with a slash. * @private */ -Graph.prototype._getIconURL = function() { +Graph.prototype._getScriptPath = function() { var scripts = document.getElementsByTagName( 'script' ); - var scriptNamePosition, srcPosition, imagePath; + + // find script named vis.js or vis.min.js for (var i = 0; i < scripts.length; i++) { - srcPosition = scripts[i].outerHTML.search("src"); - if (srcPosition != -1) { - scriptNamePosition = util.getLowestPositiveNumber(scripts[i].outerHTML.search("vis.js"), - scripts[i].outerHTML.search("vis.min.js")); - if (scriptNamePosition != -1) { - imagePath = scripts[i].outerHTML.substring(srcPosition+5,scriptNamePosition).concat("img/"); - return imagePath; - } + var src = scripts[i].src; + var match = src && /\/?vis(.min)?\.js$/.exec(src); + if (match) { + // return path without the script name + return src.substring(0, src.length - match[0].length); } } diff --git a/src/graph/NavigationMixin.js b/src/graph/NavigationMixin.js index ef8a18d2..20540622 100644 --- a/src/graph/NavigationMixin.js +++ b/src/graph/NavigationMixin.js @@ -52,22 +52,22 @@ var NavigationMixin = { var offset = 15; var intermediateOffset = 7; var navigationNodes = [ - {id: 'navigation_up', shape: 'image', image: DIR + 'uparrow.png', triggerFunction: "_moveUp", + {id: 'navigation_up', shape: 'image', image: DIR + '/uparrow.png', triggerFunction: "_moveUp", verticalAlignTop: false, x: 45 + offset + intermediateOffset, y: this.navigationClientHeight - 45 - offset - intermediateOffset}, - {id: 'navigation_down', shape: 'image', image: DIR + 'downarrow.png', triggerFunction: "_moveDown", + {id: 'navigation_down', shape: 'image', image: DIR + '/downarrow.png', triggerFunction: "_moveDown", verticalAlignTop: false, x: 45 + offset + intermediateOffset, y: this.navigationClientHeight - 15 - offset}, - {id: 'navigation_left', shape: 'image', image: DIR + 'leftarrow.png', triggerFunction: "_moveLeft", + {id: 'navigation_left', shape: 'image', image: DIR + '/leftarrow.png', triggerFunction: "_moveLeft", verticalAlignTop: false, x: 15 + offset, y: this.navigationClientHeight - 15 - offset}, - {id: 'navigation_right', shape: 'image', image: DIR + 'rightarrow.png',triggerFunction: "_moveRight", + {id: 'navigation_right', shape: 'image', image: DIR + '/rightarrow.png',triggerFunction: "_moveRight", verticalAlignTop: false, x: 75 + offset + 2 * intermediateOffset, y: this.navigationClientHeight - 15 - offset}, - {id: 'navigation_plus', shape: 'image', image: DIR + 'plus.png', triggerFunction: "_zoomIn", + {id: 'navigation_plus', shape: 'image', image: DIR + '/plus.png', triggerFunction: "_zoomIn", verticalAlignTop: false, horizontalAlignLeft: false, x: this.navigationClientWidth - 45 - offset - intermediateOffset, y: this.navigationClientHeight - 15 - offset}, - {id: 'navigation_min', shape: 'image', image: DIR + 'minus.png', triggerFunction: "_zoomOut", + {id: 'navigation_min', shape: 'image', image: DIR + '/minus.png', triggerFunction: "_zoomOut", verticalAlignTop: false, horizontalAlignLeft: false, x: this.navigationClientWidth - 15 - offset, y: this.navigationClientHeight - 15 - offset}, - {id: 'navigation_zoomExtends', shape: 'image', image: DIR + 'zoomExtends.png', triggerFunction: "zoomToFit", + {id: 'navigation_zoomExtends', shape: 'image', image: DIR + '/zoomExtends.png', triggerFunction: "zoomToFit", verticalAlignTop: false, horizontalAlignLeft: false, x: this.navigationClientWidth - 15 - offset, y: this.navigationClientHeight - 45 - offset - intermediateOffset} ];