@@ -0,0 +1,337 @@
1+var smoke = {
2+ smoketimeout: [],
3+ init: false,
4+ zindex: 1000,
5+ i: 0,
6+
7+ bodyload: function(id){
8+ var ff = document.createElement('div');
9+ ff.setAttribute('id','smoke-out-'+id);
10+/* ff.setAttribute('class','smoke-base'); */
11+ ff.className = 'smoke-base';
12+ ff.style.zIndex = smoke.zindex;
13+ smoke.zindex++;
14+ document.body.appendChild(ff);
15+ },
16+
17+ newdialog: function(){
18+ var newid = new Date().getTime();
19+ newid = Math.random(1,99) + newid;
20+
21+ // make a new container while you're at it
22+ if (!smoke.init){
23+ smoke.listen(window,"load", function(){
24+ smoke.bodyload(newid);
25+ });
26+ }else{
27+ smoke.bodyload(newid);
28+ }
29+
30+ return newid;
31+ },
32+
33+ forceload: function(){},
34+
35+ build: function(e,f){
36+ smoke.i++;
37+
38+ // determine stacking order
39+ f.stack = smoke.i;
40+
41+ e = e.replace(/\n/g,'<br />');
42+ e = e.replace(/\r/g,'<br />');
43+
44+ var prompt = '';
45+
46+ if (f.type == 'prompt'){
47+ prompt =
48+ '<div class="dialog-prompt">'+
49+ '<input id="dialog-input-'+f.newid+'" type="text" ' + (f.params.value ? 'value="' + f.params.value + '"' : '') + ' />'+
50+ '</div>';
51+ }
52+
53+
54+ var ok = 'OK';
55+ var cancel = 'Cancel';
56+ var classname = '';
57+
58+ if (f.params.ok){
59+ ok = f.params.ok;
60+ }
61+
62+ if (f.params.cancel){
63+ cancel = f.params.cancel;
64+ }
65+
66+ if (f.params.classname){
67+ classname = f.params.classname;
68+ }
69+
70+
71+ var buttons = '';
72+ if (f.type != 'signal'){
73+ buttons = '<div class="dialog-buttons">';
74+ if (f.type == 'alert'){
75+ buttons +=
76+ '<button id="alert-ok-'+f.newid+'">'+ok+'</button>';
77+ }
78+ if (f.type == 'prompt' || f.type == 'confirm'){
79+ buttons +=
80+ '<button id="'+f.type+'-cancel-'+f.newid+'" class="cancel">'+cancel+'</button>'+
81+ '<button id="'+f.type+'-ok-'+f.newid+'">'+ok+'</button>';
82+ }
83+ buttons += '</div>';
84+ }
85+
86+
87+ var box =
88+ '<div id="smoke-bg-'+f.newid+'" class="smokebg"></div>'+
89+ '<div class="dialog smoke '+classname+'">'+
90+ '<div class="dialog-inner">'+
91+ e+
92+ prompt+
93+ buttons+
94+ '</div>'+
95+ '</div>';
96+
97+
98+
99+
100+
101+ if (!smoke.init){
102+ smoke.listen(window,"load", function(){
103+ smoke.finishbuild(e,f,box);
104+ });
105+ }else{
106+ smoke.finishbuild(e,f,box);
107+ }
108+
109+ },
110+
111+
112+
113+ finishbuild: function(e,f,box){
114+
115+ var ff = document.getElementById('smoke-out-'+f.newid+'');
116+ ff.className = 'smoke-base smoke-visible smoke-' + f.type;
117+ ff.innerHTML = box;
118+
119+ while (ff.innerHTML == ""){
120+ ff.innerHTML = box;
121+ }
122+
123+ // clear the timeout if it's already been activated
124+ if (smoke.smoketimeout[f.newid]){
125+ clearTimeout(smoke.smoketimeout[f.newid]);
126+ }
127+
128+ // close on background click
129+ // buberdds got rid of this for ie support?
130+ var g = document.getElementById('smoke-bg-'+f.newid+'');
131+ smoke.listen(g,"click", function(){
132+ smoke.destroy(f.type, f.newid);
133+ if (f.type == 'prompt' || f.type == 'confirm'){
134+ f.callback(false);
135+ }
136+// checkit
137+ if (f.type == 'alert' && typeof f.callback !== 'undefined') {
138+ f.callback();
139+ }
140+ });
141+
142+
143+ // listeners for button actions
144+
145+ if (f.type == 'alert'){
146+ // return true
147+ var h = document.getElementById('alert-ok-'+f.newid+'');
148+ smoke.listen(h,"click", function(){
149+ smoke.destroy(f.type, f.newid);
150+ if (typeof f.callback !== 'undefined') {
151+ f.callback();
152+ }
153+ });
154+
155+
156+ // listen for enter key or space, close it
157+ document.onkeyup = function(e){
158+ if (!e) e = window.event;
159+ if (e.keyCode == 13 || e.keyCode == 32 || e.keyCode == 27){
160+ smoke.destroy(f.type, f.newid);
161+ if (typeof f.callback !== 'undefined') {
162+ f.callback();
163+ }
164+
165+ }
166+ };
167+ }
168+
169+ if (f.type == 'confirm'){
170+ // return false
171+ var h = document.getElementById('confirm-cancel-'+f.newid+'');
172+ smoke.listen(h,"click", function(){
173+ smoke.destroy(f.type, f.newid);
174+ f.callback(false);
175+ });
176+
177+
178+
179+ // return true
180+ var i = document.getElementById('confirm-ok-'+f.newid+'');
181+ smoke.listen(i,"click", function(){
182+ smoke.destroy(f.type, f.newid);
183+ f.callback(true);
184+ });
185+
186+ // listen for enter key or space, close it & return true, esc will close with false
187+ document.onkeyup = function(e){
188+ if (!e) e = window.event;
189+ if (e.keyCode == 13 || e.keyCode == 32){
190+ smoke.destroy(f.type, f.newid);
191+ f.callback(true);
192+ } else if (e.keyCode == 27){
193+ smoke.destroy(f.type, f.newid);
194+ f.callback(false);
195+ }
196+
197+ };
198+
199+ }
200+
201+ if (f.type == 'prompt'){
202+ // focus on input
203+ var pi = document.getElementById('dialog-input-'+f.newid+'');
204+
205+ setTimeout(function(){
206+ pi.focus();
207+ pi.select();
208+ },100);
209+
210+ // return false
211+ var h = document.getElementById('prompt-cancel-'+f.newid+'');
212+ smoke.listen(h,"click", function(){
213+ smoke.destroy(f.type, f.newid);
214+ f.callback(false);
215+ });
216+
217+ // return contents of input box
218+ var j = document.getElementById('dialog-input-'+f.newid+'');
219+ var i = document.getElementById('prompt-ok-'+f.newid+'');
220+ smoke.listen(i,"click", function(){
221+ smoke.destroy(f.type, f.newid);
222+ f.callback(j.value);
223+ });
224+
225+ // listen for enter
226+ document.onkeyup = function(e){
227+ if (!e) e = window.event;
228+ if (e.keyCode == 13){
229+ smoke.destroy(f.type, f.newid);
230+ f.callback(j.value);
231+ } else if (e.keyCode == 27){
232+ smoke.destroy(f.type, f.newid);
233+ f.callback(false);
234+ }
235+ };
236+ }
237+
238+
239+ // close after f.timeout ms
240+ if (f.type == 'signal'){
241+ smoke.smoketimeout[f.newid] = setTimeout(function(){
242+ smoke.destroy(f.type, f.newid);
243+ },f.timeout);
244+ }
245+
246+ },
247+
248+
249+
250+ destroy: function(type,id){
251+ var box = document.getElementById('smoke-out-'+id);
252+/* box.setAttribute('class','smoke-base'); */
253+ box.className = 'smoke-base';
254+
255+
256+ // confirm/alert/prompt remove click listener
257+ if (g = document.getElementById(type+'-ok-'+id)){
258+ smoke.stoplistening(g,"click",function(){});
259+ document.onkeyup = null;
260+ }
261+
262+ // confirm/prompt remove click listener
263+ if (h = document.getElementById(type+'-cancel-'+id)){
264+ smoke.stoplistening(h,"click",function(){});
265+ }
266+
267+ smoke.i = 0;
268+ box.innerHTML = '';
269+
270+ },
271+
272+ alert: function(e,f,g){
273+ if (typeof(f) != 'object'){
274+ f = false;
275+ }
276+
277+ var id = smoke.newdialog();
278+ smoke.build(e,{type:'alert',callback:g,params:f,newid:id});
279+ },
280+
281+ signal: function(e,f){
282+ if (typeof(f) == 'undefined'){
283+ f = 5000;
284+ }
285+
286+ var id = smoke.newdialog();
287+ smoke.build(e,{type:'signal',timeout:f,params:false,newid:id});
288+ },
289+
290+ confirm: function(e,f,g){
291+ if (typeof(g) != 'object'){
292+ g = false;
293+ }
294+
295+ var id = smoke.newdialog();
296+ smoke.build(e,{type:'confirm',callback:f,params:g,newid:id});
297+
298+ },
299+
300+ prompt: function(e,f,g){
301+ if (typeof(g) != 'object'){
302+ g = false;
303+ }
304+
305+ var id = smoke.newdialog();
306+ return smoke.build(e,{type:'prompt',callback:f,params:g,newid:id});
307+ },
308+
309+ listen: function(e,f,g){
310+
311+ if (e.addEventListener) {
312+ e.addEventListener(f, g, false);
313+ } else if (e.attachEvent){
314+ var r = e.attachEvent('on'+f, g);
315+ return r;
316+ }else{
317+ return false;
318+ }
319+ },
320+
321+ stoplistening: function(e,f,g){
322+ if (e.removeEventListener) {
323+ e.removeEventListener("click", g, false);
324+ } else if (e.detachEvent){
325+ var r = e.detachEvent('on'+f, g);
326+ return r;
327+ }else{
328+ return false;
329+ }
330+ }
331+};
332+
333+ if (!smoke.init){
334+ smoke.listen(window,"load", function(){
335+ smoke.init = true;
336+ });
337+ }