Skip to content

Commit

Permalink
#34 Showing files
Browse files Browse the repository at this point in the history
  • Loading branch information
elfoxero committed Mar 30, 2015
1 parent 8d8e2d2 commit bedd876
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 12 deletions.
74 changes: 63 additions & 11 deletions js/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,72 @@
function init() {
setup();

window.config.activity = 'zip';
window.config.app = window.activityData.filename;
window.files.path = 'sdcard';

load();
}

function setup() {
var section = $('article > section');
var index = $('#index');
index.removeChild($('#drawer'));

// #drawer
var section = element('section', { role: 'region', id: 'drawer', className: 'skin-dark' });

var header = element('header', { className: 'fixed' }, [
element('a', { id: 'back', className: 'folder', href: '#' }, [
element('span', { className: 'icon icon-back', text: 'back' })
]),
element('button', { id: 'close' }, [
element('span', { className: 'icon icon-close', text: 'close' })
]),
element('h1', { id: 'folder', text: ' ' })
]);

var toolbar = element('div', { role: 'toolbar' }, [
element('ul', null, [
element('li', null, [
element('span', { className: 'toolbar-text' }, [
element('span', { id: 'footer-label', 'data-l10n-id': 'items', 'data-l10n-args': '{"n": "0"}', text: '0 items' })
])
])
]),
element('ul')
]);

section.appendChild(header);
section.appendChild(toolbar);
document.body.insertBefore(section, index);

var ul = element('ul');
ul.id = 'files';
index.appendChild(element('section', { role: 'region', className: 'skin-dark' }, [
element('article', { className: 'content scrollable scrollable-y header' }, [
element('section', { 'data-type': 'list' }, [
element('ul', { className: 'files' })
])
])
]));

section.appendChild(ul);
for (var i = 0; i < 2; i++) {
document.body.appendChild(element('section', { role: 'region', name: 'side', 'data-position': 'right', 'data-skin': 'dark' }, [
element('article', { className: 'content scrollable scrollable-y header' }, [
element('section', { 'data-type': 'list' }, [
element('ul', { className: 'files' })
])
])
]));
}

// Events
$('#close').onclick = function (e) {
window.activity.postResult({saved: false});
window.activity = null;
};

$('#back').onclick = function () {
window.files.go(-1);
};
}

function load() {
Expand All @@ -50,13 +106,9 @@
}

worker.onmessage = function (e) {
var files = e.data;

files.forEach(function (file) {
var li = element('li');
li.textContent = file;
$('#files').appendChild(li);
});
window.files.set(e.data);
window.files.show();
window.config.refreshToolbar();
};

init();
Expand Down
13 changes: 12 additions & 1 deletion js/zip_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ onmessage = function (e) {
var entries = [];

Object.keys(zip.files).forEach(function (name) {
entries.push(name);
if (!zip.files[name].dir) {
entries.push({
name: '/sdcard/' + name,
disabled: false,
blob: {
name: '/sdcard/' + name,
lastModifiedDate: zip.files[name].date,
size: zip.files[name].asArrayBuffer().byteLength,
type: ''
}
});
}
});

postMessage(entries);
Expand Down

0 comments on commit bedd876

Please sign in to comment.