##// END OF EJS Templates
Merge pull request #7470 from minrk/pager-straight-down...
Matthias Bussonnier -
r19943:06667e1d merge
parent child Browse files
Show More
@@ -1,164 +1,169 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 define([
4 define([
5 'base/js/namespace',
5 'base/js/namespace',
6 'jqueryui',
6 'jqueryui',
7 'base/js/utils',
7 'base/js/utils',
8 ], function(IPython, $, utils) {
8 ], function(IPython, $, utils) {
9 "use strict";
9 "use strict";
10
10
11 var Pager = function (pager_selector, options) {
11 var Pager = function (pager_selector, options) {
12 /**
12 /**
13 * Constructor
13 * Constructor
14 *
14 *
15 * Parameters:
15 * Parameters:
16 * pager_selector: string
16 * pager_selector: string
17 * options: dictionary
17 * options: dictionary
18 * Dictionary of keyword arguments.
18 * Dictionary of keyword arguments.
19 * events: $(Events) instance
19 * events: $(Events) instance
20 */
20 */
21 this.events = options.events;
21 this.events = options.events;
22 this.pager_element = $(pager_selector);
22 this.pager_element = $(pager_selector);
23 this.pager_button_area = $('#pager-button-area');
23 this.pager_button_area = $('#pager-button-area');
24 this._default_end_space = 100;
24 this._default_end_space = 100;
25 this.pager_element.resizable({handles: 'n', resize: $.proxy(this._resize, this)});
25 this.pager_element.resizable({handles: 'n', resize: $.proxy(this._resize, this)});
26 this.expanded = false;
26 this.expanded = false;
27 this.create_button_area();
27 this.create_button_area();
28 this.bind_events();
28 this.bind_events();
29 };
29 };
30
30
31 Pager.prototype.create_button_area = function(){
31 Pager.prototype.create_button_area = function(){
32 var that = this;
32 var that = this;
33 this.pager_button_area.append(
33 this.pager_button_area.append(
34 $('<a>').attr('role', "button")
34 $('<a>').attr('role', "button")
35 .attr('title',"Open the pager in an external window")
35 .attr('title',"Open the pager in an external window")
36 .addClass('ui-button')
36 .addClass('ui-button')
37 .click(function(){that.detach();})
37 .click(function(){that.detach();})
38 .append(
38 .append(
39 $('<span>').addClass("ui-icon ui-icon-extlink")
39 $('<span>').addClass("ui-icon ui-icon-extlink")
40 )
40 )
41 );
41 );
42 this.pager_button_area.append(
42 this.pager_button_area.append(
43 $('<a>').attr('role', "button")
43 $('<a>').attr('role', "button")
44 .attr('title',"Close the pager")
44 .attr('title',"Close the pager")
45 .addClass('ui-button')
45 .addClass('ui-button')
46 .click(function(){that.collapse();})
46 .click(function(){that.collapse();})
47 .append(
47 .append(
48 $('<span>').addClass("ui-icon ui-icon-close")
48 $('<span>').addClass("ui-icon ui-icon-close")
49 )
49 )
50 );
50 );
51 };
51 };
52
52
53
53
54 Pager.prototype.bind_events = function () {
54 Pager.prototype.bind_events = function () {
55 var that = this;
55 var that = this;
56
56
57 this.pager_element.bind('collapse_pager', function (event, extrap) {
57 this.pager_element.bind('collapse_pager', function (event, extrap) {
58 // Animate hiding of the pager.
58 // Animate hiding of the pager.
59 var time = (extrap && extrap.duration) ? extrap.duration : 'fast';
59 var time = (extrap && extrap.duration) ? extrap.duration : 'fast';
60 that.pager_element.hide(time, function() {
60 that.pager_element.animate({
61 $('.end_space').css('height', that._default_end_space);
61 height: 'toggle'
62 }, {
63 duration: time,
64 done: function() {
65 $('.end_space').css('height', that._default_end_space);
66 }
62 });
67 });
63 });
68 });
64
69
65 this.pager_element.bind('expand_pager', function (event, extrap) {
70 this.pager_element.bind('expand_pager', function (event, extrap) {
66 // Clear the pager's height attr if it's set. This allows the
71 // Clear the pager's height attr if it's set. This allows the
67 // pager to size itself according to its contents.
72 // pager to size itself according to its contents.
68 that.pager_element.height('initial');
73 that.pager_element.height('initial');
69
74
70 // Animate the showing of the pager
75 // Animate the showing of the pager
71 var time = (extrap && extrap.duration) ? extrap.duration : 'fast';
76 var time = (extrap && extrap.duration) ? extrap.duration : 'fast';
72 that.pager_element.show(time, function() {
77 that.pager_element.show(time, function() {
73 // Explicitly set pager height once the pager has shown itself.
78 // Explicitly set pager height once the pager has shown itself.
74 // This allows the pager-contents div to use percentage sizing.
79 // This allows the pager-contents div to use percentage sizing.
75 that.pager_element.height(that.pager_element.height());
80 that.pager_element.height(that.pager_element.height());
76 that._resize();
81 that._resize();
77 });
82 });
78 });
83 });
79
84
80 this.events.on('open_with_text.Pager', function (event, payload) {
85 this.events.on('open_with_text.Pager', function (event, payload) {
81 // FIXME: support other mime types
86 // FIXME: support other mime types
82 if (payload.data['text/plain'] && payload.data['text/plain'] !== "") {
87 if (payload.data['text/plain'] && payload.data['text/plain'] !== "") {
83 that.clear();
88 that.clear();
84 that.expand();
89 that.expand();
85 that.append_text(payload.data['text/plain']);
90 that.append_text(payload.data['text/plain']);
86 }
91 }
87 });
92 });
88 };
93 };
89
94
90
95
91 Pager.prototype.collapse = function (extrap) {
96 Pager.prototype.collapse = function (extrap) {
92 if (this.expanded === true) {
97 if (this.expanded === true) {
93 this.expanded = false;
98 this.expanded = false;
94 this.pager_element.trigger('collapse_pager', extrap);
99 this.pager_element.trigger('collapse_pager', extrap);
95 }
100 }
96 };
101 };
97
102
98
103
99 Pager.prototype.expand = function (extrap) {
104 Pager.prototype.expand = function (extrap) {
100 if (this.expanded !== true) {
105 if (this.expanded !== true) {
101 this.expanded = true;
106 this.expanded = true;
102 this.pager_element.trigger('expand_pager', extrap);
107 this.pager_element.trigger('expand_pager', extrap);
103 }
108 }
104 };
109 };
105
110
106
111
107 Pager.prototype.toggle = function () {
112 Pager.prototype.toggle = function () {
108 if (this.expanded === true) {
113 if (this.expanded === true) {
109 this.collapse();
114 this.collapse();
110 } else {
115 } else {
111 this.expand();
116 this.expand();
112 }
117 }
113 };
118 };
114
119
115
120
116 Pager.prototype.clear = function (text) {
121 Pager.prototype.clear = function (text) {
117 this.pager_element.find(".container").empty();
122 this.pager_element.find(".container").empty();
118 };
123 };
119
124
120 Pager.prototype.detach = function(){
125 Pager.prototype.detach = function(){
121 var w = window.open("","_blank");
126 var w = window.open("","_blank");
122 $(w.document.head)
127 $(w.document.head)
123 .append(
128 .append(
124 $('<link>')
129 $('<link>')
125 .attr('rel',"stylesheet")
130 .attr('rel',"stylesheet")
126 .attr('href',"/static/css/notebook.css")
131 .attr('href',"/static/css/notebook.css")
127 .attr('type',"text/css")
132 .attr('type',"text/css")
128 )
133 )
129 .append(
134 .append(
130 $('<title>').text("IPython Pager")
135 $('<title>').text("IPython Pager")
131 );
136 );
132 var pager_body = $(w.document.body);
137 var pager_body = $(w.document.body);
133 pager_body.css('overflow','scroll');
138 pager_body.css('overflow','scroll');
134
139
135 pager_body.append(this.pager_element.clone().children());
140 pager_body.append(this.pager_element.clone().children());
136 w.document.close();
141 w.document.close();
137 this.collapse();
142 this.collapse();
138 };
143 };
139
144
140 Pager.prototype.append_text = function (text) {
145 Pager.prototype.append_text = function (text) {
141 /**
146 /**
142 * The only user content injected with this HTML call is escaped by
147 * The only user content injected with this HTML call is escaped by
143 * the fixConsole() method.
148 * the fixConsole() method.
144 */
149 */
145 this.pager_element.find(".container").append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
150 this.pager_element.find(".container").append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
146 };
151 };
147
152
148
153
149 Pager.prototype._resize = function() {
154 Pager.prototype._resize = function() {
150 /**
155 /**
151 * Update document based on pager size.
156 * Update document based on pager size.
152 */
157 */
153
158
154 // Make sure the padding at the end of the notebook is large
159 // Make sure the padding at the end of the notebook is large
155 // enough that the user can scroll to the bottom of the
160 // enough that the user can scroll to the bottom of the
156 // notebook.
161 // notebook.
157 $('.end_space').css('height', Math.max(this.pager_element.height(), this._default_end_space));
162 $('.end_space').css('height', Math.max(this.pager_element.height(), this._default_end_space));
158 };
163 };
159
164
160 // Backwards compatability.
165 // Backwards compatability.
161 IPython.Pager = Pager;
166 IPython.Pager = Pager;
162
167
163 return {'Pager': Pager};
168 return {'Pager': Pager};
164 });
169 });
General Comments 0
You need to be logged in to leave comments. Login now