forked from mbuonomo/notificationcenter
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
697 lines (673 loc) · 22.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Notification center - Jquery</title>
<meta name="viewport" content="width=1200, initial-scale=0.5">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="description" content="Apple OS X Style Notification Center for website. Written in jQuery.">
<meta name="keywords" content="Notification, Center, jQuery, OS X, Apple">
<meta name="author" content="Justin F. Hallett">
<link href="css/notifcenter.css" rel="stylesheet">
<link rel="stylesheet" href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="css/demo.css">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="js/jquery.moment.js"></script>
<script src="js/jquery.livestamp.js"></script>
<script src="js/jquery.notificationcenter.js"></script>
<script src="js/jquery.timer.js"></script>
<!-- <script src="http://176.31.127.193:8000/faye/client.js"></script> -->
<script>
// Load jquery mobile, unless we're working locally
( function() {
if ( window.location.origin !== 'file://' ) {
var scrpt = document.createElement('script');
scrpt.src = 'http://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.js';
document.getElementsByTagName('head')[0].appendChild( scrpt );
}
})();
var client = null;
$(document).ready(function(){
if (typeof $.mobile === 'object') {
$.mobile.linkBindingEnabled = false;
$.mobile.ajaxEnabled = false;
$.mobile.hashListeningEnabled = false;
}
$('.collapsable').hide();
$('.permalink').bind('click', function() {
if ($(this).parents('td').length > 0) {
$(this).closest('tr').find('.collapsable').toggle();
} else {
$(this).closest('div').find('.collapsable').toggle();
}
return false;
});
var minutes = 5;
var seconds = minutes * 60;
var counter = setInterval(function() {
if (seconds > 0) {
seconds--;
var mins = Math.floor(seconds / 60);
var secs = seconds - (mins * 60);
if (mins < 10)
mins = '0' + mins;
if (secs < 10)
secs = '0' + secs;
$('.timer').html(mins + ':' + secs);
} else {
seconds = minutes * 60;
$.notificationcenter.newAlert('This alert has been pushed via ' + minutes + ' minute timer', 'invite');
}
}, 1000);
var date = new Date();
$('body').notificationcenter({
notification_offset: 50,
types:[
{
type: 'sticky',
img: 'fa fa-clock-o',
imgtype: 'class',
display_time: 0
},
{
type: 'fontawesome',
img: 'fa fa-bullseye',
imgtype: 'class',
type_max_display: 2,
alert_hidden_sound: 'sounds/Basso'
},
{
type: 'invite',
img: 'img/invite.png',
bgcolor: '#3366ff'
},
{
type: 'todo',
img: 'img/clipboard.png',
bgcolor: '#fff',
color: '#000'
},
{
type: 'gift',
img: 'img/gift.png',
bgcolor: '#eb5d49',
truncate_message: 50
},
{
type: 'calendar',
img: 'img/calendar.png',
bgcolor: '#2767a8'
},
{
type: 'system',
img: 'img/settings.png',
type_max_display: 10
}
],
default_notifs:[
{
type: 'system',
values:[{
text: {
text: 'This is an example, I have a callback click me to see it.',
title: 'Callback'
},
time: date.getTime()/1000,
callback: function(notif) {
$.notificationcenter.alert(notif.text, notif.type);
},
new: true
}]
}
],
alert_hidden_sound: 'sounds/Purr',
store_callback: function(notifs) {
console.log(JSON.stringify(notifs));
}
});
$('.slideit').on('click', function() {
$.notificationcenter.slide();
});
$('.notif').on('click', function() {
if ($(this).attr('data-type') == 'snooze') {
$.notificationcenter.alert('New alert by button click, with a callback action.', 'sticky', function(notif) {
setTimeout( function() {
$.notificationcenter.alert(notif.text, notif.type, notif.callback, 'snooze');
}, 1 * 60 * 1000);
}, 'snooze');
} else {
$.notificationcenter.newAlert({'text':'New alert by button click.', 'title':$(this).attr('data-type')}, $(this).attr('data-type'));
}
});
var ajax_options = 'examples/object.json';
var ajax_checkTime = 5 * 60 * 1000; // 5 minutes
$('.ajax').on('click', function() {
if (!$('.ajax').hasClass('disabled')) {
$.notificationcenter.ajax(ajax_options, ajax_checkTime);
$('.ajax').addClass('disabled');
}
});
});
</script>
</head>
<body>
<div id="noticationcentermain" style="background: #fff;">
<div id="top" class="navigation">
<div class="brand">
<a href="#"><i class="fa fa-flask"></i> jquery.notificationcenter.js</a>
</div>
<ul class="right">
<li><a href="#docs">Documentation</a></li>
<li><a href="#params">Parameters</a></li>
<li><a href="#meths">Methods</a></li>
<li><a href="#tips">Tips</a></li>
<li style="padding-left: 20px;"><span id="notificationcentericon"><i class="fa fa-bars fa-2x"></i></span></li>
</ul>
</div>
<div class="content">
<div class="banner">
<h1>Notification center for jQuery!</h1>
<p>Trying to implement a simple notification center like like Apple OS X.</p>
<h4>FEATURES</h4>
<ul>
<li>Document title modification to show alert count</li>
<li>Display only a certain amount of notifs at once</li>
<li>Sound notification if the user is on an other tab/page</li>
<li>Per type Sounds/Colors/alert timeout and notif count displayed</li>
<li>Pop up alerts that are not retained in the notif pane</li>
<li>Click overlay when the pane is open so any click closes the pane</li>
<li>Notif callbacks, including a redisplay notification option</li>
<li>Export callback so you can save the list of current notifs</li>
<li>Mobile compat, includes options for swipe delete on notifs</li>
<li>Mobile on notifications stay in viewport even with pinch zoom</li>
<li>CSS Styled allows lots of styling control to the site</li>
<li>Allow ajax and/or faye alerts on top of js calls to create alerts</li>
<li>Allow Sticky notifications, sticky notifications also have an optional settable action button</li>
</ul>
<p><a class="btn btn-primary btn-large" href="https://github.com/thesin-/notificationcenter/archive/master.zip"><i class="fa fa-cloud-download fa-lg"></i> Download</a> <a class="btn btn-success btn-large" href="https://github.com/thesin-/notificationcenter"><i class="fa fa-github-alt fa-lg"></i> GitHub</a></p>
</div>
<div style="text-align: center; font-weight: bold; width: 100%">
<p>New notification in <span class="timer"></span></p>
</div>
<div>
<div class="cell">
<h2>Panel Control</h2>
<div>
<div class="cell">
<p>It's really easy to show the center. The plugin create a panel on the right side of your website.</p>
<p><a class="btn slideit" href="#">Show/Hide panel</a></p>
</div>
</div>
</div>
<div class="cell">
<h2>Notifications</h2>
<div>
<div class="cell">
<p>How to throw a notification with Javascript.</p>
<p><a class="btn notif" href="#" data-type="gift">Add a notification</a></p>
<p><a class="btn notif" href="#" data-type="calendar">Add an other type</a></p>
<p><a class="btn notif" href="#" data-type="fontawesome">Add a class type</a></p>
<p><a class="btn notif" href="#" data-type="sticky">Add a alert</a></p>
<p><a class="btn notif" href="#" data-type="snooze">Add a alert w/callback</a></p>
</div>
</div>
</div>
<div class="cell">
<h2>Ajax Notifications</h2>
<div>
<div class="cell">
<p>How to start an ajax check with Javascript. <span class="comment">Will take 5 minutes before you see the first notification.</span></p>
<p><a class="btn ajax" href="#">Start ajax</a></p>
</div>
</div>
</div>
</div>
<hr>
<div>
<div class="cell">
<a href="http://faye.jcoglan.com"><img src="img/faye-logo.gif"></a>
<div class="cell">
<p>Why not adding a little bit of push in it?</p>
<blockquote>
<p>Faye is a publish-subscribe messaging system based on the <a href="http://svn.cometd.com/trunk/bayeux/bayeux.html" target="_blank">Bayeux</a> protocol. It provides message servers for <a href="http://nodejs.org/" target="_blank">Node.js</a> and <a href="http://www.ruby-lang.org/" target="_blank">Ruby</a>, and clients for use on the server and in all major web browsers.</p>
</blockquote>
</div>
</div>
</div>
<hr>
<div>
<div class="cell">
<h2 id="tips">Tips <a class="top" href="#top">back to top</a></h2>
<div class="cell">
<ul>
<li>
<p>Want to display the date for each notification?</p>
<p>Include <a href="http://momentjs.com/" target="_blank">Moment.js</a> and <a href="http://mattbradley.github.io/livestampjs/" target="_blank">Livestamp.js</a> and ENJOY :)</p>
</li>
<li>
<p>Want mobile support with swipe delete? <span class="comment">Try it on a mobile device, swipe left on a notif in the notification panel to delete it.</span></p>
<p>Include <a href="http://jquerymobile.com" target="_blank">jquery.mobile.js</a> and ENJOY :) <span class="comment">(jquery.mobile.css not required)</span></p>
</li>
<li>
<p>Add some color to the overlay when the panel is out?</p>
<pre>
<style>
#notificationcenteroverlay {
background-color: #000;
opacity: 0.5;
}
</style></pre>
</li>
</ul>
</div>
</div>
</div>
<hr>
<div>
<div class="cell">
<h2 id="docs">Documentation <a class="top" href="#top">back to top</a></h2>
<div>
<div class="cell">
<h3>HTML setup</h3>
<div class="cell">
<pre>
<body>
<div id="noticationcentermain">
[...]all your html[...]
</div>
</body></pre>
</div>
</div>
</div>
<div>
<div class="cell">
<h3>Javascript setup</h3>
<div class="cell">
<pre>
<script>
$('body').notificationcenter({
center_element: "#notificationcenterpanel",
body_element: "#noticationcentermain",
toggle_button: "#notificationcentericon",
add_panel: true,
notification_offset: 0,
display_time: 5000,
types: [],
type_max_display: 5,
truncate_message: 0,
header_output: '{icon} {type} {count}',
counter: true,
default_notifs: [],
faye: false,
ajax: false,
ajax_checkTime: 5000,
alert_hidden: true,
alert_hidden_sound: "sounds/Funk",
store_callback: false
});
</script></pre>
</div>
</div>
</div>
<div>
<div class="cell">
<h3 id="params">Parameters <a class="top" href="#top">back to top</a></h3>
<div class="cell">
<table class="arguments">
<thead>
<tr>
<th style="width: 100px;">Name</th>
<th style="width: 50px;">type</th>
<th style="width: 50px;">default</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>center_element</td>
<td>string</td>
<td>"#notificationcenterpanel"</td>
<td>Define the id of the element embedding your dom.</td>
</tr>
<tr>
<td>body_element</td>
<td>string</td>
<td>"#noticationcentermain"</td>
<td>Closes the modal when escape key is pressed</td>
</tr>
<tr>
<td>toggle_button</td>
<td>string</td>
<td>"#notificationcentericon"</td>
<td>Id of the button to toggle the panel.</td>
</tr>
<tr>
<td>add_panel</td>
<td>boolean</td>
<td>true</td>
<td>If you want the panel on the right.</td>
</tr>
<tr>
<td>notification_offset</td>
<td>int</td>
<td>0</td>
<td>If you want the notifications to start a little lower. Useful to not cover up the notificationcentericon.</td>
</tr>
<tr>
<td>display_time</td>
<td>int</td>
<td>5000</td>
<td>Display time for each notification in milliseconds. <span class="comment">0 means the notification is sticky and will not be added to the notif pane</span></td>
</tr>
<tr>
<td><a href="#" class="permalink">types</a></td>
<td>array</td>
<td>[]</td>
<td>Array of objects to define the types of each notifications.
<div class="collapsable">
<pre>
$('body').notificationcenter({
types: [{
type: 'gift', // define the type
img: 'img/gift.png', // icon path
imgtype: 'image', // image or class, if class img is the classes
type_max_display: 5, // if not present the global is used
display_time: 5000, // if not present the global is used
alert_hidden: true, // if not present the global is used
alert_hidden_sound: 'sounds/Funk', // if not present the global is used
truncate_message: 0, // if not present the global is used
header_output: '{icon} {type} {count}', // if not present the global is used
bgcolor: '#EB5D49', // background color for the center header
color: '#FFFFFF' // text color for the center header
}, {
[...]
}]
});</pre>
</div>
</td>
</tr>
<tr>
<td>type_max_display</td>
<td>int</td>
<td>5</td>
<td>The amount of notifications per type to display in the panel, the rest will get queued as some are removed others will show. <span class="comment">0 = no limit</span></td>
</tr>
<tr>
<td>counter</td>
<td>boolean</td>
<td>true</td>
<td>Display a counter.</td>
</tr>
<tr>
<td>truncate_message</td>
<td>int</td>
<td>0</td>
<td>Display only one x characters of the notification/notif. <span class="comments">callback will always have the full message</span></td>
</tr>
<tr>
<td>header_output</td>
<td>string</td>
<td>"{icon} {type} {count}"</td>
<td>Template for the notif headers</td>
</tr>
<tr>
<td><a href="#" class="permalink">default_notifs</a></td>
<td>array</td>
<td>[]</td>
<td>Array of objects to define the default notifications. <span class="comments">callback is optional, text can be a string or an object like the example.</span>
<div class="collapsable">
<pre>
$('body').notificationcenter({
default_notifs: [{
type: 'gift', // define the type
values: [{
text: {
text: 'This is an example',
title: 'This is a title'
},
time: date.getTime()/1000,
new: true,
callback: function(notif) {
$.notificationcenter.alert(notif.text, notif.type);
}
}]
}, {
[...]
}]
});</pre>
</div>
</td>
</tr>
<tr>
<td><a href="#" class="permalink">faye</a></td>
<td>object</td>
<td>false</td>
<td>Object to define the faye connection.
<div class="collapsable">
<pre>
$('body').notificationcenter({
faye: {
server: 'http://yourserver:port'
chanel: 'your chanel'
}
});</pre>
</div>
</td>
</tr>
<tr>
<td><a href="#" class="permalink">ajax</a></td>
<td>object</td>
<td>false</td>
<td><a href="http://api.jquery.com/jQuery.ajax/">jQuery ajax Object</a> to define the ajax call.
<div class="collapsable">
<pre>
$('body').notificationcenter({
ajax: {
type: 'POST',
url: 'some.php',
data: {
authkey: 'guess',
user: 'john'
}
}
});</pre>
A JSON array is expected as a result of the query, each item can be as an array or an object.
<pre>
[
[
"This is an alert",
"system"
],
[ ... ]
]</pre>
<pre>
[
{
"text": "This is an alert",
"type": "system"
},
{
[ ... ]
}
]</pre>
</div>
</td>
</tr>
<tr>
<td>ajax_checkTime</td>
<td>int</td>
<td>5000</td>
<td>Time between ajax calls in milliseconds.</td>
</tr>
<tr>
<td>alert_hidden</td>
<td>boolean</td>
<td>true</td>
<td>If you want to be alerted even if the page has not the focus.</td>
</tr>
<tr>
<td>alert_hidden_sound</td>
<td>string</td>
<td>''</td>
<td>Url of the audio file <strong>without the extension</strong> You must provide the file in both format MP3/OGG</td>
</tr>
<tr>
<td><a href="#" class="permalink">store_callback</a></td>
<td>function</td>
<td>false</td>
<td>Function to call to store the panel's contents, false = no storage. <span class="comments">An object that holds the current panel info will be passed in as an arg. Check your console.</span>
<div class="collapsable">
<pre>
$('body').notificationcenter({
store_callback: function(notifs) {
$.ajax({
type: 'POST',
url: 'some.php',
data: {
uid: 100,
notifications: notifs
}
}).done(function(data) {
console.log('storage updated')
});
}
});</pre>
</div>
</td>
</tr>
<tr>
<td>overlay</td>
<td>boolean</td>
<td>true</td>
<td>Add overlay to prevent interaction with main page while the notification panel is open</td>
</tr>
<tr>
<td>overlay_z_index</td>
<td>int</td>
<td>1001</td>
<td>Z-index added to the overlay. This value is also used to keep elements on top of the overlay.</td>
</tr>
<tr>
<td>center_time_attr</td>
<td>string</td>
<td>"data-livestamp"</td>
<td>Attribute where the current time is added.</td>
</tr>
<tr>
<td><a href="#" class="permalink">lang</a></td>
<td>object</td>
<td>see description</td>
<td>Change the language used by notificiationcenter.
<div class="collapsable">
By default, this option is set to <pre>{
no_notifications : 'No New Notifications',
delete : 'Delete', // mobile Delete button
close : 'Close', // Close notification button
}</pre>
<ul>
<li><code>no_notifications</code> sets the text shown when the notification panel does not contain any notifications.</li>
<li><code>delete</code> sets the text of the mobile delete notification button</li>
<li><code>close</code></li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div>
<div class="cell">
<h3 id="meths">Methods <a class="top" href="#top">back to top</a></h3>
<div>
<div class="cell">
<h4><a href="#" class="permalink">$.notificationcenter.slide()</a></h4>
<div class="cell collapsable">
<pre>
$.notificationcenter.slide();</pre>
</div>
</div>
</div>
<div>
<div class="cell">
<h4><a href="#" class="permalink">$.notificationcenter.newAlert(text, [type], [display notification], [callback], [time], [new])</a></h4>
<div class="cell collapsable">
<pre>
$.notificationcenter.newAlert('This is a new alert.', 'gift', true, function(notif) { $.notificationcenter.alert(notif.text, notif.type); }, 1406857387, true);</pre>
</div>
</div>
</div>
<div>
<div class="cell">
<h4><a href="#" class="permalink">$.notificationcenter.faye(faye_object)</a></h4>
<div class="cell collapsable">
<pre>
var faye = {
server: 'http://yourserver:port',
channel: 'your channel'
};
$.notificationcenter.faye(faye);</pre>
</div>
</div>
</div>
<div>
<div class="cell">
<h4><a href="#" class="permalink">$.notificationcenter.ajax(options_object, checkTime)</a></h4>
<div class="cell collapsable">
<pre>
var ajax_options = {
type: 'POST',
url: 'some.php',
data: {
userid: 99
}
};
$.notificationcenter.ajax(ajax_options, 5000);</pre>
</div>
</div>
</div>
<div>
<div class="cell">
<h4><a href="#" class="permalink">$.notificationcenter.alert(text, [type], [callback], [action])</a></h4>
<div class="cell collapsable">
This is very useful for callbacks, you could setup a callback type even. <span type="comment">action defaults to banner, anything else gives you a action button on your callback and sets the notificaiton to sticky aka no timeout.</span>
<div class="cell">
<pre>
$.notificationcenter.alert('This is just an alert, nothing in notificaiton center', 'system', function(notif) { $.notificationcenter.alert(notif.text, notif.type); });</pre>
</div>
</div>
</div>
</div>
<div>
<div class="cell">
<h4><a href="#" class="permalink">$.notificationcenter.captureTitle([title])</a></h4>
<div class="cell collapsable">
Set a page title. <span class="comments">title is optional, it'll use the current title otherwise</span>
<div class="cell">
<pre>
$.notificationcenter.captureTitle('This is the new page title');</pre>
</div>
Use the current page title. <span class="comment">It will attempt to detect and remove any current notification counts</span>
<div class="cell">
<pre>
$.notificationcenter.captureTitle();</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
© jquery.notificationcenter.js
</footer>
</div>
</body>
</html>