##// END OF EJS Templates
Make svg, jpeg and png images resizable in notebook.
Make svg, jpeg and png images resizable in notebook.

File last commit:

r7340:4c1fd039
r7352:19c4b1ca
Show More
utils.js
137 lines | 4.5 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
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
Splitting notebook.js into muliple files for development ease.
r4349
//============================================================================
// Utilities
//============================================================================
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 IPython.namespace('IPython.utils');
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.utils = (function (IPython) {
var uuid = function () {
// http://www.ietf.org/rfc/rfc4122.txt
var s = [];
var hexDigits = "0123456789ABCDEF";
for (var i = 0; i < 32; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[12] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[16] = hexDigits.substr((s[16] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
var uuid = s.join("");
return uuid;
};
//Fix raw text to parse correctly in crazy XML
function xmlencode(string) {
return string.replace(/\&/g,'&'+'amp;')
.replace(/</g,'&'+'lt;')
.replace(/>/g,'&'+'gt;')
.replace(/\'/g,'&'+'apos;')
.replace(/\"/g,'&'+'quot;')
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 .replace(/`/g,'&'+'#96;');
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 }
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
Pager is working again.
r4361
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 //Map from terminal commands to CSS classes
Brian Granger
Colors now working in tracebacks and the pager....
r4383 ansi_colormap = {
"30":"ansiblack", "31":"ansired",
"32":"ansigreen", "33":"ansiyellow",
Michael Droettboom
Fix carriage-return handling regular expression so it doesn't treat "\r\n" as "\r".
r7338 "34":"ansiblue", "35":"ansipurple","36":"ansicyan",
Brian Granger
Colors now working in tracebacks and the pager....
r4383 "37":"ansigrey", "01":"ansibold"
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Michael Droettboom
Handle carriage return characters ("\r") in HTML notebook output....
r7339 // Transform ANSI color escape codes into HTML <span> tags with css
Brian Granger
Colors now working in tracebacks and the pager....
r4383 // classes listed in the above ansi_colormap object. The actual color used
// are set in the css file.
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 function fixConsole(txt) {
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 txt = xmlencode(txt);
MinRK
[notebook] clear_output is handled after a delay...
r6423 var re = /\033\[([\dA-Fa-f;]*?)m/;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 var opened = false;
var cmds = [];
var opener = "";
var closer = "";
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 while (re.test(txt)) {
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 var cmds = txt.match(re)[1].split(";");
closer = opened?"</span>":"";
opened = cmds.length > 1 || cmds[0] != 0;
var rep = [];
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 for (var i in cmds)
Brian Granger
Colors now working in tracebacks and the pager....
r4383 if (typeof(ansi_colormap[cmds[i]]) != "undefined")
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 rep.push(ansi_colormap[cmds[i]]);
opener = rep.length > 0?"<span class=\""+rep.join(" ")+"\">":"";
txt = txt.replace(re, closer + opener);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 }
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 if (opened) txt += "</span>";
return txt;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 }
Michael Droettboom
Fix carriage-return handling regular expression so it doesn't treat "\r\n" as "\r".
r7338 // Remove chunks that should be overridden by the effect of
// carriage return characters
function fixCarriageReturn(txt) {
tmp = txt;
do {
txt = tmp;
tmp = txt.replace(/^.*\r(?!\n)/gm, '');
} while (tmp.length < txt.length);
return txt;
}
Brian E. Granger
Pager is working again.
r4361
grow = function(element) {
// Grow the cell by hand. This is used upon reloading from JSON, when the
// autogrow handler is not called.
var dom = element.get(0);
var lines_count = 0;
// modified split rule from
// http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
var lines = dom.value.split(/\r|\r\n|\n/);
lines_count = lines.length;
if (lines_count >= 1) {
dom.rows = lines_count;
} else {
dom.rows = 1;
}
};
Matthias BUSSONNIER
add a keycodes structure to utils...
r7136 // some keycodes that seem to be platform/browser independant
var keycodes ={
Matthias BUSSONNIER
Uppercase constant keycode in utils.js
r7193 BACKSPACE: 8,
TAB : 9,
ENTER : 13,
SHIFT : 16,
CTRL : 17,
CONTROL : 17,
Brian Granger
Misc fixes to the code cell and output area.
r7199 ALT : 18,
Matthias BUSSONNIER
Uppercase constant keycode in utils.js
r7193 ESC : 27,
SPACE : 32,
PGUP : 33,
PGDOWN : 34,
LEFT_ARROW: 37,
LEFTARROW: 37,
LEFT : 37,
UP_ARROW : 38,
UPARROW : 38,
UP : 38,
RIGHT_ARROW:39,
RIGHTARROW:39,
RIGHT : 39,
DOWN_ARROW: 40,
DOWNARROW: 40,
DOWN : 40,
Matthias BUSSONNIER
add a keycodes structure to utils...
r7136 };
Brian E. Granger
Pager is working again.
r4361
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return {
uuid : uuid,
Brian E. Granger
Pager is working again.
r4361 fixConsole : fixConsole,
Matthias BUSSONNIER
add a keycodes structure to utils...
r7136 keycodes : keycodes,
grow : grow,
Michael Droettboom
Handle carriage return characters ("\r") in HTML notebook output....
r7339 fixCarriageReturn : fixCarriageReturn
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
}(IPython));