latex dir for debugging
[redakcja.git] / redakcja / static / js / wiki / view_gallery.js
index 56faaa1..65a716a 100644 (file)
@@ -1,14 +1,17 @@
 (function($){
 
     function normalizeNumber(pageNumber, pageCount){
 (function($){
 
     function normalizeNumber(pageNumber, pageCount){
-        // Numer strony musi być pomiędzy 1 a najwyższym numerem
+        // Page number should be >= 1, <= pageCount; 0 if pageCount = 0
         var pageNumber = parseInt(pageNumber, 10);
 
         var pageNumber = parseInt(pageNumber, 10);
 
+        if (!pageCount)
+            return 0;
+
         if (!pageNumber ||
         if (!pageNumber ||
-        pageNumber == NaN ||
-        pageNumber == Infinity ||
-        pageNumber == -Infinity ||
-        pageNumber < 1)
+                isNaN(pageNumber) ||
+                pageNumber == Infinity ||
+                pageNumber == -Infinity ||
+                pageNumber < 1)
             return 1;
 
         if (pageNumber > pageCount)
             return 1;
 
         if (pageNumber > pageCount)
@@ -52,6 +55,8 @@
 
             this.dimensions = {};
             this.zoomFactor = 1;
 
             this.dimensions = {};
             this.zoomFactor = 1;
+           if (this.config().page == undefined)
+               this.config().page = CurrentDocument.galleryStart;
             this.$element = $("#side-gallery");
             this.$numberInput = $('.page-number', this.$element);
 
             this.$element = $("#side-gallery");
             this.$numberInput = $('.page-number', this.$element);
 
                 self.setPage($(this).val());
             });
                     
                 self.setPage($(this).val());
             });
                     
+           $('.start-page', this.$element).click(function(){
+               self.setPage(CurrentDocument.galleryStart);
+           });
+
             $('.previous-page', this.$element).click(function(){
                 self.setPage(parseInt(self.$numberInput.val(),10) - 1);
             });
             $('.previous-page', this.$element).click(function(){
                 self.setPage(parseInt(self.$numberInput.val(),10) - 1);
             });
@@ -88,7 +97,7 @@
                 self.dimensions.galleryHeight = self.$image.parent().height();
             });
 
                 self.dimensions.galleryHeight = self.$image.parent().height();
             });
 
-            $('.gallery-image img', this.$element).load(function(){
+            this.$image.load(function(){
                 console.log("Image loaded.")
                 self._resizeImage();
             }).bind('mousedown', function() {
                 console.log("Image loaded.")
                 self._resizeImage();
             }).bind('mousedown', function() {
         var $img = this.$image;
 
         $img.css({
         var $img = this.$image;
 
         $img.css({
-            width: null,
-            height: null
+            width: '',
+            height: ''
         });
 
         this.dimensions = {
         });
 
         this.dimensions = {
 
     ScanGalleryPerspective.prototype.setPage = function(newPage){
         newPage = normalizeNumber(newPage, this.doc.galleryImages.length);
 
     ScanGalleryPerspective.prototype.setPage = function(newPage){
         newPage = normalizeNumber(newPage, this.doc.galleryImages.length);
-        $('#imagesCount').html("/"+this.doc.galleryImages.length);
         this.$numberInput.val(newPage);
                this.config().page = newPage;
         $('.gallery-image img', this.$element).attr('src', this.doc.galleryImages[newPage - 1]);
         this.$numberInput.val(newPage);
                this.config().page = newPage;
         $('.gallery-image img', this.$element).attr('src', this.doc.galleryImages[newPage - 1]);
         // var position = normalizePosition(this.$image.position().left, this.$image.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
 
                this._resizeImage();
         // var position = normalizePosition(this.$image.position().left, this.$image.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height);
 
                this._resizeImage();
-        /* this.$image.css({
-            width: this.dimensions.width,
-            height: this.dimensions.height,
-            left: position.x,
-            top: position.y
-        });*/
     };
 
        /*
     };
 
        /*
                 self.$image.show();
                                console.log("gconfig:", self.config().page );
                                self.setPage( self.config().page );
                 self.$image.show();
                                console.log("gconfig:", self.config().page );
                                self.setPage( self.config().page );
+                $('#imagesCount').html("/" + doc.galleryImages.length);
 
                 $('.error_message', self.$element).hide();
                 if(success) success();
 
                 $('.error_message', self.$element).hide();
                 if(success) success();