Skip to content

Commit 2fc31e8

Browse files
committed
v2.0
1 parent 1bdc2c9 commit 2fc31e8

4 files changed

Lines changed: 210 additions & 106 deletions

File tree

browser.js

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
exportModule("data-context-binding", ["data-context"], function factory(DC) {
99

10-
var { createDataContext, parse, stringify } = DC;
10+
var globalScope = this,
11+
{ createDataContext, parse, stringify } = DC;
1112

1213

1314
//TODO [ x ] default bind ...
@@ -22,8 +23,8 @@
2223
bindAllElements: { value: bindAllElements, writable: false, configurable: false, enumerable: false },
2324
bindElement: { value: bindElement, writable: false, configurable: false, enumerable: false },
2425
bindingContext: { value: bindingContext, writable: false, configurable: false, enumerable: false },
25-
change: { value: changeBind, writable: false, configurable: false, enumerable: false },
2626

27+
change: { value: changeBind, writable: false, configurable: false, enumerable: false },
2728
innerHTML: { value: innerHTMLBind, writable: true, configurable: false, enumerable: false },
2829
value: { value: valueBind, writable: true, configurable: false, enumerable: false },
2930
getvalue: { value: getValueBind, writable: true, configurable: false, enumerable: false },
@@ -103,7 +104,7 @@
103104

104105
bindElement(rootElement, rebinding);
105106

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]>*)")
107108
.forEach(function (element) {
108109

109110
if (!element.contextValue || rebinding) {
@@ -137,7 +138,8 @@
137138
!element?.attributes?.onbind &&
138139
!element?.attributes?.onunbind &&
139140
!element?.attributes?.bind &&
140-
!element?.attributes?.rebinding
141+
!element?.attributes?.rebinding &&
142+
!element?.attributes?.link
141143
)) {
142144

143145
return;
@@ -153,6 +155,13 @@
153155

154156
if (element.bindingContext?.isActive) { element.bindingContext.isActive(false); } // for rebinding
155157

158+
if (element.attributes.link && !element.linked) {// if true then linked
159+
160+
_link(element.attributes.link.value);
161+
162+
return;
163+
}
164+
156165
var _bindingContext = bindingContext(element, rebinding);
157166

158167
if (!rebinding && element.attributes.template) {
@@ -174,6 +183,20 @@
174183
return;
175184

176185

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+
177200
function _template(selectors, isMultiple = false) {
178201

179202
if (!selectors) { _tryBind(); return; }
@@ -786,10 +809,11 @@
786809
return false;
787810
}
788811

789-
this.innerHTML = event.newValue;
812+
var val = this.contextValue();
813+
this.innerHTML = val;
790814

791815
// I am alive!
792-
return event.newValue === undefined ? false : true;
816+
return val === undefined ? false : true;
793817
}
794818
function valueBind(event) {
795819

@@ -804,7 +828,7 @@
804828
return false;
805829
}
806830

807-
this.value = event.newValue;
831+
this.value = this.contextValue();
808832

809833
// Init
810834
if (event.eventName === "bind") {
@@ -829,7 +853,7 @@
829853
return false;
830854
}
831855

832-
this.value = event.newValue;
856+
this.value = this.contextValue();
833857

834858
// I am alive!
835859
return true;
@@ -851,7 +875,7 @@
851875
if (event.eventName === "bind") {
852876

853877
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(); } };
855879
}
856880

857881
// I am alive!
@@ -867,8 +891,8 @@
867891
return false;
868892
}
869893

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");
872896

873897
// Init
874898
if (event.eventName === "bind") {
@@ -877,7 +901,7 @@
877901
}
878902

879903
// I am alive!
880-
return event.newValue === undefined ? false : true;
904+
return this.contextValue() === undefined ? false : true;
881905
}
882906
function hiddenBind(event) {
883907

@@ -887,10 +911,10 @@
887911
return false;
888912
}
889913

890-
event.newValue ? this.setAttribute("hidden", "") : this.removeAttribute("hidden");
914+
this.contextValue() ? this.setAttribute("hidden", "") : this.removeAttribute("hidden");
891915

892916
// I am alive!
893-
return event.newValue === undefined ? false : true;
917+
return this.contextValue() === undefined ? false : true;
894918
}
895919
function changeBind(event) {
896920

@@ -944,7 +968,7 @@
944968
return false;
945969
}
946970

947-
if (event.newValue) { this.removeAttribute('disabled'); }
971+
if (this.contextValue()) { this.removeAttribute('disabled'); }
948972
else { this.setAttribute('disabled', 'disabled'); }
949973

950974
// I am alive!
@@ -960,7 +984,7 @@
960984
return false;
961985
}
962986

963-
if (event.newValue) { this.setAttribute('disabled', 'disabled'); }
987+
if (this.contextValue()) { this.setAttribute('disabled', 'disabled'); }
964988
else { this.removeAttribute('disabled'); }
965989

966990
// I am alive!

0 commit comments

Comments
 (0)