@angular-wave/angular.ts 0.0.46 → 0.0.47

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.
@@ -55,7 +55,6 @@ import { CACHE, EXPANDO } from "../../core/cache/cache";
55
55
  * - [`removeData()`](http://api.jquery.com/removeData/)
56
56
  * - [`replaceWith()`](http://api.jquery.com/replaceWith/)
57
57
  * - [`text()`](http://api.jquery.com/text/)
58
- * - [`triggerHandler()`](http://api.jquery.com/triggerHandler/) - Passes a dummy event object to handlers
59
58
  * - [`val()`](http://api.jquery.com/val/)
60
59
  *
61
60
  * ## jQuery/jqLite Extras
@@ -136,7 +135,7 @@ const BOOLEAN_ELEMENTS = {};
136
135
  * JQLite both a function and an array-like data structure for manipulation of DOM, linking elements to expando cache,
137
136
  * and execution of chain functions.
138
137
  *
139
- * @param {string|Element|Document|Window|JQLite|ArrayLike<Element>|(() => void)} element
138
+ * @param {string|Element|Comment|Document|Window|JQLite|ArrayLike<Element>|(() => void)} element
140
139
  * @returns {JQLite}
141
140
  */
142
141
  export function JQLite(element) {
@@ -538,162 +537,242 @@ JQLite.prototype.data = function (key, value) {
538
537
  return this;
539
538
  };
540
539
 
541
- /// ///////////////////////////////////////
542
- // Functions iterating traversal.
543
- // These functions chain results into a single
544
- // selector.
545
- /// ///////////////////////////////////////
546
- forEach(
547
- {
548
- replaceWith(element, replaceNode) {
549
- let index;
550
- const parent = element.parentNode;
551
- dealoc(element);
552
- forEach(new JQLite(replaceNode), (node) => {
553
- if (index) {
554
- parent.insertBefore(node, index.nextSibling);
555
- } else {
556
- parent.replaceChild(node, element);
557
- }
558
- index = node;
559
- });
560
- },
561
- children(element) {
562
- return Array.from(element.childNodes).filter(
563
- (child) => child.nodeType === Node.ELEMENT_NODE,
564
- );
565
- },
566
- append(element, node) {
567
- const { nodeType } = element;
568
- if (
569
- nodeType !== Node.ELEMENT_NODE &&
570
- nodeType !== Node.DOCUMENT_FRAGMENT_NODE
571
- )
572
- return;
540
+ JQLite.prototype.replaceWith = function (arg1) {
541
+ let value;
542
+ let fn = function (element, replaceNode) {
543
+ let index;
544
+ const parent = element.parentNode;
545
+ dealoc(element);
546
+ forEach(new JQLite(replaceNode), (node) => {
547
+ if (index) {
548
+ parent.insertBefore(node, index.nextSibling);
549
+ } else {
550
+ parent.replaceChild(node, element);
551
+ }
552
+ index = node;
553
+ });
554
+ };
555
+ for (let i = 0; i < this.length; i++) {
556
+ if (isUndefined(value)) {
557
+ value = fn(this[i], arg1);
558
+ if (isDefined(value)) {
559
+ // any function which returns a value needs to be wrapped
560
+ value = JQLite(value);
561
+ }
562
+ } else {
563
+ addNodes(value, fn(this[i], arg1));
564
+ }
565
+ }
566
+ return isDefined(value) ? value : this;
567
+ };
573
568
 
574
- node = new JQLite(node);
569
+ JQLite.prototype.children = function () {
570
+ let value;
571
+ let fn = (element) =>
572
+ Array.from(element.childNodes).filter(
573
+ (child) => child.nodeType === Node.ELEMENT_NODE,
574
+ );
575
+ for (let i = 0; i < this.length; i++) {
576
+ value = JQLite(fn(this[i]));
577
+ }
578
+ return isDefined(value) ? value : this;
579
+ };
575
580
 
576
- for (let i = 0, ii = node.length; i < ii; i++) {
577
- const child = node[i];
578
- element.appendChild(child);
579
- }
580
- },
581
+ /**
582
+ * @param {string} node
583
+ * @returns {JQLite}
584
+ */
585
+ JQLite.prototype.append = function (node) {
586
+ for (let i = 0; i < this.length; i++) {
587
+ const element = this[i];
588
+ const { nodeType } = element;
589
+ if (
590
+ nodeType !== Node.ELEMENT_NODE &&
591
+ nodeType !== Node.DOCUMENT_FRAGMENT_NODE
592
+ )
593
+ return this;
581
594
 
582
- prepend(element, node) {
583
- if (element.nodeType === Node.ELEMENT_NODE) {
584
- const index = element.firstChild;
585
- forEach(new JQLite(node), (child) => {
586
- element.insertBefore(child, index);
587
- });
588
- }
589
- },
595
+ let newNode = new JQLite(node);
590
596
 
591
- remove: removeElement,
597
+ for (let i = 0; i < newNode.length; i++) {
598
+ const child = newNode[i];
599
+ element.appendChild(child);
600
+ }
601
+ }
602
+ return this;
603
+ };
592
604
 
593
- detach(element) {
594
- removeElement(element, true);
595
- },
605
+ /**
606
+ * @param {string} node
607
+ * @returns {JQLite}
608
+ */
609
+ JQLite.prototype.prepend = function (node) {
610
+ for (let i = 0; i < this.length; i++) {
611
+ const element = this[i];
612
+ if (element.nodeType === Node.ELEMENT_NODE) {
613
+ const index = element.firstChild;
614
+ forEach(new JQLite(node), (child) => {
615
+ element.insertBefore(child, index);
616
+ });
617
+ }
618
+ }
619
+ return this;
620
+ };
596
621
 
597
- after(element, newElement) {
598
- let index = element;
599
- const parent = element.parentNode;
622
+ /**
623
+ * @param {string} newElement
624
+ * @returns {JQLite}
625
+ */
626
+ JQLite.prototype.after = function (newElement) {
627
+ for (let i = 0; i < this.length; i++) {
628
+ const element = this[i];
629
+ let index = element;
630
+ const parent = element.parentNode;
600
631
 
601
- if (parent) {
602
- newElement = new JQLite(newElement);
632
+ if (parent) {
633
+ let el = new JQLite(newElement);
603
634
 
604
- for (let i = 0, ii = newElement.length; i < ii; i++) {
605
- const node = newElement[i];
606
- parent.insertBefore(node, index.nextSibling);
607
- index = node;
608
- }
635
+ for (let i = 0, ii = el.length; i < ii; i++) {
636
+ const node = el[i];
637
+ parent.insertBefore(node, index.nextSibling);
638
+ index = node;
639
+ }
640
+ }
641
+ }
642
+ return this;
643
+ };
644
+
645
+ /**
646
+ * @param {boolean} [keepData]
647
+ * @returns
648
+ */
649
+ JQLite.prototype.remove = function (keepData = false) {
650
+ for (let i = 0; i < this.length; i++) {
651
+ const element = this[i];
652
+ removeElement(element, keepData);
653
+ }
654
+ return this;
655
+ };
656
+
657
+ JQLite.prototype.detach = function () {
658
+ for (let i = 0; i < this.length; i++) {
659
+ const element = this[i];
660
+ removeElement(element, true);
661
+ }
662
+ return this;
663
+ };
664
+
665
+ JQLite.prototype.parent = function () {
666
+ let value;
667
+ let fn = (element) => {
668
+ const parent = element.parentNode;
669
+ return parent && parent.nodeType !== Node.DOCUMENT_FRAGMENT_NODE
670
+ ? parent
671
+ : null;
672
+ };
673
+ for (let i = 0, ii = this.length; i < ii; i++) {
674
+ if (isUndefined(value)) {
675
+ value = fn(this[i]);
676
+ if (isDefined(value)) {
677
+ value = JQLite(value);
609
678
  }
610
- },
679
+ } else {
680
+ addNodes(value, fn(this[i]));
681
+ }
682
+ }
683
+ return isDefined(value) ? value : this;
684
+ };
611
685
 
612
- parent(element) {
613
- const parent = element.parentNode;
614
- return parent && parent.nodeType !== Node.DOCUMENT_FRAGMENT_NODE
615
- ? parent
616
- : null;
617
- },
686
+ JQLite.prototype.find = function (selector) {
687
+ let value;
688
+ for (let i = 0, ii = this.length; i < ii; i++) {
689
+ const element = this[i];
618
690
 
619
- // TODO: remove after migrating tests away from JQLite
620
- find(element, selector) {
691
+ if (isUndefined(value)) {
621
692
  if (element.getElementsByTagName) {
622
- return element.getElementsByTagName(selector);
693
+ value = element.getElementsByTagName(selector);
694
+ } else {
695
+ value = [];
623
696
  }
624
- return [];
625
- },
626
-
627
- triggerHandler(element, event, extraParameters) {
628
- let dummyEvent;
629
- let eventFnsCopy;
630
- let handlerArgs;
631
- const eventName = event.type || event;
632
- const expandoStore = getExpando(element);
633
- const events = expandoStore && expandoStore.events;
634
- const eventFns = events && events[eventName];
635
-
636
- if (eventFns) {
637
- // Create a dummy event to pass to the handlers
638
- dummyEvent = {
639
- preventDefault() {
640
- this.defaultPrevented = true;
641
- },
642
- isDefaultPrevented() {
643
- return this.defaultPrevented === true;
644
- },
645
- stopImmediatePropagation() {
646
- this.immediatePropagationStopped = true;
647
- },
648
- isImmediatePropagationStopped() {
649
- return this.immediatePropagationStopped === true;
650
- },
651
- stopPropagation: () => {},
652
- type: eventName,
653
- target: element,
654
- };
655
-
656
- // If a custom event was provided then extend our dummy event with it
657
- if (event.type) {
658
- dummyEvent = extend(dummyEvent, event);
659
- }
697
+ if (isDefined(value)) {
698
+ // any function which returns a value needs to be wrapped
699
+ value = JQLite(value);
700
+ }
701
+ } else {
702
+ if (element.getElementsByTagName) {
703
+ addNodes(value, element.getElementsByTagName(selector));
704
+ }
705
+ }
706
+ }
707
+ return isDefined(value) ? value : this;
708
+ };
660
709
 
661
- // Copy event handlers in case event handlers array is modified during execution.
662
- eventFnsCopy = shallowCopy(eventFns);
663
- handlerArgs = extraParameters
664
- ? [dummyEvent].concat(extraParameters)
665
- : [dummyEvent];
710
+ /**
711
+ * TODO: REMOVE! This function being used ONLY in tests!
712
+ */
713
+ JQLite.prototype.triggerHandler = function (event, extraParameters) {
714
+ let value;
715
+ let fn = function (element, event, extraParameters) {
716
+ let dummyEvent;
717
+ let eventFnsCopy;
718
+ let handlerArgs;
719
+ const eventName = event.type || event;
720
+ const expandoStore = getExpando(element);
721
+ const events = expandoStore && expandoStore.events;
722
+ const eventFns = events && events[eventName];
723
+
724
+ if (eventFns) {
725
+ // Create a dummy event to pass to the handlers
726
+ dummyEvent = {
727
+ preventDefault() {
728
+ this.defaultPrevented = true;
729
+ },
730
+ isDefaultPrevented() {
731
+ return this.defaultPrevented === true;
732
+ },
733
+ stopImmediatePropagation() {
734
+ this.immediatePropagationStopped = true;
735
+ },
736
+ isImmediatePropagationStopped() {
737
+ return this.immediatePropagationStopped === true;
738
+ },
739
+ stopPropagation: () => {},
740
+ type: eventName,
741
+ target: element,
742
+ };
666
743
 
667
- forEach(eventFnsCopy, (fn) => {
668
- if (!dummyEvent.isImmediatePropagationStopped()) {
669
- fn.apply(element, handlerArgs);
670
- }
671
- });
744
+ // If a custom event was provided then extend our dummy event with it
745
+ if (event.type) {
746
+ dummyEvent = extend(dummyEvent, event);
672
747
  }
673
- },
674
- },
675
- (fn, name) => {
676
- /**
677
- * chaining functions
678
- */
679
- JQLite.prototype[name] = function (arg1, arg2, arg3) {
680
- let value;
681
-
682
- for (let i = 0, ii = this.length; i < ii; i++) {
683
- if (isUndefined(value)) {
684
- value = fn(this[i], arg1, arg2, arg3);
685
- if (isDefined(value)) {
686
- // any function which returns a value needs to be wrapped
687
- value = JQLite(value);
688
- }
689
- } else {
690
- addNodes(value, fn(this[i], arg1, arg2, arg3));
748
+
749
+ // Copy event handlers in case event handlers array is modified during execution.
750
+ eventFnsCopy = shallowCopy(eventFns);
751
+ handlerArgs = extraParameters
752
+ ? [dummyEvent].concat(extraParameters)
753
+ : [dummyEvent];
754
+
755
+ forEach(eventFnsCopy, (fn) => {
756
+ if (!dummyEvent.isImmediatePropagationStopped()) {
757
+ fn.apply(element, handlerArgs);
691
758
  }
759
+ });
760
+ }
761
+ };
762
+ for (let i = 0, ii = this.length; i < ii; i++) {
763
+ if (isUndefined(value)) {
764
+ value = fn(this[i], event, extraParameters);
765
+ if (isDefined(value)) {
766
+ // @ts-ignore
767
+ value = JQLite(value);
692
768
  }
693
- return isDefined(value) ? value : this;
694
- };
695
- },
696
- );
769
+ } else {
770
+ // @ts-ignore
771
+ addNodes(value, fn(this[i], event, extraParameters));
772
+ }
773
+ }
774
+ return isDefined(value) ? value : this;
775
+ };
697
776
 
698
777
  ///////////////////////////////////////////////////////////////////
699
778
  //////////// HELPER FUNCTIONS /////////////////////////
@@ -1,176 +1,2 @@
1
- /**
2
- * @ngdoc directive
3
- * @name ngHref
4
- * @restrict A
5
- * @priority 99
6
- *
7
- * @description
8
- * Using AngularJS markup like `{{hash}}` in an href attribute will
9
- * make the link go to the wrong URL if the user clicks it before
10
- * AngularJS has a chance to replace the `{{hash}}` markup with its
11
- * value. Until AngularJS replaces the markup the link will be broken
12
- * and will most likely return a 404 error. The `ngHref` directive
13
- * solves this problem.
14
- *
15
- * The wrong way to write it:
16
- * ```html
17
- * <a href="http://www.gravatar.com/avatar/{{hash}}">link1</a>
18
- * ```
19
- *
20
- * The correct way to write it:
21
- * ```html
22
- * <a ng-href="http://www.gravatar.com/avatar/{{hash}}">link1</a>
23
- * ```
24
- *
25
- * @element A
26
- * @param {template} ngHref any string which can contain `{{}}` markup.
27
- *
28
- */
29
1
  export const REGEX_STRING_REGEXP: RegExp;
30
- /**
31
- * @ngdoc directive
32
- * @name ngSrc
33
- * @restrict A
34
- * @priority 99
35
- *
36
- * @description
37
- * Using AngularJS markup like `{{hash}}` in a `src` attribute doesn't
38
- * work right: The browser will fetch from the URL with the literal
39
- * text `{{hash}}` until AngularJS replaces the expression inside
40
- * `{{hash}}`. The `ngSrc` directive solves this problem.
41
- *
42
- * The buggy way to write it:
43
- * ```html
44
- * <img src="http://www.gravatar.com/avatar/{{hash}}" alt="Description"/>
45
- * ```
46
- *
47
- * The correct way to write it:
48
- * ```html
49
- * <img ng-src="http://www.gravatar.com/avatar/{{hash}}" alt="Description" />
50
- * ```
51
- *
52
- * @element IMG
53
- * @param {template} ngSrc any string which can contain `{{}}` markup.
54
- */
55
- /**
56
- * @ngdoc directive
57
- * @name ngSrcset
58
- * @restrict A
59
- * @priority 99
60
- *
61
- * @description
62
- * Using AngularJS markup like `{{hash}}` in a `srcset` attribute doesn't
63
- * work right: The browser will fetch from the URL with the literal
64
- * text `{{hash}}` until AngularJS replaces the expression inside
65
- * `{{hash}}`. The `ngSrcset` directive solves this problem.
66
- *
67
- * The buggy way to write it:
68
- * ```html
69
- * <img srcset="http://www.gravatar.com/avatar/{{hash}} 2x" alt="Description"/>
70
- * ```
71
- *
72
- * The correct way to write it:
73
- * ```html
74
- * <img ng-srcset="http://www.gravatar.com/avatar/{{hash}} 2x" alt="Description" />
75
- * ```
76
- *
77
- * @element IMG
78
- * @param {template} ngSrcset any string which can contain `{{}}` markup.
79
- */
80
- /**
81
- * @ngdoc directive
82
- * @name ngDisabled
83
- * @restrict A
84
- * @priority 100
85
- *
86
- * @description
87
- *
88
- * This directive sets the `disabled` attribute on the element (typically a form control,
89
- * e.g. `input`, `button`, `select` etc.) if the
90
- * {@link guide/expression expression} inside `ngDisabled` evaluates to truthy.
91
- *
92
- * A special directive is necessary because we cannot use interpolation inside the `disabled`
93
- * attribute. See the {@link guide/interpolation interpolation guide} for more info.
94
- *
95
- * @param {string} ngDisabled If the {@link guide/expression expression} is truthy,
96
- * then the `disabled` attribute will be set on the element
97
- */
98
- /**
99
- * @ngdoc directive
100
- * @name ngChecked
101
- * @restrict A
102
- * @priority 100
103
- *
104
- * @description
105
- * Sets the `checked` attribute on the element, if the expression inside `ngChecked` is truthy.
106
- *
107
- * Note that this directive should not be used together with {@link ngModel `ngModel`},
108
- * as this can lead to unexpected behavior.
109
- *
110
- * A special directive is necessary because we cannot use interpolation inside the `checked`
111
- * attribute. See the {@link guide/interpolation interpolation guide} for more info.
112
- *
113
- * @element INPUT
114
- * @param {string} ngChecked If the {@link guide/expression expression} is truthy,
115
- * then the `checked` attribute will be set on the element
116
- */
117
- /**
118
- *
119
- * @description
120
- *
121
- * Sets the `readonly` attribute on the element, if the expression inside `ngReadonly` is truthy.
122
- * Note that `readonly` applies only to `input` elements with specific types. [See the input docs on
123
- * MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-readonly) for more information.
124
- *
125
- * A special directive is necessary because we cannot use interpolation inside the `readonly`
126
- * attribute. See the {@link guide/interpolation interpolation guide} for more info.
127
- * @element INPUT
128
- * @param {string} ngReadonly If the {@link guide/expression expression} is truthy,
129
- * then special attribute "readonly" will be set on the element
130
- */
131
- /**
132
- * @ngdoc directive
133
- * @name ngSelected
134
- * @restrict A
135
- * @priority 100
136
- *
137
- * @description
138
- *
139
- * Sets the `selected` attribute on the element, if the expression inside `ngSelected` is truthy.
140
- *
141
- * A special directive is necessary because we cannot use interpolation inside the `selected`
142
- * attribute. See the {@link guide/interpolation interpolation guide} for more info.
143
- *
144
- * <div class="alert alert-warning">
145
- * **Note:** `ngSelected` does not interact with the `select` and `ngModel` directives, it only
146
- * sets the `selected` attribute on the element. If you are using `ngModel` on the select, you
147
- * should not use `ngSelected` on the options, as `ngModel` will set the select value and
148
- * selected options.
149
- * </div>
150
- * @element OPTION
151
- * @param {string} ngSelected If the {@link guide/expression expression} is truthy,
152
- * then special attribute "selected" will be set on the element
153
- */
154
- /**
155
- * @ngdoc directive
156
- * @name ngOpen
157
- * @restrict A
158
- * @priority 100
159
- *
160
- * @description
161
- *
162
- * Sets the `open` attribute on the element, if the expression inside `ngOpen` is truthy.
163
- *
164
- * A special directive is necessary because we cannot use interpolation inside the `open`
165
- * attribute. See the {@link guide/interpolation interpolation guide} for more info.
166
- *
167
- * ## A note about browser compatibility
168
- *
169
- * Internet Explorer and Edge do not support the `details` element, it is
170
- * recommended to use {@link ng.ngShow} and {@link ng.ngHide} instead.
171
- *
172
- * @element DETAILS
173
- * @param {string} ngOpen If the {@link guide/expression expression} is truthy,
174
- * then special attribute "open" will be set on the element
175
- */
176
2
  export const ngAttributeAliasDirectives: {};
@@ -2,19 +2,19 @@
2
2
  * JQLite both a function and an array-like data structure for manipulation of DOM, linking elements to expando cache,
3
3
  * and execution of chain functions.
4
4
  *
5
- * @param {string|Element|Document|Window|JQLite|ArrayLike<Element>|(() => void)} element
5
+ * @param {string|Element|Comment|Document|Window|JQLite|ArrayLike<Element>|(() => void)} element
6
6
  * @returns {JQLite}
7
7
  */
8
- export function JQLite(element: string | Element | Document | Window | JQLite | ArrayLike<Element> | (() => void)): JQLite;
8
+ export function JQLite(element: string | Element | Comment | Document | Window | JQLite | ArrayLike<Element> | (() => void)): JQLite;
9
9
  export class JQLite {
10
10
  /**
11
11
  * JQLite both a function and an array-like data structure for manipulation of DOM, linking elements to expando cache,
12
12
  * and execution of chain functions.
13
13
  *
14
- * @param {string|Element|Document|Window|JQLite|ArrayLike<Element>|(() => void)} element
14
+ * @param {string|Element|Comment|Document|Window|JQLite|ArrayLike<Element>|(() => void)} element
15
15
  * @returns {JQLite}
16
16
  */
17
- constructor(element: string | Element | Document | Window | JQLite | ArrayLike<Element> | (() => void));
17
+ constructor(element: string | Element | Comment | Document | Window | JQLite | ArrayLike<Element> | (() => void));
18
18
  /**
19
19
  * Remove all child nodes of the set of matched elements from the DOM and clears CACHE data, associated with the node.
20
20
  * @returns {JQLite} The current instance of JQLite.
@@ -101,6 +101,35 @@ export class JQLite {
101
101
  * @returns {JQLite|any} - The retrieved data if acting as a getter. Otherwise, returns undefined.
102
102
  */
103
103
  data(key: string | any, value?: any): JQLite | any;
104
+ replaceWith(arg1: any): void | JQLite;
105
+ children(): JQLite;
106
+ /**
107
+ * @param {string} node
108
+ * @returns {JQLite}
109
+ */
110
+ append(node: string): JQLite;
111
+ /**
112
+ * @param {string} node
113
+ * @returns {JQLite}
114
+ */
115
+ prepend(node: string): JQLite;
116
+ /**
117
+ * @param {string} newElement
118
+ * @returns {JQLite}
119
+ */
120
+ after(newElement: string): JQLite;
121
+ /**
122
+ * @param {boolean} [keepData]
123
+ * @returns
124
+ */
125
+ remove(keepData?: boolean): this;
126
+ detach(): this;
127
+ parent(): any;
128
+ find(selector: any): any;
129
+ /**
130
+ * TODO: REMOVE! This function being used ONLY in tests!
131
+ */
132
+ triggerHandler(event: any, extraParameters: any): void | JQLite;
104
133
  toString(): string;
105
134
  eq(index: any): JQLite;
106
135
  length: number;