Permalink
Browse files

Split the JS functions into logical groupings, fix some more bugs

  • Loading branch information...
1 parent 6f1c4f5 commit 990adfc2b50c009f31a6d2fa483eccc89810d068 @jamesgao committed with Oct 17, 2010
@@ -0,0 +1,14 @@
+body { font-family:sans-serif; font-size:10pt;}
+pre, p { margin:0px; }
+.cblue { color: blue }
+.ccyan { color: teal }
+.cgreen { color: green }
+.cyellow { color: yellow }
+.cred { color: red }
+.cbold { font-weight:bold }
+.hidden { display:none; }
+.clear { clear:both; }
+
+.headers { font-size:60%;}
+.xreq { font-style:italic }
+
@@ -0,0 +1,50 @@
+#sidebar { float:right; width:20%; }
+#statusbar { margin:5px; }
+#statusbar span { vertical-align:middle; }
+#statusbar .bullet {
+ font-size:150%;
+ margin-left:10px;
+ float:right;
+}
+#messages {
+ width:80%;
+ float:left;
+}
+.active {
+ border-color:#090;
+}
+.message {
+ padding:3px;
+ border:1px solid #CCC;
+ margin:5px;
+}
+.message:hover {
+ border:1px solid red;
+ cursor:pointer;
+}
+.message .input_header {
+ color:blue;
+ float:left;
+ width:10%;
+}
+.message .input {
+ float:left;
+ width:90%;
+}
+.message .output_header {
+ color:red;
+ float:left;
+ width:10%;
+}
+.message .output {
+ float:left;
+ width:90%;
+}
+
+.inlinesvg { width:432pt; height:288pt; }
+
+pre.input input {
+ width:100%;
+ border:none;
+ padding:0px;
+}
@@ -0,0 +1,86 @@
+function CometGetter() {
+ this.start()
+ this.request()
+}
+CometGetter.prototype.request = function () {
+ var thisObj = this
+ $.ajax({
+ success: function (json, status, request) {
+ thisObj.complete(json, status, request)
+ }
+ })
+}
+CometGetter.prototype.complete = function(json, status, request) {
+ this.request()
+ this.process(json)
+}
+CometGetter.prototype.process = function (json) {
+ var thisObj = this
+ if (json.msg_type == "status") {
+ statusbar.set(json.content.execution_state)
+ } else if (this.pause) {
+ setTimeout(function () { thisObj.process(json) }, 10)
+ } else {
+ var msg = manager.get(
+ json.parent_header.msg_id,
+ json.parent_header.session)
+ if (json.msg_type == "stream") {
+ msg.setOutput(fixConsole(json.content.data))
+ } else if (json.msg_type == "pyin") {
+ if (json.parent_header.session != session)
+ msg.setInput(fixConsole(json.content.code))
+ } else if (json.msg_type == "pyout") {
+ exec_count = json.content.execution_count
+ msg.num = json.content.execution_count
+ msg.setOutput(fixConsole(json.content.data), true)
+ } else if (json.msg_type == "pyerr") {
+ msg.setOutput(fixConsole(json.content.traceback.join("\n")))
+ }
+ }
+}
+CometGetter.prototype.start = function () {
+ this.pause = false
+}
+CometGetter.prototype.stop = function () {
+ this.pause = true
+}
+
+function heartbeat() {
+ $.ajax({
+ type: "POST",
+ data: {client_id:client_id, type:"heartbeat"},
+ success: function() {
+ setTimeout(heartbeat, 60000)
+ }
+ })
+}
+
+function execute(code, postfunc) {
+ $.ajax({
+ type: "POST",
+ data: {type:"execute", code:code},
+ success: function(json, status, request) {
+ if (json != null) {
+ exec_count = json.content.execution_count
+ if (typeof(postfunc) != "undefined")
+ postfunc(json)
+ if (json.content.payload.length > 0 &&
+ json.content.payload[0]['format'] == "svg") {
+ var svg = document.createElement('object')
+ svg.setAttribute('class', "inlinesvg")
+ svg.setAttribute('type', 'image/svg+xml')
+ svg.setAttribute('data', 'data:image/svg+xml,'+
+ json.content.payload[0]['data'])
+ manager.get(json.parent_header.msg_id).setOutput(svg)
+ manager.get(json.parent_header.msg_id).setOutput("<br />")
+ }
+ //Open a new input object
+ manager.get().activate()
+ }
+ }
+ })
+}
+
+function complete() {
+
+}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 990adfc

Please sign in to comment.