first import book

This commit is contained in:
Johann Dreo 2015-03-03 15:56:44 +01:00
commit dfd9c869d5
233 changed files with 47797 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,338 @@
CodeMirror.defineMode("python", function(conf, parserConf) {
var ERRORCLASS = 'error';
function wordRegexp(words) {
return new RegExp("^((" + words.join(")|(") + "))\\b");
}
var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
var wordOperators = wordRegexp(['and', 'or', 'not', 'is', 'in']);
var commonkeywords = ['as', 'assert', 'break', 'class', 'continue',
'def', 'del', 'elif', 'else', 'except', 'finally',
'for', 'from', 'global', 'if', 'import',
'lambda', 'pass', 'raise', 'return',
'try', 'while', 'with', 'yield'];
var commonBuiltins = ['abs', 'all', 'any', 'bin', 'bool', 'bytearray', 'callable', 'chr',
'classmethod', 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod',
'enumerate', 'eval', 'filter', 'float', 'format', 'frozenset',
'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id',
'input', 'int', 'isinstance', 'issubclass', 'iter', 'len',
'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next',
'object', 'oct', 'open', 'ord', 'pow', 'property', 'range',
'repr', 'reversed', 'round', 'set', 'setattr', 'slice',
'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple',
'type', 'vars', 'zip', '__import__', 'NotImplemented',
'Ellipsis', '__debug__'];
var py2 = {'builtins': ['apply', 'basestring', 'buffer', 'cmp', 'coerce', 'execfile',
'file', 'intern', 'long', 'raw_input', 'reduce', 'reload',
'unichr', 'unicode', 'xrange', 'False', 'True', 'None'],
'keywords': ['exec', 'print']};
var py3 = {'builtins': ['ascii', 'bytes', 'exec', 'print'],
'keywords': ['nonlocal', 'False', 'True', 'None']};
if (!!parserConf.version && parseInt(parserConf.version, 10) === 3) {
commonkeywords = commonkeywords.concat(py3.keywords);
commonBuiltins = commonBuiltins.concat(py3.builtins);
var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i");
} else {
commonkeywords = commonkeywords.concat(py2.keywords);
commonBuiltins = commonBuiltins.concat(py2.builtins);
var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i");
}
var keywords = wordRegexp(commonkeywords);
var builtins = wordRegexp(commonBuiltins);
var indentInfo = null;
// tokenizers
function tokenBase(stream, state) {
// Handle scope changes
if (stream.sol()) {
var scopeOffset = state.scopes[0].offset;
if (stream.eatSpace()) {
var lineOffset = stream.indentation();
if (lineOffset > scopeOffset) {
indentInfo = 'indent';
} else if (lineOffset < scopeOffset) {
indentInfo = 'dedent';
}
return null;
} else {
if (scopeOffset > 0) {
dedent(stream, state);
}
}
}
if (stream.eatSpace()) {
return null;
}
var ch = stream.peek();
// Handle Comments
if (ch === '#') {
stream.skipToEnd();
return 'comment';
}
// Handle Number Literals
if (stream.match(/^[0-9\.]/, false)) {
var floatLiteral = false;
// Floats
if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
if (floatLiteral) {
// Float literals may be "imaginary"
stream.eat(/J/i);
return 'number';
}
// Integers
var intLiteral = false;
// Hex
if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }
// Binary
if (stream.match(/^0b[01]+/i)) { intLiteral = true; }
// Octal
if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }
// Decimal
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
// Decimal literals may be "imaginary"
stream.eat(/J/i);
// TODO - Can you have imaginary longs?
intLiteral = true;
}
// Zero by itself with no other piece of number.
if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
if (intLiteral) {
// Integer literals may be "long"
stream.eat(/L/i);
return 'number';
}
}
// Handle Strings
if (stream.match(stringPrefixes)) {
state.tokenize = tokenStringFactory(stream.current());
return state.tokenize(stream, state);
}
// Handle operators and Delimiters
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
return null;
}
if (stream.match(doubleOperators)
|| stream.match(singleOperators)
|| stream.match(wordOperators)) {
return 'operator';
}
if (stream.match(singleDelimiters)) {
return null;
}
if (stream.match(keywords)) {
return 'keyword';
}
if (stream.match(builtins)) {
return 'builtin';
}
if (stream.match(identifiers)) {
return 'variable';
}
// Handle non-detected items
stream.next();
return ERRORCLASS;
}
function tokenStringFactory(delimiter) {
while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) {
delimiter = delimiter.substr(1);
}
var singleline = delimiter.length == 1;
var OUTCLASS = 'string';
return function tokenString(stream, state) {
while (!stream.eol()) {
stream.eatWhile(/[^'"\\]/);
if (stream.eat('\\')) {
stream.next();
if (singleline && stream.eol()) {
return OUTCLASS;
}
} else if (stream.match(delimiter)) {
state.tokenize = tokenBase;
return OUTCLASS;
} else {
stream.eat(/['"]/);
}
}
if (singleline) {
if (parserConf.singleLineStringErrors) {
return ERRORCLASS;
} else {
state.tokenize = tokenBase;
}
}
return OUTCLASS;
};
}
function indent(stream, state, type) {
type = type || 'py';
var indentUnit = 0;
if (type === 'py') {
if (state.scopes[0].type !== 'py') {
state.scopes[0].offset = stream.indentation();
return;
}
for (var i = 0; i < state.scopes.length; ++i) {
if (state.scopes[i].type === 'py') {
indentUnit = state.scopes[i].offset + conf.indentUnit;
break;
}
}
} else {
indentUnit = stream.column() + stream.current().length;
}
state.scopes.unshift({
offset: indentUnit,
type: type
});
}
function dedent(stream, state, type) {
type = type || 'py';
if (state.scopes.length == 1) return;
if (state.scopes[0].type === 'py') {
var _indent = stream.indentation();
var _indent_index = -1;
for (var i = 0; i < state.scopes.length; ++i) {
if (_indent === state.scopes[i].offset) {
_indent_index = i;
break;
}
}
if (_indent_index === -1) {
return true;
}
while (state.scopes[0].offset !== _indent) {
state.scopes.shift();
}
return false;
} else {
if (type === 'py') {
state.scopes[0].offset = stream.indentation();
return false;
} else {
if (state.scopes[0].type != type) {
return true;
}
state.scopes.shift();
return false;
}
}
}
function tokenLexer(stream, state) {
indentInfo = null;
var style = state.tokenize(stream, state);
var current = stream.current();
// Handle '.' connected identifiers
if (current === '.') {
style = stream.match(identifiers, false) ? null : ERRORCLASS;
if (style === null && state.lastToken === 'meta') {
// Apply 'meta' style to '.' connected identifiers when
// appropriate.
style = 'meta';
}
return style;
}
// Handle decorators
if (current === '@') {
return stream.match(identifiers, false) ? 'meta' : ERRORCLASS;
}
if ((style === 'variable' || style === 'builtin')
&& state.lastToken === 'meta') {
style = 'meta';
}
// Handle scope changes.
if (current === 'pass' || current === 'return') {
state.dedent += 1;
}
if (current === 'lambda') state.lambda = true;
if ((current === ':' && !state.lambda && state.scopes[0].type == 'py')
|| indentInfo === 'indent') {
indent(stream, state);
}
var delimiter_index = '[({'.indexOf(current);
if (delimiter_index !== -1) {
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
}
if (indentInfo === 'dedent') {
if (dedent(stream, state)) {
return ERRORCLASS;
}
}
delimiter_index = '])}'.indexOf(current);
if (delimiter_index !== -1) {
if (dedent(stream, state, current)) {
return ERRORCLASS;
}
}
if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'py') {
if (state.scopes.length > 1) state.scopes.shift();
state.dedent -= 1;
}
return style;
}
var external = {
startState: function(basecolumn) {
return {
tokenize: tokenBase,
scopes: [{offset:basecolumn || 0, type:'py'}],
lastToken: null,
lambda: false,
dedent: 0
};
},
token: function(stream, state) {
var style = tokenLexer(stream, state);
state.lastToken = style;
if (stream.eol() && stream.lambda) {
state.lambda = false;
}
return style;
},
indent: function(state, textAfter) {
if (state.tokenize != tokenBase) {
return 0;
}
return state.scopes[0].offset;
}
};
return external;
});
CodeMirror.defineMIME("text/x-python", "python");

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,185 @@
/*
Online Python Tutor
https://github.com/pgbovine/OnlinePythonTutor/
Copyright (C) 2010-2013 Philip J. Guo (philip@pgbovine.net)
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Pre-reqs: pytutor.js and jquery.ba-bbq.min.js should be imported BEFORE this file
// backend scripts to execute (Python 2 and 3 variants, if available)
// make two copies of ../web_exec.py and give them the following names,
// then change the first line (starting with #!) to the proper version
// of the Python interpreter (i.e., Python 2 or Python 3).
//var python2_backend_script = 'web_exec_py2.py';
//var python3_backend_script = 'web_exec_py3.py';
// uncomment below if you're running on Google App Engine using the built-in app.yaml
var python2_backend_script = 'exec';
var python3_backend_script = null;
var myVisualizer = null; // singleton ExecutionVisualizer instance
$(document).ready(function() {
var preseededCode = $.bbq.getState('code');
var pyState = $.bbq.getState('py');
var verticalStackBool = ($.bbq.getState('verticalStack') == 'true'); // boolean
var heapPrimitivesBool = ($.bbq.getState('heapPrimitives') == 'true');
var drawParentPointerBool = ($.bbq.getState('drawParentPointers') == 'true');
var textRefsBool = ($.bbq.getState('textReferences') == 'true');
var showOnlyOutputsBool = ($.bbq.getState('showOnlyOutputs') == 'true');
// set up all options in a JS object
var options = {cumulative_mode: ($.bbq.getState('cumulative') == 'true'),
heap_primitives: heapPrimitivesBool,
show_only_outputs: showOnlyOutputsBool,
py_crazy_mode: ($.bbq.getState('py') == '2crazy')};
var preseededCurInstr = Number($.bbq.getState('curInstr'));
if (!preseededCurInstr) {
preseededCurInstr = 0;
}
var backend_script = null;
if (pyState == '2') {
backend_script = python2_backend_script;
}
else if (pyState == '3') {
backend_script = python3_backend_script;
}
if (!backend_script) {
alert('Error: This server is not configured to run Python ' + $('#pythonVersionSelector').val());
return;
}
// David Pritchard's code for resizeContainer option ...
var resizeContainer = ($.bbq.getState('resizeContainer') == 'true');
if (resizeContainer) {
function findContainer() {
var ifs = window.top.document.getElementsByTagName("iframe");
for(var i = 0, len = ifs.length; i < len; i++) {
var f = ifs[i];
var fDoc = f.contentDocument || f.contentWindow.document;
if(fDoc === document) {
return f;
}
}
}
var container = findContainer();
function resizeContainerNow() {
$(container).height($("#vizDiv").height()+20);
};
}
$.get(backend_script,
{user_script : preseededCode,
options_json: JSON.stringify(options)},
function(dataFromBackend) {
var trace = dataFromBackend.trace;
// don't enter visualize mode if there are killer errors:
if (!trace ||
(trace.length == 0) ||
(trace[trace.length - 1].event == 'uncaught_exception')) {
if (trace.length == 1) {
alert(trace[0].exception_msg);
}
else if (trace[trace.length - 1].exception_msg) {
alert(trace[trace.length - 1].exception_msg);
}
else {
alert("Whoa, unknown error! Reload to try again, or report a bug to philip@pgbovine.net\n\n(Click the 'Generate URL' button to include a unique URL in your email bug report.)");
}
}
else {
var startingInstruction = 0;
// only do this at most ONCE, and then clear out preseededCurInstr
if (preseededCurInstr && preseededCurInstr < trace.length) { // NOP anyways if preseededCurInstr is 0
startingInstruction = preseededCurInstr;
}
myVisualizer = new ExecutionVisualizer('vizDiv',
dataFromBackend,
{startingInstruction: preseededCurInstr,
embeddedMode: true,
verticalStack: verticalStackBool,
disableHeapNesting: heapPrimitivesBool,
drawParentPointers: drawParentPointerBool,
textualMemoryLabels: textRefsBool,
showOnlyOutputs: showOnlyOutputsBool,
highlightLines: typeof $.bbq.getState("highlightLines") !== "undefined",
pyCrazyMode: ($.bbq.getState('py') == '2crazy'),
updateOutputCallback: (resizeContainer ? resizeContainerNow : null)
});
// set keyboard bindings
// VERY IMPORTANT to clear and reset this every time or
// else the handlers might be bound multiple times
$(document).unbind('keydown');
$(document).keydown(function(k) {
if (k.keyCode == 37) { // left arrow
if (myVisualizer.stepBack()) {
k.preventDefault(); // don't horizontally scroll the display
}
}
else if (k.keyCode == 39) { // right arrow
if (myVisualizer.stepForward()) {
k.preventDefault(); // don't horizontally scroll the display
}
}
});
}
},
"json");
// log a generic AJAX error handler
$(document).ajaxError(function() {
alert("Online Python Tutor server error (possibly due to memory/resource overload).");
});
// redraw connector arrows on window resize
$(window).resize(function() {
if (typeof appMode !== "undefined" && appMode == 'display') {
myVisualizer.redrawConnectors();
}
});
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,18 @@
/*
* jQuery BBQ: Back Button & Query Library - v1.2.1 - 2/17/2010
* http://benalman.com/projects/jquery-bbq-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($,p){var i,m=Array.prototype.slice,r=decodeURIComponent,a=$.param,c,l,v,b=$.bbq=$.bbq||{},q,u,j,e=$.event.special,d="hashchange",A="querystring",D="fragment",y="elemUrlAttr",g="location",k="href",t="src",x=/^.*\?|#.*$/g,w=/^.*\#/,h,C={};function E(F){return typeof F==="string"}function B(G){var F=m.call(arguments,1);return function(){return G.apply(this,F.concat(m.call(arguments)))}}function n(F){return F.replace(/^[^#]*#?(.*)$/,"$1")}function o(F){return F.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function f(H,M,F,I,G){var O,L,K,N,J;if(I!==i){K=F.match(H?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);J=K[3]||"";if(G===2&&E(I)){L=I.replace(H?w:x,"")}else{N=l(K[2]);I=E(I)?l[H?D:A](I):I;L=G===2?I:G===1?$.extend({},I,N):$.extend({},N,I);L=a(L);if(H){L=L.replace(h,r)}}O=K[1]+(H?"#":L||!K[1]?"?":"")+L+J}else{O=M(F!==i?F:p[g][k])}return O}a[A]=B(f,0,o);a[D]=c=B(f,1,n);c.noEscape=function(G){G=G||"";var F=$.map(G.split(""),encodeURIComponent);h=new RegExp(F.join("|"),"g")};c.noEscape(",/");$.deparam=l=function(I,F){var H={},G={"true":!0,"false":!1,"null":null};$.each(I.replace(/\+/g," ").split("&"),function(L,Q){var K=Q.split("="),P=r(K[0]),J,O=H,M=0,R=P.split("]["),N=R.length-1;if(/\[/.test(R[0])&&/\]$/.test(R[N])){R[N]=R[N].replace(/\]$/,"");R=R.shift().split("[").concat(R);N=R.length-1}else{N=0}if(K.length===2){J=r(K[1]);if(F){J=J&&!isNaN(J)?+J:J==="undefined"?i:G[J]!==i?G[J]:J}if(N){for(;M<=N;M++){P=R[M]===""?O.length:R[M];O=O[P]=M<N?O[P]||(R[M+1]&&isNaN(R[M+1])?{}:[]):J}}else{if($.isArray(H[P])){H[P].push(J)}else{if(H[P]!==i){H[P]=[H[P],J]}else{H[P]=J}}}}else{if(P){H[P]=F?i:""}}});return H};function z(H,F,G){if(F===i||typeof F==="boolean"){G=F;F=a[H?D:A]()}else{F=E(F)?F.replace(H?w:x,""):F}return l(F,G)}l[A]=B(z,0);l[D]=v=B(z,1);$[y]||($[y]=function(F){return $.extend(C,F)})({a:k,base:k,iframe:t,img:t,input:t,form:"action",link:k,script:t});j=$[y];function s(I,G,H,F){if(!E(H)&&typeof H!=="object"){F=H;H=G;G=i}return this.each(function(){var L=$(this),J=G||j()[(this.nodeName||"").toLowerCase()]||"",K=J&&L.attr(J)||"";L.attr(J,a[I](K,H,F))})}$.fn[A]=B(s,A);$.fn[D]=B(s,D);b.pushState=q=function(I,F){if(E(I)&&/^#/.test(I)&&F===i){F=2}var H=I!==i,G=c(p[g][k],H?I:{},H?F:2);p[g][k]=G+(/#/.test(G)?"":"#")};b.getState=u=function(F,G){return F===i||typeof F==="boolean"?v(F):v(G)[F]};b.removeState=function(F){var G={};if(F!==i){G=u();$.each($.isArray(F)?F:arguments,function(I,H){delete G[H]})}q(G,2)};e[d]=$.extend(e[d],{add:function(F){var H;function G(J){var I=J[D]=c();J.getState=function(K,L){return K===i||typeof K==="boolean"?l(I,K):l(I,L)[K]};H.apply(this,arguments)}if($.isFunction(F)){H=F;return G}else{H=F.handler;F.handler=G}}})})(jQuery,this);
/*
* jQuery hashchange event - v1.2 - 2/11/2010
* http://benalman.com/projects/jquery-hashchange-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($,i,b){var j,k=$.event.special,c="location",d="hashchange",l="href",f=$.browser,g=document.documentMode,h=f.msie&&(g===b||g<8),e="on"+d in i&&!h;function a(m){m=m||i[c][l];return m.replace(/^[^#]*#?(.*)$/,"$1")}$[d+"Delay"]=100;k[d]=$.extend(k[d],{setup:function(){if(e){return false}$(j.start)},teardown:function(){if(e){return false}$(j.stop)}});j=(function(){var m={},r,n,o,q;function p(){o=q=function(s){return s};if(h){n=$('<iframe src="javascript:0"/>').hide().insertAfter("body")[0].contentWindow;q=function(){return a(n.document[c][l])};o=function(u,s){if(u!==s){var t=n.document;t.open().close();t[c].hash="#"+u}};o(a())}}m.start=function(){if(r){return}var t=a();o||p();(function s(){var v=a(),u=q(t);if(v!==t){o(t=v,u);$(i).trigger(d)}else{if(u!==t){i[c][l]=i[c][l].replace(/#.*/,"")+"#"+u}}r=setTimeout(s,$[d+"Delay"])})()};m.stop=function(){if(!n){r&&clearTimeout(r);r=0}};return m})()})(jQuery,this);

View file

@ -0,0 +1,249 @@
/*!
* jQuery corner plugin: simple corner rounding
* Examples and documentation at: http://jquery.malsup.com/corner/
* version 2.12 (23-MAY-2011)
* Requires jQuery v1.3.2 or later
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Authors: Dave Methvin and Mike Alsup
*/
/**
* corner() takes a single string argument: $('#myDiv').corner("effect corners width")
*
* effect: name of the effect to apply, such as round, bevel, notch, bite, etc (default is round).
* corners: one or more of: top, bottom, tr, tl, br, or bl. (default is all corners)
* width: width of the effect; in the case of rounded corners this is the radius.
* specify this value using the px suffix such as 10px (yes, it must be pixels).
*/
;(function($) {
var style = document.createElement('div').style,
moz = style['MozBorderRadius'] !== undefined,
webkit = style['WebkitBorderRadius'] !== undefined,
radius = style['borderRadius'] !== undefined || style['BorderRadius'] !== undefined,
mode = document.documentMode || 0,
noBottomFold = $.browser.msie && (($.browser.version < 8 && !mode) || mode < 8),
expr = $.browser.msie && (function() {
var div = document.createElement('div');
try { div.style.setExpression('width','0+0'); div.style.removeExpression('width'); }
catch(e) { return false; }
return true;
})();
$.support = $.support || {};
$.support.borderRadius = moz || webkit || radius; // so you can do: if (!$.support.borderRadius) $('#myDiv').corner();
function sz(el, p) {
return parseInt($.css(el,p))||0;
};
function hex2(s) {
s = parseInt(s).toString(16);
return ( s.length < 2 ) ? '0'+s : s;
};
function gpc(node) {
while(node) {
var v = $.css(node,'backgroundColor'), rgb;
if (v && v != 'transparent' && v != 'rgba(0, 0, 0, 0)') {
if (v.indexOf('rgb') >= 0) {
rgb = v.match(/\d+/g);
return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
}
return v;
}
if (node.nodeName.toLowerCase() == 'html')
break;
node = node.parentNode; // keep walking if transparent
}
return '#ffffff';
};
function getWidth(fx, i, width) {
switch(fx) {
case 'round': return Math.round(width*(1-Math.cos(Math.asin(i/width))));
case 'cool': return Math.round(width*(1+Math.cos(Math.asin(i/width))));
case 'sharp': return width-i;
case 'bite': return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
case 'slide': return Math.round(width*(Math.atan2(i,width/i)));
case 'jut': return Math.round(width*(Math.atan2(width,(width-i-1))));
case 'curl': return Math.round(width*(Math.atan(i)));
case 'tear': return Math.round(width*(Math.cos(i)));
case 'wicked': return Math.round(width*(Math.tan(i)));
case 'long': return Math.round(width*(Math.sqrt(i)));
case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
case 'dogfold':
case 'dog': return (i&1) ? (i+1) : width;
case 'dog2': return (i&2) ? (i+1) : width;
case 'dog3': return (i&3) ? (i+1) : width;
case 'fray': return (i%2)*width;
case 'notch': return width;
case 'bevelfold':
case 'bevel': return i+1;
case 'steep': return i/2 + 1;
case 'invsteep':return (width-i)/2+1;
}
};
$.fn.corner = function(options) {
// in 1.3+ we can fix mistakes with the ready state
if (this.length == 0) {
if (!$.isReady && this.selector) {
var s = this.selector, c = this.context;
$(function() {
$(s,c).corner(options);
});
}
return this;
}
return this.each(function(index){
var $this = $(this),
// meta values override options
o = [$this.attr($.fn.corner.defaults.metaAttr) || '', options || ''].join(' ').toLowerCase(),
keep = /keep/.test(o), // keep borders?
cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]), // corner color
sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]), // strip color
width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10, // corner width
re = /round|bevelfold|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dogfold|dog|invsteep|steep/,
fx = ((o.match(re)||['round'])[0]),
fold = /dogfold|bevelfold/.test(o),
edges = { T:0, B:1 },
opts = {
TL: /top|tl|left/.test(o), TR: /top|tr|right/.test(o),
BL: /bottom|bl|left/.test(o), BR: /bottom|br|right/.test(o)
},
// vars used in func later
strip, pad, cssHeight, j, bot, d, ds, bw, i, w, e, c, common, $horz;
if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
opts = { TL:1, TR:1, BL:1, BR:1 };
// support native rounding
if ($.fn.corner.defaults.useNative && fx == 'round' && (radius || moz || webkit) && !cc && !sc) {
if (opts.TL)
$this.css(radius ? 'border-top-left-radius' : moz ? '-moz-border-radius-topleft' : '-webkit-border-top-left-radius', width + 'px');
if (opts.TR)
$this.css(radius ? 'border-top-right-radius' : moz ? '-moz-border-radius-topright' : '-webkit-border-top-right-radius', width + 'px');
if (opts.BL)
$this.css(radius ? 'border-bottom-left-radius' : moz ? '-moz-border-radius-bottomleft' : '-webkit-border-bottom-left-radius', width + 'px');
if (opts.BR)
$this.css(radius ? 'border-bottom-right-radius' : moz ? '-moz-border-radius-bottomright' : '-webkit-border-bottom-right-radius', width + 'px');
return;
}
strip = document.createElement('div');
$(strip).css({
overflow: 'hidden',
height: '1px',
minHeight: '1px',
fontSize: '1px',
backgroundColor: sc || 'transparent',
borderStyle: 'solid'
});
pad = {
T: parseInt($.css(this,'paddingTop'))||0, R: parseInt($.css(this,'paddingRight'))||0,
B: parseInt($.css(this,'paddingBottom'))||0, L: parseInt($.css(this,'paddingLeft'))||0
};
if (typeof this.style.zoom != undefined) this.style.zoom = 1; // force 'hasLayout' in IE
if (!keep) this.style.border = 'none';
strip.style.borderColor = cc || gpc(this.parentNode);
cssHeight = $(this).outerHeight();
for (j in edges) {
bot = edges[j];
// only add stips if needed
if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) {
strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
d = document.createElement('div');
$(d).addClass('jquery-corner');
ds = d.style;
bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);
if (bot && cssHeight != 'auto') {
if ($.css(this,'position') == 'static')
this.style.position = 'relative';
ds.position = 'absolute';
ds.bottom = ds.left = ds.padding = ds.margin = '0';
if (expr)
ds.setExpression('width', 'this.parentNode.offsetWidth');
else
ds.width = '100%';
}
else if (!bot && $.browser.msie) {
if ($.css(this,'position') == 'static')
this.style.position = 'relative';
ds.position = 'absolute';
ds.top = ds.left = ds.right = ds.padding = ds.margin = '0';
// fix ie6 problem when blocked element has a border width
if (expr) {
bw = sz(this,'borderLeftWidth') + sz(this,'borderRightWidth');
ds.setExpression('width', 'this.parentNode.offsetWidth - '+bw+'+ "px"');
}
else
ds.width = '100%';
}
else {
ds.position = 'relative';
ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' :
(pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';
}
for (i=0; i < width; i++) {
w = Math.max(0,getWidth(fx,i, width));
e = strip.cloneNode(false);
e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
}
if (fold && $.support.boxModel) {
if (bot && noBottomFold) continue;
for (c in opts) {
if (!opts[c]) continue;
if (bot && (c == 'TL' || c == 'TR')) continue;
if (!bot && (c == 'BL' || c == 'BR')) continue;
common = { position: 'absolute', border: 'none', margin: 0, padding: 0, overflow: 'hidden', backgroundColor: strip.style.borderColor };
$horz = $('<div/>').css(common).css({ width: width + 'px', height: '1px' });
switch(c) {
case 'TL': $horz.css({ bottom: 0, left: 0 }); break;
case 'TR': $horz.css({ bottom: 0, right: 0 }); break;
case 'BL': $horz.css({ top: 0, left: 0 }); break;
case 'BR': $horz.css({ top: 0, right: 0 }); break;
}
d.appendChild($horz[0]);
var $vert = $('<div/>').css(common).css({ top: 0, bottom: 0, width: '1px', height: width + 'px' });
switch(c) {
case 'TL': $vert.css({ left: width }); break;
case 'TR': $vert.css({ right: width }); break;
case 'BL': $vert.css({ left: width }); break;
case 'BR': $vert.css({ right: width }); break;
}
d.appendChild($vert[0]);
}
}
}
}
});
};
$.fn.uncorner = function() {
if (radius || moz || webkit)
this.css(radius ? 'border-radius' : moz ? '-moz-border-radius' : '-webkit-border-radius', 0);
$('div.jquery-corner', this).remove();
return this;
};
// expose options
$.fn.corner.defaults = {
useNative: true, // true if plugin should attempt to use native browser support for border radius rounding
metaAttr: 'data-corner' // name of meta attribute to use for options
};
})(jQuery);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,26 @@
/*
* SimpleModal 1.4.3 - jQuery Plugin
* http://simplemodal.com/
* Copyright (c) 2012 Eric Martin
* Licensed under MIT and GPL
* Date: Sat, Sep 8 2012 07:52:31 -0700
*/
(function(b){"function"===typeof define&&define.amd?define(["jquery"],b):b(jQuery)})(function(b){var j=[],l=b(document),m=b.browser.msie&&6===parseInt(b.browser.version)&&"object"!==typeof window.XMLHttpRequest,o=b.browser.msie&&7===parseInt(b.browser.version),n=null,k=b(window),h=[];b.modal=function(a,d){return b.modal.impl.init(a,d)};b.modal.close=function(){b.modal.impl.close()};b.modal.focus=function(a){b.modal.impl.focus(a)};b.modal.setContainerDimensions=function(){b.modal.impl.setContainerDimensions()};
b.modal.setPosition=function(){b.modal.impl.setPosition()};b.modal.update=function(a,d){b.modal.impl.update(a,d)};b.fn.modal=function(a){return b.modal.impl.init(this,a)};b.modal.defaults={appendTo:"body",focus:!0,opacity:50,overlayId:"simplemodal-overlay",overlayCss:{},containerId:"simplemodal-container",containerCss:{},dataId:"simplemodal-data",dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,autoResize:!1,autoPosition:!0,zIndex:1E3,close:!0,closeHTML:'<a class="modalCloseImg" title="Close"></a>',
closeClass:"simplemodal-close",escClose:!0,overlayClose:!1,fixed:!0,position:null,persist:!1,modal:!0,onOpen:null,onShow:null,onClose:null};b.modal.impl={d:{},init:function(a,d){if(this.d.data)return!1;n=b.browser.msie&&!b.support.boxModel;this.o=b.extend({},b.modal.defaults,d);this.zIndex=this.o.zIndex;this.occb=!1;if("object"===typeof a){if(a=a instanceof b?a:b(a),this.d.placeholder=!1,0<a.parent().parent().size()&&(a.before(b("<span></span>").attr("id","simplemodal-placeholder").css({display:"none"})),
this.d.placeholder=!0,this.display=a.css("display"),!this.o.persist))this.d.orig=a.clone(!0)}else if("string"===typeof a||"number"===typeof a)a=b("<div></div>").html(a);else return alert("SimpleModal Error: Unsupported data type: "+typeof a),this;this.create(a);this.open();b.isFunction(this.o.onShow)&&this.o.onShow.apply(this,[this.d]);return this},create:function(a){this.getDimensions();if(this.o.modal&&m)this.d.iframe=b('<iframe src="javascript:false;"></iframe>').css(b.extend(this.o.iframeCss,
{display:"none",opacity:0,position:"fixed",height:h[0],width:h[1],zIndex:this.o.zIndex,top:0,left:0})).appendTo(this.o.appendTo);this.d.overlay=b("<div></div>").attr("id",this.o.overlayId).addClass("simplemodal-overlay").css(b.extend(this.o.overlayCss,{display:"none",opacity:this.o.opacity/100,height:this.o.modal?j[0]:0,width:this.o.modal?j[1]:0,position:"fixed",left:0,top:0,zIndex:this.o.zIndex+1})).appendTo(this.o.appendTo);this.d.container=b("<div></div>").attr("id",this.o.containerId).addClass("simplemodal-container").css(b.extend({position:this.o.fixed?
"fixed":"absolute"},this.o.containerCss,{display:"none",zIndex:this.o.zIndex+2})).append(this.o.close&&this.o.closeHTML?b(this.o.closeHTML).addClass(this.o.closeClass):"").appendTo(this.o.appendTo);this.d.wrap=b("<div></div>").attr("tabIndex",-1).addClass("simplemodal-wrap").css({height:"100%",outline:0,width:"100%"}).appendTo(this.d.container);this.d.data=a.attr("id",a.attr("id")||this.o.dataId).addClass("simplemodal-data").css(b.extend(this.o.dataCss,{display:"none"})).appendTo("body");this.setContainerDimensions();
this.d.data.appendTo(this.d.wrap);(m||n)&&this.fixIE()},bindEvents:function(){var a=this;b("."+a.o.closeClass).bind("click.simplemodal",function(b){b.preventDefault();a.close()});a.o.modal&&a.o.close&&a.o.overlayClose&&a.d.overlay.bind("click.simplemodal",function(b){b.preventDefault();a.close()});l.bind("keydown.simplemodal",function(b){a.o.modal&&9===b.keyCode?a.watchTab(b):a.o.close&&a.o.escClose&&27===b.keyCode&&(b.preventDefault(),a.close())});k.bind("resize.simplemodal orientationchange.simplemodal",
function(){a.getDimensions();a.o.autoResize?a.setContainerDimensions():a.o.autoPosition&&a.setPosition();m||n?a.fixIE():a.o.modal&&(a.d.iframe&&a.d.iframe.css({height:h[0],width:h[1]}),a.d.overlay.css({height:j[0],width:j[1]}))})},unbindEvents:function(){b("."+this.o.closeClass).unbind("click.simplemodal");l.unbind("keydown.simplemodal");k.unbind(".simplemodal");this.d.overlay.unbind("click.simplemodal")},fixIE:function(){var a=this.o.position;b.each([this.d.iframe||null,!this.o.modal?null:this.d.overlay,
"fixed"===this.d.container.css("position")?this.d.container:null],function(b,f){if(f){var g=f[0].style;g.position="absolute";if(2>b)g.removeExpression("height"),g.removeExpression("width"),g.setExpression("height",'document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight + "px"'),g.setExpression("width",'document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth + "px"');else{var c,e;a&&a.constructor===
Array?(c=a[0]?"number"===typeof a[0]?a[0].toString():a[0].replace(/px/,""):f.css("top").replace(/px/,""),c=-1===c.indexOf("%")?c+' + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"':parseInt(c.replace(/%/,""))+' * ((document.documentElement.clientHeight || document.body.clientHeight) / 100) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"',a[1]&&(e="number"===typeof a[1]?
a[1].toString():a[1].replace(/px/,""),e=-1===e.indexOf("%")?e+' + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"':parseInt(e.replace(/%/,""))+' * ((document.documentElement.clientWidth || document.body.clientWidth) / 100) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"')):(c='(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"',
e='(document.documentElement.clientWidth || document.body.clientWidth) / 2 - (this.offsetWidth / 2) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"');g.removeExpression("top");g.removeExpression("left");g.setExpression("top",c);g.setExpression("left",e)}}})},focus:function(a){var d=this,a=a&&-1!==b.inArray(a,["first","last"])?a:"first",f=b(":input:enabled:visible:"+a,d.d.wrap);setTimeout(function(){0<f.length?f.focus():d.d.wrap.focus()},
10)},getDimensions:function(){var a="undefined"===typeof window.innerHeight?k.height():window.innerHeight;j=[l.height(),l.width()];h=[a,k.width()]},getVal:function(a,b){return a?"number"===typeof a?a:"auto"===a?0:0<a.indexOf("%")?parseInt(a.replace(/%/,""))/100*("h"===b?h[0]:h[1]):parseInt(a.replace(/px/,"")):null},update:function(a,b){if(!this.d.data)return!1;this.d.origHeight=this.getVal(a,"h");this.d.origWidth=this.getVal(b,"w");this.d.data.hide();a&&this.d.container.css("height",a);b&&this.d.container.css("width",
b);this.setContainerDimensions();this.d.data.show();this.o.focus&&this.focus();this.unbindEvents();this.bindEvents()},setContainerDimensions:function(){var a=m||o,d=this.d.origHeight?this.d.origHeight:b.browser.opera?this.d.container.height():this.getVal(a?this.d.container[0].currentStyle.height:this.d.container.css("height"),"h"),a=this.d.origWidth?this.d.origWidth:b.browser.opera?this.d.container.width():this.getVal(a?this.d.container[0].currentStyle.width:this.d.container.css("width"),"w"),f=this.d.data.outerHeight(!0),
g=this.d.data.outerWidth(!0);this.d.origHeight=this.d.origHeight||d;this.d.origWidth=this.d.origWidth||a;var c=this.o.maxHeight?this.getVal(this.o.maxHeight,"h"):null,e=this.o.maxWidth?this.getVal(this.o.maxWidth,"w"):null,c=c&&c<h[0]?c:h[0],e=e&&e<h[1]?e:h[1],i=this.o.minHeight?this.getVal(this.o.minHeight,"h"):"auto",d=d?this.o.autoResize&&d>c?c:d<i?i:d:f?f>c?c:this.o.minHeight&&"auto"!==i&&f<i?i:f:i,c=this.o.minWidth?this.getVal(this.o.minWidth,"w"):"auto",a=a?this.o.autoResize&&a>e?e:a<c?c:a:
g?g>e?e:this.o.minWidth&&"auto"!==c&&g<c?c:g:c;this.d.container.css({height:d,width:a});this.d.wrap.css({overflow:f>d||g>a?"auto":"visible"});this.o.autoPosition&&this.setPosition()},setPosition:function(){var a,b;a=h[0]/2-this.d.container.outerHeight(!0)/2;b=h[1]/2-this.d.container.outerWidth(!0)/2;var f="fixed"!==this.d.container.css("position")?k.scrollTop():0;this.o.position&&"[object Array]"===Object.prototype.toString.call(this.o.position)?(a=f+(this.o.position[0]||a),b=this.o.position[1]||
b):a=f+a;this.d.container.css({left:b,top:a})},watchTab:function(a){if(0<b(a.target).parents(".simplemodal-container").length){if(this.inputs=b(":input:enabled:visible:first, :input:enabled:visible:last",this.d.data[0]),!a.shiftKey&&a.target===this.inputs[this.inputs.length-1]||a.shiftKey&&a.target===this.inputs[0]||0===this.inputs.length)a.preventDefault(),this.focus(a.shiftKey?"last":"first")}else a.preventDefault(),this.focus()},open:function(){this.d.iframe&&this.d.iframe.show();b.isFunction(this.o.onOpen)?
this.o.onOpen.apply(this,[this.d]):(this.d.overlay.show(),this.d.container.show(),this.d.data.show());this.o.focus&&this.focus();this.bindEvents()},close:function(){if(!this.d.data)return!1;this.unbindEvents();if(b.isFunction(this.o.onClose)&&!this.occb)this.occb=!0,this.o.onClose.apply(this,[this.d]);else{if(this.d.placeholder){var a=b("#simplemodal-placeholder");this.o.persist?a.replaceWith(this.d.data.removeClass("simplemodal-data").css("display",this.display)):(this.d.data.hide().remove(),a.replaceWith(this.d.orig))}else this.d.data.hide().remove();
this.d.container.hide().remove();this.d.overlay.hide();this.d.iframe&&this.d.iframe.hide().remove();this.d.overlay.remove();this.d={}}}}});

View file

@ -0,0 +1,631 @@
/*
Online Python Tutor
https://github.com/pgbovine/OnlinePythonTutor/
Copyright (C) 2010-2013 Philip J. Guo (philip@pgbovine.net)
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Pre-reqs: pytutor.js and jquery.ba-bbq.min.js should be imported BEFORE this file
// backend scripts to execute (Python 2 and 3 variants, if available)
// make two copies of ../web_exec.py and give them the following names,
// then change the first line (starting with #!) to the proper version
// of the Python interpreter (i.e., Python 2 or Python 3).
// Note that your hosting provider might have stringent rules for what
// kind of scripts are allowed to execute. For instance, my provider
// (Webfaction) seems to let scripts execute only if permissions are
// something like:
// -rwxr-xr-x 1 pgbovine pgbovine 2.5K Jul 5 22:46 web_exec_py2.py*
// (most notably, only the owner of the file should have write
// permissions)
//var python2_backend_script = 'web_exec_py2.py';
//var python3_backend_script = 'web_exec_py3.py';
// uncomment below if you're running on Google App Engine using the built-in app.yaml
var python2_backend_script = 'exec';
var python3_backend_script = null;
// KRAZY experimental KODE!!! Use a custom hacked CPython interpreter
var python2crazy_backend_script = 'web_exec_py2-crazy.py';
// On Google App Engine, simply run dev_appserver.py with the
// crazy custom CPython interpreter to get 2crazy
//var python2crazy_backend_script = 'exec';
var appMode = 'edit'; // 'edit', 'display', or 'display_no_frills'
var preseededCode = null; // if you passed in a 'code=<code string>' in the URL, then set this var
var preseededCurInstr = null; // if you passed in a 'curInstr=<number>' in the URL, then set this var
var rawInputLst = []; // a list of strings inputted by the user in response to raw_input or mouse_input events
var myVisualizer = null; // singleton ExecutionVisualizer instance
function enterEditMode() {
$.bbq.pushState({ mode: 'edit' }, 2 /* completely override other hash strings to keep URL clean */);
}
function enterDisplayNoFrillsMode() {
$.bbq.pushState({ mode: 'display_no_frills' }, 2 /* completely override other hash strings to keep URL clean */);
}
var pyInputCodeMirror; // CodeMirror object that contains the input text
function setCodeMirrorVal(dat) {
pyInputCodeMirror.setValue(dat.rtrim() /* kill trailing spaces */);
$('#urlOutput,#embedCodeOutput').val('');
// also scroll to top to make the UI more usable on smaller monitors
$(document).scrollTop(0);
}
$(document).ready(function() {
$("#embedLinkDiv").hide();
pyInputCodeMirror = CodeMirror(document.getElementById('codeInputPane'), {
mode: 'python',
lineNumbers: true,
tabSize: 4,
indentUnit: 4,
// convert tab into four spaces:
extraKeys: {Tab: function(cm) {cm.replaceSelection(" ", "end");}}
});
pyInputCodeMirror.setSize(null, '420px');
// be friendly to the browser's forward and back buttons
// thanks to http://benalman.com/projects/jquery-bbq-plugin/
$(window).bind("hashchange", function(e) {
appMode = $.bbq.getState('mode'); // assign this to the GLOBAL appMode
if (appMode === undefined || appMode == 'edit') {
$("#pyInputPane").show();
$("#pyOutputPane").hide();
$("#embedLinkDiv").hide();
// destroy all annotation bubbles (NB: kludgy)
if (myVisualizer) {
myVisualizer.destroyAllAnnotationBubbles();
}
}
else if (appMode == 'display') {
$("#pyInputPane").hide();
$("#pyOutputPane").show();
$("#embedLinkDiv").show();
$('#executeBtn').html("Visualize execution");
$('#executeBtn').attr('disabled', false);
// do this AFTER making #pyOutputPane visible, or else
// jsPlumb connectors won't render properly
myVisualizer.updateOutput();
// customize edit button click functionality AFTER rendering (NB: awkward!)
$('#pyOutputPane #editCodeLinkDiv').show();
$('#pyOutputPane #editBtn').click(function() {
enterEditMode();
});
}
else if (appMode == 'display_no_frills') {
$("#pyInputPane").hide();
$("#pyOutputPane").show();
$("#embedLinkDiv").show();
}
else {
assert(false);
}
$('#urlOutput,#embedCodeOutput').val(''); // clear to avoid stale values
});
function executeCode(forceStartingInstr) {
var backend_script = null;
if ($('#pythonVersionSelector').val() == '2') {
backend_script = python2_backend_script;
}
else if ($('#pythonVersionSelector').val() == '3') {
backend_script = python3_backend_script;
}
// experimental KRAZY MODE!!!
else if ($('#pythonVersionSelector').val() == '2crazy') {
backend_script = python2crazy_backend_script;
}
if (!backend_script) {
alert('Error: This server is not configured to run Python ' + $('#pythonVersionSelector').val());
return;
}
$('#executeBtn').html("Please wait ... processing your code");
$('#executeBtn').attr('disabled', true);
$("#pyOutputPane").hide();
$("#embedLinkDiv").hide();
// set up all options in a JS object
var options = {cumulative_mode: ($('#cumulativeModeSelector').val() == 'true'),
heap_primitives: ($('#heapPrimitivesSelector').val() == 'true'),
show_only_outputs: ($('#showOnlyOutputsSelector').val() == 'true'),
py_crazy_mode: ($('#pythonVersionSelector').val() == '2crazy')};
$.get(backend_script,
{user_script : pyInputCodeMirror.getValue(),
raw_input_json: rawInputLst.length > 0 ? JSON.stringify(rawInputLst) : '',
options_json: JSON.stringify(options)},
function(dataFromBackend) {
var trace = dataFromBackend.trace;
// don't enter visualize mode if there are killer errors:
if (!trace ||
(trace.length == 0) ||
(trace[trace.length - 1].event == 'uncaught_exception')) {
if (trace.length == 1) {
var errorLineNo = trace[0].line - 1; /* CodeMirror lines are zero-indexed */
if (errorLineNo !== undefined) {
// highlight the faulting line in pyInputCodeMirror
pyInputCodeMirror.focus();
pyInputCodeMirror.setCursor(errorLineNo, 0);
pyInputCodeMirror.setLineClass(errorLineNo, null, 'errorLine');
pyInputCodeMirror.setOption('onChange', function() {
pyInputCodeMirror.setLineClass(errorLineNo, null, null); // reset line back to normal
pyInputCodeMirror.setOption('onChange', null); // cancel
});
}
alert(trace[0].exception_msg);
}
else if (trace[trace.length - 1].exception_msg) {
alert(trace[trace.length - 1].exception_msg);
}
else {
alert("Whoa, unknown error! Reload to try again, or report a bug to philip@pgbovine.net\n\n(Click the 'Generate URL' button to include a unique URL in your email bug report.)");
}
$('#executeBtn').html("Visualize execution");
$('#executeBtn').attr('disabled', false);
}
else {
var startingInstruction = 0;
// only do this at most ONCE, and then clear out preseededCurInstr
if (preseededCurInstr && preseededCurInstr < trace.length) { // NOP anyways if preseededCurInstr is 0
startingInstruction = preseededCurInstr;
preseededCurInstr = null;
}
// forceStartingInstr overrides everything else
if (forceStartingInstr !== undefined) {
startingInstruction = forceStartingInstr;
}
myVisualizer = new ExecutionVisualizer('pyOutputPane',
dataFromBackend,
{startingInstruction: startingInstruction,
updateOutputCallback: function() {$('#urlOutput,#embedCodeOutput').val('');},
// tricky: selector 'true' and 'false' values are strings!
disableHeapNesting: ($('#heapPrimitivesSelector').val() == 'true'),
drawParentPointers: ($('#drawParentPointerSelector').val() == 'true'),
textualMemoryLabels: ($('#textualMemoryLabelsSelector').val() == 'true'),
showOnlyOutputs: ($('#showOnlyOutputsSelector').val() == 'true'),
executeCodeWithRawInputFunc: executeCodeWithRawInput,
// undocumented experimental modes:
pyCrazyMode: ($('#pythonVersionSelector').val() == '2crazy'),
//allowEditAnnotations: true,
});
// set keyboard bindings
// VERY IMPORTANT to clear and reset this every time or
// else the handlers might be bound multiple times
$(document).unbind('keydown');
$(document).keydown(function(k) {
if (k.keyCode == 37) { // left arrow
if (myVisualizer.stepBack()) {
k.preventDefault(); // don't horizontally scroll the display
}
}
else if (k.keyCode == 39) { // right arrow
if (myVisualizer.stepForward()) {
k.preventDefault(); // don't horizontally scroll the display
}
}
});
// also scroll to top to make the UI more usable on smaller monitors
$(document).scrollTop(0);
$.bbq.pushState({ mode: 'display' }, 2 /* completely override other hash strings to keep URL clean */);
}
},
"json");
}
function executeCodeFromScratch() {
// reset these globals
rawInputLst = [];
executeCode();
}
function executeCodeWithRawInput(rawInputStr, curInstr) {
enterDisplayNoFrillsMode();
// set some globals
rawInputLst.push(rawInputStr);
executeCode(curInstr);
}
$("#executeBtn").attr('disabled', false);
$("#executeBtn").click(executeCodeFromScratch);
// canned examples
$("#tutorialExampleLink").click(function() {
$.get("example-code/py_tutorial.txt", setCodeMirrorVal);
return false;
});
$("#strtokExampleLink").click(function() {
$.get("example-code/strtok.txt", setCodeMirrorVal);
return false;
});
$("#listCompLink").click(function() {
$.get("example-code/list-comp.txt", setCodeMirrorVal);
return false;
});
$("#fibonacciExampleLink").click(function() {
$.get("example-code/fib.txt", setCodeMirrorVal);
return false;
});
$("#memoFibExampleLink").click(function() {
$.get("example-code/memo_fib.txt", setCodeMirrorVal);
return false;
});
$("#factExampleLink").click(function() {
$.get("example-code/fact.txt", setCodeMirrorVal);
return false;
});
$("#filterExampleLink").click(function() {
$.get("example-code/filter.txt", setCodeMirrorVal);
return false;
});
$("#insSortExampleLink").click(function() {
$.get("example-code/ins_sort.txt", setCodeMirrorVal);
return false;
});
$("#aliasExampleLink").click(function() {
$.get("example-code/aliasing.txt", setCodeMirrorVal);
return false;
});
$("#happyExampleLink").click(function() {
$.get("example-code/happy.txt", setCodeMirrorVal);
return false;
});
$("#newtonExampleLink").click(function() {
$.get("example-code/sqrt.txt", setCodeMirrorVal);
return false;
});
$("#oopSmallExampleLink").click(function() {
$.get("example-code/oop_small.txt", setCodeMirrorVal);
return false;
});
$("#mapExampleLink").click(function() {
$.get("example-code/map.txt", setCodeMirrorVal);
return false;
});
$("#rawInputExampleLink").click(function() {
$.get("example-code/raw_input.txt", setCodeMirrorVal);
return false;
});
$("#oop1ExampleLink").click(function() {
$.get("example-code/oop_1.txt", setCodeMirrorVal);
return false;
});
$("#oop2ExampleLink").click(function() {
$.get("example-code/oop_2.txt", setCodeMirrorVal);
return false;
});
$("#inheritanceExampleLink").click(function() {
$.get("example-code/oop_inherit.txt", setCodeMirrorVal);
return false;
});
$("#sumExampleLink").click(function() {
$.get("example-code/sum.txt", setCodeMirrorVal);
return false;
});
$("#pwGcdLink").click(function() {
$.get("example-code/wentworth_gcd.txt", setCodeMirrorVal);
return false;
});
$("#pwSumListLink").click(function() {
$.get("example-code/wentworth_sumList.txt", setCodeMirrorVal);
return false;
});
$("#towersOfHanoiLink").click(function() {
$.get("example-code/towers_of_hanoi.txt", setCodeMirrorVal);
return false;
});
$("#pwTryFinallyLink").click(function() {
$.get("example-code/wentworth_try_finally.txt", setCodeMirrorVal);
return false;
});
$("#sumCubesLink").click(function() {
$.get("example-code/sum-cubes.txt", setCodeMirrorVal);
return false;
});
$("#decoratorsLink").click(function() {
$.get("example-code/decorators.txt", setCodeMirrorVal);
return false;
});
$("#genPrimesLink").click(function() {
$.get("example-code/gen_primes.txt", setCodeMirrorVal);
return false;
});
$("#genExprLink").click(function() {
$.get("example-code/genexpr.txt", setCodeMirrorVal);
return false;
});
$('#closure1Link').click(function() {
$.get("example-code/closures/closure1.txt", setCodeMirrorVal);
return false;
});
$('#closure2Link').click(function() {
$.get("example-code/closures/closure2.txt", setCodeMirrorVal);
return false;
});
$('#closure3Link').click(function() {
$.get("example-code/closures/closure3.txt", setCodeMirrorVal);
return false;
});
$('#closure4Link').click(function() {
$.get("example-code/closures/closure4.txt", setCodeMirrorVal);
return false;
});
$('#closure5Link').click(function() {
$.get("example-code/closures/closure5.txt", setCodeMirrorVal);
return false;
});
$('#lambdaParamLink').click(function() {
$.get("example-code/closures/lambda-param.txt", setCodeMirrorVal);
return false;
});
$('#tortureLink').click(function() {
$.get("example-code/closures/student-torture.txt", setCodeMirrorVal);
return false;
});
$('#aliasing1Link').click(function() {
$.get("example-code/aliasing/aliasing1.txt", setCodeMirrorVal);
return false;
});
$('#aliasing2Link').click(function() {
$.get("example-code/aliasing/aliasing2.txt", setCodeMirrorVal);
return false;
});
$('#aliasing3Link').click(function() {
$.get("example-code/aliasing/aliasing3.txt", setCodeMirrorVal);
return false;
});
$('#aliasing4Link').click(function() {
$.get("example-code/aliasing/aliasing4.txt", setCodeMirrorVal);
return false;
});
$('#aliasing5Link').click(function() {
$.get("example-code/aliasing/aliasing5.txt", setCodeMirrorVal);
return false;
});
$('#aliasing6Link').click(function() {
$.get("example-code/aliasing/aliasing6.txt", setCodeMirrorVal);
return false;
});
$('#aliasing7Link').click(function() {
$.get("example-code/aliasing/aliasing7.txt", setCodeMirrorVal);
return false;
});
$('#aliasing8Link').click(function() {
$.get("example-code/aliasing/aliasing8.txt", setCodeMirrorVal);
return false;
});
$('#ll1Link').click(function() {
$.get("example-code/linked-lists/ll1.txt", setCodeMirrorVal);
return false;
});
$('#ll2Link').click(function() {
$.get("example-code/linked-lists/ll2.txt", setCodeMirrorVal);
return false;
});
$('#sumListLink').click(function() {
$.get("example-code/sum-list.txt", setCodeMirrorVal);
return false;
});
$('#varargsLink').click(function() {
$.get("example-code/varargs.txt", setCodeMirrorVal);
return false;
});
$('#forElseLink').click(function() {
$.get("example-code/for-else.txt", setCodeMirrorVal);
return false;
});
$('#nonlocalLink').click(function() {
$.get("example-code/nonlocal.txt", setCodeMirrorVal);
return false;
});
// handle hash parameters passed in when loading the page
preseededCode = $.bbq.getState('code');
if (preseededCode) {
setCodeMirrorVal(preseededCode);
}
else {
// select a canned example on start-up:
$("#aliasExampleLink").trigger('click');
}
// parse query string options ...
// ugh, ugly tristate due to the possibility of them being undefined
var cumulativeState = $.bbq.getState('cumulative');
if (cumulativeState !== undefined) {
$('#cumulativeModeSelector').val(cumulativeState);
}
var heapPrimitivesState = $.bbq.getState('heapPrimitives');
if (heapPrimitivesState !== undefined) {
$('#heapPrimitivesSelector').val(heapPrimitivesState);
}
var drawParentPointerState = $.bbq.getState('drawParentPointers');
if (drawParentPointerState !== undefined) {
$('#drawParentPointerSelector').val(drawParentPointerState);
}
var textRefsState = $.bbq.getState('textReferences');
if (textRefsState !== undefined) {
$('#textualMemoryLabelsSelector').val(textRefsState);
}
var showOnlyOutputsState = $.bbq.getState('showOnlyOutputs');
if (showOnlyOutputsState !== undefined) {
$('#showOnlyOutputsSelector').val(showOnlyOutputsState);
}
var pyState = $.bbq.getState('py');
if (pyState !== undefined) {
$('#pythonVersionSelector').val(pyState);
}
appMode = $.bbq.getState('mode'); // assign this to the GLOBAL appMode
if ((appMode == "display") && preseededCode /* jump to display only with pre-seeded code */) {
preseededCurInstr = Number($.bbq.getState('curInstr'));
$("#executeBtn").trigger('click');
}
else {
if (appMode === undefined) {
// default mode is 'edit', don't trigger a "hashchange" event
appMode = 'edit';
}
else {
// fail-soft by killing all passed-in hashes and triggering a "hashchange"
// event, which will then go to 'edit' mode
$.bbq.removeState();
}
}
// log a generic AJAX error handler
$(document).ajaxError(function() {
alert("Server error (possibly due to memory/resource overload). Report a bug to philip@pgbovine.net\n\n(Click the 'Generate URL' button to include a unique URL in your email bug report.)");
$('#executeBtn').html("Visualize execution");
$('#executeBtn').attr('disabled', false);
});
// redraw connector arrows on window resize
$(window).resize(function() {
if (appMode == 'display') {
myVisualizer.redrawConnectors();
}
});
$('#genUrlBtn').bind('click', function() {
var myArgs = {code: pyInputCodeMirror.getValue(),
mode: appMode,
cumulative: $('#cumulativeModeSelector').val(),
heapPrimitives: $('#heapPrimitivesSelector').val(),
drawParentPointers: $('#drawParentPointerSelector').val(),
textReferences: $('#textualMemoryLabelsSelector').val(),
showOnlyOutputs: $('#showOnlyOutputsSelector').val(),
py: $('#pythonVersionSelector').val()};
if (appMode == 'display') {
myArgs.curInstr = myVisualizer.curInstr;
}
var urlStr = $.param.fragment(window.location.href, myArgs, 2 /* clobber all */);
$('#urlOutput').val(urlStr);
});
$('#genEmbedBtn').bind('click', function() {
assert(appMode == 'display');
var myArgs = {code: pyInputCodeMirror.getValue(),
cumulative: $('#cumulativeModeSelector').val(),
heapPrimitives: $('#heapPrimitivesSelector').val(),
drawParentPointers: $('#drawParentPointerSelector').val(),
textReferences: $('#textualMemoryLabelsSelector').val(),
showOnlyOutputs: $('#showOnlyOutputsSelector').val(),
py: $('#pythonVersionSelector').val(),
curInstr: myVisualizer.curInstr,
};
var embedUrlStr = $.param.fragment('http://pythontutor.com/iframe-embed.html', myArgs, 2 /* clobber all */);
var iframeStr = '<iframe width="800" height="500" frameborder="0" src="' + embedUrlStr + '"> </iframe>';
$('#embedCodeOutput').val(iframeStr);
});
});

View file

@ -0,0 +1,118 @@
/*
Online Python Tutor
https://github.com/pgbovine/OnlinePythonTutor/
Copyright (C) 2010-2013 Philip J. Guo (philip@pgbovine.net)
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Pre-reqs: pytutor.js and jquery.ba-bbq.min.js should be imported BEFORE this file
var backend_script = 'exec'; // URL of backend script, which must eventually call pg_logger.py
var myVisualizer = null; // singleton ExecutionVisualizer instance
var lessonScript = null;
var metadataJSON = null;
function parseLessonFile(dat) {
var toks = dat.split('======');
// globals
lessonScript = toks[0].rtrim();
metadataJSON = $.parseJSON(toks[1]);
$('#lessonTitle').html(metadataJSON.title);
$('#lessonDescription').html(metadataJSON.description);
document.title = metadataJSON.title + ' - Online Python Tutor (v3)';
$.get(backend_script,
{user_script : lessonScript},
function(dataFromBackend) {
var trace = dataFromBackend.trace;
// don't enter visualize mode if there are killer errors:
if (!trace ||
(trace.length == 0) ||
(trace[trace.length - 1].event == 'uncaught_exception')) {
if (trace.length == 1) {
alert(trace[0].exception_msg);
}
else {
alert("Whoa, unknown error! Reload to try again, or report a bug to philip@pgbovine.net\n\n(Click the 'Generate URL' button to include a unique URL in your email bug report.)");
}
}
else {
myVisualizer = new ExecutionVisualizer('pyOutputPane',
dataFromBackend,
{embeddedMode: true,
updateOutputCallback: updateLessonNarration});
myVisualizer.updateOutput();
}
},
"json");
}
function updateLessonNarration(myViz) {
var curInstr = myViz.curInstr;
assert(metadataJSON);
var annotation = metadataJSON[curInstr + 1]; // adjust for indexing diffs
if (annotation) {
$('#lessonNarration').html(annotation);
}
else {
$('#lessonNarration').html('');
}
// hack from John DeNero to ensure that once a div grows it height, it
// never shrinks again
$('#lessonNarration').css('min-height', $('#lessonNarration').css('height'));
}
$(document).ready(function() {
//$.get("lessons/aliasing.txt", parseLessonFile);
//$.get("lessons/dive-into-python-311.txt", parseLessonFile);
//$.get("lessons/for-else.txt", parseLessonFile);
$.get("lessons/varargs.txt", parseLessonFile);
// log a generic AJAX error handler
$(document).ajaxError(function() {
alert("Server error (possibly due to memory/resource overload).");
});
// redraw connector arrows on window resize
$(window).resize(function() {
if (myVisualizer) {
myVisualizer.redrawConnectors();
}
});
});

File diff suppressed because it is too large Load diff