├── .gitignore
├── LICENSE
├── README.md
└── src
├── .npmignore
├── LICENSE
├── README.md
├── changelog.md
├── dom-global.d.ts
├── dom.js
├── index.d.ts
├── package.json
├── postinstall.js
└── unmaintained.svg
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea
2 | /demo/node_modules/
3 | /demo/platforms/
4 | *.tar
5 | *.tgz
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015-2018 Nathanael Anderson
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Archived
2 | See: https://fluentreports.com/blog/?p=1434
3 |
4 |
5 |
6 | # NativeScript-Dom
7 |
8 |
9 |
10 | We have an awesome, new service in town! This service provides tested new and upgraded plugins. All ProPlugins are already known to work with NativeScript 6.x.
11 | If you are interested in getting the latest, known working, and enhanced plugins; check out https://ProPlugins.org -- because I strongly believe in what ProPlugins offers the community all of my development work is being done on the ProPlugins version.
12 |
13 | Please feel free to continue to use this version of the plugin, it is now 100% being maintained by **YOU** the community, and as such
14 | I will gladly continue to support the community version by accepting any/all PR's for this plugin and publish it. I will attempt to verify the PR doesn't have any backdoors; but I won't be doing any testing, so if it is broken it is up to you to send a PR!
15 |
16 |
17 | ## Documentation
18 | The [documentation](src/README.md) for the plugin is located in the [src folder](src).
19 |
--------------------------------------------------------------------------------
/src/.npmignore:
--------------------------------------------------------------------------------
1 | demo/
2 | .git/
3 | .gitignore
4 | .idea/
5 | docs/
6 | *.tar
7 | *.tgz
8 | .npmignore
9 | !index.d.ts
10 | !dom-global.d.ts
11 |
--------------------------------------------------------------------------------
/src/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015-2018 Nathanael Anderson
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/src/README.md:
--------------------------------------------------------------------------------
1 | # NativeScript-Dom
2 |
3 | ## ProPlugins
4 | We have an awesome, new service in town! This service provides tested new and upgraded plugins. All ProPlugins are already known to work with NativeScript 6.x.
5 | If you are interested in getting the latest, known working, and enhanced plugins; check out https://ProPlugins.org -- because I strongly believe in what ProPlugins offers the community all of my development work is being done on the ProPlugins version.
6 |
7 |
8 |
9 | ## Community
10 | Please feel free to continue to use this version of the plugin, it is now 100% being maintained by **YOU** the community, and as such
11 | I will gladly continue to support the community version by accepting any/all PR's for this plugin and publish it. I will attempt to verify the PR doesn't have any backdoors; but I won't be doing any testing, so if it is broken it is up to you to send a PR!
12 |
13 | ## Updates
14 | Please feel free to fork this repo and update the functions or add additional DOM based functions!
15 |
16 | ## Installation
17 | For NativeScript 3.0 and later type
18 |
19 | ```bash
20 | tns plugin add nativescript-dom
21 | ```
22 |
23 | To use in Nativescript 2.5 or earlier type:
24 |
25 | ```bash
26 | tns plugin add nativescript-dom@1.1.0
27 | ```
28 |
29 | ## Usage
30 | To use the module you just `require()` it:
31 |
32 | ```js
33 | require("nativescript-dom");
34 | ```
35 |
36 | **Note:** You do NOT need to keep a reference to it; and you only need to load it once.
37 | It will automatically attach its methods to all the proper classes in the NativeScript library, making it act as if they are built in.
38 |
39 | ### Methods
40 |
41 | #### `getElementById(id)`
42 | #### `getElementsByClassName(className)`
43 | #### `getElementsByTagName(tagName)`
44 |
45 | These are globally available! Like their Web DOM counterparts; they return elements based on the critera.
46 |
47 | #### `view.getElementById(id)`
48 | #### `view.getElementsByClassName(className)`
49 | #### `view.getElementsByTagName(tagName)`
50 | Like their Web DOM counterparts; returns the children elements based on the critera.
51 |
52 | ```js
53 | exports.pageLoaded = function(args) {
54 | var page = args.object;
55 | var stackLayout = page.getElementsByTagName('StackLayout')[0];
56 | var button = stackLayout.getElementsByClassName('clickButton')[0];
57 | button.classList.toggle('hidden');
58 | }
59 | ```
60 |
61 | ### `view.runAgainstId(id, function(elem) { /* Do something with elem */ })`
62 | ### `view.runAgainstClasses(className, function(elem) { /* Do something with elem */ })`
63 | ### `view.runAgainstTagNames(tag, function(elem) { /* Do something with elem */ })`
64 | This will automatically run your function passing it the elem that it matches; it will call your function multiple times once for each element that matches your selection.
65 |
66 | ```js
67 | exports.pageLoaded = function(args) {
68 | var page = args.object;
69 | page.runAgainstClasses('clickButton', function(elem) {
70 | elem.classList.toggle('hidden');
71 | });
72 | }
73 | ```
74 |
75 | #### `view.classList.add(className, className, ...)`
76 | Add a class to the view's class list at the end
77 |
78 | ```js
79 | someButton.classList.add('hidden'); // ClassList on this button will be "class1 class2 classx hidden"
80 | ```
81 |
82 | #### `view.classList.insert(className, className, ...)`
83 | Add a class to the view's class list at the front
84 | ```js
85 | someButton.classList.insert('hidden'); // ClassList on this button will be "hidden class1 class2 classx"
86 | ```
87 |
88 |
89 | #### `view.classList.remove(className, className, ...)`
90 | Removes a class from the view's class list
91 | ```js
92 | someButton.classList.remove('hidden'); // ClassList would then equal "class1 class2 class3"
93 | ```
94 |
95 | #### `view.classList.toggle(className[, force])`
96 | Toggles a class name
97 | if force = true, will force adding the class name only. (And won't remove it, but you won't have a second)
98 | if force = false, will force removing the class name only. (And won't add it)
99 |
100 | #### `view.classList.item(index)`
101 | Returns the class name at that location in the class list.
102 |
103 | #### `view.classList.contains(className)`
104 | Returns true or false if the class name exists in the class list.
105 | ```js
106 | if (someButton.classList.contains('hidden')) {
107 | someButton.classList.remove('hidden');
108 | } else {
109 | someButton.classList.add('hidden');
110 | }
111 |
112 | // someButton.classList.toggle('hidden'); would be equivelent to the 5 lines above.
113 | ```
114 |
115 | #### TypeScript Global Augmentation
116 | This module ships a file, `dom-global.d.ts`, to enable intellisense and benefit from the TypeScript Typings
117 | add a reference in your `references.d.ts` file. Below is the snippet you can paste into the `references.d.ts` in the root of your app.
118 |
119 | *You may need to restart your IDE for it to resolve the added typings.*
120 |
121 |
122 | ```xml
123 | ///
124 | ```
125 |
126 | ## Thanks & Contributors
127 |
128 | - [Brad Martin](https://github.com/bradmartin) - For the TS Typings
129 | - [Danny Feliz](https://github.com/DannyFeliz) - For Documentation Updates
130 | - [CrazyPython](https://github.com/CrazyPython) - For Documentation Updates
131 | - [Ludwik Trammer](https://github.com/ludwiktrammer) - For 3.0 compatibility
132 |
--------------------------------------------------------------------------------
/src/changelog.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | - v1.00 - Initial Release
4 | - v1.03 - Updated the getElementById and getElementsByTagName to search ListView children
5 | - v1.04 - Doc updates
6 | - v1.05 - Added runAgainstId, runAgainstClasses & runAgainstTagNames
7 | - v1.06 - Compatibility with NS 2.2.x
8 | - v1.07 - Updated docs & Thanks to Brad for TypeScript typings!
9 | - v1.09 - getElementByTagName now supports *
10 | - v1.10 - Fixed view.runAgainstId (copy/paste error)
11 | - v2.00 - NativeScript 3.0 Compatibility (Does not work with NativeScript v2.5 or before)
12 | - v2.01 - Eliminate NativeScript 3.0 Peer dependancy.
--------------------------------------------------------------------------------
/src/dom-global.d.ts:
--------------------------------------------------------------------------------
1 | declare module 'nativescript-dom-global' {
2 |
3 | import * as TNSDom from 'nativescript-dom';
4 |
5 | global {
6 | var getElementById: typeof TNSDom.getElementById;
7 | var getElementsByClassName: typeof TNSDom.getElementsByClassName;
8 | var getElementsByTagName: typeof TNSDom.getElementsByTagName;
9 | var runAgainstClasses: typeof TNSDom.runAgainstClasses;
10 | var runAgainstId: typeof TNSDom.runAgainstId;
11 | var runAgainstTagNames: typeof TNSDom.runAgainstTagNames;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/dom.js:
--------------------------------------------------------------------------------
1 | /**********************************************************************************
2 | * (c) 2015-2017, Master Technology
3 | * Licensed under the MIT license or contact me for a Support or Commercial License
4 | *
5 | * I do contract work in most languages, so let me solve your problems!
6 | *
7 | * Any questions please feel free to email me or put a issue up on the github repo
8 | * Version 0.1.0 Nathan@master-technology.com
9 | *********************************************************************************/
10 | "use strict";
11 |
12 | /* jshint node: true, browser: true, unused: true, undef: true */
13 | /* global global */
14 |
15 | // Load the required modules
16 | var viewBase = require("@nativescript/core/ui/core/view-base");
17 | var frame = require("@nativescript/core/ui/frame");
18 |
19 | // global.android is already defined on android devices
20 | // We are defining global.ios on ios devices, since the iOS team can't seem to do it. ;-)
21 | if (global.NSObject && global.NSString && typeof global.ios === "undefined") {
22 | global.ios = true;
23 | Object.freeze(global.ios);
24 | }
25 |
26 | if (!global.getElementById) {
27 | /***
28 | * Find a element by an id
29 | * @param id
30 | * @returns {ViewBase} or {undefined}
31 | */
32 | global.getElementById = function (id) {
33 | return getElementById(getCurrentActiveModel(), id);
34 | };
35 | }
36 |
37 | if (!viewBase.ViewBase.prototype.getElementById) {
38 | /***
39 | * Find an element by a id
40 | * @param id
41 | * @returns {ViewBase} or {undefined}
42 | */
43 | viewBase.ViewBase.prototype.getElementById = function (id) {
44 | return getElementById(this, id);
45 | };
46 | }
47 |
48 | if (!global.getElementsByClassName) {
49 | /***
50 | * getElementsByClassName
51 | * @param className - The class name
52 | * @returns {Array} of elements
53 | */
54 | global.getElementsByClassName = function (className) {
55 | return getElementsByClassName(getCurrentActiveModel(), className);
56 | };
57 | }
58 |
59 | if (!viewBase.ViewBase.prototype.getElementsByClassName) {
60 | /***
61 | * Finds all elements with the class name
62 | * @param className - the Class name
63 | * @returns {Array} of elements
64 | */
65 | viewBase.ViewBase.prototype.getElementsByClassName = function (className) {
66 | return getElementsByClassName(this, className);
67 | };
68 | }
69 |
70 | if (!global.getElementsByTagName) {
71 | /**
72 | * Finds all elements by a Tag name
73 | * @param tagName
74 | * @returns {Array}
75 | */
76 | global.getElementsByTagName = function (tagName) {
77 | return getElementsByTagName(getCurrentActiveModel(), tagName);
78 | };
79 | }
80 |
81 | if (!viewBase.ViewBase.prototype.getElementsByTagName) {
82 | /**
83 | * Finds all elements by a Tag name
84 | * @param tagName
85 | * @returns {Array}
86 | */
87 | viewBase.ViewBase.prototype.getElementsByTagName = function (tagName) {
88 | return getElementsByTagName(this, tagName);
89 | };
90 | }
91 |
92 | if (!viewBase.ViewBase.prototype.classList) {
93 | var classList = function (t) {
94 | var curClassList = "";
95 |
96 | this._resync = function () {
97 | if (curClassList === t.className) {
98 | return;
99 | }
100 |
101 | // We need to zero our length; so that we can re-add anything that exists in the parent class
102 | this.length = 0;
103 | var self = this;
104 | t.cssClasses.forEach(function (item) {
105 | self.push(item);
106 | });
107 | };
108 |
109 | this._update = function () {
110 | curClassList = this.join(" ");
111 | t.className = curClassList;
112 | };
113 |
114 | this._resync();
115 | };
116 | classList.prototype = [];
117 | classList.prototype.toString = function () {
118 | this._resync();
119 | return this.join(" ");
120 | };
121 | classList.prototype.item = function (i) {
122 | this._resync();
123 | return this[i] || null;
124 | };
125 | classList.prototype.add = function () {
126 | this._resync();
127 | var updated = false;
128 | for (var i = 0, len = arguments.length; i < len; i++) {
129 | if (!this.contains(arguments[i])) {
130 | this.push(arguments[i]);
131 | updated = true;
132 | }
133 | }
134 | if (updated) {
135 | this._update();
136 | }
137 | return this;
138 | };
139 | classList.prototype.insert = function () {
140 | this._resync();
141 | var updated = false;
142 | for (var i = 0, len = arguments.length; i < len; i++) {
143 | if (!this.contains(arguments[i])) {
144 | this.unshift(arguments[i]);
145 | updated = true;
146 | }
147 | }
148 | if (updated) {
149 | this._update();
150 | }
151 | return this;
152 | };
153 |
154 | classList.prototype.remove = function () {
155 | this._resync();
156 | var updated = false;
157 | for (var i = 0, len = arguments.length; i < len; i++) {
158 | var idx = this.indexOf(arguments[i]);
159 | if (idx >= 0) {
160 | this.splice(idx, 1);
161 | updated = true;
162 | }
163 | }
164 | if (updated) {
165 | this._update();
166 | }
167 | return this;
168 | };
169 | classList.prototype.toggle = function (val, force) {
170 | this._resync();
171 | if (this.contains(val)) {
172 | if (force === true) {
173 | return this;
174 | }
175 | return this.remove(val);
176 | } else {
177 | if (force === false) {
178 | return this;
179 | }
180 | return this.add(val);
181 | }
182 | };
183 | classList.prototype.contains = function (c) {
184 | return this.indexOf(c) >= 0;
185 | };
186 | var getClassList = function (val) {
187 | var cl = new classList(val);
188 | Object.defineProperty(val, "classList", {
189 | value: cl,
190 | configurable: true,
191 | enumerable: true,
192 | });
193 | return cl;
194 | };
195 | Object.defineProperty(viewBase.ViewBase.prototype, "classList", {
196 | configurable: true,
197 | enumerable: true,
198 | get: function () {
199 | return getClassList(this);
200 | },
201 | });
202 | }
203 |
204 | global.runAgainstClasses = function (clsName, func) {
205 | runAgainstClasses(getCurrentActiveModel(), clsName, func);
206 | };
207 | viewBase.ViewBase.prototype.runAgainstClasses = function (clsName, func) {
208 | runAgainstClasses(this, clsName, func);
209 | };
210 |
211 | global.runAgainstTagNames = function (tagName, func) {
212 | runAgainstTagNames(getCurrentActiveModel(), tagName, func);
213 | };
214 | viewBase.ViewBase.prototype.runAgainstTagNames = function (tagName, func) {
215 | runAgainstTagNames(this, tagName, func);
216 | };
217 |
218 | global.runAgainstId = function (id, func) {
219 | runAgainstId(getCurrentActiveModel(), id, func);
220 | };
221 | viewBase.ViewBase.prototype.runAgainstId = function (id, func) {
222 | runAgainstId(this, id, func);
223 | };
224 |
225 | /*** Support routines, not publicly accessible ***/
226 | function getElementById(v, id) {
227 | if (!v) {
228 | return undefined;
229 | }
230 | if (v.id === id) {
231 | return view;
232 | }
233 | var retVal = undefined;
234 | var viewCallBack = function (child) {
235 | if (child.id === id) {
236 | retVal = child;
237 | return false;
238 | }
239 |
240 | // Android patch for ListView
241 | if (
242 | child._realizedItems &&
243 | child._realizedItems.size !== child._childrenCount
244 | ) {
245 | for (var key in child._realizedItems) {
246 | if (child._realizedItems.hasOwnProperty(key)) {
247 | // We return false, when we have a hit; so if we have a hit we can stop searching
248 | if (!viewCallBack(child._realizedItems[key])) {
249 | return false;
250 | }
251 | }
252 | }
253 | }
254 |
255 | return true;
256 | };
257 |
258 | viewBase.eachDescendant(v, viewCallBack);
259 |
260 | if (typeof retVal === "undefined") {
261 | // Android patch for ListView
262 | if (v._realizedItems && v._realizedItems.size !== v._childrenCount) {
263 | for (var key in v._realizedItems) {
264 | if (v._realizedItems.hasOwnProperty(key)) {
265 | // viewCallback will return false, if we found a match
266 | if (!viewCallBack(v._realizedItems[key])) {
267 | return retVal;
268 | }
269 | }
270 | }
271 | }
272 | }
273 |
274 | return retVal;
275 | }
276 |
277 | function getElementsByClassName(v, clsName) {
278 | var retVal = [];
279 | if (!v) {
280 | return retVal;
281 | }
282 |
283 | if (v.classList.contains(clsName)) {
284 | retVal.push(v);
285 | }
286 |
287 | var classNameCallback = function (child) {
288 | if (child.classList.contains(clsName)) {
289 | retVal.push(child);
290 | }
291 |
292 | // Android patch for ListView
293 | if (
294 | child._realizedItems &&
295 | child._realizedItems.size !== child._childrenCount
296 | ) {
297 | for (var key in child._realizedItems) {
298 | if (child._realizedItems.hasOwnProperty(key)) {
299 | classNameCallback(child._realizedItems[key]);
300 | }
301 | }
302 | }
303 |
304 | return true;
305 | };
306 |
307 | viewBase.eachDescendant(v, classNameCallback);
308 |
309 | // Android patch for ListView
310 | if (v._realizedItems && v._realizedItems.size !== v._childrenCount) {
311 | for (var key in v._realizedItems) {
312 | if (v._realizedItems.hasOwnProperty(key)) {
313 | classNameCallback(v._realizedItems[key]);
314 | }
315 | }
316 | }
317 |
318 | return retVal;
319 | }
320 |
321 | function getElementsByTagName(v, tagName) {
322 | // TagName is case-Insensitive
323 | var tagNameLC = tagName.toLowerCase();
324 |
325 | var retVal = [],
326 | allTags = false;
327 | if (!v) {
328 | return retVal;
329 | }
330 |
331 | if (tagName === "*") {
332 | allTags = true;
333 | }
334 |
335 | if ((v.typeName && v.typeName.toLowerCase() === tagNameLC) || allTags) {
336 | retVal.push(v);
337 | }
338 |
339 | var tagNameCallback = function (child) {
340 | if (
341 | (child.typeName && child.typeName.toLowerCase() === tagNameLC) ||
342 | allTags
343 | ) {
344 | retVal.push(child);
345 | }
346 |
347 | // Android patch for ListView
348 | if (
349 | child._realizedItems &&
350 | child._realizedItems.size !== child._childrenCount
351 | ) {
352 | for (var key in child._realizedItems) {
353 | if (child._realizedItems.hasOwnProperty(key)) {
354 | tagNameCallback(child._realizedItems[key]);
355 | }
356 | }
357 | }
358 |
359 | return true;
360 | };
361 |
362 | viewBase.eachDescendant(v, tagNameCallback);
363 |
364 | // Android patch for ListView
365 | if (v._realizedItems && v._realizedItems.size !== v._childrenCount) {
366 | for (var key in v._realizedItems) {
367 | if (v._realizedItems.hasOwnProperty(key)) {
368 | tagNameCallback(v._realizedItems[key]);
369 | }
370 | }
371 | }
372 |
373 | return retVal;
374 | }
375 |
376 | var getCurrentActiveModel = function () {
377 | var topFrame = frame.topmost();
378 | var model = topFrame.currentPage && topFrame.currentPage.model;
379 | if (model) {
380 | return model;
381 | }
382 | return topFrame;
383 | };
384 |
385 | function runAgainstClasses(v, clsName, func) {
386 | var elements = getElementsByClassName(v, clsName);
387 | for (var i = 0; i < elements.length; i++) {
388 | func(elements[i]);
389 | }
390 | }
391 |
392 | function runAgainstTagNames(v, tagName, func) {
393 | var elements = getElementsByTagName(v, tagName);
394 | for (var i = 0; i < elements.length; i++) {
395 | func(elements[i]);
396 | }
397 | }
398 |
399 | function runAgainstId(v, id, func) {
400 | var element = getElementById(v, id);
401 | if (element) {
402 | func(element);
403 | }
404 | }
405 |
--------------------------------------------------------------------------------
/src/index.d.ts:
--------------------------------------------------------------------------------
1 | import { ViewBase } from "ui/core/view-base";
2 |
3 |
4 | /**
5 | * Get the child element with the id. ** NativeScript DOM plugin only **
6 | * @param {string} id - The id of the element to get.
7 | * @returns {ViewBase} - The view element with the specified id.
8 | */
9 | export function getElementById(id: string): ViewBase;
10 |
11 |
12 | /**
13 | * Gets all child elements of the parent view with the specified className. ** NativeScript DOM plugin only **
14 | * @param {string} className - The class name to get children elements with.
15 | * @returns {Array} - An array of view elements with the specified class name.
16 | */
17 | export function getElementsByClassName(className: string): Array;
18 |
19 |
20 | /**
21 | * Gets all child elements with specified tag name in the parent view. ** NativeScript DOM plugin only **
22 | * @param {string} tagName - The tag name to get children elements with.
23 | * @returns {Array} - An array of view elements with the specified tag name.
24 | */
25 | export function getElementsByTagName(tagName: string): Array;
26 |
27 |
28 | /**
29 | * Execute a function on any view with the id. ** NativeScript DOM plugin only **
30 | * @param {string} id - The view id.
31 | * @param {Function} callback - The function to run
32 | */
33 | export function runAgainstId(id: string, callback: (element: ViewBase) => void);
34 |
35 |
36 | /**
37 | * Executes a function on all view components with a matching className. ** NativeScript DOM plugin only **
38 | * @param {string} className - The tag name to get children elements with.
39 | * @param {Function} callback - The function to run
40 | */
41 | export function runAgainstClasses(className: string, callback: (element: ViewBase) => void);
42 |
43 |
44 | /**
45 | * Executes a function on all view components with a matching tagName. ** NativeScript DOM plugin only **
46 | * @param {string} tagName - The tag name to get children elements with.
47 | * @param {Function} callback - The function to run
48 | */
49 | export function runAgainstTagNames(tagName: string, callback: (element: ViewBase) => void);
50 |
51 |
52 | declare module "ui/core/view-base" {
53 | interface ViewBase {
54 |
55 | /**
56 | * Get the child element with the id. ** NativeScript DOM plugin only **
57 | * @param {string} id - The id of the element to get.
58 | * @returns {ViewBase} - The view element with the specified id.
59 | */
60 | getElementById(id: string): ViewBase;
61 |
62 | /**
63 | * Gets all child elements of the parent view with the specified className. ** NativeScript DOM plugin only **
64 | * @param {string} className - The class name to get children elements with.
65 | * @returns {Array} - An array of view elements with the specified class name.
66 | */
67 | getElementsByClassName(className: string): Array;
68 |
69 | /**
70 | * Gets all child elements with specified tag name in the parent view. ** NativeScript DOM plugin only **
71 | * @param {string} tagName - The tag name to get children elements with.
72 | * @returns {Array} - An array of view elements with the specified tag name.
73 | */
74 | getElementsByTagName(tagName: string): Array;
75 |
76 | /**
77 | * Execute a function on any child view with the id. ** NativeScript DOM plugin only **
78 | * @param {string} id - The view id.
79 | */
80 | runAgainstId(id: string, callback: (element: ViewBase) => void);
81 |
82 | /**
83 | * Executes a function on the child view components with the className. ** NativeScript DOM plugin only **
84 | * @param {string} className - The tag name to get children elements with.
85 | */
86 | runAgainstClasses(className: string, callback: (element: ViewBase) => void);
87 |
88 | /**
89 | * Executes a function on the child view components with the tagName. ** NativeScript DOM plugin only **
90 | * @param {string} tagName - The tag name to get children elements with.
91 | */
92 | runAgainstTagNames(tagName: string, callback: (element: ViewBase) => void);
93 |
94 | /**
95 | * Property that contains the CSS classes for a view component.
96 | */
97 | classList: classList;
98 |
99 | }
100 |
101 |
102 | }
103 |
104 | interface classList {
105 |
106 | /**
107 | * Add a class to the view's class list at the end.
108 | * @param {string} className - The class to add.
109 | */
110 | add(...className: string[]);
111 |
112 | /**
113 | * Add a class to the view's class list at the front.
114 | * @param {string} className - The class to add.
115 | */
116 | insert(...className: string[]);
117 |
118 | /**
119 | * Removes a class from the view's class list
120 | * @param {string} className - The class to remove.
121 | */
122 | remove(...className: string[]);
123 |
124 | /**
125 | * Toggles a class name if force = true, will force adding the class name only. (And won't remove it, but you won't have a second) if force = false, will force removing the class name only. (And won't add it)
126 | * @param {string} className - The class to toggle.
127 | * @param {boolean} force - Force this class on (true) or off (false) the class list
128 | */
129 | toggle(className: string, force?: boolean);
130 |
131 | /**
132 | * Get the class at the specified location in the classList.
133 | * @param {number} index - The class item in the classList.
134 | * @returns - The class at the index of the classList.
135 | */
136 | item(index: number);
137 |
138 | /**
139 | * Check if a view has a class name.
140 | * @param {string} className - The className to check in the classList.
141 | * @returns - True if the class name exists in the class list.
142 | */
143 | contains(className: string);
144 | }
145 |
--------------------------------------------------------------------------------
/src/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nativescript-dom",
3 | "version": "2.0.5",
4 | "description": "A NativeScript module for DOM Emulation",
5 | "main": "dom",
6 | "typings": "index.d.ts",
7 | "nativescript": {
8 | "platforms": {
9 | "android": "3.0.0",
10 | "ios": "3.0.0"
11 | },
12 | "plugin": {
13 | "nan": "false",
14 | "pan": "true",
15 | "core3": "true",
16 | "category": "Processing"
17 | }
18 | },
19 | "repository": {
20 | "type": "git",
21 | "url": "https://git.proplugins.org/proplugins/nativescript-dom.git"
22 | },
23 | "keywords": [
24 | "NativeScript",
25 | "dom",
26 | "development",
27 | "classList",
28 | "getElementById",
29 | "getElementsByTagName",
30 | "getElementsByClassName"
31 | ],
32 | "author": {
33 | "name": "Nathanael Anderson",
34 | "email": "nathan@master-technology.com"
35 | },
36 | "contributors": [
37 | {
38 | "name": "Brad Martin",
39 | "email": "bradwaynemartin@gmail.com",
40 | "url": "https://github.com/bradmartin"
41 | },
42 | {
43 | "name": "Ludwik Trammer",
44 | "email": "ludwik@gmail.com",
45 | "url": "https://github.com/ludwiktrammer"
46 | }
47 | ],
48 | "license": "Unsupported",
49 | "bugs": {
50 | "url": "https://git.proplugins.org/proplugins/nativescript-dom/issues"
51 | },
52 | "homepage": "https://git.proplugins.org/proplugins/nativescript-dom",
53 | "readmeFilename": "README.md",
54 | "scripts": {
55 | "postinstall": "node postinstall.js || echo \"ignore\""
56 | }
57 | }
--------------------------------------------------------------------------------
/src/postinstall.js:
--------------------------------------------------------------------------------
1 |
2 | // Get the defaults
3 | const PROPLUGINS = isenv(process.env.PROPLUGINS);
4 | const plugin_name = process.env.npm_package_name || 'Unknown';
5 | const CI = isenv(process.env.CI);
6 | const COLOR = CI ? false : isenv(process.env.npm_config_color);
7 |
8 | function isenv(val) {
9 | return !!val && val !== '0' && val !== 'false';
10 | }
11 |
12 | function log(value) {
13 | console.log(COLOR ? value : value.replace(/\u001B\[[\d|1;\d]+m/g, ''));
14 | }
15 |
16 | function padr(value, size) {
17 | while(value.length < size) {
18 | value += ' ';
19 | }
20 | return value;
21 | }
22 |
23 | function padc(value, size) {
24 | while(value.length < size) {
25 | value = ' ' + value + ' ';
26 | }
27 | return value.substr(0, size);
28 | }
29 |
30 |
31 | function highlight(value, color) {
32 | if (color == null) { color = "33"; }
33 | return "\u001B["+color+"m"+value+"\u001B[37m";
34 | }
35 |
36 | if (!PROPLUGINS) {
37 | if (COLOR) { console.log('\x07'); }
38 | log('\n\u001B[37m\u001B[1;41m--------------------------------[ \u001B[5m\u001B[33mWARNING\u001B[0m\u001B[1;41m\u001B[37m ]------------------------------------\u001B[0m');
39 | log('\u001B[37m\u001B[1;41m'+padr('- '+highlight(plugin_name)+' is DEPRECATED and is not maintained!', 88)+'-\u001B[0m');
40 | log('\u001B[37m\u001B[1;41m'+padr('- This plugin has NOT been tested in NS 6.x, and is likely to crash or fail!', 78)+'-\u001B[0m');
41 | log('\u001B[37m\u001B[1;41m'+padr('- ', 78)+'-\u001B[0m');
42 | log('\u001B[37m\u001B[1;41m'+padr('- Please switch to the supported, tested, and maintained version:', 78)+'-\u001B[0m');
43 | log('\u001B[37m\u001B[1;41m-'+padc(highlight('@proplugins/'+plugin_name), 87)+'-\u001B[0m');
44 | log('\u001B[37m\u001B[1;41m'+padr('- ', 78)+'-\u001B[0m');
45 | log('\u001B[37m\u001B[1;41m'+padr('- For more information see '+highlight('https://proplugins.org/upgrade'), 88)+'-\u001B[0m');
46 | log('\u001B[37m\u001B[1;41m-------------------------------------------------------------------------------\u001B[0m\n');
47 |
48 | if (!COLOR) {
49 | // console.log("\u001B[0m");
50 | }
51 |
52 | delay();
53 | }
54 |
55 | async function delay() {
56 | await new Promise( (resolve) => { setTimeout(resolve, 5000); } );
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/src/unmaintained.svg:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | This plugin is no longer being maintained by the original author here! It has moved to a new home.
6 |
7 |
8 |
--------------------------------------------------------------------------------