Browse Source

Tweaked the script to get icon path

css_transitions
josdejong 10 years ago
parent
commit
1f56efe37c
2 changed files with 19 additions and 20 deletions
  1. +12
    -13
      src/graph/Graph.js
  2. +7
    -7
      src/graph/NavigationMixin.js

+ 12
- 13
src/graph/Graph.js View File

@ -88,7 +88,7 @@ function Graph (container, data, options) {
}, },
navigation: { navigation: {
enabled: false, enabled: false,
iconPath: this._getIconURL()
iconPath: this._getScriptPath() + '/img'
}, },
keyboard: { keyboard: {
enabled: false, 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 * @private
*/ */
Graph.prototype._getIconURL = function() {
Graph.prototype._getScriptPath = function() {
var scripts = document.getElementsByTagName( 'script' ); 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++) { 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);
} }
} }

+ 7
- 7
src/graph/NavigationMixin.js View File

@ -52,22 +52,22 @@ var NavigationMixin = {
var offset = 15; var offset = 15;
var intermediateOffset = 7; var intermediateOffset = 7;
var navigationNodes = [ 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}, 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}, 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}, 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}, 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, verticalAlignTop: false, horizontalAlignLeft: false,
x: this.navigationClientWidth - 45 - offset - intermediateOffset, y: this.navigationClientHeight - 15 - offset}, 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, verticalAlignTop: false, horizontalAlignLeft: false,
x: this.navigationClientWidth - 15 - offset, y: this.navigationClientHeight - 15 - offset}, 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, verticalAlignTop: false, horizontalAlignLeft: false,
x: this.navigationClientWidth - 15 - offset, y: this.navigationClientHeight - 45 - offset - intermediateOffset} x: this.navigationClientWidth - 15 - offset, y: this.navigationClientHeight - 45 - offset - intermediateOffset}
]; ];

Loading…
Cancel
Save