Commit 2a3d40a4 authored by Yuanle Song's avatar Yuanle Song
Browse files

WIP add help page and first impl of overlay.

This impl doesn't work well on mobile device.
It's suitable for small pop-up window, not good for long texts.
parent 45a45515
Loading
Loading
Loading
Loading
+91 −2
Original line number Diff line number Diff line
@@ -92,6 +92,36 @@
      .trail-active td.trail-op {
	  border-left: 2px lightblue solid;
      }
      .overlay {
	  display: none;
      }
      #help-overlay-container {
	  width: 700px;
	  height: 100vh;
	  max-height: 523px;	/*I just want to cover the page content*/
	  background: rgba(65,105,225,0.2);
	  position: fixed;
	  top: 10px;
      }
      #help-overlay-content {
	  width: 500px;
	  margin: 0px auto;
	  background: white;
	  box-shadow: 3px 3px 3px black;
	  padding: 20px;
      }
      #help-overlay-content h4 {
	  margin: 0px 0;
      }
      #close-help-overlay {
	  position: relative;
	  left: 350px;
      }
      .button-group {
	  width: 100%;
	  display: flex;
	  justify-content: center;
      }
@media only screen and (max-device-width: 480px) {
      #container {
	  width: 300px;
@@ -132,6 +162,16 @@
	  width: 60px;
	  height: 50px;
      }
      #help-overlay-container {
	  width: 300px;
      }
      #help-overlay-content {
	  width: 300px;
      }
      #close-help-overlay {
	  position: relative;
	  left: 100px;
      }
}
    </style>
  </head>
@@ -145,7 +185,7 @@
      <div id="keyboard">
	<p>Keyboard
	  <a title="reset RPN calculator" id="reset" href="#">Reset All</a>
	  <a title="refresh page" id="refresh-page" href="#">Refresh Page</a>
	  <a title="help (?)" id="help-link" href="#">Help</a>
	</p>
	<div class="keyboard">
	  <table>
@@ -199,7 +239,25 @@
	<p>Trail <a title="clear trail" id="clear-trail" href="#">Clear Trail</a> <a title="expand trail" id="expand-trail" href="#">Expand Trail</a></p>
	<div id="trail-content"></div>
      </div>
<div id="help-overlay-container" class="overlay">
      <div id="help-overlay-content">
	<h3>HELP <a id="close-help-overlay" class="close-help-overlay" href="#">Close</a></h3>
	<h4>About RPN calculator</h4>
	<p>RPN calculator is a web implementation of a <a href="#TODO">reverse polish notation calculator</a>. You push numbers to stack first, then push operator keys which will pop number from stack and run the computation. For example, you may press num1, return, num2, num3, return, plus, and you will see result 24 in top of stack. Number is pushed to stack using return key.</p>
	<p>Supported operators are: +, -, *, /, square-root, power, sum-all. Utility features include delete number, duplicate number, swap top 2 number on stack, undo, clear stack. Hover over button to see what that button does and the hotkey for that button.</p>
	<p>This program should work on desktop and mobile browser. Tested in chrome and firefox.</p>
	<h4>Credit</h4>
	<p>This project is inspired by <a href="#TODO">emacs calc mode</a>. It tries to mimic the behavior when possible.</p>
	<h4>Debug Features</h4>
	<p>This website use service worker to make it work offline. If the local cache does not work for some reason, you may <a title="refresh page" id="refresh-page" href="#">force refresh page</a> to get latest version. You may also <a title="purge service worker cache" id="purge-service-worker-cache" href="#">purge all service worker cache</a>.</p>
	<p>RPN calculator v1.0.0, Copyright (C) 2017  Yuanle Song &lt;sylecn@gmail.com&gt;</p>
	<div class="button-group">
	  <button class="close-help-overlay">Close</button>
	</div>
      </div>
    </div>
    </div>

    <script type="text/javascript" src="vendor/localforage.min.js"></script>
    <script type="text/javascript" src="vendor/jquery.min.js"></script>
    <script type="text/javascript" src="fifo.js"></script>
@@ -208,9 +266,10 @@
      (function () {
	  const testing = false;
	  const uiTesting = false;
	  const enableServiceWorker = false;

	  // service worker
	  if ('serviceWorker' in navigator) {
	  if ('serviceWorker' in navigator && enableServiceWorker) {
	      navigator.serviceWorker
		  .register('sw.js', {scope: './'})
		  .then(function() {
@@ -610,6 +669,22 @@
	      updateUI(rpnCalculator);
	      return false;
	  });
	  $('#help-link').click(function (evt) {
	      $('#help-overlay-container').show();
	      return false;
	  });
	  $('#help-overlay-container').show(); // TODO remove me.
	  $('.close-help-overlay').click(function (evt) {
	      $('#help-overlay-container').hide();
	      return false;
	  });
	  $('#help-overlay-container').click(function (evt) {
	      $(event.target).hide();
	  });
	  $('#help-overlay-content').click(function (evt) {
	      // consume this event, do not propagate to #help-overlay-container.
	      return false;
	  });
	  $('#refresh-page').click(function (evt) {
	      const urlJoin = function (baseUrl, path) {
		  const lastSlash = baseUrl.lastIndexOf("/");
@@ -641,6 +716,16 @@
	      });
	      return false;
	  });
	  $('#purge-service-worker-cache').click(function (evt) {
	      localforage.clear().then(function (_) {
		  caches.delete('calc').then(function (_) {
		      const msg = "clear all done";
		      console.log(msg);
		      $('#error-msg').text(msg);
		      $('#help-overlay-container').hide();
		  });
	      });
	  });
	  $('#expand-stack').click(function (evt) {
	      const oldMaxHeight = $('#stack-content').css("max-height");
	      if (oldMaxHeight === "100px") {
@@ -695,6 +780,10 @@
	      if (keyName !== undefined) {
		  rpnCalculator.sendKey(keyName);
		  updateUI(rpnCalculator);
	      } else {
		  if (evt.key === "?") {
		      $('#help-overlay-container').toggle();
		  }
	      }
	  });
      }());
+20 −7
Original line number Diff line number Diff line
@@ -72,11 +72,22 @@ the parent DOM.

* current                                                             :entry:
** 
** 2017-01-28 add more content in about page.
- fill in link for #TODO link in about page.
- add LICENSE info and source code repo address in about overlay.
** 2017-01-28 UI tweaks
- "refresh page" is for debugging purpose, hide it somewhere.
- DONE "refresh page" is for debugging purpose, hide it somewhere.
- div title should put buttons across the row.
  I think there is a flex property for this.
- add about dialog. could put "refresh page" in this page. hidden by default.
  - test it in mobile mode.

  - make scroll work on desktop and mobile when window height is small.
    position: fixed probably won't work.

    move overlay to <body>. use slide effect.
    hide #container when showing #help-overlay-container and vice verse.
    I don't need the dark effect and click to go back event handler.

- implementation notes
  - how to implement a pop up window (overlay)?
@@ -87,12 +98,7 @@ the parent DOM.
    ~/html/yxyAR/src/static/common.css
    box-shadow: 2px 2px 2px black;

** 2017-01-27 add an about dialog.
add "about" button beside "Reset All".

- show what is RPN calculator, how to use this program, author, program
  version and source code location.
- 
  - move "Help" to center. move "close" button to right.

** 2017-01-27 deploy on https://rpn.emacsos.com/
- I considered https://www.emacsos.com/rpn-calculator.html, but I don't want
@@ -109,6 +115,13 @@ should set a max-width on #number-display.
overflow: auto
doesn't work with <td> in firefox.
* done                                                                :entry:
** 2017-01-27 add an about dialog.
add "about" button beside "Reset All".

- show what is RPN calculator, how to use this program, author, program
  version and source code location.
- 

** 2017-01-26 make it work offline, add sw.js
- cache calc.html, fifo.js, fsm.js.
  try update cache when cached page is more than 1d old.
+0 −2
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@
	  margin: 20px auto;
	  background: white;
	  box-shadow: 3px 3px 3px black;
      }
      #overlay1-content {
	  padding: 20px;
      }
      #close-overlay1 {