Show More
@@ -600,14 +600,7 b' define([' | |||||
600 | } |
|
600 | } | |
601 | this.set_input_prompt(data.execution_count); |
|
601 | this.set_input_prompt(data.execution_count); | |
602 | this.output_area.trusted = data.metadata.trusted || false; |
|
602 | this.output_area.trusted = data.metadata.trusted || false; | |
603 | this.output_area.fromJSON(data.outputs); |
|
603 | this.output_area.fromJSON(data.outputs, data.metadata); | |
604 | if (data.metadata.collapsed !== undefined) { |
|
|||
605 | if (data.metadata.collapsed) { |
|
|||
606 | this.collapse_output(); |
|
|||
607 | } else { |
|
|||
608 | this.expand_output(); |
|
|||
609 | } |
|
|||
610 | } |
|
|||
611 | } |
|
604 | } | |
612 | }; |
|
605 | }; | |
613 |
|
606 | |||
@@ -625,6 +618,11 b' define([' | |||||
625 | data.outputs = outputs; |
|
618 | data.outputs = outputs; | |
626 | data.metadata.trusted = this.output_area.trusted; |
|
619 | data.metadata.trusted = this.output_area.trusted; | |
627 | data.metadata.collapsed = this.output_area.collapsed; |
|
620 | data.metadata.collapsed = this.output_area.collapsed; | |
|
621 | if (this.output_area.scroll_state === 'auto') { | |||
|
622 | delete data.metadata.scrolled; | |||
|
623 | } else { | |||
|
624 | data.metadata.scrolled = this.output_area.scroll_state; | |||
|
625 | } | |||
628 | return data; |
|
626 | return data; | |
629 | }; |
|
627 | }; | |
630 |
|
628 |
@@ -26,6 +26,7 b' define([' | |||||
26 | this.outputs = []; |
|
26 | this.outputs = []; | |
27 | this.collapsed = false; |
|
27 | this.collapsed = false; | |
28 | this.scrolled = false; |
|
28 | this.scrolled = false; | |
|
29 | this.scroll_state = 'auto'; | |||
29 | this.trusted = true; |
|
30 | this.trusted = true; | |
30 | this.clear_queued = null; |
|
31 | this.clear_queued = null; | |
31 | if (options.prompt_area === undefined) { |
|
32 | if (options.prompt_area === undefined) { | |
@@ -72,24 +73,28 b' define([' | |||||
72 |
|
73 | |||
73 | /** |
|
74 | /** | |
74 | * Should the OutputArea scroll? |
|
75 | * Should the OutputArea scroll? | |
75 |
* Returns whether the height (in lines) exceeds |
|
76 | * Returns whether the height (in lines) exceeds the current threshold. | |
76 | * |
|
77 | * Threshold will be OutputArea.minimum_scroll_threshold if scroll_state=true (manually requested) | |
77 | * @private |
|
78 | * or OutputArea.auto_scroll_threshold if scroll_state='auto'. | |
78 | * @method _should_scroll |
|
79 | * This will always return false if scroll_state=false (scroll disabled). | |
79 | * @param [lines=100]{Integer} |
|
|||
80 | * @return {Bool} |
|
|||
81 | * |
|
80 | * | |
82 | */ |
|
81 | */ | |
83 |
OutputArea.prototype._should_scroll = function ( |
|
82 | OutputArea.prototype._should_scroll = function () { | |
84 | if (lines <=0 ){ return; } |
|
83 | var threshold; | |
85 | if (!lines) { |
|
84 | if (this.scroll_state === false) { | |
86 |
|
|
85 | return false; | |
|
86 | } else if (this.scroll_state === true) { | |||
|
87 | threshold = OutputArea.minimum_scroll_threshold; | |||
|
88 | } else { | |||
|
89 | threshold = OutputArea.auto_scroll_threshold; | |||
|
90 | } | |||
|
91 | if (threshold <=0) { | |||
|
92 | return false; | |||
87 | } |
|
93 | } | |
88 | // line-height from http://stackoverflow.com/questions/1185151 |
|
94 | // line-height from http://stackoverflow.com/questions/1185151 | |
89 | var fontSize = this.element.css('font-size'); |
|
95 | var fontSize = this.element.css('font-size'); | |
90 | var lineHeight = Math.floor(parseInt(fontSize.replace('px','')) * 1.5); |
|
96 | var lineHeight = Math.floor(parseInt(fontSize.replace('px','')) * 1.5); | |
91 |
|
97 | return (this.element.height() > threshold * lineHeight); | ||
92 | return (this.element.height() > lines * lineHeight); |
|
|||
93 | }; |
|
98 | }; | |
94 |
|
99 | |||
95 |
|
100 | |||
@@ -105,7 +110,7 b' define([' | |||||
105 | } |
|
110 | } | |
106 | // maybe scroll output, |
|
111 | // maybe scroll output, | |
107 | // if it's grown large enough and hasn't already been scrolled. |
|
112 | // if it's grown large enough and hasn't already been scrolled. | |
108 |
if ( |
|
113 | if (!that.scrolled && that._should_scroll()) { | |
109 | that.scroll_area(); |
|
114 | that.scroll_area(); | |
110 | } |
|
115 | } | |
111 | }); |
|
116 | }); | |
@@ -123,6 +128,8 b' define([' | |||||
123 | this.collapse_button.show(); |
|
128 | this.collapse_button.show(); | |
124 | } |
|
129 | } | |
125 | this.collapsed = true; |
|
130 | this.collapsed = true; | |
|
131 | // collapsing output clears scroll state | |||
|
132 | this.scroll_state = 'auto'; | |||
126 | } |
|
133 | } | |
127 | }; |
|
134 | }; | |
128 |
|
135 | |||
@@ -133,6 +140,7 b' define([' | |||||
133 | this.element.show(); |
|
140 | this.element.show(); | |
134 | this.prompt_overlay.show(); |
|
141 | this.prompt_overlay.show(); | |
135 | this.collapsed = false; |
|
142 | this.collapsed = false; | |
|
143 | this.scroll_if_long(); | |||
136 | } |
|
144 | } | |
137 | }; |
|
145 | }; | |
138 |
|
146 | |||
@@ -160,34 +168,30 b' define([' | |||||
160 | }; |
|
168 | }; | |
161 |
|
169 | |||
162 | /** |
|
170 | /** | |
|
171 | * Scroll OutputArea if height exceeds a threshold. | |||
163 | * |
|
172 | * | |
164 | * Scroll OutputArea if height supperior than a threshold (in lines). |
|
173 | * Threshold is OutputArea.minimum_scroll_threshold if scroll_state = true, | |
165 | * |
|
174 | * OutputArea.auto_scroll_threshold if scroll_state='auto'. | |
166 | * Threshold is a maximum number of lines. If unspecified, defaults to |
|
|||
167 | * OutputArea.minimum_scroll_threshold. |
|
|||
168 | * |
|
|||
169 | * Negative threshold will prevent the OutputArea from ever scrolling. |
|
|||
170 | * |
|
|||
171 | * @method scroll_if_long |
|
|||
172 | * |
|
|||
173 | * @param [lines=20]{Number} Default to 20 if not set, |
|
|||
174 | * behavior undefined for value of `0`. |
|
|||
175 | * |
|
175 | * | |
176 | **/ |
|
176 | **/ | |
177 |
OutputArea.prototype.scroll_if_long = function ( |
|
177 | OutputArea.prototype.scroll_if_long = function () { | |
178 | var n = lines || OutputArea.minimum_scroll_threshold; |
|
178 | var should_scroll = this._should_scroll(); | |
179 | if(n <= 0){ |
|
179 | if (!this.scrolled && should_scroll) { | |
180 | return; |
|
|||
181 | } |
|
|||
182 |
|
||||
183 | if (this._should_scroll(n)) { |
|
|||
184 | // only allow scrolling long-enough output |
|
180 | // only allow scrolling long-enough output | |
185 | this.scroll_area(); |
|
181 | this.scroll_area(); | |
|
182 | } else if (this.scrolled && !should_scroll) { | |||
|
183 | // scrolled and shouldn't be | |||
|
184 | this.unscroll_area(); | |||
186 | } |
|
185 | } | |
187 | }; |
|
186 | }; | |
188 |
|
187 | |||
189 |
|
188 | |||
190 | OutputArea.prototype.toggle_scroll = function () { |
|
189 | OutputArea.prototype.toggle_scroll = function () { | |
|
190 | if (this.scroll_state == 'auto') { | |||
|
191 | this.scroll_state = !this.scrolled; | |||
|
192 | } else { | |||
|
193 | this.scroll_state = !this.scroll_state; | |||
|
194 | } | |||
191 | if (this.scrolled) { |
|
195 | if (this.scrolled) { | |
192 | this.unscroll_area(); |
|
196 | this.unscroll_area(); | |
193 | } else { |
|
197 | } else { | |
@@ -515,7 +519,7 b' define([' | |||||
515 | .attr("href", "#") |
|
519 | .attr("href", "#") | |
516 | .text("Unrecognized output: " + json.output_type) |
|
520 | .text("Unrecognized output: " + json.output_type) | |
517 | .click(function () { |
|
521 | .click(function () { | |
518 | that.events.trigger('unrecognized_output.OutputArea', {output: json}) |
|
522 | that.events.trigger('unrecognized_output.OutputArea', {output: json}); | |
519 | }) |
|
523 | }) | |
520 | ); |
|
524 | ); | |
521 | this._safe_append(toinsert); |
|
525 | this._safe_append(toinsert); | |
@@ -903,19 +907,18 b' define([' | |||||
903 | for (var i=0; i<len; i++) { |
|
907 | for (var i=0; i<len; i++) { | |
904 | this.append_output(outputs[i]); |
|
908 | this.append_output(outputs[i]); | |
905 | } |
|
909 | } | |
906 |
|
||||
907 | if (metadata.collapsed !== undefined) { |
|
910 | if (metadata.collapsed !== undefined) { | |
908 | this.collapsed = metadata.collapsed; |
|
911 | this.collapsed = metadata.collapsed; | |
909 | if (metadata.collapsed) { |
|
912 | if (metadata.collapsed) { | |
910 |
this.collapse |
|
913 | this.collapse(); | |
911 | } |
|
914 | } | |
912 | } |
|
915 | } | |
913 |
if (metadata. |
|
916 | if (metadata.scrolled !== undefined) { | |
914 |
this. |
|
917 | this.scroll_state = metadata.scrolled; | |
915 |
if (metadata.coll |
|
918 | if (metadata.scrolled) { | |
916 |
this. |
|
919 | this.scroll_if_long(); | |
917 | } else { |
|
920 | } else { | |
918 |
this. |
|
921 | this.unscroll_area(); | |
919 | } |
|
922 | } | |
920 | } |
|
923 | } | |
921 | }; |
|
924 | }; |
@@ -159,7 +159,7 b'' | |||||
159 | "description": "Whether the cell is collapsed/expanded.", |
|
159 | "description": "Whether the cell is collapsed/expanded.", | |
160 | "type": "boolean" |
|
160 | "type": "boolean" | |
161 | }, |
|
161 | }, | |
162 |
" |
|
162 | "scrolled": { | |
163 | "description": "Whether the cell's output is scrolled, unscrolled, or autoscrolled.", |
|
163 | "description": "Whether the cell's output is scrolled, unscrolled, or autoscrolled.", | |
164 | "enum": [true, false, "auto"] |
|
164 | "enum": [true, false, "auto"] | |
165 | }, |
|
165 | }, |
General Comments 0
You need to be logged in to leave comments.
Login now