@syncfusion/ej2-base 24.2.7 → 25.1.35-579988
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.
- package/.eslintrc.json +2 -1
- package/CHANGELOG.md +641 -677
- package/{README.md → ReadMe.md} +100 -100
- package/dist/ej2-base.umd.min.js +1 -10
- package/dist/ej2-base.umd.min.js.map +1 -1
- package/dist/es6/ej2-base.es2015.js +178 -1025
- package/dist/es6/ej2-base.es2015.js.map +1 -1
- package/dist/es6/ej2-base.es5.js +226 -934
- package/dist/es6/ej2-base.es5.js.map +1 -1
- package/dist/global/ej2-base.min.js +1 -10
- package/dist/global/ej2-base.min.js.map +1 -1
- package/dist/global/index.d.ts +0 -9
- package/dist/ts/ajax.ts +236 -0
- package/dist/ts/animation.ts +544 -0
- package/dist/ts/base.ts +357 -0
- package/dist/ts/browser.ts +387 -0
- package/dist/ts/child-property.ts +192 -0
- package/dist/ts/component.ts +519 -0
- package/dist/ts/dom.ts +488 -0
- package/dist/ts/draggable.ts +1155 -0
- package/dist/ts/droppable.ts +172 -0
- package/dist/ts/event-handler.ts +169 -0
- package/dist/ts/internationalization.ts +369 -0
- package/dist/ts/intl/date-formatter.ts +317 -0
- package/dist/ts/intl/date-parser.ts +426 -0
- package/dist/ts/intl/intl-base.ts +1104 -0
- package/dist/ts/intl/number-formatter.ts +411 -0
- package/dist/ts/intl/number-parser.ts +158 -0
- package/dist/ts/intl/parser-base.ts +394 -0
- package/dist/ts/keyboard.ts +238 -0
- package/dist/ts/l10n.ts +94 -0
- package/dist/ts/module-loader.ts +149 -0
- package/dist/ts/notify-property-change.ts +726 -0
- package/dist/ts/observer.ts +236 -0
- package/dist/ts/sanitize-helper.ts +224 -0
- package/dist/ts/template-engine.ts +191 -0
- package/dist/ts/template.ts +329 -0
- package/dist/ts/touch.ts +544 -0
- package/dist/ts/util.ts +523 -0
- package/dist/ts/validate-lic.ts +0 -0
- package/e2e/crypto.js +16 -16
- package/e2e/m.protractor.config.js +286 -286
- package/e2e/modified-protractor/protractor.config.js +316 -316
- package/e2e/protractor.config.js +389 -332
- package/helpers/e2e/index.js +3 -3
- package/license +10 -10
- package/package.json +225 -174
- package/src/ajax.d.ts +1 -1
- package/src/ajax.js +3 -8
- package/src/animation-model.d.ts +41 -41
- package/src/animation.d.ts +6 -6
- package/src/animation.js +25 -25
- package/src/base.d.ts +2 -1
- package/src/base.js +9 -7
- package/src/component-model.d.ts +16 -16
- package/src/component.d.ts +9 -3
- package/src/component.js +50 -38
- package/src/draggable-model.d.ts +113 -113
- package/src/draggable.d.ts +2 -0
- package/src/draggable.js +45 -29
- package/src/droppable-model.d.ts +23 -23
- package/src/droppable.js +19 -19
- package/src/event-handler.js +2 -1
- package/src/index.d.ts +0 -3
- package/src/index.js +0 -3
- package/src/intl/date-formatter.js +2 -6
- package/src/intl/date-parser.js +1 -20
- package/src/intl/intl-base.js +1 -164
- package/src/intl/number-formatter.d.ts +3 -0
- package/src/intl/number-formatter.js +7 -7
- package/src/intl/number-parser.js +1 -0
- package/src/keyboard-model.d.ts +16 -16
- package/src/keyboard.js +19 -19
- package/src/module-loader.d.ts +12 -0
- package/src/module-loader.js +11 -0
- package/src/notify-property-change.js +3 -2
- package/src/observer.js +2 -0
- package/src/sanitize-helper.js +5 -0
- package/src/template-engine.js +1 -0
- package/src/template.js +3 -2
- package/src/touch-model.d.ts +39 -39
- package/src/touch.js +19 -19
- package/src/validate-lic.d.ts +0 -11
- package/src/validate-lic.js +1 -259
- package/styles/_all.scss +2 -2
- package/styles/_bds-dark-definition.scss +15 -0
- package/styles/_bds-definition.scss +15 -0
- package/styles/_bootstrap-dark-definition.scss +42 -42
- package/styles/_bootstrap-definition.scss +42 -42
- package/styles/_bootstrap4-definition.scss +11 -11
- package/styles/_bootstrap5-dark-definition.scss +9 -9
- package/styles/_bootstrap5-definition.scss +8 -8
- package/styles/_fabric-dark-definition.scss +42 -42
- package/styles/_fabric-definition.scss +42 -42
- package/styles/_fluent-dark-definition.scss +9 -9
- package/styles/_fluent-definition.scss +9 -9
- package/styles/_fluent2-definition.scss +9 -0
- package/styles/_fusionnew-dark-definition.scss +8 -8
- package/styles/_fusionnew-definition.scss +8 -8
- package/styles/_highcontrast-definition.scss +42 -42
- package/styles/_highcontrast-light-definition.scss +42 -42
- package/styles/_material-dark-definition.scss +48 -48
- package/styles/_material-definition.scss +49 -49
- package/styles/_material3-dark-definition.scss +14 -14
- package/styles/_material3-definition.scss +15 -15
- package/styles/_tailwind-dark-definition.scss +15 -15
- package/styles/_tailwind-definition.scss +15 -15
- package/styles/animation/_all.scss +560 -560
- package/styles/bootstrap-dark.css +10 -1
- package/styles/bootstrap.css +10 -1
- package/styles/bootstrap4.css +10 -1
- package/styles/bootstrap5-dark.css +10 -1
- package/styles/bootstrap5.css +10 -1
- package/styles/common/_all.scss +2 -2
- package/styles/common/_core.scss +117 -117
- package/styles/common/_mixin.scss +9 -9
- package/styles/definition/_bds-dark.scss +1179 -0
- package/styles/definition/_bds.scss +1474 -0
- package/styles/definition/_bootstrap-dark.scss +219 -219
- package/styles/definition/_bootstrap.scss +215 -215
- package/styles/definition/_bootstrap4.scss +167 -167
- package/styles/definition/_bootstrap5-dark.scss +493 -493
- package/styles/definition/_bootstrap5.scss +494 -494
- package/styles/definition/_fabric-dark.scss +200 -200
- package/styles/definition/_fabric.scss +198 -198
- package/styles/definition/_fluent-dark.scss +557 -557
- package/styles/definition/_fluent.scss +558 -558
- package/styles/definition/_fluent2.scss +2198 -0
- package/styles/definition/_fusionnew-dark.scss +362 -362
- package/styles/definition/_fusionnew.scss +363 -363
- package/styles/definition/_highcontrast-light.scss +193 -193
- package/styles/definition/_highcontrast.scss +195 -195
- package/styles/definition/_material-dark.scss +198 -198
- package/styles/definition/_material.scss +192 -192
- package/styles/definition/_material3-dark.scss +710 -710
- package/styles/definition/_material3.scss +792 -792
- package/styles/definition/_tailwind-dark.scss +488 -488
- package/styles/definition/_tailwind.scss +485 -485
- package/styles/fabric-dark.css +10 -1
- package/styles/fabric.css +10 -1
- package/styles/fluent-dark.css +10 -1
- package/styles/fluent.css +10 -1
- package/styles/highcontrast-light.css +10 -1
- package/styles/highcontrast.css +10 -1
- package/styles/material-dark.css +10 -1
- package/styles/material.css +10 -1
- package/styles/material3-dark.css +10 -1
- package/styles/material3.css +10 -1
- package/styles/offline-theme/material-dark.css +10 -1
- package/styles/offline-theme/material.css +10 -1
- package/styles/offline-theme/tailwind-dark.css +10 -1
- package/styles/offline-theme/tailwind.css +10 -1
- package/styles/tailwind-dark.css +10 -1
- package/styles/tailwind.css +10 -1
- package/.github/PULL_REQUEST_TEMPLATE/Bug.md +0 -60
- package/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -42
- package/bin/syncfusion-license.js +0 -2
- package/dist/ej2-base.min.js +0 -10
- package/e2e/index.d.ts +0 -27
- package/src/fetch.d.ts +0 -114
- package/src/fetch.js +0 -116
- package/src/hijri-parser.d.ts +0 -19
- package/src/hijri-parser.js +0 -204
package/dist/ts/dom.ts
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functions related to dom operations.
|
|
3
|
+
*/
|
|
4
|
+
import { EventHandler } from './event-handler';
|
|
5
|
+
import { isNullOrUndefined, getValue, setValue, isObject, extend } from './util';
|
|
6
|
+
|
|
7
|
+
const SVG_REG: RegExp = /^svg|^path|^g/;
|
|
8
|
+
|
|
9
|
+
export interface ElementProperties {
|
|
10
|
+
id?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
innerHTML?: string;
|
|
13
|
+
styles?: string;
|
|
14
|
+
attrs?: { [key: string]: string };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Function to create Html element.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} tagName - Name of the tag, id and class names.
|
|
20
|
+
* @param {ElementProperties} properties - Object to set properties in the element.
|
|
21
|
+
* @param {ElementProperties} properties.id - To set the id to the created element.
|
|
22
|
+
* @param {ElementProperties} properties.className - To add classes to the element.
|
|
23
|
+
* @param {ElementProperties} properties.innerHTML - To set the innerHTML to element.
|
|
24
|
+
* @param {ElementProperties} properties.styles - To set the some custom styles to element.
|
|
25
|
+
* @param {ElementProperties} properties.attrs - To set the attributes to element.
|
|
26
|
+
* @returns {any} ?
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
export function createElement(tagName: string, properties?: ElementProperties): HTMLElement {
|
|
30
|
+
const element: Element = (SVG_REG.test(tagName) ? document.createElementNS('http://www.w3.org/2000/svg', tagName) : document.createElement(tagName));
|
|
31
|
+
if (typeof (properties) === 'undefined') {
|
|
32
|
+
return <HTMLElement>element;
|
|
33
|
+
}
|
|
34
|
+
element.innerHTML = (properties.innerHTML ? properties.innerHTML : '');
|
|
35
|
+
|
|
36
|
+
if (properties.className !== undefined) {
|
|
37
|
+
element.className = properties.className;
|
|
38
|
+
}
|
|
39
|
+
if (properties.id !== undefined) {
|
|
40
|
+
element.id = properties.id;
|
|
41
|
+
}
|
|
42
|
+
if (properties.styles !== undefined) {
|
|
43
|
+
element.setAttribute('style', properties.styles);
|
|
44
|
+
}
|
|
45
|
+
if (properties.attrs !== undefined) {
|
|
46
|
+
attributes(element, properties.attrs);
|
|
47
|
+
}
|
|
48
|
+
return <HTMLElement>element;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The function used to add the classes to array of elements
|
|
53
|
+
*
|
|
54
|
+
* @param {Element[]|NodeList} elements - An array of elements that need to add a list of classes
|
|
55
|
+
* @param {string|string[]} classes - String or array of string that need to add an individual element as a class
|
|
56
|
+
* @returns {any} .
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
export function addClass(elements: Element[] | NodeList, classes: string | string[]): Element[] | NodeList {
|
|
60
|
+
const classList: string[] = getClassList(classes);
|
|
61
|
+
const regExp: RegExpConstructor = RegExp;
|
|
62
|
+
for (const ele of (elements as Element[])) {
|
|
63
|
+
for (const className of classList) {
|
|
64
|
+
if (isObject(ele)) {
|
|
65
|
+
const curClass: string = getValue('attributes.className', ele);
|
|
66
|
+
if (isNullOrUndefined(curClass)) {
|
|
67
|
+
setValue('attributes.className', className, ele);
|
|
68
|
+
} else if (!new regExp('\\b' + className + '\\b', 'i').test(curClass)) {
|
|
69
|
+
setValue('attributes.className', curClass + ' ' + className, ele);
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (!ele.classList.contains(className)) {
|
|
73
|
+
ele.classList.add(className);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return elements;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The function used to add the classes to array of elements
|
|
82
|
+
*
|
|
83
|
+
* @param {Element[]|NodeList} elements - An array of elements that need to remove a list of classes
|
|
84
|
+
* @param {string|string[]} classes - String or array of string that need to add an individual element as a class
|
|
85
|
+
* @returns {any} .
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
export function removeClass(elements: Element[] | NodeList, classes: string | string[]): Element[] | NodeList {
|
|
89
|
+
const classList: string[] = getClassList(classes);
|
|
90
|
+
for (const ele of (elements as Element[])) {
|
|
91
|
+
const flag: boolean = isObject(ele);
|
|
92
|
+
const canRemove: boolean = flag ? getValue('attributes.className', ele) : ele.className !== '';
|
|
93
|
+
if (canRemove) {
|
|
94
|
+
for (const className of classList) {
|
|
95
|
+
if (flag) {
|
|
96
|
+
const classes: string = getValue('attributes.className', ele);
|
|
97
|
+
const classArr: string[] = classes.split(' ');
|
|
98
|
+
const index: number = classArr.indexOf(className);
|
|
99
|
+
if (index !== -1) {
|
|
100
|
+
classArr.splice(index, 1);
|
|
101
|
+
}
|
|
102
|
+
setValue('attributes.className', classArr.join(' '), ele);
|
|
103
|
+
} else {
|
|
104
|
+
ele.classList.remove(className);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return elements;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The function used to get classlist.
|
|
114
|
+
*
|
|
115
|
+
* @param {string | string[]} classes - An element the need to check visibility
|
|
116
|
+
* @returns {string[]} ?
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
function getClassList(classes: string | string[]): string[] {
|
|
120
|
+
let classList: string[] = [];
|
|
121
|
+
if (typeof classes === 'string') {
|
|
122
|
+
classList.push(classes);
|
|
123
|
+
} else {
|
|
124
|
+
classList = classes;
|
|
125
|
+
}
|
|
126
|
+
return classList;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The function used to check element is visible or not.
|
|
131
|
+
*
|
|
132
|
+
* @param {Element|Node} element - An element the need to check visibility
|
|
133
|
+
* @returns {boolean} ?
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
136
|
+
export function isVisible(element: Element | Node): boolean {
|
|
137
|
+
const ele: HTMLElement = <HTMLElement>element;
|
|
138
|
+
return (ele.style.visibility === '' && ele.offsetWidth > 0);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The function used to insert an array of elements into a first of the element.
|
|
143
|
+
*
|
|
144
|
+
* @param {Element[]|NodeList} fromElements - An array of elements that need to prepend.
|
|
145
|
+
* @param {Element} toElement - An element that is going to prepend.
|
|
146
|
+
* @param {boolean} isEval - ?
|
|
147
|
+
* @returns {Element[] | NodeList} ?
|
|
148
|
+
* @private
|
|
149
|
+
*/
|
|
150
|
+
export function prepend(fromElements: Element[] | NodeList, toElement: Element, isEval?: boolean): Element[] | NodeList {
|
|
151
|
+
const docFrag: DocumentFragment = document.createDocumentFragment();
|
|
152
|
+
for (const ele of (fromElements as Element[])) {
|
|
153
|
+
docFrag.appendChild(ele);
|
|
154
|
+
}
|
|
155
|
+
toElement.insertBefore(docFrag, toElement.firstElementChild);
|
|
156
|
+
if (isEval) {
|
|
157
|
+
executeScript(toElement);
|
|
158
|
+
}
|
|
159
|
+
return fromElements;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The function used to insert an array of elements into last of the element.
|
|
164
|
+
*
|
|
165
|
+
* @param {Element[]|NodeList} fromElements - An array of elements that need to append.
|
|
166
|
+
* @param {Element} toElement - An element that is going to prepend.
|
|
167
|
+
* @param {boolean} isEval - ?
|
|
168
|
+
* @returns {Element[] | NodeList} ?
|
|
169
|
+
* @private
|
|
170
|
+
*/
|
|
171
|
+
export function append(fromElements: Element[] | NodeList, toElement: Element, isEval?: boolean): Element[] | NodeList {
|
|
172
|
+
const docFrag: DocumentFragment = document.createDocumentFragment();
|
|
173
|
+
if (fromElements instanceof NodeList) {
|
|
174
|
+
while (fromElements.length > 0) {
|
|
175
|
+
docFrag.appendChild(fromElements[0]);
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
for (const ele of <Element[]>fromElements) {
|
|
179
|
+
docFrag.appendChild(ele);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
toElement.appendChild(docFrag);
|
|
183
|
+
if (isEval) {
|
|
184
|
+
executeScript(toElement);
|
|
185
|
+
}
|
|
186
|
+
return fromElements;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The function is used to evaluate script from Ajax request
|
|
191
|
+
*
|
|
192
|
+
* @param {Element} ele - An element is going to evaluate the script
|
|
193
|
+
* @returns {void} ?
|
|
194
|
+
*/
|
|
195
|
+
function executeScript(ele: Element): void {
|
|
196
|
+
const eleArray: NodeList = ele.querySelectorAll('script');
|
|
197
|
+
eleArray.forEach((element: Element) => {
|
|
198
|
+
const script: HTMLScriptElement = document.createElement('script');
|
|
199
|
+
script.text = element.innerHTML;
|
|
200
|
+
document.head.appendChild(script);
|
|
201
|
+
detach(script);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The function used to remove the element from parentnode
|
|
207
|
+
*
|
|
208
|
+
* @param {Element|Node|HTMLElement} element - An element that is going to detach from the Dom
|
|
209
|
+
* @returns {any} ?
|
|
210
|
+
* @private
|
|
211
|
+
*/
|
|
212
|
+
// eslint-disable-next-line
|
|
213
|
+
export function detach(element: Element | Node | HTMLElement): any {
|
|
214
|
+
const parentNode: Node = element.parentNode;
|
|
215
|
+
if (parentNode) {
|
|
216
|
+
return <Element>parentNode.removeChild(element);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The function used to remove the element from Dom also clear the bounded events
|
|
222
|
+
*
|
|
223
|
+
* @param {Element|Node|HTMLElement} element - An element remove from the Dom
|
|
224
|
+
* @returns {void} ?
|
|
225
|
+
* @private
|
|
226
|
+
*/
|
|
227
|
+
export function remove(element: Element | Node | HTMLElement): void {
|
|
228
|
+
const parentNode: Node = element.parentNode;
|
|
229
|
+
EventHandler.clearEvents(<Element>element);
|
|
230
|
+
parentNode.removeChild(element);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The function helps to set multiple attributes to an element
|
|
235
|
+
*
|
|
236
|
+
* @param {Element|Node} element - An element that need to set attributes.
|
|
237
|
+
* @param {string} attributes - JSON Object that is going to as attributes.
|
|
238
|
+
* @returns {Element} ?
|
|
239
|
+
* @private
|
|
240
|
+
*/
|
|
241
|
+
// eslint-disable-next-line
|
|
242
|
+
export function attributes(element: Element | Node | any, attributes: { [key: string]: string }): Element {
|
|
243
|
+
const keys: string[] = Object.keys(attributes);
|
|
244
|
+
const ele: Element = <Element>element;
|
|
245
|
+
for (const key of keys) {
|
|
246
|
+
if (isObject(ele)) {
|
|
247
|
+
let iKey: string = key;
|
|
248
|
+
if (key === 'tabindex') {
|
|
249
|
+
iKey = 'tabIndex';
|
|
250
|
+
}
|
|
251
|
+
ele.attributes[`${iKey}`] = attributes[`${key}`];
|
|
252
|
+
} else {
|
|
253
|
+
ele.setAttribute(key, attributes[`${key}`]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return ele;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The function selects the element from giving context.
|
|
261
|
+
*
|
|
262
|
+
* @param {string} selector - Selector string need fetch element
|
|
263
|
+
* @param {Document|Element} context - It is an optional type, That specifies a Dom context.
|
|
264
|
+
* @param {boolean} needsVDOM ?
|
|
265
|
+
* @returns {any} ?
|
|
266
|
+
* @private
|
|
267
|
+
*/
|
|
268
|
+
// eslint-disable-next-line
|
|
269
|
+
export function select(selector: string, context: Document | Element = document, needsVDOM?: boolean): any {
|
|
270
|
+
selector = querySelectId(selector);
|
|
271
|
+
return context.querySelector(selector);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The function selects an array of element from the given context.
|
|
276
|
+
*
|
|
277
|
+
* @param {string} selector - Selector string need fetch element
|
|
278
|
+
* @param {Document|Element} context - It is an optional type, That specifies a Dom context.
|
|
279
|
+
* @param {boolean} needsVDOM ?
|
|
280
|
+
* @returns {HTMLElement[]} ?
|
|
281
|
+
* @private
|
|
282
|
+
*/
|
|
283
|
+
// eslint-disable-next-line
|
|
284
|
+
export function selectAll(selector: string, context: Document | Element = document, needsVDOM?: boolean): HTMLElement[] {
|
|
285
|
+
selector = querySelectId(selector);
|
|
286
|
+
const nodeList: NodeList = context.querySelectorAll(selector);
|
|
287
|
+
return <HTMLElement[] & NodeList>nodeList;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* The function selects an id of element from the given context.
|
|
292
|
+
*
|
|
293
|
+
* @param {string} selector - Selector string need fetch element
|
|
294
|
+
* @returns {string} ?
|
|
295
|
+
* @private
|
|
296
|
+
*/
|
|
297
|
+
function querySelectId(selector: string): string {
|
|
298
|
+
const charRegex: RegExp = /(!|"|\$|%|&|'|\(|\)|\*|\/|:|;|<|=|\?|@|\]|\^|`|{|}|\||\+|~)/g;
|
|
299
|
+
if (selector.match(/#[0-9]/g) || selector.match(charRegex)) {
|
|
300
|
+
const idList: string[] = selector.split(',');
|
|
301
|
+
for (let i: number = 0; i < idList.length; i++) {
|
|
302
|
+
const list: string[] = idList[parseInt(i.toString(), 10)].split(' ');
|
|
303
|
+
for (let j: number = 0; j < list.length; j++) {
|
|
304
|
+
if (list[parseInt(j.toString(), 10)].indexOf('#') > -1) {
|
|
305
|
+
if (!list[parseInt(j.toString(), 10)].match(/\[.*\]/)) {
|
|
306
|
+
const splitId: string[] = list[parseInt(j.toString(), 10)].split('#');
|
|
307
|
+
if (splitId[1].match(/^\d/) || splitId[1].match(charRegex)) {
|
|
308
|
+
const setId: string[] = list[parseInt(j.toString(), 10)].split('.');
|
|
309
|
+
setId[0] = setId[0].replace(/#/, '[id=\'') + '\']';
|
|
310
|
+
list[parseInt(j.toString(), 10)] = setId.join('.');
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
idList[parseInt(i.toString(), 10)] = list.join(' ');
|
|
316
|
+
}
|
|
317
|
+
return idList.join(',');
|
|
318
|
+
}
|
|
319
|
+
return selector;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Returns single closest parent element based on class selector.
|
|
324
|
+
*
|
|
325
|
+
* @param {Element} element - An element that need to find the closest element.
|
|
326
|
+
* @param {string} selector - A classSelector of closest element.
|
|
327
|
+
* @returns {Element} ?
|
|
328
|
+
* @private
|
|
329
|
+
*/
|
|
330
|
+
export function closest(element: Element | Node, selector: string): Element {
|
|
331
|
+
let el: Element = <Element>element;
|
|
332
|
+
if (typeof el.closest === 'function') {
|
|
333
|
+
return el.closest(selector);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
while (el && el.nodeType === 1) {
|
|
337
|
+
if (matches(el, selector)) {
|
|
338
|
+
return el;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
el = <Element>el.parentNode;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Returns all sibling elements of the given element.
|
|
349
|
+
*
|
|
350
|
+
* @param {Element|Node} element - An element that need to get siblings.
|
|
351
|
+
* @returns {Element[]} ?
|
|
352
|
+
* @private
|
|
353
|
+
*/
|
|
354
|
+
export function siblings(element: Element | Node): Element[] {
|
|
355
|
+
const siblings: Element[] = [];
|
|
356
|
+
const childNodes: Node[] = Array.prototype.slice.call(element.parentNode.childNodes);
|
|
357
|
+
for (const curNode of childNodes) {
|
|
358
|
+
if (curNode.nodeType === Node.ELEMENT_NODE && element !== curNode) {
|
|
359
|
+
siblings.push(<Element>curNode);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return <Element[]>siblings;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* set the value if not exist. Otherwise set the existing value
|
|
367
|
+
*
|
|
368
|
+
* @param {HTMLElement} element - An element to which we need to set value.
|
|
369
|
+
* @param {string} property - Property need to get or set.
|
|
370
|
+
* @param {string} value - value need to set.
|
|
371
|
+
* @returns {string} ?
|
|
372
|
+
* @private
|
|
373
|
+
*/
|
|
374
|
+
export function getAttributeOrDefault(element: HTMLElement, property: string, value: string): string {
|
|
375
|
+
let attrVal: string;
|
|
376
|
+
const isObj: boolean = isObject(element);
|
|
377
|
+
if (isObj) {
|
|
378
|
+
attrVal = getValue('attributes.' + property, element);
|
|
379
|
+
} else {
|
|
380
|
+
attrVal = element.getAttribute(property);
|
|
381
|
+
}
|
|
382
|
+
if (isNullOrUndefined(attrVal) && value) {
|
|
383
|
+
if (!isObj) {
|
|
384
|
+
element.setAttribute(property, value.toString());
|
|
385
|
+
} else {
|
|
386
|
+
element.attributes[`${property}`] = value;
|
|
387
|
+
}
|
|
388
|
+
attrVal = value;
|
|
389
|
+
}
|
|
390
|
+
return attrVal;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Set the style attributes to Html element.
|
|
395
|
+
*
|
|
396
|
+
* @param {HTMLElement} element - Element which we want to set attributes
|
|
397
|
+
* @param {any} attrs - Set the given attributes to element
|
|
398
|
+
* @returns {void} ?
|
|
399
|
+
* @private
|
|
400
|
+
*/
|
|
401
|
+
export function setStyleAttribute(element: HTMLElement, attrs: { [key: string]: Object }): void {
|
|
402
|
+
if (attrs !== undefined) {
|
|
403
|
+
Object.keys(attrs).forEach((key: string) => {
|
|
404
|
+
// eslint-disable-next-line
|
|
405
|
+
(<any>element).style[key] = attrs[key];
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Method for add and remove classes to a dom element.
|
|
412
|
+
*
|
|
413
|
+
* @param {Element} element - Element for add and remove classes
|
|
414
|
+
* @param {string[]} addClasses - List of classes need to be add to the element
|
|
415
|
+
* @param {string[]} removeClasses - List of classes need to be remove from the element
|
|
416
|
+
* @returns {void} ?
|
|
417
|
+
* @private
|
|
418
|
+
*/
|
|
419
|
+
export function classList(element: Element, addClasses: string[], removeClasses: string[]): void {
|
|
420
|
+
addClass([element], addClasses);
|
|
421
|
+
removeClass([element], removeClasses);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Method to check whether the element matches the given selector.
|
|
426
|
+
*
|
|
427
|
+
* @param {Element} element - Element to compare with the selector.
|
|
428
|
+
* @param {string} selector - String selector which element will satisfy.
|
|
429
|
+
* @returns {void} ?
|
|
430
|
+
* @private
|
|
431
|
+
*/
|
|
432
|
+
export function matches(element: Element, selector: string): boolean {
|
|
433
|
+
// eslint-disable-next-line
|
|
434
|
+
let matches: Function = element.matches || (element as any).msMatchesSelector || element.webkitMatchesSelector;
|
|
435
|
+
if (matches) {
|
|
436
|
+
return matches.call(element, selector);
|
|
437
|
+
} else {
|
|
438
|
+
return [].indexOf.call(document.querySelectorAll(selector), element) !== -1;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Method to get the html text from DOM.
|
|
444
|
+
*
|
|
445
|
+
* @param {HTMLElement} ele - Element to compare with the selector.
|
|
446
|
+
* @param {string} innerHTML - String selector which element will satisfy.
|
|
447
|
+
* @returns {void} ?
|
|
448
|
+
* @private
|
|
449
|
+
*/
|
|
450
|
+
export function includeInnerHTML(ele: HTMLElement, innerHTML: string): void {
|
|
451
|
+
ele.innerHTML = innerHTML;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Method to get the containsclass.
|
|
456
|
+
*
|
|
457
|
+
* @param {HTMLElement} ele - Element to compare with the selector.
|
|
458
|
+
* @param {string} className - String selector which element will satisfy.
|
|
459
|
+
* @returns {any} ?
|
|
460
|
+
* @private
|
|
461
|
+
*/
|
|
462
|
+
// eslint-disable-next-line
|
|
463
|
+
export function containsClass(ele: HTMLElement, className: string): any {
|
|
464
|
+
if (isObject(ele)) {
|
|
465
|
+
// eslint-disable-next-line
|
|
466
|
+
return new RegExp('\\b' + className + '\\b', 'i').test((ele as any).attributes.className);
|
|
467
|
+
} else {
|
|
468
|
+
return ele.classList.contains(className);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Method to check whether the element matches the given selector.
|
|
473
|
+
*
|
|
474
|
+
* @param {Object} element - Element to compare with the selector.
|
|
475
|
+
* @param {boolean} deep ?
|
|
476
|
+
* @returns {any} ?
|
|
477
|
+
* @private
|
|
478
|
+
*/
|
|
479
|
+
// eslint-disable-next-line
|
|
480
|
+
export function cloneNode(element: Object, deep?: boolean): any {
|
|
481
|
+
if (isObject(element)) {
|
|
482
|
+
if (deep) {
|
|
483
|
+
return extend({}, {}, element, true);
|
|
484
|
+
}
|
|
485
|
+
} else {
|
|
486
|
+
return (element as HTMLElement).cloneNode(deep);
|
|
487
|
+
}
|
|
488
|
+
}
|