From 9f2203340af414e65e147778e52c3643f3c93fff Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Mon, 13 Jan 2014 16:25:53 -0800 Subject: [PATCH 1/5] emit event when mimetype are append to output area. --- IPython/html/static/notebook/js/outputarea.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index 3e673521a..d881d35e2 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -533,7 +533,8 @@ var IPython = (function (IPython) { var append = OutputArea.append_map[type]; if ((json[type] !== undefined) && append) { var md = json.metadata || {}; - append.apply(this, [json[type], md, element]); + var toinsert = append.apply(this, [json[type], md, element]); + $([IPython.events]).trigger('output_appended.OutputArea', [type, json[type], md, toinsert]); return true; } } @@ -547,6 +548,7 @@ var IPython = (function (IPython) { IPython.keyboard_manager.register_events(toinsert); toinsert.append(html); element.append(toinsert); + return toinsert; }; @@ -562,6 +564,7 @@ var IPython = (function (IPython) { console.log(err); this._append_javascript_error(err, element); } + return container; }; @@ -577,6 +580,7 @@ var IPython = (function (IPython) { } toinsert.append($("
").html(data));
         element.append(toinsert);
+        return toinsert;
     };
 
 
@@ -585,6 +589,7 @@ var IPython = (function (IPython) {
         var toinsert = this.create_output_subarea(md, "output_svg", type);
         toinsert.append(svg);
         element.append(toinsert);
+        return toinsert;
     };
 
 
@@ -629,6 +634,7 @@ var IPython = (function (IPython) {
         this._dblclick_to_reset_size(img);
         toinsert.append(img);
         element.append(toinsert);
+        return toinsert;
     };
 
 
@@ -645,6 +651,7 @@ var IPython = (function (IPython) {
         this._dblclick_to_reset_size(img);
         toinsert.append(img);
         element.append(toinsert);
+        return toinsert;
     };
 
 
@@ -655,6 +662,7 @@ var IPython = (function (IPython) {
         var toinsert = this.create_output_subarea(md, "output_latex", type);
         toinsert.append(latex);
         element.append(toinsert);
+        return toinsert;
     };
 
     OutputArea.append_map = {

From aa5477beb7301ce834c8812c56e9a3131f79ee16 Mon Sep 17 00:00:00 2001
From: Matthias BUSSONNIER 
Date: Mon, 27 Jan 2014 21:26:34 +0100
Subject: [PATCH 2/5] fix Brian and Min comment

---
 IPython/html/static/notebook/js/outputarea.js | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js
index d881d35e2..ef1355fa6 100644
--- a/IPython/html/static/notebook/js/outputarea.js
+++ b/IPython/html/static/notebook/js/outputarea.js
@@ -552,19 +552,22 @@ var IPython = (function (IPython) {
     };
 
 
-    OutputArea.prototype.append_javascript = function (js, md, container) {
+    OutputArea.prototype.append_javascript = function (js, md, element) {
         // We just eval the JS code, element appears in the local scope.
         var type = 'application/javascript';
-        var element = this.create_output_subarea(md, "output_javascript", type);
-        IPython.keyboard_manager.register_events(element);
-        container.append(element);
+        var toinsert = this.create_output_subarea(md, "output_javascript", type);
+        IPython.keyboard_manager.register_events(toinsert);
+        element.append(toinsert);
+        //backward compat, js should be eval'ed in a context where `container` is defined.
+        var container = element;
+        container.show = function(){console.log('Warning "container.show()" is deprecated.')};
         try {
             eval(js);
         } catch(err) {
             console.log(err);
-            this._append_javascript_error(err, element);
+            this._append_javascript_error(err, toinsert);
         }
-        return container;
+        return toinsert;
     };
 
 

From 8c57e9e788bb56e584d07c1bb82a64050a6123ff Mon Sep 17 00:00:00 2001
From: Matthias BUSSONNIER 
Date: Wed, 29 Jan 2014 07:54:15 +0100
Subject: [PATCH 3/5] Fixme comment + whatsnew

---
 IPython/html/static/notebook/js/outputarea.js | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js
index ef1355fa6..817adc0eb 100644
--- a/IPython/html/static/notebook/js/outputarea.js
+++ b/IPython/html/static/notebook/js/outputarea.js
@@ -558,9 +558,11 @@ var IPython = (function (IPython) {
         var toinsert = this.create_output_subarea(md, "output_javascript", type);
         IPython.keyboard_manager.register_events(toinsert);
         element.append(toinsert);
+        // FIXME TODO : remove `container element for 3.0` 
         //backward compat, js should be eval'ed in a context where `container` is defined.
         var container = element;
         container.show = function(){console.log('Warning "container.show()" is deprecated.')};
+        // end backward compat
         try {
             eval(js);
         } catch(err) {

From 9d54212f17aba845badde39589e359817391f700 Mon Sep 17 00:00:00 2001
From: Matthias BUSSONNIER 
Date: Wed, 29 Jan 2014 08:13:26 +0100
Subject: [PATCH 4/5] reorder class properties

---
 IPython/html/static/notebook/js/outputarea.js | 147 ++++++++++--------
 1 file changed, 79 insertions(+), 68 deletions(-)

diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js
index 817adc0eb..b762b440a 100644
--- a/IPython/html/static/notebook/js/outputarea.js
+++ b/IPython/html/static/notebook/js/outputarea.js
@@ -41,7 +41,85 @@ var IPython = (function (IPython) {
         this.style();
         this.bind_events();
     };
-    
+
+    /**
+     * Class properties
+     **/
+
+    /**
+     * Threshold to trigger autoscroll when the OutputArea is resized,
+     * typically when new outputs are added.
+     *
+     * Behavior is undefined if autoscroll is lower than minimum_scroll_threshold,
+     * unless it is < 0, in which case autoscroll will never be triggered
+     *
+     * @property auto_scroll_threshold
+     * @type Number
+     * @default 100
+     *
+     **/
+    OutputArea.auto_scroll_threshold = 100;
+
+    /**
+     * Lower limit (in lines) for OutputArea to be made scrollable. OutputAreas
+     * shorter than this are never scrolled.
+     *
+     * @property minimum_scroll_threshold
+     * @type Number
+     * @default 20
+     *
+     **/
+    OutputArea.minimum_scroll_threshold = 20;
+
+
+
+    OutputArea.mime_map = {
+        "text/plain" : "text",
+        "text/html" : "html",
+        "image/svg+xml" : "svg",
+        "image/png" : "png",
+        "image/jpeg" : "jpeg",
+        "text/latex" : "latex",
+        "application/json" : "json",
+        "application/javascript" : "javascript",
+    };
+
+    OutputArea.mime_map_r = {
+        "text" : "text/plain",
+        "html" : "text/html",
+        "svg" : "image/svg+xml",
+        "png" : "image/png",
+        "jpeg" : "image/jpeg",
+        "latex" : "text/latex",
+        "json" : "application/json",
+        "javascript" : "application/javascript",
+    };
+
+    OutputArea.display_order = [
+        'application/javascript',
+        'text/html',
+        'text/latex',
+        'image/svg+xml',
+        'image/png',
+        'image/jpeg',
+        'text/plain'
+    ];
+
+    OutputArea.append_map = {
+        "text/plain" : OutputArea.prototype.append_text,
+        "text/html" : OutputArea.prototype.append_html,
+        "image/svg+xml" : OutputArea.prototype.append_svg,
+        "image/png" : OutputArea.prototype.append_png,
+        "image/jpeg" : OutputArea.prototype.append_jpeg,
+        "text/latex" : OutputArea.prototype.append_latex,
+        "application/json" : OutputArea.prototype.append_json,
+        "application/javascript" : OutputArea.prototype.append_javascript,
+    };
+
+    /**
+     * Class prototypes
+     **/
+
     OutputArea.prototype.create_elements = function () {
         this.element = $("
"); this.collapse_button = $("
"); @@ -158,33 +236,6 @@ var IPython = (function (IPython) { this.scrolled = false; }; - /** - * Threshold to trigger autoscroll when the OutputArea is resized, - * typically when new outputs are added. - * - * Behavior is undefined if autoscroll is lower than minimum_scroll_threshold, - * unless it is < 0, in which case autoscroll will never be triggered - * - * @property auto_scroll_threshold - * @type Number - * @default 100 - * - **/ - OutputArea.auto_scroll_threshold = 100; - - - /** - * Lower limit (in lines) for OutputArea to be made scrollable. OutputAreas - * shorter than this are never scrolled. - * - * @property minimum_scroll_threshold - * @type Number - * @default 20 - * - **/ - OutputArea.minimum_scroll_threshold = 20; - - /** * * Scroll OutputArea if height supperior than a threshold (in lines). @@ -254,28 +305,7 @@ var IPython = (function (IPython) { } this.append_output(json); }; - - OutputArea.mime_map = { - "text/plain" : "text", - "text/html" : "html", - "image/svg+xml" : "svg", - "image/png" : "png", - "image/jpeg" : "jpeg", - "text/latex" : "latex", - "application/json" : "json", - "application/javascript" : "javascript", - }; - OutputArea.mime_map_r = { - "text" : "text/plain", - "html" : "text/html", - "svg" : "image/svg+xml", - "png" : "image/png", - "jpeg" : "image/jpeg", - "latex" : "text/latex", - "json" : "application/json", - "javascript" : "application/javascript", - }; OutputArea.prototype.rename_keys = function (data, key_map) { var remapped = {}; @@ -516,15 +546,6 @@ var IPython = (function (IPython) { } }; - OutputArea.display_order = [ - 'application/javascript', - 'text/html', - 'text/latex', - 'image/svg+xml', - 'image/png', - 'image/jpeg', - 'text/plain' - ]; OutputArea.prototype.append_mime_type = function (json, element) { @@ -670,16 +691,6 @@ var IPython = (function (IPython) { return toinsert; }; - OutputArea.append_map = { - "text/plain" : OutputArea.prototype.append_text, - "text/html" : OutputArea.prototype.append_html, - "image/svg+xml" : OutputArea.prototype.append_svg, - "image/png" : OutputArea.prototype.append_png, - "image/jpeg" : OutputArea.prototype.append_jpeg, - "text/latex" : OutputArea.prototype.append_latex, - "application/json" : OutputArea.prototype.append_json, - "application/javascript" : OutputArea.prototype.append_javascript, - }; OutputArea.prototype.append_raw_input = function (msg) { var that = this; From 03b5e0b2e054f14697e98ed328b97248d99a20d9 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Sat, 1 Feb 2014 11:42:28 +0100 Subject: [PATCH 5/5] put OutputArea map at the end --- IPython/html/static/notebook/js/outputarea.js | 146 +++++++++--------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index b762b440a..a062c45bf 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -42,79 +42,6 @@ var IPython = (function (IPython) { this.bind_events(); }; - /** - * Class properties - **/ - - /** - * Threshold to trigger autoscroll when the OutputArea is resized, - * typically when new outputs are added. - * - * Behavior is undefined if autoscroll is lower than minimum_scroll_threshold, - * unless it is < 0, in which case autoscroll will never be triggered - * - * @property auto_scroll_threshold - * @type Number - * @default 100 - * - **/ - OutputArea.auto_scroll_threshold = 100; - - /** - * Lower limit (in lines) for OutputArea to be made scrollable. OutputAreas - * shorter than this are never scrolled. - * - * @property minimum_scroll_threshold - * @type Number - * @default 20 - * - **/ - OutputArea.minimum_scroll_threshold = 20; - - - - OutputArea.mime_map = { - "text/plain" : "text", - "text/html" : "html", - "image/svg+xml" : "svg", - "image/png" : "png", - "image/jpeg" : "jpeg", - "text/latex" : "latex", - "application/json" : "json", - "application/javascript" : "javascript", - }; - - OutputArea.mime_map_r = { - "text" : "text/plain", - "html" : "text/html", - "svg" : "image/svg+xml", - "png" : "image/png", - "jpeg" : "image/jpeg", - "latex" : "text/latex", - "json" : "application/json", - "javascript" : "application/javascript", - }; - - OutputArea.display_order = [ - 'application/javascript', - 'text/html', - 'text/latex', - 'image/svg+xml', - 'image/png', - 'image/jpeg', - 'text/plain' - ]; - - OutputArea.append_map = { - "text/plain" : OutputArea.prototype.append_text, - "text/html" : OutputArea.prototype.append_html, - "image/svg+xml" : OutputArea.prototype.append_svg, - "image/png" : OutputArea.prototype.append_png, - "image/jpeg" : OutputArea.prototype.append_jpeg, - "text/latex" : OutputArea.prototype.append_latex, - "application/json" : OutputArea.prototype.append_json, - "application/javascript" : OutputArea.prototype.append_javascript, - }; /** * Class prototypes @@ -835,6 +762,79 @@ var IPython = (function (IPython) { return outputs; }; + /** + * Class properties + **/ + + /** + * Threshold to trigger autoscroll when the OutputArea is resized, + * typically when new outputs are added. + * + * Behavior is undefined if autoscroll is lower than minimum_scroll_threshold, + * unless it is < 0, in which case autoscroll will never be triggered + * + * @property auto_scroll_threshold + * @type Number + * @default 100 + * + **/ + OutputArea.auto_scroll_threshold = 100; + + /** + * Lower limit (in lines) for OutputArea to be made scrollable. OutputAreas + * shorter than this are never scrolled. + * + * @property minimum_scroll_threshold + * @type Number + * @default 20 + * + **/ + OutputArea.minimum_scroll_threshold = 20; + + + + OutputArea.mime_map = { + "text/plain" : "text", + "text/html" : "html", + "image/svg+xml" : "svg", + "image/png" : "png", + "image/jpeg" : "jpeg", + "text/latex" : "latex", + "application/json" : "json", + "application/javascript" : "javascript", + }; + + OutputArea.mime_map_r = { + "text" : "text/plain", + "html" : "text/html", + "svg" : "image/svg+xml", + "png" : "image/png", + "jpeg" : "image/jpeg", + "latex" : "text/latex", + "json" : "application/json", + "javascript" : "application/javascript", + }; + + OutputArea.display_order = [ + 'application/javascript', + 'text/html', + 'text/latex', + 'image/svg+xml', + 'image/png', + 'image/jpeg', + 'text/plain' + ]; + + OutputArea.append_map = { + "text/plain" : OutputArea.prototype.append_text, + "text/html" : OutputArea.prototype.append_html, + "image/svg+xml" : OutputArea.prototype.append_svg, + "image/png" : OutputArea.prototype.append_png, + "image/jpeg" : OutputArea.prototype.append_jpeg, + "text/latex" : OutputArea.prototype.append_latex, + "application/json" : OutputArea.prototype.append_json, + "application/javascript" : OutputArea.prototype.append_javascript, + }; IPython.OutputArea = OutputArea;