/[cvs]/nfo/js/com.cross-browser.cbe/cbe_clip.js
ViewVC logotype

Annotation of /nfo/js/com.cross-browser.cbe/cbe_clip.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Apr 18 16:14:42 2003 UTC (21 years, 2 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
File MIME type: application/javascript
rest of main cbe include files (currently not required)

1 joko 1.1 /* cbe_clip.js $Revision: 0.11 $
2     * CBE v4.19, Cross-Browser DHTML API from Cross-Browser.com
3     * Copyright (c) 2002 Michael Foster (mike@cross-browser.com)
4     * Distributed under the terms of the GNU LGPL from gnu.org
5     */
6     CrossBrowserElement.prototype.autoClip = function(cp, cmd, increment, endListener, dt, dr, db, dl) {
7     if (arguments.length <= 4) {
8     if (this.clipping) return;
9     else this.clipping = true;
10     if (increment) this.clipSpeed = increment;
11     else if (!this.clipSpeed) this.clipSpeed = 10;
12     var unclip = true, w = this.width(), h = this.height(), xcs = Math.abs(this.clipSpeed), ycs = xcs;
13     // Get x and y speeds that are proportional to the element's width and height
14     if (h > w) ycs *= (h/w);
15     else if(w > h) xcs *= (w/h);
16     // Setup clip parameters and initial clip position
17     if (cmd.toLowerCase() == 'clip') { xcs *= -1; ycs *= -1; unclip = false; this.clip(0, w, h, 0); }
18     if (endListener) this.onclipend = endListener;
19     switch(cp.toLowerCase()) {
20     case 'n': dt = -ycs; dr = 0; db = 0; dl = 0; if (unclip) {this.clip(h, w, h, 0);} break;
21     case 'ne': dt = -ycs; dr = xcs; db = 0; dl = 0; if (unclip) {this.clip(h, 0, h, 0);} break;
22     case 'e': dt = 0; dr = xcs; db = 0; dl = 0; if (unclip) {this.clip(0, 0, h, 0);} break;
23     case 'se': dt = 0; dr = xcs; db = ycs; dl = 0; if (unclip) {this.clip(0, 0, 0, 0);} break;
24     case 's': dt = 0; dr = 0; db = ycs; dl = 0; if (unclip) {this.clip(0, w, 0, 0);} break;
25     case 'sw': dt = 0; dr = 0; db = ycs; dl = -xcs; if (unclip) {this.clip(0, w, 0, w);} break;
26     case 'w': dt = 0; dr = 0; db = 0; dl = -xcs; if (unclip) {this.clip(0, w, h, w);} break;
27     case 'nw': dt = -ycs; dr = 0; db = 0; dl = -xcs; if (unclip) {this.clip(h, w, h, w);} break;
28     case 'cen': case 'center': dt = -ycs; dr = xcs; db = ycs; dl = -xcs; if (unclip) {this.clip(h/2, w/2, h/2, w/2);} break;
29     }
30     } // end if
31     if (this.clipBy(dt, dr, db, dl)) { setTimeout("cbeAll["+this.index+"].autoClip("+null+","+null+","+null+","+null+","+dt+","+dr+","+db+","+dl+")", this.timeout); }
32     else {
33     this.clipping = false; var listener = this.onclipend;
34     if (listener) { this.onclipend = null; cbeEval(listener, this); }
35     }
36     }
37     CrossBrowserElement.prototype.scrollBy = function(dx, dy) {
38     var ct = this.clipTop(), cr = this.clipRight(), cb = this.clipBottom(), cl = this.clipLeft(), w = this.width(), h = this.height();
39     // Don't scroll beyond the edge of the element
40     if (cl + dx < 0) dx = -cl;
41     else if (cr + dx > w) dx = w - cr;
42     if (ct + dy < 0) dy = -ct;
43     else if (cb + dy > h) dy = h - cb;
44     // Clip and move to simulate scrolling
45     this.clip(ct + dy, cr + dx, cb + dy, cl + dx);
46     this.moveBy(-dx, -dy);
47     }
48     CrossBrowserElement.prototype.clipBy = function(dt, dr, db, dl) {
49     var ct = this.clipTop();
50     var cr = this.clipRight();
51     var cb = this.clipBottom();
52     var cl = this.clipLeft();
53     var w = this.width();
54     var h = this.height();
55     // Don't clip beyond the existing width and height of the element and don't let top/bottom and left/right coords cross.
56     // Top
57     if (ct + dt < 0) { ct = 0; dt = 0; }
58     else if (ct + dt > cb) { ct = cb; dt = 0; }
59     // Right
60     if (cr + dr < cl) { cr = cl; dr = 0; }
61     else if (cr + dr > w) { cr = w; dr = 0; }
62     // Bottom
63     if (cb + db < ct) { cb = ct; db = 0; }
64     else if (cb + db > h) { cb = h; db = 0; }
65     // Left
66     if (cl + dl < 0) { cl = 0; dl = 0; }
67     else if (cl + dl > cr) { cl = cr; dl = 0; }
68     this.clip(ct + dt, cr + dr, cb + db, cl + dl);
69     if (dt || dr || db || dl) return true;
70     else return false;
71     }
72     CrossBrowserElement.prototype.clipArray = function() {
73     if (this.ele.style) { var re = /\(|px,?\s?\)?|\s|,|\)/; return this.ele.style.clip.split(re); }
74     else return null;
75     }
76     CrossBrowserElement.prototype.clipTop = function() {
77     var v = 0, a = this.clipArray();
78     if (a) v = parseInt(a[1]);
79     else if (this.ele.clip) v = this.ele.clip.top;
80     return v;
81     }
82     CrossBrowserElement.prototype.clipRight = function() {
83     var v = this.width(), a = this.clipArray();
84     if (a) v = parseInt(a[2]);
85     else if (this.ele.clip) v = this.ele.clip.right;
86     return v;
87     }
88     CrossBrowserElement.prototype.clipBottom = function() {
89     var v = this.height(), a = this.clipArray();
90     if (a) v = parseInt(a[3]);
91     else if (this.ele.clip) v = this.ele.clip.bottom;
92     return v;
93     }
94     CrossBrowserElement.prototype.clipLeft = function() {
95     var v = 0, a = this.clipArray();
96     if (a) v = parseInt(a[4]);
97     else if (this.ele.clip) v = this.ele.clip.left;
98     return v;
99     }
100     CrossBrowserElement.prototype.clipWidth = function() {
101     var v = this.width(), a = this.clipArray();
102     if (a) v = parseInt(a[2]) - parseInt(a[4]);
103     else if (this.ele.clip) v = this.ele.clip.width;
104     return v;
105     }
106     CrossBrowserElement.prototype.clipHeight = function() {
107     var v = this.height(), a = this.clipArray();
108     if (a) v = parseInt(a[3]) - parseInt(a[1]);
109     else if (this.ele.clip) v = this.ele.clip.height;
110     return v;
111     }
112     CrossBrowserElement.prototype.timeout = 35;
113     var cbeClipJsLoaded = true;
114     // End cbe_clip.js

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed