From fafb84e83c9207660410a3baa9110e3ecac523a0 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Sun, 26 May 2013 21:38:25 +0200 Subject: [PATCH 1/3] Inject requirejs in notebook and start using it. --- .../html/notebook/static/notebook/js/main.js | 26 ++++++++++++++----- .../html/notebook/templates/notebook.html | 2 -- .../html/notebook/templates/page.html | 7 ++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/IPython/frontend/html/notebook/static/notebook/js/main.js b/IPython/frontend/html/notebook/static/notebook/js/main.js index ae2123142..2ecb15107 100644 --- a/IPython/frontend/html/notebook/static/notebook/js/main.js +++ b/IPython/frontend/html/notebook/static/notebook/js/main.js @@ -8,17 +8,30 @@ //============================================================================ // On document ready //============================================================================ +"use strict"; +// for the time beeing, we have to pass marked as a parameter here, +// as injecting require.js make marked not to put itself in the globals, +// which make both this file fail at setting marked configuration, and textcell.js +// which search marked into global. +require(['static/components/marked/lib/marked.js', + 'static/notebook/js/config.js'], -$(document).ready(function () { +function (marked, config) { + IPython.config = config; + console.log('config is',config); + + window.marked = marked // monkey patch CM to be able to syntax highlight cell magics // bug reported upstream, // see https://github.com/marijnh/CodeMirror2/issues/670 if(CodeMirror.getMode(1,'text/plain').indent == undefined ){ console.log('patching CM for undefined indent'); - CodeMirror.modes.null = function() { return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}}} + CodeMirror.modes.null = function() { + return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}} } + } CodeMirror.patchedGetMode = function(config, mode){ var cmmode = CodeMirror.getMode(config, mode); @@ -90,10 +103,11 @@ $(document).ready(function () { // only do this once $([IPython.events]).off('notebook_loaded.Notebook', first_load); }; - + $([IPython.events]).on('notebook_loaded.Notebook', first_load); IPython.notebook.load_notebook($('body').data('notebookId')); - + + var marked; if (marked) { marked.setOptions({ gfm : true, @@ -110,6 +124,6 @@ $(document).ready(function () { } }) } +} -}); - +); diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index f5339bd58..e171aff16 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -205,7 +205,6 @@ class="notebook_app" - @@ -231,7 +230,6 @@ class="notebook_app" - diff --git a/IPython/frontend/html/notebook/templates/page.html b/IPython/frontend/html/notebook/templates/page.html index e9354dd6e..27857dcd5 100644 --- a/IPython/frontend/html/notebook/templates/page.html +++ b/IPython/frontend/html/notebook/templates/page.html @@ -24,7 +24,12 @@ {% endblock %} {% endblock %} - + + {% block meta %} {% endblock %} From 66ff7dde481317f87b222db1b26d1a16acfb242f Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Tue, 4 Jun 2013 10:09:18 +0200 Subject: [PATCH 2/3] de-require-config --- .../frontend/html/notebook/static/notebook/js/main.js | 10 +++------- IPython/frontend/html/notebook/templates/notebook.html | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/IPython/frontend/html/notebook/static/notebook/js/main.js b/IPython/frontend/html/notebook/static/notebook/js/main.js index 2ecb15107..8c21b3a11 100644 --- a/IPython/frontend/html/notebook/static/notebook/js/main.js +++ b/IPython/frontend/html/notebook/static/notebook/js/main.js @@ -14,15 +14,12 @@ // as injecting require.js make marked not to put itself in the globals, // which make both this file fail at setting marked configuration, and textcell.js // which search marked into global. -require(['static/components/marked/lib/marked.js', - 'static/notebook/js/config.js'], +require(['static/components/marked/lib/marked.js'], -function (marked, config) { - - IPython.config = config; - console.log('config is',config); +function (marked) { window.marked = marked + // monkey patch CM to be able to syntax highlight cell magics // bug reported upstream, // see https://github.com/marijnh/CodeMirror2/issues/670 @@ -107,7 +104,6 @@ function (marked, config) { $([IPython.events]).on('notebook_loaded.Notebook', first_load); IPython.notebook.load_notebook($('body').data('notebookId')); - var marked; if (marked) { marked.setOptions({ gfm : true, diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index e171aff16..80b53a6f6 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -230,6 +230,7 @@ class="notebook_app" + From 9f229a8e1cc4f6693464cb60f5e31a5d1c4ab0bb Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Tue, 4 Jun 2013 20:47:38 +0200 Subject: [PATCH 3/3] Use {{static_url}} as require search root --- IPython/frontend/html/notebook/static/notebook/js/main.js | 2 +- IPython/frontend/html/notebook/templates/page.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/html/notebook/static/notebook/js/main.js b/IPython/frontend/html/notebook/static/notebook/js/main.js index 8c21b3a11..0024d6ce1 100644 --- a/IPython/frontend/html/notebook/static/notebook/js/main.js +++ b/IPython/frontend/html/notebook/static/notebook/js/main.js @@ -14,7 +14,7 @@ // as injecting require.js make marked not to put itself in the globals, // which make both this file fail at setting marked configuration, and textcell.js // which search marked into global. -require(['static/components/marked/lib/marked.js'], +require(['components/marked/lib/marked'], function (marked) { diff --git a/IPython/frontend/html/notebook/templates/page.html b/IPython/frontend/html/notebook/templates/page.html index 27857dcd5..b92027b5f 100644 --- a/IPython/frontend/html/notebook/templates/page.html +++ b/IPython/frontend/html/notebook/templates/page.html @@ -27,7 +27,7 @@