Skip to content

Commit 0999904

Browse files
committed
fixed template add list item
1 parent 2518efe commit 0999904

File tree

4 files changed

+97
-30
lines changed

4 files changed

+97
-30
lines changed

assets/js/app/controller.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@ export default class Controller {
1919
}
2020

2121
addImages (files) {
22-
console.log(files);
22+
// TODO: Add a flag indicating file loads are currently in progress
2323

2424
for(let i = 0; i < files.length; i++) {
2525
this.view.addListItem({
26-
id: i, // TODO: Make real id
26+
id: this.store.getNewId(),
2727
src: window.URL.createObjectURL(files[i]),
28-
name: files[i].name.substring(0, files[i].name.indexOf('.'))
28+
name: files[i].name.substring(0, files[i].name.indexOf('.')),
29+
onLoadSuccess: this.onLoadSuccess.bind(this)
2930
});
3031
}
3132

32-
// TODO: bind on image load
33+
}
3334

35+
onLoadSuccess (candidate) {
36+
console.log(candidate);
37+
// TODO: Check if all images have finished loading
38+
// TODO: Pass on to our texture packer
3439
}
3540

3641
updateSettingsValues (settings) {

assets/js/app/store.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default class Store {
4242

4343
}
4444

45+
getNewId () {
46+
let newId = this.id;
47+
this.id++;
48+
return newId;
49+
}
50+
4551
getSettings () {
4652
return this.settings;
4753
}

assets/js/app/templates.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
const parser = new DOMParser();
2-
31
export default class Template {
42
listItem(item) {
5-
let xmlString = `<li data-id="${item.id}">` +
6-
`<img src="${item.src}" height="60" />` +
7-
`<span>${item.name}</span>` +
8-
`<div class="remove"></div>` +
9-
`</li>`;
10-
return parser.parseFromString(xmlString, "text/xml").querySelector('li');
3+
4+
let li = document.createElement('li');
5+
let img = document.createElement('img');
6+
let info = document.createElement('span');
7+
let remove = document.createElement('div');
8+
9+
li.setAttribute('data-id', item.id);
10+
11+
img.src = item.src;
12+
img.height = 60;
13+
img.onload = function() {
14+
window.URL.revokeObjectURL(item.src);
15+
item.onLoadSuccess({
16+
img: this,
17+
name: item.name,
18+
id: item.id
19+
});
20+
};
21+
22+
li.appendChild(img);
23+
info.innerHTML = item.name;
24+
li.appendChild(info);
25+
26+
remove.classList.add('remove');
27+
li.appendChild(remove);
28+
29+
return li;
30+
1131
}
1232
}

assets/js/bundle.js

Lines changed: 54 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)