JavaScript Calculator (jscalc)

Gem Version

jscalc is a calculator written entirely in JavaScript and CSS-3, and may be easily incorporated into a web-page. There are no images.

To make it draggable (moveable), jQuery-UI is required.

As well as having basic mathematical functions, many built-in JavaScript functions, such as those available in the Math Object are available. Examples are Math.random () and parseInt().

See the gem in a basic Ruby-on-Rails (v 3.2)

Installation

Add this line to your application's Gemfile:

gem 'jscalc'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install jscalc

Add the following HTML code to the page where you want the calculator to appear

<div id = "myCalculator"> <div id="panelDiv"> <input type ="text" id = "calcPanel" /> </div> <!--End panelDiv--> </div><!--End myCalculator Div-->

Add the following to the bottom of application.html.erb (the script file must render in the body section of the HTML page, not in the Head section)

<%= javascript_include_tag "jscalc.js" %>

Add the following line to the head section of application.html.erb

<%= stylesheet_link_tag "jscalc.css" %>

To Make THE Calculator Draggable

Ensure that jQuery-ui is installed or add the following code to the Head section of application.html.erb BEFORE the stylesheet link tag.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>

To Inspect the Code

When the gem is installed in an App running on a local machine, the code may be inspected using the following URLs

http://localhost:3000/assets/jscalc.js

http://localhost:3000/assets/jscalc.css

Usage

Math.random()

Math.PI

Math.sqrt()

Math.exp()

Math.pow(10,3)

Math.E

Math.round()

x = new Date()

x.getMonth()

x.getDate()

x.getDay()

x.getFullYear()

navigator.appName

parseInt(1101,2) 

isNaN(2)

typeof(2)

See here for a more comprehensive list.

Contributing

Written by Thomas Dowling (tomgdow)

The National College of Ireland

[email protected]