Skip to content

Conversation

@yearski
Copy link

@yearski yearski commented Apr 13, 2019

Two motivations:

  1. Calculate/return numbers that can be directly cast as numbers without addition text parsing. The grouping ("thousands") separator is a problem. Using javascript Intl.NumberFormat class as an option allows very fine control of number to string formatting and provides additional options for currency and other locale differences. (as a minor benefit, it also simplifies the current logic that utilizes regex replacements that are somewhat inflexible)

  2. Append to an optional parent_element instead of only $("body"). This allows the ticket to be visible when the input with calculadora is in a modal above the main body. In this case, for me, this creates a bug whereby the alignment is off (the ticket isn't close to the input to appear "attached") but at least it's visible.

I wrote this in a way that I believe is backward-compatible with the current options: decimals and useCommaAsDecimalMark. It could be further simplified to eliminate those options and only use this new numberFormat option.

I did not create a minified map so that could be done if desired.

My previous pull-request addresses a bug-fix without any change to features or functionality; it would be unnecessary if merging this PR.

I know there haven't been commits to this project for many years. So this may just be a note of appreciation. I am submitting this to share my work in case it would be useful to you or others.

Cheers,
Greg

yearski and others added 5 commits April 12, 2019 17:32
FIX: declare variables for script mode, bump rev
refactor number format using Intl.NumberFormat, add parent_element option
1. allow calculation when input is 0:
	Testing for != 0 does not ensure that ensure that input is a number.
This logic would need to be implemented elsewhere. Remove this
condition, ensure that division by 0 is avoided/ignored.

2. implement '=':

3. refactor calculation operation logic:
	Change switch from KeyboardEvent.which (deprecated) to
KeyboardEvent.key (this also makes code much easier to read).
	Remove keypress handler for key code 37 (left arrow). This
functionality doesn't seem to be working as intended (divide by 100, to
allow quicker decimal entry?). Instead, I added an 'm' "milli"
functionality to divide by 1000, like the existing 'k'
	Trigger change event after '=' TotalSoFar calculation to enable
external event listeners.

4. bump version, update minified file
@yearski
Copy link
Author

yearski commented May 1, 2019

1159b85:
calculator operations don't work when starting with 0.
It also seems that the previous changes to '=' key disabled it.
change to event key instead of code.

Use jQuery offset function instead of coded calculation. The offset was
not calculated correctly when using a Bootstrap modal. Also test/change
the ticket visibility using jQuery instead of state variable and css.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant