##// END OF EJS Templates
Update Widget Events.ipynb
Update Widget Events.ipynb

File last commit:

r19936:55c25b2e
r20620:313bf26c
Show More
pager.js
169 lines | 5.4 KiB | application/javascript | JavascriptLexer
MinRK
pager payload is a mime-bundle
r16586 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
Brian E. Granger
Refactoring pager into its own class.
r4357
Jonathan Frederic
Progress...
r17196 define([
'base/js/namespace',
Jonathan Frederic
More requirejs fixes
r17215 'jqueryui',
Jonathan Frederic
Pager
r17197 'base/js/utils',
Jonathan Frederic
Almost done!...
r17198 ], function(IPython, $, utils) {
Matthias BUSSONNIER
"use strict" in most (if not all) our javascript...
r12103 "use strict";
Brian E. Granger
Refactoring pager into its own class.
r4357
Jonathan Frederic
Kill the layout manager
r19179 var Pager = function (pager_selector, options) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Constructor
*
* Parameters:
* pager_selector: string
* options: dictionary
* Dictionary of keyword arguments.
* events: $(Events) instance
*/
jon
In person review with @ellisonbg
r17210 this.events = options.events;
Brian E. Granger
Refactoring pager into its own class.
r4357 this.pager_element = $(pager_selector);
Jonathan Frederic
Address @carreau 's review comments
r19207 this.pager_button_area = $('#pager-button-area');
Matthias Bussonnier
fix end_space size...
r19872 this._default_end_space = 100;
Jonathan Frederic
Address @carreau 's review comments
r19207 this.pager_element.resizable({handles: 'n', resize: $.proxy(this._resize, this)});
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723 this.expanded = false;
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 this.create_button_area();
Brian E. Granger
Refactoring pager into its own class.
r4357 this.bind_events();
};
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 Pager.prototype.create_button_area = function(){
var that = this;
this.pager_button_area.append(
$('<a>').attr('role', "button")
Erik Tollerud
Added clickable icon to collapse pager...
r10469 .attr('title',"Open the pager in an external window")
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 .addClass('ui-button')
Jonathan Frederic
Progress...
r17196 .click(function(){that.detach();})
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 .append(
Bussonnier Matthias
change detach icon and tab title
r8449 $('<span>').addClass("ui-icon ui-icon-extlink")
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 )
Jonathan Frederic
Progress...
r17196 );
Erik Tollerud
Added clickable icon to collapse pager...
r10469 this.pager_button_area.append(
$('<a>').attr('role', "button")
Erik Tollerud
Collapse -> Close in button description as suggested by @fperez
r10474 .attr('title',"Close the pager")
Erik Tollerud
Added clickable icon to collapse pager...
r10469 .addClass('ui-button')
Jonathan Frederic
Progress...
r17196 .click(function(){that.collapse();})
Erik Tollerud
Added clickable icon to collapse pager...
r10469 .append(
$('<span>').addClass("ui-icon ui-icon-close")
)
Jonathan Frederic
Progress...
r17196 );
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 };
Brian E. Granger
Refactoring pager into its own class.
r4357
Pager.prototype.bind_events = function () {
var that = this;
Brian E. Granger
Pager is working again.
r4361
Matthias BUSSONNIER
pep 8 and js...
r6739 this.pager_element.bind('collapse_pager', function (event, extrap) {
Jonathan Frederic
Fix scroll/resize handle missing behavior.
r19181 // Animate hiding of the pager.
Jonathan Frederic
Address @carreau 's review comments
r19207 var time = (extrap && extrap.duration) ? extrap.duration : 'fast';
Min RK
hide pager straight down...
r19936 that.pager_element.animate({
height: 'toggle'
}, {
duration: time,
done: function() {
$('.end_space').css('height', that._default_end_space);
}
Jonathan Frederic
Address @carreau 's review comments
r19207 });
Brian E. Granger
Pager is working again.
r4361 });
Matthias BUSSONNIER
pep 8 and js...
r6739 this.pager_element.bind('expand_pager', function (event, extrap) {
Jonathan Frederic
Fix scroll/resize handle missing behavior.
r19181 // Clear the pager's height attr if it's set. This allows the
// pager to size itself according to its contents.
that.pager_element.height('initial');
// Animate the showing of the pager
var time = (extrap && extrap.duration) ? extrap.duration : 'fast';
that.pager_element.show(time, function() {
// Explicitly set pager height once the pager has shown itself.
// This allows the pager-contents div to use percentage sizing.
that.pager_element.height(that.pager_element.height());
Jonathan Frederic
Address @carreau 's review comments
r19207 that._resize();
Jonathan Frederic
Fix scroll/resize handle missing behavior.
r19181 });
Brian E. Granger
Refactoring pager into its own class.
r4357 });
Jonathan Frederic
Progress...
r17196 this.events.on('open_with_text.Pager', function (event, payload) {
MinRK
pager payload is a mime-bundle
r16586 // FIXME: support other mime types
if (payload.data['text/plain'] && payload.data['text/plain'] !== "") {
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 that.clear();
that.expand();
MinRK
pager payload is a mime-bundle
r16586 that.append_text(payload.data['text/plain']);
}
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 });
Brian E. Granger
Refactoring pager into its own class.
r4357 };
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723 Pager.prototype.collapse = function (extrap) {
Brian E. Granger
Pager is working again.
r4361 if (this.expanded === true) {
this.expanded = false;
Jonathan Frederic
Fix, prevent notebook from having its height set on pager display
r19182 this.pager_element.trigger('collapse_pager', extrap);
MinRK
pager payload is a mime-bundle
r16586 }
Brian E. Granger
Refactoring pager into its own class.
r4357 };
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723 Pager.prototype.expand = function (extrap) {
Brian E. Granger
Pager is working again.
r4361 if (this.expanded !== true) {
this.expanded = true;
Jonathan Frederic
Fix, prevent notebook from having its height set on pager display
r19182 this.pager_element.trigger('expand_pager', extrap);
MinRK
pager payload is a mime-bundle
r16586 }
Brian E. Granger
Pager is working again.
r4361 };
Pager.prototype.toggle = function () {
if (this.expanded === true) {
this.collapse();
} else {
this.expand();
MinRK
pager payload is a mime-bundle
r16586 }
Brian E. Granger
Refactoring pager into its own class.
r4357 };
Pager.prototype.clear = function (text) {
MinRK
pager styling...
r10914 this.pager_element.find(".container").empty();
Brian E. Granger
Refactoring pager into its own class.
r4357 };
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 Pager.prototype.detach = function(){
MinRK
fix Pager.detach...
r11542 var w = window.open("","_blank");
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 $(w.document.head)
.append(
$('<link>')
.attr('rel',"stylesheet")
.attr('href',"/static/css/notebook.css")
.attr('type',"text/css")
Bussonnier Matthias
change detach icon and tab title
r8449 )
.append(
$('<title>').text("IPython Pager")
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 );
MinRK
fix Pager.detach...
r11542 var pager_body = $(w.document.body);
pager_body.css('overflow','scroll');
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265
MinRK
fix Pager.detach...
r11542 pager_body.append(this.pager_element.clone().children());
Matthias BUSSONNIER
This create the ability to detach the pager...
r8265 w.document.close();
this.collapse();
MinRK
pager payload is a mime-bundle
r16586 };
Brian E. Granger
Refactoring pager into its own class.
r4357
Pager.prototype.append_text = function (text) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* The only user content injected with this HTML call is escaped by
* the fixConsole() method.
*/
Jonathan Frederic
Almost done!...
r17198 this.pager_element.find(".container").append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
Matthias BUSSONNIER
Make pager resizable, and remember size......
r6723 };
Brian E. Granger
Refactoring pager into its own class.
r4357
Jonathan Frederic
Address @carreau 's review comments
r19207
Pager.prototype._resize = function() {
/**
* Update document based on pager size.
*/
// Make sure the padding at the end of the notebook is large
// enough that the user can scroll to the bottom of the
// notebook.
$('.end_space').css('height', Math.max(this.pager_element.height(), this._default_end_space));
};
Jonathan Frederic
Progress...
r17196 // Backwards compatability.
Brian E. Granger
Refactoring pager into its own class.
r4357 IPython.Pager = Pager;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'Pager': Pager};
Jonathan Frederic
Progress...
r17196 });