author | Dan |
Sun, 04 Jan 2009 22:56:57 -0500 | |
changeset 67 | c4aefad02ce4 |
parent 58 | 05a69bab5f10 |
permissions | -rw-r--r-- |
1 | 1 |
// The "Dynano" Javascript framework. Similar in syntax to JQuery but only has what Enano needs. |
2 |
// License = GPLv2 |
|
3 |
||
4 |
var $ = function(id) |
|
5 |
{ |
|
6 |
return new DNobj(id); |
|
7 |
} |
|
8 |
var $dynano = $; |
|
9 |
function DNobj(id) |
|
10 |
{ |
|
11 |
this.object = ( typeof(id) == 'object' ) ? id : document.getElementById(id); |
|
12 |
if ( !this.object ) |
|
13 |
{ |
|
14 |
this.object = false; |
|
58
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
15 |
return false; |
1 | 16 |
} |
58
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
17 |
if ( this.object.Dynano ) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
18 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
19 |
return this.object.Dynano; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
20 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
21 |
this.object.Dynano = this; |
1 | 22 |
this.height = __DNObjGetHeight(this.object); |
23 |
this.width = __DNObjGetWidth(this.object); |
|
58
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
24 |
// fixme: make more accurate? |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
25 |
this.object.DN_opac = 100; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
26 |
|
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
27 |
return true; |
1 | 28 |
} |
29 |
function __DNObjGetHeight(o) { |
|
30 |
return o.offsetHeight; |
|
31 |
} |
|
32 |
||
33 |
function __DNObjGetWidth(o) { |
|
34 |
return o.offsetWidth; |
|
35 |
} |
|
36 |
||
37 |
function addClass(obj, clsname) |
|
38 |
{ |
|
39 |
var cnt = obj.className; |
|
40 |
var space = ( (cnt + '').length > 0 ) ? ' ' : ''; |
|
41 |
var cls = cnt + space + clsname; |
|
42 |
obj.className = cls; |
|
43 |
} |
|
44 |
||
45 |
function rmClass(obj, clsname) |
|
46 |
{ |
|
47 |
var cnt = obj.className; |
|
48 |
if ( cnt == clsname ) |
|
49 |
{ |
|
50 |
obj.className = ''; |
|
51 |
} |
|
52 |
else |
|
53 |
{ |
|
54 |
cnt = cnt.replace(clsname, ''); |
|
55 |
cnt = trim(cnt); |
|
56 |
obj.className = cnt; |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
function hasClass(obj, clsname) |
|
61 |
{ |
|
62 |
var cnt = obj.className; |
|
63 |
if ( !cnt ) |
|
64 |
return false; |
|
65 |
if ( cnt == clsname ) |
|
66 |
return true; |
|
67 |
cnt = cnt.split(' '); |
|
68 |
||
69 |
for ( var i in cnt ) |
|
70 |
if ( cnt[i] == clsname ) |
|
71 |
return true; |
|
72 |
||
73 |
return false; |
|
74 |
} |
|
75 |
function __DNObjGetLeft(obj) { |
|
76 |
var left_offset = obj.offsetLeft; |
|
77 |
while ((obj = obj.offsetParent) != null) { |
|
78 |
left_offset += obj.offsetLeft; |
|
79 |
} |
|
80 |
return left_offset; |
|
81 |
} |
|
82 |
||
83 |
function __DNObjGetTop(obj) { |
|
84 |
var left_offset = obj.offsetTop; |
|
85 |
while ((obj = obj.offsetParent) != null) { |
|
86 |
left_offset += obj.offsetTop; |
|
87 |
} |
|
88 |
return left_offset; |
|
89 |
} |
|
90 |
||
91 |
DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; }; |
|
92 |
DNobj.prototype.rmClass = function(clsname) { rmClass( this.object, clsname); return this; }; |
|
93 |
DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); }; |
|
58
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
94 |
DNobj.prototype.Height = function() { return __DNObjGetHeight(this.object); }; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
95 |
DNobj.prototype.Width = function() { return __DNObjGetWidth( this.object); }; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
96 |
DNobj.prototype.Left = function() { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); }; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
97 |
DNobj.prototype.Top = function() { /* return this.object.offsetTop; */ return __DNObjGetTop( this.object); }; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
98 |
DNobj.prototype.insertText = function(text) { this.object.appendChild(document.createTextNode(text)); return this; }; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
99 |
DNobj.prototype.insertBR = function() { this.object.appendChild(document.createElement('br')); return this; }; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
100 |
DNobj.prototype.attr = function(attribute, value) { this.object.setAttribute(attribute, value); return this; }; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
101 |
DNobj.prototype.css = function(attribute, value) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
102 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
103 |
if ( attribute == 'float' ) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
104 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
105 |
this.object.style.cssFloat = value; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
106 |
this.object.style.styleFloat = value; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
107 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
108 |
else |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
109 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
110 |
// convert attribute to CamelCase format (quick and easy version) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
111 |
var i; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
112 |
while ( (i = attribute.indexOf('-')) > -1 ) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
113 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
114 |
attribute = attribute.substr(0, i) + |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
115 |
attribute.substr(i + 1, 1).toUpperCase() + |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
116 |
attribute.substr(i + 2); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
117 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
118 |
this.object.style[attribute] = value; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
119 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
120 |
return this; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
121 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
122 |
DNobj.prototype.opacity = function(opacity) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
123 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
124 |
var object = this.object.style; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
125 |
object.opacity = (opacity / 100); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
126 |
object.MozOpacity = (opacity / 100); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
127 |
object.KhtmlOpacity = (opacity / 100); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
128 |
object.filter = "alpha(opacity=" + opacity + ")"; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
129 |
this.object.DN_opac = opacity; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
130 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
131 |
DNobj.prototype.fade = function(to, time, done) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
132 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
133 |
var from = this.object.DN_opac; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
134 |
if ( to == from ) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
135 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
136 |
return this; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
137 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
138 |
time = time || 500; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
139 |
var op = to > from ? 1 : -1; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
140 |
var timestep = time / ( op * (to - from) ); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
141 |
var i = from, tick = 0, o = this.object; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
142 |
this.object.id = this.object.id || 'dynano_autofade_' + Math.floor(Math.random() * 1000000); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
143 |
|
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
144 |
while ( true ) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
145 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
146 |
i += op; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
147 |
tick += timestep; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
148 |
|
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
149 |
if ( ( op == -1 && i < to ) || ( op == 1 && i > to ) ) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
150 |
break; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
151 |
|
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
152 |
setTimeout('$("' + this.object.id + '").opacity(' + i + ');', tick); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
153 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
154 |
if ( typeof(done) == 'function' ) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
155 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
156 |
setTimeout(function() |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
157 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
158 |
done(o); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
159 |
}, tick); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
160 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
161 |
return this; |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
162 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
163 |
DNobj.prototype.fadeIn = function(time, done) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
164 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
165 |
return this.fade(100, time, done); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
166 |
} |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
167 |
DNobj.prototype.fadeOut = function(time, done) |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
168 |
{ |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
169 |
return this.fade(0, time, done); |
05a69bab5f10
Added custom volume setting function (press v in the playlist window)
Dan
parents:
11
diff
changeset
|
170 |
} |
1 | 171 |
|
2
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
172 |
// Equivalent to PHP trim() function |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
173 |
function trim(text) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
174 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
175 |
text = text.replace(/^([\s]+)/, ''); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
176 |
text = text.replace(/([\s]+)$/, ''); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
177 |
return text; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
178 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
179 |
|
11
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
180 |
// Tell which elements have the specified CSS class |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
181 |
// Parameters: |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
182 |
// * object - HTMLElement |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
183 |
// * string - class name |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
184 |
// * string - tag name, if omitted will test all elements (slow) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
185 |
function getElementsByClassName(oRoot, className, tagName) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
186 |
{ |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
187 |
tagName = ( tagName ) ? tagName : '*'; |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
188 |
var arrEls = document.getElementsByTagName(tagName); |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
189 |
var arrResult = []; |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
190 |
for ( var i = 0; i < arrEls.length; i++ ) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
191 |
{ |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
192 |
if ( $(arrEls[i]).hasClass(className) ) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
193 |
{ |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
194 |
arrResult.push(arrEls[i]); |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
195 |
} |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
196 |
} |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
197 |
return arrResult; |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
198 |
} |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
199 |
|
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
200 |
// shortcut :) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
201 |
document.getElementsByClassName = function(a, b) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
202 |
{ |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
203 |
return getElementsByClassName(document, a, b); |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
204 |
} |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
205 |