# HG changeset patch # User hertzhaft # Date 1295217269 -3600 # Node ID 09167ef1512e897963000c8a5bdd7f5a4a2b9069 # Parent cd846b5c8be846d75cb2f870aee85073133fc275 some refactoring, onclick handlers now work with arguments diff -r cd846b5c8be8 -r 09167ef1512e client/digitallibrary/jquery/jquery-test-full.html --- a/client/digitallibrary/jquery/jquery-test-full.html Sun Jan 16 22:24:50 2011 +0100 +++ b/client/digitallibrary/jquery/jquery-test-full.html Sun Jan 16 23:34:29 2011 +0100 @@ -66,6 +66,7 @@ $('div.digilib').each(function(){ console.log($(this).data('digilib').settings); }); + $('div.digilib').digilib('toggleAboutDiv'); }); diff -r cd846b5c8be8 -r 09167ef1512e client/digitallibrary/jquery/jquery.digilib.js --- a/client/digitallibrary/jquery/jquery.digilib.js Sun Jan 16 22:24:50 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.js Sun Jan 16 23:34:29 2011 +0100 @@ -4,7 +4,7 @@ */ (function($) { - var buttons = { + var actions = { reference : { onclick : "javascript:getRefWin()", tooltip : "get a reference URL", @@ -56,7 +56,7 @@ img : "birds-eye.png" }, help : { - onclick : "toggleAboutDiv", + onclick : ["toggleAboutDiv", 0.2], tooltip : "about Digilib", img : "help.png" }, @@ -153,14 +153,14 @@ // fullscreen: takes parameters from page URL, keeps state in page URL // embedded: takes parameters from Javascript options, keeps state inside object 'interactionMode' : 'fullscreen', - // buttons - 'buttons' : buttons, + // actions + 'actions' : actions, // path to button images (must end with a slash) 'buttonsImagePath' : '../greyskin/', - // button groups - 'buttonsStandard' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","options"], - 'buttonsSpecial' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","options"], - 'buttonsCustom' : [], + // actions groups + 'actionsStandard' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","options"], + 'actionsSpecial' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","options"], + 'actionsCustom' : [], // is birdView shown? 'isBirdDivVisible' : false, // dimensions of bird's eye window @@ -208,7 +208,7 @@ } // create HTML structure setupScalerDiv($elem, elemSettings); - setupButtons($elem, elemSettings, 'buttonsStandard'); + setupButtons($elem, elemSettings, 'actionsStandard'); // bird's eye view creation - could be deferred? setupBirdviewDiv($elem, elemSettings); // about window creation - could be deferred? restrict to only one item? @@ -361,15 +361,15 @@ }; // creates HTML structure for buttons in elem - var setupButtons = function ($elem, settings, buttonGroup) { + var setupButtons = function ($elem, settings, actionGroup) { if (settings.interactionMode === 'fullscreen') { // fullscreen -- create new var $buttonsDiv = $('
'); $elem.append($buttonsDiv); - var buttonNames = settings[buttonGroup]; - for (var i = 0; i < buttonNames.length; i++) { - var buttonName = buttonNames[i]; - var buttonSettings = settings.buttons[buttonName]; + var actionNames = settings[actionGroup]; + for (var i = 0; i < actionNames.length; i++) { + var actionName = actionNames[i]; + var actionSettings = settings.actions[actionName]; // construct the button html var $button = $('
'); var $a = $(''); @@ -378,26 +378,30 @@ $button.append($a); $a.append($img); // add attributes and bindings - $button.attr('title', buttonSettings.tooltip); - $button.addClass('button-' + buttonName); + $button.attr('title', actionSettings.tooltip); + $button.addClass('button-' + actionName); // let the clicked element know about the digilib context - $a.data('digilib', { 'name' : buttonName, 'settings' : settings } ); + $a.data('digilib', { 'action' : actionName, 'settings' : settings } ); $a.bind('click', function() { // get the context settings var data = $(this).data('digilib'); // find the action for the clicked element - var method = data.settings.buttons[data.name].onclick; + var method = data.settings.actions[data.action].onclick; // find the digilib object with methods var $root = data.settings.digilibRoot; // execute as a method - $a.digilib(method); - console.log(onclick); + console.log(method); + if ($.isArray(method)) { + $a.digilib.apply(this, method); + } else { + $a.digilib(method); + }; }); // binding mit closure //(function(){ var action = buttonSettings.onclick; // $a.bind('click', function(){ console.log( action )} ); //})(); - $img.attr('src', settings.buttonsImagePath + buttonSettings.img); + $img.attr('src', settings.buttonsImagePath + actionSettings.img); }; } return $buttonsDiv;