PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/app/index.html

https://github.com/colincarr/pubnub-backbone
HTML | 291 lines | 228 code | 46 blank | 17 comment | 0 complexity | 79f74dcb6740e225cf584d6326104243 MD5 | raw file
  1. <!doctype html>
  2. <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
  3. <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
  4. <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
  5. <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  6. <head>
  7. <meta charset="utf-8">
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  9. <title>Backbone.js and PubNub Integration - Real Time Backbone Collections and Models</title>
  10. <meta name="description" content="">
  11. <meta name="viewport" content="width=device-width">
  12. <link href="favicon.ico" rel="shortcut icon" type="image/x-icon">
  13. <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300' rel='stylesheet' type='text/css'>
  14. <link rel="stylesheet" href="bower_components/google-code-prettify/src/prettify.css">
  15. <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
  16. <!-- build:css(.tmp) styles/main.css -->
  17. <link rel="stylesheet" href="styles/main.css">
  18. <!-- endbuild -->
  19. <!-- build:js scripts/vendor/modernizr.js -->
  20. <script src="bower_components/modernizr/modernizr.js"></script>
  21. <!-- endbuild -->
  22. </head>
  23. <body>
  24. <a href="https://github.com/pubnub" id="github"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub"></a>
  25. <div class="title">
  26. <div class="container">
  27. <div class="row-fluid">
  28. <div class="span12">
  29. <h1>Backbone.js + PubNub</h1>
  30. <h3>Real-Time Multi-User Backbone Collections and Models</h3>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="main">
  36. <div class="container">
  37. <div class="row-fluid border-row">
  38. <div class="span6">
  39. <div id="todoapp">
  40. <header>
  41. <h3>Todos</h3>
  42. <input id="new-todo" type="text" placeholder="What needs to be done?">
  43. <br />
  44. <input id="toggle-all" type="checkbox">
  45. <label for="toggle-all">Mark all as complete</label>
  46. </header>
  47. <section id="main">
  48. <div class="row-fluid">
  49. <ul id="todo-list"></ul>
  50. </div>
  51. </section>
  52. <footer>
  53. <a id="clear-completed">Clear completed</a>
  54. <div id="todo-count"></div>
  55. <div id="instructions">
  56. Double-click to edit a todo.
  57. </div>
  58. </footer>
  59. </div>
  60. </div>
  61. <div class="span6 what-is-happening">
  62. <div>
  63. <h2>How It Works</h2>
  64. <p>This is an example of the <a href="http://backbonejs.org/examples/todos/index.html" target="_blank">Backbone Todo List</a> extended with the real-time power of <a href="http://pubnub.com" target="_blank">PubNub</a>. Every time a change is detected in the collection of todos, that change is propagated to all other clients running the same demo in their browser. <a href="http://pubnub.github.io/backbone" target="_blank">Open this page in another browser window</a> to see it in action!</p>
  65. <a href="http://github.com/pubnub/backbone" id="github" class="btn btn-large"><i class="icon-github-sign"></i>View on GitHub</a>
  66. <br />
  67. <br />
  68. <iframe src="http://ghbtns.com/github-btn.html?user=pubnub&repo=backbone&type=watch&count=true"
  69. allowtransparency="true" frameborder="0" scrolling="0" width="110" height="20"></iframe>
  70. <a href="https://twitter.com/share" class="twitter-share-button" data-via="pubnub">Tweet</a>
  71. <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
  72. <div class="fb-like" data-href="https://www.facebook.com/PubNub" data-width="450" data-layout="button_count" data-show-faces="false" data-send="false"></div>
  73. </div>
  74. </div>
  75. </div>
  76. <div class="row-fluid">
  77. <div class="span12">
  78. <h3>Getting Started</h3>
  79. <p>You can install the package using bower and <code>bower install pubnub-backbone</code> or by cloning this repository. Install the PubNub library along with this one in your html file like so, replacing the *&#39;s with the PubNub version you want to use:</p>
  80. <p><pre class="prettyprint linenums">&lt;script src=&quot;http://cdn.pubnub.com/pubnub.min.js&quot;&gt;&lt;/script&gt;
  81. &lt;script src=&quot;/path/to/backbone-pubnub.min.js&quot;&gt;&lt;/script&gt;</pre></p>
  82. <p>From here the framework gives you three ways to integrate:</p>
  83. </div>
  84. </div>
  85. <div class="row-fluid">
  86. <div class="span12">
  87. <h3>Backbone.PubNub.Collection</h3>
  88. <p>This collection takes the pubnub instance and a name and then publishes all create, update, and delete methods across clients using PubNub. The <code>name</code> property is used to generate a unique channel name so collections do not collide with each other. As a warning, with the same name will update each other regardless of what class they come from.</p>
  89. <p><pre class="prettyprint linenums">
  90. var MyCollection = Backbone.PubNub.Collection.extend({
  91. name: &#39;MyCollection&#39;, // Used to namespace the updates to this collection
  92. pubnub: pubnub // A global instance of PubNub
  93. });
  94. var myCollection = new MyCollection();</pre></p>
  95. </div>
  96. </div>
  97. <div class="row-fluid">
  98. <div class="span12">
  99. <h3>Backbone.sync</h3>
  100. <p>The Backbone.sync method allows you to have a collection with a remote store, much like the LocalStorage module from the original Backbone Todos demo. This allows you to take updates from other clients when you want them and not automatically.</p>
  101. <p><pre class="prettyprint linenums">
  102. var MyCollection = Backbone.Collection.extend({
  103. pubnub: new Backbone.PubNub(pubnub, "MyCollection") // A PubNub plugin to make the collection real-time
  104. });
  105. var myCollection = new MyCollection();</pre></p>
  106. </div>
  107. </div>
  108. <div class="row-fluid">
  109. <div class="span12">
  110. <h3>Backbone.PubNub.Model</h3>
  111. <p>This will create a model that is updated in real-time across all instances. This works very similarly to the collection in that it publishes all changes across the PubNub network.</p>
  112. </div>
  113. </div>
  114. <div class="row-fluid border-row">
  115. <div class="span6">
  116. <p><pre class="prettyprint linenums">
  117. var MyModel = Backbone.PubNub.Model.extend({
  118. name: &#39;MyModel&#39;,
  119. pubnub: pubnub
  120. });
  121. var myModel = new MyModel();</pre></p>
  122. </div>
  123. <div class="span6">
  124. <div id="mymodel"></div>
  125. </div>
  126. </div>
  127. <div class="row-fluid">
  128. <div class="span4">
  129. <h3>What is PubNub?</h3>
  130. <p>Todays users expect to interact in real-time. PubNub makes it easy for you to add real-time capabilities to your apps, without worrying about the infrastructure. Build apps that allow your users to engage in real-time across mobile, browser, desktop and server.</p>
  131. </div>
  132. <div class="span8">
  133. <h3>What Can I Build With PubNub?</h3>
  134. <p>The PubNub Real-Time Network takes care of the connections, global infrastructure and key building blocks for real-time interactivity, so you can focus creating killer apps</p>
  135. <ul style="float: left; width: 50%;">
  136. <li>Real-Time Collaboration</li>
  137. <li>Machine-to-Machine</li>
  138. <li>Real-Time Financial Streams</li>
  139. <li>Real-Time Location Tracking</li>
  140. <li>Call Triggering</li>
  141. </ul>
  142. <ul>
  143. <li>2nd Screen Sync</li>
  144. <li>Live Dashboards</li>
  145. <li>Multi-Player Games</li>
  146. <li>Group Chat Rooms</li>
  147. <li>Thousands more</li>
  148. </ul>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. <div class="highlight">
  154. <div class="container">
  155. <div class="row-fluid">
  156. <div class="span8">
  157. <h3 class="call-to-action">Start Building Real-Time Apps Now!</h3>
  158. </div>
  159. <div class="span2 offset2">
  160. <a href="http://pubnub.com/free-trial" class="btn btn-large" id="get-started">Get Started</a>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. <footer class="text-center">
  166. &copy; 2013 PubNub
  167. </footer>
  168. <script type="text/template" id="mymodel-template">
  169. <h3>Real-Time Model</h3>
  170. <p>Open this page in another window to see me update in real-time!</p>
  171. <p>Rand: <%= rand %></p>
  172. <button id="update">Set Random Number</button>
  173. </script>
  174. <!-- Templates -->
  175. <script type="text/template" id="item-template">
  176. <div class="view">
  177. <input class="toggle" type="checkbox" <%= done ? 'checked="checked"' : '' %> />
  178. <label><%- title %></label>
  179. <a class="destroy"><i class="icon-remove-circle"></i></a>
  180. </div>
  181. <input class="edit" type="text" value="<%- title %>" />
  182. </script>
  183. <script type="text/template" id="stats-template">
  184. <% if (done) { %>
  185. <a id="clear-completed">Clear <%= done %> completed <%= done == 1 ? 'item' : 'items' %></a>
  186. <% } %>
  187. <div class="todo-count"><b><%= remaining %></b> <%= remaining == 1 ? 'item' : 'items' %> left</div>
  188. </script>
  189. <!--[if lt IE 7]>
  190. <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
  191. <![endif]-->
  192. <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
  193. <script>
  194. (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
  195. function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
  196. e=o.createElement(i);r=o.getElementsByTagName(i)[0];
  197. e.src='//www.google-analytics.com/analytics.js';
  198. r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
  199. ga('create','UA-41019038-2');ga('send','pageview');
  200. </script>
  201. <script type="text/javascript">
  202. (function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===e.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f);b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==
  203. typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.track_charge people.clear_charges people.delete_user".split(" ");for(g=0;g<i.length;g++)f(c,i[g]);
  204. b._i.push([a,e,d])};b.__SV=1.2}})(document,window.mixpanel||[]);
  205. mixpanel.init("778311a72655af3d2eaebacbccf26122");
  206. </script>
  207. <div id="fb-root"></div>
  208. <script>(function(d, s, id) {
  209. var js, fjs = d.getElementsByTagName(s)[0];
  210. if (d.getElementById(id)) return;
  211. js = d.createElement(s); js.id = id;
  212. js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  213. fjs.parentNode.insertBefore(js, fjs);
  214. }(document, 'script', 'facebook-jssdk'));</script>
  215. <script src="http://cdn.pubnub.com/pubnub-3.5.3.min.js"></script>
  216. <!-- build:js scripts/plugins.js -->
  217. <script src="bower_components/jquery/jquery.js"></script>
  218. <script src="bower_components/sass-bootstrap/js/bootstrap-affix.js"></script>
  219. <script src="bower_components/sass-bootstrap/js/bootstrap-alert.js"></script>
  220. <script src="bower_components/sass-bootstrap/js/bootstrap-dropdown.js"></script>
  221. <script src="bower_components/sass-bootstrap/js/bootstrap-tooltip.js"></script>
  222. <script src="bower_components/sass-bootstrap/js/bootstrap-modal.js"></script>
  223. <script src="bower_components/sass-bootstrap/js/bootstrap-transition.js"></script>
  224. <script src="bower_components/sass-bootstrap/js/bootstrap-button.js"></script>
  225. <script src="bower_components/sass-bootstrap/js/bootstrap-popover.js"></script>
  226. <script src="bower_components/sass-bootstrap/js/bootstrap-typeahead.js"></script>
  227. <script src="bower_components/sass-bootstrap/js/bootstrap-carousel.js"></script>
  228. <script src="bower_components/sass-bootstrap/js/bootstrap-scrollspy.js"></script>
  229. <script src="bower_components/sass-bootstrap/js/bootstrap-collapse.js"></script>
  230. <script src="bower_components/sass-bootstrap/js/bootstrap-tab.js"></script>
  231. <script src="bower_components/underscore/underscore.js"></script>
  232. <script src="bower_components/backbone/backbone.js"></script>
  233. <script src="bower_components/google-code-prettify/src/prettify.js"></script>
  234. <!-- endbuild -->
  235. <script>
  236. (function(){
  237. prettyPrint();
  238. })();
  239. </script>
  240. <!-- build:js(.tmp) scripts/main.js -->
  241. <script src="scripts/backbone-pubnub.js"></script>
  242. <script src="scripts/main.js"></script>
  243. <!-- endbuild -->
  244. </body>
  245. </html>