Commits

Justin Venezuela committed d65afaf

Templated noted.js.

Comments (0)

Files changed (4)

   else:
     g.user = None
 
+@app.route('/noted.js', methods=['GET'])
+def noted_js():
+  return render_template('noted.js')
+
 @app.route('/', methods=['GET'])
 def home():
   # Redirect user to notes if already logged in.

src/static/js/noted.js

-/**
- * Author: Justin Venezuela (jven@mit.edu)
- * Client-side JavaScript for Noted web application.
- */
-
-$(document).ready(function() {
-  /**
-   * Initializes the UI for the Noted web application.
-   */
-  var main = function() {
-    // Example text stuff. TODO(jven): back button browser issues
-    $('.textbox').each(function(idx, elt_id) {
-      var textbox = $(elt_id);
-      var example = textbox.siblings(':last-child');
-      textbox.focus(function() {
-        example.hide();
-      });
-      textbox.blur(function() {
-        if (textbox.val() == '') {
-          example.show();
-        }
-      });
-      example.click(function() {
-        textbox.focus();
-      });
-    });
-
-    // Pressing ` brings up admin panel.
-    $(document).keydown(function(event) {
-      if (event.keyCode == '192') {
-        // `
-        $('#admin_panel').slideToggle();
-      }
-    });
-
-    // Make new note upon clicking note container.
-    var note_container = $('#note_container');
-    note_container.click(function(event) {
-      var newNote = $('<div/>', {
-          'class':'note',
-      });
-      var newNoteInterior = $('<div/>', {
-          'class':'note_interior'
-      });
-      var newNoteLoader = $('<div/>', {
-          'class':'loader'
-      });
-      $.post('/data', {
-          'method':'new'
-      }, function(data) {
-        newNote.attr('id', 'note_' + data);
-        newNote.attr('note-id', data);
-        var newNoteDelete = $('<div/>', {
-            'id':'note_delete_' + data,
-            'class':'note_delete',
-            'note-id':data
-        });
-        newNoteDelete.prependTo(newNote);
-        var newNoteContent = $('<textarea/>', {
-            'class':'note_content',
-            'note-id':data
-        });
-        newNoteLoader.remove();
-        newNoteContent.appendTo(newNoteInterior);
-        refreshNotes();
-        // focus the new note
-        newNoteContent.focus();
-      });
-      newNoteLoader.appendTo(newNoteInterior);
-      newNoteInterior.appendTo(newNote);
-      newNote.appendTo(note_container);
-      refreshNotes();
-    });
-
-    // Register/login buttons.
-    $('#register_submit').click(function() {
-      $.post('/register', {
-          'name':$('#register_name').val(),
-          'email':$('#register_email').val(),
-          'password_1':$('#register_password_1').val(),
-          'password_2':$('#register_password_2').val()
-      }, function(data) {
-        response = eval('(' + data + ')');
-        if (response.type == 'error') {
-          $('#errors').html(response.message);
-          $('#errors').fadeIn();
-        } else if (response.type == 'redirect') {
-          $('#errors').hide();
-          window.location = response.url;
-        }
-      });
-    });
-    $('#login_submit').click(function() {
-      $.post('/login', {
-          'email':$('#login_email').val(),
-          'password':$('#login_password').val()
-      }, function(data) {
-        response = eval('(' + data + ')');
-        if (response.type == 'error') {
-          $('#errors').html(response.message);
-          $('#errors').fadeIn();
-        } else if (response.type == 'redirect') {
-          $('#errors').hide();
-          window.location = response.url;
-        }
-      });
-    });
-
-    // Enter button form sends the appropriate request.
-    var registerOnEnter = function(event) {
-      if (event.keyCode == 13) {
-        $('#register_submit').click();
-      }
-    };
-    var loginOnEnter = function(event) {
-      if (event.keyCode == 13) {
-        $('#login_submit').click();
-      }
-    }
-    $('#register_name').keydown(registerOnEnter);
-    $('#register_email').keydown(registerOnEnter);
-    $('#register_password_1').keydown(registerOnEnter);
-    $('#register_password_2').keydown(registerOnEnter);
-    $('#login_email').keydown(loginOnEnter);
-    $('#login_password').keydown(loginOnEnter);
-
-    // Stop propagation of keydowns from textboxes.
-    $('.textbox').keydown(function(event) {
-      event.stopPropagation();
-    });
-
-    // Initialize notes page.
-    refreshNotes();
-  };
-
-  /**
-   * Binds the events for the notes page. Show/hide instructions.
-   */
-  var refreshNotes = function() {
-    // Instructions.
-    if ($('.note').length != 0) {
-      $('#instructions').fadeOut();
-    } else {
-      $('#instructions').show();
-    }
-
-    // Make notes draggable and make delete button partially visible on hover.
-    // Also, stop propagation of click events on notes.
-    $('.note').each(function(idx, elt_id) {
-      var note = $(elt_id);
-      var note_delete = $(
-          '#note_delete_' + note.attr('note-id'));
-      note.draggable({
-          'containment':'parent'
-      });
-      note.unbind('hover');
-      note.hover(function() {
-        note_delete.css('opacity', 0.3);
-      }, function() {
-        note_delete.css('opacity', 0.0);
-      });
-      note.click(function(event) {
-        event.stopPropagation();
-      });
-    });
-
-    // Make delete buttons completely visible on hover and delete note
-    // and stop propagation on click.
-    $('.note_delete').each(function(idx, elt_id) {
-      var note_delete = $(elt_id);
-      var note = $('#note_' + note_delete.attr('note-id'));
-      note_delete.unbind('hover');
-      note_delete.hover(function() {
-        note_delete.css('opacity', 1.0);
-      }, function() {
-        note_delete.css('opacity', 0.3);
-      });
-      note_delete.unbind('click');
-      note_delete.click(function(event) {
-        event.stopPropagation();
-        $.post('/data', {
-            'method':'delete',
-            'id':note_delete.attr('note-id'),
-        });
-        note.remove();
-        refreshNotes();
-      });
-    });
-    // Change note content backgrounds on focus. Revert backgrounds and
-    // modify note on blur. Also modify note on keydown and blur note on enter.
-    // Also, stop propagation of keyboard events.
-    $('.note_content').each(function(idx, elt_id) {
-      var note_content = $(elt_id);
-      note_content.unbind('focus');
-      note_content.focus(function() {
-        note_content.addClass('note_content_selected');
-      });
-      note_content.unbind('blur');
-      note_content.blur(function() {
-        note_content.removeClass('note_content_selected');
-        $.post('/data', {
-            'method':'modify',
-            'id':note_content.attr('note-id'),
-            'content':note_content.val()
-        });
-      });
-      note_content.unbind('keydown');
-      note_content.keydown(function(event) {
-        event.stopPropagation();
-        if (event.keyCode == 13) {
-          // enter
-          note_content.blur();
-        } else {
-          $.post('/data', {
-              'method':'modify',
-              'id':note_content.attr('note-id'),
-              'content':note_content.val()
-          });
-        }
-      });
-    });
-  };
-
-  // Call the main method.
-  main();
-});

src/templates/_base.html

     type="text/javascript"></script>
 <script src="{{ url_for('static', filename='js/jquery.example.min.js') }}"
     type="text/javascript"></script>
-<script src="{{ url_for('static', filename='js/noted.js') }}"
-    type="text/javascript"></script>
+<script src="{{ url_for('noted_js') }}" type="text/javascript"></script>
 <title>Noted!</title>
 </head>
 <body>

src/templates/noted.js

+/**
+ * Author: Justin Venezuela (jven@mit.edu)
+ * Client-side JavaScript for Noted web application.
+ */
+
+$(document).ready(function() {
+  /**
+   * Initializes the UI for the Noted web application.
+   */
+  var main = function() {
+    // Example text stuff. TODO(jven): back button browser issues
+    $('.textbox').each(function(idx, elt_id) {
+      var textbox = $(elt_id);
+      var example = textbox.siblings(':last-child');
+      textbox.focus(function() {
+        example.hide();
+      });
+      textbox.blur(function() {
+        if (textbox.val() == '') {
+          example.show();
+        }
+      });
+      example.click(function() {
+        textbox.focus();
+      });
+    });
+
+    // Pressing ` brings up admin panel.
+    $(document).keydown(function(event) {
+      if (event.keyCode == '192') {
+        // `
+        $('#admin_panel').slideToggle();
+      }
+    });
+
+    // Make new note upon clicking note container.
+    var note_container = $('#note_container');
+    note_container.click(function(event) {
+      var newNote = $('<div/>', {
+          'class':'note',
+      });
+      var newNoteInterior = $('<div/>', {
+          'class':'note_interior'
+      });
+      var newNoteLoader = $('<div/>', {
+          'class':'loader'
+      });
+      $.post('{{ url_for('data') }}', {
+          'method':'new'
+      }, function(data) {
+        newNote.attr('id', 'note_' + data);
+        newNote.attr('note-id', data);
+        var newNoteDelete = $('<div/>', {
+            'id':'note_delete_' + data,
+            'class':'note_delete',
+            'note-id':data
+        });
+        newNoteDelete.prependTo(newNote);
+        var newNoteContent = $('<textarea/>', {
+            'class':'note_content',
+            'note-id':data
+        });
+        newNoteLoader.remove();
+        newNoteContent.appendTo(newNoteInterior);
+        refreshNotes();
+        // focus the new note
+        newNoteContent.focus();
+      });
+      newNoteLoader.appendTo(newNoteInterior);
+      newNoteInterior.appendTo(newNote);
+      newNote.appendTo(note_container);
+      refreshNotes();
+    });
+
+    // Register/login buttons.
+    $('#register_submit').click(function() {
+      $.post('{{ url_for('register') }}', {
+          'name':$('#register_name').val(),
+          'email':$('#register_email').val(),
+          'password_1':$('#register_password_1').val(),
+          'password_2':$('#register_password_2').val()
+      }, function(data) {
+        response = eval('(' + data + ')');
+        if (response.type == 'error') {
+          $('#errors').html(response.message);
+          $('#errors').fadeIn();
+        } else if (response.type == 'redirect') {
+          $('#errors').hide();
+          window.location = response.url;
+        }
+      });
+    });
+    $('#login_submit').click(function() {
+      $.post('{{ url_for('login') }}', {
+          'email':$('#login_email').val(),
+          'password':$('#login_password').val()
+      }, function(data) {
+        response = eval('(' + data + ')');
+        if (response.type == 'error') {
+          $('#errors').html(response.message);
+          $('#errors').fadeIn();
+        } else if (response.type == 'redirect') {
+          $('#errors').hide();
+          window.location = response.url;
+        }
+      });
+    });
+
+    // Enter button form sends the appropriate request.
+    var registerOnEnter = function(event) {
+      if (event.keyCode == 13) {
+        $('#register_submit').click();
+      }
+    };
+    var loginOnEnter = function(event) {
+      if (event.keyCode == 13) {
+        $('#login_submit').click();
+      }
+    }
+    $('#register_name').keydown(registerOnEnter);
+    $('#register_email').keydown(registerOnEnter);
+    $('#register_password_1').keydown(registerOnEnter);
+    $('#register_password_2').keydown(registerOnEnter);
+    $('#login_email').keydown(loginOnEnter);
+    $('#login_password').keydown(loginOnEnter);
+
+    // Stop propagation of keydowns from textboxes.
+    $('.textbox').keydown(function(event) {
+      event.stopPropagation();
+    });
+
+    // Initialize notes page.
+    refreshNotes();
+  };
+
+  /**
+   * Binds the events for the notes page. Show/hide instructions.
+   */
+  var refreshNotes = function() {
+    // Instructions.
+    if ($('.note').length != 0) {
+      $('#instructions').fadeOut();
+    } else {
+      $('#instructions').show();
+    }
+
+    // Make notes draggable and make delete button partially visible on hover.
+    // Also, stop propagation of click events on notes.
+    $('.note').each(function(idx, elt_id) {
+      var note = $(elt_id);
+      var note_delete = $(
+          '#note_delete_' + note.attr('note-id'));
+      note.draggable({
+          'containment':'parent'
+      });
+      note.unbind('hover');
+      note.hover(function() {
+        note_delete.css('opacity', 0.3);
+      }, function() {
+        note_delete.css('opacity', 0.0);
+      });
+      note.click(function(event) {
+        event.stopPropagation();
+      });
+    });
+
+    // Make delete buttons completely visible on hover and delete note
+    // and stop propagation on click.
+    $('.note_delete').each(function(idx, elt_id) {
+      var note_delete = $(elt_id);
+      var note = $('#note_' + note_delete.attr('note-id'));
+      note_delete.unbind('hover');
+      note_delete.hover(function() {
+        note_delete.css('opacity', 1.0);
+      }, function() {
+        note_delete.css('opacity', 0.3);
+      });
+      note_delete.unbind('click');
+      note_delete.click(function(event) {
+        event.stopPropagation();
+        $.post('{{ url_for('data') }}', {
+            'method':'delete',
+            'id':note_delete.attr('note-id'),
+        });
+        note.remove();
+        refreshNotes();
+      });
+    });
+    // Change note content backgrounds on focus. Revert backgrounds and
+    // modify note on blur. Also modify note on keydown and blur note on enter.
+    // Also, stop propagation of keyboard events.
+    $('.note_content').each(function(idx, elt_id) {
+      var note_content = $(elt_id);
+      note_content.unbind('focus');
+      note_content.focus(function() {
+        note_content.addClass('note_content_selected');
+      });
+      note_content.unbind('blur');
+      note_content.blur(function() {
+        note_content.removeClass('note_content_selected');
+        $.post('{{ url_for('data') }}', {
+            'method':'modify',
+            'id':note_content.attr('note-id'),
+            'content':note_content.val()
+        });
+      });
+      note_content.unbind('keydown');
+      note_content.keydown(function(event) {
+        event.stopPropagation();
+        if (event.keyCode == 13) {
+          // enter
+          note_content.blur();
+        } else {
+          $.post('{{ url_for('data') }}', {
+              'method':'modify',
+              'id':note_content.attr('note-id'),
+              'content':note_content.val()
+          });
+        }
+      });
+    });
+  };
+
+  // Call the main method.
+  main();
+});
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.