3 function normalizeNumber(pageNumber, pageCount){
4 // Numer strony musi być pomiędzy 1 a najwyższym numerem
5 var pageNumber = parseInt(pageNumber, 10);
9 pageNumber == Infinity ||
10 pageNumber == -Infinity ||
14 if (pageNumber > pageCount)
20 function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight){
24 minX: galleryWidth - imageWidth,
25 minY: galleryHeight - imageHeight
29 function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight){
30 var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight);
32 x: Math.min(b.maxX, Math.max(b.minX, x)),
33 y: Math.min(b.maxY, Math.max(b.minY, y))
37 function fixImageSize(){
44 function ScanGalleryPerspective(options){
45 var old_callback = options.callback || function() { };
47 this.noupdate_hash_onenter = true;
48 this.vsplitbar = 'GALERIA';
50 options.callback = function(){
55 this.$element = $("#side-gallery");
56 this.$numberInput = $('.page-number', this.$element);
62 this.$image = $('.gallery-image img', this.$element).attr('unselectable', 'on');
65 this.$numberInput.change(function(event){
66 event.preventDefault();
67 self.setPage($(this).val());
70 $('.previous-page', this.$element).click(function(){
71 self.setPage(parseInt(self.$numberInput.val(),10) - 1);
74 $('.next-page', this.$element).click(function(){
75 self.setPage(parseInt(self.$numberInput.val(),10) + 1);
78 $('.zoom-in', this.$element).click(function(){
82 $('.zoom-out', this.$element).click(function(){
83 self.alterZoom((-0.2));
86 $(window).resize(function(){
87 self.dimensions.galleryWidth = self.$image.parent().width();
88 self.dimensions.galleryHeight = self.$image.parent().height();
91 $('.gallery-image img', this.$element).load(function(){
92 console.log("Image loaded.")
94 }).bind('mousedown', function() {
95 self.imageMoveStart.apply(self, arguments);
100 old_callback.call(this);
103 $.wiki.Perspective.call(this, options);
106 ScanGalleryPerspective.prototype = new $.wiki.Perspective();
108 ScanGalleryPerspective.prototype._resizeImage = function(){
109 var $img = this.$image;
117 width: $img.width() * this.zoomFactor,
118 height: $img.height() * this.zoomFactor,
119 originWidth: $img.width(),
120 originHeight: $img.height(),
121 galleryWidth: $img.parent().width(),
122 galleryHeight: $img.parent().height()
125 if (!(this.dimensions.width && this.dimensions.height)) {
126 setTimeout(function(){
131 var position = normalizePosition($img.position().left, $img.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
136 width: $img.width() * this.zoomFactor,
137 height: $img.height() * this.zoomFactor
141 ScanGalleryPerspective.prototype.setPage = function(newPage){
142 newPage = normalizeNumber(newPage, this.doc.galleryImages.length);
143 $('#imagesCount').html("/"+this.doc.galleryImages.length);
144 this.$numberInput.val(newPage);
145 this.config().page = newPage;
146 $('.gallery-image img', this.$element).attr('src', this.doc.galleryImages[newPage - 1]);
149 ScanGalleryPerspective.prototype.alterZoom = function(delta){
150 var zoomFactor = this.zoomFactor + delta;
151 if (zoomFactor < 0.2)
155 this.setZoom(zoomFactor);
158 ScanGalleryPerspective.prototype.setZoom = function(factor){
159 this.zoomFactor = factor;
161 this.dimensions.width = this.dimensions.originWidth * this.zoomFactor;
162 this.dimensions.height = this.dimensions.originHeight * this.zoomFactor;
164 // var position = normalizePosition(this.$image.position().left, this.$image.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
168 width: this.dimensions.width,
169 height: this.dimensions.height,
178 ScanGalleryPerspective.prototype.imageMoved = function(event){
179 event.preventDefault();
181 // origin is where the drag started
182 // imageOrigin is where the drag started on the image
184 var newX = event.clientX - this.origin.x + this.imageOrigin.left;
185 var newY = event.clientY - this.origin.y + this.imageOrigin.top;
187 var position = normalizePosition(newX, newY, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
197 ScanGalleryPerspective.prototype.imageMoveStart = function(event){
198 event.preventDefault();
207 this.imageOrigin = self.$image.position();
208 $(document).bind('mousemove.gallery', function(){
209 self.imageMoved.apply(self, arguments);
210 }).bind('mouseup.gallery', function() {
211 self.imageMoveStop.apply(self, arguments);
217 ScanGalleryPerspective.prototype.imageMoveStop = function(event){
218 $(document).unbind('mousemove.gallery').unbind('mouseup.gallery');
224 ScanGalleryPerspective.prototype.onEnter = function(success, failure){
227 $.wiki.Perspective.prototype.onEnter.call(this);
229 $('.vsplitbar').not('.active').trigger('click');
230 $(".vsplitbar-title").html("↓ GALERIA ↓");
232 this.doc.refreshGallery({
233 success: function(doc, data){
235 console.log("gconfig:", self.config().page );
236 self.setPage( self.config().page );
238 $('.error_message', self.$element).hide();
239 if(success) success();
241 failure: function(doc, message){
243 $('.error_message', self.$element).show().html(message);
244 if(failure) failure();
250 ScanGalleryPerspective.prototype.onExit = function(success, failure) {
254 $.wiki.ScanGalleryPerspective = ScanGalleryPerspective;