Skip to content

Commit

Permalink
Add bindings.if to core
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriro committed Jul 3, 2023
1 parent 53d9a96 commit 09c6827
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
20 changes: 0 additions & 20 deletions binding/_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,6 @@
return fn.apply(el, slice.call(arguments, 3))
}

bindings["if"] = bindingsIf
function bindingsIf(el, enabled) {
var parent = el.parentNode
, scope = this
if (enabled) {
if (!parent && el._ifComm) el._ifComm.parentNode.replaceChild(el, el._ifComm)
} else {
if (parent) {
if (!el._ifComm) {
El.on(el, "kill", El.kill.bind(el, el._ifComm = document.createComment("if")))
el._ifComm.render = function() {
El.render(el, scope)
}
}
parent.replaceChild(el._ifComm, el)
}
return true
}
}

bindings.is = function bindingIs(node, model, path, list, state, prefix) {
var match
, scope = this
Expand Down
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@
css: El.css = acceptMany(function(el, key, val) {
el.style[key.replace(camelRe, camelFn)] = "" + val
}),
"if": function(el, enabled) {
if (enabled) {
elReplace(el._ifComm, el)
} else {
if (!el._ifComm) {
addEvent(el, "kill", kill.bind(el, el._ifComm = document.createComment("if")))
el._ifComm.render = render.bind(el, el, this)
}
elReplace(el, el._ifComm)
return true
}
},
on: El.on = bindingsOn,
ref: function(el, name) {
this[name] = el
Expand Down Expand Up @@ -661,7 +673,7 @@
El.hasClass = hasClass
El.matches = matches
El.rate = rate
El.replace = replace
El.replace = elReplace
El.scope = elScope
El.scrollLeft = scrollLeft
El.scrollTop = scrollTop
Expand Down Expand Up @@ -977,9 +989,9 @@
} catch(e) {}
}

function replace(oldEl, newEl) {
function elReplace(oldEl, newEl) {
var parent = oldEl && oldEl.parentNode
if (parent && newEl) return parent.replaceChild(oldEl, newEl)
if (parent && newEl) return parent.replaceChild(newEl, oldEl)
}

function parseTemplate(str) {
Expand Down

0 comments on commit 09c6827

Please sign in to comment.