-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
emit event on appended element on dom #4774
Changes from all commits
a17618e
0ea988b
d0c9476
8d44953
bac8c38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,12 @@ var IPython = (function (IPython) { | |
this.style(); | ||
this.bind_events(); | ||
}; | ||
|
||
|
||
|
||
/** | ||
* Class prototypes | ||
**/ | ||
|
||
OutputArea.prototype.create_elements = function () { | ||
this.element = $("<div/>"); | ||
this.collapse_button = $("<div/>"); | ||
|
@@ -158,33 +163,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 +232,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 +473,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) { | ||
|
||
|
@@ -533,7 +481,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,21 +496,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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I name it element to keep a constant naming in API, but I need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gotcha, thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a FIXME: mark for removal, then? |
||
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; | ||
}; | ||
|
||
|
||
|
@@ -577,6 +533,7 @@ var IPython = (function (IPython) { | |
} | ||
toinsert.append($("<pre/>").html(data)); | ||
element.append(toinsert); | ||
return toinsert; | ||
}; | ||
|
||
|
||
|
@@ -585,6 +542,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 +587,7 @@ var IPython = (function (IPython) { | |
this._dblclick_to_reset_size(img); | ||
toinsert.append(img); | ||
element.append(toinsert); | ||
return toinsert; | ||
}; | ||
|
||
|
||
|
@@ -645,6 +604,7 @@ var IPython = (function (IPython) { | |
this._dblclick_to_reset_size(img); | ||
toinsert.append(img); | ||
element.append(toinsert); | ||
return toinsert; | ||
}; | ||
|
||
|
||
|
@@ -655,18 +615,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; | ||
|
@@ -811,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; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* calling `container.show()` on javascript display is deprecated and will | ||
trigger errors on future IPython notebook versions. `container` now show | ||
itself as soon as non-empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this
toinsert
beelement
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or is there a missing
var insert = append...
in the line above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@minrk is right that one of these two things needs to be there as
toinsert
is not defined in scope.