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

/views/layout.html

https://bitbucket.org/mpuckett/iostudio-whiteboard
HTML | 191 lines | 169 code | 22 blank | 0 comment | 0 complexity | aaf94895b7c0c09b68ec9f6ec4222910 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, MIT
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>iostudio Whiteboard</title>
  6. <style type="text/css" media="screen">
  7. * {
  8. box-sizing: border;
  9. margin: 0;
  10. padding: 0;
  11. }
  12. html,
  13. body {
  14. font-family: Helvetica, sans-serif;
  15. height: 100%;
  16. margin: 50px auto 0;
  17. padding: 20px;
  18. text-align: center;
  19. width: 100%;
  20. }
  21. #dropzone {
  22. border:4px dashed red;
  23. }
  24. .dragover {
  25. background-color: orange;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div id="dashboard">Drag files here.</div>
  31. <div id="files-list"></div>
  32. <script src="http://d3js.org/d3.v2.js"></script>
  33. <svg id="main"></svg>
  34. <script type="text/javascript">
  35. var svg = d3.select("#main");
  36. var line = d3.svg.line()
  37. .x(function(d) { return d[0]; })
  38. .y(function(d) { return d[1] + 200; })
  39. .interpolate('cardinal');
  40. function init(){
  41. randData = [];
  42. for (var i = 0; i < 7; i++){
  43. randData.push([i*50, Math.random() * 100]);
  44. }
  45. svg.data([randData])
  46. .append("svg:path")
  47. .attr("d", line)
  48. .attr("fill", "#444")
  49. .attr("stroke", "#aaa")
  50. .attr("stroke-width", 7);
  51. setInterval(refresh, 500);
  52. }
  53. function refresh(){
  54. //var randData = [];
  55. for (var i = 0; i < 1; i++){
  56. randData.push([Math.random() * 200, Math.random() * 200]);
  57. }
  58. svg.data([randData])
  59. .select("path")
  60. .transition()
  61. .duration(500)
  62. .attr("d", line);
  63. }
  64. init();
  65. </script>
  66. <script id="template-file" type="text/handlebars">
  67. <li><a href="{{name}}" download="{{data}}">{{name}} ({{author}} at {{timestamp}})</a></li>
  68. </script>
  69. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
  70. <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
  71. <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
  72. <script src="//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.5.0-dev/mustache.min.js"></script>
  73. <script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0.beta6/handlebars.min.js"></script>
  74. <script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.10/socket.io.min.js"></script>
  75. <script>
  76. var socket = io.connect('http://localhost:8080');
  77. var AppModel = Backbone.Model.extend({
  78. initialize: function () {
  79. this.on('change', function () {
  80. appController.trigger('change', {
  81. model: this,
  82. changes: arguments[1].changes
  83. });
  84. });
  85. }
  86. });
  87. var FileModel = Backbone.Model.extend({
  88. defaults: {
  89. 'name': 'file.txt',
  90. 'data': 'data:',
  91. 'author': 'New Author',
  92. 'timestamp': 'New Date',
  93. 'location': {
  94. 'offsetX': 0,
  95. 'offsetY': 0
  96. }
  97. }
  98. });
  99. var FilesCollection = Backbone.Collection.extend({
  100. model: FileModel,
  101. initialize: function () {
  102. this.on('add', function (file) {
  103. appController.trigger('newFileAdded', file);
  104. });
  105. }
  106. });
  107. var FilesListView = Backbone.View.extend({
  108. el: '#files-list',
  109. //template: (function () { return Handlebars.compile( $('#template-file').html() ) }()),
  110. template: (function () { return $('#template-file').html() }()),
  111. initialize: function () {
  112. this.on('add', this.add);
  113. },
  114. render: function (file) {
  115. console.log(this.template, file);
  116. return Mustache.render(this.template, file);
  117. },
  118. add: function (file) {
  119. var html = this.render(file);
  120. console.log(html);
  121. this.$el.append(html);
  122. }
  123. });
  124. var DashboardView = Backbone.View.extend({
  125. el: 'body',
  126. events: {
  127. 'dragover': function () {
  128. //this.trigger('stateChange', 'dragover');
  129. console.log('dragover');
  130. },
  131. 'dragleave': function () {
  132. //this.trigger('stateChange', 'dragleave');
  133. console.log('dragleave');
  134. },
  135. 'drop': function (e) {
  136. e.preventDefault();
  137. appController.trigger('newFileDropped', e.originalEvent.dataTransfer.files[0]);
  138. }
  139. }
  140. });
  141. var AppController = Backbone.View.extend({
  142. initialize: function () {
  143. var appModel = new AppModel();
  144. var dashboardView = new DashboardView();
  145. var filesCollection = new FilesCollection();
  146. var filesListView = new FilesListView();
  147. this.on('newFileDropped', function (file) {
  148. var reader = new FileReader();
  149. reader.onload = function () {
  150. socket.emit('newFile', { name: file.name, timestamp: new Date().getTime(), data: this.result });
  151. };
  152. reader.readAsDataURL(file);
  153. });
  154. this.on('newFileFromServer', function (file) {
  155. filesCollection.add(file);
  156. });
  157. this.on('newFileAdded', function (file) {
  158. filesListView.trigger('add', file.toJSON() );
  159. });
  160. }
  161. });
  162. appController = new AppController();
  163. socket.on('_sendFile', function (data) {
  164. console.log(data);
  165. appController.trigger('newFileFromServer', data);
  166. });
  167. </script>
  168. </body>
  169. </html>