0
1
Fork 0
hedera-web-mindshore/js/htk/full-image/index.js

80 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-06-06 08:53:59 +00:00
require('./style.scss');
var Popup = require('../popup');
var Spinner = require('../spinner');
2016-09-26 09:28:47 +00:00
module.exports = new Class
({
Extends: Vn.Object
2016-05-02 13:05:49 +00:00
,Properties:
{
2016-05-02 13:05:49 +00:00
/**
* Subdirectory where full images are allocated.
2022-05-26 06:08:31 +00:00
*/
2016-05-02 13:05:49 +00:00
fullDir:
2015-09-22 07:20:47 +00:00
{
2016-05-02 13:05:49 +00:00
type: String
2022-05-26 06:08:31 +00:00
,set: function(x) {
2016-05-02 13:05:49 +00:00
this._fullDir = x;
}
2022-05-26 06:08:31 +00:00
,get: function() {
2016-05-02 13:05:49 +00:00
return this._fullDir;
}
2015-09-22 07:20:47 +00:00
}
2016-05-02 13:05:49 +00:00
}
2015-02-08 15:38:38 +00:00
2022-05-26 06:08:31 +00:00
,show: function(src) {
var popup = new Popup({class: 'htk-full-image', modal: true});
2022-05-26 06:08:31 +00:00
var img = document.createElement('img');
2016-05-02 13:05:49 +00:00
img.className = 'htk-full-image';
2022-05-26 06:08:31 +00:00
img.addEventListener('click', this._onImageClick.bind(this, popup));
2016-05-02 13:05:49 +00:00
//img.addEventListener ('error', this._onImageError.bind (this, popup));
img.src = src;
2022-05-26 06:08:31 +00:00
if (!img.complete) {
img.addEventListener('load', this._onImageLoad.bind(this, popup, img));
2016-05-02 13:05:49 +00:00
2022-05-26 06:08:31 +00:00
var spinner = new Spinner();
spinner.start();
2016-05-02 13:05:49 +00:00
popup.child = spinner;
2022-05-26 06:08:31 +00:00
} else
this._onImageLoad(popup, img);
2016-05-02 13:05:49 +00:00
2022-05-26 06:08:31 +00:00
popup.open();
}
2022-05-26 06:08:31 +00:00
,_onImageLoad: function(popup, img) {
2016-05-02 13:05:49 +00:00
var scale = null;
var width = img.width;
var height = img.height;
2022-05-26 06:08:31 +00:00
var innerWidth = Vn.Browser.getInnerWidth() - 50;
var innerHeight = Vn.Browser.getInnerHeight() - 50;
2022-05-26 06:08:31 +00:00
if (width > innerWidth) {
scale = width / innerWidth;
2022-05-26 06:08:31 +00:00
height = parseInt(height / scale);
width = innerWidth;
}
2022-05-26 06:08:31 +00:00
if (height > innerHeight) {
scale = height / innerHeight;
2022-05-26 06:08:31 +00:00
width = parseInt(width / scale);
height = innerHeight;
}
2022-05-26 06:08:31 +00:00
if (scale !== null) {
img.style.width = width +'px';
img.style.height = height +'px';
}
2016-05-02 13:05:49 +00:00
popup.childNode = img;
2022-05-26 06:08:31 +00:00
popup.reset();
}
2022-05-26 06:08:31 +00:00
,_onImageClick: function(popup) {
popup.hide();
2015-02-01 03:21:54 +00:00
}
2022-05-26 06:08:31 +00:00
,_onImageError: function(popup) {}
});