comparison client/digitallibrary/jquery/jquery.digilib.js @ 635:7293a42f44f5 jquery

changed button onclick binding to use closure toggleAboutDiv action is now showAboutDiv(), dito for BirdDiv showXXDiv function is now showDiv
author robcast
date Tue, 18 Jan 2011 19:27:20 +0100
parents 34ee220a664b
children 7049579a0097
comparison
equal deleted inserted replaced
634:34ee220a664b 635:7293a42f44f5
49 onclick : "javascript:gotoPageWin()", 49 onclick : "javascript:gotoPageWin()",
50 tooltip : "specify image", 50 tooltip : "specify image",
51 img : "page.png" 51 img : "page.png"
52 }, 52 },
53 bird : { 53 bird : {
54 onclick : "toggleBirdDiv", 54 onclick : "showBirdDiv",
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 : "showAboutDiv",
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()",
137 137
138 var defaults = { 138 var defaults = {
139 // the root digilib element, for easy retrieval 139 // the root digilib element, for easy retrieval
140 'digilibRoot' : null, 140 'digilibRoot' : null,
141 // version of this script 141 // version of this script
142 'version' : 'jquery.digilib.js 1.0', 142 'version' : 'jquery.digilib.js 0.9',
143 // logo url 143 // logo url
144 'logoUrl' : '../img/digilib-logo-text1.png', 144 'logoUrl' : '../img/digilib-logo-text1.png',
145 // repository url 145 // homepage url (behind logo)
146 'reposUrl' : 'http://digilib.berlios.de', 146 'homeUrl' : 'http://digilib.berlios.de',
147 // base URL to Scaler servlet 147 // base URL to Scaler servlet
148 'scalerBaseUrl' : 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler', 148 'scalerBaseUrl' : 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler',
149 // list of Scaler parameters 149 // list of Scaler parameters
150 'scalerParamNames' : ['fn','pn','dw','dh','ww','wh','wx','wy','ws','mo', 150 'scalerParamNames' : ['fn','pn','dw','dh','ww','wh','wx','wy','ws','mo',
151 'rot','cont','brgt','rgbm','rgba','ddpi','ddpix','ddpiy'], 151 'rot','cont','brgt','rgbm','rgba','ddpi','ddpix','ddpiy'],
234 data.digilib.remove(); 234 data.digilib.remove();
235 $this.removeData('digilib'); 235 $this.removeData('digilib');
236 }); 236 });
237 }, 237 },
238 238
239 // event handler: toggles the visibility of the 'about' window 239 // show or hide the 'about' window
240 toggleAboutDiv : function() { 240 showAboutDiv : function(show) {
241 var $this = $(this); 241 var $this = $(this);
242 var data = $this.data('digilib'); 242 var data = $this.data('digilib');
243 showAboutDivFn(data)(); 243 data.settings.isAboutDivVisible = showDiv(data.settings.isAboutDivVisible, data.$aboutDiv, show);
244 }, 244 },
245 245
246 // event handler: toggles the visibility of the bird's eye window 246 // event handler: toggles the visibility of the bird's eye window
247 toggleBirdDiv : function () { 247 showBirdDiv : function (show) {
248 // TODO: red frame functionality 248 var $this = $(this);
249 var $elem = $(this); // the clicked button 249 var data = $this.data('digilib');
250 var settings = $elem.data('digilib').settings; 250 data.settings.isBirdDivVisible = showDiv(data.settings.isBirdDivVisible, data.$birdDiv, show);
251 var $root = settings.digilibRoot;
252 var $bird = $root.find('div.birdview');
253 settings.isBirdDivVisible = !settings.isBirdDivVisible;
254 if (settings.isBirdDivVisible) {
255 $bird.fadeIn();
256 } else {
257 $bird.fadeOut();
258 };
259 return false;
260 }, 251 },
261 252
262 // goto given page nr (+/-: relative) 253 // goto given page nr (+/-: relative)
263 gotoPage : function(pageNr, keepMarks) { 254 gotoPage : function(pageNr, keepMarks) {
264 var $elem = $(this); // the clicked button 255 var $elem = $(this); // the clicked button
468 $button.append($a); 459 $button.append($a);
469 $a.append($img); 460 $a.append($img);
470 // add attributes and bindings 461 // add attributes and bindings
471 $button.attr('title', actionSettings.tooltip); 462 $button.attr('title', actionSettings.tooltip);
472 $button.addClass('button-' + actionName); 463 $button.addClass('button-' + actionName);
473 // let the clicked <a> element know about the digilib context 464 // create handler for the buttons
474 $a.data('digilib', { 'action' : actionName, 'settings' : settings } ); 465 $a.bind('click', (function () {
475 $a.bind('click', function() { 466 // we create a new closure to capture the value of method
476 var $elem = $(this); 467 var method = actionSettings.onclick;
477 // get the context data
478 var data = $elem.data('digilib');
479 // find the action for the clicked element
480 var method = data.settings.actions[data.action].onclick;
481 if ($.isArray(method)) { 468 if ($.isArray(method)) {
482 $elem.digilib.apply(this, method); 469 // the handler function calls digilib with method and parameters
470 return function () {
471 console.debug('click method=', method);
472 $elem.digilib.apply($elem, method);
473 };
483 } else { 474 } else {
484 $elem.digilib(method); 475 // the handler function calls digilib with method
476 return function () {
477 console.debug('click method=', method);
478 $elem.digilib(method);
485 }; 479 };
486 console.log(method); 480 }
487 }); 481 })());
488 // binding mit closure
489 //(function(){ var action = actionSettings.onclick;
490 // $a.bind('click', function(){ console.log( action )} );
491 //})();
492 $img.attr('src', settings.buttonsImagePath + actionSettings.img); 482 $img.attr('src', settings.buttonsImagePath + actionSettings.img);
493 }; 483 };
494 } 484 }
495 return $buttonsDiv; 485 return $buttonsDiv;
496 }; 486 };
515 var $birdImg = $('<img class="birdimg"/>'); 505 var $birdImg = $('<img class="birdimg"/>');
516 $elem.append($birdviewDiv); 506 $elem.append($birdviewDiv);
517 $birdviewDiv.append($birdzoomDiv); 507 $birdviewDiv.append($birdzoomDiv);
518 $birdviewDiv.append($birdImg); 508 $birdviewDiv.append($birdImg);
519 $birdImg.attr('src', birdUrl); 509 $birdImg.attr('src', birdUrl);
510 data.$birdDiv = $birdviewDiv;
520 }; 511 };
521 512
522 // creates HTML structure for the about view in elem 513 // creates HTML structure for the about view in elem
523 var setupAboutDiv = function (data) { 514 var setupAboutDiv = function (data) {
524 var $elem = data.target; 515 var $elem = data.target;
532 $aboutDiv.append($header); 523 $aboutDiv.append($header);
533 $aboutDiv.append($link); 524 $aboutDiv.append($link);
534 $aboutDiv.append($content); 525 $aboutDiv.append($content);
535 $link.append($logo); 526 $link.append($logo);
536 $logo.attr('src', settings.logoUrl); 527 $logo.attr('src', settings.logoUrl);
537 $link.attr('href', settings.reposUrl); 528 $link.attr('href', settings.homeUrl);
538 $content.text('Version: ' + settings.version); 529 $content.text('Version: ' + settings.version);
539 // let the element know about the digilib context 530 // click hides
540 $aboutDiv.data('digilib', { 'settings' : settings } ); 531 $aboutDiv.bind('click', function () { showDiv(settings.isAboutDivVisible, $aboutDiv, 0); });
541 $aboutDiv.bind('click', showAboutDivFn(data, 0)); 532 data.$aboutDiv = $aboutDiv;
542 }; 533 };
543 534
544 // returns handler for showing the 'about' window (toggle visibility if show is null) 535 // shows some window e.g. 'about' (toggle visibility if show is null)
545 var showAboutDivFn = function (data, show) { 536 var showDiv = function (isVisible, $div, show) {
546 var $elem = data.target; 537 if (typeof(show) !== 'number') {
547 var settings = data.settings; 538 // toggle visibility
548 // event handler: toggles the visibility of the 'about' window 539 isVisible = !isVisible;
549 return function () { 540 } else {
550 var $about = $elem.find('div.about'); 541 // set visibility
551 if (typeof(show) !== 'number') { 542 isVisible = show;
552 // toggle visibility 543 }
553 settings.isAboutDivVisible = !settings.isAboutDivVisible; 544 if (isVisible) {
554 } else { 545 $div.fadeIn();
555 // set visibility 546 } else {
556 settings.isAboutDivVisible = show; 547 $div.fadeOut();
557 } 548 }
558 if (settings.isAboutDivVisible) { 549 return isVisible;
559 $about.fadeIn();
560 } else {
561 $about.fadeOut();
562 }
563 };
564 }; 550 };
565 551
566 // returns function for load event of scaler img 552 // returns function for load event of scaler img
567 var scalerImgLoadedFn = function (data) { 553 var scalerImgLoadedFn = function (data) {
568 var settings = data.settings; 554 var settings = data.settings;
583 trafo.concat(trafo.getScale(picrect)); 569 trafo.concat(trafo.getScale(picrect));
584 trafo.concat(trafo.getTranslation(picrect)); 570 trafo.concat(trafo.getTranslation(picrect));
585 data.imgTrafo = trafo; 571 data.imgTrafo = trafo;
586 // display marks 572 // display marks
587 renderMarks(data); 573 renderMarks(data);
588 //digilib.showBirdDiv(isBirdDivVisible); 574 // show birds eye view
575 //showDiv(settings.isBirdDivVisible);
589 //digilib.showArrows(); // show arrow overlays for zoom navigation 576 //digilib.showArrows(); // show arrow overlays for zoom navigation
590 // done -- hide about div 577 // done -- hide about div
591 showAboutDivFn(data, 0)(); 578 settings.isAboutDivVisible = showDiv(null, data.$aboutDiv, 0);
592 }; 579 };
593 }; 580 };
594 581
595 // place marks on the image 582 // place marks on the image
596 var renderMarks = function (data) { 583 var renderMarks = function (data) {