Skip to content

Instantly share code, notes, and snippets.

@danieltroger
Created May 24, 2015 13:25
Show Gist options
  • Select an option

  • Save danieltroger/94324a808344b26c5859 to your computer and use it in GitHub Desktop.

Select an option

Save danieltroger/94324a808344b26c5859 to your computer and use it in GitHub Desktop.
A better image viewer for blogspot pages (unfinished)
/* This script is not finished and won't work as it is.
The MIT License (MIT)
Copyright (c) 2015 Daniel Troger
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
HTMLElement.prototype.appendChilds = function() {
var a = arguments,
b = 0;
for (; b < a.length; b++) {
var c = a[b];
if (typeof c == "object") {
this.appendChild(a[b])
}
}
};
var viewer = function () {
var images = arguments[0] != undefined ? arguments[0] : document.images;
this.images = [];
this.current = 0;
for(var i = 0; i < images.length; i++)
{
var image = images[i],
parent = image.parentElement,
attrib = parent.attributes;
if(attrib.getNamedItem("imageanchor"))
{
parent.dataset.href = parent.href;
attrib.removeNamedItem("href");
parent.addEventListener("click",this.loadimage);
parent.style.cursor = "pointer";
this.images.push(image);
}
}
this.elements = {'container': document.createElement("div"),
'previous': new Image(),
'next': new Image(),
'close': new Image,
'main': new Image(),
'loading': document.createElement("span")
};
this.state = "paused"; //, loading, active
this.elements.container.appendChilds(
this.elements.previous,
this.elements.next,
this.elements.close,
this.elements.main,
this.elements.loading
);
document.body.appendChild(this.elements.container);
}
viewer.prototype.loadimage = function(e)
{
e.preventDefault();
var url = this.dataset.href;
console.log(url);
};
var v = new viewer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment