summaryrefslogtreecommitdiffstats
path: root/afb-client/bower_components/jszip/documentation/examples
diff options
context:
space:
mode:
Diffstat (limited to 'afb-client/bower_components/jszip/documentation/examples')
-rw-r--r--afb-client/bower_components/jszip/documentation/examples/download-zip-file.html59
-rw-r--r--afb-client/bower_components/jszip/documentation/examples/downloader.html58
-rw-r--r--afb-client/bower_components/jszip/documentation/examples/downloader.js89
-rw-r--r--afb-client/bower_components/jszip/documentation/examples/get-binary-files-ajax.html43
-rw-r--r--afb-client/bower_components/jszip/documentation/examples/read-local-file-api.html87
5 files changed, 336 insertions, 0 deletions
diff --git a/afb-client/bower_components/jszip/documentation/examples/download-zip-file.html b/afb-client/bower_components/jszip/documentation/examples/download-zip-file.html
new file mode 100644
index 0000000..869a54e
--- /dev/null
+++ b/afb-client/bower_components/jszip/documentation/examples/download-zip-file.html
@@ -0,0 +1,59 @@
+---
+title: "Download the generated zip file"
+layout: default
+section: example
+---
+
+<p>Tip : check the source of the page !</p>
+<h2>The FileSaver API</h2>
+<div>
+ Works on firefox, chrome , opera &gt;= 15 and IE &gt;= 10 (but NOT in compatibility view).<br/>
+ <button id="blob" class="btn btn-primary">click to download</button>
+</div>
+<h2>The data URL</h2>
+<div>
+ Does not work in IE, has restrictions on the length.<br/>
+ <button id="data_uri" class="btn btn-primary">click to download</button>
+</div>
+<script type="text/javascript">
+(function () {
+ var zip = new JSZip();
+ zip.file("Hello.txt", "Hello world\n");
+
+ function bindEvent(el, eventName, eventHandler) {
+ if (el.addEventListener){
+ // standard way
+ el.addEventListener(eventName, eventHandler, false);
+ } else if (el.attachEvent){
+ // old IE
+ el.attachEvent('on'+eventName, eventHandler);
+ }
+ }
+
+ // Blob
+ var blobLink = document.getElementById('blob');
+ if (JSZip.support.blob) {
+ function downloadWithBlob() {
+ try {
+ var blob = zip.generate({type:"blob"});
+ // see FileSaver.js
+ saveAs(blob, "hello.zip");
+ } catch(e) {
+ blobLink.innerHTML += " " + e;
+ }
+ return false;
+ }
+ bindEvent(blobLink, 'click', downloadWithBlob);
+ } else {
+ blobLink.innerHTML += " (not supported on this browser)";
+ }
+
+ // data URI
+ function downloadWithDataURI() {
+ window.location = "data:application/zip;base64," + zip.generate({type:"base64"});
+ }
+ var dataUriLink = document.getElementById('data_uri');
+ bindEvent(dataUriLink, 'click', downloadWithDataURI);
+
+})();
+</script>
diff --git a/afb-client/bower_components/jszip/documentation/examples/downloader.html b/afb-client/bower_components/jszip/documentation/examples/downloader.html
new file mode 100644
index 0000000..e3589db
--- /dev/null
+++ b/afb-client/bower_components/jszip/documentation/examples/downloader.html
@@ -0,0 +1,58 @@
+---
+title: "Mini app : Downloader"
+layout: default
+section: example
+---
+
+<p>Tip : check the source of the page !</p>
+
+<p>
+ This mini application let you choose the files you want in a list, download
+ them, zip them and give the result to the user.
+</p>
+<p>
+ This demo requires a recent browser, see <a href="{{site.baseurl}}/documentation/howto/write_zip.html">
+ the howto</a>.
+</p>
+
+
+
+<div id="downloader_application">
+ <h3>Please select your files</h3>
+ <form action="#" id="download_form">
+ <ul>
+ <li>
+ <label>
+ <input type="checkbox" data-url="{{site.baseurl}}/test/ref/complex_files/Franz Kafka - The Metamorphosis.epub" checked />
+ Franz Kafka - The Metamorphosis.epub
+ </label>
+ </li>
+ <li>
+ <label>
+ <input type="checkbox" data-url="{{site.baseurl}}/documentation/css/pygments.css" checked />
+ pygments.css
+ </label>
+ </li>
+ <li>
+ <label>
+ <input type="checkbox" data-url="{{site.baseurl}}/dist/jszip.js" />
+ jszip.js
+ </label>
+ </li>
+ <li>
+ <label>
+ <input type="checkbox" data-url="{{site.baseurl}}/test/ref/all.zip" />
+ all.zip
+ </label>
+ </li>
+ </ul>
+
+ <button type="submit" class="btn btn-primary">pack them !</button>
+</form>
+
+<p class="hide" id="result"></p>
+
+
+</div>
+
+<script type="text/javascript" src="{{site.baseurl}}/documentation/examples/downloader.js"></script>
diff --git a/afb-client/bower_components/jszip/documentation/examples/downloader.js b/afb-client/bower_components/jszip/documentation/examples/downloader.js
new file mode 100644
index 0000000..13903cc
--- /dev/null
+++ b/afb-client/bower_components/jszip/documentation/examples/downloader.js
@@ -0,0 +1,89 @@
+jQuery(function ($) {
+ "use strict";
+
+ /**
+ * Reset the message.
+ */
+ function resetMessage () {
+ $("#result")
+ .removeClass()
+ .text("");
+ }
+ /**
+ * show a successful message.
+ * @param {String} text the text to show.
+ */
+ function showMessage(text) {
+ resetMessage();
+ $("#result")
+ .addClass("alert alert-success")
+ .text(text);
+ }
+ /**
+ * show an error message.
+ * @param {String} text the text to show.
+ */
+ function showError(text) {
+ resetMessage();
+ $("#result")
+ .addClass("alert alert-danger")
+ .text(text);
+ }
+
+ /**
+ * Fetch the content, add it to the JSZip object
+ * and use a jQuery deferred to hold the result.
+ * @param {String} url the url of the content to fetch.
+ * @param {String} filename the filename to use in the JSZip object.
+ * @param {JSZip} zip the JSZip instance.
+ * @return {jQuery.Deferred} the deferred containing the data.
+ */
+ function deferredAddZip(url, filename, zip) {
+ var deferred = $.Deferred();
+ JSZipUtils.getBinaryContent(url, function (err, data) {
+ if(err) {
+ deferred.reject(err);
+ } else {
+ zip.file(filename, data, {binary:true});
+ deferred.resolve(data);
+ }
+ });
+ return deferred;
+ }
+
+ if(!JSZip.support.blob) {
+ showError("This demo works only with a recent browser !");
+ return;
+ }
+
+ var $form = $("#download_form").on("submit", function () {
+
+ resetMessage();
+
+ var zip = new JSZip();
+ var deferreds = [];
+
+ // find every checked item
+ $(this).find(":checked").each(function () {
+ var $this = $(this);
+ var url = $this.data("url");
+ var filename = url.replace(/.*\//g, "");
+ deferreds.push(deferredAddZip(url, filename, zip));
+ });
+
+ // when everything has been downloaded, we can trigger the dl
+ $.when.apply($, deferreds).done(function () {
+ var blob = zip.generate({type:"blob"});
+
+ // see FileSaver.js
+ saveAs(blob, "example.zip");
+
+ showMessage("done !");
+ }).fail(function (err) {
+ showError(err);
+ });
+ return false;
+ });
+});
+
+// vim: set shiftwidth=4 softtabstop=4:
diff --git a/afb-client/bower_components/jszip/documentation/examples/get-binary-files-ajax.html b/afb-client/bower_components/jszip/documentation/examples/get-binary-files-ajax.html
new file mode 100644
index 0000000..ee7594e
--- /dev/null
+++ b/afb-client/bower_components/jszip/documentation/examples/get-binary-files-ajax.html
@@ -0,0 +1,43 @@
+---
+title: "Get a file with an ajax call"
+layout: default
+section: example
+---
+
+<p>Tip : check the source of the page !</p>
+
+<h3>With JSZipUtils</h3>
+<div id="jszip_utils"></div>
+
+<script type="text/javascript">
+(function () {
+
+ function showError(elt, err) {
+ elt.innerHTML = "<p class='alert alert-danger'>" + err + "</p>";
+ }
+
+ function showContent(elt, type, content) {
+ elt.innerHTML = "<p class='alert alert-success'>loaded ! (as a " + type + ")<br/>" +
+ "Content = " + content + "</p>";
+ }
+
+ //=========================
+ // JSZipUtils
+ //=========================
+ JSZipUtils.getBinaryContent('{{site.baseurl}}/test/ref/text.zip', function(err, data) {
+ var elt = document.getElementById('jszip_utils');
+ if(err) {
+ showError(elt, err);
+ return;
+ }
+
+ try {
+ var zip = new JSZip(data);
+ showContent(elt, "" + data, zip.file("Hello.txt").asText());
+ } catch(e) {
+ showError(elt, e);
+ }
+ });
+
+})();
+</script>
diff --git a/afb-client/bower_components/jszip/documentation/examples/read-local-file-api.html b/afb-client/bower_components/jszip/documentation/examples/read-local-file-api.html
new file mode 100644
index 0000000..da307c2
--- /dev/null
+++ b/afb-client/bower_components/jszip/documentation/examples/read-local-file-api.html
@@ -0,0 +1,87 @@
+---
+title: "Reading a local file with the File API"
+layout: default
+section: example
+---
+
+<h3>Choose the local(s) zip file(s)</h3>
+<p class="note">Note : your browser will process the zip file, don't choose a file too big !</p>
+<input type="file" id="file" name="file" multiple /><br />
+
+<div id="error_block" class="alert alert-danger hidden">
+ You will need a recent browser to use this demo :(
+</div>
+
+<div id="result_block" class="hidden">
+ <h3>Content :</h3>
+ <div id="result"></div>
+</div>
+<script type="text/javascript" src="{{site.baseurl}}/test/jquery-1.8.3.min.js"></script>
+<script type="text/javascript">
+(function () {
+ if (!window.FileReader || !window.ArrayBuffer) {
+ $("#error_block").removeClass("hidden").addClass("show");
+ return;
+ }
+
+
+ var $result = $("#result");
+ $("#file").on("change", function(evt) {
+ // remove content
+ $result.html("");
+ // be sure to show the results
+ $("#result_block").removeClass("hidden").addClass("show");
+
+ // see http://www.html5rocks.com/en/tutorials/file/dndfiles/
+
+ var files = evt.target.files;
+ for (var i = 0, f; f = files[i]; i++) {
+
+ var reader = new FileReader();
+
+ // Closure to capture the file information.
+ reader.onload = (function(theFile) {
+ return function(e) {
+ var $title = $("<h4>", {
+ text : theFile.name
+ });
+ $result.append($title);
+ var $fileContent = $("<ul>");
+ try {
+
+ var dateBefore = new Date();
+ // read the content of the file with JSZip
+ var zip = new JSZip(e.target.result);
+ var dateAfter = new Date();
+
+ $title.append($("<span>", {
+ text:" (parsed in " + (dateAfter - dateBefore) + "ms)"
+ }));
+
+ // that, or a good ol' for(var entryName in zip.files)
+ $.each(zip.files, function (index, zipEntry) {
+ $fileContent.append($("<li>", {
+ text : zipEntry.name
+ }));
+ // the content is here : zipEntry.asText()
+ });
+ // end of the magic !
+
+ } catch(e) {
+ $fileContent = $("<div>", {
+ "class" : "alert alert-danger",
+ text : "Error reading " + theFile.name + " : " + e.message
+ });
+ }
+ $result.append($fileContent);
+ }
+ })(f);
+
+ // read the file !
+ // readAsArrayBuffer and readAsBinaryString both produce valid content for JSZip.
+ reader.readAsArrayBuffer(f);
+ // reader.readAsBinaryString(f);
+ }
+ });
+})();
+</script>