3 function normalizeNumber(number, length){
4 // Numer strony musi być pomiędzy 1 a najwyższym numerem
5 var pageCount = length;
6 pageNumber = parseInt(pageNumber, 10);
10 pageNumber == Infinity ||
11 pageNumber == -Infinity ||
15 if (pageNumber > pageCount)
21 function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight){
25 minX: galleryWidth - imageWidth,
26 minY: galleryHeight - imageHeight
30 function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight){
31 var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight);
33 x: Math.min(b.maxX, Math.max(b.minX, x)),
34 y: Math.min(b.maxY, Math.max(b.minY, y))
38 function fixImageSize(){
45 function ScanGalleryPerspective(doc, callback){
48 this.perspective_id = '';
53 this.$element = $("#side-gallery");
54 this.$numberInput = $('.page-number', this.$element);
60 this.$image = $('.gallery-image img', this.$element).attr('unselectable', 'on');
63 this.$numberInput.change(function(event){
64 event.preventDefault();
65 self.setPage($(this).val());
68 $('.previous-page', this.$element).click(function(){
69 self.setPage(self.$numberInput.val() - 1);
72 $('.nexy-page', this.$element).click(function(){
73 self.setPage(self.$numberInput.val() + 1);
76 $('.zoom-in', this.$element).click(function(){
80 $('.zoom-out', this.$element).click(function(){
84 $(window).resize(function(){
85 self.dimensions.galleryWidth = self.$image.parent().width();
86 self.dimensions.galleryHeight = self.$image.parent().height();
89 $('.gallery-image img', this.$element).load(function(){
90 console.load("Image loaded.")
95 ScanGalleryPerspective.prototype = new $.wiki.Perspective();
97 ScanGalleryPerspective.prototype._resizeImage = function(){
98 var $img = this.$image;
106 width: $img.width() * this.zoomFactor,
107 height: $img.height() * this.zoomFactor,
108 originWidth: $img.width(),
109 originHeight: $img.height(),
110 galleryWidth: $img.parent().width(),
111 galleryHeight: $img.parent().height()
114 if (!(this.dimensions.width && this.dimensions.height)) {
115 setTimeout(function(){
120 var position = normalizePosition($img.position().left, $img.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
125 width: $img.width() * this.zoomFactor,
126 height: $img.height() * this.zoomFactor
130 ScanGalleryPerspective.prototype.setPage = function(newPage){
131 newPage = normalizeNumber(newPage, this.$image.length);
132 this.$numberInput.val(newPage);
133 $('.gallery-image img', this.$element).attr('src', this.doc.galleryImages[newPage - 1]);
136 ScanGalleryPerspective.prototype.alterZoom = function(delta){
137 var zoomFactor = this.zoomFactor + delta;
138 if (zoomFactor < 0.2)
142 this.setZoom(zoomFactor);
145 ScanGalleryPerspective.prototype.setZoom = function(factor){
146 this.zoomFactor = factor;
148 this.dimensions.width = this.dimensions.originWidth * this.zoomFactor;
149 this.dimensions.height = this.dimensions.originHeight * this.zoomFactor;
151 var position = normalizePosition(this.$image.position().left, this.$image.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
154 width: this.dimensions.width,
155 height: this.dimensions.height,
164 ScanGalleryPerspective.prototype.onEnter = function(success, failure){
167 $.wiki.Perspective.prototype.onEnter.call(this);
169 this.doc.refreshGallery({
170 success: function(doc, data) {
172 $('.error_message', self.$element).hide();
175 failure: function(doc, message) {
177 $('.error_message', self.$element).show().html(message);
183 $.wiki.ScanGalleryPerspective = ScanGalleryPerspective;
190 function onMouseMove(event){
193 var position = normalizePosition(event.clientX - origin.x + imageOrigin.left, event.clientY - origin.y + imageOrigin.top, imageDimensions.galleryWidth, imageDimensions.galleryHeight, imageDimensions.width, imageDimensions.height);
199 position: 'absolute',
217 function onMouseUp(event){
220 $(document).unbind('mousemove.gallery').unbind('mouseup.gallery');
229 image.bind('mousedown', function(event){
244 imageOrigin = image.position();
247 $(document).bind('mousemove.gallery', onMouseMove).bind('mouseup.gallery', onMouseUp);