##// END OF EJS Templates
third attempt at scrolled long output...
MinRK -
Show More
@@ -100,7 +100,7 b' div#notebook {'
100 width: 100%;
100 width: 100%;
101 /* This spaces the cell away from the edge of the notebook area */
101 /* This spaces the cell away from the edge of the notebook area */
102 padding: 5px 5px 15px 5px;
102 padding: 5px 5px 15px 5px;
103 margin: 0px
103 margin: 0px;
104 background-color: white;
104 background-color: white;
105 }
105 }
106
106
@@ -133,6 +133,7 b' div.cell {'
133 div.code_cell {
133 div.code_cell {
134 background-color: white;
134 background-color: white;
135 }
135 }
136
136 /* any special styling for code cells that are currently running goes here */
137 /* any special styling for code cells that are currently running goes here */
137 div.code_cell.running {
138 div.code_cell.running {
138 }
139 }
@@ -164,13 +165,50 b' div.input_prompt {'
164 border-top: 1px solid transparent;
165 border-top: 1px solid transparent;
165 }
166 }
166
167
167 div.output {
168 div.output_wrapper {
168 /* This is a spacer between the input and output of each cell */
169 /* This is a spacer between the input and output of each cell */
169 margin-top: 5px;
170 margin-top: 5px;
171 margin-left: 5px;
172 /* FF needs explicit width to stretch */
173 width: 100%;
174 /* this position must be relative to enable descendents to be absolute within it */
175 position: relative;
176 }
177
178 /* class for the output area when it should be height-limited */
179 div.output_scroll {
180 /* ideally, this would be max-height, but FF barfs all over that */
181 height: 24em;
182 /* FF needs this *and the wrapper* to specify full width, or it will shrinkwrap */
183 width: 100%;
184
185 overflow: auto;
186 border-radius: 3px;
187 box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8);
188 }
189
190 /* output div while it is collapsed */
191 div.output_collapsed {
192 margin-right: 5px;
193 }
194
195 div.out_prompt_overlay {
196 height: 100%;
197 padding: 0px;
198 position: absolute;
199 border-radius: 3px;
200 }
201
202 div.out_prompt_overlay:hover {
203 /* use inner shadow to get border that is computed the same on WebKit/FF */
204 box-shadow: inset 0 0 1px #000;
205 background: rgba(200, 200, 255, 0.5);
170 }
206 }
171
207
172 div.output_prompt {
208 div.output_prompt {
173 color: darkred;
209 color: darkred;
210 /* 5px right shift to account for margin in parent container */
211 margin-left: 0 5px 0 -5px;
174 }
212 }
175
213
176 /* This class is the outer container of all output sections. */
214 /* This class is the outer container of all output sections. */
@@ -158,6 +158,15 b' var IPython = (function (IPython) {'
158 this.element.find('#toggle_output').click(function () {
158 this.element.find('#toggle_output').click(function () {
159 IPython.notebook.toggle_output();
159 IPython.notebook.toggle_output();
160 });
160 });
161 this.element.find('#collapse_all_output').click(function () {
162 IPython.notebook.collapse_all_output();
163 });
164 this.element.find('#scroll_all_output').click(function () {
165 IPython.notebook.scroll_all_output();
166 });
167 this.element.find('#expand_all_output').click(function () {
168 IPython.notebook.expand_all_output();
169 });
161 this.element.find('#clear_all_output').click(function () {
170 this.element.find('#clear_all_output').click(function () {
162 IPython.notebook.clear_all_output();
171 IPython.notebook.clear_all_output();
163 });
172 });
@@ -865,6 +865,47 b' var IPython = (function (IPython) {'
865 };
865 };
866
866
867
867
868 Notebook.prototype.collapse_all_output = function () {
869 var ncells = this.ncells();
870 var cells = this.get_cells();
871 for (var i=0; i<ncells; i++) {
872 if (cells[i] instanceof IPython.CodeCell) {
873 cells[i].output_area.collapse();
874 }
875 };
876 // this should not be set if the `collapse` key is removed from nbformat
877 this.dirty = true;
878 };
879
880
881 Notebook.prototype.scroll_all_output = function () {
882 var ncells = this.ncells();
883 var cells = this.get_cells();
884 for (var i=0; i<ncells; i++) {
885 if (cells[i] instanceof IPython.CodeCell) {
886 cells[i].output_area.expand();
887 cells[i].output_area.scroll_if_long(20);
888 }
889 };
890 // this should not be set if the `collapse` key is removed from nbformat
891 this.dirty = true;
892 };
893
894
895 Notebook.prototype.expand_all_output = function () {
896 var ncells = this.ncells();
897 var cells = this.get_cells();
898 for (var i=0; i<ncells; i++) {
899 if (cells[i] instanceof IPython.CodeCell) {
900 cells[i].output_area.expand();
901 cells[i].output_area.unscroll_area();
902 }
903 };
904 // this should not be set if the `collapse` key is removed from nbformat
905 this.dirty = true;
906 };
907
908
868 Notebook.prototype.clear_all_output = function () {
909 Notebook.prototype.clear_all_output = function () {
869 var ncells = this.ncells();
910 var ncells = this.ncells();
870 var cells = this.get_cells();
911 var cells = this.get_cells();
@@ -16,28 +16,92 b' var IPython = (function (IPython) {'
16
16
17 var OutputArea = function (selector, prompt_area) {
17 var OutputArea = function (selector, prompt_area) {
18 this.selector = selector;
18 this.selector = selector;
19 this.element = $(selector);
19 this.wrapper = $(selector);
20 this.outputs = [];
20 this.outputs = [];
21 this.collapsed = false;
21 this.collapsed = false;
22 this.scrolled = false;
22 this.clear_out_timeout = null;
23 this.clear_out_timeout = null;
23 if (prompt_area === undefined) {
24 if (prompt_area === undefined) {
24 this.prompt_area = true;
25 this.prompt_area = true;
25 } else {
26 } else {
26 this.prompt_area = prompt_area;
27 this.prompt_area = prompt_area;
27 };
28 };
29 this.create_elements();
28 this.style();
30 this.style();
31 this.bind_events();
32 };
33
34 OutputArea.prototype.create_elements = function () {
35 this.element = $("<div/>");
36 this.collapse_button = $("<div/>");
37 this.prompt_overlay = $("<div/>");
38 this.wrapper.append(this.prompt_overlay);
39 this.wrapper.append(this.element);
40 this.wrapper.append(this.collapse_button);
29 };
41 };
30
42
31
43
32 OutputArea.prototype.style = function () {
44 OutputArea.prototype.style = function () {
45 this.collapse_button.hide();
46 this.prompt_overlay.hide();
47
48 this.wrapper.addClass('output_wrapper');
33 this.element.addClass('output vbox');
49 this.element.addClass('output vbox');
50
51 this.collapse_button.button();
52 this.collapse_button.addClass('output_collapsed vbox');
53 this.collapse_button.attr('title', 'click to expand outout');
54 this.collapse_button.html('. . .');
55
56 this.prompt_overlay.addClass('out_prompt_overlay prompt');
57 this.prompt_overlay.attr('title', 'click to expand outout; dblclick to hide output');
58
34 this.collapse();
59 this.collapse();
35 };
60 };
36
61
37
62
63 OutputArea.prototype._should_scroll = function (lines) {
64 if (!lines) {
65 lines = 50;
66 }
67 // line-height from http://stackoverflow.com/questions/1185151
68 var fontSize = this.element.css('font-size');
69 var lineHeight = Math.floor(parseInt(fontSize.replace('px','')) * 1.5);
70
71 return (this.element.height() > lines * lineHeight);
72 };
73
74
75 OutputArea.prototype.bind_events = function () {
76 var that = this;
77 this.prompt_overlay.dblclick(function () { that.toggle_output(); });
78 this.prompt_overlay.click(function () { that.toggle_scroll(); });
79
80 this.element.resize(function () {
81 // maybe scroll output,
82 // if it's grown large enough and hasn't already been scrolled.
83 if ( !that.scrolled && that._should_scroll()) {
84 that.scroll_area();
85 }
86 });
87 this.collapse_button.click(function () {
88 that.expand();
89 });
90 this.collapse_button.hover(function () {
91 $(this).addClass("ui-state-hover");
92 }, function () {
93 $(this).removeClass("ui-state-hover");
94 });
95 };
96
97
38 OutputArea.prototype.collapse = function () {
98 OutputArea.prototype.collapse = function () {
39 if (!this.collapsed) {
99 if (!this.collapsed) {
40 this.element.hide();
100 this.element.hide();
101 this.prompt_overlay.hide();
102 if (this.element.html()){
103 this.collapse_button.show();
104 }
41 this.collapsed = true;
105 this.collapsed = true;
42 };
106 };
43 };
107 };
@@ -45,7 +109,9 b' var IPython = (function (IPython) {'
45
109
46 OutputArea.prototype.expand = function () {
110 OutputArea.prototype.expand = function () {
47 if (this.collapsed) {
111 if (this.collapsed) {
112 this.collapse_button.hide();
48 this.element.show();
113 this.element.show();
114 this.prompt_overlay.show();
49 this.collapsed = false;
115 this.collapsed = false;
50 };
116 };
51 };
117 };
@@ -60,6 +126,38 b' var IPython = (function (IPython) {'
60 };
126 };
61
127
62
128
129 OutputArea.prototype.scroll_area = function () {
130 this.element.addClass('output_scroll');
131 this.prompt_overlay.attr('title', 'click to unscroll output; dblclick to hide');
132 this.scrolled = true;
133 };
134
135
136 OutputArea.prototype.unscroll_area = function () {
137 this.element.removeClass('output_scroll');
138 this.prompt_overlay.attr('title', 'click to scroll output; dblclick to hide');
139 this.scrolled = false;
140 };
141
142
143 OutputArea.prototype.scroll_if_long = function (lines) {
144 if (this._should_scroll(lines)) {
145 // only allow scrolling long-enough output
146 this.scroll_area();
147 };
148 };
149
150
151 OutputArea.prototype.toggle_scroll = function () {
152 if (this.scrolled) {
153 this.unscroll_area();
154 } else {
155 // only allow scrolling long-enough output
156 this.scroll_if_long(20);
157 };
158 };
159
160
63 // typeset with MathJax if MathJax is available
161 // typeset with MathJax if MathJax is available
64 OutputArea.prototype.typeset = function () {
162 OutputArea.prototype.typeset = function () {
65 if (window.MathJax){
163 if (window.MathJax){
@@ -132,6 +230,8 b' var IPython = (function (IPython) {'
132 this.append_stream(json);
230 this.append_stream(json);
133 };
231 };
134 this.outputs.push(json);
232 this.outputs.push(json);
233 var that = this;
234 setTimeout(function(){that.element.trigger('resize');}, 100);
135 };
235 };
136
236
137
237
@@ -346,6 +446,7 b' var IPython = (function (IPython) {'
346 // clear all, no need for logic
446 // clear all, no need for logic
347 output_div.html("");
447 output_div.html("");
348 this.outputs = [];
448 this.outputs = [];
449 this.unscroll_area();
349 return;
450 return;
350 }
451 }
351 // remove html output
452 // remove html output
@@ -360,7 +461,8 b' var IPython = (function (IPython) {'
360 if (other) {
461 if (other) {
361 output_div.find("div.output_subarea").not("div.output_stderr").not("div.output_stdout").parent().remove();
462 output_div.find("div.output_subarea").not("div.output_stderr").not("div.output_stdout").parent().remove();
362 }
463 }
363
464 this.unscroll_area();
465
364 // remove cleared outputs from JSON list:
466 // remove cleared outputs from JSON list:
365 for (var i = this.outputs.length - 1; i >= 0; i--) {
467 for (var i = this.outputs.length - 1; i >= 0; i--) {
366 var out = this.outputs[i];
468 var out = this.outputs[i];
@@ -117,8 +117,15 b' data-notebook-id={{notebook_id}}'
117 <li id="to_heading5"><a href="#">Heading 5</a></li>
117 <li id="to_heading5"><a href="#">Heading 5</a></li>
118 <li id="to_heading6"><a href="#">Heading 6</a></li>
118 <li id="to_heading6"><a href="#">Heading 6</a></li>
119 <hr/>
119 <hr/>
120 <li id="toggle_output"><a href="#">Toggle Output</a></li>
120 <li id="toggle_output"><a href="#">Toggle Current Output</a></li>
121 <li id="clear_all_output"><a href="#">Clear All Output</a></li>
121 <li id="all_outputs"><a href="#">All Output</a>
122 <ul>
123 <li id="expand_all_output"><a href="#">Expand</a></li>
124 <li id="scroll_all_output"><a href="#">Scroll Long</a></li>
125 <li id="collapse_all_output"><a href="#">Collapse</a></li>
126 <li id="clear_all_output"><a href="#">Clear</a></li>
127 </ul>
128 </li>
122 </ul>
129 </ul>
123 </li>
130 </li>
124 <li><a href="#">Kernel</a>
131 <li><a href="#">Kernel</a>
General Comments 0
You need to be logged in to leave comments. Login now