changeset 954:36102de2301e

code cosmetics
author robcast
date Wed, 04 Jan 2012 14:26:55 +0100
parents 3d5e7458f9ae
children c8c441d1d7a0
files webapp/src/main/webapp/jquery/jquery.digilib.js
diffstat 1 files changed, 156 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.js	Wed Jan 04 11:28:46 2012 +0100
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.js	Wed Jan 04 14:26:55 2012 +0100
@@ -89,13 +89,13 @@
         'zoomArrowMoveFactor' : 0.5,
         // is the "about" window shown?
         'isAboutDivVisible' : false,
-        // default size of background image for drag-scroll (same as Bird's Eye View image)
-        'bgImgWidth' : 200,
-        'bgImgHeight' : 200,
-        // maximum width or height of background image for drag-scroll
+        // default size of preview image for drag-scroll (same as Bird's Eye View image)
+        'previewImgWidth' : 200,
+        'previewImgHeight' : 200,
+        // maximum width or height of preview background image for drag-scroll
         'maxBgSize' : 10000,
         // parameters used by background image
-        'bgImgParamNames' : ['fn','pn','dw','dh','mo','rot'],
+        'previewImgParamNames' : ['fn','pn','dw','dh','mo','rot'],
         // reserved space in full page display (default value accounts for vertical scrollbar)
         'scalerInset' : 10
         };
@@ -114,7 +114,12 @@
     var buttons = {};
 
     var actions = {
-        // init: digilib initialization
+            
+        /** init: digilib initialization
+         * 
+         * @param options
+         * @returns
+         */
         init : function(options) {
             // import geometry classes
             if (plugins.geometry == null) {
@@ -245,7 +250,11 @@
             });
         },
 
-        // destroy: clean up digilib
+        /** destroy: clean up digilib
+         * 
+         * @param data
+         * @returns
+         */
         destroy : function(data) {
             return this.each(function(){
                 var $elem = $(this);
@@ -255,14 +264,23 @@
             });
         },
 
-        // show or hide the 'about' window
+        /** show or hide the 'about' window
+         * 
+         * @param data
+         * @param show
+         */
         showAboutDiv : function(data, show) {
             var on = showDiv(data.settings.isAboutDivVisible, data.$aboutDiv, show);
             data.settings.isAboutDivVisible = on;
             //FIXME: highlightButtons(data, 'help', on);
         },
 
-        // goto given page nr (+/-: relative)
+        /** goto given page nr (+/-: relative)
+         * 
+         * @param data
+         * @param pageNr
+         * @returns {Boolean}
+         */
         gotoPage : function (data, pageNr) {
             var settings = data.settings;
             var oldpn = settings.pn;
@@ -291,12 +309,20 @@
             redisplay(data);
         },
 
-        // zoom by a given factor
+        /** zoom by a given factor
+         * 
+         * @param data
+         * @param factor
+         */
         zoomBy : function (data, factor) {
             zoomBy(data, factor);
         },
 
-        // zoom to area (or interactive)
+        /** zoom to area (or interactive)
+         * 
+         * @param data
+         * @param area
+         */
         zoomArea : function (data, area) {
             if (area == null) {
                 // interactively
@@ -307,7 +333,11 @@
             }
         },
 
-        // zoom out to full page
+        /** zoom out to full page
+         * 
+         * @param data
+         * @param mode
+         */
         zoomFull : function (data, mode) {
             data.zoomArea = FULL_AREA.copy();
             if (mode === 'width') {
@@ -323,7 +353,12 @@
             redisplay(data);
         },
 
-        // move zoomed area
+        /** move zoomed area
+         * 
+         * @param data
+         * @param dx
+         * @param dy
+         */
         moveZoomArea : function (data, dx, dy) {
             var za = data.zoomArea.copy();
             var factor = data.settings.zoomArrowMoveFactor;
@@ -336,7 +371,11 @@
             redisplay(data);
         },
 
-        // set a mark by clicking (or giving a position)
+        /** set a mark by clicking (or giving a position)
+         * 
+         * @param data
+         * @param mpos
+         */
         setMark : function (data, mpos) {
             if (mpos == null) {
                 // interactive
@@ -348,13 +387,20 @@
             }
         },
 
-        // remove the last mark
+        /** remove the last mark
+         * 
+         * @param data
+         */
         removeMark : function (data) {
             data.marks.pop();
             redisplay(data);
         },
 
-        // mirror the image
+        /** mirror the image
+         * 
+         * @param data
+         * @param mode
+         */
         mirror : function (data, mode) {
             var flags = data.scalerFlags;
             if (mode === 'h') {
@@ -373,7 +419,11 @@
             redisplay(data);
         },
 
-        // rotate the image
+        /** rotate the image
+         * 
+         * @param data
+         * @param angle
+         */
         rotate : function (data, angle) {
             var rot = data.settings.rot;
             if (angle == null) {
@@ -383,7 +433,11 @@
             redisplay(data);
         },
 
-        // change brightness
+        /** change brightness
+         * 
+         * @param data
+         * @param factor
+         */
         brightness : function (data, factor) {
             var brgt = data.settings.brgt;
             if (factor == null) {
@@ -393,7 +447,11 @@
             redisplay(data);
         },
 
-        // change contrast
+        /** change contrast
+         * 
+         * @param data
+         * @param factor
+         */
         contrast : function (data, factor) {
             var cont = data.settings.cont;
             if (factor == null) {
@@ -403,7 +461,11 @@
             redisplay(data);
         },
 
-        // reset image parameters to defaults TODO: improve this!
+        /** reset image parameters to defaults 
+         * TODO: improve this!
+         * 
+         * @param data
+         */
         reset : function (data) {
             var settings = data.settings;
             var paramNames = settings.digilibParamNames;
@@ -428,7 +490,12 @@
             redisplay(data);
         },
 
-        // presents a reference url (returns value if noprompt)
+        /** presents a reference url (returns value if noprompt)
+         * 
+         * @param data
+         * @param noprompt
+         * @returns
+         */
         reference : function (data, noprompt) {
             var url = getDigilibUrl(data);
             if (noprompt == null) {
@@ -437,7 +504,11 @@
             return url;
         },
 
-        // set image quality
+        /** set image quality
+         * 
+         * @param data
+         * @param qual
+         */
         setQuality : function (data, qual) {
             var oldq = getQuality(data);
             if (qual == null) {
@@ -450,7 +521,11 @@
             }
         },
 
-        // calibrate (only faking)
+        /** calibrate (only faking)
+         * 
+         * @param data
+         * @param res
+         */
         calibrate : function (data, res) {
             var oldRes = data.settings.ddpi;
             if (res == null) {
@@ -462,7 +537,11 @@
             }
         },
 
-        // set image scale mode
+        /** set image scale mode
+         * 
+         * @param data
+         * @param mode
+         */
         setScaleMode : function (data, mode) {
             var oldM = getScaleMode(data);
             if (mode == null) {
@@ -478,12 +557,16 @@
     // end of actions
     };
 
-    // returns parameters from page url
+    /** return parameters from page url
+     * 
+     */
     var parseQueryParams = function() {
         return parseQueryString(window.location.search.slice(1));
     };
 
-    // returns parameters from embedded img-element
+    /** returns parameters from embedded img-element
+     * 
+     */
     var parseImgParams = function($elem) {
         var src = $elem.find('img').first().attr('src');
         if (!src) return null;
@@ -495,7 +578,9 @@
         return params;
     };
 
-    // parses query parameter string into parameter object
+    /** parses query parameter string into parameter object
+     * 
+     */
     var parseQueryString = function(query) {
         var params = {};
         if (query == null) return params;
@@ -511,7 +596,10 @@
         return params;
     };
 
-    // returns a query string from key names from a parameter hash (ignoring if the same value is in defaults)
+    /** return a query string from key names from a parameter hash 
+     * (ignores keys if the same value is in defaults)
+     * 
+     */
     var getParamString = function (settings, keys, defaults) {
         var paramString = '';
         var nx = false;
@@ -531,7 +619,9 @@
         return paramString;
     };
 
-    // returns URL and query string for Scaler
+    /** returns URL and query string for Scaler
+     * 
+     */
     var getScalerUrl = function (data) {
         packParams(data);
         var settings = data.settings;
@@ -544,12 +634,14 @@
         return url;
     };
 
-    // returns URL for bird's eye view image
-    var getBgImgUrl = function (data, moreParams) {
+    /** returns URL for preview background image
+     * 
+     */
+    var getPreviewImgUrl = function (data, moreParams) {
         var settings = data.settings;
         var bgOptions = {
-                dw : settings.bgImgWidth,
-                dh : settings.bgImgHeight
+                dw : settings.previewImgWidth,
+                dh : settings.previewImgHeight
         };
         var bgSettings = $.extend({}, settings, bgOptions);
         // filter scaler flags (use only hmir and vmir)
@@ -563,12 +655,14 @@
             }
             bgSettings.mo = mo;
         }
-        var params = getParamString(bgSettings, settings.bgImgParamNames, defaults);
+        var params = getParamString(bgSettings, settings.previewImgParamNames, defaults);
         var url = settings.scalerBaseUrl + '?' + params;
         return url;
     };
 
-    // returns URL and query string for current digilib
+    /** returns URL and query string for current digilib
+     * 
+     */
     var getDigilibUrl = function (data) {
         packParams(data);
         var settings = data.settings;
@@ -593,7 +687,9 @@
         return url + '?' + queryString;
     };
 
-    // loads image information from digilib server via HTTP
+    /** loads image information from digilib server via HTTP
+     * 
+     */
     var loadImageInfo = function (data) {
         var settings = data.settings;
         // bind default function (only once)
@@ -610,7 +706,9 @@
         });
     };
 
-    // processes some parameters into objects and stuff
+    /** processes some parameters into objects and stuff
+     * 
+     */
     var unpackParams = function (data) {
         var settings = data.settings;
         // zoom area
@@ -647,7 +745,9 @@
         retrieveOptions(data);
     };
 
-    // put area into parameters
+    /** put area into parameters
+     * 
+     */
     var packArea = function (settings, area) {
         if (!area) return;
         // zoom area
@@ -657,7 +757,9 @@
         settings.wh = cropFloat(area.height);
     };
 
-    // put marks into parameters
+    /** put marks into parameters
+     * 
+     */
     var packMarks = function (settings, marks) {
         if (!marks) return;
         settings.mk = '';
@@ -671,7 +773,9 @@
             }
     };
 
-    // pack scaler flags into parameters
+    /** pack scaler flags into parameters
+     * 
+     */
     var packScalerFlags = function (settings, flags) {
         if (!flags) return;
         var mo = '';
@@ -684,7 +788,9 @@
         settings.mo = mo;
     };
 
-    // put objects back into parameters
+    /** put objects back into parameters
+     * 
+     */
     var packParams = function (data) {
         var settings = data.settings;
         packArea(settings, data.zoomArea);
@@ -694,8 +800,10 @@
         storeOptions(data);
     };
 
+    /** store digilib options in a cookie   
+     * 
+     */
     var storeOptions = function (data) {
-        // save digilib options in cookie
         var settings = data.settings;
         if (data.dlOpts) {
             // save digilib settings in options
@@ -723,6 +831,9 @@
         }
     };
 
+    /** restrieve digilib options from a cookie
+     * 
+     */
     var retrieveOptions = function (data) {
         // clop (digilib options)
         var opts = {};
@@ -823,7 +934,7 @@
     };
 
     /** handle "update" display event.
-     * updates overlays etc.
+     * updates image transform, redraws marks etc.
      */
     var handleUpdate = function (evt) {
     	var data = this;
@@ -1335,6 +1446,7 @@
         	// check if aspect ratio has changed
         	if (newZoomArea.getAspect() !== data.zoomArea.getAspect()) {
         		console.debug("aspect ratio changed!");
+        		// what now?
         	}
         	// get transform for new zoomArea
         	imgTrafo = getImgTrafo($img, newZoomArea, data.settings.rot,
@@ -1359,7 +1471,7 @@
             if (fullRect.height < data.settings.maxBgSize && fullRect.width < data.settings.maxBgSize) {
                 // correct offset because background is relative
                 fullRect.addPosition(scalerPos.neg());
-                var url = getBgImgUrl(data);
+                var url = getPreviewImgUrl(data);
                 // add second background url, size and position
                 scalerCss['background-image'] += ', url(' + url + ')';
                 scalerCss[data.bgSizeName] += ', ' + Math.round(fullRect.width) + 'px ' + Math.round(fullRect.height) + 'px';