changeset 1056:89c5b56933af

Ticket #9: new option 'showPageButtons', function 'disableButtons'
author hertzhaft
date Tue, 27 Mar 2012 23:35:33 +0200
parents f6292c6ec440
children d139f59a5f80
files webapp/src/main/webapp/jquery/jquery.digilib.buttons.js webapp/src/main/webapp/jquery/jquery.digilib.css webapp/src/main/webapp/jquery/jquery.digilib.dialogs.js
diffstat 3 files changed, 60 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.buttons.js	Tue Mar 27 09:32:24 2012 +0200
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.buttons.js	Tue Mar 27 23:35:33 2012 +0200
@@ -157,6 +157,10 @@
     var defaults = {
         // buttons (reference added later)
         'buttons' : null,
+        // disabled buttons (should be an array of button names)
+        'buttonsDisabled' : [],
+        // show buttons needed for consecutive (book-like) consultation of image files
+        'showPageButtons' : true,
         // defaults for digilib buttons
         'buttonSettings' : {
             'fullscreen' : {
@@ -165,6 +169,7 @@
                 'buttonSetWidth' : 36,
                 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","about","reset","toggleoptions"],
                 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","lessoptions"],
+                'pageSet' : ["back","fwd","page"],
                 'buttonSets' : ['standardSet', 'specialSet']
                 },
             'embedded' : {
@@ -172,6 +177,7 @@
                 'buttonSetWidth' : 18,
                 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","about","reset","toggleoptions"],
                 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","scale","lessoptions"],
+                'pageSet' : ["back","fwd","page"],
                 'buttonSets' : ['standardSet', 'specialSet']
                 }
         },
@@ -229,13 +235,19 @@
         fn.createButton = createButton;
         fn.highlightButtons = highlightButtons;
         fn.setButtonAction = setButtonAction;
+        fn.findButtonByName = findButtonByName;
     };
 
     // plugin initialization
     var init = function (data) {
         console.debug('initialising buttons plugin. data:', data);
+        var settings = data.settings;
         // add insets
         data.currentInsets['buttons'] = getInsets(data);
+        if (!settings.showPageButtons) {
+            var pageSet = settings.buttonSettings[settings.interactionMode].pageSet;
+            $.merge(settings.buttonsDisabled, pageSet);
+        }
         // install event handler
         var $data = $(data);
         $data.bind('setup', handleSetup);
@@ -249,6 +261,7 @@
         for (var i = 0; i < settings.visibleButtonSets; ++i) {
             showButtons(data, true, i);
         }
+        disableButtons(data);
     };
 
     /** 
@@ -284,17 +297,14 @@
         var tooltip = buttonConfig.tooltip;
         var icon = imagePath + buttonConfig.icon;
         // construct the button html
-        var $button = $('<div class="'+cssPrefix+'button"></div>');
-        var $a = $('<a href=""/>');
-        var $img = $('<img class="'+cssPrefix+'button"/>');
-        $div.append($button);
-        $button.append($a);
-        $a.append($img);
-        // add attributes and bindings
-        $button.attr('title', tooltip);
-        $button.attr('id', cssPrefix+'button-'+buttonName);
-        $button.addClass(cssPrefix+'button-'+buttonName);
-        $img.attr('src', icon);
+        var html = '\
+            <div id="'+cssPrefix+'button-'+buttonName+'" class="'+cssPrefix+'button" title="'+tooltip+'">\
+                <a href="">\
+                    <img class="'+cssPrefix+'button" src="'+icon+'"/>\
+                </a>\
+            </div>';
+        var $button = $(html);
+        $button.appendTo($div);
         // create handler for the buttons
         $button.on('click.digilib', (function () {
             // we create a new closure to capture the value of action
@@ -402,7 +412,7 @@
         var $buttons = data.$elem.find('div.'+cssPrefix+'buttons:visible'); // include hidden?
         // add a class for highlighted button
         var highlight = function (name, on) {
-            var $button = $buttons.find('div.'+cssPrefix+'button-' + name);
+            var $button = findButtonByName(data, name);
             if (on) {
                 $button.addClass(cssPrefix+'button-on');
             } else {
@@ -424,6 +434,29 @@
         highlight('zoomin', ! isFullArea(data.zoomArea));
         };
 
+    // find a button
+    var findButtonByName = function (data, name) {
+        var $elem = data.$elem;
+        var cssPrefix = data.settings.cssPrefix;
+        var $button = $elem.find('#'+cssPrefix+'button-'+name);
+        console.debug("find button", name, $button);
+        return $button;
+    };
+
+    // hide disabled buttons
+    var disableButtons = function (data, buttonnames) {
+        // if present, buttonnames should be an array of button names
+        var $elem = data.$elem;
+        var settings = data.settings;
+        var cssPrefix = settings.cssPrefix;
+        var disabled = buttonnames || settings.buttonsDisabled;
+        $.each(disabled, function(index, name) {
+            var $button = findButtonByName(data, name);
+            $button.addClass(cssPrefix+'disabled');
+            });
+        console.debug('disabled buttons:', disabled);
+    };
+
     // set standard button "onclick" field to a new action
     var setButtonAction = function(buttonName, action) {
         var button = buttons[buttonName];
--- a/webapp/src/main/webapp/jquery/jquery.digilib.css	Tue Mar 27 09:32:24 2012 +0200
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.css	Tue Mar 27 23:35:33 2012 +0200
@@ -4,6 +4,10 @@
  * Martin Raspe, Robert Casties, 11.1.2011
  */
 
+div.dl-digilib .dl-disabled {
+    display: none;
+}
+
 div.dl-digilib,
 div.dl-digilib button,
 div.dl-digilib input {
--- a/webapp/src/main/webapp/jquery/jquery.digilib.dialogs.js	Tue Mar 27 09:32:24 2012 +0200
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.dialogs.js	Tue Mar 27 23:35:33 2012 +0200
@@ -132,16 +132,19 @@
             fn.withdraw($scaleDiv);
             });
         // position the element next to the scale button
-        var $button = $elem.find('#'+cssPrefix+'button-scale');
-        // var $button = digilib.buttons['scale'].button;
-        var buttonRect = geom.rectangle($button);
         $scaleDiv.fadeIn();
         $select.focus();
-        var divRect = geom.rectangle($scaleDiv);
-        $scaleDiv.offset({
-            left : Math.abs(buttonRect.x - divRect.width - 4),
-            top : buttonRect.y + 4
-        });
+        if (digilib.plugins.buttons == null) {
+            fn.centerOnScreen($scaleDiv)
+        } else {
+            var $button = fn.findButtonByName(data, 'scale');
+            var buttonRect = geom.rectangle($button);
+            var divRect = geom.rectangle($scaleDiv);
+            $scaleDiv.offset({
+                left : Math.abs(buttonRect.x - divRect.width - 4),
+                top : buttonRect.y + 4
+            });
+        }
     };
 
     var setButtonActions = function () {