comparison client/digitallibrary/jquery/jquery.digilib.js @ 618:09167ef1512e jquery

some refactoring, onclick handlers now work with arguments
author hertzhaft
date Sun, 16 Jan 2011 23:34:29 +0100
parents cd846b5c8be8
children a473998de5f8
comparison
equal deleted inserted replaced
617:cd846b5c8be8 618:09167ef1512e
2 * digilib jQuery plugin 2 * digilib jQuery plugin
3 * 3 *
4 */ 4 */
5 5
6 (function($) { 6 (function($) {
7 var buttons = { 7 var actions = {
8 reference : { 8 reference : {
9 onclick : "javascript:getRefWin()", 9 onclick : "javascript:getRefWin()",
10 tooltip : "get a reference URL", 10 tooltip : "get a reference URL",
11 img : "reference.png" 11 img : "reference.png"
12 }, 12 },
54 onclick : "toggleBirdDiv", 54 onclick : "toggleBirdDiv",
55 tooltip : "show bird's eye view", 55 tooltip : "show bird's eye view",
56 img : "birds-eye.png" 56 img : "birds-eye.png"
57 }, 57 },
58 help : { 58 help : {
59 onclick : "toggleAboutDiv", 59 onclick : ["toggleAboutDiv", 0.2],
60 tooltip : "about Digilib", 60 tooltip : "about Digilib",
61 img : "help.png" 61 img : "help.png"
62 }, 62 },
63 reset : { 63 reset : {
64 onclick : "javascript:resetImage()", 64 onclick : "javascript:resetImage()",
151 'rot','cont','brgt','rgbm','rgba','ddpi','ddpix','ddpiy'], 151 'rot','cont','brgt','rgbm','rgba','ddpi','ddpix','ddpiy'],
152 // mode of operation. 152 // mode of operation.
153 // fullscreen: takes parameters from page URL, keeps state in page URL 153 // fullscreen: takes parameters from page URL, keeps state in page URL
154 // embedded: takes parameters from Javascript options, keeps state inside object 154 // embedded: takes parameters from Javascript options, keeps state inside object
155 'interactionMode' : 'fullscreen', 155 'interactionMode' : 'fullscreen',
156 // buttons 156 // actions
157 'buttons' : buttons, 157 'actions' : actions,
158 // path to button images (must end with a slash) 158 // path to button images (must end with a slash)
159 'buttonsImagePath' : '../greyskin/', 159 'buttonsImagePath' : '../greyskin/',
160 // button groups 160 // actions groups
161 'buttonsStandard' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","options"], 161 'actionsStandard' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","options"],
162 'buttonsSpecial' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","options"], 162 'actionsSpecial' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","options"],
163 'buttonsCustom' : [], 163 'actionsCustom' : [],
164 // is birdView shown? 164 // is birdView shown?
165 'isBirdDivVisible' : false, 165 'isBirdDivVisible' : false,
166 // dimensions of bird's eye window 166 // dimensions of bird's eye window
167 'birdMaxX' : 200, 167 'birdMaxX' : 200,
168 'birdMaxY' : 200, 168 'birdMaxY' : 200,
206 settings : elemSettings 206 settings : elemSettings
207 }); 207 });
208 } 208 }
209 // create HTML structure 209 // create HTML structure
210 setupScalerDiv($elem, elemSettings); 210 setupScalerDiv($elem, elemSettings);
211 setupButtons($elem, elemSettings, 'buttonsStandard'); 211 setupButtons($elem, elemSettings, 'actionsStandard');
212 // bird's eye view creation - could be deferred? 212 // bird's eye view creation - could be deferred?
213 setupBirdviewDiv($elem, elemSettings); 213 setupBirdviewDiv($elem, elemSettings);
214 // about window creation - could be deferred? restrict to only one item? 214 // about window creation - could be deferred? restrict to only one item?
215 setupAboutDiv($elem, elemSettings); 215 setupAboutDiv($elem, elemSettings);
216 }); 216 });
359 $scaler.append($img); 359 $scaler.append($img);
360 $img.load(scalerImgLoadedFn(settings)); 360 $img.load(scalerImgLoadedFn(settings));
361 }; 361 };
362 362
363 // creates HTML structure for buttons in elem 363 // creates HTML structure for buttons in elem
364 var setupButtons = function ($elem, settings, buttonGroup) { 364 var setupButtons = function ($elem, settings, actionGroup) {
365 if (settings.interactionMode === 'fullscreen') { 365 if (settings.interactionMode === 'fullscreen') {
366 // fullscreen -- create new 366 // fullscreen -- create new
367 var $buttonsDiv = $('<div class="buttons"></div>'); 367 var $buttonsDiv = $('<div class="buttons"></div>');
368 $elem.append($buttonsDiv); 368 $elem.append($buttonsDiv);
369 var buttonNames = settings[buttonGroup]; 369 var actionNames = settings[actionGroup];
370 for (var i = 0; i < buttonNames.length; i++) { 370 for (var i = 0; i < actionNames.length; i++) {
371 var buttonName = buttonNames[i]; 371 var actionName = actionNames[i];
372 var buttonSettings = settings.buttons[buttonName]; 372 var actionSettings = settings.actions[actionName];
373 // construct the button html 373 // construct the button html
374 var $button = $('<div class="button"></div>'); 374 var $button = $('<div class="button"></div>');
375 var $a = $('<a/>'); 375 var $a = $('<a/>');
376 var $img = $('<img class="button"/>'); 376 var $img = $('<img class="button"/>');
377 $buttonsDiv.append($button); 377 $buttonsDiv.append($button);
378 $button.append($a); 378 $button.append($a);
379 $a.append($img); 379 $a.append($img);
380 // add attributes and bindings 380 // add attributes and bindings
381 $button.attr('title', buttonSettings.tooltip); 381 $button.attr('title', actionSettings.tooltip);
382 $button.addClass('button-' + buttonName); 382 $button.addClass('button-' + actionName);
383 // let the clicked <a> element know about the digilib context 383 // let the clicked <a> element know about the digilib context
384 $a.data('digilib', { 'name' : buttonName, 'settings' : settings } ); 384 $a.data('digilib', { 'action' : actionName, 'settings' : settings } );
385 $a.bind('click', function() { 385 $a.bind('click', function() {
386 // get the context settings 386 // get the context settings
387 var data = $(this).data('digilib'); 387 var data = $(this).data('digilib');
388 // find the action for the clicked element 388 // find the action for the clicked element
389 var method = data.settings.buttons[data.name].onclick; 389 var method = data.settings.actions[data.action].onclick;
390 // find the digilib object with methods 390 // find the digilib object with methods
391 var $root = data.settings.digilibRoot; 391 var $root = data.settings.digilibRoot;
392 // execute as a method 392 // execute as a method
393 $a.digilib(method); 393 console.log(method);
394 console.log(onclick); 394 if ($.isArray(method)) {
395 $a.digilib.apply(this, method);
396 } else {
397 $a.digilib(method);
398 };
395 }); 399 });
396 // binding mit closure 400 // binding mit closure
397 //(function(){ var action = buttonSettings.onclick; 401 //(function(){ var action = buttonSettings.onclick;
398 // $a.bind('click', function(){ console.log( action )} ); 402 // $a.bind('click', function(){ console.log( action )} );
399 //})(); 403 //})();
400 $img.attr('src', settings.buttonsImagePath + buttonSettings.img); 404 $img.attr('src', settings.buttonsImagePath + actionSettings.img);
401 }; 405 };
402 } 406 }
403 return $buttonsDiv; 407 return $buttonsDiv;
404 }; 408 };
405 409