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