Merge pull request #4774 from Carreau/emit-output

emit event on appended element on dom
This commit is contained in:
Min RK 2014-02-04 16:53:51 -08:00
commit a5feb922a3

View File

@ -42,7 +42,12 @@ var IPython = (function (IPython) {
this.style();
this.bind_events();
};
/**
* Class prototypes
**/
OutputArea.prototype.create_elements = function () {
this.element = $("<div/>");
this.collapse_button = $("<div/>");
@ -159,33 +164,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).
@ -255,28 +233,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 = {};
@ -518,15 +475,6 @@ var IPython = (function (IPython) {
}
};
OutputArea.display_order = [
'application/javascript',
'text/html',
'text/latex',
'image/svg+xml',
'image/png',
'image/jpeg',
'text/plain'
];
OutputArea.safe_outputs = {
'text/plain' : true,
@ -549,7 +497,8 @@ var IPython = (function (IPython) {
continue;
}
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;
}
}
@ -563,21 +512,28 @@ var IPython = (function (IPython) {
IPython.keyboard_manager.register_events(toinsert);
toinsert.append(html);
element.append(toinsert);
return toinsert;
};
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);
// 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) {
console.log(err);
this._append_javascript_error(err, element);
this._append_javascript_error(err, toinsert);
}
return toinsert;
};
@ -593,6 +549,7 @@ var IPython = (function (IPython) {
}
toinsert.append($("<pre/>").html(data));
element.append(toinsert);
return toinsert;
};
@ -601,6 +558,7 @@ var IPython = (function (IPython) {
var toinsert = this.create_output_subarea(md, "output_svg", type);
toinsert.append(svg);
element.append(toinsert);
return toinsert;
};
@ -646,6 +604,7 @@ var IPython = (function (IPython) {
this._dblclick_to_reset_size(img);
toinsert.append(img);
element.append(toinsert);
return toinsert;
};
@ -657,6 +616,7 @@ var IPython = (function (IPython) {
this._dblclick_to_reset_size(img);
toinsert.append(img);
element.append(toinsert);
return toinsert;
};
@ -667,18 +627,9 @@ 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 = {
"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;
@ -819,6 +770,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;