Skip to content

Commit

Permalink
Bugs Removed Event Firing Multiple Times, calculator Id removed no ne…
Browse files Browse the repository at this point in the history
…ed now, inline code removed
  • Loading branch information
planetapex committed Apr 26, 2017
1 parent 3f99d05 commit 8683424
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 803 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Available on

## Changelog

#### 1.1 - Bugs Removed Event Firing Multiple Times
#### 1.0 - Initial Release


Expand Down
2 changes: 1 addition & 1 deletion apexplugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Atom Calculator",
"version": "1.0",
"version": "1.1",
"private": "N",
"description": "A Dynamic action plugin providing a popup calculator for realtime calculations. ",
"keywords": ["oracle", "apex", "plugin", "dynamicAction", "calculator", "popup", "calculation", "math"],
Expand Down
496 changes: 221 additions & 275 deletions plugin/dynamic_action_plugin_com_planetapex_atom_calculator.sql

Large diffs are not rendered by default.

21 changes: 3 additions & 18 deletions src/jcalculator.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,6 @@
transition: opacity 0.3s ease, transform 0.3s ease, left 0s 0s, -webkit-transform 0.3s ease;
}

.calculator-inline .calculator {
border-color: #d7d7d7;
box-shadow: none;
position: static;
left: auto;
right: auto;
opacity: 1;
-webkit-transform: none;
transform: none;
}

.calculator-inline .calculator--pointer {
display: none;
}

.calculator--content {
box-sizing: content-box;
padding: 0px;
Expand All @@ -92,15 +77,15 @@
z-index: -1;
}

.mat {
.calculator--pointer.mat {
background: #3b3b3b;
}

.drk {
.calculator--pointer.drk {
background: #1a1a1a;
}

.lit {
.calculator--pointer.lit {
background: #ffffff;
}

Expand Down
114 changes: 47 additions & 67 deletions src/jcalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
classes: '',
inline: false,
autoClose: false,
calcID: null,
// calcID: null,

// events
onInput: function() {},
Expand All @@ -49,7 +49,7 @@

this.opts = $.extend(true, {}, defaults, options, this.$el.data());

if ($body == undefined) {
if ($body === undefined) {
$body = $('body');
}

Expand Down Expand Up @@ -102,7 +102,7 @@
if (this.opts.keyboardNav) {
this._bindKeyboardEvents();
}
this.opts.calcID = 'jCalc_' + Math.floor(Math.random() * 10000000 + 10000);
// this.opts.calcID = 'jCalc_' + Math.floor(Math.random() * 10000000 + 10000);
new $.fn.calculator.Body(this, '', this.opts);

this.inited = true;
Expand All @@ -123,18 +123,14 @@
_onKeyDown: function(e) {
var code = e.which;
this._registerKey(code);
// console.log('e', e);
// console.log('ins', this.$calculator.find('.jcalculator span#opa'));



if ((code >= 96 && code <= 105) || code == 110) {
var spn = code == 110 ? 'Dot' : 0 + code - 96;

e.preventDefault();
// $(this.$calculator).find('.jcalculator span#num' + spn).trigger('click');
// $('#' + this.opts.calcID).find('span#num' + spn).trigger('click');
this.$calculator.find('.jcalculator span#num' + spn).trigger('click');


$('#' + this.opts.calcID).find('span#num' + spn).trigger('click');
spn = '';


Expand All @@ -158,12 +154,14 @@

}
e.preventDefault();
$('#' + this.opts.calcID).find('span#op' + spn).trigger('click');
// $('#' + this.opts.calcID).find('span#op' + spn).trigger('click');
this.$calculator.find('.jcalculator span#op' + spn).trigger('click');
spn = '';

} else if (code == 13) { // Enter
e.preventDefault();
$('#' + this.opts.calcID).find('span#ope').trigger('click');
// $('#' + this.opts.calcID).find('span#ope').trigger('click');
this.$calculator.find('.jcalculator span#ope').trigger('click');
spn = '';
} else if (code == 27) { // Esc
e.preventDefault();
Expand Down Expand Up @@ -215,27 +213,11 @@
},

_buildBaseHtml: function() {
var $appendTarget,
$inline = $('<div class="calculator-inline">');

if (this.el.nodeName == 'INPUT') {
if (!this.opts.inline) {
$appendTarget = $calculatorsContainer;
} else {
$appendTarget = $inline.insertAfter(this.$el)
}
} else {
$appendTarget = $inline.appendTo(this.$el)
}

this.$calculator = $(baseTemplate).appendTo($appendTarget);

this.$calculator = $(baseTemplate).appendTo($calculatorsContainer);
if (this.opts.theme == 'material') this.$calculator.find('.calculator--pointer').addClass('mat');
else if (this.opts.theme == 'dark') this.$calculator.find('.calculator--pointer').addClass('drk');
else if (this.opts.theme == 'light') this.$calculator.find('.calculator--pointer').addClass('lit');



this.$content = $('.calculator--content', this.$calculator);

},
Expand All @@ -254,7 +236,6 @@
.removeAttr('class')
.addClass(classes);
},

setPosition: function(position) {
position = position || this.opts.position;

Expand All @@ -265,17 +246,15 @@
offset = parseInt(this.opts.offset),
main = pos[0],
secondary = pos[1];


// console.log('top', dims.top, 'height', selfDims.height);

switch (main) {
case 'top':
top = dims.top - selfDims.height - offset;
// console.log('top', top);
break;
case 'right':
left = parseFloat(dims.left) + parseFloat(dims.width) + offset;
// console.log('left', left);
left = dims.left + dims.width + offset;

break;
case 'bottom':
top = dims.top + dims.height + offset;
Expand All @@ -287,7 +266,7 @@

switch (secondary) {
case 'top':
top = parseFloat(dims.top);
top = dims.top;
break;
case 'right':
left = dims.left + dims.width - selfDims.width;
Expand All @@ -310,7 +289,7 @@
.css({
left: left + 'px',
top: top + 'px'
})
});
},

_getDimensions: function($el) {
Expand Down Expand Up @@ -383,13 +362,8 @@


_this.focused = '';
_this.$calculator.remove();


if (_this.opts.inline || !_this.elIsInput) {
_this.$calculator.closest('.calculator-inline').remove();
} else {
_this.$calculator.remove();
}
},

_onShowEvent: function(e) {
Expand Down Expand Up @@ -503,7 +477,7 @@
}


if (this.opts.displayMode == "basic") { //jCalculator Obj
if (this.opts.displayMode === "basic") { //jCalculator Obj
this.$calc = $(this.template1)
.appendTo(this.d.$content)
.addClass("temp1")
Expand All @@ -516,7 +490,7 @@

$('');

this.$calc.attr('id', calc.opts.calcID);
// this.$calc.attr('id', calc.opts.calcID);
this.$calc.addClass('temp');

if (calc.opts.buttonStyle) {
Expand All @@ -534,24 +508,30 @@
}


$(this.$calc).on('click', 'span.clear-btn', this._clrPress.bind(self));
$(this.$calc).on('click', 'span.num-btn', this._numPress.bind(self));
$(this.$calc).on('click', '.func-btn', this._funcPress.bind(self));
$(this.$calc).on('click', 'span.eql-btn', this._eqPress.bind(self));

$('span.clear-btn', this.$calc).on('click', this._clrPress.bind(self));
$('span.num-btn', this.$calc).on('click', this._numPress.bind(self));
//
$("span.plusminus-btn", this.$calc).on('click', this._signPress.bind(self));
// Percent operations
$('span.percent-btn', this.$calc).on('click', this._percPress.bind(self));
// $('span.func-btn', this.$calc).on('click', this._funcPress.bind(self));
$('.func-btn').on('click', this._funcPress.bind(self));
$('span.eql-btn', this.$calc).on('click', this._eqPress.bind(self));

if (this.opts.displayMode == "extended") {
$(this.$calc).on('click', 'span.plusminus-btn', this._signPress.bind(self));
$(this.$calc).on('click', 'span.percent-btn', this._percPress.bind(self));
}



this.init();

// $('span.clear-btn', this.$calc).on('click', this._clrPress.bind(self));
// $('span.num-btn', this.$calc).on('click', this._numPress.bind(self));
// $('.func-btn', this.$calc).on('click', this._funcPress.bind(self));
// $('span.eql-btn', this.$calc).on('click', this._eqPress.bind(self));

// if (this.opts.displayMode == "extended") {
// $("span.plusminus-btn", this.$calc).on('click', this._signPress.bind(self));
// $('span.percent-btn', this.$calc).on('click', this.$calc, this._percPress.bind(self));
// }

this.init();

};

Expand Down Expand Up @@ -756,9 +736,9 @@



if ((this.$display.data("isCurrFunction") == true) && (this.$display.data("valueOneLocked") == true)) {
if (this.$display.data("isCurrFunction") && this.$display.data("valueOneLocked")) {
// console.log("2nd Entry");
if (this.$display.data("typing1stChar") === true) { //first Digit
if (this.$display.data("typing1stChar")) { //first Digit
// console.log("first Digit");
if ($numPressed == '.') {
this.push('0' + $numPressed);
Expand Down Expand Up @@ -810,7 +790,7 @@
// Clicking on a number fresh/first Entry
} else {
// console.log("First Entry");
if (this.$display.data("typing1stChar") === true) {
if (this.$display.data("typing1stChar")) {
// console.log("first character");
if ($numPressed == '.') {
// console.log("dot pressed")
Expand Down Expand Up @@ -865,16 +845,16 @@

_signPress: function(e) {
this.ripple(e.target);
if ((this.$display.data("valueOneLocked") == false) && (this.$display.data("valueTwoLocked") == false)) {
if (!this.$display.data("valueOneLocked") && !this.$display.data("valueTwoLocked")) {
var changesign = this.pull();
changesign = changesign * -1;
this.push(changesign);
} else if ((this.$display.data("valueOneLocked") == true)) {
} else if (this.$display.data("valueOneLocked")) {
var changesign = this.$display.data("valueTwo");
changesign = changesign * -1;
this.$display.data("valueTwo", changesign);
this.push(changesign);
} else if ((this.$display.data("valueTwoLocked") == true)) {
} else if (this.$display.data("valueTwoLocked")) {
var changesign = this.$display.data("valueOne");
changesign = changesign * -1;
this.$display.data("valueOne", changesign);
Expand All @@ -885,20 +865,20 @@
_percPress: function(e) {
this.ripple(e.target);
var percentNum, finalValue;
if ((this.$display.data("valueOneLocked") == false && this.$display.data("valueTwoLocked") == false) || (this.$display.data("valueOneLocked") == true && this.$display.data("valueTwoLocked") == false && this.$display.data("isCurrFunction") === true)) {
if ((!this.$display.data("valueOneLocked") && !this.$display.data("valueTwoLocked")) || (this.$display.data("valueOneLocked") && !this.$display.data("valueTwoLocked") && this.$display.data("isCurrFunction"))) {
percentNum = this.pull();
finalValue = percentNum / 100;
//this.push(finalValue);
this.resetCalculator(finalValue);

} else if ((this.$display.data("valueTwoLocked") == true) && (this.$display.data("CurrFunction") == "-") || (this.$display.data("CurrFunction") == "+")) {
} else if (this.$display.data("valueTwoLocked") && (this.$display.data("CurrFunction") == "-") || (this.$display.data("CurrFunction") == "+")) {
percentNum = this.$display.data("valueTwo");
var newNum = this.$display.data("valueOne");
percentNum = percentNum / 100;
finalValue = newNum * percentNum;
this.push(finalValue);
this.$display.data("valueTwo", finalValue);
} else if ((this.$display.data("valueTwoLocked") === true) && (this.$display.data("CurrFunction") == "x") || (this.$display.data("CurrFunction") == String.fromCharCode(247))) {
} else if (this.$display.data("valueTwoLocked") && (this.$display.data("CurrFunction") == "x") || (this.$display.data("CurrFunction") == String.fromCharCode(247))) {
percentNum = this.$display.data("valueTwo");
finalValue = percentNum / 100;
this.push(finalValue);
Expand All @@ -917,7 +897,7 @@
var dispVal = this.pull();
var pendingFunction = $(e.target).text().trim();

if (this.$display.data("isCurrFunction") === true) {
if (this.$display.data("isCurrFunction")) {
this.$display.data("PrevFunction", this.$display.data("CurrFunction"))
this.$display.data("isPrevFunction", true);
this.$display.data("isRunTotal", true);
Expand Down Expand Up @@ -995,7 +975,7 @@
// }


if (this.$display.data("isRunTotal") === true) {
if (this.$display.data("isRunTotal")) {
this.resetDisplay(finalValue, true);

} else {
Expand Down
Loading

0 comments on commit 8683424

Please sign in to comment.