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;
49 options.callback = function(){
54 this.$element = $("#side-gallery");
55 this.$numberInput = $('.page-number', this.$element);
61 this.$image = $('.gallery-image img', this.$element).attr('unselectable', 'on');
64 this.$numberInput.change(function(event){
65 event.preventDefault();
66 self.setPage($(this).val());
69 $('.previous-page', this.$element).click(function(){
70 self.setPage(parseInt(self.$numberInput.val(),10) - 1);
73 $('.next-page', this.$element).click(function(){
74 self.setPage(parseInt(self.$numberInput.val(),10) + 1);
77 $('.zoom-in', this.$element).click(function(){
81 $('.zoom-out', this.$element).click(function(){
82 self.alterZoom((-0.2));
85 $(window).resize(function(){
86 self.dimensions.galleryWidth = self.$image.parent().width();
87 self.dimensions.galleryHeight = self.$image.parent().height();
90 $('.gallery-image img', this.$element).load(function(){
91 console.log("Image loaded.")
93 }).bind('mousedown', function() {
94 self.imageMoveStart.apply(self, arguments);
99 old_callback.call(this);
102 $.wiki.Perspective.call(this, options);
105 ScanGalleryPerspective.prototype = new $.wiki.Perspective();
107 ScanGalleryPerspective.prototype._resizeImage = function(){
108 var $img = this.$image;
116 width: $img.width() * this.zoomFactor,
117 height: $img.height() * this.zoomFactor,
118 originWidth: $img.width(),
119 originHeight: $img.height(),
120 galleryWidth: $img.parent().width(),
121 galleryHeight: $img.parent().height()
124 if (!(this.dimensions.width && this.dimensions.height)) {
125 setTimeout(function(){
130 var position = normalizePosition($img.position().left, $img.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
135 width: $img.width() * this.zoomFactor,
136 height: $img.height() * this.zoomFactor
140 ScanGalleryPerspective.prototype.setPage = function(newPage){
141 newPage = normalizeNumber(newPage, this.doc.galleryImages.length);
142 $('#imagesCount').html("/"+this.doc.galleryImages.length);
143 this.$numberInput.val(newPage);
144 this.config().page = newPage;
145 $('.gallery-image img', this.$element).attr('src', this.doc.galleryImages[newPage - 1]);
148 ScanGalleryPerspective.prototype.alterZoom = function(delta){
149 var zoomFactor = this.zoomFactor + delta;
150 if (zoomFactor < 0.2)
154 this.setZoom(zoomFactor);
157 ScanGalleryPerspective.prototype.setZoom = function(factor){
158 this.zoomFactor = factor;
160 this.dimensions.width = this.dimensions.originWidth * this.zoomFactor;
161 this.dimensions.height = this.dimensions.originHeight * this.zoomFactor;
163 // var position = normalizePosition(this.$image.position().left, this.$image.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
167 width: this.dimensions.width,
168 height: this.dimensions.height,
177 ScanGalleryPerspective.prototype.imageMoved = function(event){
178 event.preventDefault();
180 // origin is where the drag started
181 // imageOrigin is where the drag started on the image
183 var newX = event.clientX - this.origin.x + this.imageOrigin.left;
184 var newY = event.clientY - this.origin.y + this.imageOrigin.top;
186 var position = normalizePosition(newX, newY, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
196 ScanGalleryPerspective.prototype.imageMoveStart = function(event){
197 event.preventDefault();
206 this.imageOrigin = self.$image.position();
207 $(document).bind('mousemove.gallery', function(){
208 self.imageMoved.apply(self, arguments);
209 }).bind('mouseup.gallery', function() {
210 self.imageMoveStop.apply(self, arguments);
216 ScanGalleryPerspective.prototype.imageMoveStop = function(event){
217 $(document).unbind('mousemove.gallery').unbind('mouseup.gallery');
223 ScanGalleryPerspective.prototype.onEnter = function(success, failure){
226 $.wiki.Perspective.prototype.onEnter.call(this);
228 $('.vsplitbar').not('.active').trigger('click');
229 $(".vsplitbar-title").html("↓ GALERIA ↓");
231 this.doc.refreshGallery({
232 success: function(doc, data){
234 console.log("gconfig:", self.config().page );
235 self.setPage( self.config().page );
237 $('.error_message', self.$element).hide();
238 if(success) success();
240 failure: function(doc, message){
242 $('.error_message', self.$element).show().html(message);
243 if(failure) failure();
249 ScanGalleryPerspective.prototype.onExit = function(success, failure) {
253 $.wiki.ScanGalleryPerspective = ScanGalleryPerspective;