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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Apr 18 16:14:42 2003 UTC (21 years, 7 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_slide.js $Revision: 0.12 $
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.slideBy = function(dX, dY, totalTime, endListener) {
7     var targetX, targetY;
8     dX = parseInt(dX); dY = parseInt(dY); targetX = this.left() + dX; targetY = this.top() + dY;
9     this.slideTo(targetX, targetY, totalTime, endListener)
10     }
11     CrossBrowserElement.prototype.slideTo = function(x, y, totalTime, endListener) {
12     if (this.onslidestart) cbeEval(this.onslidestart, this);
13     this.xTarget = parseInt(x); this.yTarget = parseInt(y);
14     this.slideTime = parseInt(totalTime);
15     if (isNaN(this.xTarget)) {
16     var outside=false;
17     if (isNaN(this.yTarget)) { y = 0; outside = true; }
18     this.cardinalPosition(x, y, outside); this.xTarget = this.x; this.yTarget = this.y;
19     }
20     if (endListener && window.cbeEventJsLoaded) { this.autoRemoveListener = true; this.addEventListener('slideend', endListener); }
21     this.stop = false;
22     this.yA = this.yTarget - this.top(); this.xA = this.xTarget - this.left(); // A = distance
23     this.B = Math.PI / (2 * this.slideTime); // B = period
24     this.yD = this.top(); this.xD = this.left(); // D = initial position
25     if (this.slideRate == cbeSlideRateLinear) { this.B = 1/this.slideTime; }
26     else if (this.slideRate == cbeSlideRateCosine) {
27     this.yA = -this.yA; this.xA = -this.xA; this.yD = this.yTarget; this.xD = this.xTarget;
28     }
29     var d = new Date(); this.C = d.getTime();
30     if (!this.moving) this.slide();
31     }
32     CrossBrowserElement.prototype.slide = function() {
33     var now, s, t, newY, newX;
34     now = new Date();
35     t = now.getTime() - this.C;
36     if (this.stop) { this.moving = false; }
37     else if (t < this.slideTime) {
38     setTimeout("window.cbeAll["+this.index+"].slide()", this.timeout);
39     if (this.slideRate == cbeSlideRateLinear) s = this.B * t;
40     else if (this.slideRate == cbeSlideRateSine) s = Math.sin(this.B * t);
41     else s = Math.cos(this.B * t); // this.slideRate == cbeSlideRateCosine
42     newX = Math.round(this.xA * s + this.xD);
43     newY = Math.round(this.yA * s + this.yD);
44     if (this.onslide) cbeEval(this.onslide, this, newX, newY, t);
45     this.moveTo(newX, newY);
46     this.moving = true;
47     }
48     else {
49     this.moveTo(this.xTarget, this.yTarget);
50     this.moving = false;
51     if (this.onslideend) {
52     var tmp = this.onslideend;
53     if (this.autoRemoveListener && window.cbeEventJsLoaded) {
54     this.autoRemoveListener = false;
55     this.removeEventListener('slideend');
56     }
57     cbeEval(tmp, this);
58     }
59     }
60     }
61     CrossBrowserElement.prototype.ellipse = function(xRadius, yRadius, radiusInc, totalTime, startAngle, stopAngle, endListener) {
62     if (this.onslidestart) cbeEval(this.onslidestart, this);
63     this.stop = false;
64     this.xA = parseInt(xRadius);
65     this.yA = parseInt(yRadius);
66     this.radiusInc = parseInt(radiusInc);
67     this.slideTime = parseInt(totalTime);
68     startAngle = cbeRadians(parseFloat(startAngle));
69     stopAngle = cbeRadians(parseFloat(stopAngle));
70     if (endListener && window.cbeEventJsLoaded) {
71     this.autoRemoveListener = true;
72     this.addEventListener('slideend', endListener);
73     }
74     var startTime = (startAngle * this.slideTime) / (stopAngle - startAngle);
75     this.stopTime = this.slideTime + startTime;
76     this.B = (stopAngle - startAngle) / this.slideTime;
77     this.xD = this.left() - Math.round(this.xA * Math.cos(this.B * startTime)); // center point
78     this.yD = this.top() - Math.round(this.yA * Math.sin(this.B * startTime));
79     this.xTarget = Math.round(this.xA * Math.cos(this.B * this.stopTime) + this.xD); // end point
80     this.yTarget = Math.round(this.yA * Math.sin(this.B * this.stopTime) + this.yD);
81     var d = new Date();
82     this.C = d.getTime() - startTime;
83     if (!this.moving) this.ellipse1();
84     }
85     CrossBrowserElement.prototype.ellipse1 = function() {
86     var now, t, newY, newX;
87     now = new Date();
88     t = now.getTime() - this.C;
89     if (this.stop) { this.moving = false; }
90     else if (t < this.stopTime) {
91     setTimeout("window.cbeAll["+this.index+"].ellipse1()", this.timeout);
92     if (this.radiusInc) {
93     this.xA += this.radiusInc;
94     this.yA += this.radiusInc;
95     }
96     newX = Math.round(this.xA * Math.cos(this.B * t) + this.xD);
97     newY = Math.round(this.yA * Math.sin(this.B * t) + this.yD);
98     if (this.onslide) cbeEval(this.onslide, this, newX, newY, t);
99     this.moveTo(newX, newY);
100     this.moving = true;
101     }
102     else {
103     if (this.radiusInc) {
104     this.xTarget = Math.round(this.xA * Math.cos(this.B * this.slideTime) + this.xD);
105     this.yTarget = Math.round(this.yA * Math.sin(this.B * this.slideTime) + this.yD);
106     }
107     this.moveTo(this.xTarget, this.yTarget);
108     this.moving = false;
109     if (this.onslideend) {
110     var tmp = this.onslideend;
111     if (this.autoRemoveListener && window.cbeEventJsLoaded) {
112     this.autoRemoveListener = false;
113     this.removeEventListener('slideend');
114     }
115     cbeEval(tmp, this);
116     }
117     }
118     }
119     CrossBrowserElement.prototype.stopSlide = function() { this.stop = true; }
120     CrossBrowserElement.prototype.startSequence = function(uIndex) {
121     if (!this.moving) {
122     if (!uIndex) this.seqIndex = 0;
123     else this.seqIndex = uIndex;
124     this.addEventListener('slideEnd', cbeSlideSequence);
125     cbeSlideSequence(this);
126     }
127     }
128     CrossBrowserElement.prototype.stopSequence = function() {
129     this.stop=true;
130     this.removeEventListener('slideEnd', cbeSlideSequence);
131     }
132     function cbeSlideSequence(cbe) {
133     var
134     pw = cbe.parentNode.width(),
135     ph = cbe.parentNode.height(),
136     w = cbe.width(),
137     h = cbe.height();
138     if (cbe.seqIndex >= cbe.sequence.length) cbe.seqIndex = 0;
139     eval('cbe.'+cbe.sequence[cbe.seqIndex++]);
140     }
141     var cbeSlideRateLinear=0, cbeSlideRateSine=1, cbeSlideRateCosine=2;
142     CrossBrowserElement.prototype.slideRate = cbeSlideRateSine;
143     CrossBrowserElement.prototype.seqIndex = 0;
144     CrossBrowserElement.prototype.radiusInc = 0;
145     CrossBrowserElement.prototype.t = 0;
146     CrossBrowserElement.prototype.xTarget = 0;
147     CrossBrowserElement.prototype.yTarget = 0;
148     CrossBrowserElement.prototype.slideTime = 1000;
149     CrossBrowserElement.prototype.xA = 0;
150     CrossBrowserElement.prototype.yA = 0;
151     CrossBrowserElement.prototype.xD = 0;
152     CrossBrowserElement.prototype.yD = 0;
153     CrossBrowserElement.prototype.B = 0;
154     CrossBrowserElement.prototype.C = 0;
155     CrossBrowserElement.prototype.moving = false;
156     CrossBrowserElement.prototype.stop = true;
157     CrossBrowserElement.prototype.timeout = 35;
158     CrossBrowserElement.prototype.autoRemoveListener = false;
159     CrossBrowserElement.prototype.onslidestart = null;
160     CrossBrowserElement.prototype.onslide = null;
161     CrossBrowserElement.prototype.onslideend = null;
162     var cbeSlideJsLoaded = true;
163     // End cbe_slide.js

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