ozdenui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
PhoneField - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- You can customize, this template code as you need:
|
|
9
|
+
- NEW PROJECTS: styleName "light" (the default) on a light page, "dark" on a dark page (the packages
|
|
10
|
+
of TextField, comp/text-field.js; the look of 02-comp-examples/text-field-8-light-dark.htm), unless the user asks for another one.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
Started Date: June 2024
|
|
14
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
15
|
+
|
|
16
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
17
|
+
Licensed under the Apache License, Version 2.0
|
|
18
|
+
SPDX-License-Identifier: Apache-2.0
|
|
19
|
+
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
|
|
24
|
+
- input.getValue();
|
|
25
|
+
-- Returns "" while no digit is written. (The field holds only its mask: "+90 (___) ___-____")
|
|
26
|
+
-- So an optional field with no number is not wrong, a required one shows "Required",
|
|
27
|
+
and a form does not send the mask.
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
"use strict";
|
|
32
|
+
|
|
33
|
+
// Default values:
|
|
34
|
+
const PhoneFieldDefaults = {
|
|
35
|
+
required: 1,
|
|
36
|
+
titleText: "PHONE NUMBER",
|
|
37
|
+
placeholder: "(auto)",
|
|
38
|
+
warningText: "Invalid phone number format",
|
|
39
|
+
warningColor: "#E5885E",
|
|
40
|
+
countryCode: "+90",
|
|
41
|
+
phoneMask: " (___) ___-____",
|
|
42
|
+
//phoneMask: " (___) ___ __ __",
|
|
43
|
+
//phoneMask: " ___ ___ __ __",
|
|
44
|
+
//phoneMask: " ___ ___-__-__",
|
|
45
|
+
unitText: "TR",
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const PhoneField = function(params = {}) {
|
|
49
|
+
|
|
50
|
+
// Merge params:
|
|
51
|
+
// WHY the style package of TextField first: a key it sets (warningColor) wins over the defaults here, as over the
|
|
52
|
+
// defaults of TextField
|
|
53
|
+
basic.applyStylePackage(params, TextField.styles, TextFieldDefaults);
|
|
54
|
+
mergeIntoIfMissing(params, PhoneFieldDefaults);
|
|
55
|
+
|
|
56
|
+
// Edit params, if needed:
|
|
57
|
+
if (params.createInput == 0) {
|
|
58
|
+
params.createInput = 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// BOX: Component container
|
|
62
|
+
const box = startExtendedObject(TextField, params);
|
|
63
|
+
|
|
64
|
+
// NOTE: Parent container is box.containerBox
|
|
65
|
+
|
|
66
|
+
// *** PRIVATE VARIABLES:
|
|
67
|
+
const inputElem = box.input.inputElement;
|
|
68
|
+
let codeInField = box.countryCode; // the country code written in the field (setCountryCode() changes box.countryCode first)
|
|
69
|
+
|
|
70
|
+
// *** PRIVATE FUNCTIONS:
|
|
71
|
+
|
|
72
|
+
const getFullMask = function() {
|
|
73
|
+
return box.countryCode + box.phoneMask;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// The cursor goes to the first empty digit (the first "_"), or to the end when the number is full.
|
|
77
|
+
const setCursorToFirstUnderscore = function() {
|
|
78
|
+
if (!inputElem) return;
|
|
79
|
+
const firstUnderscore = inputElem.value.indexOf("_");
|
|
80
|
+
if (inputElem.selectionStart === firstUnderscore) return;
|
|
81
|
+
|
|
82
|
+
const cursorPos = (firstUnderscore !== -1) ? firstUnderscore : inputElem.value.length;
|
|
83
|
+
inputElem.setSelectionRange(cursorPos, cursorPos); // WHY: the caret must not jump to the end first.
|
|
84
|
+
box.after(0, () => {
|
|
85
|
+
inputElem.setSelectionRange(cursorPos, cursorPos); // WHY: this moves the caret (after the browser moved it).
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// The text without the country code at its start: the one in the field, or the new one (the longest).
|
|
90
|
+
// WHY: the first countryCode.length characters went without a look: "+90 (555) 123-4567" became
|
|
91
|
+
// "+1 (055) 512-3456" after setCountryCode("+1") (a valid wrong number), and a number autofilled
|
|
92
|
+
// without its code lost its first digits
|
|
93
|
+
const withoutCountryCode = function(text) {
|
|
94
|
+
const codes = [codeInField, box.countryCode].filter(function(code) {
|
|
95
|
+
return typeof code === "string" && code.length > 0 && text.indexOf(code) === 0;
|
|
96
|
+
});
|
|
97
|
+
codes.sort(function(a, b) { return b.length - a.length; });
|
|
98
|
+
return (codes.length) ? text.substring(codes[0].length) : text;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const makeRandomPhoneNumber = function() {
|
|
102
|
+
return box.phoneMask.replace(/_/g, () => Math.floor(Math.random() * 10));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Every "_" of the mask gets the next digit; a "_" stays when there is no digit left.
|
|
106
|
+
const fillMaskWithDigits = function(mask, digits) {
|
|
107
|
+
let digitIndex = 0;
|
|
108
|
+
let result = "";
|
|
109
|
+
for (let i = 0; i < mask.length; i++) {
|
|
110
|
+
if (mask[i] !== "_") {
|
|
111
|
+
result += mask[i];
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (digitIndex < digits.length) {
|
|
115
|
+
result += digits[digitIndex];
|
|
116
|
+
digitIndex++;
|
|
117
|
+
} else {
|
|
118
|
+
result += "_";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// The digits of a pasted number for the mask: "555 123 45 67", "(555) 123-4567", "0555 123 45 67",
|
|
125
|
+
// "+90 555 123 45 67" and "0090 555..." all give "5551234567". (The country code and a leading 0 go.)
|
|
126
|
+
const getPastedDigits = function(text) {
|
|
127
|
+
let digits = String(text).replace(/[^0-9]/g, "");
|
|
128
|
+
const maxDigits = (box.phoneMask.match(/_/g) || []).length;
|
|
129
|
+
const codeDigits = String(box.countryCode || "").replace(/[^0-9]/g, "");
|
|
130
|
+
if (digits.length > maxDigits && codeDigits && digits.indexOf("00" + codeDigits) === 0) digits = digits.substring(2 + codeDigits.length);
|
|
131
|
+
if (digits.length > maxDigits && codeDigits && digits.indexOf(codeDigits) === 0) digits = digits.substring(codeDigits.length);
|
|
132
|
+
if (digits.length > maxDigits && digits[0] === "0") digits = digits.substring(1);
|
|
133
|
+
return digits.substring(0, maxDigits);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// Backspace deletes only the digits: the country code and the fixed characters stay
|
|
137
|
+
const deleteDigitBeforeCursor = function(event) {
|
|
138
|
+
const cursorPos = inputElem.selectionStart;
|
|
139
|
+
const value = inputElem.value;
|
|
140
|
+
const mask = getFullMask();
|
|
141
|
+
const firstDigitIndex = mask.indexOf("_");
|
|
142
|
+
|
|
143
|
+
// The caret at the start of the country code or of the fixed characters: nothing is deleted
|
|
144
|
+
if (cursorPos <= firstDigitIndex) {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
setCursorToFirstUnderscore();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// The first digit to the left
|
|
151
|
+
const left = value.slice(0, cursorPos);
|
|
152
|
+
const right = value.slice(cursorPos);
|
|
153
|
+
let i = left.length - 1;
|
|
154
|
+
while (i >= 0 && mask[i] !== "_") i--;
|
|
155
|
+
|
|
156
|
+
if (i >= 0) {
|
|
157
|
+
inputElem.value = left.substring(0, i) + "_" + left.substring(i + 1) + right;
|
|
158
|
+
}
|
|
159
|
+
// WHY: The browser does not delete: the digit became "_" above (or there was no digit to delete).
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
setCursorToFirstUnderscore();
|
|
162
|
+
|
|
163
|
+
// WHY: Backspace updates it too.
|
|
164
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
165
|
+
box.showWarningIfNotValid(box.isValid());
|
|
166
|
+
box.onChange(box); // WHY: a delete changes the value too
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// *** PUBLIC FUNCTIONS:
|
|
170
|
+
|
|
171
|
+
const superSetValue = box.setValue; // TextField: the text as it is (the mask is made here)
|
|
172
|
+
|
|
173
|
+
// The typed number in the form of box.phoneMask.
|
|
174
|
+
box.applyFormattedValueToInput = function() { // OVERRIDE
|
|
175
|
+
|
|
176
|
+
// 1. The country code at the start of the field goes.
|
|
177
|
+
// WHY the field itself: also when it holds only the mask (getValue() is "" then)
|
|
178
|
+
const value = withoutCountryCode(inputElem.value);
|
|
179
|
+
|
|
180
|
+
// 2. Only the digits stay (the characters of the mask go too)
|
|
181
|
+
let digits = value.replace(/[^0-9]/g, "");
|
|
182
|
+
|
|
183
|
+
// The digits that are too many are left out
|
|
184
|
+
const maxDigits = (box.phoneMask.match(/_/g) || []).length;
|
|
185
|
+
digits = digits.substring(0, maxDigits);
|
|
186
|
+
|
|
187
|
+
// 3. Fill countryCode + phoneMask with them
|
|
188
|
+
superSetValue(fillMaskWithDigits(getFullMask(), digits));
|
|
189
|
+
codeInField = box.countryCode;
|
|
190
|
+
setCursorToFirstUnderscore();
|
|
191
|
+
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// WHY: a number given in code (or as the start value) was written as it is: "5551234567" was not in the mask, and
|
|
195
|
+
// isValid() said 1. It goes into the mask as a pasted number does ("0555 123 45 67": the same digits).
|
|
196
|
+
box.setValue = function(value) { // OVERRIDE
|
|
197
|
+
const text = String(value ?? "");
|
|
198
|
+
if (text === "") {
|
|
199
|
+
superSetValue("");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
superSetValue(fillMaskWithDigits(getFullMask(), getPastedDigits(withoutCountryCode(text))));
|
|
203
|
+
codeInField = box.countryCode;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
box.setPhoneMask = function(mask) {
|
|
207
|
+
box.phoneMask = mask;
|
|
208
|
+
box.refreshInput();
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
box.setCountryCode = function(code) {
|
|
212
|
+
box.countryCode = code;
|
|
213
|
+
box.refreshInput();
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// WHY: The mask is written into the field on focus, and it is not a value. Before, an empty field with
|
|
217
|
+
// the mask was "not valid": a form counted an optional phone as a missing entry while the cursor
|
|
218
|
+
// was in it, a required one showed "Invalid" instead of "Required", and the mask could be sent.
|
|
219
|
+
box.getValue = function() { // OVERRIDE
|
|
220
|
+
const value = box.input.text;
|
|
221
|
+
return (value === getFullMask()) ? "" : value;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
box.isValid = function() { // OVERRIDE
|
|
225
|
+
const value = box.getValue();
|
|
226
|
+
if (!value || value.indexOf("_") !== -1) {
|
|
227
|
+
return 0;
|
|
228
|
+
}
|
|
229
|
+
return 1;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// Re make input value and show warning if needed
|
|
233
|
+
box.refreshInput = function() {
|
|
234
|
+
|
|
235
|
+
box.applyFormattedValueToInput();
|
|
236
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
237
|
+
box.showWarningIfNotValid(box.isValid());
|
|
238
|
+
setCursorToFirstUnderscore();
|
|
239
|
+
box.value = inputElem.value;
|
|
240
|
+
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
box.fillAutoPlaceholder = function() {
|
|
244
|
+
box.setPlaceholder(box.countryCode + makeRandomPhoneNumber());
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// *** OBJECT INIT CODE:
|
|
248
|
+
|
|
249
|
+
// Show example placeholder
|
|
250
|
+
if (box.placeholder == "(auto)") {
|
|
251
|
+
// A random phone number
|
|
252
|
+
box.fillAutoPlaceholder();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if(box.createInput == 1) { // Always will be 1
|
|
256
|
+
|
|
257
|
+
// WHY: box.paintFocus() of TextField: this copy painted only the background and the line, so the
|
|
258
|
+
// border of a package (ozden, ozdenDark, dark) did not change on focus.
|
|
259
|
+
box.focusFunc = function () {
|
|
260
|
+
box.paintFocus(1);
|
|
261
|
+
// An empty field: write countryCode + phoneMask
|
|
262
|
+
if (inputElem.value.trim() === "") {
|
|
263
|
+
inputElem.value = getFullMask();
|
|
264
|
+
}
|
|
265
|
+
setCursorToFirstUnderscore();
|
|
266
|
+
// WHY: updated at the first focus: the mask shows, and the field is not empty any more.
|
|
267
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
268
|
+
box.showWarningIfNotValid(box.isValid());
|
|
269
|
+
box.onFocus(box);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
box.blurFunc = function() {
|
|
273
|
+
box.paintFocus(0);
|
|
274
|
+
|
|
275
|
+
if (inputElem.value == getFullMask()) { // WHY: The field itself. (getValue() is "" for the mask.)
|
|
276
|
+
box.setValue("");
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
box.onBlur(box);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// A click or a selection anywhere in the field takes the caret to the first _
|
|
283
|
+
const eventNameList = ["mousedown", "mouseup", "click", "select"];
|
|
284
|
+
eventNameList.forEach(function(eventName) {
|
|
285
|
+
inputElem.addEventListener(eventName, function() {
|
|
286
|
+
setCursorToFirstUnderscore();
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
inputElem.addEventListener("keydown", function(event) {
|
|
291
|
+
if (event.key === "Backspace") {
|
|
292
|
+
deleteDigitBeforeCursor(event);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// WHY: a pasted number went next to the mask: maxLength cut it, and its 0 or country code became digits
|
|
297
|
+
// ("555 123 45 67" -> "+90 (555) 123-456_"). The paste now takes the place of the whole number.
|
|
298
|
+
inputElem.addEventListener("paste", function(event) {
|
|
299
|
+
const text = (event.clipboardData) ? event.clipboardData.getData("text") : "";
|
|
300
|
+
if (!text) return;
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
superSetValue(fillMaskWithDigits(getFullMask(), getPastedDigits(text)));
|
|
303
|
+
setCursorToFirstUnderscore();
|
|
304
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
305
|
+
box.showWarningIfNotValid(box.isValid());
|
|
306
|
+
box.onChange(box);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// On an input event, a caret in a wrong place is put right
|
|
310
|
+
box.inputFunc = function () { // If needed, you can override function on ExtendedObject.
|
|
311
|
+
box.refreshInput();
|
|
312
|
+
box.onChange(box);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (inputElem.value !== "") box.setValue(inputElem.value); // WHY: a start value goes into the mask too (setValue)
|
|
318
|
+
box.checkInputValue(); // WHY: TextField checked the start value before this isValid()
|
|
319
|
+
|
|
320
|
+
return endExtendedObject(box);
|
|
321
|
+
|
|
322
|
+
};
|