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