-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.savefile.js
More file actions
executable file
·41 lines (38 loc) · 1.06 KB
/
jquery.savefile.js
File metadata and controls
executable file
·41 lines (38 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Generated by CoffeeScript 1.7.1
(function() {
var $;
$ = jQuery;
$.fn.savefile = function(options) {
var buildFilename, buildForm, buildURL, settings;
settings = $.extend({
filename: 'file',
extension: 'txt'
}, options);
buildURL = function(filename, content) {
var url;
url = "https://savefile.herokuapp.com/" + (encodeURIComponent(filename));
if (content) {
return url += encodeURIComponent(content);
}
};
buildFilename = "" + settings.filename + "." + settings.extension;
buildForm = function(content) {
return $('<form></form>', {
action: buildURL(buildFilename()),
method: 'POST'
}).append($('<input></input>', {
type: 'hidden',
name: 'content',
value: content
}));
};
return this.each(function() {
var content;
content = this.val() !== "" ? this.val() : this.text();
if (settings.content != null) {
content = settings.content;
}
return buildForm(content).submit();
});
};
}).call(this);