1 |
|
---|
2 | // elementFade based on javascript from fotonotes.net
|
---|
3 |
|
---|
4 | function elementFade(elm, show, doneCallback)
|
---|
5 | {
|
---|
6 | // Fader function that shows/hides an element.
|
---|
7 | var speed = show ? 4 : 2;
|
---|
8 | elm._f_count |= 0;
|
---|
9 | elm._f_timer |= null;
|
---|
10 | clearTimeout(elm._f_timer);
|
---|
11 |
|
---|
12 | if (show && !elm._f_count) elm.style.visibility = 'inherit';
|
---|
13 |
|
---|
14 | elm._f_count = Math.max(0, Math.min(100, elm._f_count + speed*(show?1:-1)));
|
---|
15 |
|
---|
16 | var f = elm.filters, done = (elm._f_count==100);
|
---|
17 | if (f)
|
---|
18 | {
|
---|
19 | if (!done && elm.style.filter.indexOf("alpha") == -1) {
|
---|
20 | elm.style.filter += ' alpha(opacity=' + elm._f_count + ')';
|
---|
21 | }
|
---|
22 | else if (f.length && f.alpha) with (f.alpha) {
|
---|
23 | if (done) { enabled = false; }
|
---|
24 | else { opacity = elm._f_count; enabled=true }
|
---|
25 | }
|
---|
26 | }
|
---|
27 | else {
|
---|
28 | elm.style.opacity = elm.style.MozOpacity = elm._f_count/100.1;
|
---|
29 | }
|
---|
30 |
|
---|
31 | if (!show && !elm._f_count) {
|
---|
32 | elm.style.visibility = 'hidden';
|
---|
33 | }
|
---|
34 |
|
---|
35 | if (elm._f_count % 100) {
|
---|
36 | // set fresh timeout if count != 100
|
---|
37 | elm._f_timer = setTimeout(function() { elementFade(elm,show,doneCallback) }, 50);
|
---|
38 | }
|
---|
39 | else {
|
---|
40 | if (doneCallback) { doneCallback(); }
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 |
|
---|
45 | function setAlphaVal(elm,val)
|
---|
46 | {
|
---|
47 | var f = elm.filters;
|
---|
48 |
|
---|
49 | if (f)
|
---|
50 | {
|
---|
51 | if (elm.style.filter.indexOf("alpha") == -1) {
|
---|
52 | elm.style.filter += ' alpha(opacity=' + val + ')';
|
---|
53 | }
|
---|
54 | else if (f.length && f.alpha) with (f.alpha) {
|
---|
55 | opacity = val;
|
---|
56 | }
|
---|
57 | }
|
---|
58 | else {
|
---|
59 | elm.style.opacity = elm.style.MozOpacity = val/100.1;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 | function collageSwap()
|
---|
67 | {
|
---|
68 | var collagecanvas = document.getElementById('collagecanvas');
|
---|
69 | var fadingincanvas = document.getElementById('fadingincanvas');
|
---|
70 |
|
---|
71 | fadingincanvas._f_count = 0;
|
---|
72 | fadingincanvas.style.visibility = 'hidden';
|
---|
73 |
|
---|
74 | var collageimg = document.getElementById('collageimg');
|
---|
75 | var fadingimg = document.getElementById('fadingimg');
|
---|
76 |
|
---|
77 | collageimg.src = fadingimg.src;
|
---|
78 |
|
---|
79 | var keyframeNum = fadingimg.keyframeNum;
|
---|
80 | var totalNumKeyframes = fadingimg.totalNumKeyframes;
|
---|
81 |
|
---|
82 | nextKeyframeNum = (keyframeNum % totalNumKeyframes) +1;
|
---|
83 |
|
---|
84 | var collageTimer = setTimeout('fadeNextImage('+nextKeyframeNum+')',2000);
|
---|
85 | fadingimg.collageTimer = collageTimer;
|
---|
86 |
|
---|
87 |
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | function getElementsByClass(searchClass,node,tag) {
|
---|
92 | var classElements = new Array();
|
---|
93 | if ( node == null )
|
---|
94 | node = document;
|
---|
95 | if ( tag == null )
|
---|
96 | tag = '*';
|
---|
97 | var els = node.getElementsByTagName(tag);
|
---|
98 | var elsLen = els.length;
|
---|
99 | var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
|
---|
100 | for (i = 0, j = 0; i < elsLen; i++) {
|
---|
101 | if ( pattern.test(els[i].className) ) {
|
---|
102 | classElements[j] = els[i];
|
---|
103 | j++;
|
---|
104 | }
|
---|
105 | }
|
---|
106 | return classElements;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * sprintf() for JavaScript v.0.4
|
---|
112 | *
|
---|
113 | * Copyright (c) 2007 Alexandru Marasteanu <http://alexei.417.ro/>
|
---|
114 | * Thanks to David Baird (unit test and patch).
|
---|
115 | *
|
---|
116 | * This program is free software; you can redistribute it and/or modify it under
|
---|
117 | * the terms of the GNU General Public License as published by the Free Software
|
---|
118 | * Foundation; either version 2 of the License, or (at your option) any later
|
---|
119 | * version.
|
---|
120 | *
|
---|
121 | * This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
122 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
123 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
---|
124 | * details.
|
---|
125 | *
|
---|
126 | * You should have received a copy of the GNU General Public License along with
|
---|
127 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
128 | * Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
129 | */
|
---|
130 |
|
---|
131 | function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }
|
---|
132 |
|
---|
133 | function sprintf () {
|
---|
134 | var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
|
---|
135 | while (f) {
|
---|
136 | if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
|
---|
137 | else if (m = /^\x25{2}/.exec(f)) o.push('%');
|
---|
138 | else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
|
---|
139 | if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
|
---|
140 | if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
|
---|
141 | throw("Expecting number but found " + typeof(a));
|
---|
142 | switch (m[7]) {
|
---|
143 | case 'b': a = a.toString(2); break;
|
---|
144 | case 'c': a = String.fromCharCode(a); break;
|
---|
145 | case 'd': a = parseInt(a); break;
|
---|
146 | case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
|
---|
147 | case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
|
---|
148 | case 'o': a = a.toString(8); break;
|
---|
149 | case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
|
---|
150 | case 'u': a = Math.abs(a); break;
|
---|
151 | case 'x': a = a.toString(16); break;
|
---|
152 | case 'X': a = a.toString(16).toUpperCase(); break;
|
---|
153 | }
|
---|
154 | a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
|
---|
155 | c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
|
---|
156 | x = m[5] - String(a).length;
|
---|
157 | p = m[5] ? str_repeat(c, x) : '';
|
---|
158 | o.push(m[4] ? a + p : p + a);
|
---|
159 | }
|
---|
160 | else throw ("Huh ?!");
|
---|
161 | f = f.substring(m[0].length);
|
---|
162 | }
|
---|
163 | return o.join('');
|
---|
164 | }
|
---|