##// END OF EJS Templates
get monospace pager back
Matthias BUSSONNIER -
Show More
@@ -1,166 +1,164 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2008-2011 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // Pager
10 10 //============================================================================
11 11
12 12 var IPython = (function (IPython) {
13 13
14 14 var utils = IPython.utils;
15 15
16 16 var Pager = function (pager_selector, pager_splitter_selector) {
17 17 this.pager_element = $(pager_selector);
18 18 this.pager_button_area = $('#pager_button_area');
19 19 var that = this;
20 20 this.percentage_height = 0.40;
21 21 this.pager_splitter_element = $(pager_splitter_selector)
22 22 .draggable({
23 23 containment: 'window',
24 24 axis:'y',
25 25 helper: null ,
26 26 drag: function(event, ui) {
27 27 // recalculate the amount of space the pager should take
28 28 var pheight = ($(body).height()-event.clientY-4);
29 29 var downprct = pheight/IPython.layout_manager.app_height();
30 30 downprct = Math.min(0.9, downprct);
31 31 if (downprct < 0.1) {
32 32 that.percentage_height = 0.1;
33 33 that.collapse({'duration':0});
34 34 } else if (downprct > 0.2) {
35 35 that.percentage_height = downprct;
36 36 that.expand({'duration':0});
37 37 }
38 38 IPython.layout_manager.do_resize();
39 39 }
40 40 });
41 41 this.expanded = false;
42 42 this.style();
43 43 this.create_button_area();
44 44 this.bind_events();
45 45 };
46 46
47 47 Pager.prototype.create_button_area = function(){
48 48 var that = this;
49 49 this.pager_button_area.append(
50 50 $('<a>').attr('role', "button")
51 51 .attr('title',"open the pager in an external window")
52 52 .addClass('ui-button')
53 53 .click(function(){that.detach()})
54 54 .attr('style','position: absolute; right: 10px;')
55 55 .append(
56 56 $('<span>').addClass("ui-icon ui-icon-extlink")
57 57 )
58 58 )
59 59 };
60 60
61 61 Pager.prototype.style = function () {
62 62 this.pager_splitter_element.addClass('border-box-sizing ui-widget ui-state-default');
63 63 this.pager_element.addClass('border-box-sizing ui-widget');
64 64 this.pager_splitter_element.attr('title', 'Click to Show/Hide pager area, drag to Resize');
65 65 };
66 66
67 67
68 68 Pager.prototype.bind_events = function () {
69 69 var that = this;
70 70
71 71 this.pager_element.bind('collapse_pager', function (event, extrap) {
72 72 var time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast';
73 73 that.pager_element.hide(time);
74 74 });
75 75
76 76 this.pager_element.bind('expand_pager', function (event, extrap) {
77 77 var time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast';
78 78 that.pager_element.show(time);
79 79 });
80 80
81 81 this.pager_splitter_element.hover(
82 82 function () {
83 83 that.pager_splitter_element.addClass('ui-state-hover');
84 84 },
85 85 function () {
86 86 that.pager_splitter_element.removeClass('ui-state-hover');
87 87 }
88 88 );
89 89
90 90 this.pager_splitter_element.click(function () {
91 91 that.toggle();
92 92 });
93 93
94 94 $([IPython.events]).on('open_with_text.Pager', function (event, data) {
95 95 if (data.text.trim() !== '') {
96 96 that.clear();
97 97 that.expand();
98 98 that.append_text(data.text);
99 99 };
100 100 });
101 101 };
102 102
103 103
104 104 Pager.prototype.collapse = function (extrap) {
105 105 if (this.expanded === true) {
106 106 this.expanded = false;
107 107 this.pager_element.add($('div#notebook')).trigger('collapse_pager', extrap);
108 108 };
109 109 };
110 110
111 111
112 112 Pager.prototype.expand = function (extrap) {
113 113 if (this.expanded !== true) {
114 114 this.expanded = true;
115 115 this.pager_element.add($('div#notebook')).trigger('expand_pager', extrap);
116 116 };
117 117 };
118 118
119 119
120 120 Pager.prototype.toggle = function () {
121 121 if (this.expanded === true) {
122 122 this.collapse();
123 123 } else {
124 124 this.expand();
125 125 };
126 126 };
127 127
128 128
129 129 Pager.prototype.clear = function (text) {
130 130 this.pager_element.empty();
131 131 };
132 132
133 133 Pager.prototype.detach = function(){
134 134 var w = window.open("","_blank")
135 135 $(w.document.head)
136 136 .append(
137 137 $('<link>')
138 138 .attr('rel',"stylesheet")
139 139 .attr('href',"/static/css/notebook.css")
140 140 .attr('type',"text/css")
141 141 )
142 142 .append(
143 143 $('<title>').text("IPython Pager")
144 144 );
145 145 var pager_body = $(w.document.body)
146 146 pager_body.attr('style','overflow:scroll');
147 147
148 148 pager_body.append(this.pager_element.children())
149 149 w.document.close();
150 150 this.collapse();
151 151
152 152 }
153 153
154 154 Pager.prototype.append_text = function (text) {
155 var toinsert = $("<div/>").addClass("output_area output_stream");
156 toinsert.append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
157 this.pager_element.append(toinsert);
155 this.pager_element.append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
158 156 };
159 157
160 158
161 159 IPython.Pager = Pager;
162 160
163 161 return IPython;
164 162
165 163 }(IPython));
166 164
General Comments 0
You need to be logged in to leave comments. Login now