Mercurial > hg > digilib-old
comparison client/digitallibrary/jquery/jquery.digilib.js @ 612:fb94f1b74d59 jquery
bind data and actions to buttons
author | hertzhaft |
---|---|
date | Fri, 14 Jan 2011 17:07:09 +0100 |
parents | 1b6202aba26e |
children | 53ee659e2d00 |
comparison
equal
deleted
inserted
replaced
611:1b6202aba26e | 612:fb94f1b74d59 |
---|---|
145 // fullscreen: takes parameters from page URL, keeps state in page URL | 145 // fullscreen: takes parameters from page URL, keeps state in page URL |
146 // embedded: takes parameters from Javascript options, keeps state inside object | 146 // embedded: takes parameters from Javascript options, keeps state inside object |
147 'interactionMode' : 'fullscreen', | 147 'interactionMode' : 'fullscreen', |
148 // buttons | 148 // buttons |
149 'buttons' : buttons, | 149 'buttons' : buttons, |
150 // path to button images | 150 // path to button images (must end with a slash) |
151 'buttonsImagePath' : 'img/buttons/', | 151 'buttonsImagePath' : '../greyskin/', |
152 // button groups | 152 // button groups |
153 'buttonsStandard' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","options"], | 153 'buttonsStandard' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","options"], |
154 'buttonsSpecial' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","options"], | 154 'buttonsSpecial' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","options"], |
155 'buttonsCustom' : [] | 155 'buttonsCustom' : [] |
156 }; | 156 }; |
290 } | 290 } |
291 }; | 291 }; |
292 | 292 |
293 // creates HTML structure for buttons in elem | 293 // creates HTML structure for buttons in elem |
294 var setupButtons = function ($elem, settings, buttonGroup) { | 294 var setupButtons = function ($elem, settings, buttonGroup) { |
295 var $buttonDiv; | |
296 if (settings.interactionMode === 'fullscreen') { | 295 if (settings.interactionMode === 'fullscreen') { |
297 // fullscreen -- create new | 296 // fullscreen -- create new |
298 $buttonDiv = $elem.append('<div class="buttons"/>'); | 297 var $buttonsDiv = $('<div class="buttons"></div>'); |
298 $elem.append($buttonsDiv); | |
299 var buttonNames = settings[buttonGroup]; | 299 var buttonNames = settings[buttonGroup]; |
300 for (var i = 0; i < buttonNames.length; i++) { | 300 for (var i = 0; i < buttonNames.length; i++) { |
301 var buttonName = buttonNames[i]; | 301 var buttonName = buttonNames[i]; |
302 var buttonConfig = settings.buttons[buttonName]; | 302 var buttonSettings = settings.buttons[buttonName]; |
303 var $button = $buttonDiv.append('<div class="button"/>'); | 303 // construct the button html |
304 $button.addClass('digilib-button-' + buttonName); | 304 var $button = $('<div class="button"></div>'); |
305 var $link = $button.append('<a/>'); | 305 var $a = $('<a/>'); |
306 $link.bind('click', buttonConfig.onclick) | 306 var $img = $('<img/>'); |
307 .attr('title', buttonConfig.toolTip ); | 307 $buttonsDiv.append($button); |
308 var $img = $link.append('<img class="button"/>'); | 308 $button.append($a); |
309 $img.attr('src', settings.buttonsImagePath + buttonConfig.img); | 309 $a.append($img); |
310 // add attributes and bindings | |
311 $button.attr('title', buttonSettings.tooltip); | |
312 $button.addClass('button-' + buttonName); | |
313 // let the clicked <a> element know about the digilib context | |
314 $a.data('digilib', { 'name' : buttonName, 'settings' : settings } ); | |
315 $a.bind('click', function(){ | |
316 // get the context settings | |
317 var data = $(this).data('digilib'); | |
318 // find the action for the clicked element | |
319 console.log(data.settings.buttons[data.name].onclick); | |
320 }); | |
321 // binding mit closure | |
322 //(function(){ var action = buttonSettings.onclick; | |
323 // $a.bind('click', function(){ console.log( action )} ); | |
324 //})(); | |
325 $img.attr('src', settings.buttonsImagePath + buttonSettings.img); | |
310 }; | 326 }; |
311 } | 327 } |
312 return $buttonDiv; | 328 return $buttonsDiv; |
313 }; | 329 }; |
314 | 330 |
315 // hook plugin into jquery | 331 // hook plugin into jquery |
316 $.fn.digilib = function(method) { | 332 $.fn.digilib = function(method) { |
317 if (methods[method]) { | 333 if (methods[method]) { |