2018-10-30 14:05:23 +00:00
|
|
|
function Lightbox()
|
|
|
|
{
|
|
|
|
this.container = null;
|
2018-11-02 12:57:28 +00:00
|
|
|
this.img = null;
|
2018-10-30 14:05:23 +00:00
|
|
|
|
2018-11-02 12:57:28 +00:00
|
|
|
this.install = function(container, prefix)
|
2018-10-30 14:05:23 +00:00
|
|
|
{
|
2018-11-02 12:57:28 +00:00
|
|
|
this.container = container;
|
|
|
|
|
|
|
|
let back = document.createElement('div');
|
|
|
|
back.className = prefix + '-back';
|
|
|
|
this.addEvent(back, 'click', function(){ lightbox.close(); });
|
|
|
|
this.container.appendChild(back);
|
|
|
|
|
|
|
|
this.img = document.createElement('img');
|
|
|
|
this.img.className = prefix + '-img';
|
|
|
|
this.addEvent(this.img, 'click', function(){ lightbox.close(); });
|
|
|
|
this.container.appendChild(this.img);
|
2018-10-30 14:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.load = function(file)
|
|
|
|
{
|
2018-11-02 12:57:28 +00:00
|
|
|
this.img.src = file;
|
2018-10-30 14:05:23 +00:00
|
|
|
this.container.style.display = 'block';
|
|
|
|
}
|
|
|
|
|
|
|
|
this.close = function()
|
|
|
|
{
|
|
|
|
if (this.container.style.display != 'none')
|
|
|
|
{
|
|
|
|
this.container.style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
2018-11-02 12:57:28 +00:00
|
|
|
|
|
|
|
this.handle = function(element, file)
|
|
|
|
{
|
|
|
|
this.addEvent(element, 'click', function(){ lightbox.load(file); });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.addEvent = function(element, evnt, funct)
|
|
|
|
{
|
|
|
|
if (element.attachEvent)
|
|
|
|
{
|
|
|
|
return element.attachEvent('on'+evnt, funct);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return element.addEventListener(evnt, funct, false);
|
|
|
|
}
|
|
|
|
}
|
2018-10-30 14:05:23 +00:00
|
|
|
}
|