comparison client/digitallibrary/baselib.js @ 242:e2c455c2a0d0

new digimage with red triangles for moving the zoomed area (can be switched off with "clop=noarrows")
author robcast
date Wed, 04 Aug 2004 20:35:35 +0200
parents bc30dea2bb2e
children 4caec1a85233
comparison
equal deleted inserted replaced
241:bc30dea2bb2e 242:e2c455c2a0d0
1 /* Copyright (C) 2003,2004 WTWG, Uni Bern and others 1 /* Copyright (C) 2003,2004 IT-Group MPIWG, WTWG Uni Bern and others
2 2
3 This program is free software; you can redistribute it and/or 3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License 4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; either version 2 5 as published by the Free Software Foundation; either version 2
6 of the License, or (at your option) any later version. 6 of the License, or (at your option) any later version.
7 7
12 12
13 You should have received a copy of the GNU General Public License 13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software 14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
16 16
17 Authors: ROC 03.06.2004 17 Authors:
18 first version by Christian Luginbuehl, 01.05.2003 18 Christian Luginbuehl, 01.05.2003 (first version)
19 Changed for digiLib in Zope by DW 24.03.2004 19 DW 24.03.2004 (Changed for digiLib in Zope)
20 Robert Casties, 03.08.2004
21
20 */ 22 */
21 23
22 function getInt(n) { 24 function getInt(n) {
23 // returns always an integer 25 // returns always an integer
24 n = parseInt(n); 26 n = parseInt(n);
465 alert("evtPosition: don't know how to deal with "+evt); 467 alert("evtPosition: don't know how to deal with "+evt);
466 } 468 }
467 return new Position(x, y); 469 return new Position(x, y);
468 } 470 }
469 471
472 function registerEvent(type, elem, handler) {
473 // register the given event handler on the indicated element
474 if (elem.addEventListener) {
475 elem.addEventListener(type, handler, false);
476 } else {
477 if (type = "mousedown") {
478 if (elem.captureEvents) {
479 elem.captureEvents(Event.MOUSEDOWN);
480 }
481 elem.onmousedown = handler;
482 } else if (type = "mouseup") {
483 if (elem.captureEvents) {
484 elem.captureEvents(Event.MOUSEUP);
485 }
486 elem.onmouseup = handler;
487 } else if (type = "mousemove") {
488 if (elem.captureEvents) {
489 elem.captureEvents(Event.MOUSEMOVE);
490 }
491 elem.onmousemove = handler;
492 } else if (type = "keypress") {
493 if (elem.captureEvents) {
494 elem.captureEvents(Event.KEYPRESS);
495 }
496 elem.onkeypress = handler;
497 } else {
498 alert("registerEvent: unknown event type "+type);
499 return false;
500 }
501 }
502 return true;
503 }
504
505 function unregisterEvent(type, elem, handler) {
506 // unregister the given event handler from the indicated element
507 if (elem.removeEventListener) {
508 elem.removeEventListener(type, handler, false);
509 } else {
510 if (type = "mousedown") {
511 if (elem.releaseEvents) {
512 elem.releaseEvents(Event.MOUSEDOWN);
513 }
514 elem.onmousedown = null;
515 } else if (type = "mouseup") {
516 if (elem.releaseEvents) {
517 elem.releaseEvents(Event.MOUSEUP);
518 }
519 elem.onmouseup = null;
520 } else if (type = "mousemove") {
521 if (elem.releaseEvents) {
522 elem.releaseEvents(Event.MOUSEMOVE);
523 }
524 elem.onmousemove = null;
525 } else if (type = "keypress") {
526 if (elem.releaseEvents) {
527 elem.releaseEvents(Event.KEYPRESS);
528 }
529 elem.onkeypress = null;
530 } else {
531 alert("unregisterEvent: unknown event type "+type);
532 return false;
533 }
534 }
535 return true;
536 }
537
538
539 // old registerXXYY API for compatibility
470 function registerMouseDown(elem, handler) { 540 function registerMouseDown(elem, handler) {
471 // register a mouse down event handler on the indicated element 541 return registerEvent("mousedown", elem, handler);
472 if (elem.addEventListener) { 542 }
473 elem.addEventListener("mousedown", handler, false);
474 } else {
475 if (elem.captureEvents) {
476 elem.captureEvents(Event.MOUSEDOWN);
477 }
478 elem.onmousedown = handler;
479 }
480 return true;
481 }
482
483 function unregisterMouseDown(elem, handler) { 543 function unregisterMouseDown(elem, handler) {
484 // unregister the mouse down event handler 544 return unregisterEvent("mousedown", elem, handler);
485 if (elem.removeEventListener) { 545 }
486 elem.removeEventListener("mousedown", handler, false);
487 } else {
488 if (elem.releaseEvents) {
489 elem.releaseEvents(Event.MOUSEDOWN);
490 }
491 elem.onmousedown = null;
492 }
493 return true;
494 }
495
496 function registerMouseMove(elem, handler) { 546 function registerMouseMove(elem, handler) {
497 // register a mouse move event handler on the indicated element 547 return registerEvent("mousemove", elem, handler);
498 if (elem.addEventListener) { 548 }
499 elem.addEventListener("mousemove", handler, false);
500 } else {
501 if (elem.captureEvents) {
502 elem.captureEvents(Event.MOUSEMOVE);
503 }
504 elem.onmousemove = handler;
505 }
506 return true;
507 }
508
509 function unregisterMouseMove(elem, handler) { 549 function unregisterMouseMove(elem, handler) {
510 // unregister the mouse move event handler 550 return unregisterEvent("mousemove", elem, handler);
511 if (elem.removeEventListener) { 551 }
512 elem.removeEventListener("mousemove", handler, false);
513 } else {
514 if (elem.releaseEvents) {
515 elem.releaseEvents(Event.MOUSEMOVE);
516 }
517 elem.onmousemove = null;
518 }
519 return true;
520 }
521
522 function registerKeyDown(handler) { 552 function registerKeyDown(handler) {
523 // register a key down handler 553 return registerEvent("keypress", elem, handler);
524 if ( document.addEventListener ) { 554 }
525 this.document.addEventListener('keypress', handler, false); 555
526 } else {
527 if (elem.captureEvents) {
528 elem.captureEvents(Event.MOUSEDOWN);
529 }
530 this.document.onkeypress = handler
531 }
532 return true;
533 }
534 556
535 function getWinSize() { 557 function getWinSize() {
536 // returns a Size with the current window size (mostly from www.quirksmode.org) 558 // returns a Size with the current window size (mostly from www.quirksmode.org)
537 var wsize = new Size(100, 100); 559 var wsize = new Size(100, 100);
538 if (defined(self.innerHeight)) { 560 if (defined(self.innerHeight)) {