aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/comments/frontend/openembeddedimage.js
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap/comments/frontend/openembeddedimage.js')
-rw-r--r--bootstrap/comments/frontend/openembeddedimage.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/bootstrap/comments/frontend/openembeddedimage.js b/bootstrap/comments/frontend/openembeddedimage.js
new file mode 100644
index 0000000..fc95e16
--- /dev/null
+++ b/bootstrap/comments/frontend/openembeddedimage.js
@@ -0,0 +1,50 @@
+// Callback to close the embedded image (openembeddedimage.js)
+HashOverConstructor.prototype.closeEmbeddedImage = function (image)
+{
+ // Reset source
+ image.src = image.dataset.placeholder;
+
+ // Reset title
+ image.title = this.locale['external-image-tip'];
+
+ // Remove loading class from wrapper
+ this.classes.remove (image.parentNode, 'hashover-loading');
+};
+
+// Onclick callback function for embedded images (openembeddedimage.js)
+HashOverConstructor.prototype.openEmbeddedImage = function (image)
+{
+ // Reference to this object
+ var hashover = this;
+
+ // If embedded image is open, close it and return false
+ if (image.src === image.dataset.url) {
+ this.closeEmbeddedImage (image);
+ return false;
+ }
+
+ // Set title
+ image.title = this.locale['loading'];
+
+ // Add loading class to wrapper
+ this.classes.add (image.parentNode, 'hashover-loading');
+
+ // Change title and remove load event handler once image is loaded
+ image.onload = function ()
+ {
+ image.title = hashover.locale['click-to-close'];
+ image.onload = null;
+
+ // Remove loading class from wrapper
+ hashover.classes.remove (image.parentNode, 'hashover-loading');
+ };
+
+ // Close embedded image if any error occurs
+ image.onerror = function ()
+ {
+ hashover.closeEmbeddedImage (this);
+ };
+
+ // Set placeholder image to embedded source
+ image.src = image.dataset.url;
+};