pager.js
123 lines
| 4.1 KiB
| application/javascript
|
JavascriptLexer
Brian E. Granger
|
r4609 | //---------------------------------------------------------------------------- | ||
// Copyright (C) 2008-2011 The IPython Development Team | ||||
// | ||||
// Distributed under the terms of the BSD License. The full license is in | ||||
// the file COPYING, distributed as part of this software. | ||||
//---------------------------------------------------------------------------- | ||||
Brian E. Granger
|
r4357 | |||
//============================================================================ | ||||
// Pager | ||||
//============================================================================ | ||||
var IPython = (function (IPython) { | ||||
var utils = IPython.utils; | ||||
Brian E. Granger
|
r4363 | var Pager = function (pager_selector, pager_splitter_selector) { | ||
Brian E. Granger
|
r4357 | this.pager_element = $(pager_selector); | ||
Matthias BUSSONNIER
|
r6723 | var that = this; | ||
Brian E. Granger
|
r4372 | this.percentage_height = 0.40; | ||
Matthias BUSSONNIER
|
r6723 | this.pager_splitter_element = $(pager_splitter_selector) | ||
.draggable({ | ||||
containment: 'window', | ||||
axis:'y', | ||||
helper: null , | ||||
Matthias BUSSONNIER
|
r6739 | drag: function(event, ui) { | ||
Matthias BUSSONNIER
|
r6723 | // recalculate the amount of space the pager should take | ||
Matthias BUSSONNIER
|
r6739 | var pheight = ($(body).height()-event.clientY-4); | ||
Matthias BUSSONNIER
|
r6723 | var downprct = pheight/IPython.layout_manager.app_height(); | ||
Matthias BUSSONNIER
|
r6739 | downprct = Math.min(0.9, downprct); | ||
if (downprct < 0.1) { | ||||
Matthias BUSSONNIER
|
r6723 | that.percentage_height = 0.1; | ||
that.collapse({'duration':0}); | ||||
Matthias BUSSONNIER
|
r6739 | } else if (downprct > 0.2) { | ||
Matthias BUSSONNIER
|
r6723 | that.percentage_height = downprct; | ||
that.expand({'duration':0}); | ||||
} | ||||
IPython.layout_manager.do_resize(); | ||||
} | ||||
}); | ||||
this.expanded = false; | ||||
Brian E. Granger
|
r4357 | this.style(); | ||
this.bind_events(); | ||||
}; | ||||
Pager.prototype.style = function () { | ||||
Brian E. Granger
|
r4363 | this.pager_splitter_element.addClass('border-box-sizing ui-widget ui-state-default'); | ||
Brian E. Granger
|
r4361 | this.pager_element.addClass('border-box-sizing ui-widget'); | ||
Matthias BUSSONNIER
|
r6723 | this.pager_splitter_element.attr('title', 'Click to Show/Hide pager area, drag to Resize'); | ||
Brian E. Granger
|
r4357 | }; | ||
Pager.prototype.bind_events = function () { | ||||
var that = this; | ||||
Brian E. Granger
|
r4361 | |||
Matthias BUSSONNIER
|
r6739 | this.pager_element.bind('collapse_pager', function (event, extrap) { | ||
Matthias BUSSONNIER
|
r6723 | time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast'; | ||
that.pager_element.hide(time); | ||||
Brian E. Granger
|
r4361 | }); | ||
Matthias BUSSONNIER
|
r6739 | this.pager_element.bind('expand_pager', function (event, extrap) { | ||
Matthias BUSSONNIER
|
r6723 | time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast'; | ||
that.pager_element.show(time); | ||||
Brian E. Granger
|
r4357 | }); | ||
Brian E. Granger
|
r4363 | this.pager_splitter_element.hover( | ||
Brian E. Granger
|
r4357 | function () { | ||
Brian E. Granger
|
r4363 | that.pager_splitter_element.addClass('ui-state-hover'); | ||
Brian E. Granger
|
r4357 | }, | ||
function () { | ||||
Brian E. Granger
|
r4363 | that.pager_splitter_element.removeClass('ui-state-hover'); | ||
Brian E. Granger
|
r4357 | } | ||
); | ||||
Brian E. Granger
|
r4361 | |||
Brian E. Granger
|
r4363 | this.pager_splitter_element.click(function () { | ||
Brian E. Granger
|
r4361 | that.toggle(); | ||
}); | ||||
Brian E. Granger
|
r4363 | |||
Brian E. Granger
|
r4357 | }; | ||
Matthias BUSSONNIER
|
r6723 | Pager.prototype.collapse = function (extrap) { | ||
Brian E. Granger
|
r4361 | if (this.expanded === true) { | ||
this.expanded = false; | ||||
Matthias BUSSONNIER
|
r6739 | this.pager_element.add($('div#notebook')).trigger('collapse_pager', extrap); | ||
Brian E. Granger
|
r4361 | }; | ||
Brian E. Granger
|
r4357 | }; | ||
Matthias BUSSONNIER
|
r6723 | Pager.prototype.expand = function (extrap) { | ||
Brian E. Granger
|
r4361 | if (this.expanded !== true) { | ||
this.expanded = true; | ||||
Matthias BUSSONNIER
|
r6739 | this.pager_element.add($('div#notebook')).trigger('expand_pager', extrap); | ||
Brian E. Granger
|
r4361 | }; | ||
}; | ||||
Pager.prototype.toggle = function () { | ||||
if (this.expanded === true) { | ||||
this.collapse(); | ||||
} else { | ||||
this.expand(); | ||||
}; | ||||
Brian E. Granger
|
r4357 | }; | ||
Pager.prototype.clear = function (text) { | ||||
this.pager_element.empty(); | ||||
}; | ||||
Pager.prototype.append_text = function (text) { | ||||
Brian E. Granger
|
r4379 | var toinsert = $("<div/>").addClass("output_area output_stream"); | ||
MinRK
|
r6676 | toinsert.append($('<pre/>').html(utils.fixConsole(text))); | ||
Brian E. Granger
|
r4357 | this.pager_element.append(toinsert); | ||
Matthias BUSSONNIER
|
r6723 | }; | ||
Brian E. Granger
|
r4357 | |||
IPython.Pager = Pager; | ||||
return IPython; | ||||
}(IPython)); | ||||