123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- //简单多张图片排列显示模块
- var single_image_view = function(option, success) {
- var object = new SingleImageView(option);
- success();
- return object;
- }
- function SingleImageView(option) {
- this.markControl = option.markControl;
- this.defaultZoom = 100;
- this.loading = false;
- this.init();
- this.markControl.on('step.board.show', this, function(event, context, eventObject) {
- this.container.removeClass('span12');
- this.container.addClass('span10');
- this.container.perfectScrollbar('update');
- if (this.iviewer != undefined) {
- this.iviewer.iviewer('update');
- }
- });
- this.markControl.on('step.board.hide', this, function(event, context, eventObject) {
- this.container.removeClass('span10');
- this.container.addClass('span12');
- this.container.perfectScrollbar('update');
- if (this.iviewer != undefined) {
- this.iviewer.iviewer('update');
- }
- });
- this.markControl.on('center.width.change', this, function(event, context, eventObject) {
- this.container.perfectScrollbar('update');
- if (this.iviewer != undefined) {
- this.iviewer.iviewer('update');
- this.iviewer.iviewer('fit');
- }
- });
- this.markControl.on('view.sidebar.open', this, function(event, context, eventObject) {
- this.imageControl.hide();
- });
- this.markControl.on('view.sidebar.close', this, function(event, context, eventObject) {
- this.imageControl.show();
- });
- this.markControl.on('task.get.before', this, function(event, context, eventObject) {
- this.task = undefined;
- this.render();
- });
- this.markControl.on('task.get.success', this, function(event, context, eventObject) {
- this.task = context.task;
- this.render();
- });
- this.markControl.on('task.get.none', this, function(event, context, eventObject) {
- this.task = undefined;
- this.render();
- });
- this.markControl.on('image.position.change', this, function(event, context, topPercent) {
- if (this.task != undefined && this.loading == false) {
- this.updateScrollTop(topPercent);
- }
- });
- }
- SingleImageView.prototype.init = function() {
- this.configCache = {};
- //this.container = getDom(this.container_dom).appendTo(this.markControl.container.imageContent);
- this.container = this.markControl.container.imageContent;
- this.container.height(this.markControl.container.centerContent.height());
- this.container.perfectScrollbar({
- wheelSpeed: 20
- });
- this.imageHolder = getDom(this.image_holder_dom, this.markControl).appendTo(this.container);
- this.imageHolder.width('100%');
- this.imageControl = getDom(this.image_control_dom, this.markControl).insertBefore(this.markControl.container.assistantButton.parent());
- this.imageControl.find('.zoom-out-button').click(this, function(event) {
- var iviewer = event.data.iviewer;
- if (iviewer != undefined) {
- iviewer.iviewer('zoom_by', 1);
- }
- });
- this.imageControl.find('.zoom-in-button').click(this, function(event) {
- var iviewer = event.data.iviewer;
- if (iviewer != undefined) {
- iviewer.iviewer('zoom_by', -1);
- }
- });
- this.imageControl.find('.zoom-fit-button').click(this, function(event) {
- var iviewer = event.data.iviewer;
- if (iviewer != undefined) {
- iviewer.iviewer('fit');
- }
- });
- this.imageControl.find('.zoom-origin-button').click(this, function(event) {
- var iviewer = event.data.iviewer;
- if (iviewer != undefined) {
- iviewer.iviewer('set_zoom', 100);
- }
- });
- this.imageControl.find('.rotate-button').click(this, function(event) {
- var iviewer = event.data.iviewer;
- if (iviewer != undefined) {
- iviewer.iviewer('angle', 90);
- }
- });
- var self = this;
- this.container.scroll(function() {
- if (self.currentConfig != undefined) {
- self.currentConfig.scrollTop = self.container.scrollTop() / self.imageHolder.height();
- self.currentConfig.scrollLeft = self.container.scrollLeft() / self.imageHolder.width();
- }
- });
- }
- SingleImageView.prototype.render = function() {
- if (this.task != undefined) {
- var config = this.configCache[this.task.blockId];
- if (config == undefined) {
- config = {
- zoom: this.defaultZoom
- };
- this.configCache[this.task.blockId] = config;
- }
- this.currentConfig = config;
- this.loadImage();
- // this.imageControl.show();
- // this.imageHolder.show();
- // this.imageHolder.trigger('mouseenter');
- } else {
- this.imageControl.hide();
- this.imageHolder.hide();
- this.currentConfig = undefined;
- }
- }
- SingleImageView.prototype.loadImage = function() {
- if (this.task.imageData != undefined && this.loading == false) {
- this.loading = true;
- if (this.iviewer == undefined) {
- var self = this;
- this.iviewer = this.imageHolder.iviewer({
- src: self.task.imageData,
- zoom_delta: 1.2,
- zoom: 100,
- zoom_min: 10,
- ui_disabled: true,
- mousewheel: false,
- zoom_animation: false,
- onAfterZoom: function(ev, new_zoom) {
- self.onZoomSet(new_zoom);
- },
- onStopDrag: function(ev, point) {
- self.onStopDrag(point);
- },
- onFinishLoad: function(ev, url) {
- self.onImageLoad();
- },
- angle: function(ev, info) {
- self.onRotate(info.angle);
- }
- });
- this.imageHolder.css('overflow', '');
- } else {
- this.iviewer.iviewer('loadImage', this.task.imageData);
- }
- }
- }
- SingleImageView.prototype.onImageLoad = function() {
- this.loading = false;
- this.container.scrollTop(0);
- if (this.currentConfig != undefined && this.currentConfig.zoom != undefined && this.currentConfig.zoom != this.defaultZoom) {
- if (this.currentConfig.rotate != undefined && this.currentConfig.rotate > 0) {
- this.iviewer.iviewer('angle', this.currentConfig.rotate);
- }
- if (this.currentConfig.zoom != undefined && this.currentConfig.zoom != this.defaultZoom) {
- this.iviewer.iviewer('set_zoom', this.currentConfig.zoom);
- }
- }
- //this.imageHolder.find('img').css('border', '2px solid');
- // if (this.currentConfig.dx != undefined && this.currentConfig.dy != undefined) {
- // this.iviewer.iviewer('moveTo', this.currentConfig.dx, this.currentConfig.dy);
- // }
- this.imageControl.show();
- this.imageHolder.show();
- this.imageHolder.trigger('mouseenter');
- this.markControl.trigger('task.load.finish');
- }
- SingleImageView.prototype.onZoomSet = function(zoom) {
- if (this.loading == false && this.currentConfig != undefined) {
- this.currentConfig.zoom = zoom;
- this.updateScrollTop(this.currentConfig.scrollTop);
- this.updateScrollLeft(this.currentConfig.scrollLeft);
- }
- }
- SingleImageView.prototype.onStopDrag = function(point) {
- if (this.loading == false) {
- this.currentConfig.dx = point.x;
- this.currentConfig.dy = point.y;
- }
- }
- SingleImageView.prototype.onRotate = function(angle) {
- if (this.loading == false) {
- this.currentConfig.rotate = angle;
- }
- }
- SingleImageView.prototype.updateScrollTop = function(scrollTopPercent) {
- var height = this.imageHolder.height();
- var minHeight = this.container.height();
- if (scrollTopPercent != undefined && scrollTopPercent >= 0 && scrollTopPercent <= 1 && height > minHeight) {
- var left = height * (1 - scrollTopPercent);
- var scrollTop = left > minHeight ? (height - left) : (height - minHeight);
- this.container.scrollTop(scrollTop);
- } else {
- this.container.scrollTop(0);
- }
- }
- SingleImageView.prototype.updateScrollLeft = function(scrollLeftPercent) {
- var width = this.imageHolder.width();
- var minWidth = this.container.width();
- if (scrollLeftPercent != undefined && scrollLeftPercent >= 0 && scrollLeftPercent <= 1 && width > minWidth) {
- var left = width * (1 - scrollLeftPercent);
- var scrollLeft = left > minWidth ? (width - left) : (width - minWidth);
- this.container.scrollLeft(scrollLeft);
- } else {
- this.container.scrollLeft(0);
- }
- }
- SingleImageView.prototype.container_dom = '<div class="image-content"></div>';
- SingleImageView.prototype.image_control_dom = '<em>\
- <a href="#" class="btn zoom-out-button">放大</a>\
- <a href="#" class="btn zoom-in-button">缩小</a>\
- <a href="#" class="btn zoom-fit-button">适应</a>\
- <a href="#" class="btn zoom-origin-button">原始</a>\
- <a href="#" class="btn rotate-button">旋转</a>\
- </em>';
- SingleImageView.prototype.image_holder_dom = '<div style="position: relative;"></div>';
|