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