diff --git a/.gitignore b/.gitignore
index 29c1ae2e..9471387e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ node_modules
.settings/org.eclipse.wst.jsdt.ui.superType.name
npm-debug.log
examples/graph/24_hierarchical_layout_userdefined2.html
+.DS_Store
diff --git a/docs/network.html b/docs/network.html
index 63a68dd8..e6791994 100644
--- a/docs/network.html
+++ b/docs/network.html
@@ -964,6 +964,12 @@ All options defined per-node override these global settings.
undefined |
Default image url for the nodes. only applicable to shape image . |
+
+ brokenImage |
+ String |
+ undefined |
+ Image url to use in the event that the url specified in the image property fails to load. only applicable to shape image . |
+
mass |
number |
diff --git a/lib/network/Images.js b/lib/network/Images.js
index 266eb491..7d46eea5 100644
--- a/lib/network/Images.js
+++ b/lib/network/Images.js
@@ -20,9 +20,10 @@ Images.prototype.setOnloadCallback = function(callback) {
/**
*
* @param {string} url Url of the image
+ * @param {string} url Url of an image to use if the url image is not found
* @return {Image} img The image object
*/
-Images.prototype.load = function(url) {
+Images.prototype.load = function(url, brokenUrl) {
var img = this.images[url];
if (img == undefined) {
// create the image
@@ -34,6 +35,14 @@ Images.prototype.load = function(url) {
images.callback(this);
}
};
+
+ img.onerror = function () {
+ this.src = brokenUrl;
+ if (images.callback) {
+ images.callback(this);
+ }
+ };
+
img.src = url;
}
diff --git a/lib/network/Node.js b/lib/network/Node.js
index cdaf0109..a9faec28 100644
--- a/lib/network/Node.js
+++ b/lib/network/Node.js
@@ -135,7 +135,7 @@ Node.prototype.setProperties = function(properties, constants) {
return;
}
- var fields = ['borderWidth','borderWidthSelected','shape','image','radius','fontColor',
+ var fields = ['borderWidth','borderWidthSelected','shape','image','brokenImage','radius','fontColor',
'fontSize','fontFace','fontFill','group','mass'
];
util.selectiveDeepExtend(fields, this.options, properties);
@@ -176,7 +176,7 @@ Node.prototype.setProperties = function(properties, constants) {
if (this.options.image!== undefined && this.options.image!= "") {
if (this.imagelist) {
- this.imageObj = this.imagelist.load(this.options.image);
+ this.imageObj = this.imagelist.load(this.options.image, this.options.brokenImage);
}
else {
throw "No imagelist provided";