##// END OF EJS Templates
Merge pull request #7522 from minrk/store-scroll...
Matthias Bussonnier -
r20141:d0fbe137 merge
parent child Browse files
Show More
@@ -600,14 +600,7 b' define(['
600 600 }
601 601 this.set_input_prompt(data.execution_count);
602 602 this.output_area.trusted = data.metadata.trusted || false;
603 this.output_area.fromJSON(data.outputs);
604 if (data.metadata.collapsed !== undefined) {
605 if (data.metadata.collapsed) {
606 this.collapse_output();
607 } else {
608 this.expand_output();
609 }
610 }
603 this.output_area.fromJSON(data.outputs, data.metadata);
611 604 }
612 605 };
613 606
@@ -625,6 +618,11 b' define(['
625 618 data.outputs = outputs;
626 619 data.metadata.trusted = this.output_area.trusted;
627 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 626 return data;
629 627 };
630 628
@@ -26,6 +26,7 b' define(['
26 26 this.outputs = [];
27 27 this.collapsed = false;
28 28 this.scrolled = false;
29 this.scroll_state = 'auto';
29 30 this.trusted = true;
30 31 this.clear_queued = null;
31 32 if (options.prompt_area === undefined) {
@@ -72,24 +73,28 b' define(['
72 73
73 74 /**
74 75 * Should the OutputArea scroll?
75 * Returns whether the height (in lines) exceeds a threshold.
76 *
77 * @private
78 * @method _should_scroll
79 * @param [lines=100]{Integer}
80 * @return {Bool}
76 * Returns whether the height (in lines) exceeds the current threshold.
77 * Threshold will be OutputArea.minimum_scroll_threshold if scroll_state=true (manually requested)
78 * or OutputArea.auto_scroll_threshold if scroll_state='auto'.
79 * This will always return false if scroll_state=false (scroll disabled).
81 80 *
82 81 */
83 OutputArea.prototype._should_scroll = function (lines) {
84 if (lines <=0 ){ return; }
85 if (!lines) {
86 lines = 100;
82 OutputArea.prototype._should_scroll = function () {
83 var threshold;
84 if (this.scroll_state === false) {
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 94 // line-height from http://stackoverflow.com/questions/1185151
89 95 var fontSize = this.element.css('font-size');
90 96 var lineHeight = Math.floor(parseInt(fontSize.replace('px','')) * 1.5);
91
92 return (this.element.height() > lines * lineHeight);
97 return (this.element.height() > threshold * lineHeight);
93 98 };
94 99
95 100
@@ -105,7 +110,7 b' define(['
105 110 }
106 111 // maybe scroll output,
107 112 // if it's grown large enough and hasn't already been scrolled.
108 if ( !that.scrolled && that._should_scroll(OutputArea.auto_scroll_threshold)) {
113 if (!that.scrolled && that._should_scroll()) {
109 114 that.scroll_area();
110 115 }
111 116 });
@@ -123,6 +128,8 b' define(['
123 128 this.collapse_button.show();
124 129 }
125 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 140 this.element.show();
134 141 this.prompt_overlay.show();
135 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).
165 *
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`.
173 * Threshold is OutputArea.minimum_scroll_threshold if scroll_state = true,
174 * OutputArea.auto_scroll_threshold if scroll_state='auto'.
175 175 *
176 176 **/
177 OutputArea.prototype.scroll_if_long = function (lines) {
178 var n = lines || OutputArea.minimum_scroll_threshold;
179 if(n <= 0){
180 return;
181 }
182
183 if (this._should_scroll(n)) {
177 OutputArea.prototype.scroll_if_long = function () {
178 var should_scroll = this._should_scroll();
179 if (!this.scrolled && should_scroll) {
184 180 // only allow scrolling long-enough output
185 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 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 195 if (this.scrolled) {
192 196 this.unscroll_area();
193 197 } else {
@@ -515,7 +519,7 b' define(['
515 519 .attr("href", "#")
516 520 .text("Unrecognized output: " + json.output_type)
517 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 525 this._safe_append(toinsert);
@@ -903,19 +907,18 b' define(['
903 907 for (var i=0; i<len; i++) {
904 908 this.append_output(outputs[i]);
905 909 }
906
907 910 if (metadata.collapsed !== undefined) {
908 911 this.collapsed = metadata.collapsed;
909 912 if (metadata.collapsed) {
910 this.collapse_output();
913 this.collapse();
911 914 }
912 915 }
913 if (metadata.autoscroll !== undefined) {
914 this.collapsed = metadata.collapsed;
915 if (metadata.collapsed) {
916 this.collapse_output();
916 if (metadata.scrolled !== undefined) {
917 this.scroll_state = metadata.scrolled;
918 if (metadata.scrolled) {
919 this.scroll_if_long();
917 920 } else {
918 this.expand_output();
921 this.unscroll_area();
919 922 }
920 923 }
921 924 };
@@ -159,7 +159,7 b''
159 159 "description": "Whether the cell is collapsed/expanded.",
160 160 "type": "boolean"
161 161 },
162 "autoscroll": {
162 "scrolled": {
163 163 "description": "Whether the cell's output is scrolled, unscrolled, or autoscrolled.",
164 164 "enum": [true, false, "auto"]
165 165 },
General Comments 0
You need to be logged in to leave comments. Login now