Permalink
Browse files

Merge remote branch 'upstream/master' into polynomials

  • Loading branch information...
jeffdyer committed Jan 19, 2012
2 parents 906de7f + 790708d commit f91220cab37b6e59ea5b7d7f376f53451ec4047d
Showing 342 changed files with 21,956 additions and 3,746 deletions.
View
@@ -0,0 +1 @@
+exercises-packed
View
@@ -1,6 +1,6 @@
# Khan Academy Exercises
-Copyright 2011 Khan Academy
+Copyright 2012 Khan Academy
The exercise framework is [MIT licensed](http://en.wikipedia.org/wiki/MIT_License).
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -19,6 +19,7 @@ MathJax.Hub.Config({
Definitions: {
macros: {
lrsplit: "LRSplit",
+ cancel: "Cancel",
lcm: ["NamedOp", 0]
}
},
@@ -33,6 +34,9 @@ MathJax.Hub.Config({
frac.denomalign = MathJax.ElementJax.mml.ALIGN.RIGHT;
frac.linethickness = "0em";
this.Push( frac );
+ },
+ Cancel: function( name ) {
+ this.Push( MathJax.ElementJax.mml.menclose( this.ParseArg( name ) ).With({ notation: MathJax.ElementJax.mml.NOTATION.UPDIAGONALSTRIKE }) );
}
}
}
View
@@ -0,0 +1,117 @@
+begin
+ require 'rubygems'
+ require 'nokogiri'
+ require 'execjs'
+ require 'uglifier'
+ require 'fileutils'
+rescue LoadError
+ puts
+ puts "-" * 78
+ puts "Oops! Some gems are missing; please run:"
+ puts " sudo gem install nokogiri uglifier therubyracer"
+ puts "-" * 78
+ puts
+ exit 1
+end
+
+begin
+ require 'v8'
+rescue LoadError
+ puts
+ puts "-" * 78
+ puts "Warning! You don't have therubyracer installed, packing might be slow. Try:"
+ puts " sudo gem install therubyracer"
+ puts
+ puts "If you prefer another JS runtime (https://github.com/sstephenson/execjs),"
+ puts "be aware that this script is much faster (around 50x speedup) using"
+ puts "therubyracer, which is based on Chrome's V8 engine."
+ puts "-" * 78
+ puts
+end
+
+JSHINT_ENABLED = false
+JSHINT_OPTIONS = {
+ :laxbreak => true,
+ :eqeqeq => true,
+ :loopfunc => true,
+}
+
+def jshint(js)
+ return unless JSHINT_ENABLED
+ if !@jshint.call("JSHINT", js, JSHINT_OPTIONS)
+ @jshint.eval("JSHINT.errors").each do |err|
+ break if err["reason"] == "Expected ')' to match '(' from line 1 and instead saw ','."
+ # puts "-- #{js}"
+ puts "-- #{err["reason"]} (#{err["line"]}:#{err["character"]})"
+ puts "-- > #{(err["evidence"] || "").strip}"
+ puts "--"
+ end
+ end
+end
+
+# All paths are relative to khan-exercises/ root
+Dir.chdir(File.join(File.dirname(__FILE__), ".."))
+
+@uglifier = Uglifier.new(:copyright => false) # Discard all comments
+@jshint = ExecJS.compile(File.read("build/jshint.js"))
+
+FileUtils.mkdir_p("exercises-packed")
+
+Dir["exercises/*.html"].each do |filename|
+ packed_filename = filename.gsub(/^exercises\//, "exercises-packed/")
+ next if File.exist?(packed_filename) && File.mtime(packed_filename) > File.mtime(filename)
+
+ puts filename
+ cant = 0
+ doc = Nokogiri::HTML::Document.parse(File.read(filename))
+
+ doc.css("var").each do |var|
+ if var.elements.any?
+ puts "-- error: JS element has children"
+ puts var.inner_html
+ exit 1
+ end
+
+ next if var.content !~ /\S/ # only whitespace
+
+ jshint("return (#{var.content});")
+ exp = "(#{var.content})"
+ var.content = @uglifier.compile(exp)
+ end
+
+ doc.css(".graphie", "div.guess", "div.show-guess", "div.show-guess-solutionarea").each do |graphie|
+ if graphie.elements.any?
+ puts "-- error: JS element has children"
+ exit 1
+ end
+
+ js = graphie.content
+ graphie.content = @uglifier.compile(js)
+ end
+
+ doc.css("div.validator-function").each do |validator|
+ if validator.elements.any?
+ puts "-- error: JS element has children"
+ exit 1
+ end
+
+ # need to wrap validator-function content in a function, so uglifier
+ # doesn't get confused by the estranged 'return' statement
+ js = "(function(){" + validator.content + "})()"
+ uglified = @uglifier.compile(js)
+ # strip out the anonymous function wrapper to put things back the way they were
+ validator.content = uglified[ /^\(function\(\)\{(.*)\}\)\(\)$/, 1 ]
+ end
+
+ %w[data-ensure data-if data-else-if].each do |data_attr|
+ doc.css("[#{data_attr}]").each do |el|
+ jshint("return (#{el[data_attr]});")
+ js = el[data_attr]
+ el[data_attr] = @uglifier.compile(js)
+ end
+ end
+
+ File.open(packed_filename, "w") do |f|
+ f.write doc.to_html
+ end
+end
View
@@ -13,6 +13,10 @@ var { font-style: normal; }
#answer_area ul { list-style: none; }
#answer_area li { margin: 14px 0; }
+#extras li { display: inline; }
+#extras li:before { content: "| "; }
+#extras li:first-child:before { content: ""; }
+
#answer_area #check-answer-results { overflow: hidden; margin: 5px 0; }
#answer_area #check-answer-results .check-answer-message { font-size: 12px; line-height: 20px; margin: 0; }
#sad, #happy { float: left; margin: 0 6px 4px 0; }
@@ -112,15 +116,14 @@ var, div.graphie { white-space: pre; }
}
.user-activity {
- margin: 5px;
+ margin: 8px;
padding: 2px 5px;
border: 1px solid #999;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
float: left;
cursor: pointer;
- /*height: 25px;*/
color: white;
}
@@ -307,11 +310,9 @@ div.timeline-total {
}
#warning-bar {
- background: red;
width: 100%;
height: 35px;
text-align: center;
- color: #eee;
font-size: 15px;
display: none;
}
@@ -328,15 +329,28 @@ div.timeline-total {
position: relative;
}
-#warning-bar a {
- color: #eee;
-}
-
#warning-bar-content a {
- color: #eee;
text-decoration: underline;
}
+#warning-bar.error {
+ background-color: red;
+ color: #eee;
+}
+
+#warning-bar.error a {
+ color: #eee;
+}
+
+#warning-bar.warning {
+ background-color: #f5e722;
+ color: #222;
+}
+
+#warning-bar.warning a {
+ color: #222;
+}
+
/* Faux table styles that allow revealing data row by row in hints */
.fake_header > span {
@@ -431,6 +445,8 @@ div.timeline-total {
border: 1px solid #ccc;
border-bottom: 1px solid #aaa;
padding: 13px;
+ position: relative;
+ z-index: 2;
box-shadow: 0 1px 2px #ccc;
-moz-box-shadow: 0 1px 2px #ccc;
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html data-require="math graphie graphie-helpers">
<head>
- <meta charset="UTF-8" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Absolute value</title>
<script src="../khan-exercise.js"></script>
</head>
<body>
<div class="exercise">
- <div class="vars" data-ensure="SIGN == &quot;&quot; || INT != 0 || FRAC != 0">
+ <div class="vars" data-ensure="SIGN === &quot;&quot; || INT !== 0 || FRAC !== 0">
<var id="INT">rand(5) > 0 ? randRange( 1, 9 ) : 0</var>
<var id="FRAC">rand(3) > 0 ? "." + randRange(1, 9) : ""</var>
<var id="SIGN">randFromArray(["", "-"])</var>
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html data-require="math math-format">
<head>
- <meta charset="UTF-8" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Absolute value equations</title>
<script src="../khan-exercise.js"></script>
</head>
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html data-require="math word-problems spin graphie graphie-helpers-arithmetic">
<head>
- <meta charset="UTF-8" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Adding and subtracting decimals word problems</title>
<script src="../khan-exercise.js"></script>
</head>
@@ -33,7 +33,7 @@
<p class="question">How much did <var>person(1)</var> need to pay for <var>his(1)</var> produce?</p></div>
- <div class="solution"><var>fruit_1+fruit_2</var></div>
+ <div class="solution" data-forms="dollar"><var>fruit_1+fruit_2</var></div>
<div class="hints">
<p>To find the total amount <var>person(1)</var> needs to pay, we need to add the price of the <var>plural(fruit(1))</var> and the price of the <var>plural(fruit(2))</var>.</p>
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html data-require="math math-format">
<head>
- <meta charset="UTF-8" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Adding and subtracting fractions</title>
<script src="../khan-exercise.js"></script>
</head>
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html data-require="math graphie graphie-helpers">
<head>
- <meta charset="UTF-8" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Adding and subtracting negative numbers</title>
<script src="../khan-exercise.js"></script>
</head>
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html data-require="math math-format polynomials functional">
<head>
- <meta charset="UTF-8" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Adding and subtracting polynomials</title>
<script src="../khan-exercise.js"></script>
<script type="text/javascript">
@@ -42,9 +42,9 @@
<var id="NON_ZERO_INDICES">randRangeUniqueNonZero( 0, MAX_DEGREE, randRange(2, 3) ).sort().reverse()</var>
<var id="POL_1, POL_2" data-ensure="POL_1.add( POL_2 ).getNumberOfTerms() >= 1 && POL_1.subtract( POL_2 ).getNumberOfTerms() >= 1">tabulate( function() {
var coefs = [];
- for ( var i = 0; i <= MAX_DEGREE; i++ ) {
+ for ( var i = 0; i &lt;= MAX_DEGREE; i++ ) {
var value = 0;
- for ( var j = 0; j < NON_ZERO_INDICES.length; j++ ) {
+ for ( var j = 0; j &lt; NON_ZERO_INDICES.length; j++ ) {
if ( i === NON_ZERO_INDICES[ j ] ) {
value = randRangeNonZero( -7, 7 );
break;
@@ -103,7 +103,7 @@
</div>
<div>
<p>Identify like terms.</p>
- <p><code><span data-each="[ POL_1, POL_2 ] as POL"><span data-each="NON_ZERO_INDICES as n, index" data-unwrap><var>( POL.coefs[ index ] < 0 ) ? "-" : ( n === 0 && POL === POL_1 ) ? "" : "+"</var>\color{<var>COLORS[ n ]</var>}{<var>abs( POL.coefs[ index ] ) === 1 ? "" : abs( POL.coefs[ index ] )</var><var>X</var>^<var>index</var>}</span></span></code></p>
+ <p><code><span data-each="[ POL_1, POL_2 ] as POL"><span data-each="NON_ZERO_INDICES as n, index" data-unwrap><var>( POL.coefs[ index ] &lt; 0 ) ? "-" : ( n === 0 && POL === POL_1 ) ? "" : "+"</var>\color{<var>COLORS[ n ]</var>}{<var>abs( POL.coefs[ index ] ) === 1 ? "" : abs( POL.coefs[ index ] )</var><var>X</var>^<var>index</var>}</span></span></code></p>
</div>
<div>
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html data-require="math math-format expressions">
<head>
- <meta charset="UTF-8" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Adding and subtracting radicals</title>
<script src="../khan-exercise.js"></script>
</head>
@@ -1,36 +1,56 @@
<!DOCTYPE html>
<html data-require="math graphie graphie-helpers-arithmetic">
<head>
- <meta charset="UTF-8" />
- <title>Adding decimals</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Adding decimals 2</title>
<script src="../khan-exercise.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="A">randRange( 100, 999 )</var>
<var id="B">randRange( 100, 999 )</var>
-
- <var id="A_DECIMAL">randRange( 1, 3 )</var>
- <var id="B_DECIMAL">randRange( 1, 3 )</var>
-
- <var id="A_FLOAT">A / pow( 10, A_DECIMAL )</var>
- <var id="B_FLOAT">B / pow( 10, B_DECIMAL )</var>
+ <div data-ensure="B_DECIMAL !== A_DECIMAL">
+ <var id="A_DECIMAL">randRangeWeighted( 0, 3, 0, 0.1 )</var>
+ <var id="B_DECIMAL">randRange( 1, 3 )</var>
+ </div>
+ <var id="NEW_A">A * ( B_DECIMAL &gt; A_DECIMAL ? pow( 10, B_DECIMAL - A_DECIMAL ) : 1)</var>
+ <var id="NEW_B">B * ( A_DECIMAL &gt; B_DECIMAL ? pow( 10, A_DECIMAL - B_DECIMAL ) : 1)</var>
+ <var id="A_DIGITS">
+ (function() {
+ var result = digits( NEW_A );
+ for ( var i = 0; i &lt; ( A_DECIMAL - B_DECIMAL ) || result.length &lt; A_DECIMAL + 1; i++ ) {
+ result.push( 0 );
+ }
+ return result;
+ })()</var>
+ <var id="B_DIGITS">
+ (function() {
+ var result = digits( NEW_B );
+ for ( var i = 0; i &lt; ( B_DECIMAL - A_DECIMAL ) || result.length &lt; B_DECIMAL + 1; i++ ) {
+ result.push( 0 );
+ }
+ return result;
+ })()</var>
+ <var id="DUMMY">[]</var>
</div>
<div class="problems">
<div>
- <p class="question"><code>\Huge{<var>A_FLOAT.toFixed( A_DECIMAL )</var> + <var>B_FLOAT.toFixed( B_DECIMAL )</var> = {?}}</code></p>
- <div class="solution" data-type="decimal"><var>A_FLOAT + B_FLOAT</var></div>
+ <p class="question"><code>\Huge{<var>roundTo( A_DECIMAL, A * pow( 10, -A_DECIMAL ) ).toFixed( A_DECIMAL )</var> + <var>roundTo( B_DECIMAL, B * pow( 10, -B_DECIMAL ) ).toFixed( B_DECIMAL )</var> = {?}}</code></p>
+ <p class="solution" data-type="decimal"><var>A / pow( 10, A_DECIMAL ) + B / pow( 10, B_DECIMAL )</var></p>
+ <div class="graphie" id="numbers">
+ graph.adder = new Adder( NEW_A, NEW_B, A_DIGITS, B_DIGITS );
+ DUMMY = Array( graph.adder.getNumHints() );
+ </div>
</div>
</div>
<div class="hints">
- <div class="graphie" id="numbers">
- graph.adder = new DecimalAdder( A, A_DECIMAL, B, B_DECIMAL );
+ <div class="graphie" data-update="numbers">
graph.adder.show();
- graph.adder.showDecimals();
+ graph.adder.showDecimals( A_DECIMAL, B_DECIMAL );
</div>
- <div class="graphie" data-update="numbers" data-each="DecimalAdder.numHintsFor( A, A_DECIMAL, B, B_DECIMAL ) times">
+ <div class="graphie" data-update="numbers" data-each="DUMMY as dummy">
graph.adder.showHint();
</div>
</div>
Oops, something went wrong.

0 comments on commit f91220c

Please sign in to comment.