Skip to content

Commit

Permalink
adding id as direct refs (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
eavichay committed Dec 10, 2016
1 parent b952c46 commit 8eb4640
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
17 changes: 13 additions & 4 deletions SlimElement.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;(function() {


var css = 'slim-component, s-repeat { all: inherit; padding: 0; margin: 0; background: none; left: 0; top: 0;}',
var css = 's-repeat { display: none; } slim-component { all: inherit; padding: 0; margin: 0; background: none; left: 0; top: 0;}',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');

Expand Down Expand Up @@ -249,7 +249,7 @@
var arr = desc.split(".");
while(arr.length && obj) {
obj = obj[arr.shift()]
};
}
return obj;
}

Expand Down Expand Up @@ -339,6 +339,9 @@
allChildren = Array.prototype.slice.call(allChildren).concat(this)
for (let child of allChildren) {
child.parentBind = child.parentBind || this
if (child.getAttribute('id')) {
child.parentBind[ child.getAttribute('id') ] = child
}
if (child.attributes) for (let i = 0; i < child.attributes.length; i++) {
let descriptor = __describeAttribute(child.attributes[i])
if (descriptor.type) {
Expand Down Expand Up @@ -443,7 +446,12 @@
}

update() {
this.innerHTML = ''
if (this.childrenToRemove) {
for (let child of this.childrenToRemove) {
if (child.parentNode) child.parentNode.removeChild(child)
}
}
this.childrenToRemove = []
let childrenToAdd = []
for (let dataItem of this.sourceData) {
for (let child of this.__bindingTree.children) {
Expand All @@ -468,7 +476,8 @@
}
}
for (let child of childrenToAdd) {
this.appendChild(child)
this.parentNode.appendChild(child)
this.childrenToRemove.push(child)
}
}
})
Expand Down
1 change: 1 addition & 0 deletions example/Kanban/KanbanDemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
height: 100%;
margin: 0;
padding: 0;
background: black;
}

* {
Expand Down
11 changes: 8 additions & 3 deletions example/Kanban/kanban-column.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


get template() {
return `<span bind>[[data.name]]</span><kanban-item slim-repeat="myTasks"></kanban-item>`
return `<div id="title" bind>[[data.name]]</div><kanban-item slim-repeat="myTasks"></kanban-item>`
}

get myTasks() {
Expand All @@ -15,7 +15,7 @@

afterRender() {
this.model.addEventListener('change', () => {
this.update()
this.update(false, true)
})
$(this).droppable({
accept: 'kanban-item',
Expand All @@ -38,11 +38,16 @@
kanban-column {
display: inline-flex;
flex-direction: column;
height: 100%;
width: 15em;
padding: 1em;
padding-bottom: 5em;
background: antiquewhite;
align-items: center;
justify-content: flex-start;
}

kanban-column #title {
align-self: flex-start;
margin-bottom: 1em;
}
</style>
36 changes: 35 additions & 1 deletion example/Kanban/kanban-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,49 @@
return `
<div>
<div class="title"><span bind>[[data.title]]</span></div>
<div><input class="toggle" type="button" value="[getToggleText(open)]" /></div>
<div class="description" bind>[[data.description]]</div>
</div>`
}

beforeRender() {
this.open = true;
}

getToggleText(value) {
if (value) {
return '-'
}
return '+'
}

afterRender() {
$(this).draggable({
handle: '.title',
scroll: 'false',
start: () => {
this.open = false
this.update()
},
snap: 'kanban-column',
revert: 'invalid',
revertDuration: 100,
connectWith: 'kanban-column'
})
$(this.find('.toggle')).click( () => {
this.open = !this.open
this.update()
})
this.update()
}

update() {
super.update()
if (this.open) {
$(this.find('.description')).show()
} else {
$(this.find('.description')).hide()
}
}

})
Expand Down Expand Up @@ -52,8 +85,9 @@
kanban-item .title {
font-family: "Catamaran", Sans-serif;
font-weight: normal;
display: block;
font-size: 1.3em;
width: 100%;
border-bottom: 1px solid black;
display: inline-flex;
}
</style>

0 comments on commit 8eb4640

Please sign in to comment.