Just what you need to write.
This commit is contained in:
parent
13166dd93b
commit
a590528daa
39
Rakefile
39
Rakefile
@ -1,39 +0,0 @@
|
|||||||
require 'uglifier'
|
|
||||||
|
|
||||||
task default: %w[build]
|
|
||||||
|
|
||||||
task :build_mla do
|
|
||||||
puts "browserifying"
|
|
||||||
puts system("browserify -t coffeeify browser.app.coffee > js/markdowntomla.js")
|
|
||||||
|
|
||||||
puts "building minified self-contained index.html"
|
|
||||||
html = File.read('template.html')
|
|
||||||
bundled = html.split("\n").map{|line|
|
|
||||||
if line =~ /\<script.*src=\"(.*)\"/
|
|
||||||
path = $1
|
|
||||||
js = Uglifier.compile(File.read(path))
|
|
||||||
"<script type='text/javascript'>#{js}</script>"
|
|
||||||
else
|
|
||||||
line
|
|
||||||
end
|
|
||||||
}
|
|
||||||
File.open('built/index.html', 'w'){|f| f.puts bundled}
|
|
||||||
end
|
|
||||||
|
|
||||||
task :build_apa do
|
|
||||||
puts "browserifying"
|
|
||||||
puts system("browserify -t coffeeify browser.markdowntoapa.coffee > js/markdowntoapa.js")
|
|
||||||
|
|
||||||
puts "building minified self-contained index.html"
|
|
||||||
html = File.read('template_markdowntoapa.html')
|
|
||||||
bundled = html.split("\n").map{|line|
|
|
||||||
if line =~ /\<script.*src=\"(.*)\"/
|
|
||||||
path = $1
|
|
||||||
js = Uglifier.compile(File.read(path))
|
|
||||||
"<script type='text/javascript'>#{js}</script>"
|
|
||||||
else
|
|
||||||
line
|
|
||||||
end
|
|
||||||
}
|
|
||||||
File.open('built/apa/index.html', 'w'){|f| f.puts bundled}
|
|
||||||
end
|
|
Binary file not shown.
44
apa_paper.md
44
apa_paper.md
@ -1,44 +0,0 @@
|
|||||||
author: Christian R. Genco
|
|
||||||
institution: Southern Methodist University
|
|
||||||
title: Varying Definitions of Online Communication and\nTheir Effects on Relationship Research
|
|
||||||
runninghead: VARYING DEFINITIONS OF ONLINE COMMUNICATION
|
|
||||||
abstract: This paper explores four published articles that report on results from research conducted on online (Internet) and offline (non-Internet) relationships and their relationship to computer-mediated communication (CMC). The articles, however, vary in their definitions and uses of CMC. Butler and Kraut (2002) suggest that face-to-face (FtF) interactions are more effective than CMC, defined and used as “email,” in creating feelings of closeness or intimacy. Other articles define CMC differently and, therefore, offer different results. This paper examines Cummings, Butler, and Kraut’s (2002) research in relation to three other research articles to suggest that all forms of CMC should be studied in order to fully understand how CMC influences online and offline relationships.
|
|
||||||
keywords: computer-mediated communication, face-to-face communication
|
|
||||||
|
|
||||||
Numerous studies have been conducted on various facets of Internet relationships, focusing on the levels of intimacy, closeness, different communication modalities, and the frequency of use of computer-mediated communication (CMC). However, contradictory results are suggested within this research because only certain aspects of CMC are investigated, for example, email only. Cummings, Butler, and Kraut (2002) suggest that face-to-face (FtF) interactions are more effective than CMC (read: email) in creating feelings of closeness or intimacy, while other studies suggest the opposite. To understand how both online (Internet) and offline (non-Internet) relationships are affected by CMC, all forms of CMC should be studied. This paper examines Cummings et al.’s research against other CMC research to propose that additional research be conducted to better understand how online communication affects relationships.
|
|
||||||
|
|
||||||
# Literature Review
|
|
||||||
|
|
||||||
In Cummings et al.’s (2002) summary article reviewing three empirical studies on online social relationships, it was found that CMC, especially email, was less effective than FtF contact in creating and maintaining close social relationships. Two of the three reviewed studies focusing on communication in non-Internet and Internet relationships mediated by FtF, phone, or email modalities found that the frequency of each modality’s use was significantly linked to the strength of the particular relationship (Cummings et al., 2002). The strength of the relationship was predicted best by FtF and phone communication, as participants rated email as an inferior means of maintaining personal relationships as compared to FtF and phone contacts (Cummings et al., 2002).
|
|
||||||
|
|
||||||
Cummings et al. (2002) reviewed an additional study conducted in 1999 by the HomeNet project (see Appendix A for more information on the HomeNet project). In this project, Kraut, Mukhopadhyay, Szczypula, Kiesler, and Scherlis (1999) compared the value of using CMC and non-CMC to maintain relationships with partners. They found that participants corresponded less frequently with their Internet partner (5.2 times per month) than with their non-Internet partner (7.2 times per month) (as cited in Cummings et al., 2002). This difference does not seem significant, as it is only two times less per month. However, in additional self-report surveys, participants responded feeling more distant, or less intimate, towards their Internet partner than their nonInternet partner. This finding may be attributed to participants’ beliefs that email is an inferior mode of personal relationship communication.
|
|
||||||
|
|
||||||
# Discussion
|
|
||||||
|
|
||||||
In 2002, Cummings et al. stated that the evidence from their research conflicted with other data examining the effectiveness of online social relationships. This statement is supported by the aforementioned discussion of other research. There may be a few possible theoretical explanations for these discrepancies.
|
|
||||||
|
|
||||||
## Limitations of These Studies
|
|
||||||
|
|
||||||
The discrepancies identified may result from a number of limitations found in the materials reviewed by Cummings et al. These limitations can result from technological constraints, demographic factors, or issues of modality. Each of these limitations will be examined in further detail below.
|
|
||||||
|
|
||||||
### Technological limitations.
|
|
||||||
|
|
||||||
First, one reviewed study by Cummings et al. (2002) examined only email correspondence for their CMC modality. Therefore, the study is limited to only one mode of communication among other alternatives, e.g., IM as studied by Hu et al. (2004). Because of its many personalized features, IM provides more personal CMC. For example, it is in real time without delay, voice-chat and video features are available for many IM programs, and text boxes can be personalized with the user’s picture, favorite colors and text, and a wide variety of emoticons, e.g., :). These options allow for both an increase in self-expression and the ability to overcompensate for the barriers of CMC through customizable features, as stated in Tidwell and Walther
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Conclusions and Future Study
|
|
||||||
|
|
||||||
In order to gain a complete understanding of CMC’s true effect on both online and offline relationships, it is necessary to conduct a study that examines all aspects of CMC. This includes, but is not limited to, email, IM, voice-chat, video-chat, online journals and diaries, online social groups with message boards, and chat rooms. The effects on relationships of each modality may be different, and this is demonstrated by the discrepancies in intimacy between email and IM correspondence. As each mode of communication becomes more prevalent in individuals’ lives, it is important to examine the impact of all modes of CMC on online and offline relationship formation, maintenance, and even termination
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# References
|
|
||||||
|
|
||||||
Cummings, J. N., Butler, B., & Kraut, R. (2002). The quality of online social relationships. *Communications of the ACM, 45*(7), 103-108.
|
|
||||||
|
|
||||||
Hu, Y., Wood, J. F., Smith, V., & Westbrook, N. (2004). Friendships through IM: Examining the relationship between instant messaging and intimacy. *Journal of Computer-Mediated Communication, 10*, 38-48.
|
|
||||||
|
|
||||||
Tidwell, L. C., & Walther, J. B. (2002). Computer-mediated communication effects on disclosure, impressions, and interpersonal evaluations: Getting to know one another a bit at a time. *Human Communication Research, 28*, 317-348.
|
|
||||||
|
|
||||||
Underwood, H., & Findlay, B. (2004). Internet relationships and their impact on primary relationships. *Behaviour Change, 21*(2), 127-140.
|
|
@ -1,45 +0,0 @@
|
|||||||
# browserify -t coffeeify browser.app.coffee > js/markdowntomla.js
|
|
||||||
|
|
||||||
window.markdowntomla = require('./markdowntomla.coffee')
|
|
||||||
window.md = require('markdown').markdown
|
|
||||||
window._ = require('underscore')
|
|
||||||
window.extractMetadata = markdowntomla.extractMetadata
|
|
||||||
window.createMLADocument = markdowntomla.createMLADocument
|
|
||||||
window.blobStream = require('blob-stream')
|
|
||||||
|
|
||||||
window.editor = ace.edit("editor")
|
|
||||||
editor.setTheme("ace/theme/textmate")
|
|
||||||
editor.getSession().setMode("ace/mode/markdown")
|
|
||||||
editor.getSession().setUseWrapMode(true)
|
|
||||||
editor.renderer.setShowPrintMargin(false)
|
|
||||||
|
|
||||||
# do we have anything saved?
|
|
||||||
if essay = localStorage?.getItem('essay')
|
|
||||||
editor.getSession().setValue(essay)
|
|
||||||
|
|
||||||
refreshTimer = null
|
|
||||||
editor.getSession().on 'change', ->
|
|
||||||
clearTimeout(refreshTimer)
|
|
||||||
refreshTimer = setTimeout(->
|
|
||||||
refresh()
|
|
||||||
localStorage?.setItem('essay', editor.getSession().getValue())
|
|
||||||
, 1000)
|
|
||||||
|
|
||||||
window.refresh = ->
|
|
||||||
stream = blobStream()
|
|
||||||
content = editor.getSession().getValue()
|
|
||||||
content = extractMetadata(content)
|
|
||||||
body = content.body
|
|
||||||
metadata = content.metadata
|
|
||||||
createMLADocument(body, metadata, stream)
|
|
||||||
stream.on 'finish', ->
|
|
||||||
# get a blob you can do whatever you like with
|
|
||||||
# blob = stream.toBlob('application/pdf')
|
|
||||||
|
|
||||||
# or get a blob URL for display in the browser
|
|
||||||
url = stream.toBlobURL('application/pdf')
|
|
||||||
document.getElementById('preview').src = url
|
|
||||||
|
|
||||||
document.title = "#{metadata.title} - MarkdownToMLA.com"
|
|
||||||
|
|
||||||
refresh()
|
|
@ -1,46 +0,0 @@
|
|||||||
# browserify -t coffeeify browser.app.coffee > js/markdowntomla.js
|
|
||||||
|
|
||||||
window.markdowntoapa = require('./markdowntoapa.coffee')
|
|
||||||
window.md = require('markdown').markdown
|
|
||||||
window._ = require('underscore')
|
|
||||||
window.extractMetadata = markdowntoapa.extractMetadata
|
|
||||||
window.createMLADocument = markdowntoapa.createAPADocument
|
|
||||||
window.blobStream = require('blob-stream')
|
|
||||||
|
|
||||||
window.editor = ace.edit("editor")
|
|
||||||
editor.setTheme("ace/theme/textmate")
|
|
||||||
editor.getSession().setMode("ace/mode/markdown")
|
|
||||||
editor.getSession().setUseWrapMode(true)
|
|
||||||
editor.renderer.setShowPrintMargin(false)
|
|
||||||
|
|
||||||
# do we have anything saved?
|
|
||||||
if essay = localStorage?.getItem('APA_paper')
|
|
||||||
editor.getSession().setValue(essay)
|
|
||||||
|
|
||||||
refreshTimer = null
|
|
||||||
editor.getSession().on 'change', ->
|
|
||||||
clearTimeout(refreshTimer)
|
|
||||||
refreshTimer = setTimeout(->
|
|
||||||
refresh()
|
|
||||||
localStorage?.setItem('APA_paper', editor.getSession().getValue())
|
|
||||||
, 1000)
|
|
||||||
|
|
||||||
window.refresh = ->
|
|
||||||
content = editor.getSession().getValue()
|
|
||||||
content = extractMetadata(content)
|
|
||||||
body = content.body
|
|
||||||
metadata = content.metadata
|
|
||||||
doc = createMLADocument(body, metadata)
|
|
||||||
stream = blobStream()
|
|
||||||
doc.pipe(stream)
|
|
||||||
stream.on 'finish', ->
|
|
||||||
# get a blob you can do whatever you like with
|
|
||||||
# blob = stream.toBlob('application/pdf')
|
|
||||||
|
|
||||||
# or get a blob URL for display in the browser
|
|
||||||
url = stream.toBlobURL('application/pdf')
|
|
||||||
document.getElementById('preview').src = url
|
|
||||||
|
|
||||||
document.title = "#{metadata.title} - MarkdownToAPA.com"
|
|
||||||
|
|
||||||
refresh()
|
|
@ -38,21 +38,23 @@
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<pre id="editor">
|
<pre id="editor">
|
||||||
author: Christian Genco
|
author: YOUR NAME
|
||||||
instructor: Professor Elisa Farrell
|
instructor: INSTRUCTOR NAME
|
||||||
course: ENGL 1341
|
course: COURSE NAME
|
||||||
date: 6 April 2015
|
date: DAY MONTH YEAR
|
||||||
title: On MarkdownToMLA.com and the Human Condition
|
title: TITLE
|
||||||
|
|
||||||
Hi! Welcome to MarkdownToMLA.com - a simple website with an even simpler purpose: making it less annoying to generate MLA-formatted documents and essays for school (or work, if you... write essays for work? Maybe you're an english teacher? I'm actually not sure if anyone actually uses MLA in the real world).
|
This is an example of body text.
|
||||||
|
|
||||||
The stuff on the left is editable, and automatically generates the PDF on the right, which can be downloaded and emailed to your teacher, or printed out, or whatever else you want to do with a PDF. Everything you write is automatically saved as soon as you pause typing, but it's still a good idea to copy and paste it somewhere else every once in a while as a backup. You can even use this website without being connected to the internet!
|
This will be the bulk of how you're going to be writing.
|
||||||
|
|
||||||
The special format on the left is called Markdown. You can easily make things *italic* and **bold**, as well as quote important people:
|
Perform *italics* and **bolds** like so.
|
||||||
|
|
||||||
|
Here's how you quote.
|
||||||
|
|
||||||
> Writing MLA-formatted essays is much easier with markdowntomla.com. I use it all the time when I write essays to foreign dictators, as well as to my wife when I need her to pick up something from the store on the way home (we're a very formal family). (Obama)
|
> Writing MLA-formatted essays is much easier with markdowntomla.com. I use it all the time when I write essays to foreign dictators, as well as to my wife when I need her to pick up something from the store on the way home (we're a very formal family). (Obama)
|
||||||
|
|
||||||
Some teachers don't like you to use subheadings in a paper, but here's the standard way of doing that:
|
Subheadings:
|
||||||
|
|
||||||
# Heading 1
|
# Heading 1
|
||||||
|
|
||||||
@ -64,25 +66,20 @@ Some teachers don't like you to use subheadings in a paper, but here's the stand
|
|||||||
|
|
||||||
##### Heading 5
|
##### Heading 5
|
||||||
|
|
||||||
Need a page break? Just type three dashes on an empty line.
|
Page Break
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Whoa, so much more room on this page. There's two things left to cover: the special **author**, **instructor**, **course**, **date**, and **title** section at the top; and the work's cited page. The former is used for the MLA heading, numbering the pages, and naming your downloaded PDF. The later is pretty self explanatory (look at the markdown source code at the bottom of this essay).
|
The special **author**, **instructor**, **course**, **date**, and **title** section at the top; and the work's cited page. The former is used for the MLA heading, numbering the pages, and naming your downloaded PDF. The later is pretty self explanatory (look at the markdown source code at the bottom of this essay).
|
||||||
|
|
||||||
For help generating those citations, check out easybib.com, bibme.org, and citationmachine.net. Be careful citing Wikipedia, but there's also a handy "cite this page" button on every page.
|
For help generating those citations, check out easybib.com, bibme.org, and citationmachine.net. Be careful citing Wikipedia, but there's also a handy "cite this page" button on every page.
|
||||||
|
|
||||||
If you have any suggestions or feedback for how this can be improved, send me a tweet @cgenco or contact me through my website at http://christian.gen.co (I also have a talk on there about how to go to college for free). Have fun writing essays :D
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# Works Cited
|
# Works Cited
|
||||||
|
|
||||||
Egan, Greg. *Permutation City*. New York: HarperPrism, 1994. Print.
|
[Christian Genco's Markdown to MLA](https://github.com/christiangenco/markdowntomla)
|
||||||
|
|
||||||
Rowling, J. K., and Mary GrandPre. *Harry Potter and the Chamber of Secrets*. New York: Arthur A. Levine, 1999. Print.
|
|
||||||
|
|
||||||
Wikipedia contributors. "Hacker News." Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 18 Mar. 2015. Web. 7 Apr. 2015.
|
|
||||||
</pre>
|
</pre>
|
||||||
<iframe id="preview"></iframe>
|
<iframe id="preview"></iframe>
|
||||||
|
|
BIN
js/.DS_Store
vendored
BIN
js/.DS_Store
vendored
Binary file not shown.
@ -1,177 +0,0 @@
|
|||||||
/* Blob.js
|
|
||||||
* A Blob implementation.
|
|
||||||
* 2013-01-23
|
|
||||||
*
|
|
||||||
* By Eli Grey, http://eligrey.com
|
|
||||||
* By Devin Samarin, https://github.com/eboyjr
|
|
||||||
* License: X11/MIT
|
|
||||||
* See LICENSE.md
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*global self, unescape */
|
|
||||||
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
|
|
||||||
plusplus: true */
|
|
||||||
|
|
||||||
/*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
|
|
||||||
|
|
||||||
if (typeof Blob !== "function")
|
|
||||||
var Blob = (function (view) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || view.MSBlobBuilder || (function(view) {
|
|
||||||
var
|
|
||||||
get_class = function(object) {
|
|
||||||
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
|
|
||||||
}
|
|
||||||
, FakeBlobBuilder = function BlobBuilder() {
|
|
||||||
this.data = [];
|
|
||||||
}
|
|
||||||
, FakeBlob = function Blob(data, type, encoding) {
|
|
||||||
this.data = data;
|
|
||||||
this.size = data.length;
|
|
||||||
this.type = type;
|
|
||||||
this.encoding = encoding;
|
|
||||||
}
|
|
||||||
, FBB_proto = FakeBlobBuilder.prototype
|
|
||||||
, FB_proto = FakeBlob.prototype
|
|
||||||
, FileReaderSync = view.FileReaderSync
|
|
||||||
, FileException = function(type) {
|
|
||||||
this.code = this[this.name = type];
|
|
||||||
}
|
|
||||||
, file_ex_codes = (
|
|
||||||
"NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
|
|
||||||
+ "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
|
|
||||||
).split(" ")
|
|
||||||
, file_ex_code = file_ex_codes.length
|
|
||||||
, real_URL = view.URL || view.webkitURL || view
|
|
||||||
, real_create_object_URL = real_URL.createObjectURL
|
|
||||||
, real_revoke_object_URL = real_URL.revokeObjectURL
|
|
||||||
, URL = real_URL
|
|
||||||
, btoa = view.btoa
|
|
||||||
, atob = view.atob
|
|
||||||
, can_apply_typed_arrays = false
|
|
||||||
, can_apply_typed_arrays_test = function(pass) {
|
|
||||||
can_apply_typed_arrays = !pass;
|
|
||||||
}
|
|
||||||
|
|
||||||
, ArrayBuffer = view.ArrayBuffer
|
|
||||||
, Uint8Array = view.Uint8Array
|
|
||||||
;
|
|
||||||
FakeBlob.fake = FB_proto.fake = true;
|
|
||||||
while (file_ex_code--) {
|
|
||||||
FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (Uint8Array) {
|
|
||||||
can_apply_typed_arrays_test.apply(0, new Uint8Array(1));
|
|
||||||
}
|
|
||||||
} catch (ex) {}
|
|
||||||
if (!real_URL.createObjectURL) {
|
|
||||||
URL = view.URL = {};
|
|
||||||
}
|
|
||||||
URL.createObjectURL = function(blob) {
|
|
||||||
var
|
|
||||||
type = blob.type
|
|
||||||
, data_URI_header
|
|
||||||
;
|
|
||||||
if (type === null) {
|
|
||||||
type = "application/octet-stream";
|
|
||||||
}
|
|
||||||
if (blob instanceof FakeBlob) {
|
|
||||||
data_URI_header = "data:" + type;
|
|
||||||
if (blob.encoding === "base64") {
|
|
||||||
return data_URI_header + ";base64," + blob.data;
|
|
||||||
} else if (blob.encoding === "URI") {
|
|
||||||
return data_URI_header + "," + decodeURIComponent(blob.data);
|
|
||||||
} if (btoa) {
|
|
||||||
return data_URI_header + ";base64," + btoa(blob.data);
|
|
||||||
} else {
|
|
||||||
return data_URI_header + "," + encodeURIComponent(blob.data);
|
|
||||||
}
|
|
||||||
} else if (real_create_object_URL) {
|
|
||||||
return real_create_object_URL.call(real_URL, blob);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
URL.revokeObjectURL = function(object_URL) {
|
|
||||||
if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
|
|
||||||
real_revoke_object_URL.call(real_URL, object_URL);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
FBB_proto.append = function(data/*, endings*/) {
|
|
||||||
var bb = this.data;
|
|
||||||
// decode data to a binary string
|
|
||||||
if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
|
|
||||||
if (can_apply_typed_arrays) {
|
|
||||||
bb.push(String.fromCharCode.apply(String, new Uint8Array(data)));
|
|
||||||
} else {
|
|
||||||
var
|
|
||||||
str = ""
|
|
||||||
, buf = new Uint8Array(data)
|
|
||||||
, i = 0
|
|
||||||
, buf_len = buf.length
|
|
||||||
;
|
|
||||||
for (; i < buf_len; i++) {
|
|
||||||
str += String.fromCharCode(buf[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (get_class(data) === "Blob" || get_class(data) === "File") {
|
|
||||||
if (FileReaderSync) {
|
|
||||||
var fr = new FileReaderSync;
|
|
||||||
bb.push(fr.readAsBinaryString(data));
|
|
||||||
} else {
|
|
||||||
// async FileReader won't work as BlobBuilder is sync
|
|
||||||
throw new FileException("NOT_READABLE_ERR");
|
|
||||||
}
|
|
||||||
} else if (data instanceof FakeBlob) {
|
|
||||||
if (data.encoding === "base64" && atob) {
|
|
||||||
bb.push(atob(data.data));
|
|
||||||
} else if (data.encoding === "URI") {
|
|
||||||
bb.push(decodeURIComponent(data.data));
|
|
||||||
} else if (data.encoding === "raw") {
|
|
||||||
bb.push(data.data);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (typeof data !== "string") {
|
|
||||||
data += ""; // convert unsupported types to strings
|
|
||||||
}
|
|
||||||
// decode UTF-16 to binary string
|
|
||||||
bb.push(unescape(encodeURIComponent(data)));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
FBB_proto.getBlob = function(type) {
|
|
||||||
if (!arguments.length) {
|
|
||||||
type = null;
|
|
||||||
}
|
|
||||||
return new FakeBlob(this.data.join(""), type, "raw");
|
|
||||||
};
|
|
||||||
FBB_proto.toString = function() {
|
|
||||||
return "[object BlobBuilder]";
|
|
||||||
};
|
|
||||||
FB_proto.slice = function(start, end, type) {
|
|
||||||
var args = arguments.length;
|
|
||||||
if (args < 3) {
|
|
||||||
type = null;
|
|
||||||
}
|
|
||||||
return new FakeBlob(
|
|
||||||
this.data.slice(start, args > 1 ? end : this.data.length)
|
|
||||||
, type
|
|
||||||
, this.encoding
|
|
||||||
);
|
|
||||||
};
|
|
||||||
FB_proto.toString = function() {
|
|
||||||
return "[object Blob]";
|
|
||||||
};
|
|
||||||
return FakeBlobBuilder;
|
|
||||||
}(view));
|
|
||||||
|
|
||||||
return function Blob(blobParts, options) {
|
|
||||||
var type = options ? (options.type || "") : "";
|
|
||||||
var builder = new BlobBuilder();
|
|
||||||
if (blobParts) {
|
|
||||||
for (var i = 0, len = blobParts.length; i < len; i++) {
|
|
||||||
builder.append(blobParts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.getBlob(type);
|
|
||||||
};
|
|
||||||
}(self));
|
|
@ -1,161 +0,0 @@
|
|||||||
/* BlobBuilder.js
|
|
||||||
* A BlobBuilder implementation.
|
|
||||||
* 2012-04-21
|
|
||||||
*
|
|
||||||
* By Eli Grey, http://eligrey.com
|
|
||||||
* License: X11/MIT
|
|
||||||
* See LICENSE.md
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*global self, unescape */
|
|
||||||
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
|
|
||||||
plusplus: true */
|
|
||||||
|
|
||||||
/*! @source http://purl.eligrey.com/github/BlobBuilder.js/blob/master/BlobBuilder.js */
|
|
||||||
|
|
||||||
var BlobBuilder = BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder || (function(view) {
|
|
||||||
"use strict";
|
|
||||||
var
|
|
||||||
get_class = function(object) {
|
|
||||||
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
|
|
||||||
}
|
|
||||||
, FakeBlobBuilder = function(){
|
|
||||||
this.data = [];
|
|
||||||
}
|
|
||||||
, FakeBlob = function(data, type, encoding) {
|
|
||||||
this.data = data;
|
|
||||||
this.size = data.length;
|
|
||||||
this.type = type;
|
|
||||||
this.encoding = encoding;
|
|
||||||
}
|
|
||||||
, FBB_proto = FakeBlobBuilder.prototype
|
|
||||||
, FB_proto = FakeBlob.prototype
|
|
||||||
, FileReaderSync = view.FileReaderSync
|
|
||||||
, FileException = function(type) {
|
|
||||||
this.code = this[this.name = type];
|
|
||||||
}
|
|
||||||
, file_ex_codes = (
|
|
||||||
"NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
|
|
||||||
+ "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
|
|
||||||
).split(" ")
|
|
||||||
, file_ex_code = file_ex_codes.length
|
|
||||||
, real_URL = view.URL || view.webkitURL || view
|
|
||||||
, real_create_object_URL = real_URL.createObjectURL
|
|
||||||
, real_revoke_object_URL = real_URL.revokeObjectURL
|
|
||||||
, URL = real_URL
|
|
||||||
, btoa = view.btoa
|
|
||||||
, atob = view.atob
|
|
||||||
, can_apply_typed_arrays = false
|
|
||||||
, can_apply_typed_arrays_test = function(pass) {
|
|
||||||
can_apply_typed_arrays = !pass;
|
|
||||||
}
|
|
||||||
|
|
||||||
, ArrayBuffer = view.ArrayBuffer
|
|
||||||
, Uint8Array = view.Uint8Array
|
|
||||||
;
|
|
||||||
FakeBlobBuilder.fake = FB_proto.fake = true;
|
|
||||||
while (file_ex_code--) {
|
|
||||||
FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (Uint8Array) {
|
|
||||||
can_apply_typed_arrays_test.apply(0, new Uint8Array(1));
|
|
||||||
}
|
|
||||||
} catch (ex) {}
|
|
||||||
if (!real_URL.createObjectURL) {
|
|
||||||
URL = view.URL = {};
|
|
||||||
}
|
|
||||||
URL.createObjectURL = function(blob) {
|
|
||||||
var
|
|
||||||
type = blob.type
|
|
||||||
, data_URI_header
|
|
||||||
;
|
|
||||||
if (type === null) {
|
|
||||||
type = "application/octet-stream";
|
|
||||||
}
|
|
||||||
if (blob instanceof FakeBlob) {
|
|
||||||
data_URI_header = "data:" + type;
|
|
||||||
if (blob.encoding === "base64") {
|
|
||||||
return data_URI_header + ";base64," + blob.data;
|
|
||||||
} else if (blob.encoding === "URI") {
|
|
||||||
return data_URI_header + "," + decodeURIComponent(blob.data);
|
|
||||||
} if (btoa) {
|
|
||||||
return data_URI_header + ";base64," + btoa(blob.data);
|
|
||||||
} else {
|
|
||||||
return data_URI_header + "," + encodeURIComponent(blob.data);
|
|
||||||
}
|
|
||||||
} else if (real_create_object_URL) {
|
|
||||||
return real_create_object_URL.call(real_URL, blob);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
URL.revokeObjectURL = function(object_URL) {
|
|
||||||
if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
|
|
||||||
real_revoke_object_URL.call(real_URL, object_URL);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
FBB_proto.append = function(data/*, endings*/) {
|
|
||||||
var bb = this.data;
|
|
||||||
// decode data to a binary string
|
|
||||||
if (Uint8Array && data instanceof ArrayBuffer) {
|
|
||||||
if (can_apply_typed_arrays) {
|
|
||||||
bb.push(String.fromCharCode.apply(String, new Uint8Array(data)));
|
|
||||||
} else {
|
|
||||||
var
|
|
||||||
str = ""
|
|
||||||
, buf = new Uint8Array(data)
|
|
||||||
, i = 0
|
|
||||||
, buf_len = buf.length
|
|
||||||
;
|
|
||||||
for (; i < buf_len; i++) {
|
|
||||||
str += String.fromCharCode(buf[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (get_class(data) === "Blob" || get_class(data) === "File") {
|
|
||||||
if (FileReaderSync) {
|
|
||||||
var fr = new FileReaderSync;
|
|
||||||
bb.push(fr.readAsBinaryString(data));
|
|
||||||
} else {
|
|
||||||
// async FileReader won't work as BlobBuilder is sync
|
|
||||||
throw new FileException("NOT_READABLE_ERR");
|
|
||||||
}
|
|
||||||
} else if (data instanceof FakeBlob) {
|
|
||||||
if (data.encoding === "base64" && atob) {
|
|
||||||
bb.push(atob(data.data));
|
|
||||||
} else if (data.encoding === "URI") {
|
|
||||||
bb.push(decodeURIComponent(data.data));
|
|
||||||
} else if (data.encoding === "raw") {
|
|
||||||
bb.push(data.data);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (typeof data !== "string") {
|
|
||||||
data += ""; // convert unsupported types to strings
|
|
||||||
}
|
|
||||||
// decode UTF-16 to binary string
|
|
||||||
bb.push(unescape(encodeURIComponent(data)));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
FBB_proto.getBlob = function(type) {
|
|
||||||
if (!arguments.length) {
|
|
||||||
type = null;
|
|
||||||
}
|
|
||||||
return new FakeBlob(this.data.join(""), type, "raw");
|
|
||||||
};
|
|
||||||
FBB_proto.toString = function() {
|
|
||||||
return "[object BlobBuilder]";
|
|
||||||
};
|
|
||||||
FB_proto.slice = function(start, end, type) {
|
|
||||||
var args = arguments.length;
|
|
||||||
if (args < 3) {
|
|
||||||
type = null;
|
|
||||||
}
|
|
||||||
return new FakeBlob(
|
|
||||||
this.data.slice(start, args > 1 ? end : this.data.length)
|
|
||||||
, type
|
|
||||||
, this.encoding
|
|
||||||
);
|
|
||||||
};
|
|
||||||
FB_proto.toString = function() {
|
|
||||||
return "[object Blob]";
|
|
||||||
};
|
|
||||||
return FakeBlobBuilder;
|
|
||||||
}(self));
|
|
2
js/Blob.js/BlobBuilder.min.js
vendored
2
js/Blob.js/BlobBuilder.min.js
vendored
@ -1,2 +0,0 @@
|
|||||||
/*! @source http://purl.eligrey.com/github/BlobBuilder.js/blob/master/BlobBuilder.js */
|
|
||||||
var BlobBuilder=BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||(function(j){"use strict";var c=function(v){return Object.prototype.toString.call(v).match(/^\[object\s(.*)\]$/)[1]},u=function(){this.data=[]},t=function(x,v,w){this.data=x;this.size=x.length;this.type=v;this.encoding=w},k=u.prototype,s=t.prototype,n=j.FileReaderSync,a=function(v){this.code=this[this.name=v]},l=("NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR").split(" "),r=l.length,o=j.URL||j.webkitURL||j,p=o.createObjectURL,b=o.revokeObjectURL,e=o,i=j.btoa,f=j.atob,m=false,h=function(v){m=!v},d=j.ArrayBuffer,g=j.Uint8Array;u.fake=s.fake=true;while(r--){a.prototype[l[r]]=r+1}try{if(g){h.apply(0,new g(1))}}catch(q){}if(!o.createObjectURL){e=j.URL={}}e.createObjectURL=function(w){var x=w.type,v;if(x===null){x="application/octet-stream"}if(w instanceof t){v="data:"+x;if(w.encoding==="base64"){return v+";base64,"+w.data}else{if(w.encoding==="URI"){return v+","+decodeURIComponent(w.data)}}if(i){return v+";base64,"+i(w.data)}else{return v+","+encodeURIComponent(w.data)}}else{if(real_create_object_url){return real_create_object_url.call(o,w)}}};e.revokeObjectURL=function(v){if(v.substring(0,5)!=="data:"&&real_revoke_object_url){real_revoke_object_url.call(o,v)}};k.append=function(z){var B=this.data;if(g&&z instanceof d){if(m){B.push(String.fromCharCode.apply(String,new g(z)))}else{var A="",w=new g(z),x=0,y=w.length;for(;x<y;x++){A+=String.fromCharCode(w[x])}}}else{if(c(z)==="Blob"||c(z)==="File"){if(n){var v=new n;B.push(v.readAsBinaryString(z))}else{throw new a("NOT_READABLE_ERR")}}else{if(z instanceof t){if(z.encoding==="base64"&&f){B.push(f(z.data))}else{if(z.encoding==="URI"){B.push(decodeURIComponent(z.data))}else{if(z.encoding==="raw"){B.push(z.data)}}}}else{if(typeof z!=="string"){z+=""}B.push(unescape(encodeURIComponent(z)))}}}};k.getBlob=function(v){if(!arguments.length){v=null}return new t(this.data.join(""),v,"raw")};k.toString=function(){return"[object BlobBuilder]"};s.slice=function(y,v,x){var w=arguments.length;if(w<3){x=null}return new t(this.data.slice(y,w>1?v:this.data.length),x,this.encoding)};s.toString=function(){return"[object Blob]"};return u}(self));
|
|
@ -1,30 +0,0 @@
|
|||||||
This software is licensed under the MIT/X11 license.
|
|
||||||
|
|
||||||
MIT/X11 license
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Copyright © 2011 [Eli Grey][1].
|
|
||||||
|
|
||||||
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, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the
|
|
||||||
Software is furnished to do so, 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.
|
|
||||||
|
|
||||||
|
|
||||||
[1]: http://eligrey.com
|
|
@ -1,9 +0,0 @@
|
|||||||
Blob.js
|
|
||||||
==============
|
|
||||||
|
|
||||||
Blob.js implements the W3C [`Blob`][1] interface in browsers that do
|
|
||||||
not natively support it.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
[1]: http://www.w3.org/TR/FileAPI/#blob
|
|
@ -1,182 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2012 chick307 <chick307@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the MIT License.
|
|
||||||
* http://opensource.org/licenses/mit-license
|
|
||||||
*/
|
|
||||||
|
|
||||||
void function(global, callback) {
|
|
||||||
if (typeof module === 'object') {
|
|
||||||
module.exports = callback();
|
|
||||||
} else if (typeof define === 'function') {
|
|
||||||
define(callback);
|
|
||||||
} else {
|
|
||||||
global.adler32cs = callback();
|
|
||||||
}
|
|
||||||
}(this, function() {
|
|
||||||
var _hasArrayBuffer = typeof ArrayBuffer === 'function' &&
|
|
||||||
typeof Uint8Array === 'function';
|
|
||||||
|
|
||||||
var _Buffer = null, _isBuffer = (function() {
|
|
||||||
if (!_hasArrayBuffer)
|
|
||||||
return function _isBuffer() { return false };
|
|
||||||
|
|
||||||
try {
|
|
||||||
var buffer = require('buffer');
|
|
||||||
if (typeof buffer.Buffer === 'function')
|
|
||||||
_Buffer = buffer.Buffer;
|
|
||||||
} catch (error) {}
|
|
||||||
|
|
||||||
return function _isBuffer(value) {
|
|
||||||
return value instanceof ArrayBuffer ||
|
|
||||||
_Buffer !== null && value instanceof _Buffer;
|
|
||||||
};
|
|
||||||
}());
|
|
||||||
|
|
||||||
var _utf8ToBinary = (function() {
|
|
||||||
if (_Buffer !== null) {
|
|
||||||
return function _utf8ToBinary(utf8String) {
|
|
||||||
return new _Buffer(utf8String, 'utf8').toString('binary');
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return function _utf8ToBinary(utf8String) {
|
|
||||||
return unescape(encodeURIComponent(utf8String));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
|
|
||||||
var MOD = 65521;
|
|
||||||
|
|
||||||
var _update = function _update(checksum, binaryString) {
|
|
||||||
var a = checksum & 0xFFFF, b = checksum >>> 16;
|
|
||||||
for (var i = 0, length = binaryString.length; i < length; i++) {
|
|
||||||
a = (a + (binaryString.charCodeAt(i) & 0xFF)) % MOD;
|
|
||||||
b = (b + a) % MOD;
|
|
||||||
}
|
|
||||||
return (b << 16 | a) >>> 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
var _updateUint8Array = function _updateUint8Array(checksum, uint8Array) {
|
|
||||||
var a = checksum & 0xFFFF, b = checksum >>> 16;
|
|
||||||
for (var i = 0, length = uint8Array.length, x; i < length; i++) {
|
|
||||||
a = (a + uint8Array[i]) % MOD;
|
|
||||||
b = (b + a) % MOD;
|
|
||||||
}
|
|
||||||
return (b << 16 | a) >>> 0
|
|
||||||
};
|
|
||||||
|
|
||||||
var exports = {};
|
|
||||||
|
|
||||||
var Adler32 = exports.Adler32 = (function() {
|
|
||||||
var ctor = function Adler32(checksum) {
|
|
||||||
if (!(this instanceof ctor)) {
|
|
||||||
throw new TypeError(
|
|
||||||
'Constructor cannot called be as a function.');
|
|
||||||
}
|
|
||||||
if (!isFinite(checksum = checksum == null ? 1 : +checksum)) {
|
|
||||||
throw new Error(
|
|
||||||
'First arguments needs to be a finite number.');
|
|
||||||
}
|
|
||||||
this.checksum = checksum >>> 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
var proto = ctor.prototype = {};
|
|
||||||
proto.constructor = ctor;
|
|
||||||
|
|
||||||
ctor.from = function(from) {
|
|
||||||
from.prototype = proto;
|
|
||||||
return from;
|
|
||||||
}(function from(binaryString) {
|
|
||||||
if (!(this instanceof ctor)) {
|
|
||||||
throw new TypeError(
|
|
||||||
'Constructor cannot called be as a function.');
|
|
||||||
}
|
|
||||||
if (binaryString == null)
|
|
||||||
throw new Error('First argument needs to be a string.');
|
|
||||||
this.checksum = _update(1, binaryString.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
ctor.fromUtf8 = function(fromUtf8) {
|
|
||||||
fromUtf8.prototype = proto;
|
|
||||||
return fromUtf8;
|
|
||||||
}(function fromUtf8(utf8String) {
|
|
||||||
if (!(this instanceof ctor)) {
|
|
||||||
throw new TypeError(
|
|
||||||
'Constructor cannot called be as a function.');
|
|
||||||
}
|
|
||||||
if (utf8String == null)
|
|
||||||
throw new Error('First argument needs to be a string.');
|
|
||||||
var binaryString = _utf8ToBinary(utf8String.toString());
|
|
||||||
this.checksum = _update(1, binaryString);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (_hasArrayBuffer) {
|
|
||||||
ctor.fromBuffer = function(fromBuffer) {
|
|
||||||
fromBuffer.prototype = proto;
|
|
||||||
return fromBuffer;
|
|
||||||
}(function fromBuffer(buffer) {
|
|
||||||
if (!(this instanceof ctor)) {
|
|
||||||
throw new TypeError(
|
|
||||||
'Constructor cannot called be as a function.');
|
|
||||||
}
|
|
||||||
if (!_isBuffer(buffer))
|
|
||||||
throw new Error('First argument needs to be ArrayBuffer.');
|
|
||||||
var array = new Uint8Array(buffer);
|
|
||||||
return this.checksum = _updateUint8Array(1, array);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
proto.update = function update(binaryString) {
|
|
||||||
if (binaryString == null)
|
|
||||||
throw new Error('First argument needs to be a string.');
|
|
||||||
binaryString = binaryString.toString();
|
|
||||||
return this.checksum = _update(this.checksum, binaryString);
|
|
||||||
};
|
|
||||||
|
|
||||||
proto.updateUtf8 = function updateUtf8(utf8String) {
|
|
||||||
if (utf8String == null)
|
|
||||||
throw new Error('First argument needs to be a string.');
|
|
||||||
var binaryString = _utf8ToBinary(utf8String.toString());
|
|
||||||
return this.checksum = _update(this.checksum, binaryString);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (_hasArrayBuffer) {
|
|
||||||
proto.updateBuffer = function updateBuffer(buffer) {
|
|
||||||
if (!_isBuffer(buffer))
|
|
||||||
throw new Error('First argument needs to be ArrayBuffer.');
|
|
||||||
var array = new Uint8Array(buffer);
|
|
||||||
return this.checksum = _updateUint8Array(this.checksum, array);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
proto.clone = function clone() {
|
|
||||||
return new Adler32(this.checksum);
|
|
||||||
};
|
|
||||||
|
|
||||||
return ctor;
|
|
||||||
}());
|
|
||||||
|
|
||||||
exports.from = function from(binaryString) {
|
|
||||||
if (binaryString == null)
|
|
||||||
throw new Error('First argument needs to be a string.');
|
|
||||||
return _update(1, binaryString.toString());
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.fromUtf8 = function fromUtf8(utf8String) {
|
|
||||||
if (utf8String == null)
|
|
||||||
throw new Error('First argument needs to be a string.');
|
|
||||||
var binaryString = _utf8ToBinary(utf8String.toString());
|
|
||||||
return _update(1, binaryString);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (_hasArrayBuffer) {
|
|
||||||
exports.fromBuffer = function fromBuffer(buffer) {
|
|
||||||
if (!_isBuffer(buffer))
|
|
||||||
throw new Error('First argument need to be ArrayBuffer.');
|
|
||||||
var array = new Uint8Array(buffer);
|
|
||||||
return _updateUint8Array(1, array);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return exports;
|
|
||||||
});
|
|
File diff suppressed because it is too large
Load Diff
@ -1,22 +0,0 @@
|
|||||||
Downloadify: Client Side File Creation
|
|
||||||
JavaScript + Flash Library
|
|
||||||
|
|
||||||
Copyright (c) 2009 Douglas C. Neiner
|
|
||||||
|
|
||||||
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, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, 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.
|
|
@ -1,113 +0,0 @@
|
|||||||
h2. Downloadify: Client Side File Creation
|
|
||||||
|
|
||||||
*_Important! The swf has been compiled for online use only. Testing from the file path (i.e. file:// ) will not work as it will violate the security sandbox._*
|
|
||||||
|
|
||||||
h3. Overview
|
|
||||||
|
|
||||||
This library is a tiny JavaScript + Flash library that allows you to generate files on the fly, in the browser, without server interaction. Web applications that allow you to generate vCards, color palettes, custom code, etc would benefit from using this library. In addition to increasing speed (no round trip to the server) this solution can reduce the database and server load of existing web applications. _This is not a library to 'force download' a file from a server. It does not interact with a server at all._
|
|
||||||
|
|
||||||
h3. Demo
|
|
||||||
|
|
||||||
A "very simple demo is available":http://pixelgraphics.us/downloadify/test.html that lets you supply your own content and filename and test out saving, canceling, and the error functionality when the file is blank.
|
|
||||||
|
|
||||||
For a real world usage, see "Starter for jQuery":http://starter.pixelgraphics.us . To quickly demo the usage, just click "Load Example Data" then click Download. After the initial page load, no further contact is made with the server. Everything happens on the client side.
|
|
||||||
|
|
||||||
h3. Download
|
|
||||||
|
|
||||||
Please download from the "Downloads":http://github.com/dcneiner/Downloadify/downloads section of this project.
|
|
||||||
|
|
||||||
h3. Support
|
|
||||||
|
|
||||||
For support, please use the "Issues":http://github.com/dcneiner/Downloadify/issues section of this project. You can also try to hit me up on "Twitter at @dougneiner":http://twitter.com/dougneiner but I might just ask you to file an issue. :)
|
|
||||||
|
|
||||||
h3. Dependencies
|
|
||||||
|
|
||||||
_The end user must have Flash 10 or higher installed for this plugin to work. As of September 2009, it was at a 93% saturation, so most users should already have it installed._
|
|
||||||
|
|
||||||
Downloadify is only dependent on "SWFObject 2.0":http://code.google.com/p/swfobject/ which is included with the download. It is compatible with any JavaScript framework but has a helper for both jQuery and MooTools. Neither helper will be activatd if Downloadify is inserted prior to including the framework library.
|
|
||||||
|
|
||||||
h3. Usage
|
|
||||||
|
|
||||||
*Any JavaScript framework*:
|
|
||||||
|
|
||||||
<pre>Downloadify.create( id_or_DOM_element, options );</pre>
|
|
||||||
|
|
||||||
*jQuery*:
|
|
||||||
|
|
||||||
<pre>$("#element").downloadify( options );</pre>
|
|
||||||
|
|
||||||
*MooTools:*
|
|
||||||
|
|
||||||
<pre>$("elementid").downloadify( options );</pre>
|
|
||||||
|
|
||||||
h3. Options
|
|
||||||
|
|
||||||
Unless you are using the jQuery plugin included with Downloadify, you must supply all required options with your call to the <tt>Downloadify.create</tt> function.
|
|
||||||
|
|
||||||
*Defaults and Required Options*
|
|
||||||
|
|
||||||
* <tt>swf</tt>: <tt>'media/downloadify.swf'</tt> <span style="color:red">*Required*</span> <br />_Path to the SWF File. Can be relative from the page, or an absolute path._
|
|
||||||
* <tt>downloadImage</tt>: <tt>'images/download.png'</tt> <span style="color:red">*Required*</span> <br />_Path to the Button Image. Can be relative from the page or an absolute path._
|
|
||||||
* <tt>width</tt>: 175 <span style="color:red">*Required*</span> <br />_Width of the button (and the flash movie)_
|
|
||||||
* <tt>height</tt>: 55 <span style="color:red">*Required*</span> <br />_Height of the button. This will be 1/4 the height of the image._
|
|
||||||
* <tt>filename</tt>: <span style="color:red">*Required*</span><br /> _Can be a String or a function callback. If a function, the return value of the function will be used as the filename._
|
|
||||||
* <tt>data</tt>: <span style="color:red">*Required*</span><br /> _Can be a normal String, base64 encoded String, or a function callback. If a function, the return value of the function will be used as the file data._
|
|
||||||
* <tt>dataType</tt>: <tt>'string'</tt><br /> _Must be a String with the value <tt>string</tt> or <tt>base64</tt>. Data paired with the <tt>dataType</tt> of <tt>base64</tt> will be decoded into a <tt>ByteArray</tt> prior to saving._
|
|
||||||
* <tt>transparent</tt>: false <br />_Set this to true to use wmode=transparent on the flash movie._
|
|
||||||
* <tt>append</tt>: false <br />_By default the contents of the targeted DOM element are removed. Set this to true to keep the contents and append the button._
|
|
||||||
|
|
||||||
*Event Callbacks*
|
|
||||||
|
|
||||||
No data is passed into these functions, they are simply called.
|
|
||||||
|
|
||||||
* <tt>onError</tt>: _Called when the Download button is clicked but your <tt>data</tt> callback returns <tt>""</tt>._
|
|
||||||
* <tt>onCancel</tt>: _Called when the Download button is clicked but the user then cancels without saving._
|
|
||||||
* <tt>onComplete</tt>: _Called when the Download button is clicked and the file is saved to the user's computer._
|
|
||||||
|
|
||||||
h3. Setting Up the Image
|
|
||||||
|
|
||||||
Downloadify supports (i.e. requires) three button states with limited support for a fourth. The states are:
|
|
||||||
|
|
||||||
* *Normal*
|
|
||||||
* *Over* ( When the mouse hovers over the button )
|
|
||||||
* *Down* ( When the button is pressed )
|
|
||||||
* *Disabled* ( Limited support, when .disable() is called on the Downloadify.Container object )
|
|
||||||
|
|
||||||
In trying to keep this plugin as simple as possible, all four states are always assumed to be present. You should prepare your button image as a single image the width you want your button, and four times the height of the button. All four states should then live in that one image in the same order as the previous list from top to bottom.
|
|
||||||
|
|
||||||
h3. Potential Issues
|
|
||||||
|
|
||||||
When working with different button images, you may find Flash has cached your image. This is the desired behavior on a live site, but not during development. To get around this, simply supply a ?rev=1 or ?rev=2 etc on the end of your downloadImage url.
|
|
||||||
|
|
||||||
h3. Compiling Notes
|
|
||||||
|
|
||||||
I develop locally using Xcode and the Flex 4 SDK Beta 2. Please do not submit request on how to setup a local testing environment. If you are interested in my Xcode project files, send me a message.
|
|
||||||
|
|
||||||
h3. Developers
|
|
||||||
|
|
||||||
*Core Developer:* "Doug Neiner":http://dougneiner.com
|
|
||||||
|
|
||||||
*Contributors:*
|
|
||||||
|
|
||||||
* "David Walsh":http://davidwalsh.name -- Contributed the MooTools helper
|
|
||||||
|
|
||||||
h3. Change Log
|
|
||||||
|
|
||||||
* *Version 0.2*:
|
|
||||||
** Added support for <tt>base64</tt> via the "as3base64 Library":http://github.com/spjwebster/as3base64
|
|
||||||
** Added <tt>dataType</tt> option
|
|
||||||
** Added MooTools helper (Thanks David!)
|
|
||||||
** Upgraded SWFObject to v2.2
|
|
||||||
* *Original Release:* Version 0.1
|
|
||||||
|
|
||||||
h3. License Information: MIT
|
|
||||||
|
|
||||||
as3base64: "Copyright (c) 2006 Steve Webster":http://github.com/spjwebster/as3base64
|
|
||||||
|
|
||||||
All Downloadify Code: Copyright (c) 2009 Douglas C. Neiner
|
|
||||||
|
|
||||||
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, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 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.
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.4 KiB |
3
js/Downloadify/js/downloadify.min.js
vendored
3
js/Downloadify/js/downloadify.min.js
vendored
@ -1,3 +0,0 @@
|
|||||||
/* Downloadify 0.2 (c) 2009 by Douglas Neiner. Licensed under the MIT license */
|
|
||||||
/* See http://github.com/dcneiner/Downloadify for license and more info */
|
|
||||||
(function(){Downloadify=window.Downloadify={queue:{},uid:new Date().getTime(),getTextForSave:function(a){var b=Downloadify.queue[a];if(b)return b.getData();return""},getFileNameForSave:function(a){var b=Downloadify.queue[a];if(b)return b.getFilename();return""},getDataTypeForSave:function(a){var b=Downloadify.queue[a];if(b)return b.getDataType();return""},saveComplete:function(a){var b=Downloadify.queue[a];if(b)b.complete();return true},saveCancel:function(a){var b=Downloadify.queue[a];if(b)b.cancel();return true},saveError:function(a){var b=Downloadify.queue[a];if(b)b.error();return true},addToQueue:function(a){Downloadify.queue[a.queue_name]=a},getUID:function(a){if(a.id=="")a.id='downloadify_'+Downloadify.uid++;return a.id}};Downloadify.create=function(a,b){var c=(typeof(a)=="string"?document.getElementById(a):a);return new Downloadify.Container(c,b)};Downloadify.Container=function(d,e){var f=this;f.el=d;f.enabled=true;f.dataCallback=null;f.filenameCallback=null;f.data=null;f.filename=null;var g=function(){f.options=e;if(!f.options.append)f.el.innerHTML="";f.flashContainer=document.createElement('span');f.el.appendChild(f.flashContainer);f.queue_name=Downloadify.getUID(f.flashContainer);if(typeof(f.options.filename)==="function")f.filenameCallback=f.options.filename;else if(f.options.filename)f.filename=f.options.filename;if(typeof(f.options.data)==="function")f.dataCallback=f.options.data;else if(f.options.data)f.data=f.options.data;var a={queue_name:f.queue_name,width:f.options.width,height:f.options.height};var b={allowScriptAccess:'always'};var c={id:f.flashContainer.id,name:f.flashContainer.id};if(f.options.enabled===false)f.enabled=false;if(f.options.transparent===true)b.wmode="transparent";if(f.options.downloadImage)a.downloadImage=f.options.downloadImage;swfobject.embedSWF(f.options.swf,f.flashContainer.id,f.options.width,f.options.height,"10",null,a,b,c);Downloadify.addToQueue(f)};f.enable=function(){var a=document.getElementById(f.flashContainer.id);a.setEnabled(true);f.enabled=true};f.disable=function(){var a=document.getElementById(f.flashContainer.id);a.setEnabled(false);f.enabled=false};f.getData=function(){if(!f.enabled)return"";if(f.dataCallback)return f.dataCallback();else if(f.data)return f.data;else return""};f.getFilename=function(){if(f.filenameCallback)return f.filenameCallback();else if(f.filename)return f.filename;else return""};f.getDataType=function(){if(f.options.dataType)return f.options.dataType;return"string"};f.complete=function(){if(typeof(f.options.onComplete)==="function")f.options.onComplete()};f.cancel=function(){if(typeof(f.options.onCancel)==="function")f.options.onCancel()};f.error=function(){if(typeof(f.options.onError)==="function")f.options.onError()};g()};Downloadify.defaultOptions={swf:'media/downloadify.swf',downloadImage:'images/download.png',width:100,height:30,transparent:true,append:false,dataType:"string"}})();if(typeof(jQuery)!="undefined"){(function($){$.fn.downloadify=function(b){return this.each(function(){b=$.extend({},Downloadify.defaultOptions,b);var a=Downloadify.create(this,b);$(this).data('Downloadify',a)})}})(jQuery)};if(typeof(MooTools)!='undefined'){Element.implement({downloadify:function(a){a=$merge(Downloadify.defaultOptions,a);return this.store('Downloadify',Downloadify.create(this,a))}})};
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -1,173 +0,0 @@
|
|||||||
/*
|
|
||||||
Downloadify: Client Side File Creation
|
|
||||||
JavaScript + Flash Library
|
|
||||||
|
|
||||||
Version: 0.2
|
|
||||||
|
|
||||||
Copyright (c) 2009 Douglas C. Neiner
|
|
||||||
|
|
||||||
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, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, 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.
|
|
||||||
*/
|
|
||||||
package {
|
|
||||||
import flash.system.Security;
|
|
||||||
import flash.events.Event;
|
|
||||||
import flash.events.MouseEvent;
|
|
||||||
import flash.net.FileReference;
|
|
||||||
import flash.net.FileFilter;
|
|
||||||
import flash.net.URLRequest;
|
|
||||||
import flash.display.*;
|
|
||||||
import flash.utils.ByteArray;
|
|
||||||
import flash.external.ExternalInterface;
|
|
||||||
import com.dynamicflash.util.Base64;
|
|
||||||
|
|
||||||
[SWF(backgroundColor="#CCCCCC")]
|
|
||||||
[SWF(backgroundAlpha=0)]
|
|
||||||
public class Downloadify extends Sprite {
|
|
||||||
|
|
||||||
private var options:Object,
|
|
||||||
file:FileReference = new FileReference(),
|
|
||||||
queue_name:String = "",
|
|
||||||
|
|
||||||
_width:Number = 0,
|
|
||||||
_height:Number = 0,
|
|
||||||
|
|
||||||
enabled:Boolean = true,
|
|
||||||
over:Boolean = false,
|
|
||||||
down:Boolean = false,
|
|
||||||
|
|
||||||
buttonImage:String = "images/download.png",
|
|
||||||
|
|
||||||
button:Loader;
|
|
||||||
|
|
||||||
public function Downloadify() {
|
|
||||||
Security.allowDomain('*');
|
|
||||||
|
|
||||||
stage.align = StageAlign.TOP_LEFT;
|
|
||||||
stage.scaleMode = StageScaleMode.NO_SCALE;
|
|
||||||
|
|
||||||
options = this.root.loaderInfo.parameters;
|
|
||||||
|
|
||||||
queue_name = options.queue_name.toString();
|
|
||||||
|
|
||||||
_width = options.width;
|
|
||||||
_height = options.height;
|
|
||||||
|
|
||||||
if(options.downloadImage){
|
|
||||||
buttonImage = options.downloadImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
setupDefaultButton();
|
|
||||||
addChild(button);
|
|
||||||
|
|
||||||
this.buttonMode = true;
|
|
||||||
|
|
||||||
this.addEventListener(MouseEvent.CLICK, onMouseClickEvent);
|
|
||||||
this.addEventListener(MouseEvent.ROLL_OVER , onMouseEnter);
|
|
||||||
this.addEventListener(MouseEvent.ROLL_OUT , onMouseLeave);
|
|
||||||
this.addEventListener(MouseEvent.MOUSE_DOWN , onMouseDown);
|
|
||||||
this.addEventListener(MouseEvent.MOUSE_UP , onMouseUp);
|
|
||||||
|
|
||||||
ExternalInterface.addCallback('setEnabled', setEnabled);
|
|
||||||
|
|
||||||
file.addEventListener(Event.COMPLETE, onSaveComplete);
|
|
||||||
file.addEventListener(Event.CANCEL, onSaveCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function setEnabled(isEnabled:Boolean):Boolean {
|
|
||||||
enabled = isEnabled;
|
|
||||||
if(enabled === true){
|
|
||||||
button.y = 0;
|
|
||||||
this.buttonMode = true;
|
|
||||||
} else {
|
|
||||||
button.y = (-3 * _height);
|
|
||||||
this.buttonMode = false;
|
|
||||||
}
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function setupDefaultButton():void {
|
|
||||||
button = new Loader();
|
|
||||||
var urlReq:URLRequest = new URLRequest(buttonImage);
|
|
||||||
button.load(urlReq);
|
|
||||||
button.x = 0;
|
|
||||||
button.y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected function onMouseEnter(event:Event):void {
|
|
||||||
if(enabled === true){
|
|
||||||
if(down === false) button.y = (-1 * _height);
|
|
||||||
over = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected function onMouseLeave(event:Event):void {
|
|
||||||
if(enabled === true){
|
|
||||||
if(down === false) button.y = 0;
|
|
||||||
over = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected function onMouseDown(event:Event):void {
|
|
||||||
if(enabled === true){
|
|
||||||
button.y = button.y = (-2 * _height);
|
|
||||||
down = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected function onMouseUp(event:Event):void {
|
|
||||||
if(enabled === true){
|
|
||||||
if(over === false){
|
|
||||||
button.y = 0;
|
|
||||||
} else {
|
|
||||||
button.y = (-1 * _height);
|
|
||||||
}
|
|
||||||
down = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function onMouseClickEvent(event:Event):void{
|
|
||||||
var theData:String = ExternalInterface.call('Downloadify.getTextForSave',queue_name),
|
|
||||||
filename:String = ExternalInterface.call('Downloadify.getFileNameForSave',queue_name),
|
|
||||||
dataType:String = ExternalInterface.call('Downloadify.getDataTypeForSave',queue_name);
|
|
||||||
|
|
||||||
if (dataType == "string" && theData != "") {
|
|
||||||
file.save(theData, filename);
|
|
||||||
} else if (dataType == "base64" && theData){
|
|
||||||
file.save(Base64.decodeToByteArray(theData), filename);
|
|
||||||
} else {
|
|
||||||
onSaveError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function onSaveComplete(event:Event):void{
|
|
||||||
trace('Save Complete');
|
|
||||||
ExternalInterface.call('Downloadify.saveComplete',queue_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function onSaveCancel(event:Event):void{
|
|
||||||
trace('Save Cancel');
|
|
||||||
ExternalInterface.call('Downloadify.saveCancel',queue_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function onSaveError():void{
|
|
||||||
trace('Save Error');
|
|
||||||
ExternalInterface.call('Downloadify.saveError',queue_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
Base64 - 1.1.0
|
|
||||||
|
|
||||||
Copyright (c) 2006 Steve Webster
|
|
||||||
|
|
||||||
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, distribute, sublicense, and/or sell copies of
|
|
||||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.dynamicflash.util {
|
|
||||||
|
|
||||||
import flash.utils.ByteArray;
|
|
||||||
|
|
||||||
public class Base64 {
|
|
||||||
|
|
||||||
private static const BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
||||||
|
|
||||||
public static const version:String = "1.1.0";
|
|
||||||
|
|
||||||
public static function encode(data:String):String {
|
|
||||||
// Convert string to ByteArray
|
|
||||||
var bytes:ByteArray = new ByteArray();
|
|
||||||
bytes.writeUTFBytes(data);
|
|
||||||
|
|
||||||
// Return encoded ByteArray
|
|
||||||
return encodeByteArray(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function encodeByteArray(data:ByteArray):String {
|
|
||||||
// Initialise output
|
|
||||||
var output:String = "";
|
|
||||||
|
|
||||||
// Create data and output buffers
|
|
||||||
var dataBuffer:Array;
|
|
||||||
var outputBuffer:Array = new Array(4);
|
|
||||||
|
|
||||||
// Rewind ByteArray
|
|
||||||
data.position = 0;
|
|
||||||
|
|
||||||
// while there are still bytes to be processed
|
|
||||||
while (data.bytesAvailable > 0) {
|
|
||||||
// Create new data buffer and populate next 3 bytes from data
|
|
||||||
dataBuffer = new Array();
|
|
||||||
for (var i:uint = 0; i < 3 && data.bytesAvailable > 0; i++) {
|
|
||||||
dataBuffer[i] = data.readUnsignedByte();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to data buffer Base64 character positions and
|
|
||||||
// store in output buffer
|
|
||||||
outputBuffer[0] = (dataBuffer[0] & 0xfc) >> 2;
|
|
||||||
outputBuffer[1] = ((dataBuffer[0] & 0x03) << 4) | ((dataBuffer[1]) >> 4);
|
|
||||||
outputBuffer[2] = ((dataBuffer[1] & 0x0f) << 2) | ((dataBuffer[2]) >> 6);
|
|
||||||
outputBuffer[3] = dataBuffer[2] & 0x3f;
|
|
||||||
|
|
||||||
// If data buffer was short (i.e not 3 characters) then set
|
|
||||||
// end character indexes in data buffer to index of '=' symbol.
|
|
||||||
// This is necessary because Base64 data is always a multiple of
|
|
||||||
// 4 bytes and is basses with '=' symbols.
|
|
||||||
for (var j:uint = dataBuffer.length; j < 3; j++) {
|
|
||||||
outputBuffer[j + 1] = 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through output buffer and add Base64 characters to
|
|
||||||
// encoded data string for each character.
|
|
||||||
for (var k:uint = 0; k < outputBuffer.length; k++) {
|
|
||||||
output += BASE64_CHARS.charAt(outputBuffer[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return encoded data
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function decode(data:String):String {
|
|
||||||
// Decode data to ByteArray
|
|
||||||
var bytes:ByteArray = decodeToByteArray(data);
|
|
||||||
|
|
||||||
// Convert to string and return
|
|
||||||
return bytes.readUTFBytes(bytes.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function decodeToByteArray(data:String):ByteArray {
|
|
||||||
// Initialise output ByteArray for decoded data
|
|
||||||
var output:ByteArray = new ByteArray();
|
|
||||||
|
|
||||||
// Create data and output buffers
|
|
||||||
var dataBuffer:Array = new Array(4);
|
|
||||||
var outputBuffer:Array = new Array(3);
|
|
||||||
|
|
||||||
// While there are data bytes left to be processed
|
|
||||||
for (var i:uint = 0; i < data.length; i += 4) {
|
|
||||||
// Populate data buffer with position of Base64 characters for
|
|
||||||
// next 4 bytes from encoded data
|
|
||||||
for (var j:uint = 0; j < 4 && i + j < data.length; j++) {
|
|
||||||
dataBuffer[j] = BASE64_CHARS.indexOf(data.charAt(i + j));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode data buffer back into bytes
|
|
||||||
outputBuffer[0] = (dataBuffer[0] << 2) + ((dataBuffer[1] & 0x30) >> 4);
|
|
||||||
outputBuffer[1] = ((dataBuffer[1] & 0x0f) << 4) + ((dataBuffer[2] & 0x3c) >> 2);
|
|
||||||
outputBuffer[2] = ((dataBuffer[2] & 0x03) << 6) + dataBuffer[3];
|
|
||||||
|
|
||||||
// Add all non-padded bytes in output buffer to decoded data
|
|
||||||
for (var k:uint = 0; k < outputBuffer.length; k++) {
|
|
||||||
if (dataBuffer[k+1] == 64) break;
|
|
||||||
output.writeByte(outputBuffer[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rewind decoded data ByteArray
|
|
||||||
output.position = 0;
|
|
||||||
|
|
||||||
// Return decoded data
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Base64() {
|
|
||||||
throw new Error("Base64 class is static container only");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2006 Steve Webster
|
|
||||||
|
|
||||||
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, distribute, sublicense, and/or sell copies of
|
|
||||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.dynamicflash.util.tests {
|
|
||||||
|
|
||||||
import flexunit.framework.TestCase;
|
|
||||||
import flexunit.framework.TestSuite;
|
|
||||||
import flash.utils.ByteArray;
|
|
||||||
|
|
||||||
import com.dynamicflash.util.Base64;
|
|
||||||
|
|
||||||
public class Base64Test extends TestCase {
|
|
||||||
|
|
||||||
public function Base64Test(methodName:String = null) {
|
|
||||||
super(methodName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testEncode():void {
|
|
||||||
assertEquals("VGhpcyBpcyBhIHRlc3Q=",Base64.encode("This is a test"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testEncodeDecodeBytes():void {
|
|
||||||
var obj:Object = {name:"Dynamic Flash", url:"http://dynamicflash.com"};
|
|
||||||
var source:ByteArray = new ByteArray();
|
|
||||||
source.writeObject(obj);
|
|
||||||
var encoded:String = Base64.encodeByteArray(source);
|
|
||||||
var decoded:ByteArray = Base64.decodeToByteArray(encoded);
|
|
||||||
var obj2:Object = decoded.readObject();
|
|
||||||
assertEquals(obj.name, obj2.name);
|
|
||||||
assertEquals(obj.url, obj2.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDecode():void {
|
|
||||||
assertEquals("This is a test",Base64.decode("VGhpcyBpcyBhIHRlc3Q="));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testEncodeDecode():void {
|
|
||||||
var string:String = "The quick brown fox jumped over the lazy dogs";
|
|
||||||
assertEquals(string, Base64.decode(Base64.encode(string)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,213 +0,0 @@
|
|||||||
/*
|
|
||||||
Downloadify: Client Side File Creation
|
|
||||||
JavaScript + Flash Library
|
|
||||||
|
|
||||||
Version: 0.2
|
|
||||||
|
|
||||||
Copyright (c) 2009 Douglas C. Neiner
|
|
||||||
|
|
||||||
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, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, 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(){
|
|
||||||
Downloadify = window.Downloadify = {
|
|
||||||
queue: {},
|
|
||||||
uid: new Date().getTime(),
|
|
||||||
getTextForSave: function(queue){
|
|
||||||
var obj = Downloadify.queue[queue];
|
|
||||||
if(obj) return obj.getData();
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
getFileNameForSave: function(queue){
|
|
||||||
var obj = Downloadify.queue[queue];
|
|
||||||
if(obj) return obj.getFilename();
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
getDataTypeForSave: function(queue){
|
|
||||||
var obj = Downloadify.queue[queue];
|
|
||||||
if(obj) return obj.getDataType();
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
saveComplete: function(queue){
|
|
||||||
var obj = Downloadify.queue[queue];
|
|
||||||
if(obj) obj.complete();
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
saveCancel: function(queue){
|
|
||||||
var obj = Downloadify.queue[queue];
|
|
||||||
if(obj) obj.cancel();
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
saveError: function(queue){
|
|
||||||
var obj = Downloadify.queue[queue];
|
|
||||||
if(obj) obj.error();
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
addToQueue: function(container){
|
|
||||||
Downloadify.queue[container.queue_name] = container;
|
|
||||||
},
|
|
||||||
// Concept adapted from: http://tinyurl.com/yzsyfto
|
|
||||||
// SWF object runs off of ID's, so this is the good way to get a unique ID
|
|
||||||
getUID: function(el){
|
|
||||||
if(el.id == "") el.id = 'downloadify_' + Downloadify.uid++;
|
|
||||||
return el.id;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Downloadify.create = function( idOrDOM, options ){
|
|
||||||
var el = (typeof(idOrDOM) == "string" ? document.getElementById(idOrDOM) : idOrDOM );
|
|
||||||
return new Downloadify.Container(el, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
Downloadify.Container = function(el, options){
|
|
||||||
var base = this;
|
|
||||||
|
|
||||||
base.el = el;
|
|
||||||
base.enabled = true;
|
|
||||||
base.dataCallback = null;
|
|
||||||
base.filenameCallback = null;
|
|
||||||
base.data = null;
|
|
||||||
base.filename = null;
|
|
||||||
|
|
||||||
var init = function(){
|
|
||||||
base.options = options;
|
|
||||||
|
|
||||||
if( !base.options.append ) base.el.innerHTML = "";
|
|
||||||
|
|
||||||
base.flashContainer = document.createElement('span');
|
|
||||||
base.el.appendChild(base.flashContainer);
|
|
||||||
|
|
||||||
base.queue_name = Downloadify.getUID( base.flashContainer );
|
|
||||||
|
|
||||||
if( typeof(base.options.filename) === "function" )
|
|
||||||
base.filenameCallback = base.options.filename;
|
|
||||||
else if (base.options.filename)
|
|
||||||
base.filename = base.options.filename;
|
|
||||||
|
|
||||||
if( typeof(base.options.data) === "function" )
|
|
||||||
base.dataCallback = base.options.data;
|
|
||||||
else if (base.options.data)
|
|
||||||
base.data = base.options.data;
|
|
||||||
|
|
||||||
|
|
||||||
var flashVars = {
|
|
||||||
queue_name: base.queue_name,
|
|
||||||
width: base.options.width,
|
|
||||||
height: base.options.height
|
|
||||||
};
|
|
||||||
|
|
||||||
var params = {
|
|
||||||
allowScriptAccess: 'always'
|
|
||||||
};
|
|
||||||
|
|
||||||
var attributes = {
|
|
||||||
id: base.flashContainer.id,
|
|
||||||
name: base.flashContainer.id
|
|
||||||
};
|
|
||||||
|
|
||||||
if(base.options.enabled === false) base.enabled = false;
|
|
||||||
|
|
||||||
if(base.options.transparent === true) params.wmode = "transparent";
|
|
||||||
|
|
||||||
if(base.options.downloadImage) flashVars.downloadImage = base.options.downloadImage;
|
|
||||||
|
|
||||||
swfobject.embedSWF(base.options.swf, base.flashContainer.id, base.options.width, base.options.height, "10", null, flashVars, params, attributes );
|
|
||||||
|
|
||||||
Downloadify.addToQueue( base );
|
|
||||||
};
|
|
||||||
|
|
||||||
base.enable = function(){
|
|
||||||
var swf = document.getElementById(base.flashContainer.id);
|
|
||||||
swf.setEnabled(true);
|
|
||||||
base.enabled = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
base.disable = function(){
|
|
||||||
var swf = document.getElementById(base.flashContainer.id);
|
|
||||||
swf.setEnabled(false);
|
|
||||||
base.enabled = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
base.getData = function(){
|
|
||||||
if( !base.enabled ) return "";
|
|
||||||
if( base.dataCallback ) return base.dataCallback();
|
|
||||||
else if (base.data) return base.data;
|
|
||||||
else return "";
|
|
||||||
};
|
|
||||||
|
|
||||||
base.getFilename = function(){
|
|
||||||
if( base.filenameCallback ) return base.filenameCallback();
|
|
||||||
else if (base.filename) return base.filename;
|
|
||||||
else return "";
|
|
||||||
};
|
|
||||||
|
|
||||||
base.getDataType = function(){
|
|
||||||
if (base.options.dataType) return base.options.dataType;
|
|
||||||
return "string";
|
|
||||||
};
|
|
||||||
|
|
||||||
base.complete = function(){
|
|
||||||
if( typeof(base.options.onComplete) === "function" ) base.options.onComplete();
|
|
||||||
};
|
|
||||||
|
|
||||||
base.cancel = function(){
|
|
||||||
if( typeof(base.options.onCancel) === "function" ) base.options.onCancel();
|
|
||||||
};
|
|
||||||
|
|
||||||
base.error = function(){
|
|
||||||
if( typeof(base.options.onError) === "function" ) base.options.onError();
|
|
||||||
};
|
|
||||||
|
|
||||||
init();
|
|
||||||
};
|
|
||||||
|
|
||||||
Downloadify.defaultOptions = {
|
|
||||||
swf: 'media/downloadify.swf',
|
|
||||||
downloadImage: 'images/download.png',
|
|
||||||
width: 100,
|
|
||||||
height: 30,
|
|
||||||
transparent: true,
|
|
||||||
append: false,
|
|
||||||
dataType: "string"
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
// Support for jQuery
|
|
||||||
if(typeof(jQuery) != "undefined"){
|
|
||||||
(function($){
|
|
||||||
$.fn.downloadify = function(options){
|
|
||||||
return this.each(function(){
|
|
||||||
options = $.extend({}, Downloadify.defaultOptions, options);
|
|
||||||
var dl = Downloadify.create( this, options);
|
|
||||||
$(this).data('Downloadify', dl);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
})(jQuery);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* mootools helper */
|
|
||||||
if(typeof(MooTools) != 'undefined'){
|
|
||||||
Element.implement({
|
|
||||||
downloadify: function(options) {
|
|
||||||
options = $merge(Downloadify.defaultOptions,options);
|
|
||||||
return this.store('Downloadify',Downloadify.create(this,options));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Downloadify</title>
|
|
||||||
<style type="text/css" media="screen">
|
|
||||||
body {background: #fff; width: 500px; margin: 20px auto;}
|
|
||||||
label, input, textarea, h1, h2, p { font-family: Arial, sans-serif; font-size: 12pt;}
|
|
||||||
input, textarea { border: solid 1px #aaa; padding: 4px; width: 98%;}
|
|
||||||
label { font-weight: bold;}
|
|
||||||
h1 { font-size: 30pt; font-weight: bold; letter-spacing: -1px;}
|
|
||||||
h2 { font-size: 14pt;}
|
|
||||||
pre { overflow: auto; padding: 10px; background: #222; color: #ccc;}
|
|
||||||
</style>
|
|
||||||
<script type="text/javascript" src="js/swfobject.js"></script>
|
|
||||||
<script type="text/javascript" src="js/downloadify.min.js"></script>
|
|
||||||
</head>
|
|
||||||
<body onload="load();">
|
|
||||||
<h1>Downloadify Example</h1>
|
|
||||||
<p>More info available at the <a href="http://github.com/dcneiner/Downloadify">Github Project Page</a></p>
|
|
||||||
<form>
|
|
||||||
<p>
|
|
||||||
<label for="filename">Filename</label><br />
|
|
||||||
<input type="text" name="filename" value="testfile.txt" id="filename" />
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<label for="data">File Contents</label><br />
|
|
||||||
<textarea cols="60" rows="10" name="data" id="data">
|
|
||||||
Whatever you put in this text box will be downloaded and saved in the file. If you leave it blank, no file will be downloaded</textarea>
|
|
||||||
</p>
|
|
||||||
<p id="downloadify">
|
|
||||||
You must have Flash 10 installed to download this file.
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
function load(){
|
|
||||||
Downloadify.create('downloadify',{
|
|
||||||
filename: function(){
|
|
||||||
return document.getElementById('filename').value;
|
|
||||||
},
|
|
||||||
data: function(){
|
|
||||||
return document.getElementById('data').value;
|
|
||||||
},
|
|
||||||
onComplete: function(){ alert('Your File Has Been Saved!'); },
|
|
||||||
onCancel: function(){ alert('You have cancelled the saving of this file.'); },
|
|
||||||
onError: function(){ alert('You must put something in the File Contents or there will be nothing to save!'); },
|
|
||||||
swf: 'media/downloadify.swf',
|
|
||||||
downloadImage: 'images/download.png',
|
|
||||||
width: 100,
|
|
||||||
height: 30,
|
|
||||||
transparent: true,
|
|
||||||
append: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<h2>Downloadify Invoke Script For This Page</h2>
|
|
||||||
<pre>
|
|
||||||
Downloadify.create('downloadify',{
|
|
||||||
filename: function(){
|
|
||||||
return document.getElementById('filename').value;
|
|
||||||
},
|
|
||||||
data: function(){
|
|
||||||
return document.getElementById('data').value;
|
|
||||||
},
|
|
||||||
onComplete: function(){
|
|
||||||
alert('Your File Has Been Saved!');
|
|
||||||
},
|
|
||||||
onCancel: function(){
|
|
||||||
alert('You have cancelled the saving of this file.');
|
|
||||||
},
|
|
||||||
onError: function(){
|
|
||||||
alert('You must put something in the File Contents or there will be nothing to save!');
|
|
||||||
},
|
|
||||||
swf: 'media/downloadify.swf',
|
|
||||||
downloadImage: 'images/download.png',
|
|
||||||
width: 100,
|
|
||||||
height: 30,
|
|
||||||
transparent: true,
|
|
||||||
append: false
|
|
||||||
});
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,217 +0,0 @@
|
|||||||
/* FileSaver.js
|
|
||||||
* A saveAs() FileSaver implementation.
|
|
||||||
* 2013-01-23
|
|
||||||
*
|
|
||||||
* By Eli Grey, http://eligrey.com
|
|
||||||
* License: X11/MIT
|
|
||||||
* See LICENSE.md
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*global self */
|
|
||||||
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
|
|
||||||
plusplus: true */
|
|
||||||
|
|
||||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
|
||||||
|
|
||||||
var saveAs = saveAs
|
|
||||||
|| (navigator.msSaveBlob && navigator.msSaveBlob.bind(navigator))
|
|
||||||
|| (function(view) {
|
|
||||||
"use strict";
|
|
||||||
var
|
|
||||||
doc = view.document
|
|
||||||
// only get URL when necessary in case BlobBuilder.js hasn't overridden it yet
|
|
||||||
, get_URL = function() {
|
|
||||||
return view.URL || view.webkitURL || view;
|
|
||||||
}
|
|
||||||
, URL = view.URL || view.webkitURL || view
|
|
||||||
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
|
|
||||||
, can_use_save_link = "download" in save_link
|
|
||||||
, click = function(node) {
|
|
||||||
var event = doc.createEvent("MouseEvents");
|
|
||||||
event.initMouseEvent(
|
|
||||||
"click", true, false, view, 0, 0, 0, 0, 0
|
|
||||||
, false, false, false, false, 0, null
|
|
||||||
);
|
|
||||||
return node.dispatchEvent(event); // false if event was cancelled
|
|
||||||
}
|
|
||||||
, webkit_req_fs = view.webkitRequestFileSystem
|
|
||||||
, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
|
|
||||||
, throw_outside = function (ex) {
|
|
||||||
(view.setImmediate || view.setTimeout)(function() {
|
|
||||||
throw ex;
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
, force_saveable_type = "application/octet-stream"
|
|
||||||
, fs_min_size = 0
|
|
||||||
, deletion_queue = []
|
|
||||||
, process_deletion_queue = function() {
|
|
||||||
var i = deletion_queue.length;
|
|
||||||
while (i--) {
|
|
||||||
var file = deletion_queue[i];
|
|
||||||
if (typeof file === "string") { // file is an object URL
|
|
||||||
URL.revokeObjectURL(file);
|
|
||||||
} else { // file is a File
|
|
||||||
file.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deletion_queue.length = 0; // clear queue
|
|
||||||
}
|
|
||||||
, dispatch = function(filesaver, event_types, event) {
|
|
||||||
event_types = [].concat(event_types);
|
|
||||||
var i = event_types.length;
|
|
||||||
while (i--) {
|
|
||||||
var listener = filesaver["on" + event_types[i]];
|
|
||||||
if (typeof listener === "function") {
|
|
||||||
try {
|
|
||||||
listener.call(filesaver, event || filesaver);
|
|
||||||
} catch (ex) {
|
|
||||||
throw_outside(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
, FileSaver = function(blob, name) {
|
|
||||||
// First try a.download, then web filesystem, then object URLs
|
|
||||||
var
|
|
||||||
filesaver = this
|
|
||||||
, type = blob.type
|
|
||||||
, blob_changed = false
|
|
||||||
, object_url
|
|
||||||
, target_view
|
|
||||||
, get_object_url = function() {
|
|
||||||
var object_url = get_URL().createObjectURL(blob);
|
|
||||||
deletion_queue.push(object_url);
|
|
||||||
return object_url;
|
|
||||||
}
|
|
||||||
, dispatch_all = function() {
|
|
||||||
dispatch(filesaver, "writestart progress write writeend".split(" "));
|
|
||||||
}
|
|
||||||
// on any filesys errors revert to saving with object URLs
|
|
||||||
, fs_error = function() {
|
|
||||||
// don't create more object URLs than needed
|
|
||||||
if (blob_changed || !object_url) {
|
|
||||||
object_url = get_object_url(blob);
|
|
||||||
}
|
|
||||||
if (target_view) {
|
|
||||||
target_view.location.href = object_url;
|
|
||||||
}
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
dispatch_all();
|
|
||||||
}
|
|
||||||
, abortable = function(func) {
|
|
||||||
return function() {
|
|
||||||
if (filesaver.readyState !== filesaver.DONE) {
|
|
||||||
return func.apply(this, arguments);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
, create_if_not_found = {create: true, exclusive: false}
|
|
||||||
, slice
|
|
||||||
;
|
|
||||||
filesaver.readyState = filesaver.INIT;
|
|
||||||
if (!name) {
|
|
||||||
name = "download";
|
|
||||||
}
|
|
||||||
if (can_use_save_link) {
|
|
||||||
object_url = get_object_url(blob);
|
|
||||||
save_link.href = object_url;
|
|
||||||
save_link.download = name;
|
|
||||||
if (click(save_link)) {
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
dispatch_all();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Object and web filesystem URLs have a problem saving in Google Chrome when
|
|
||||||
// viewed in a tab, so I force save with application/octet-stream
|
|
||||||
// http://code.google.com/p/chromium/issues/detail?id=91158
|
|
||||||
if (view.chrome && type && type !== force_saveable_type) {
|
|
||||||
slice = blob.slice || blob.webkitSlice;
|
|
||||||
blob = slice.call(blob, 0, blob.size, force_saveable_type);
|
|
||||||
blob_changed = true;
|
|
||||||
}
|
|
||||||
// Since I can't be sure that the guessed media type will trigger a download
|
|
||||||
// in WebKit, I append .download to the filename.
|
|
||||||
// https://bugs.webkit.org/show_bug.cgi?id=65440
|
|
||||||
if (webkit_req_fs && name !== "download") {
|
|
||||||
name += ".download";
|
|
||||||
}
|
|
||||||
if (type === force_saveable_type || webkit_req_fs) {
|
|
||||||
target_view = view;
|
|
||||||
} else {
|
|
||||||
target_view = view.open();
|
|
||||||
}
|
|
||||||
if (!req_fs) {
|
|
||||||
fs_error();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fs_min_size += blob.size;
|
|
||||||
req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
|
|
||||||
fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
|
|
||||||
var save = function() {
|
|
||||||
dir.getFile(name, create_if_not_found, abortable(function(file) {
|
|
||||||
file.createWriter(abortable(function(writer) {
|
|
||||||
writer.onwriteend = function(event) {
|
|
||||||
target_view.location.href = file.toURL();
|
|
||||||
deletion_queue.push(file);
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
dispatch(filesaver, "writeend", event);
|
|
||||||
};
|
|
||||||
writer.onerror = function() {
|
|
||||||
var error = writer.error;
|
|
||||||
if (error.code !== error.ABORT_ERR) {
|
|
||||||
fs_error();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
"writestart progress write abort".split(" ").forEach(function(event) {
|
|
||||||
writer["on" + event] = filesaver["on" + event];
|
|
||||||
});
|
|
||||||
writer.write(blob);
|
|
||||||
filesaver.abort = function() {
|
|
||||||
writer.abort();
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
};
|
|
||||||
filesaver.readyState = filesaver.WRITING;
|
|
||||||
}), fs_error);
|
|
||||||
}), fs_error);
|
|
||||||
};
|
|
||||||
dir.getFile(name, {create: false}, abortable(function(file) {
|
|
||||||
// delete file if it already exists
|
|
||||||
file.remove();
|
|
||||||
save();
|
|
||||||
}), abortable(function(ex) {
|
|
||||||
if (ex.code === ex.NOT_FOUND_ERR) {
|
|
||||||
save();
|
|
||||||
} else {
|
|
||||||
fs_error();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}), fs_error);
|
|
||||||
}), fs_error);
|
|
||||||
}
|
|
||||||
, FS_proto = FileSaver.prototype
|
|
||||||
, saveAs = function(blob, name) {
|
|
||||||
return new FileSaver(blob, name);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
FS_proto.abort = function() {
|
|
||||||
var filesaver = this;
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
dispatch(filesaver, "abort");
|
|
||||||
};
|
|
||||||
FS_proto.readyState = FS_proto.INIT = 0;
|
|
||||||
FS_proto.WRITING = 1;
|
|
||||||
FS_proto.DONE = 2;
|
|
||||||
|
|
||||||
FS_proto.error =
|
|
||||||
FS_proto.onwritestart =
|
|
||||||
FS_proto.onprogress =
|
|
||||||
FS_proto.onwrite =
|
|
||||||
FS_proto.onabort =
|
|
||||||
FS_proto.onerror =
|
|
||||||
FS_proto.onwriteend =
|
|
||||||
null;
|
|
||||||
|
|
||||||
view.addEventListener("unload", process_deletion_queue, false);
|
|
||||||
return saveAs;
|
|
||||||
}(self));
|
|
2
js/FileSaver.js/FileSaver.min.js
vendored
2
js/FileSaver.js/FileSaver.min.js
vendored
@ -1,2 +0,0 @@
|
|||||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
|
||||||
var saveAs=saveAs||navigator.msSaveBlob&&navigator.msSaveBlob.bind(navigator)||function(a){"use strict";var b=a.document,c=function(){return a.URL||a.webkitURL||a},d=a.URL||a.webkitURL||a,e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),f="download"in e,g=function(c){var d=b.createEvent("MouseEvents");return d.initMouseEvent("click",!0,!1,a,0,0,0,0,0,!1,!1,!1,!1,0,null),c.dispatchEvent(d)},h=a.webkitRequestFileSystem,i=a.requestFileSystem||h||a.mozRequestFileSystem,j=function(b){(a.setImmediate||a.setTimeout)(function(){throw b},0)},k="application/octet-stream",l=0,m=[],n=function(){for(var a=m.length;a--;){var b=m[a];"string"==typeof b?d.revokeObjectURL(b):b.remove()}m.length=0},o=function(a,b,c){b=[].concat(b);for(var d=b.length;d--;){var e=a["on"+b[d]];if("function"==typeof e)try{e.call(a,c||a)}catch(f){j(f)}}},p=function(b,d){var q,r,x,j=this,n=b.type,p=!1,s=function(){var a=c().createObjectURL(b);return m.push(a),a},t=function(){o(j,"writestart progress write writeend".split(" "))},u=function(){(p||!q)&&(q=s(b)),r&&(r.location.href=q),j.readyState=j.DONE,t()},v=function(a){return function(){return j.readyState!==j.DONE?a.apply(this,arguments):void 0}},w={create:!0,exclusive:!1};return j.readyState=j.INIT,d||(d="download"),f&&(q=s(b),e.href=q,e.download=d,g(e))?(j.readyState=j.DONE,t(),void 0):(a.chrome&&n&&n!==k&&(x=b.slice||b.webkitSlice,b=x.call(b,0,b.size,k),p=!0),h&&"download"!==d&&(d+=".download"),r=n===k||h?a:a.open(),i?(l+=b.size,i(a.TEMPORARY,l,v(function(a){a.root.getDirectory("saved",w,v(function(a){var c=function(){a.getFile(d,w,v(function(a){a.createWriter(v(function(c){c.onwriteend=function(b){r.location.href=a.toURL(),m.push(a),j.readyState=j.DONE,o(j,"writeend",b)},c.onerror=function(){var a=c.error;a.code!==a.ABORT_ERR&&u()},"writestart progress write abort".split(" ").forEach(function(a){c["on"+a]=j["on"+a]}),c.write(b),j.abort=function(){c.abort(),j.readyState=j.DONE},j.readyState=j.WRITING}),u)}),u)};a.getFile(d,{create:!1},v(function(a){a.remove(),c()}),v(function(a){a.code===a.NOT_FOUND_ERR?c():u()}))}),u)}),u),void 0):(u(),void 0))},q=p.prototype,r=function(a,b){return new p(a,b)};return q.abort=function(){var a=this;a.readyState=a.DONE,o(a,"abort")},q.readyState=q.INIT=0,q.WRITING=1,q.DONE=2,q.error=q.onwritestart=q.onprogress=q.onwrite=q.onabort=q.onerror=q.onwriteend=null,a.addEventListener("unload",n,!1),r}(self);
|
|
@ -1,30 +0,0 @@
|
|||||||
This software is licensed under the MIT/X11 license.
|
|
||||||
|
|
||||||
MIT/X11 license
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Copyright © 2011 [Eli Grey][1].
|
|
||||||
|
|
||||||
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, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the
|
|
||||||
Software is furnished to do so, 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.
|
|
||||||
|
|
||||||
|
|
||||||
[1]: http://eligrey.com
|
|
@ -1,69 +0,0 @@
|
|||||||
FileSaver.js
|
|
||||||
============
|
|
||||||
|
|
||||||
FileSaver.js implements the W3C `saveAs()` [FileSaver][1] interface in browsers that do
|
|
||||||
not natively support it. There is a [FileSaver.js demo][2] that demonstrates saving
|
|
||||||
various media types.
|
|
||||||
|
|
||||||
FileSaver.js is the solution to saving files on the client side, and is perfect for
|
|
||||||
webapps that need to generate files or for saving sensitive information that shouldn't be
|
|
||||||
sent to an external server.
|
|
||||||
|
|
||||||
Supported Browsers
|
|
||||||
------------------
|
|
||||||
|
|
||||||
* Internet Explorer 10+
|
|
||||||
* Firefox 4+
|
|
||||||
* Google Chrome
|
|
||||||
* Opera 11+
|
|
||||||
* Safari 5+
|
|
||||||
|
|
||||||
Unlisted versions of browsers (e.g. Firefox 3.6) will probably work too; I just haven't
|
|
||||||
tested them.
|
|
||||||
|
|
||||||
Syntax
|
|
||||||
------
|
|
||||||
|
|
||||||
FileSaver saveAs(in Blob data, in DOMString filename)
|
|
||||||
|
|
||||||
Examples
|
|
||||||
--------
|
|
||||||
|
|
||||||
### Saving text
|
|
||||||
|
|
||||||
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
|
||||||
saveAs(blob, "hello world.txt");
|
|
||||||
|
|
||||||
The standard W3C File API [`Blob`][3] interface is not available in all browsers.
|
|
||||||
[Blob.js][4] is a cross-browser `BlobBuilder` implementation that solves this.
|
|
||||||
|
|
||||||
### Saving a canvas
|
|
||||||
|
|
||||||
var canvas = document.getElementById("my-canvas"), ctx = canvas.getContext("2d");
|
|
||||||
// draw to canvas...
|
|
||||||
canvas.toBlob(function(blob) {
|
|
||||||
saveAs(blob, "pretty image.png");
|
|
||||||
});
|
|
||||||
|
|
||||||
Note: The standard HTML5 `canvas.toBlob()` method is not available in all browsers.
|
|
||||||
[canvas-toBlob.js][5] is a cross-browser `canvas.toBlob()` implementation that solves
|
|
||||||
this.
|
|
||||||
|
|
||||||
### Aborting a save
|
|
||||||
|
|
||||||
var filesaver = saveAs(blob, "whatever");
|
|
||||||
cancel_button.addEventListener("click", function() {
|
|
||||||
if (filesaver.abort) {
|
|
||||||
filesaver.abort();
|
|
||||||
}
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
This isn't that useful unless you're saving very large files (e.g. generated video).
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
[1]: http://www.w3.org/TR/file-writer-api/#the-filesaver-interface
|
|
||||||
[2]: http://oftn.org/projects/FileSaver.js/demo/
|
|
||||||
[3]: https://developer.mozilla.org/en-US/docs/DOM/Blob
|
|
||||||
[4]: https://github.com/eligrey/Blob.js
|
|
||||||
[5]: https://github.com/eligrey/canvas-toBlob.js
|
|
@ -1,55 +0,0 @@
|
|||||||
html {
|
|
||||||
background-color: #DDD;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
width: 900px;
|
|
||||||
margin: 0 auto;
|
|
||||||
font-family: Verdana, Helvetica, Arial, sans-serif;
|
|
||||||
box-shadow: 0 0 5px #000;
|
|
||||||
box-shadow: 0 0 10px 2px rgba(0, 0, 0, .5);
|
|
||||||
padding: 7px 25px;
|
|
||||||
background-color: #FFF;
|
|
||||||
}
|
|
||||||
h1, h2, h3, h4, h5, h6 {
|
|
||||||
font-family: Georgia, "Times New Roman", serif;
|
|
||||||
}
|
|
||||||
h2, form {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
form {
|
|
||||||
margin-top: 5px;
|
|
||||||
}
|
|
||||||
.input {
|
|
||||||
width: 500px;
|
|
||||||
height: 300px;
|
|
||||||
margin: 0 auto;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
section {
|
|
||||||
margin-top: 40px;
|
|
||||||
}
|
|
||||||
dt {
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: larger;
|
|
||||||
}
|
|
||||||
#canvas {
|
|
||||||
cursor: crosshair;
|
|
||||||
}
|
|
||||||
#canvas, #html {
|
|
||||||
border: 1px solid black;
|
|
||||||
}
|
|
||||||
.filename {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
#html {
|
|
||||||
box-sizing: border-box;
|
|
||||||
ms-box-sizing: border-box;
|
|
||||||
webkit-box-sizing: border-box;
|
|
||||||
moz-box-sizing: border-box;
|
|
||||||
overflow: auto;
|
|
||||||
padding: 1em;
|
|
||||||
}
|
|
||||||
dt:target {
|
|
||||||
background-color: Highlight;
|
|
||||||
color: HighlightText;
|
|
||||||
}
|
|
@ -1,212 +0,0 @@
|
|||||||
/* FileSaver.js demo script
|
|
||||||
* 2012-01-23
|
|
||||||
*
|
|
||||||
* By Eli Grey, http://eligrey.com
|
|
||||||
* License: X11/MIT
|
|
||||||
* See LICENSE.md
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/demo/demo.js */
|
|
||||||
|
|
||||||
(function(view) {
|
|
||||||
"use strict";
|
|
||||||
// The canvas drawing portion of the demo is based off the demo at
|
|
||||||
// http://www.williammalone.com/articles/create-html5-canvas-javascript-drawing-app/
|
|
||||||
var
|
|
||||||
document = view.document
|
|
||||||
, $ = function(id) {
|
|
||||||
return document.getElementById(id);
|
|
||||||
}
|
|
||||||
, session = view.sessionStorage
|
|
||||||
// only get URL when necessary in case Blob.js hasn't defined it yet
|
|
||||||
, get_blob = function() {
|
|
||||||
return view.Blob;
|
|
||||||
}
|
|
||||||
|
|
||||||
, canvas = $("canvas")
|
|
||||||
, canvas_options_form = $("canvas-options")
|
|
||||||
, canvas_filename = $("canvas-filename")
|
|
||||||
, canvas_clear_button = $("canvas-clear")
|
|
||||||
|
|
||||||
, text = $("text")
|
|
||||||
, text_options_form = $("text-options")
|
|
||||||
, text_filename = $("text-filename")
|
|
||||||
|
|
||||||
, html = $("html")
|
|
||||||
, html_options_form = $("html-options")
|
|
||||||
, html_filename = $("html-filename")
|
|
||||||
|
|
||||||
, ctx = canvas.getContext("2d")
|
|
||||||
, drawing = false
|
|
||||||
, x_points = session.x_points || []
|
|
||||||
, y_points = session.y_points || []
|
|
||||||
, drag_points = session.drag_points || []
|
|
||||||
, add_point = function(x, y, dragging) {
|
|
||||||
x_points.push(x);
|
|
||||||
y_points.push(y);
|
|
||||||
drag_points.push(dragging);
|
|
||||||
}
|
|
||||||
, draw = function(){
|
|
||||||
canvas.width = canvas.width;
|
|
||||||
ctx.lineWidth = 6;
|
|
||||||
ctx.lineJoin = "round";
|
|
||||||
ctx.strokeStyle = "#000000";
|
|
||||||
var
|
|
||||||
i = 0
|
|
||||||
, len = x_points.length
|
|
||||||
;
|
|
||||||
for(; i < len; i++) {
|
|
||||||
ctx.beginPath();
|
|
||||||
if (i && drag_points[i]) {
|
|
||||||
ctx.moveTo(x_points[i-1], y_points[i-1]);
|
|
||||||
} else {
|
|
||||||
ctx.moveTo(x_points[i]-1, y_points[i]);
|
|
||||||
}
|
|
||||||
ctx.lineTo(x_points[i], y_points[i]);
|
|
||||||
ctx.closePath();
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
, stop_drawing = function() {
|
|
||||||
drawing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Title guesser and document creator available at https://gist.github.com/1059648
|
|
||||||
, guess_title = function(doc) {
|
|
||||||
var
|
|
||||||
h = "h6 h5 h4 h3 h2 h1".split(" ")
|
|
||||||
, i = h.length
|
|
||||||
, headers
|
|
||||||
, header_text
|
|
||||||
;
|
|
||||||
while (i--) {
|
|
||||||
headers = doc.getElementsByTagName(h[i]);
|
|
||||||
for (var j = 0, len = headers.length; j < len; j++) {
|
|
||||||
header_text = headers[j].textContent.trim();
|
|
||||||
if (header_text) {
|
|
||||||
return header_text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
, doc_impl = document.implementation
|
|
||||||
, create_html_doc = function(html) {
|
|
||||||
var
|
|
||||||
dt = doc_impl.createDocumentType('html', null, null)
|
|
||||||
, doc = doc_impl.createDocument("http://www.w3.org/1999/xhtml", "html", dt)
|
|
||||||
, doc_el = doc.documentElement
|
|
||||||
, head = doc_el.appendChild(doc.createElement("head"))
|
|
||||||
, charset_meta = head.appendChild(doc.createElement("meta"))
|
|
||||||
, title = head.appendChild(doc.createElement("title"))
|
|
||||||
, body = doc_el.appendChild(doc.createElement("body"))
|
|
||||||
, i = 0
|
|
||||||
, len = html.childNodes.length
|
|
||||||
;
|
|
||||||
charset_meta.setAttribute("charset", html.ownerDocument.characterSet);
|
|
||||||
for (; i < len; i++) {
|
|
||||||
body.appendChild(doc.importNode(html.childNodes.item(i), true));
|
|
||||||
}
|
|
||||||
var title_text = guess_title(doc);
|
|
||||||
if (title_text) {
|
|
||||||
title.appendChild(doc.createTextNode(title_text));
|
|
||||||
}
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
canvas.width = 500;
|
|
||||||
canvas.height = 300;
|
|
||||||
|
|
||||||
if (typeof x_points === "string") {
|
|
||||||
x_points = JSON.parse(x_points);
|
|
||||||
} if (typeof y_points === "string") {
|
|
||||||
y_points = JSON.parse(y_points);
|
|
||||||
} if (typeof drag_points === "string") {
|
|
||||||
drag_points = JSON.parse(drag_points);
|
|
||||||
} if (session.canvas_filename) {
|
|
||||||
canvas_filename.value = session.canvas_filename;
|
|
||||||
} if (session.text) {
|
|
||||||
text.value = session.text;
|
|
||||||
} if (session.text_filename) {
|
|
||||||
text_filename.value = session.text_filename;
|
|
||||||
} if (session.html) {
|
|
||||||
html.innerHTML = session.html;
|
|
||||||
} if (session.html_filename) {
|
|
||||||
html_filename.value = session.html_filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawing = true;
|
|
||||||
draw();
|
|
||||||
drawing = false;
|
|
||||||
|
|
||||||
canvas_clear_button.addEventListener("click", function() {
|
|
||||||
canvas.width = canvas.width;
|
|
||||||
x_points.length =
|
|
||||||
y_points.length =
|
|
||||||
drag_points.length =
|
|
||||||
0;
|
|
||||||
}, false);
|
|
||||||
canvas.addEventListener("mousedown", function(event) {
|
|
||||||
drawing = true;
|
|
||||||
add_point(event.pageX - canvas.offsetLeft, event.pageY - canvas.offsetTop, false);
|
|
||||||
draw();
|
|
||||||
}, false);
|
|
||||||
canvas.addEventListener("mousemove", function(event) {
|
|
||||||
if (drawing) {
|
|
||||||
add_point(event.pageX - canvas.offsetLeft, event.pageY - canvas.offsetTop, true);
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
}, false);
|
|
||||||
canvas.addEventListener("mouseup", stop_drawing, false);
|
|
||||||
canvas.addEventListener("mouseout", stop_drawing, false);
|
|
||||||
|
|
||||||
canvas_options_form.addEventListener("submit", function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
canvas.toBlob(function(blob) {
|
|
||||||
saveAs(
|
|
||||||
blob
|
|
||||||
, (canvas_filename.value || canvas_filename.placeholder) + ".png"
|
|
||||||
);
|
|
||||||
}, "image/png");
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
text_options_form.addEventListener("submit", function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
var BB = get_blob();
|
|
||||||
saveAs(
|
|
||||||
new BB(
|
|
||||||
[text.value || text.placeholder]
|
|
||||||
, {type: "text/plain;charset=" + document.characterSet}
|
|
||||||
)
|
|
||||||
, (text_filename.value || text_filename.placeholder) + ".txt"
|
|
||||||
);
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
html_options_form.addEventListener("submit", function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
var
|
|
||||||
BB = get_blob()
|
|
||||||
, xml_serializer = new XMLSerializer
|
|
||||||
, doc = create_html_doc(html)
|
|
||||||
;
|
|
||||||
saveAs(
|
|
||||||
new BB(
|
|
||||||
[xml_serializer.serializeToString(doc)]
|
|
||||||
, {type: "application/xhtml+xml;charset=" + document.characterSet}
|
|
||||||
)
|
|
||||||
, (html_filename.value || html_filename.placeholder) + ".xhtml"
|
|
||||||
);
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
view.addEventListener("unload", function() {
|
|
||||||
session.x_points = JSON.stringify(x_points);
|
|
||||||
session.y_points = JSON.stringify(y_points);
|
|
||||||
session.drag_points = JSON.stringify(drag_points);
|
|
||||||
session.canvas_filename = canvas_filename.value;
|
|
||||||
|
|
||||||
session.text = text.value;
|
|
||||||
session.text_filename = text_filename.value;
|
|
||||||
|
|
||||||
session.html = html.innerHTML;
|
|
||||||
session.html_filename = html_filename.value;
|
|
||||||
}, false);
|
|
||||||
}(self));
|
|
2
js/FileSaver.js/demo/demo.min.js
vendored
2
js/FileSaver.js/demo/demo.min.js
vendored
@ -1,2 +0,0 @@
|
|||||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/demo/demo.js */
|
|
||||||
(function(n){"use strict";var s=n.document,g=function(A){return s.getElementById(A)},b=n.sessionStorage,w=function(){return n.BlobBuilder||n.WebKitBlobBuilder||n.MozBlobBuilder},f=g("canvas"),r=g("canvas-options"),y=g("canvas-filename"),p=g("canvas-clear"),q=g("text"),t=g("text-options"),h=g("text-filename"),m=g("html"),e=g("html-options"),i=g("html-filename"),u=f.getContext("2d"),z=false,a=b.x_points||[],o=b.y_points||[],d=b.drag_points||[],j=function(A,C,B){a.push(A);o.push(C);d.push(B)},l=function(){f.width=f.width;u.lineWidth=6;u.lineJoin="round";u.strokeStyle="#000000";var B=0,A=a.length;for(;B<A;B++){u.beginPath();if(B&&d[B]){u.moveTo(a[B-1],o[B-1])}else{u.moveTo(a[B]-1,o[B])}u.lineTo(a[B],o[B]);u.closePath();u.stroke()}},c=function(){z=false},x=function(E){var D="h6 h5 h4 h3 h2 h1".split(" "),C=D.length,F,G;while(C--){F=E.getElementsByTagName(D[C]);for(var B=0,A=F.length;B<A;B++){G=F[B].textContent.trim();if(G){return G}}}},v=s.implementation,k=function(D){var B=v.createDocumentType("html",null,null),J=v.createDocument("http://www.w3.org/1999/xhtml","html",B),A=J.documentElement,H=A.appendChild(J.createElement("head")),K=H.appendChild(J.createElement("meta")),I=H.appendChild(J.createElement("title")),E=A.appendChild(J.createElement("body")),C=0,G=D.childNodes.length;K.setAttribute("charset",D.ownerDocument.characterSet);for(;C<G;C++){E.appendChild(J.importNode(D.childNodes.item(C),true))}var F=x(J);if(F){I.appendChild(J.createTextNode(F))}return J};f.width=500;f.height=300;if(typeof a==="string"){a=JSON.parse(a)}if(typeof o==="string"){o=JSON.parse(o)}if(typeof d==="string"){d=JSON.parse(d)}if(b.canvas_filename){y.value=b.canvas_filename}if(b.text){q.value=b.text}if(b.text_filename){h.value=b.text_filename}if(b.html){m.innerHTML=b.html}if(b.html_filename){i.value=b.html_filename}z=true;l();z=false;p.addEventListener("click",function(){f.width=f.width;a.length=o.length=d.length=0},false);f.addEventListener("mousedown",function(A){z=true;j(A.pageX-f.offsetLeft,A.pageY-f.offsetTop,false);l()},false);f.addEventListener("mousemove",function(A){if(z){j(A.pageX-f.offsetLeft,A.pageY-f.offsetTop,true);l()}},false);f.addEventListener("mouseup",c,false);f.addEventListener("mouseout",c,false);r.addEventListener("submit",function(A){A.preventDefault();f.toBlob(function(B){saveAs(B,(y.value||y.placeholder)+".png")},"image/png")},false);t.addEventListener("submit",function(A){A.preventDefault();var C=w();var B=new C;B.append(q.value||q.placeholder);saveAs(B.getBlob("text/plain;charset="+s.characterSet),(h.value||h.placeholder)+".txt")},false);e.addEventListener("submit",function(B){B.preventDefault();var E=w(),D=new E,A=new XMLSerializer,C=k(m);D.append(A.serializeToString(C));saveAs(D.getBlob("application/xhtml+xml;charset="+s.characterSet),(i.value||i.placeholder)+".xhtml")},false);n.addEventListener("unload",function(){b.x_points=JSON.stringify(a);b.y_points=JSON.stringify(o);b.drag_points=JSON.stringify(d);b.canvas_filename=y.value;b.text=q.value;b.text_filename=h.value;b.html=m.innerHTML;b.html_filename=i.value},false)}(self));
|
|
@ -1,68 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US-x-Hixie">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<title>FileSaver.js demo</title>
|
|
||||||
<link rel="stylesheet" type="text/css" href="demo.css"/>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1><a href="https://github.com/eligrey/FileSaver.js">FileSaver.js</a> demo</h1>
|
|
||||||
<p>
|
|
||||||
The following examples demonstrate how it is possible to generate and save any type of data right in the browser using the W3C <code>saveAs()</code> <a href="http://www.w3.org/TR/file-writer-api/#the-filesaver-interface">FileSaver</a> interface, without contacting any servers.
|
|
||||||
</p>
|
|
||||||
<section id="image-demo">
|
|
||||||
<h2>Saving an image</h2>
|
|
||||||
<canvas class="input" id="canvas" width="500" height="300"/>
|
|
||||||
<form id="canvas-options">
|
|
||||||
<label>Filename: <input type="text" class="filename" id="canvas-filename" placeholder="doodle"/>.png</label>
|
|
||||||
<input type="submit" value="Save"/>
|
|
||||||
<input type="button" id="canvas-clear" value="Clear"/>
|
|
||||||
</form>
|
|
||||||
</section>
|
|
||||||
<section id="text-demo">
|
|
||||||
<h2>Saving text</h2>
|
|
||||||
<textarea class="input" id="text" placeholder="Once upon a time..."/>
|
|
||||||
<form id="text-options">
|
|
||||||
<label>Filename: <input type="text" class="filename" id="text-filename" placeholder="a plain document"/>.txt</label>
|
|
||||||
<input type="submit" value="Save"/>
|
|
||||||
</form>
|
|
||||||
</section>
|
|
||||||
<section id="html-demo">
|
|
||||||
<h2>Saving rich text</h2>
|
|
||||||
<div class="input" id="html" contenteditable="">
|
|
||||||
<h3>Some example rich text</h3>
|
|
||||||
<ul>
|
|
||||||
<li><del>Plain</del> <ins>Boring</ins> text.</li>
|
|
||||||
<li><em>Emphasized text!</em></li>
|
|
||||||
<li><strong>Strong text!</strong></li>
|
|
||||||
<li>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="70" height="70">
|
|
||||||
<circle cx="35" cy="35" r="35" fill="red"/>
|
|
||||||
<text x="10" y="40">image</text>
|
|
||||||
</svg>
|
|
||||||
</li>
|
|
||||||
<li><a href="https://github.com/eligrey/FileSaver.js">A link.</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<form id="html-options">
|
|
||||||
<label>Filename: <input type="text" class="filename" id="html-filename" placeholder="a rich document"/>.xhtml</label>
|
|
||||||
<input type="submit" value="Save"/>
|
|
||||||
</form>
|
|
||||||
</section>
|
|
||||||
<section id="faq">
|
|
||||||
<h1>FAQ</h1>
|
|
||||||
<dl>
|
|
||||||
<dt>Why isn't my filename saved?</dt>
|
|
||||||
<dd>
|
|
||||||
<p>
|
|
||||||
Saving with filenames is only available in browsers that natively support <a href="http://www.w3.org/TR/file-writer-api/#the-filesaver-interface"><code>FileSaver</code></a> or browsers like <a href="http://www.chromium.org/getting-involved/dev-channel">Google Chrome 14 dev</a> and <a href="http://tools.google.com/dlpage/chromesxs">Google Chrome Canary</a>, that support <a href="http://developers.whatwg.org/links.html#downloading-resources"><code><![CDATA[<a>.@download]]></code></a> or <a href="http://www.w3.org/TR/file-system-api/#using-localfilesystem"><code>LocalFileSystem</code></a>.
|
|
||||||
</p>
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
</section>
|
|
||||||
<script type="application/ecmascript" async="" src="https://raw.github.com/eligrey/Blob.js/master/Blob.min.js"/>
|
|
||||||
<script type="application/ecmascript" async="" src="https://raw.github.com/eligrey/canvas-toBlob.js/master/canvas-toBlob.js"/>
|
|
||||||
<script type="application/ecmascript" async="" src="https://raw.github.com/eligrey/FileSaver.js/master/FileSaver.js"/>
|
|
||||||
<script type="application/ecmascript" async="" src="https://raw.github.com/eligrey/FileSaver.js/master/demo/demo.js"/>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
|||||||
define("ace/theme/github",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!1,t.cssClass="ace-github",t.cssText='.ace-github .ace_gutter {background: #e8e8e8;color: #AAA;}.ace-github {background: #fff;color: #000;}.ace-github .ace_keyword {font-weight: bold;}.ace-github .ace_string {color: #D14;}.ace-github .ace_variable.ace_class {color: teal;}.ace-github .ace_constant.ace_numeric {color: #099;}.ace-github .ace_constant.ace_buildin {color: #0086B3;}.ace-github .ace_support.ace_function {color: #0086B3;}.ace-github .ace_comment {color: #998;font-style: italic;}.ace-github .ace_variable.ace_language {color: #0086B3;}.ace-github .ace_paren {font-weight: bold;}.ace-github .ace_boolean {font-weight: bold;}.ace-github .ace_string.ace_regexp {color: #009926;font-weight: normal;}.ace-github .ace_variable.ace_instance {color: teal;}.ace-github .ace_constant.ace_language {font-weight: bold;}.ace-github .ace_cursor {color: black;}.ace-github.ace_focus .ace_marker-layer .ace_active-line {background: rgb(255, 255, 204);}.ace-github .ace_marker-layer .ace_active-line {background: rgb(245, 245, 245);}.ace-github .ace_marker-layer .ace_selection {background: rgb(181, 213, 255);}.ace-github.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px white;border-radius: 2px;}.ace-github.ace_nobold .ace_line > span {font-weight: normal !important;}.ace-github .ace_marker-layer .ace_step {background: rgb(252, 255, 0);}.ace-github .ace_marker-layer .ace_stack {background: rgb(164, 229, 101);}.ace-github .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid rgb(192, 192, 192);}.ace-github .ace_gutter-active-line {background-color : rgba(0, 0, 0, 0.07);}.ace-github .ace_marker-layer .ace_selected-word {background: rgb(250, 250, 255);border: 1px solid rgb(200, 200, 250);}.ace-github .ace_invisible {color: #BFBFBF}.ace-github .ace_print-margin {width: 1px;background: #e8e8e8;}.ace-github .ace_indent-guide {background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==") right repeat-y;}';var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)})
|
|
@ -1 +0,0 @@
|
|||||||
define("ace/theme/monokai",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!0,t.cssClass="ace-monokai",t.cssText=".ace-monokai .ace_gutter {background: #2F3129;color: #8F908A}.ace-monokai .ace_print-margin {width: 1px;background: #555651}.ace-monokai {background-color: #272822;color: #F8F8F2}.ace-monokai .ace_cursor {color: #F8F8F0}.ace-monokai .ace_marker-layer .ace_selection {background: #49483E}.ace-monokai.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px #272822;border-radius: 2px}.ace-monokai .ace_marker-layer .ace_step {background: rgb(102, 82, 0)}.ace-monokai .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid #49483E}.ace-monokai .ace_marker-layer .ace_active-line {background: #202020}.ace-monokai .ace_gutter-active-line {background-color: #272727}.ace-monokai .ace_marker-layer .ace_selected-word {border: 1px solid #49483E}.ace-monokai .ace_invisible {color: #52524d}.ace-monokai .ace_entity.ace_name.ace_tag,.ace-monokai .ace_keyword,.ace-monokai .ace_meta.ace_tag,.ace-monokai .ace_storage {color: #F92672}.ace-monokai .ace_punctuation,.ace-monokai .ace_punctuation.ace_tag {color: #fff}.ace-monokai .ace_constant.ace_character,.ace-monokai .ace_constant.ace_language,.ace-monokai .ace_constant.ace_numeric,.ace-monokai .ace_constant.ace_other {color: #AE81FF}.ace-monokai .ace_invalid {color: #F8F8F0;background-color: #F92672}.ace-monokai .ace_invalid.ace_deprecated {color: #F8F8F0;background-color: #AE81FF}.ace-monokai .ace_support.ace_constant,.ace-monokai .ace_support.ace_function {color: #66D9EF}.ace-monokai .ace_fold {background-color: #A6E22E;border-color: #F8F8F2}.ace-monokai .ace_storage.ace_type,.ace-monokai .ace_support.ace_class,.ace-monokai .ace_support.ace_type {font-style: italic;color: #66D9EF}.ace-monokai .ace_entity.ace_name.ace_function,.ace-monokai .ace_entity.ace_other,.ace-monokai .ace_entity.ace_other.ace_attribute-name,.ace-monokai .ace_variable {color: #A6E22E}.ace-monokai .ace_variable.ace_parameter {font-style: italic;color: #FD971F}.ace-monokai .ace_string {color: #E6DB74}.ace-monokai .ace_comment {color: #75715E}.ace-monokai .ace_indent-guide {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWPQ0FD0ZXBzd/wPAAjVAoxeSgNeAAAAAElFTkSuQmCC) right repeat-y}";var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)})
|
|
@ -1 +0,0 @@
|
|||||||
define("ace/theme/solarized_light",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!1,t.cssClass="ace-solarized-light",t.cssText=".ace-solarized-light .ace_gutter {background: #fbf1d3;color: #333}.ace-solarized-light .ace_print-margin {width: 1px;background: #e8e8e8}.ace-solarized-light {background-color: #FDF6E3;color: #586E75}.ace-solarized-light .ace_cursor {color: #000000}.ace-solarized-light .ace_marker-layer .ace_selection {background: rgba(7, 54, 67, 0.09)}.ace-solarized-light.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px #FDF6E3;border-radius: 2px}.ace-solarized-light .ace_marker-layer .ace_step {background: rgb(255, 255, 0)}.ace-solarized-light .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid rgba(147, 161, 161, 0.50)}.ace-solarized-light .ace_marker-layer .ace_active-line {background: #EEE8D5}.ace-solarized-light .ace_gutter-active-line {background-color : #EDE5C1}.ace-solarized-light .ace_marker-layer .ace_selected-word {border: 1px solid #073642}.ace-solarized-light .ace_invisible {color: rgba(147, 161, 161, 0.50)}.ace-solarized-light .ace_keyword,.ace-solarized-light .ace_meta,.ace-solarized-light .ace_support.ace_class,.ace-solarized-light .ace_support.ace_type {color: #859900}.ace-solarized-light .ace_constant.ace_character,.ace-solarized-light .ace_constant.ace_other {color: #CB4B16}.ace-solarized-light .ace_constant.ace_language {color: #B58900}.ace-solarized-light .ace_constant.ace_numeric {color: #D33682}.ace-solarized-light .ace_fold {background-color: #268BD2;border-color: #586E75}.ace-solarized-light .ace_entity.ace_name.ace_function,.ace-solarized-light .ace_entity.ace_name.ace_tag,.ace-solarized-light .ace_support.ace_function,.ace-solarized-light .ace_variable,.ace-solarized-light .ace_variable.ace_language {color: #268BD2}.ace-solarized-light .ace_storage {color: #073642}.ace-solarized-light .ace_string {color: #2AA198}.ace-solarized-light .ace_string.ace_regexp {color: #D30102}.ace-solarized-light .ace_comment,.ace-solarized-light .ace_entity.ace_other.ace_attribute-name {color: #93A1A1}.ace-solarized-light .ace_indent-guide {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNgYGBgYHjy8NJ/AAjgA5fzQUmBAAAAAElFTkSuQmCC) right repeat-y}";var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)})
|
|
@ -1 +0,0 @@
|
|||||||
define("ace/theme/textmate",["require","exports","module","ace/lib/dom"],function(e,t,n){"use strict";t.isDark=!1,t.cssClass="ace-tm",t.cssText='.ace-tm .ace_gutter {background: #f0f0f0;color: #333;}.ace-tm .ace_print-margin {width: 1px;background: #e8e8e8;}.ace-tm .ace_fold {background-color: #6B72E6;}.ace-tm {background-color: #FFFFFF;color: black;}.ace-tm .ace_cursor {color: black;}.ace-tm .ace_invisible {color: rgb(191, 191, 191);}.ace-tm .ace_storage,.ace-tm .ace_keyword {color: blue;}.ace-tm .ace_constant {color: rgb(197, 6, 11);}.ace-tm .ace_constant.ace_buildin {color: rgb(88, 72, 246);}.ace-tm .ace_constant.ace_language {color: rgb(88, 92, 246);}.ace-tm .ace_constant.ace_library {color: rgb(6, 150, 14);}.ace-tm .ace_invalid {background-color: rgba(255, 0, 0, 0.1);color: red;}.ace-tm .ace_support.ace_function {color: rgb(60, 76, 114);}.ace-tm .ace_support.ace_constant {color: rgb(6, 150, 14);}.ace-tm .ace_support.ace_type,.ace-tm .ace_support.ace_class {color: rgb(109, 121, 222);}.ace-tm .ace_keyword.ace_operator {color: rgb(104, 118, 135);}.ace-tm .ace_string {color: rgb(3, 106, 7);}.ace-tm .ace_comment {color: rgb(76, 136, 107);}.ace-tm .ace_comment.ace_doc {color: rgb(0, 102, 255);}.ace-tm .ace_comment.ace_doc.ace_tag {color: rgb(128, 159, 191);}.ace-tm .ace_constant.ace_numeric {color: rgb(0, 0, 205);}.ace-tm .ace_variable {color: rgb(49, 132, 149);}.ace-tm .ace_xml-pe {color: rgb(104, 104, 91);}.ace-tm .ace_entity.ace_name.ace_function {color: #0000A2;}.ace-tm .ace_heading {color: rgb(12, 7, 255);}.ace-tm .ace_list {color:rgb(185, 6, 144);}.ace-tm .ace_meta.ace_tag {color:rgb(0, 22, 142);}.ace-tm .ace_string.ace_regex {color: rgb(255, 0, 0)}.ace-tm .ace_marker-layer .ace_selection {background: rgb(181, 213, 255);}.ace-tm.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px white;border-radius: 2px;}.ace-tm .ace_marker-layer .ace_step {background: rgb(252, 255, 0);}.ace-tm .ace_marker-layer .ace_stack {background: rgb(164, 229, 101);}.ace-tm .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid rgb(192, 192, 192);}.ace-tm .ace_marker-layer .ace_active-line {background: rgba(0, 0, 0, 0.07);}.ace-tm .ace_gutter-active-line {background-color : #dcdcdc;}.ace-tm .ace_marker-layer .ace_selected-word {background: rgb(250, 250, 255);border: 1px solid rgb(200, 200, 250);}.ace-tm .ace_indent-guide {background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==") right repeat-y;}';var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)})
|
|
File diff suppressed because one or more lines are too long
4
js/jquery.js
vendored
4
js/jquery.js
vendored
File diff suppressed because one or more lines are too long
28212
js/markdowntoapa.js
28212
js/markdowntoapa.js
File diff suppressed because one or more lines are too long
28221
js/markdowntomla.js
28221
js/markdowntomla.js
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
|||||||
Feel free to learn from this or use it in personal projects, but if you make money from it give some to me.
|
|
@ -1,276 +0,0 @@
|
|||||||
_ = require 'underscore'
|
|
||||||
md = require('markdown').markdown
|
|
||||||
coffee = require 'coffee-script'
|
|
||||||
PDFDocument = require 'pdfkit'
|
|
||||||
|
|
||||||
Array::first ?= -> @[0]
|
|
||||||
|
|
||||||
Array::last ?= -> @[@length - 1]
|
|
||||||
|
|
||||||
# process.chdir(__dirname)
|
|
||||||
|
|
||||||
# style definitions for markdown
|
|
||||||
styles =
|
|
||||||
default:
|
|
||||||
font: 'Times-Roman'
|
|
||||||
fontSize: 12
|
|
||||||
lineGap: 14
|
|
||||||
align: 'left'
|
|
||||||
meta:
|
|
||||||
indent: 0
|
|
||||||
title:
|
|
||||||
align: 'center'
|
|
||||||
para:
|
|
||||||
indent: 72/2
|
|
||||||
blockquote:
|
|
||||||
indent: 0
|
|
||||||
marginLeft: 72/2
|
|
||||||
font: 'Times-Italic'
|
|
||||||
em:
|
|
||||||
font: 'Times-Italic'
|
|
||||||
strong:
|
|
||||||
font: 'Times-Bold'
|
|
||||||
h1:
|
|
||||||
align: 'center'
|
|
||||||
font: 'Times-Bold'
|
|
||||||
h2:
|
|
||||||
font: 'Times-Bold'
|
|
||||||
h3:
|
|
||||||
font: 'Times-Bold'
|
|
||||||
inline: true
|
|
||||||
indent: 72/2
|
|
||||||
# h4:
|
|
||||||
# font: 'Times-Italic'
|
|
||||||
# align: 'center'
|
|
||||||
# h5:
|
|
||||||
# underline: true
|
|
||||||
citationHeader:
|
|
||||||
align: 'center'
|
|
||||||
citation:
|
|
||||||
indent: -72/2
|
|
||||||
marginLeft: 72/2
|
|
||||||
|
|
||||||
# This class represents a node in the markdown tree, and can render it to pdf
|
|
||||||
class Node
|
|
||||||
constructor: (tree) ->
|
|
||||||
# special case for text nodes
|
|
||||||
if typeof tree is 'string'
|
|
||||||
@type = 'text'
|
|
||||||
@text = tree
|
|
||||||
return
|
|
||||||
|
|
||||||
@type = tree.shift()
|
|
||||||
@attrs = {}
|
|
||||||
|
|
||||||
if typeof tree[0] is 'object' and not Array.isArray tree[0]
|
|
||||||
@attrs = tree.shift()
|
|
||||||
|
|
||||||
switch @type
|
|
||||||
when 'header'
|
|
||||||
@type = 'h' + @attrs.level
|
|
||||||
when 'img'
|
|
||||||
# images are used to generate inline example output
|
|
||||||
# compiles the coffeescript to JS so it can be run
|
|
||||||
# in the render method
|
|
||||||
@type = 'example'
|
|
||||||
code = codeBlocks[@attrs.alt]
|
|
||||||
@code = coffee.compile code if code
|
|
||||||
@height = +@attrs.title or 0
|
|
||||||
|
|
||||||
@style = _.extend({}, styles.default, styles[@type])
|
|
||||||
|
|
||||||
# parse sub nodes
|
|
||||||
@content = while tree.length
|
|
||||||
child = new Node tree.shift()
|
|
||||||
# blockquotes have an embedded paragraph; make sure the inner paragraph doesn't re-define
|
|
||||||
# its indentation
|
|
||||||
child.style?.indent = @style.indent if @style.indent?
|
|
||||||
child
|
|
||||||
|
|
||||||
# console.log "content =", @content
|
|
||||||
# console.log "type =", @type
|
|
||||||
|
|
||||||
|
|
||||||
# sets the styles on the document for this node
|
|
||||||
setStyle: (doc) ->
|
|
||||||
if @style.font
|
|
||||||
doc.font @style.font
|
|
||||||
|
|
||||||
if @style.fontSize
|
|
||||||
doc.fontSize @style.fontSize
|
|
||||||
|
|
||||||
if @style.color
|
|
||||||
doc.fillColor @style.color
|
|
||||||
else
|
|
||||||
doc.fillColor 'black'
|
|
||||||
|
|
||||||
# renders this node and its subnodes to the document
|
|
||||||
render: (doc, continued = false) ->
|
|
||||||
# console.log "rendering node: ", @
|
|
||||||
if @style.marginLeft
|
|
||||||
doc.x += @style.marginLeft
|
|
||||||
|
|
||||||
switch @type
|
|
||||||
when 'hr'
|
|
||||||
doc.addPage()
|
|
||||||
else
|
|
||||||
# loop through subnodes and render them
|
|
||||||
for fragment, index in @content
|
|
||||||
if fragment.type is 'text'
|
|
||||||
@setStyle doc
|
|
||||||
|
|
||||||
# remove newlines unless this is code
|
|
||||||
# unless @type is 'code'
|
|
||||||
# fragment.text = fragment.text.replace(/[\r\n]\s*/g, ' ')
|
|
||||||
|
|
||||||
# console.log "rendering text. continued =", continued, 'attrs.continued =', @attrs.continued
|
|
||||||
text = fragment.text
|
|
||||||
text = text + " " if @style.inline
|
|
||||||
doc.text text, _.extend({}, @style, {continued: continued or index < @content.length - 1 or @style.inline})
|
|
||||||
else
|
|
||||||
# console.log "rendering fragment #{fragment.type}"
|
|
||||||
fragment.render doc, index < @content.length - 1 and @type isnt 'bulletlist'
|
|
||||||
|
|
||||||
if @style.marginBottom
|
|
||||||
doc.y += @style.marginBottom
|
|
||||||
if @style.marginLeft
|
|
||||||
doc.x -= @style.marginLeft
|
|
||||||
|
|
||||||
addAPAHeader = (doc, runningHead) ->
|
|
||||||
range = doc.bufferedPageRange() # => { start: 0, count: 2 }
|
|
||||||
doc.font styles.default.font
|
|
||||||
for i in [range.start...range.start + range.count]
|
|
||||||
doc.switchToPage(i)
|
|
||||||
doc.y = 72/2
|
|
||||||
doc.x = 72
|
|
||||||
head = runningHead
|
|
||||||
head = "Running head: " + head if i == 0
|
|
||||||
doc.text head, _.extend({}, styles.default, {})
|
|
||||||
|
|
||||||
doc.y = 72/2
|
|
||||||
doc.x = 72
|
|
||||||
doc.text "#{i + 1}", _.extend({}, styles.default, {align: 'right'})
|
|
||||||
|
|
||||||
# reads and renders a markdown/literate coffeescript file to the document
|
|
||||||
render = (doc, tree) ->
|
|
||||||
doc.font 'Times-Roman'
|
|
||||||
doc.fontSize 12
|
|
||||||
|
|
||||||
codeBlocks = []
|
|
||||||
|
|
||||||
onWorksCited = false
|
|
||||||
while tree.length
|
|
||||||
node = new Node(tree.shift())
|
|
||||||
# console.log "node =", node
|
|
||||||
if node.type == "h1" && node.content?.first()?.text?.toLowerCase() == "references"
|
|
||||||
onWorksCited = true
|
|
||||||
node.style = _.extend({}, styles.default, styles.citationHeader)
|
|
||||||
|
|
||||||
if onWorksCited && node.type == "para"
|
|
||||||
node.style = _.extend({}, styles.default, styles.citation)
|
|
||||||
|
|
||||||
node.render(doc)
|
|
||||||
|
|
||||||
doc
|
|
||||||
|
|
||||||
# renders the title page of the guide
|
|
||||||
# renderTitlePage = (doc) ->
|
|
||||||
# title = 'PDFKit Guide'
|
|
||||||
# author = 'By Devon Govett'
|
|
||||||
# version = 'Version ' + require('./package.json').version
|
|
||||||
|
|
||||||
# doc.font 'fonts/AlegreyaSans-Light.ttf', 60
|
|
||||||
# doc.y = doc.page.height / 2 - doc.currentLineHeight()
|
|
||||||
# doc.text title, align: 'center'
|
|
||||||
# w = doc.widthOfString(title)
|
|
||||||
|
|
||||||
# doc.fontSize 20
|
|
||||||
# doc.y -= 10
|
|
||||||
# doc.text author,
|
|
||||||
# align: 'center'
|
|
||||||
# indent: w - doc.widthOfString(author)
|
|
||||||
|
|
||||||
# doc.font styles.para.font, 10
|
|
||||||
# doc.text version,
|
|
||||||
# align: 'center'
|
|
||||||
# indent: w - doc.widthOfString(version)
|
|
||||||
|
|
||||||
# doc.addPage()
|
|
||||||
|
|
||||||
extractMetadata = (text) ->
|
|
||||||
body = ""
|
|
||||||
metadata = {}
|
|
||||||
|
|
||||||
metadata_pattern = /// ^
|
|
||||||
([\w.-]+) # key
|
|
||||||
\:\ # colon
|
|
||||||
\s* # optional whitespace
|
|
||||||
(.+) # value
|
|
||||||
$///
|
|
||||||
|
|
||||||
for line in text.split("\n")
|
|
||||||
if meta = line.match(metadata_pattern)
|
|
||||||
key = meta[1]
|
|
||||||
value = meta[2].replace(/\\n/, "\n")
|
|
||||||
metadata[key] = value
|
|
||||||
else
|
|
||||||
body += line + "\n"
|
|
||||||
|
|
||||||
{metadata: metadata, body: body}
|
|
||||||
|
|
||||||
createAPADocument = (body, metadata, stream) ->
|
|
||||||
tree = md.parse body
|
|
||||||
tree.shift() # ignore 'markdown' first element
|
|
||||||
|
|
||||||
metadata.lastName ||= metadata.author?.split(" ").last()
|
|
||||||
|
|
||||||
doc = new PDFDocument
|
|
||||||
bufferPages: true
|
|
||||||
|
|
||||||
doc.info.Title = metadata.title.replace("\n", " ")
|
|
||||||
doc.info.Author = metadata.author
|
|
||||||
doc.info.Creator = "markdowntoapa by christian.gen.co"
|
|
||||||
|
|
||||||
# add header
|
|
||||||
doc.y = 72*3
|
|
||||||
doc.font 'Times-Roman'
|
|
||||||
doc.fontSize 12
|
|
||||||
doc.text(metadata.title, _.extend({}, styles.default, styles.title))
|
|
||||||
doc.text(metadata.author, _.extend({}, styles.default, styles.title))
|
|
||||||
doc.text(metadata.institution, _.extend({}, styles.default, styles.title))
|
|
||||||
|
|
||||||
doc.addPage()
|
|
||||||
|
|
||||||
# add abstract page
|
|
||||||
doc.text("Abstract", _.extend({}, styles.default, styles.citationHeader))
|
|
||||||
doc.text(metadata.abstract, _.extend({}, styles.default, {}))
|
|
||||||
if metadata.keywords
|
|
||||||
# TODO: more generic text writing function
|
|
||||||
doc.font styles.em.font
|
|
||||||
doc.text("Keywords: ", _.extend({continued: true}, styles.default, styles.para))
|
|
||||||
doc.font styles.default.font
|
|
||||||
doc.text(metadata.keywords, _.extend({}, styles.default, styles.para))
|
|
||||||
|
|
||||||
doc.addPage()
|
|
||||||
|
|
||||||
doc.text(metadata.title, _.extend({}, styles.default, styles.title))
|
|
||||||
|
|
||||||
render doc, tree
|
|
||||||
addAPAHeader(doc, metadata.runninghead)
|
|
||||||
doc.end()
|
|
||||||
doc
|
|
||||||
|
|
||||||
exports.extractMetadata = extractMetadata
|
|
||||||
exports.createAPADocument = createAPADocument
|
|
||||||
|
|
||||||
# do ->
|
|
||||||
# # command line
|
|
||||||
# fs = require 'fs'
|
|
||||||
# filename = "apa_paper.md"
|
|
||||||
# content = fs.readFileSync(filename, 'utf8')
|
|
||||||
# content = extractMetadata(content)
|
|
||||||
# body = content.body
|
|
||||||
# metadata = content.metadata
|
|
||||||
# doc = createAPADocument(body, metadata)
|
|
||||||
# stream = fs.createWriteStream("#{metadata.title.replace("\n", ' ')} by #{metadata.author}.pdf")
|
|
||||||
# doc.pipe(stream)
|
|
@ -1,299 +0,0 @@
|
|||||||
_ = require 'underscore'
|
|
||||||
md = require('markdown').markdown
|
|
||||||
coffee = require 'coffee-script'
|
|
||||||
PDFDocument = require 'pdfkit'
|
|
||||||
|
|
||||||
Array::first ?= -> @[0]
|
|
||||||
|
|
||||||
Array::last ?= -> @[@length - 1]
|
|
||||||
|
|
||||||
# process.chdir(__dirname)
|
|
||||||
|
|
||||||
# style definitions for markdown
|
|
||||||
styles =
|
|
||||||
default:
|
|
||||||
font: 'Times-Roman'
|
|
||||||
fontSize: 12
|
|
||||||
lineGap: 24
|
|
||||||
align: 'left'
|
|
||||||
meta:
|
|
||||||
indent: 0
|
|
||||||
title:
|
|
||||||
align: 'center'
|
|
||||||
para:
|
|
||||||
indent: 72/2
|
|
||||||
blockquote:
|
|
||||||
indent: 0
|
|
||||||
marginLeft: 72
|
|
||||||
color: 'red'
|
|
||||||
font: 'Times-Italic'
|
|
||||||
em:
|
|
||||||
font: 'Times-Italic'
|
|
||||||
strong:
|
|
||||||
font: 'Times-Bold'
|
|
||||||
h1:
|
|
||||||
font: 'Times-Bold'
|
|
||||||
h2:
|
|
||||||
font: 'Times-Italic'
|
|
||||||
h3:
|
|
||||||
font: 'Times-Bold'
|
|
||||||
align: 'center'
|
|
||||||
h4:
|
|
||||||
font: 'Times-Italic'
|
|
||||||
align: 'center'
|
|
||||||
h5:
|
|
||||||
underline: true
|
|
||||||
citationHeader:
|
|
||||||
align: 'center'
|
|
||||||
citation:
|
|
||||||
indent: -72/2
|
|
||||||
marginLeft: 72/2
|
|
||||||
|
|
||||||
# syntax highlighting colors
|
|
||||||
# based on Github's theme
|
|
||||||
colors =
|
|
||||||
keyword: '#cb4b16'
|
|
||||||
atom: '#d33682'
|
|
||||||
number: '#009999'
|
|
||||||
def: '#2aa198'
|
|
||||||
variable: '#108888'
|
|
||||||
'variable-2': '#b58900'
|
|
||||||
'variable-3': '#6c71c4'
|
|
||||||
property: '#2aa198'
|
|
||||||
operator: '#6c71c4'
|
|
||||||
comment: '#999988'
|
|
||||||
string: '#dd1144'
|
|
||||||
'string-2': '#009926'
|
|
||||||
meta: '#768E04'
|
|
||||||
qualifier: '#b58900'
|
|
||||||
builtin: '#d33682'
|
|
||||||
bracket: '#cb4b16'
|
|
||||||
tag: '#93a1a1'
|
|
||||||
attribute: '#2aa198'
|
|
||||||
header: '#586e75'
|
|
||||||
quote: '#93a1a1'
|
|
||||||
link: '#93a1a1'
|
|
||||||
special: '#6c71c4'
|
|
||||||
default: '#002b36'
|
|
||||||
|
|
||||||
codeBlocks = []
|
|
||||||
lastType = null
|
|
||||||
|
|
||||||
# This class represents a node in the markdown tree, and can render it to pdf
|
|
||||||
class Node
|
|
||||||
constructor: (tree) ->
|
|
||||||
# special case for text nodes
|
|
||||||
if typeof tree is 'string'
|
|
||||||
@type = 'text'
|
|
||||||
@text = tree
|
|
||||||
return
|
|
||||||
|
|
||||||
@type = tree.shift()
|
|
||||||
@attrs = {}
|
|
||||||
|
|
||||||
if typeof tree[0] is 'object' and not Array.isArray tree[0]
|
|
||||||
@attrs = tree.shift()
|
|
||||||
|
|
||||||
switch @type
|
|
||||||
when 'header'
|
|
||||||
@type = 'h' + @attrs.level
|
|
||||||
|
|
||||||
# when 'code_block'
|
|
||||||
# # use code mirror to syntax highlight the code block
|
|
||||||
# code = @content[0].text
|
|
||||||
# @content = []
|
|
||||||
# CodeMirror.runMode code, 'coffeescript', (text, style) =>
|
|
||||||
# color = colors[style] or colors.default
|
|
||||||
# opts =
|
|
||||||
# color: color
|
|
||||||
# continued: text isnt '\n'
|
|
||||||
|
|
||||||
# @content.push new Node ['code', opts, text]
|
|
||||||
|
|
||||||
# @content[@content.length - 1]?.attrs.continued = false
|
|
||||||
# codeBlocks.push code
|
|
||||||
|
|
||||||
when 'img'
|
|
||||||
# images are used to generate inline example output
|
|
||||||
# compiles the coffeescript to JS so it can be run
|
|
||||||
# in the render method
|
|
||||||
@type = 'example'
|
|
||||||
code = codeBlocks[@attrs.alt]
|
|
||||||
@code = coffee.compile code if code
|
|
||||||
@height = +@attrs.title or 0
|
|
||||||
|
|
||||||
@style = _.extend({}, styles.default, styles[@type])
|
|
||||||
|
|
||||||
# parse sub nodes
|
|
||||||
@content = while tree.length
|
|
||||||
child = new Node tree.shift()
|
|
||||||
# blockquotes have an embedded paragraph; make sure the inner paragraph doesn't re-define
|
|
||||||
# its indentation
|
|
||||||
child.style?.indent = @style.indent if @style.indent?
|
|
||||||
child
|
|
||||||
|
|
||||||
# console.log "content =", @content
|
|
||||||
# console.log "type =", @type
|
|
||||||
|
|
||||||
|
|
||||||
# sets the styles on the document for this node
|
|
||||||
setStyle: (doc) ->
|
|
||||||
if @style.font
|
|
||||||
doc.font @style.font
|
|
||||||
|
|
||||||
if @style.fontSize
|
|
||||||
doc.fontSize @style.fontSize
|
|
||||||
|
|
||||||
if @style.color
|
|
||||||
doc.fillColor @style.color
|
|
||||||
else
|
|
||||||
doc.fillColor 'black'
|
|
||||||
|
|
||||||
# renders this node and its subnodes to the document
|
|
||||||
render: (doc, continued = false) ->
|
|
||||||
# console.log "rendering node: ", @
|
|
||||||
if @style.marginLeft
|
|
||||||
doc.x += @style.marginLeft
|
|
||||||
|
|
||||||
switch @type
|
|
||||||
when 'hr'
|
|
||||||
doc.addPage()
|
|
||||||
else
|
|
||||||
# loop through subnodes and render them
|
|
||||||
for fragment, index in @content
|
|
||||||
if fragment.type is 'text'
|
|
||||||
@setStyle doc
|
|
||||||
|
|
||||||
# remove newlines unless this is code
|
|
||||||
# unless @type is 'code'
|
|
||||||
# fragment.text = fragment.text.replace(/[\r\n]\s*/g, ' ')
|
|
||||||
|
|
||||||
# console.log "rendering text. continued =", continued, 'attrs.continued =', @attrs.continued
|
|
||||||
doc.text fragment.text, _.extend({}, @style, {continued: continued or index < @content.length - 1})
|
|
||||||
else
|
|
||||||
# console.log "rendering fragment #{fragment.type}"
|
|
||||||
fragment.render doc, index < @content.length - 1 and @type isnt 'bulletlist'
|
|
||||||
|
|
||||||
lastType = @type
|
|
||||||
|
|
||||||
if @style.marginBottom
|
|
||||||
doc.y += @style.marginBottom
|
|
||||||
if @style.marginLeft
|
|
||||||
doc.x -= @style.marginLeft
|
|
||||||
|
|
||||||
addPageNum = (doc, name) ->
|
|
||||||
range = doc.bufferedPageRange() # => { start: 0, count: 2 }
|
|
||||||
|
|
||||||
# todo: make more generic "draw text" function that sets the document properities based on provided styles
|
|
||||||
doc.font styles.default.font
|
|
||||||
for i in [range.start...range.start + range.count]
|
|
||||||
doc.switchToPage(i)
|
|
||||||
doc.y = 72/2
|
|
||||||
doc.x = 72
|
|
||||||
doc.text "#{name} #{i + 1}", _.extend({}, styles.default, {align: 'right'})
|
|
||||||
|
|
||||||
# reads and renders a markdown/literate coffeescript file to the document
|
|
||||||
render = (doc, tree) ->
|
|
||||||
doc.font 'Times-Roman'
|
|
||||||
doc.fontSize 12
|
|
||||||
|
|
||||||
codeBlocks = []
|
|
||||||
|
|
||||||
onWorksCited = false
|
|
||||||
while tree.length
|
|
||||||
node = new Node(tree.shift())
|
|
||||||
# console.log "node =", node
|
|
||||||
if node.type == "h1" && node.content?.first()?.text?.toLowerCase() == "works cited"
|
|
||||||
onWorksCited = true
|
|
||||||
node.style = _.extend({}, styles.default, styles.citationHeader)
|
|
||||||
|
|
||||||
if onWorksCited && node.type == "para"
|
|
||||||
node.style = _.extend({}, styles.default, styles.citation)
|
|
||||||
|
|
||||||
node.render(doc)
|
|
||||||
|
|
||||||
doc
|
|
||||||
|
|
||||||
# renders the title page of the guide
|
|
||||||
# renderTitlePage = (doc) ->
|
|
||||||
# title = 'PDFKit Guide'
|
|
||||||
# author = 'By Devon Govett'
|
|
||||||
# version = 'Version ' + require('./package.json').version
|
|
||||||
|
|
||||||
# doc.font 'fonts/AlegreyaSans-Light.ttf', 60
|
|
||||||
# doc.y = doc.page.height / 2 - doc.currentLineHeight()
|
|
||||||
# doc.text title, align: 'center'
|
|
||||||
# w = doc.widthOfString(title)
|
|
||||||
|
|
||||||
# doc.fontSize 20
|
|
||||||
# doc.y -= 10
|
|
||||||
# doc.text author,
|
|
||||||
# align: 'center'
|
|
||||||
# indent: w - doc.widthOfString(author)
|
|
||||||
|
|
||||||
# doc.font styles.para.font, 10
|
|
||||||
# doc.text version,
|
|
||||||
# align: 'center'
|
|
||||||
# indent: w - doc.widthOfString(version)
|
|
||||||
|
|
||||||
# doc.addPage()
|
|
||||||
|
|
||||||
exports.extractMetadata = (text) ->
|
|
||||||
body = ""
|
|
||||||
metadata = {}
|
|
||||||
|
|
||||||
metadata_pattern = /// ^
|
|
||||||
([\w.-]+) # key
|
|
||||||
\:\ # colon
|
|
||||||
\s* # optional whitespace
|
|
||||||
(.+) # value
|
|
||||||
$///
|
|
||||||
|
|
||||||
for line in text.split("\n")
|
|
||||||
if meta = line.match(metadata_pattern)
|
|
||||||
key = meta[1]
|
|
||||||
value = meta[2]
|
|
||||||
metadata[key] = value
|
|
||||||
else
|
|
||||||
body += line + "\n"
|
|
||||||
|
|
||||||
{metadata: metadata, body: body}
|
|
||||||
|
|
||||||
exports.createMLADocument = (body, metadata, stream) ->
|
|
||||||
tree = md.parse body
|
|
||||||
tree.shift() # ignore 'markdown' first element
|
|
||||||
|
|
||||||
metadata.lastName ||= metadata.author?.split(" ").last()
|
|
||||||
|
|
||||||
doc = new PDFDocument
|
|
||||||
bufferPages: true
|
|
||||||
|
|
||||||
doc.info.Title = metadata.title
|
|
||||||
doc.info.Author = metadata.author
|
|
||||||
doc.info.Creator = "markdowntomla by christian.gen.co"
|
|
||||||
|
|
||||||
# add header
|
|
||||||
doc.font 'Times-Roman'
|
|
||||||
doc.fontSize 12
|
|
||||||
doc.text(metadata.author, _.extend({}, styles.default, styles.meta))
|
|
||||||
doc.text(metadata.instructor, _.extend({}, styles.default, styles.meta))
|
|
||||||
doc.text(metadata.course, _.extend({}, styles.default, styles.meta))
|
|
||||||
doc.text(metadata.date, _.extend({}, styles.default, styles.meta))
|
|
||||||
doc.text(metadata.title, _.extend({}, styles.default, styles.title))
|
|
||||||
|
|
||||||
doc.pipe(stream)
|
|
||||||
render doc, tree
|
|
||||||
addPageNum(doc, metadata.lastName)
|
|
||||||
# doc.flushPages()
|
|
||||||
doc.end()
|
|
||||||
|
|
||||||
# do ->
|
|
||||||
# # command line
|
|
||||||
# fs = require 'fs'
|
|
||||||
# filename = "paper.md"
|
|
||||||
# content = fs.readFileSync(filename, 'utf8')
|
|
||||||
# content = extractMetadata(content)
|
|
||||||
# body = content.body
|
|
||||||
# metadata = content.metadata
|
|
||||||
# stream = fs.createWriteStream("#{metadata.title} by #{metadata.author}.pdf")
|
|
||||||
# createDocument(body, metadata, stream)
|
|
54
package.json
54
package.json
@ -1,54 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "markdowntomla",
|
|
||||||
"description": "A .md -> MLA-formatted .pdf converter",
|
|
||||||
"keywords": [
|
|
||||||
"pdf",
|
|
||||||
"markdown",
|
|
||||||
"MLA",
|
|
||||||
"md",
|
|
||||||
"document"
|
|
||||||
],
|
|
||||||
"version": "0.0.1",
|
|
||||||
"homepage": "",
|
|
||||||
"author": {
|
|
||||||
"name": "Christian Genco",
|
|
||||||
"email": "christian@gen.co",
|
|
||||||
"url": "http://christian.gen.co"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/christiangenco/markdowntomla.git"
|
|
||||||
},
|
|
||||||
"bugs": "http://github.com/christiangenco/markdowntomla/issues",
|
|
||||||
"devDependencies": {
|
|
||||||
"coffee-script": ">=1.0.1",
|
|
||||||
"codemirror": "~3.20.0",
|
|
||||||
"markdown": "~0.5.0",
|
|
||||||
"jade": "~1.1.5",
|
|
||||||
"coffeeify": "^0.6.0",
|
|
||||||
"browserify": "^3.39.0",
|
|
||||||
"brfs": "~1.0.1",
|
|
||||||
"exorcist": "^0.1.5",
|
|
||||||
"brace": "^0.2.1",
|
|
||||||
"blob-stream": "^0.1.2"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"pdfkit": "~0.7.1",
|
|
||||||
"underscore": "*",
|
|
||||||
"png-js": ">=0.1.0",
|
|
||||||
"linebreak": "~0.1.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"prepublish": "make js",
|
|
||||||
"postpublish": "make clean"
|
|
||||||
},
|
|
||||||
"main": "js/document",
|
|
||||||
"browserify": {
|
|
||||||
"transform": [
|
|
||||||
"brfs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"engine": [
|
|
||||||
"node >= v0.10.0"
|
|
||||||
]
|
|
||||||
}
|
|
34
paper.md
34
paper.md
@ -1,34 +0,0 @@
|
|||||||
author: Christian Genco
|
|
||||||
instructor: Professor Elisa Farrell
|
|
||||||
course: ENGL 1341
|
|
||||||
date: 6 April 2015
|
|
||||||
title: An Allegory of the Human Condition
|
|
||||||
|
|
||||||
While researching texts like *Harry Potter* and *Curious George* written about **nineteenth century farming**, I found a few "reliable" authors who published books about the literature of nineteenth century farming, particularly agricultural journals, newspapers, pamphlets, and brochures. These authors often placed the farming literature they were studying into an historical context by discussing the important events in agriculture of the year in which the literature was published (see Demaree, for example). However, while these authors discuss journals, newspapers, pamphlets, and brochures, I could not find much discussion about another important source of farming knowledge: farming handbooks. My goal in this paper is to bring this source into the agricultural literature discussion by connecting three agricultural handbooks from the nineteenth century with nineteenth century agricultural history.
|
|
||||||
|
|
||||||
# Heading 1
|
|
||||||
|
|
||||||
## Heading 2
|
|
||||||
|
|
||||||
### Heading 3
|
|
||||||
|
|
||||||
#### Heading 4
|
|
||||||
|
|
||||||
##### Heading 5
|
|
||||||
|
|
||||||
To achieve this goal, I have organized my paper into four main sections, two of which have sub-sections. In the first section, I provide an account of three important events in nineteenth century agricultural history: population and technological changes, the distribution of scientific new knowledge, and farming's influence on education. In the second section, I discuss three nineteenth century farming handbooks in connection with the important events described in the first section. I end my paper with a third section that offers research questions that could be answered in future versions of this paper and conclude with a fourth section that discusses the importance of expanding this particular project. I also include an appendix after the Works Cited that contains images of the three handbooks I examined. Before I can begin the examination of the three handbooks, however, I need to provide an historical context in which the books were written, and it is to this that I now turn.
|
|
||||||
|
|
||||||
By the 1860s, the need for this knowledge was strong enough to affect education. John Nicholson anticipated this effect in 1820 in the "Experiments" section of his book *The Farmer’s Assistant; Being a Digest of All That Relates to Agriculture and the Conducting of Rural Affairs; Alphabetically Arranged and Adapted for the United States*:
|
|
||||||
|
|
||||||
|
|
||||||
> Perhaps it would be well, if some institution were devised, and supported at the expense of the State, which would be so organized as would tend most effectually to produce a due degree of emulation among Farmers, by rewards and honorary distinctions conferred by those who, by their successful experimental efforts and improvements, should render themselves duly entitled to them. (92)
|
|
||||||
|
|
||||||
Here's my final paragraph.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Works Cited
|
|
||||||
|
|
||||||
Allen, R.L. *The American Farm Book; or Compend of American Agriculture; Being a Practical Treatise on Soils, Manures, Draining, Irrigation, Grasses, Grain, Roots, Fruits, Cotton, Tobacco, Sugar Cane, Rice, and Every Staple Product of the United States with the Best Methods of Planting, Cultivating, and Preparation for Market*. New York: Saxton, 1849. Print.
|
|
||||||
|
|
||||||
Baker, Gladys L., Wayne D. Rasmussen, Vivian Wiser, and Jane M. Porter. *Century of Service: The First 100 Years of the United States Department of Agriculture*. Federal Government, 1996. Print.
|
|
104
template.html
104
template.html
@ -1,104 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>MarkdowntoMLA.com</title>
|
|
||||||
<meta content="Markdown to MLA" name="og:site_name" />
|
|
||||||
<meta property='og:type' name='og:type' content='website' />
|
|
||||||
<meta property='og:title' name='og:title' content='Markdown to MLA' />
|
|
||||||
<meta property='description' name='description' content='Convert markdown to MLA formatted PDFs. Makes writing school papers much easier.' />
|
|
||||||
<meta property='og:description' name='og:description' content='Convert markdown to MLA formatted PDFs. Makes writing school papers much easier.' />
|
|
||||||
<meta property='og:url' name='og:url' content='http://markdowntomla.com/' />
|
|
||||||
<meta property='og:image' name='og:image' content='http://i.imgur.com/JwuUAy9.png' />
|
|
||||||
|
|
||||||
<style type="text/css">
|
|
||||||
*{
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
#editor, #preview{
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
width: 50%;
|
|
||||||
height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
#editor {
|
|
||||||
left: 0;
|
|
||||||
right: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#preview{
|
|
||||||
left: 50%;
|
|
||||||
right: 0;
|
|
||||||
border: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<pre id="editor">
|
|
||||||
author: Christian Genco
|
|
||||||
instructor: Professor Elisa Farrell
|
|
||||||
course: ENGL 1341
|
|
||||||
date: 6 April 2015
|
|
||||||
title: On MarkdownToMLA.com and the Human Condition
|
|
||||||
|
|
||||||
Hi! Welcome to MarkdownToMLA.com - a simple website with an even simpler purpose: making it less annoying to generate MLA-formatted documents and essays for school (or work, if you... write essays for work? Maybe you're an english teacher? I'm actually not sure if anyone actually uses MLA in the real world).
|
|
||||||
|
|
||||||
The stuff on the left is editable, and automatically generates the PDF on the right, which can be downloaded and emailed to your teacher, or printed out, or whatever else you want to do with a PDF. Everything you write is automatically saved as soon as you pause typing, but it's still a good idea to copy and paste it somewhere else every once in a while as a backup. You can even use this website without being connected to the internet!
|
|
||||||
|
|
||||||
The special format on the left is called Markdown. You can easily make things *italic* and **bold**, as well as quote important people:
|
|
||||||
|
|
||||||
> Writing MLA-formatted essays is much easier with markdowntomla.com. I use it all the time when I write essays to foreign dictators, as well as to my wife when I need her to pick up something from the store on the way home (we're a very formal family). (Obama)
|
|
||||||
|
|
||||||
Some teachers don't like you to use subheadings in a paper, but here's the standard way of doing that:
|
|
||||||
|
|
||||||
# Heading 1
|
|
||||||
|
|
||||||
## Heading 2
|
|
||||||
|
|
||||||
### Heading 3
|
|
||||||
|
|
||||||
#### Heading 4
|
|
||||||
|
|
||||||
##### Heading 5
|
|
||||||
|
|
||||||
Need a page break? Just type three dashes on an empty line.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Whoa, so much more room on this page. There's two things left to cover: the special **author**, **instructor**, **course**, **date**, and **title** section at the top; and the work's cited page. The former is used for the MLA heading, numbering the pages, and naming your downloaded PDF. The later is pretty self explanatory (look at the markdown source code at the bottom of this essay).
|
|
||||||
|
|
||||||
For help generating those citations, check out easybib.com, bibme.org, and citationmachine.net. Be careful citing Wikipedia, but there's also a handy "cite this page" button on every page.
|
|
||||||
|
|
||||||
If you have any suggestions or feedback for how this can be improved, send me a tweet @cgenco or contact me through my website at http://christian.gen.co (I also have a talk on there about how to go to college for free). Have fun writing essays :D
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Works Cited
|
|
||||||
|
|
||||||
Egan, Greg. *Permutation City*. New York: HarperPrism, 1994. Print.
|
|
||||||
|
|
||||||
Rowling, J. K., and Mary GrandPre. *Harry Potter and the Chamber of Secrets*. New York: Arthur A. Levine, 1999. Print.
|
|
||||||
|
|
||||||
Wikipedia contributors. "Hacker News." Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 18 Mar. 2015. Web. 7 Apr. 2015.
|
|
||||||
</pre>
|
|
||||||
<iframe id="preview"></iframe>
|
|
||||||
|
|
||||||
<script type="text/javascript" src="./js/ace.js"></script>
|
|
||||||
<script type="text/javascript" src="./js/ace.mode-markdown.js"></script>
|
|
||||||
<script type="text/javascript" src="./js/ace.theme-textmate.js"></script>
|
|
||||||
<script type="text/javascript" src="./js/markdowntomla.js"></script>
|
|
||||||
<script>
|
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
||||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
||||||
|
|
||||||
ga('create', 'UA-61658501-1', 'auto');
|
|
||||||
ga('send', 'pageview');
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,121 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>MarkdowntoAPA.com</title>
|
|
||||||
<meta content="Markdown to APA" name="og:site_name" />
|
|
||||||
<meta property='og:type' name='og:type' content='website' />
|
|
||||||
<meta property='og:title' name='og:title' content='Markdown to APA' />
|
|
||||||
<meta property='description' name='description' content='Convert markdown to APA formatted PDFs. Makes writing school papers much easier.' />
|
|
||||||
<meta property='og:description' name='og:description' content='Convert markdown to APA formatted PDFs. Makes writing school papers much easier.' />
|
|
||||||
<meta property='og:url' name='og:url' content='http://markdowntoapa.com/' />
|
|
||||||
<meta property='og:image' name='og:image' content='http://i.imgur.com/7mgT3KE.png' />
|
|
||||||
|
|
||||||
<style type="text/css">
|
|
||||||
*{
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
#editor, #preview{
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
width: 50%;
|
|
||||||
height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
#editor {
|
|
||||||
left: 0;
|
|
||||||
right: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#preview{
|
|
||||||
left: 50%;
|
|
||||||
right: 0;
|
|
||||||
border: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<pre id="editor">
|
|
||||||
author: Christian R. Genco
|
|
||||||
institution: Southern Methodist University
|
|
||||||
title: How to use MarkdownToAPA.com to\nWrite APA Papers Easier
|
|
||||||
runninghead: WRITE APA PAPERS ON MARKDOWNTOAPA.COM
|
|
||||||
abstract: This paper shows you how to use the website you're viewing it on, MarkdownToAPA.com, to write APA papers in markdown and automatically format them really prettily as a downloadable/printable PDF document. It's pretty meta, yo.
|
|
||||||
keywords: game changing, next facebook, #thedress, document formats are tedious
|
|
||||||
|
|
||||||
Hi! Welcome to MarkdownToAPA.com - a simple website with an even simpler purpose: making it less annoying to generate APA-formatted papers.
|
|
||||||
|
|
||||||
The stuff on the left is editable, and automatically generates the PDF on the right, which can be downloaded and emailed to your professor, or printed out and made into a paper airplane, or whatever else you can do with a PDF. Everything you write is automatically saved as soon as you pause your furious typing, but it's still a good idea to copy and paste it somewhere else every once in a while as a backup. You can even use this website without being connected to the internet!
|
|
||||||
|
|
||||||
The special format on the left is called Markdown. You can easily make things *italic* and **bold**, as well as quote important people:
|
|
||||||
|
|
||||||
> Writing MLA-formatted essays is much easier with markdowntomla.com. I use it all the time when I write essays to foreign dictators, as well as to my wife when I need her to pick up something from the store on the way home (we're a very formal family). (Obama)
|
|
||||||
|
|
||||||
You can also play around with headings:
|
|
||||||
|
|
||||||
# Important Stuff
|
|
||||||
|
|
||||||
I'm going to talk about really important stuff here.
|
|
||||||
|
|
||||||
## Important Stuff I am Wearing
|
|
||||||
|
|
||||||
There's a lot of important stuff out there, but the stuff I'm wearing is a pretty large subset of it. Let's further explore the topic of my clothing.
|
|
||||||
|
|
||||||
### Pants
|
|
||||||
|
|
||||||
My belt holds my pants up, but my belt loops hold my belt up. Who's the real hero?
|
|
||||||
|
|
||||||
### Socks
|
|
||||||
|
|
||||||
Feet can get pretty cold without an external layer of cloth to hold in their heat. I'm not keeping score or anything, but I'd say socks rank pretty high up there.
|
|
||||||
|
|
||||||
# Non-important Stuff
|
|
||||||
|
|
||||||
Actually, most stuff is pretty important. I'll leave this section blank. Except for, of course, the previous sentence.
|
|
||||||
|
|
||||||
Need a page break? Just type three dashes on an empty line.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Whoa, so much more room on this page. There are two things left to cover: the special **author**, **institution**, **runninghead**, **title**, **abstract**, and **keywords** section at the top; and the work's cited page. The former is used for the MLA heading, numbering the pages, and naming your downloaded PDF. The later is pretty self explanatory (look at the markdown source code at the bottom of this essay).
|
|
||||||
|
|
||||||
For help generating those citations, check out bibme.org, and citationmachine.net. Be careful citing Wikipedia, but there's also a handy "cite this page" button on every page.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Conclusions and Future Study
|
|
||||||
|
|
||||||
Get out there and research some cool things to write about! Or just start editing the markdown on the left. Either way, let me know if you have any suggestions for improvement on twitter @cgenco, or through my website at http://christian.gen.co (where I also have a lecture on how to go to college for free, and other websites I've made).
|
|
||||||
|
|
||||||
Want this for MLA? Head over to http://MarkdownToMLA.com
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# References
|
|
||||||
|
|
||||||
Egan, G. (1994). Permutation city. New York: HarperPrism.
|
|
||||||
|
|
||||||
Hacker News. (2015, March 18). In *Wikipedia, The Free Encyclopedia*. Retrieved 08:46, April 7, 2015, from http://en.wikipedia.org/w/index.php?title=Hacker_News&oldid=651986110
|
|
||||||
|
|
||||||
Rowling, J. (1999). *Harry Potter and the Chamber of Secrets*. New York: Arthur A. Levine Books.
|
|
||||||
</pre>
|
|
||||||
<iframe id="preview"></iframe>
|
|
||||||
|
|
||||||
<script type="text/javascript" src="./js/ace.js"></script>
|
|
||||||
<script type="text/javascript" src="./js/ace.mode-markdown.js"></script>
|
|
||||||
<script type="text/javascript" src="./js/ace.theme-textmate.js"></script>
|
|
||||||
<script type="text/javascript" src="./js/markdowntoapa.js"></script>
|
|
||||||
<script>
|
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
||||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
||||||
|
|
||||||
ga('create', 'UA-61649905-1', 'auto');
|
|
||||||
ga('send', 'pageview');
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user