Mercurial > hg > digilib-old
comparison client/digitallibrary/jquery/jquery.digilib.js @ 649:fd526464ae87 jquery
beter event handling for setMark...
author | robcast |
---|---|
date | Thu, 20 Jan 2011 14:31:45 +0100 |
parents | 64cc32ec25de |
children | 0c5930916d53 |
comparison
equal
deleted
inserted
replaced
648:64cc32ec25de | 649:fd526464ae87 |
---|---|
522 $elem.empty(); // TODO: should we keep stuff for customization? | 522 $elem.empty(); // TODO: should we keep stuff for customization? |
523 var $scaler = $('<div class="scaler"/>'); | 523 var $scaler = $('<div class="scaler"/>'); |
524 $elem.append($scaler); | 524 $elem.append($scaler); |
525 $scaler.append($img); | 525 $scaler.append($img); |
526 $img.addClass('pic'); | 526 $img.addClass('pic'); |
527 data.$scaler = $scaler; | |
527 data.$img = $img; | 528 data.$img = $img; |
528 $img.load(scalerImgLoadedHandler(data)); | 529 $img.load(scalerImgLoadedHandler(data)); |
529 }; | 530 }; |
530 | 531 |
531 // creates HTML structure for buttons in elem | 532 // creates HTML structure for buttons in elem |
549 $a.append($img); | 550 $a.append($img); |
550 // add attributes and bindings | 551 // add attributes and bindings |
551 $button.attr('title', actionSettings.tooltip); | 552 $button.attr('title', actionSettings.tooltip); |
552 $button.addClass('button-' + actionName); | 553 $button.addClass('button-' + actionName); |
553 // create handler for the buttons | 554 // create handler for the buttons |
554 $a.bind('click', (function () { | 555 $a.bind('click.digilib', (function () { |
555 // we create a new closure to capture the value of method | 556 // we create a new closure to capture the value of method |
556 var method = actionSettings.onclick; | 557 var method = actionSettings.onclick; |
557 if ($.isArray(method)) { | 558 if ($.isArray(method)) { |
558 // the handler function calls digilib with method and parameters | 559 // the handler function calls digilib with method and parameters |
559 return function () { | 560 return function (evt) { |
560 console.debug('click method=', method); | 561 console.debug('click method=', method, ' evt=', evt); |
561 $elem.digilib.apply($elem, method); | 562 $elem.digilib.apply($elem, method); |
563 return false; | |
562 }; | 564 }; |
563 } else { | 565 } else { |
564 // the handler function calls digilib with method | 566 // the handler function calls digilib with method |
565 return function () { | 567 return function (evt) { |
566 console.debug('click method=', method); | 568 console.debug('click method=', method, ' evt=', evt); |
567 $elem.digilib(method); | 569 $elem.digilib(method); |
570 return false; | |
568 }; | 571 }; |
569 } | 572 } |
570 })()); | 573 })()); |
571 $img.attr('src', settings.buttonsImagePath + actionSettings.img); | 574 $img.attr('src', settings.buttonsImagePath + actionSettings.img); |
572 } | 575 } |
614 $link.append($logo); | 617 $link.append($logo); |
615 $logo.attr('src', settings.logoUrl); | 618 $logo.attr('src', settings.logoUrl); |
616 $link.attr('href', settings.homeUrl); | 619 $link.attr('href', settings.homeUrl); |
617 $content.text('Version: ' + settings.version); | 620 $content.text('Version: ' + settings.version); |
618 // click hides | 621 // click hides |
619 $aboutDiv.bind('click', function () { | 622 $aboutDiv.bind('click.digilib', function () { |
620 settings.isAboutDivVisible = showDiv(settings.isAboutDivVisible, $aboutDiv, 0); | 623 settings.isAboutDivVisible = showDiv(settings.isAboutDivVisible, $aboutDiv, 0); |
621 }); | 624 return false; |
625 }); | |
622 data.$aboutDiv = $aboutDiv; | 626 data.$aboutDiv = $aboutDiv; |
623 }; | 627 }; |
624 | 628 |
625 // shows some window e.g. 'about' (toggle visibility if show is null) | 629 // shows some window e.g. 'about' (toggle visibility if show is null) |
626 var showDiv = function (isVisible, $div, show) { | 630 var showDiv = function (isVisible, $div, show) { |
670 | 674 |
671 // place marks on the image | 675 // place marks on the image |
672 var renderMarks = function (data) { | 676 var renderMarks = function (data) { |
673 var $elem = data.$elem; | 677 var $elem = data.$elem; |
674 var marks = data.marks; | 678 var marks = data.marks; |
679 // TODO: clear marks first(?) | |
675 for (var i = 0; i < marks.length; i++) { | 680 for (var i = 0; i < marks.length; i++) { |
676 var mark = marks[i]; | 681 var mark = marks[i]; |
677 if (data.zoomArea.containsPosition(mark)) { | 682 if (data.zoomArea.containsPosition(mark)) { |
678 var mpos = data.imgTrafo.transform(mark); | 683 var mpos = data.imgTrafo.transform(mark); |
679 // create mark | 684 // create mark |
700 redisplay(data); | 705 redisplay(data); |
701 }; | 706 }; |
702 | 707 |
703 // add a mark where clicked | 708 // add a mark where clicked |
704 var setMark = function (data) { | 709 var setMark = function (data) { |
705 var $div = data.$elem; | 710 var $scaler = data.$scaler; |
706 var $img = data.$img; | |
707 console.debug("setmark"); | 711 console.debug("setmark"); |
708 // start event capturing | 712 // start event capturing |
709 $img.one('click.digilib', function (evt) { | 713 $scaler.one('click.digilib', function (evt) { |
710 // event handler adding a new mark | 714 // event handler adding a new mark |
711 console.debug("setmark.click evt=",evt); | 715 console.debug("setmark.click evt=",evt); |
712 var mpos = geom.position(evt.pageX, evt.pageY); | 716 var mpos = geom.position(evt.pageX, evt.pageY); |
713 var pos = data.imgTrafo.invtransform(mpos); | 717 var pos = data.imgTrafo.invtransform(mpos); |
714 data.marks.push(pos); | 718 data.marks.push(pos); |
715 redisplay(data); | 719 redisplay(data); |
716 //return stopEvent(evt); | 720 return false; // do we even get here? |
717 }); | 721 }); |
718 }; | 722 }; |
719 | 723 |
720 // auxiliary function (from Douglas Crockford, A.10) | 724 // auxiliary function (from Douglas Crockford, A.10) |
721 var isNumber = function isNumber(value) { | 725 var isNumber = function isNumber(value) { |