|
7 | 7 |
|
8 | 8 | exportModule("data-context-binding", ["data-context"], function factory(DC) { |
9 | 9 |
|
10 | | - var { createDataContext, parse, stringify } = DC; |
| 10 | + var globalScope = this, |
| 11 | + { createDataContext, parse, stringify } = DC; |
11 | 12 |
|
12 | 13 |
|
13 | 14 | //TODO [ x ] default bind ... |
|
22 | 23 | bindAllElements: { value: bindAllElements, writable: false, configurable: false, enumerable: false }, |
23 | 24 | bindElement: { value: bindElement, writable: false, configurable: false, enumerable: false }, |
24 | 25 | bindingContext: { value: bindingContext, writable: false, configurable: false, enumerable: false }, |
25 | | - change: { value: changeBind, writable: false, configurable: false, enumerable: false }, |
26 | 26 |
|
| 27 | + change: { value: changeBind, writable: false, configurable: false, enumerable: false }, |
27 | 28 | innerHTML: { value: innerHTMLBind, writable: true, configurable: false, enumerable: false }, |
28 | 29 | value: { value: valueBind, writable: true, configurable: false, enumerable: false }, |
29 | 30 | getvalue: { value: getValueBind, writable: true, configurable: false, enumerable: false }, |
|
103 | 104 |
|
104 | 105 | bindElement(rootElement, rebinding); |
105 | 106 |
|
106 | | - rootElement.querySelectorAll("[bind]:not(template>*),[onbind]:not(template>*),[onunbind]:not(template>*),[template]:not(template>*),[templates]:not(template>*),[rebinding]:not(template>*)") |
| 107 | + rootElement.querySelectorAll("[bind]:not(template>*):not([link]>*),[onbind]:not(template>*):not([link]>*),[onunbind]:not(template>*):not([link]>*),[template]:not(template>*):not([link]>*),[templates]:not(template>*):not([link]>*),[rebinding]:not(template>*):not([link]>*),[link]:not(template>*):not([link]>*)") |
107 | 108 | .forEach(function (element) { |
108 | 109 |
|
109 | 110 | if (!element.contextValue || rebinding) { |
|
137 | 138 | !element?.attributes?.onbind && |
138 | 139 | !element?.attributes?.onunbind && |
139 | 140 | !element?.attributes?.bind && |
140 | | - !element?.attributes?.rebinding |
| 141 | + !element?.attributes?.rebinding && |
| 142 | + !element?.attributes?.link |
141 | 143 | )) { |
142 | 144 |
|
143 | 145 | return; |
|
153 | 155 |
|
154 | 156 | if (element.bindingContext?.isActive) { element.bindingContext.isActive(false); } // for rebinding |
155 | 157 |
|
| 158 | + if (element.attributes.link && !element.linked) {// if true then linked |
| 159 | + |
| 160 | + _link(element.attributes.link.value); |
| 161 | + |
| 162 | + return; |
| 163 | + } |
| 164 | + |
156 | 165 | var _bindingContext = bindingContext(element, rebinding); |
157 | 166 |
|
158 | 167 | if (!rebinding && element.attributes.template) { |
|
174 | 183 | return; |
175 | 184 |
|
176 | 185 |
|
| 186 | + function _link(path) { |
| 187 | + |
| 188 | + var { CreateLink } = globalScope?.modules?.['ws-user']; |
| 189 | + |
| 190 | + if (CreateLink) { |
| 191 | + |
| 192 | + element.wsLink = WsUser.CreateLink(path, element); |
| 193 | + element.datacontext = element.wsLink.datacontext; |
| 194 | + element.setAttribute("linked", path); |
| 195 | + element.removeAttribute("link"); |
| 196 | + bindAllElements(element, rebinding); |
| 197 | + } |
| 198 | + } |
| 199 | + |
177 | 200 | function _template(selectors, isMultiple = false) { |
178 | 201 |
|
179 | 202 | if (!selectors) { _tryBind(); return; } |
|
786 | 809 | return false; |
787 | 810 | } |
788 | 811 |
|
789 | | - this.innerHTML = event.newValue; |
| 812 | + var val = this.contextValue(); |
| 813 | + this.innerHTML = val; |
790 | 814 |
|
791 | 815 | // I am alive! |
792 | | - return event.newValue === undefined ? false : true; |
| 816 | + return val === undefined ? false : true; |
793 | 817 | } |
794 | 818 | function valueBind(event) { |
795 | 819 |
|
|
804 | 828 | return false; |
805 | 829 | } |
806 | 830 |
|
807 | | - this.value = event.newValue; |
| 831 | + this.value = this.contextValue(); |
808 | 832 |
|
809 | 833 | // Init |
810 | 834 | if (event.eventName === "bind") { |
|
829 | 853 | return false; |
830 | 854 | } |
831 | 855 |
|
832 | | - this.value = event.newValue; |
| 856 | + this.value = this.contextValue(); |
833 | 857 |
|
834 | 858 | // I am alive! |
835 | 859 | return true; |
|
851 | 875 | if (event.eventName === "bind") { |
852 | 876 |
|
853 | 877 | this.onchange = function () { this.contextValue(this.value); }; |
854 | | - this.onkeydown = function (ev) { if (ev.keyCode === 27) { this.value = his.contextValue(); } }; |
| 878 | + this.onkeydown = function (ev) { if (ev.keyCode === 27) { this.value = this.contextValue(); } }; |
855 | 879 | } |
856 | 880 |
|
857 | 881 | // I am alive! |
|
867 | 891 | return false; |
868 | 892 | } |
869 | 893 |
|
870 | | - this.checked = event.newValue; |
871 | | - event.newValue ? this.setAttribute("checked", "") : this.removeAttribute("checked"); |
| 894 | + this.checked = this.contextValue(); |
| 895 | + this.checked ? this.setAttribute("checked", "") : this.removeAttribute("checked"); |
872 | 896 |
|
873 | 897 | // Init |
874 | 898 | if (event.eventName === "bind") { |
|
877 | 901 | } |
878 | 902 |
|
879 | 903 | // I am alive! |
880 | | - return event.newValue === undefined ? false : true; |
| 904 | + return this.contextValue() === undefined ? false : true; |
881 | 905 | } |
882 | 906 | function hiddenBind(event) { |
883 | 907 |
|
|
887 | 911 | return false; |
888 | 912 | } |
889 | 913 |
|
890 | | - event.newValue ? this.setAttribute("hidden", "") : this.removeAttribute("hidden"); |
| 914 | + this.contextValue() ? this.setAttribute("hidden", "") : this.removeAttribute("hidden"); |
891 | 915 |
|
892 | 916 | // I am alive! |
893 | | - return event.newValue === undefined ? false : true; |
| 917 | + return this.contextValue() === undefined ? false : true; |
894 | 918 | } |
895 | 919 | function changeBind(event) { |
896 | 920 |
|
|
944 | 968 | return false; |
945 | 969 | } |
946 | 970 |
|
947 | | - if (event.newValue) { this.removeAttribute('disabled'); } |
| 971 | + if (this.contextValue()) { this.removeAttribute('disabled'); } |
948 | 972 | else { this.setAttribute('disabled', 'disabled'); } |
949 | 973 |
|
950 | 974 | // I am alive! |
|
960 | 984 | return false; |
961 | 985 | } |
962 | 986 |
|
963 | | - if (event.newValue) { this.setAttribute('disabled', 'disabled'); } |
| 987 | + if (this.contextValue()) { this.setAttribute('disabled', 'disabled'); } |
964 | 988 | else { this.removeAttribute('disabled'); } |
965 | 989 |
|
966 | 990 | // I am alive! |
|
0 commit comments