Skip to content

Commit

Permalink
#34 Created a main viewer (for TXT and ZIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
elfoxero committed Mar 29, 2015
1 parent b3c4118 commit 6a25b06
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 1 deletion.
29 changes: 29 additions & 0 deletions css/viewer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2013-2015 Jhon Klever, http://github.com/elfoxero
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish and distribute, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/

.hide {
display: none;
}

.shown {
display: block;
}
68 changes: 68 additions & 0 deletions elements/viewer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!--
Copyright (c) 2013-2015 Jhon Klever, http://github.com/elfoxero
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish and distribute, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
-->
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>File Viewer</title>

<link rel="stylesheet" href="../libraries/buildingblocks/style/headers.css">
<link rel="stylesheet" href="../libraries/buildingblocks/style/toolbars.css">

<link rel="stylesheet" href="../libraries/buildingblocks/icons/styles/action_icons.css">

<link rel="stylesheet" href="../libraries/buildingblocks/util.css">
<link rel="stylesheet" href="../libraries/buildingblocks/fonts.css">

<link rel="stylesheet" href="../libraries/buildingblocks/cross_browser.css">

<link rel="stylesheet" href="../libraries/buildingblocks/extra.css">
<link rel="stylesheet" href="../css/viewer.css">

<!-- END OF STYLES -->

<link rel="prefetch" type="application/l10n" href="../locales/locales.ini" />
</head>
<body>
<section id="index" data-position="current" class="left-to-current">
<section id="drawer" role="region" class="skin-dark">
<header>
<button id="close"><span class="icon icon-close">close</span></button>
<menu type="toolbar" class="hide"><button id="save" data-l10n-id="save">Save</button></menu>
<h1 id="name"></h1>
</header>
<article>
<section class="content"></section>
<div role="toolbar"></div>
</article>
</section>
</section>

<!-- START OF SCRIPTS -->

<script defer src="../libraries/l10n.js"></script>

<script defer src="../js/viewer.js"></script>
</body>
</html>
84 changes: 84 additions & 0 deletions js/viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2013-2015 Jhon Klever, http://github.com/elfoxero
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish and distribute, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/

;+function (window, document, undefined) {
var _ = window.document.webL10n.get;

window.activity = null;
navigator.setMessageHandler = navigator.setMessageHandler || navigator.mozSetMessageHandler;

var addJs = function (src, callback) {
var el = element('script', { src: src });
callback && (el.onload = callback);
document.body.appendChild(el);
};

var addCss = function (href) {
var el = element('link', { rel: 'stylesheet', href: href });
document.querySelector('head').appendChild(el);
};

window.$ = function (selector) {
return document.querySelector(selector);
};

window.element = function (tag, attrs) {
var elem = document.createElement(tag);

if (attrs) {
if (typeof attrs === 'string') {
elem.textContent = attrs;
} else if (typeof attrs === 'object') {
Object.keys(attrs).forEach(function (attr) {
if (attr === 'text') {
elem.textContent = attrs[attr];
} else {
elem[attr] = attrs[attr];
}
});
}
}

return elem;
};

navigator.setMessageHandler('activity', function(request) {
activity = request;

window.activityData = activity.source.data;

$('#name').textContent = activityData.filename;

if (/text/ .test(activityData.type) || /javascript/ .test(activityData.type)) {
// Include scripts for Text Viewer
} else if (/zip/ .test(activityData.type)) {
// Include scripts for ZIP Viewer
}
});

$('#close').onclick = function (e) {
if (window.activity) {
activity.postResult({saved: false});
activity = null;
}
};
} (window, document, undefined);
2 changes: 1 addition & 1 deletion manifest.webapp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"disposition": "inline",
"returnValue": true,
"href": "/elements/text.html"
"href": "/elements/viewer.html"
},
"pick-folder": {
"disposition": "inline",
Expand Down

0 comments on commit 6a25b06

Please sign in to comment.