forked from parallax/jsPDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownloadify.js
More file actions
213 lines (176 loc) · 6.31 KB
/
Copy pathdownloadify.js
File metadata and controls
213 lines (176 loc) · 6.31 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
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));
}
});
};