function FluidbookLinksZoomHD(fluidbook) {
this.fluidbook = fluidbook;
+ this.scale = 1;
+ this.refScale = 1;
+ this.element;
+ this.image;
+ this.mouseX;
+ this.mouseY;
+ this.ah;
+ this.aw;
+
+ this.draging = false;
+ this.dragX = 0;
+ this.dragY = 0;
+ this.dragMinX = 0;
+ this.dragMaxX = 0;
+ this.dragMinY = 0;
+ this.dragMaxY = 0;
+ this.dragXPct = 0.5;
+ this.dragYPct = 0.5;
+
this.init();
}
$this.openZoomhd(p1, p2, p3);
};
+ $(this.fluidbook).on('fluidbook.resize', function () {
+ try {
+ $this.resize();
+ } catch (e) {
+
+ }
+ });
+
+ $(document).on('click', '.zoomhdControls a', function () {
+ var s = $this.scale;
+ if ($(this).hasClass('minus')) {
+ s -= 0.5;
+ } else {
+ s += 0.5;
+ }
+ $this.scale = $this.normalizeScale(s);
+ $this.resize();
+ return false;
+ });
+
+ $(document).on('mousewheel', function (e) {
+ var s = $this.scale;
+ s += 0.25 * e.deltaY;
+ $this.scale = $this.normalizeScale(s);
+ $this.resize();
+ return false;
+ });
+ },
+
+ normalizeScale: function (s) {
+ return Math.max(1, Math.min(3.5, s));
},
openZoomhd: function (p1, p2, callback) {
+ var $this = this;
var link = this.fluidbook.links.getLinkDataById(p1);
- var image = new Image();
- image.src = 'data/links/' + link.to;
+ this.fluidbook.displayLoader();
view = '<div class="caption">' + this.fluidbook.menu.closeButton() + '</div>';
- view += '<div class="content"><div class="zoomhdHolder"><div class="zoomhdScale">';
- view += '</div><div class="zoomhdControls"><a href="#" class="minus">'+getSpriteIcon('interface-minus')+'</a><a href="#" class="plus">'+getSpriteIcon('interface-plus')+'</a></div></div></div>';
+ view += '<div class="content"><div class="zoomhdHolder"><div class="zoomhdMove"><div class="zoomhdRefScale"><div class="zoomhdScale"><div class="zoomhdImage"></div>';
+ view += '</div></div></div><div class="zoomhdControls"><a href="#" class="minus">' + getSpriteIcon('interface-minus') + '</a><a href="#" class="plus">' + getSpriteIcon('interface-plus') + '</a></div></div></div>';
$("#view").append('<div class="mview" dir="ltr" data-menu="zoomhd" data-fullscreen="1">' + view + '</div>');
+ this.element = $("#view").find('.zoomhdScale');
- var e = $("#view").find('.zoomhdScale');
- e.append(image);
-
- this.initZoomHD(e);
+ this.image = fluidbook.loader.loadImage('data/links/' + link.to, null, null, null, function () {
+ setTimeout(function () {
+ $this.initZoomHD();
+ setTimeout(function () {
+ $($this.image).closest('.zoomhdImage').css('opacity', 1);
+ }, 10)
+ setTimeout(function () {
+ $this.fluidbook.hideLoader();
+ }, 200)
+ }, 1000);
+ }).get(0);
if (callback != undefined) {
callback();
}
},
- initZoomHD: function (e) {
+ initZoomHD: function () {
+ var $this = this;
+
+ var i = this.element.find('.zoomhdImage');
+ i.append(this.image);
+ this.scale = 1;
+
+ this.isDragging = false;
+
+ var h = this.element.closest('.zoomhdHolder');
+ var m = this.element.closest('.zoomhdMove');
+ var mc = new Hammer(h.get(0));
+
+ mc.get('pan').set({direction: Hammer.DIRECTION_ALL});
+ mc.on('pan', function (e) {
+ if ($this.scale == 1) {
+ return false;
+ }
+ if (!$this.dragging) {
+ $this.dragging = true;
+ $this.dragY = parseFloat(m.css('top'));
+ $this.dragX = parseFloat(m.css('left'));
+ $this.calcDragLimits();
+ }
+
+ $this.setMovePos($this.dragX + e.deltaX, $this.dragY + e.deltaY);
+
+
+ if (e.isFinal) {
+ $this.dragging = false;
+ $this.dragX = $this.dragY = 0;
+ }
+ return false;
+ });
+
+ i.css(
+ {
+ left: this.image.naturalWidth / -2,
+ top: this.image.naturalHeight / -2
+ }
+ );
+ this.resize();
+ },
+
+ updateMovePosPct: function () {
+ this.calcDragLimits();
+ this.setMovePos(this.dragXPct * (this.dragMaxX - this.dragMinX), this.dragYPct * (this.dragMaxY - this.dragMinY));
+ },
+
+ setMovePos: function (x, y) {
+ x = Math.max(this.dragMinX, Math.min(this.dragMaxX, x));
+ y = Math.max(this.dragMinY, Math.min(this.dragMaxY, y));
+
+ this.dragXPct = (x - this.dragMinX) / (this.dragMaxX - this.dragMinX);
+ this.dragYPct = (y - this.dragMinY) / (this.dragMaxY - this.dragMinY);
+
+ this.element.closest('.zoomhdMove').css({
+ top: y,
+ left: x
+ });
+ },
+
+ calcDragLimits: function () {
+ if (this.scale <= 1) {
+ this.dragMinX = this.dragMaxX = this.dragMinY = this.dragMaxY = 0;
+ return;
+ }
+ var irect = this.element.find('.zoomhdImage').get(0).getBoundingClientRect();
+
+ this.dragMaxX = 60 + Math.abs(this.fluidbook.resize.ww - irect.width) / 2;
+ this.dragMinX = -this.dragMaxX;
+ this.dragMaxY = 60 + Math.abs(this.fluidbook.resize.hh - irect.height) / 2;
+ this.dragMinY = -this.dragMaxY;
+ },
+
+ resize: function () {
+ var ww = this.fluidbook.resize.ww;
+ var hh = this.fluidbook.resize.hh;
+
+ this.aw = ww - 60;
+ this.ah = hh - 110;
+
+ this.refScale = Math.min(this.aw / this.image.naturalWidth, this.ah / this.image.naturalHeight);
+
+ this.element.closest('.zoomhdRefScale').css({transform: 'scale(' + this.refScale + ')'});
+ this.element.css({transform: 'scale(' + this.scale + ')'});
+ this.updateMovePosPct();
},
}