Permalink
Browse files

Preliminary JS refactoring

  • Loading branch information...
1 parent 0cfe86d commit 69f6a3d3a8e50b756002ddf3bc5083b285a2576d @rf- committed Dec 31, 2012
@@ -1,48 +1,23 @@
<!doctype html>
<html>
-<head>
- <meta charset="utf-8">
- <title>Pry Notebook</title>
- <style>
- .content {
- width: 800px;
- margin: 0 auto;
- background: #EEEEEE;
- padding: 1em;
- }
- </style>
-
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js"></script>
-
- <script>
- $(function () {
- var klass = ("MozWebSocket" in window) ? MozWebSocket : WebSocket,
- socket = new klass('ws://' + window.location.host);
-
- socket.onmessage = function (msg) {
- var data = JSON.parse(msg.data),
- div = $('<div/>');
-
- div.addClass("pry-" + data.type);
- div.text(data.value);
- $('.output').append(div);
- }
-
- $('input').on('keyup', function (e) {
- if (e.keyCode == 13) {
- $.post('/', $(this).val());
- $(this).val('');
- }
- });
- });
- </script>
-</head>
-<body>
- <div class="content">
- <h1>Pry Notebook</h1>
- <div class="output"></div>
- <input type="text"></input>
- </div>
-</body>
+ <head>
+ <meta charset="utf-8">
+ <title>Pry Notebook</title>
+ <link rel="stylesheet" type="text/css" href="/pry-notebook.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js"></script>
+ <script src="/notebook.js"></script>
+ <script src="/main.js"></script>
+ </head>
+ <body>
+ <div class="content">
+ <div class="header">
+ <h1>Pry Notebook</h1>
+ </div>
+ <div class="output"></div>
+ <div class="footer">
+ <input type="text"></input>
+ </div>
+ </div>
+ </body>
</html>
Oops, something went wrong.
@@ -0,0 +1,7 @@
+$(function () {
+ var nb = new Notebook({ input: ".input input", output: ".output" });
+
+ Notebook.openSocket(function (msg) {
+ nb.handleMessage(JSON.parse(msg.data));
+ });
+});
@@ -0,0 +1,24 @@
+function Notebook(options) {
+ this.bindKeyup();
+};
+
+Notebook.openSocket = function(callback) {
+ var klass = ("MozWebSocket" in window) ? MozWebSocket : WebSocket,
+ socket = new klass('ws://' + window.location.host);
+
+ socket.onmessage = callback;
+};
+
+Notebook.prototype.handleMessage = function(data) {
+ var div = $('<div/>').addClass("pry-" + data.type).text(data.value);
+ $('.output').append(div);
+};
+
+Notebook.prototype.bindKeyup = function () {
+ $('input').on('keyup', function (e) {
+ if (e.keyCode == 13) {
+ $.post('/', $(this).val());
+ $(this).val('');
+ }
+ });
+};
@@ -0,0 +1,19 @@
+.content {
+ width: 800px;
+ margin: 0 auto;
+ background: #EEEEEE;
+ padding: 16px;
+}
+
+.output, input {
+ font-family: Monaco, Consolas, monospace;
+ font-size: 16px;
+}
+
+input {
+ border: none;
+ width: 800px;
+ position: relative;
+ left: -8px;
+ padding: 2px 8px;
+}
@@ -0,0 +1,15 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Pry Notebook</title>
+ <link rel="stylesheet" type="text/css" href="/pry-notebook.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js"></script>
+ <script src="/notebook.js"></script>
+ <script src="/jasmine.js"></script>
+ <script src="/test.js"></script>
+ </head>
+ <body>
+ </body>
+</html>
@@ -0,0 +1,5 @@
+describe("This shit", function() {
+ it("is bananas", function() {
+ expect(true).toBe(true);
+ });
+});

0 comments on commit 69f6a3d

Please sign in to comment.