Cleanup, enforce style and standards
jdarwood007

jdarwood007 commited on 2021-02-23 08:33:07
Showing 4 changed files, with 100 additions and 15 deletions.

... ...
@@ -0,0 +1,36 @@
1
+module.exports = {
2
+	'env': {
3
+		'browser': true,
4
+		'commonjs': true,
5
+		'es2021': true,
6
+		'jquery': true,
7
+		'amd': true
8
+	},
9
+	'extends': 'eslint:recommended',
10
+	'parserOptions': {
11
+		'ecmaVersion': 12,
12
+		'sourceType': 'module'
13
+	},
14
+	'rules': {
15
+		'indent': [
16
+			'error',
17
+			'tab',
18
+			{"SwitchCase": 1}
19
+		],
20
+		'linebreak-style': [
21
+			'error',
22
+			'unix'
23
+		],
24
+		'quotes': [
25
+			'error',
26
+			'single'
27
+		],
28
+		'no-unused-vars': [
29
+			'error',
30
+			{
31
+				'vars': 'local',
32
+				'args' : 'none'
33
+			}
34
+		]
35
+	}
36
+};
... ...
@@ -0,0 +1,15 @@
1
+name: Javascript Checks
2
+
3
+on: [push, pull_request]
4
+
5
+  workflow_dispatch:
6
+jobs:          
7
+  lint:
8
+    runs-on: ubuntu-latest
9
+    name: LINT Checks
10
+    steps:
11
+      - uses: actions/checkout@master
12
+      - name: Javascript LINT
13
+        uses: tj-actions/eslint-changed-files@v4
14
+        with:
15
+          config-path: .eslintrc.js
0 16
\ No newline at end of file
... ...
@@ -0,0 +1,4 @@
1
+node_modules
2
+package-lock.json
3
+package.json
4
+yarn.lock
... ...
@@ -1,7 +1,33 @@
1
-;(function ($) {
2
-    "use strict"
1
+(function (factory) {
2
+	if (typeof define === 'function' && define.amd) {
3
+		// AMD. Register as an anonymous module.
4
+		define(['jquery'], factory);
5
+	} else if (typeof module === 'object' && module.exports) {
6
+		// Node/CommonJS
7
+		module.exports = function( root, jQuery ) {
8
+			if ( jQuery === undefined ) {
9
+				// require('jQuery') returns a factory that requires window to
10
+				// build a jQuery instance, we normalize how we use modules
11
+				// that require this pattern but the window provided is a noop
12
+				// if it's defined (how jquery works)
13
+				if ( typeof window !== 'undefined' ) {
14
+					jQuery = require('jquery');
15
+				}
16
+				else {
17
+					jQuery = require('jquery')(root);
18
+				}
19
+			}
20
+			factory(jQuery);
21
+			return jQuery;
22
+		};
23
+	} else {
24
+		// Browser globals
25
+		factory(jQuery);
26
+	}
27
+}(function ($) {
28
+	'use strict'
3 29
 	$.fn.numbercontrol = function (methodOrProps) {
4
-		if (methodOrProps === "destory") {
30
+		if (methodOrProps === 'destory') {
5 31
 			this.each(function () {
6 32
 				$(this).parent().children().each(function (index, value) {
7 33
 					var thisSelector = $(value);
... ...
@@ -25,7 +51,7 @@
25 51
 		var options = {
26 52
 			debug: false,
27 53
 			separator: '.',
28
-        	type: "number",
54
+			type: 'number',
29 55
 			prependHtml: '<div class="input-group-prepend"><button class="btn btn-decrease btn-outline-secondary px-1"><span class="oi oi-minus" /></button></div>',
30 56
 			appendHtml: '<div class="input-group-append"><button class="btn btn-increase btn-outline-secondary px-1"><span class="oi oi-plus" /></button></div>',
31 57
 			inputParentCss: 'input-group numberControl',
... ...
@@ -128,8 +154,8 @@
128 154
 			});
129 155
 
130 156
 			// The increase event.
131
-			var $decreaseButton = $parent.find('.btn-increase');
132
-			$decreaseButton.on(options.bindButtonEvents, function (event) {
157
+			var $increaseButton = $parent.find('.btn-increase');
158
+			$increaseButton.on(options.bindButtonEvents, function (event) {
133 159
 				event.preventDefault();
134 160
 
135 161
 				if (options.onBeforeClickIncrease !== undefined)
... ...
@@ -145,6 +171,8 @@
145 171
 			// The Popup Numberpad
146 172
 			if (!options.disableVirtualKeyboard)
147 173
 			{
174
+				var $KeyboardLayout;
175
+
148 176
 				if (options.onBeforeVirtualKeyboardInitalized !== undefined)
149 177
 					options.onBeforeVirtualKeyboardInitalized(this);
150 178
 
... ...
@@ -157,9 +185,9 @@
157 185
 					var $location = options.virtualKeyboardAttachSelector ? $(options.virtualKeyboardAttachSelector) : $base;
158 186
 
159 187
 					if (options.keyboardLayout)
160
-						var $KeyboardLayout = options.keyboardLayout;
188
+						$KeyboardLayout = options.keyboardLayout;
161 189
 					else
162
-						var $KeyboardLayout = 
190
+						$KeyboardLayout = 
163 191
 							'<div class="modal-dialog modal-dialog-centered" style="width: 250px;">' +
164 192
 								'<div class="modal-content">' +
165 193
 									'<table>' +
... ...
@@ -192,9 +220,9 @@
192 220
 						;
193 221
 
194 222
 					// Fill out the input.
195
-					if (typeof options.keyboardControl["INPUTBOX"] === 'undefined')
196
-						options.keyboardControl["INPUTBOX"] = '<input class="numberControlVirtualNumPad numberControlVirtualNumPadINPUT form-control" type="text" readonly value="{VAL}"/>';
197
-					$KeyboardLayout = $KeyboardLayout.replace('{INPUTBOX}', options.keyboardControl["INPUTBOX"].replace('{VAL}', $base.val()).toString());
223
+					if (typeof options.keyboardControl['INPUTBOX'] === 'undefined')
224
+						options.keyboardControl['INPUTBOX'] = '<input class="numberControlVirtualNumPad numberControlVirtualNumPadINPUT form-control" type="text" readonly value="{VAL}"/>';
225
+					$KeyboardLayout = $KeyboardLayout.replace('{INPUTBOX}', options.keyboardControl['INPUTBOX'].replace('{VAL}', $base.val()).toString());
198 226
 
199 227
 					// Fill out all buttons.
200 228
 					$.each(options.buttons, function(i, v){
... ...
@@ -228,10 +256,9 @@
228 256
 								break;
229 257
 							
230 258
 							case 'CLEAR':
231
-								$VirtualKeyboardInput.val("");
259
+								$VirtualKeyboardInput.val('');
232 260
 								break;
233 261
 							
234
-							// Done break.
235 262
 							case 'DONE':
236 263
 								if ($VirtualKeyboardInput.val() > $maxValue)
237 264
 									setNewValue($base, $maxValue);
... ...
@@ -239,6 +266,10 @@
239 266
 									setNewValue($base, $minValue);
240 267
 								else
241 268
 									setNewValue($base, $VirtualKeyboardInput.val());
269
+								
270
+								$VirtualKeyboard.remove();
271
+								break;
272
+
242 273
 							case 'CANCEL':
243 274
 								$VirtualKeyboard.remove();
244 275
 								break;
... ...
@@ -287,5 +318,4 @@
287 318
 			if (options.debug) console.log($base.parent());
288 319
 		});
289 320
 	}
290
-
291
-}(jQuery));
292 321
\ No newline at end of file
322
+}));
293 323
\ No newline at end of file
294 324