jdarwood007 commited on 2021-02-22 18:32:55
Showing 1 changed files, with 34 additions and 5 deletions.
... | ... |
@@ -1,11 +1,24 @@ |
1 | 1 |
;(function ($) { |
2 | 2 |
"use strict" |
3 | 3 |
$.fn.numbercontrol = function (methodOrProps) { |
4 |
- if (methodOrProps === "destroy") { |
|
4 |
+ if (methodOrProps === "destory") { |
|
5 | 5 |
this.each(function () { |
6 |
- this.destroyInputSpinner() |
|
6 |
+ $(this).parent().children().each(function (index, value) { |
|
7 |
+ var thisSelector = $(value); |
|
8 |
+ |
|
9 |
+ if (options.onBeforeDestoryInitialize !== undefined) |
|
10 |
+ options.onBeforeDestoryInitialize(this); |
|
11 |
+ |
|
12 |
+ if (!thisSelector.is('input')) |
|
13 |
+ thisSelector.remove(); |
|
14 |
+ |
|
15 |
+ if (options.onAfterDestoryInitialize !== undefined) |
|
16 |
+ options.onAfterDestoryInitialize(this); |
|
17 |
+ }); |
|
18 |
+ |
|
19 |
+ $(this).parent().removeClass().addClass('numberControlDestoryed'); |
|
7 | 20 |
}) |
8 |
- return this |
|
21 |
+ return this; |
|
9 | 22 |
} |
10 | 23 |
|
11 | 24 |
// Allow customizing the options. |
... | ... |
@@ -15,7 +28,8 @@ |
15 | 28 |
type: "number", |
16 | 29 |
prependHtml: '<div class="input-group-prepend"><button class="btn btn-decrease btn-outline-secondary px-1"><span class="oi oi-minus" /></button></div>', |
17 | 30 |
appendHtml: '<div class="input-group-append"><button class="btn btn-increase btn-outline-secondary px-1"><span class="oi oi-plus" /></button></div>', |
18 |
- inputWrap: '<div class="input-group numberControl"></div>', |
|
31 |
+ inputParentCss: 'input-group numberControl', |
|
32 |
+ inputParent: 'div', |
|
19 | 33 |
inputCss: 'numberControlInput form-control px-1', |
20 | 34 |
bindButtonEvents: 'click tap touch touchstart', |
21 | 35 |
keyboardLanguage: { |
... | ... |
@@ -34,10 +48,16 @@ |
34 | 48 |
|
35 | 49 |
function setNewValue(container, value) |
36 | 50 |
{ |
51 |
+ if (options.onBeforeSetNewvalue !== undefined) |
|
52 |
+ options.onBeforeSetNewvalue(this, event, container, value); |
|
53 |
+ |
|
37 | 54 |
if (options.type === 'number') |
38 | 55 |
$(container).val(parseInt(value)); |
39 | 56 |
else |
40 | 57 |
$(container).val(parseFloat(value)); |
58 |
+ |
|
59 |
+ if (options.onAfterSetNewvalue !== undefined) |
|
60 |
+ options.onAfterSetNewvalue(this, event, container, value); |
|
41 | 61 |
} |
42 | 62 |
|
43 | 63 |
function findMinMaxValue() |
... | ... |
@@ -70,8 +90,11 @@ |
70 | 90 |
var $maxValue = findMinMaxValue(options.max, $base.attr('max'), Number.MAX_VALUE); |
71 | 91 |
|
72 | 92 |
// Build the parent up. |
73 |
- $base.wrap(options.inputWrap); |
|
93 |
+ if (!$($base).parent().is('div') || !$($base).parent().hasClass('numberControlDestoryed')) { |
|
94 |
+ $base.wrap('<' + options.inputParent + '></' + options.inputParent + '>'); |
|
95 |
+ } |
|
74 | 96 |
var $parent = $base.parent(options.parentSelector); |
97 |
+ $parent.removeClass().addClass(options.inputParentCss); |
|
75 | 98 |
|
76 | 99 |
// Set the base. |
77 | 100 |
$base.attr('type', options.type); |
... | ... |
@@ -92,6 +115,8 @@ |
92 | 115 |
// The decrease event. |
93 | 116 |
var $decreaseButton = $parent.find('.btn-decrease'); |
94 | 117 |
$decreaseButton.on(options.bindButtonEvents, function (event) { |
118 |
+ event.preventDefault(); |
|
119 |
+ |
|
95 | 120 |
if (options.onBeforeClickDecrease !== undefined) |
96 | 121 |
options.onBeforeClickDecrease(this, event); |
97 | 122 |
if ($base.val() > $minValue) |
... | ... |
@@ -105,6 +130,8 @@ |
105 | 130 |
// The increase event. |
106 | 131 |
var $decreaseButton = $parent.find('.btn-increase'); |
107 | 132 |
$decreaseButton.on(options.bindButtonEvents, function (event) { |
133 |
+ event.preventDefault(); |
|
134 |
+ |
|
108 | 135 |
if (options.onBeforeClickIncrease !== undefined) |
109 | 136 |
options.onBeforeClickIncrease(this, event); |
110 | 137 |
if ($base.val() < $maxValue) |
... | ... |
@@ -185,6 +212,8 @@ |
185 | 212 |
|
186 | 213 |
// Bind the virtual Keyboard action. |
187 | 214 |
$VirtualKeyboard.find('.numberControlVirtualNumPad').on(options.bindButtonEvents, function(event){ |
215 |
+ event.preventDefault(); |
|
216 |
+ |
|
188 | 217 |
if (options.debug) console.log('numbercontrl: numberControlVirtualNumPad: Click', event, $base.val(), $VirtualKeyboardInput.val().toString(), $(this).attr('data-function')); |
189 | 218 |
|
190 | 219 |
var thisFunction = $(this).attr('data-function'); |
191 | 220 |