2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
Htk.FullImage = new Class
|
|
|
|
({
|
|
|
|
Extends: Vn.Object
|
|
|
|
|
|
|
|
,img: null
|
|
|
|
,timeout: 0
|
|
|
|
,loading: false
|
|
|
|
,visible: false
|
|
|
|
,hideCalled: false
|
2015-02-08 15:38:38 +00:00
|
|
|
,closed: false
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,initialize: function (props)
|
|
|
|
{
|
|
|
|
var div = document.createElement ('div');
|
2015-03-06 23:33:54 +00:00
|
|
|
div.className = 'htk-full-image';
|
2015-02-01 03:21:54 +00:00
|
|
|
div.addEventListener ('mouseover', this.cancelHide.bind (this));
|
|
|
|
div.addEventListener ('mouseout', this.hideNow.bind (this));
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var loadingBox = document.createElement ('div');
|
2015-03-06 23:33:54 +00:00
|
|
|
loadingBox.className = 'htk-full-image-loader';
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-11-30 16:46:24 +00:00
|
|
|
var spinner = new Htk.Spinner ();
|
|
|
|
loadingBox.appendChild (spinner.getNode ());
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
this.div = div;
|
|
|
|
this.loadingBox = loadingBox;
|
2015-11-30 16:46:24 +00:00
|
|
|
this.spinner = spinner;
|
2015-11-09 08:14:33 +00:00
|
|
|
this.parent (props);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,getLeft: function (width)
|
|
|
|
{
|
2015-12-15 15:37:10 +00:00
|
|
|
return parseInt ((Vn.Browser.getInnerWidth () - width) / 2) +'px';
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,getTop: function (height)
|
|
|
|
{
|
2015-12-15 15:37:10 +00:00
|
|
|
return parseInt ((Vn.Browser.getInnerHeight () - height) / 2) +'px';
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 08:50:06 +00:00
|
|
|
,show: function (src)
|
|
|
|
{
|
2015-02-08 15:38:38 +00:00
|
|
|
if (this.closed && this.src == src)
|
2015-09-22 07:20:47 +00:00
|
|
|
{
|
|
|
|
this.closed = false;
|
2015-02-08 15:38:38 +00:00
|
|
|
return;
|
2015-09-22 07:20:47 +00:00
|
|
|
}
|
2015-02-08 15:38:38 +00:00
|
|
|
|
2015-02-01 03:21:54 +00:00
|
|
|
this.cancelHide ();
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-02-08 15:38:38 +00:00
|
|
|
this.closed = false;
|
|
|
|
this.src = src
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
this.img = document.createElement ('img');
|
2015-02-08 15:38:38 +00:00
|
|
|
this.img.src = src;
|
2015-01-23 13:09:30 +00:00
|
|
|
this.img.addEventListener ('load', this.imageLoaded.bind (this, this.img));
|
|
|
|
this.img.addEventListener ('error', this.hideLoading.bind (this));
|
|
|
|
|
|
|
|
if (!this.img.complete && !this.loading)
|
|
|
|
{
|
|
|
|
document.body.appendChild (this.loadingBox);
|
2015-11-30 16:46:24 +00:00
|
|
|
this.spinner.start ();
|
2015-01-23 13:09:30 +00:00
|
|
|
this.loading = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,imageLoaded: function (img)
|
|
|
|
{
|
|
|
|
if (img != this.img || this.hideCalled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var scale = 1.0;
|
|
|
|
var width = img.width;
|
|
|
|
var height = img.height;
|
2015-08-26 22:18:53 +00:00
|
|
|
var innerWidth = Vn.Browser.getInnerWidth () - 50;
|
|
|
|
var innerHeight = Vn.Browser.getInnerHeight () - 50;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (width > innerWidth)
|
|
|
|
{
|
|
|
|
scale = width / innerWidth;
|
|
|
|
height = parseInt (height / scale);
|
|
|
|
width = innerWidth;
|
|
|
|
}
|
|
|
|
if (height > innerHeight)
|
|
|
|
{
|
|
|
|
scale = height / innerHeight;
|
|
|
|
width = parseInt (width / scale);
|
|
|
|
height = innerHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.hideLoading ();
|
|
|
|
this.div.style.left = this.getLeft (width + 2);
|
|
|
|
this.div.style.top = this.getTop (height + 2);
|
|
|
|
this.div.style.width = width +'px';
|
|
|
|
this.div.style.height = height +'px';
|
|
|
|
|
|
|
|
if (scale !== 1.0)
|
|
|
|
{
|
|
|
|
img.style.width = width +'px';
|
|
|
|
img.style.height = height +'px';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.div.firstChild != null)
|
|
|
|
this.div.replaceChild (img, this.div.firstChild);
|
|
|
|
else
|
|
|
|
this.div.appendChild (img);
|
2015-02-08 15:38:38 +00:00
|
|
|
|
|
|
|
img.addEventListener ('click', this.onImageClick.bind (this));
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (!this.visible)
|
|
|
|
{
|
|
|
|
document.body.appendChild (this.div);
|
|
|
|
this.visible = true;
|
2015-02-01 03:21:54 +00:00
|
|
|
|
|
|
|
this.onDocumentClickCallback = this.hideNow.bind (this);
|
|
|
|
document.addEventListener ('click', this.onDocumentClickCallback);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-08 15:38:38 +00:00
|
|
|
|
|
|
|
,onImageClick: function ()
|
|
|
|
{
|
|
|
|
this.closed = true;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,hide: function ()
|
|
|
|
{
|
|
|
|
this.hideCalled = true;
|
|
|
|
this.hideLoading ();
|
|
|
|
|
|
|
|
if (this.visible)
|
2015-02-01 03:21:54 +00:00
|
|
|
this.timeout = setTimeout (this.hideNow.bind (this), 450);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-02-01 03:21:54 +00:00
|
|
|
,hideNow: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-02-01 03:21:54 +00:00
|
|
|
if (this.visible)
|
|
|
|
{
|
|
|
|
document.body.removeChild (this.div);
|
|
|
|
this.hideCalled = true;
|
|
|
|
this.visible = false;
|
|
|
|
this.timeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.removeEventListener ('click', this.onDocumentClickCallback);
|
|
|
|
this.onDocumentClickCallback = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
,cancelHide: function ()
|
|
|
|
{
|
|
|
|
if (this.timeout)
|
|
|
|
{
|
|
|
|
clearTimeout (this.timeout);
|
|
|
|
this.timeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.hideCalled = false;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,hideLoading: function ()
|
|
|
|
{
|
|
|
|
if (this.loading)
|
|
|
|
{
|
|
|
|
document.body.removeChild (this.loadingBox);
|
2015-11-30 16:46:24 +00:00
|
|
|
this.spinner.stop ();
|
2015-01-23 13:09:30 +00:00
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|