Instance Settings
Customise each targetted field with the settings below (all are optional):
$(selector).calculator({showOn: 'button'});
appendText | base | buttonImage | buttonImageOnly | calculatorClass | constrainInput | cookieExpires | cookieName | cookiePath | duration | isOperator | layout | memoryAsCookie | onButton | onClose | onOpen | precision | prompt | showAnim | showFormula | showOn | showOptions | useDegrees | useThemeRoller | value
Name | Type | Default | Comments |
---|---|---|---|
showOn | string | 'focus' | Control when the calculator is displayed: 'focus' for only on focus of the text field,
'button' for only on clicking the trigger button, 'both' for either focus or the button,
'operator' for only when a non-numeric character is entered, or
'opbutton' for either non-numeric entry or a button. Since 1.1.1 - added 'operator' and 'opbutton'. |
buttonImage | string | '' | The URL of an image to use for the trigger button. |
buttonImageOnly | boolean | false | Set to true to indicate that the trigger image should appear
by itself and not on a button. |
isOperator | function | null | A callback function to determine whether or not an entered character should
trigger display of the calculator in 'operator' or 'opbutton'
modes. The function is passed the character being typed,
the corresponding key event, the current value of the input field,
the current number base, and the current decimal character.
By default any non-numeric character is a trigger.
The example below only triggers on the basic maths operators.
Since 1.2.3. |
showAnim | string | 'show' | Set which animation is used to display the calculator. Choose from three standard
animations: 'show', 'fadeIn', or 'slideDown', or use one of the
jQuery UI effects
if you include that package. For no animation use ''. Since 1.2.4 - use '' for no animation. |
showOptions | object | {} | If you use one of the jQuery UI effects for the animation above,
you can supply additional options for that effect via this setting.
|
duration | string | 'normal' | Control the speed of the show/hide animation with this setting: 'slow', 'normal', 'fast', or a number of milliseconds. |
appendText | string | '' | Text that is to be appended to all affected fields, perhaps to describe the presence or purpose of the calculator. |
useThemeRoller | boolean | false | Set to true to add ThemeRoller
classes to the keypad to allow the calculator to integrate with other UI
components using a theme.Since 1.3.0. |
calculatorClass | string | '' | One popup calculator is shared by all instances, so this setting allows you to apply different CSS styling by adding an extra class to the calculator for each instance. |
showFormula | boolean | false | Set to true to display the formula being calculated,
of false to only show the current number and result.Since 2.0.1. |
prompt | string | '' | Text that is displayed at the top of the calculator. |
layout | string[] | this. standardLayout | Set the layout of the calculator by defining the keys present on each row. Use the two-character codes for each of the keys, or their equivalent constants. |
value | number | 0 | The initial value shown in the calculator.
It only applies to inline calculators - popup calculators
take their initial value from their input field. Since 1.2.3. |
base | number | 10 | The numeric base for values shown in the calculator. It should only be one of 2, 8, 10, or 16. Use the number base keys for controls to change this setting interactively. |
precision | number | 10 | The number of digits of precision to use in rounding.
This value can resolve obvious rounding errors in JavaScript
(e.g. 2.1 * 7), but may then affect the accuracy of other calculations.
You need to strike a balance between these two requirements.
Note that this setting only affects the displayed value and that
the full value is retained in the calculator for further computations. Since 1.0.1. |
memoryAsCookie | boolean | false | Set to true to indicate that the memory value should be saved as a cookie
and be re-initialised on page load, or false to just have it in-memory.
Use the following settings to fine tune the cookie.Since 1.3.2. |
cookieName | string | 'calculatorMemory' | The name of the cookie to store when
memoryAsCookie is true .Since 1.3.2. |
cookieExpires | number or Date | 24 * 60 * 60 | The expiry period for the cookie when
memoryAsCookie is true .
Specify as a Date or as the number of seconds offset
from now (default is one day).Since 1.3.2. |
cookiePath | string | '' | The path of the cookie to store when
memoryAsCookie is true .Since 1.3.2. |
useDegrees | boolean | false | Set to true to indicate that values are in degrees when using
trigonometric functions, or false for radians (2π per circle).
Use the degrees/radians keys
for controls to change this setting interactively. |
constrainInput | boolean | true | Indicate whether to restrict entry into the input field to numeric
values only (true ) or to allow anything to be typed (false ).Since 1.1.1. |
onOpen | function | null | A function that is called before a popup calculator is opened.
The function receives the current field value and the calculator instance object
as parameters, while this refers to the text field.
The field value can be altered and will be used in the calculator.
Usually this function would be used in conjunction with the
onClose event.
Since 1.2.5. |
onButton | function | null | A function that is called when a button is activated on the calculator.
The function receives the button label, the current value,
and the calculator instance object as parameters,
while this refers to the text field.
Of course, you can still have an onchange handler
for the input field itself.
|
onClose | function | null | A function that is called when the calculator is closed.
The function receives the current field value and the calculator instance object
as parameters, while this refers to the text field.
|