Advertisement
lmohanarun

A simple PUBNUB based HTML/JavaScript code to interact with

Oct 15th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.58 KB | None | 0 0
  1. <html>
  2. <head>
  3.     <p>
  4.         <button id=broadcast-enable class=broadcast-button>Enable Desktop Notifications</button>
  5.         <span id=broadcast-ready>Loading...</span>
  6.     </p>
  7.     <p>
  8.         <button id=broadcast-button class=broadcast-button>Broadcast HTML5 Desktop Notification</button>
  9.         <input id=broadcast-text value='Hello Everyone!' />
  10.     </p>
  11.  
  12. <div channel-name=notifications-channel segregate-notifications-by-page=false id=desktop-notifications-config></div>
  13. </head>
  14. <body>
  15.     <script src=http://cdn.pubnub.com/pubnub-3.7.14.min.js></script>
  16.     <script src=html5-desktop-notification-broadcasting.js></script>
  17.     <script>(function(){
  18.         function update_ready(enabled) {
  19.             var ready = PUBNUB.$('broadcast-ready');
  20.  
  21.             if (enabled) {
  22.                 ready.innerHTML = 'Enabled';
  23.                 PUBNUB.attr( ready, 'class', 'broadcast-enabled' );
  24.             }
  25.             else {
  26.                 ready.innerHTML = 'Disabled';
  27.                 PUBNUB.attr( ready, 'class', 'broadcast-disabled' );
  28.             }
  29.         }
  30.  
  31.         update_ready(PUBNUB.notify.ready());
  32.  
  33.         PUBNUB.bind('mousedown,touchstart', PUBNUB.$('broadcast-button'),
  34.             function() {
  35.                 return PUBNUB.notify({
  36.                     image : 'http://cdn.pubnub.com/assets/pubnub-70x70.png',
  37.                     title : 'PubNub Notification',
  38.                     body : PUBNUB.$('broadcast-text').value || "empty message"
  39.                 });
  40.             }
  41.         );
  42.  
  43.         PUBNUB.bind('mousedown,touchstart', PUBNUB.$('broadcast-enable'),
  44.             function() {
  45.                 PUBNUB.notify.enable(function(){
  46.                     update_ready(PUBNUB.notify.ready());
  47.                 });
  48.             }
  49.         );
  50.     })();</script>
  51.  
  52. <p><p>Powered by
  53. <img src="https://cdn.evbuc.com/eventlogos/3970164/pubnub.png" width="75" length="50">
  54.  
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement