Skip to content

Commit

Permalink
Refactor static printing.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanv committed Aug 18, 2011
1 parent 1e86624 commit 968e3fe
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 33 deletions.
18 changes: 0 additions & 18 deletions IPython/frontend/html/notebook/static/js/notebook.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -762,24 +762,6 @@ var IPython = (function (IPython) {
}; };
}; };


Notebook.prototype.publish_notebook = function () {
var w = window.open('', '_blank', 'scrollbars=1,menubar=1');
var html = '<html><head>' +
$('head').clone().html() +
'<style type="text/css">' +
'@media print { body { overflow: visible !important; } }' +
'.ui-widget-content { border: 0px; }' +
'</style>' +
'</head><body style="overflow: auto;">' +
$('#notebook').clone().html() +
'</body></html>';

w.document.open();
w.document.write(html);
w.document.close();

return false;
};


Notebook.prototype.notebook_saved = function (data, status, xhr) { Notebook.prototype.notebook_saved = function (data, status, xhr) {
this.dirty = false; this.dirty = false;
Expand Down
1 change: 1 addition & 0 deletions IPython/frontend/html/notebook/static/js/notebook_main.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $(document).ready(function () {
IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter'); IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
IPython.left_panel = new IPython.LeftPanel('div#left_panel', 'div#left_panel_splitter'); IPython.left_panel = new IPython.LeftPanel('div#left_panel', 'div#left_panel_splitter');
IPython.save_widget = new IPython.SaveWidget('span#save_widget'); IPython.save_widget = new IPython.SaveWidget('span#save_widget');
IPython.print_widget = new IPython.PrintWidget('span#print_widget');
IPython.notebook = new IPython.Notebook('div#notebook'); IPython.notebook = new IPython.Notebook('div#notebook');
IPython.kernel_status_widget = new IPython.KernelStatusWidget('#kernel_status'); IPython.kernel_status_widget = new IPython.KernelStatusWidget('#kernel_status');
IPython.kernel_status_widget.status_idle(); IPython.kernel_status_widget.status_idle();
Expand Down
54 changes: 54 additions & 0 deletions IPython/frontend/html/notebook/static/js/printwidget.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,54 @@
var IPython = (function (IPython) {

var PrintWidget = function (selector) {
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
this.bind_events();
}
};

PrintWidget.prototype.style = function () {
this.element.find('button#print_notebook').button();
};

PrintWidget.prototype.bind_events = function () {
var that = this;
this.element.find('button#print_notebook').click(function () {
that.print_notebook();
});
};

PrintWidget.prototype.enable = function () {
this.element.find('button#print_notebook').button('enable');
};

PrintWidget.prototype.disable = function () {
this.element.find('button#print_notebook').button('disable');
};

PrintWidget.prototype.print_notebook = function () {
var w = window.open('', '_blank', 'scrollbars=1,menubar=1');
var html = '<html><head>' +
$('head').clone().html() +
'<style type="text/css">' +
'@media print { body { overflow: visible !important; } }' +
'.ui-widget-content { border: 0px; }' +
'</style>' +
'</head><body style="overflow: auto;">' +
$('#notebook').clone().html() +
'</body></html>';

w.document.open();
w.document.write(html);
w.document.close();

return false;
};

IPython.PrintWidget = PrintWidget;

return IPython;

}(IPython));
23 changes: 9 additions & 14 deletions IPython/frontend/html/notebook/static/js/savewidget.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var IPython = (function (IPython) {
SaveWidget.prototype.style = function () { SaveWidget.prototype.style = function () {
this.element.find('input#notebook_name').addClass('ui-widget ui-widget-content'); this.element.find('input#notebook_name').addClass('ui-widget ui-widget-content');
this.element.find('button#save_notebook').button(); this.element.find('button#save_notebook').button();
this.element.find('button#publish_notebook').button();
var left_panel_width = $('div#left_panel').outerWidth(); var left_panel_width = $('div#left_panel').outerWidth();
var left_panel_splitter_width = $('div#left_panel_splitter').outerWidth(); var left_panel_splitter_width = $('div#left_panel_splitter').outerWidth();
$('span#save_widget').css({marginLeft:left_panel_width+left_panel_splitter_width}); $('span#save_widget').css({marginLeft:left_panel_width+left_panel_splitter_width});
Expand All @@ -34,10 +33,6 @@ var IPython = (function (IPython) {
IPython.notebook.save_notebook(); IPython.notebook.save_notebook();
that.set_document_title(); that.set_document_title();
}); });

this.element.find('button#publish_notebook').click(function () {
IPython.notebook.publish_notebook();
});
}; };




Expand Down Expand Up @@ -89,23 +84,23 @@ var IPython = (function (IPython) {




SaveWidget.prototype.status_save = function () { SaveWidget.prototype.status_save = function () {
$('button#save_notebook').button('option', 'label', 'Save'); this.element.find('button#save_notebook').button('option', 'label', 'Save');
$('button#save_notebook').button('enable'); this.element.find('button#save_notebook').button('enable');
$('button#publish_notebook').button('enable'); IPython.print_widget.enable();
}; };




SaveWidget.prototype.status_saving = function () { SaveWidget.prototype.status_saving = function () {
$('button#save_notebook').button('option', 'label', 'Saving'); this.element.find('button#save_notebook').button('option', 'label', 'Saving');
$('button#save_notebook').button('disable'); this.element.find('button#save_notebook').button('disable');
$('button#publish_notebook').button('disable'); IPython.print_widget.disable();
}; };




SaveWidget.prototype.status_loading = function () { SaveWidget.prototype.status_loading = function () {
$('button#save_notebook').button('option', 'label', 'Loading'); this.element.find('button#save_notebook').button('option', 'label', 'Loading');
$('button#save_notebook').button('disable'); this.element.find('button#save_notebook').button('disable');
$('button#publish_notebook').button('disable'); IPython.print_widget.disable();
}; };




Expand Down
6 changes: 5 additions & 1 deletion IPython/frontend/html/notebook/templates/notebook.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<input type="text" id="notebook_name" size="20"></textarea> <input type="text" id="notebook_name" size="20"></textarea>
<span id="notebook_id" style="display:none">{{notebook_id}}</span> <span id="notebook_id" style="display:none">{{notebook_id}}</span>
<button id="save_notebook">Save</button> <button id="save_notebook">Save</button>
<button id="publish_notebook">Publish</button>
</span> </span>
<span id="kernel_status">Idle</span> <span id="kernel_status">Idle</span>
</div> </div>
Expand Down Expand Up @@ -69,6 +68,10 @@ <h3 class="section_header">Notebook</h3>
</select> </select>
</span> </span>
<span class="section_row_buttons"> <span class="section_row_buttons">
<span id="print_widget">
<button id="print_notebook">Print/HTML</button>
</span>

<button id="download_notebook">Export</button> <button id="download_notebook">Export</button>
</span> </span>
</div> </div>
Expand Down Expand Up @@ -213,6 +216,7 @@ <h3 class="section_header">Help</h3>
<script src="static/js/savewidget.js" type="text/javascript" charset="utf-8"></script> <script src="static/js/savewidget.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/pager.js" type="text/javascript" charset="utf-8"></script> <script src="static/js/pager.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/panelsection.js" type="text/javascript" charset="utf-8"></script> <script src="static/js/panelsection.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/printwidget.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/leftpanel.js" type="text/javascript" charset="utf-8"></script> <script src="static/js/leftpanel.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script> <script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script>
<script src="static/js/notebook_main.js" type="text/javascript" charset="utf-8"></script> <script src="static/js/notebook_main.js" type="text/javascript" charset="utf-8"></script>
Expand Down

0 comments on commit 968e3fe

Please sign in to comment.