Loading calc.html +21 −5 Original line number Diff line number Diff line Loading @@ -65,10 +65,11 @@ height: 30px; } .trail-op { min-width: 10px; min-width: 40px; text-align: right; } .trail-num { padding-left: 10px; min-width: 10px; text-align: left; } Loading @@ -81,11 +82,11 @@ <body> <div id="container"> <div id="stack"> <p>Stack</p> <p>Stack <a title="clear stack" id="clear-stack" href="#">Clear Stack</a></p> <div id="stack-content"></div> </div> <div id="keyboard"> <p>Keyboard</p> <p>Keyboard <a title="reset RPN calculator" id="reset" href="#">Reset All</a></p> <div class="keyboard"> <table> <tr> Loading Loading @@ -128,7 +129,7 @@ </div> </div> <div id="trail"> <p>Trail</p> <p>Trail <a title="clear trail" id="clear-trail" href="#">Clear Trail</a></p> <div id="trail-content"></div> </div> </div> Loading Loading @@ -393,8 +394,8 @@ trNode.append($('<td>').text(trailNum).addClass("trail-num")); trailTable.append(trNode); } if (trailSize > 0) { $("#trail-content").children().remove(); if (trailSize > 0) { $("#trail-content").append(trailTable).scrollTop(900); // TODO how to scroll to bottom? } }; Loading @@ -420,6 +421,21 @@ updateUI(rpnCalculator); } }); $('#clear-trail').click(function (evt) { rpnCalculator.clearTrail(); updateUI(rpnCalculator); return false; }); $('#clear-stack').click(function (evt) { rpnCalculator.clearStack(); updateUI(rpnCalculator); return false; }); $('#reset').click(function (evt) { rpnCalculator.reset(); updateUI(rpnCalculator); return false; }); }()); </script> </body> Loading fifo.js +19 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,9 @@ var fifo = function () { this.pop = function () { return this.data.shift(); }; this.clear = function () { this.data = []; }; }; /** Loading @@ -40,6 +43,9 @@ var fifo = function () { this.pop = function () { return this.data.shift(); }; this.clear = function () { this.data = []; }; }; const testFIFO = function () { Loading Loading @@ -68,9 +74,21 @@ var fifo = function () { console.assert(q.pop() === 3); console.assert(q.pop() === 4); }; const testClearFunction = function () { q = new BoundedQueue(3); q.push(1); q.push(2); q.clear(); console.assert(q.pop() === undefined); console.assert(q.data.length === 0); }; const runAllTests = function () { testFIFO(); testClearFunction(); }; // run all tests testFIFO(); runAllTests(); return { Queue: Queue, Loading fsm.js +13 −0 Original line number Diff line number Diff line Loading @@ -433,6 +433,19 @@ var fsm = function () { this.clearErrorMsg(); return this.currentState; }; this.clearTrail = function () { this.trail.clear(); }; this.clearStack = function () { this.numberStack = []; }; this.reset = function () { this.currentState = stateIdle; this.numberStack = []; this.currentNumber = ""; this.lastError = null; this.trail = new fifo.BoundedQueue(trailHistorySize); }; const runTests = function () { testChangeNumberString(); Loading operational +13 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,18 @@ the parent DOM. * current :entry: ** ** 2017-01-27 add a reset button. browser refresh button is not always easily accessible, esp on mobile. ** 2017-01-27 design a layout for mobile. - layout on mobile: stack keyboard trail - stack and trail has smaller height as well. - 200+300+200=700 apply css when width < 720. ** 2017-01-27 make trail work - when is trail being updated? - when a number is committed to number stack. return. Loading Loading @@ -98,6 +109,7 @@ trail cache. it's not a problem. - DONE make DUP and SWP work - make trail work * done :entry: ** 2017-01-27 add a reset button. browser refresh button is not always easily accessible, esp on mobile. ** 2017-01-27 stack, trail: overflow problem. - when there is not enough room, show scrollbar. - always show the title section. Loading Loading
calc.html +21 −5 Original line number Diff line number Diff line Loading @@ -65,10 +65,11 @@ height: 30px; } .trail-op { min-width: 10px; min-width: 40px; text-align: right; } .trail-num { padding-left: 10px; min-width: 10px; text-align: left; } Loading @@ -81,11 +82,11 @@ <body> <div id="container"> <div id="stack"> <p>Stack</p> <p>Stack <a title="clear stack" id="clear-stack" href="#">Clear Stack</a></p> <div id="stack-content"></div> </div> <div id="keyboard"> <p>Keyboard</p> <p>Keyboard <a title="reset RPN calculator" id="reset" href="#">Reset All</a></p> <div class="keyboard"> <table> <tr> Loading Loading @@ -128,7 +129,7 @@ </div> </div> <div id="trail"> <p>Trail</p> <p>Trail <a title="clear trail" id="clear-trail" href="#">Clear Trail</a></p> <div id="trail-content"></div> </div> </div> Loading Loading @@ -393,8 +394,8 @@ trNode.append($('<td>').text(trailNum).addClass("trail-num")); trailTable.append(trNode); } if (trailSize > 0) { $("#trail-content").children().remove(); if (trailSize > 0) { $("#trail-content").append(trailTable).scrollTop(900); // TODO how to scroll to bottom? } }; Loading @@ -420,6 +421,21 @@ updateUI(rpnCalculator); } }); $('#clear-trail').click(function (evt) { rpnCalculator.clearTrail(); updateUI(rpnCalculator); return false; }); $('#clear-stack').click(function (evt) { rpnCalculator.clearStack(); updateUI(rpnCalculator); return false; }); $('#reset').click(function (evt) { rpnCalculator.reset(); updateUI(rpnCalculator); return false; }); }()); </script> </body> Loading
fifo.js +19 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,9 @@ var fifo = function () { this.pop = function () { return this.data.shift(); }; this.clear = function () { this.data = []; }; }; /** Loading @@ -40,6 +43,9 @@ var fifo = function () { this.pop = function () { return this.data.shift(); }; this.clear = function () { this.data = []; }; }; const testFIFO = function () { Loading Loading @@ -68,9 +74,21 @@ var fifo = function () { console.assert(q.pop() === 3); console.assert(q.pop() === 4); }; const testClearFunction = function () { q = new BoundedQueue(3); q.push(1); q.push(2); q.clear(); console.assert(q.pop() === undefined); console.assert(q.data.length === 0); }; const runAllTests = function () { testFIFO(); testClearFunction(); }; // run all tests testFIFO(); runAllTests(); return { Queue: Queue, Loading
fsm.js +13 −0 Original line number Diff line number Diff line Loading @@ -433,6 +433,19 @@ var fsm = function () { this.clearErrorMsg(); return this.currentState; }; this.clearTrail = function () { this.trail.clear(); }; this.clearStack = function () { this.numberStack = []; }; this.reset = function () { this.currentState = stateIdle; this.numberStack = []; this.currentNumber = ""; this.lastError = null; this.trail = new fifo.BoundedQueue(trailHistorySize); }; const runTests = function () { testChangeNumberString(); Loading
operational +13 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,18 @@ the parent DOM. * current :entry: ** ** 2017-01-27 add a reset button. browser refresh button is not always easily accessible, esp on mobile. ** 2017-01-27 design a layout for mobile. - layout on mobile: stack keyboard trail - stack and trail has smaller height as well. - 200+300+200=700 apply css when width < 720. ** 2017-01-27 make trail work - when is trail being updated? - when a number is committed to number stack. return. Loading Loading @@ -98,6 +109,7 @@ trail cache. it's not a problem. - DONE make DUP and SWP work - make trail work * done :entry: ** 2017-01-27 add a reset button. browser refresh button is not always easily accessible, esp on mobile. ** 2017-01-27 stack, trail: overflow problem. - when there is not enough room, show scrollbar. - always show the title section. Loading