xonecas.io
1361
Xc

xonecas.com / commit 57c891d

added smoke.js alerts!

sean2011-09-21 57c891db799d19f86bc38100837dd529a5c84ea3 parent 191fac0

5 files changed

index.html+1−0
@@ -54,6 +54,7 @@
5454 <script src="vendor/underscore.js?v=0.0.3"></script>
5555 <script src="vendor/backbone.js?v=0.0.3"></script>
5656 <script src="vendor/hijs.js?v=0.0.3"></script>
57+ <script src="vendor/smoke.js?v=0.0.3"></script>
5758
5859 <!-- app -->
5960 <script src="js/script.js?v=0.0.3"></script>
js/script.js+3−3
@@ -37,7 +37,7 @@ $(function () {
3737 next: function () {
3838 this.idx++;
3939 if (this.idx + (this.count * this.page) === this.total) {
40- console.log('no more :-(');
40+ this.trigger('error', 'At oldest post.');
4141 this.idx--;
4242 return;
4343 }
@@ -68,7 +68,7 @@ $(function () {
6868 this.fetch();
6969 } else {
7070 this.idx++;
71- this.trigger('error', 'At most recent post');
71+ this.trigger('error', 'At most recent post.');
7272 }
7373 }
7474
@@ -97,7 +97,7 @@ $(function () {
9797 },
9898
9999 report: function (err) {
100- console.log(err);
100+ smoke.alert(err);
101101 },
102102
103103 render: function () {
styles/base.less+2−0
@@ -1,3 +1,5 @@
1+@import "styles/smoke.css";
2+
13 body {
24 margin-top: 50px;
35 }
styles/smoke.css+167−0
@@ -0,0 +1,167 @@
1+.smoke-base {
2+ position: fixed;
3+ top: 0;
4+ left: 0;
5+ bottom: 0;
6+ right: 0;
7+ visibility: hidden;
8+ opacity: 0;
9+ -moz-transition: all .3s;
10+ -webkit-transition: opacity .3s;
11+ -o-transition: all .3s;
12+ transition: all .3s;
13+}
14+
15+.smoke-base.smoke-visible {
16+ opacity: 1;
17+ visibility: visible;
18+}
19+
20+.smokebg {
21+ position: fixed;
22+ top: 0;
23+ left: 0;
24+ bottom: 0;
25+ right: 0;
26+}
27+
28+.smoke-base .dialog {
29+ position: absolute
30+}
31+
32+.dialog-prompt {
33+ margin-top: 5px;
34+ text-align: center;
35+}
36+
37+.dialog-buttons {
38+ margin: 10px 0 5px 0
39+}
40+
41+.smoke {
42+ font-family: sans-serif;
43+ font-weight: bold;
44+ text-align: center;
45+ font-size: 30px;
46+ line-height: 130%;
47+}
48+
49+.dialog-buttons button {
50+ display: inline-block;
51+ vertical-align: baseline;
52+ cursor: pointer;
53+ font-family: sans-serif;
54+ font-style: normal;
55+ text-decoration: none;
56+ border: 0;
57+ outline: 0;
58+ margin: 0 5px;
59+ -webkit-background-clip: padding-box;
60+ font-size: 13px;
61+ line-height: 13px;
62+ font-weight: bold;
63+ padding: 9px 12px;
64+}
65+
66+.dialog-prompt input {
67+ margin: 0;
68+ border: 0;
69+ font-family: sans-serif;
70+ outline: none;
71+ border: 1px solid #333;
72+ width: 97%;
73+ background-color: #fff;
74+ font-size: 15px;
75+ padding: 5px;
76+}
77+
78+.smoke-base {
79+ background: rgba(0,0,0,.3);
80+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#90000000,endColorstr=#900000000);
81+}
82+
83+.smoke-base .dialog {
84+ top: 25%;
85+ left: 25%;
86+ width: 50%;
87+}
88+
89+.smoke-base .dialog-inner {
90+ padding: 15px
91+}
92+
93+.smoke {
94+ text-transform: uppercase;
95+ background-color: rgba(255,255,255,1);
96+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff,endColorstr=#ffffff);
97+}
98+
99+.dialog-buttons button {
100+ border-radius: 5px;
101+ text-transform: uppercase;
102+ background-color: rgba(0,0,0,.9);
103+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#222222,endColorstr=#222222);
104+ color: #fff;
105+}
106+
107+button.cancel {
108+ background-color: rgba(0,0,0,.7);
109+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#444444,endColorstr=#444444);
110+}
111+
112+.queue{
113+ display:none;
114+}
115+
116+
117+.smoke-base {
118+ background: none;
119+}
120+
121+.smoke-base .dialog {
122+ top: 15%;
123+ left: 0;
124+ width: 100%;
125+}
126+
127+.smoke-base .dialog-inner {
128+ padding: 15px;
129+}
130+
131+.smoke {
132+ font-family: 'Helvetica', arial, serif;
133+ text-transform: none;
134+ color:#eee;
135+ font-weight: normal;
136+ background-color: rgba(0,0,0,.75);
137+ font-size:35px;
138+ border-radius: 0;
139+}
140+.dialog-buttons {
141+ margin: 0px 0 5px 0;
142+}
143+
144+.dialog-buttons button {
145+ border-radius: 3px;
146+ text-transform: none;
147+ background-color: #ebebeb;
148+ color: #333;
149+ font-size:13px;
150+ padding:7px 10px;
151+ margin:0 10px;
152+}
153+
154+button.cancel {
155+ background-color: #999;
156+ color:#222
157+}
158+
159+.dialog-prompt{
160+ margin-top:0;
161+}
162+.dialog-prompt input{
163+ width:300px;
164+ text-align:center;
165+ background-color:#ccc;
166+}
167+
vendor/smoke.js+337−0
@@ -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+ }