uploader 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/app/controllers/uploader/uploads_controller.rb +74 -62
- data/app/helpers/uploader_helper.rb +1 -0
- data/app/views/uploads/_swf_javascript.html.erb +2 -2
- data/lib/active_record/acts/uploader_upload.rb +20 -1
- data/public/images/cancelbutton.gif +0 -0
- data/public/javascripts/swfupload/swfupload.js +102 -67
- data/public/javascripts/swfupload/swfupload.queue.js +79 -58
- data/public/javascripts/swfupload/swfupload.speed.js +342 -0
- data/public/javascripts/swfupload/swfupload.swfobject.js +4 -3
- data/public/stylesheets/swfupload.css +1 -1
- data/public/swf/swfupload.swf +0 -0
- data/rails/init.rb +3 -3
- data/test/rails_root/app/controllers/uploads_controller.rb +4 -0
- data/test/rails_root/config/environment.rb +3 -3
- data/test/rails_root/db/test.sqlite3 +0 -0
- data/test/rails_root/public/stylesheets/swfupload.css +1 -1
- data/test/rails_root/test/functional/uploads_controller_test.rb +53 -1
- data/test/rails_root/test/test.doc +0 -0
- data/test/rails_root/test/test.pdf +0 -0
- data/test/rails_root/test/test.xls +0 -0
- data/test/rails_root/test/test_helper.rb +5 -1
- data/uploader.gemspec +7 -2
- metadata +7 -2
@@ -1,77 +1,98 @@
|
|
1
1
|
/*
|
2
|
-
Queue Plug-in
|
3
|
-
|
4
|
-
Features:
|
5
|
-
*Adds a cancelQueue() method for cancelling the entire queue.
|
6
|
-
*All queued files are uploaded when startUpload() is called.
|
7
|
-
*If false is returned from uploadComplete then the queue upload is stopped.
|
8
|
-
If false is not returned (strict comparison) then the queue upload is continued.
|
9
|
-
*Adds a QueueComplete event that is fired when all the queued files have finished uploading.
|
10
|
-
Set the event handler with the queue_complete_handler setting.
|
11
|
-
|
12
|
-
*/
|
2
|
+
Queue Plug-in
|
3
|
+
|
4
|
+
Features:
|
5
|
+
*Adds a cancelQueue() method for cancelling the entire queue.
|
6
|
+
*All queued files are uploaded when startUpload() is called.
|
7
|
+
*If false is returned from uploadComplete then the queue upload is stopped.
|
8
|
+
If false is not returned (strict comparison) then the queue upload is continued.
|
9
|
+
*Adds a QueueComplete event that is fired when all the queued files have finished uploading.
|
10
|
+
Set the event handler with the queue_complete_handler setting.
|
11
|
+
|
12
|
+
*/
|
13
13
|
|
14
14
|
var SWFUpload;
|
15
15
|
if (typeof(SWFUpload) === "function") {
|
16
16
|
SWFUpload.queue = {};
|
17
|
-
|
17
|
+
|
18
18
|
SWFUpload.prototype.initSettings = (function (oldInitSettings) {
|
19
19
|
return function () {
|
20
20
|
if (typeof(oldInitSettings) === "function") {
|
21
21
|
oldInitSettings.call(this);
|
22
22
|
}
|
23
|
-
|
24
|
-
this.
|
25
|
-
|
26
|
-
|
27
|
-
this.
|
23
|
+
|
24
|
+
this.queueSettings = {};
|
25
|
+
|
26
|
+
this.queueSettings.queue_cancelled_flag = false;
|
27
|
+
this.queueSettings.queue_upload_count = 0;
|
28
|
+
|
29
|
+
this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
|
30
|
+
this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
|
28
31
|
this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
|
29
|
-
|
32
|
+
this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
|
33
|
+
|
30
34
|
this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
|
31
35
|
};
|
32
|
-
|
36
|
+
})(SWFUpload.prototype.initSettings);
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
SWFUpload.prototype.startUpload = function (fileID) {
|
39
|
+
this.queueSettings.queue_cancelled_flag = false;
|
40
|
+
this.callFlash("StartUpload", [fileID]);
|
41
|
+
};
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
SWFUpload.prototype.cancelQueue = function () {
|
44
|
+
this.queueSettings.queue_cancelled_flag = true;
|
45
|
+
this.stopUpload();
|
46
|
+
|
47
|
+
var stats = this.getStats();
|
48
|
+
while (stats.files_queued > 0) {
|
49
|
+
this.cancelUpload();
|
50
|
+
stats = this.getStats();
|
51
|
+
}
|
52
|
+
};
|
53
|
+
|
54
|
+
SWFUpload.queue.uploadStartHandler = function (file) {
|
55
|
+
var returnValue;
|
56
|
+
if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
|
57
|
+
returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
|
58
|
+
}
|
59
|
+
|
60
|
+
// To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
|
61
|
+
returnValue = (returnValue === false) ? false : true;
|
62
|
+
|
63
|
+
this.queueSettings.queue_cancelled_flag = !returnValue;
|
42
64
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
SWFUpload.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
if (file.file_status === SWFUpload.FILE_STATUS.COMPLETE) {
|
55
|
-
this.customSettings.queue_upload_count++;
|
56
|
-
}
|
65
|
+
return returnValue;
|
66
|
+
};
|
67
|
+
|
68
|
+
SWFUpload.queue.uploadCompleteHandler = function (file) {
|
69
|
+
var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
|
70
|
+
var continueUpload;
|
71
|
+
|
72
|
+
if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
|
73
|
+
this.queueSettings.queue_upload_count++;
|
74
|
+
}
|
57
75
|
|
58
|
-
|
59
|
-
|
76
|
+
if (typeof(user_upload_complete_handler) === "function") {
|
77
|
+
continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
|
78
|
+
} else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
|
79
|
+
// If the file was stopped and re-queued don't restart the upload
|
80
|
+
continueUpload = false;
|
81
|
+
} else {
|
82
|
+
continueUpload = true;
|
83
|
+
}
|
84
|
+
|
85
|
+
if (continueUpload) {
|
86
|
+
var stats = this.getStats();
|
87
|
+
if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
|
88
|
+
this.startUpload();
|
89
|
+
} else if (this.queueSettings.queue_cancelled_flag === false) {
|
90
|
+
this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
|
91
|
+
this.queueSettings.queue_upload_count = 0;
|
60
92
|
} else {
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
if (continueUpload) {
|
65
|
-
var stats = this.getStats();
|
66
|
-
if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) {
|
67
|
-
this.startUpload();
|
68
|
-
} else if (this.customSettings.queue_cancelled_flag === false) {
|
69
|
-
this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]);
|
70
|
-
this.customSettings.queue_upload_count = 0;
|
71
|
-
} else {
|
72
|
-
this.customSettings.queue_cancelled_flag = false;
|
73
|
-
this.customSettings.queue_upload_count = 0;
|
74
|
-
}
|
93
|
+
this.queueSettings.queue_cancelled_flag = false;
|
94
|
+
this.queueSettings.queue_upload_count = 0;
|
75
95
|
}
|
76
|
-
}
|
77
|
-
}
|
96
|
+
}
|
97
|
+
};
|
98
|
+
}
|
@@ -0,0 +1,342 @@
|
|
1
|
+
/*
|
2
|
+
Speed Plug-in
|
3
|
+
|
4
|
+
Features:
|
5
|
+
*Adds several properties to the 'file' object indicated upload speed, time left, upload time, etc.
|
6
|
+
- currentSpeed -- String indicating the upload speed, bytes per second
|
7
|
+
- averageSpeed -- Overall average upload speed, bytes per second
|
8
|
+
- movingAverageSpeed -- Speed over averaged over the last several measurements, bytes per second
|
9
|
+
- timeRemaining -- Estimated remaining upload time in seconds
|
10
|
+
- timeElapsed -- Number of seconds passed for this upload
|
11
|
+
- percentUploaded -- Percentage of the file uploaded (0 to 100)
|
12
|
+
- sizeUploaded -- Formatted size uploaded so far, bytes
|
13
|
+
|
14
|
+
*Adds setting 'moving_average_history_size' for defining the window size used to calculate the moving average speed.
|
15
|
+
|
16
|
+
*Adds several Formatting functions for formatting that values provided on the file object.
|
17
|
+
- SWFUpload.speed.formatBPS(bps) -- outputs string formatted in the best units (Gbps, Mbps, Kbps, bps)
|
18
|
+
- SWFUpload.speed.formatTime(seconds) -- outputs string formatted in the best units (x Hr y M z S)
|
19
|
+
- SWFUpload.speed.formatSize(bytes) -- outputs string formatted in the best units (w GB x MB y KB z B )
|
20
|
+
- SWFUpload.speed.formatPercent(percent) -- outputs string formatted with a percent sign (x.xx %)
|
21
|
+
- SWFUpload.speed.formatUnits(baseNumber, divisionArray, unitLabelArray, fractionalBoolean)
|
22
|
+
- Formats a number using the division array to determine how to apply the labels in the Label Array
|
23
|
+
- factionalBoolean indicates whether the number should be returned as a single fractional number with a unit (speed)
|
24
|
+
or as several numbers labeled with units (time)
|
25
|
+
*/
|
26
|
+
|
27
|
+
var SWFUpload;
|
28
|
+
if (typeof(SWFUpload) === "function") {
|
29
|
+
SWFUpload.speed = {};
|
30
|
+
|
31
|
+
SWFUpload.prototype.initSettings = (function (oldInitSettings) {
|
32
|
+
return function () {
|
33
|
+
if (typeof(oldInitSettings) === "function") {
|
34
|
+
oldInitSettings.call(this);
|
35
|
+
}
|
36
|
+
|
37
|
+
this.ensureDefault = function (settingName, defaultValue) {
|
38
|
+
this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
|
39
|
+
};
|
40
|
+
|
41
|
+
// List used to keep the speed stats for the files we are tracking
|
42
|
+
this.fileSpeedStats = {};
|
43
|
+
this.speedSettings = {};
|
44
|
+
|
45
|
+
this.ensureDefault("moving_average_history_size", "10");
|
46
|
+
|
47
|
+
this.speedSettings.user_file_queued_handler = this.settings.file_queued_handler;
|
48
|
+
this.speedSettings.user_file_queue_error_handler = this.settings.file_queue_error_handler;
|
49
|
+
this.speedSettings.user_upload_start_handler = this.settings.upload_start_handler;
|
50
|
+
this.speedSettings.user_upload_error_handler = this.settings.upload_error_handler;
|
51
|
+
this.speedSettings.user_upload_progress_handler = this.settings.upload_progress_handler;
|
52
|
+
this.speedSettings.user_upload_success_handler = this.settings.upload_success_handler;
|
53
|
+
this.speedSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
|
54
|
+
|
55
|
+
this.settings.file_queued_handler = SWFUpload.speed.fileQueuedHandler;
|
56
|
+
this.settings.file_queue_error_handler = SWFUpload.speed.fileQueueErrorHandler;
|
57
|
+
this.settings.upload_start_handler = SWFUpload.speed.uploadStartHandler;
|
58
|
+
this.settings.upload_error_handler = SWFUpload.speed.uploadErrorHandler;
|
59
|
+
this.settings.upload_progress_handler = SWFUpload.speed.uploadProgressHandler;
|
60
|
+
this.settings.upload_success_handler = SWFUpload.speed.uploadSuccessHandler;
|
61
|
+
this.settings.upload_complete_handler = SWFUpload.speed.uploadCompleteHandler;
|
62
|
+
|
63
|
+
delete this.ensureDefault;
|
64
|
+
};
|
65
|
+
})(SWFUpload.prototype.initSettings);
|
66
|
+
|
67
|
+
|
68
|
+
SWFUpload.speed.fileQueuedHandler = function (file) {
|
69
|
+
if (typeof this.speedSettings.user_file_queued_handler === "function") {
|
70
|
+
file = SWFUpload.speed.extendFile(file);
|
71
|
+
|
72
|
+
return this.speedSettings.user_file_queued_handler.call(this, file);
|
73
|
+
}
|
74
|
+
};
|
75
|
+
|
76
|
+
SWFUpload.speed.fileQueueErrorHandler = function (file, errorCode, message) {
|
77
|
+
if (typeof this.speedSettings.user_file_queue_error_handler === "function") {
|
78
|
+
file = SWFUpload.speed.extendFile(file);
|
79
|
+
|
80
|
+
return this.speedSettings.user_file_queue_error_handler.call(this, file, errorCode, message);
|
81
|
+
}
|
82
|
+
};
|
83
|
+
|
84
|
+
SWFUpload.speed.uploadStartHandler = function (file) {
|
85
|
+
if (typeof this.speedSettings.user_upload_start_handler === "function") {
|
86
|
+
file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
|
87
|
+
return this.speedSettings.user_upload_start_handler.call(this, file);
|
88
|
+
}
|
89
|
+
};
|
90
|
+
|
91
|
+
SWFUpload.speed.uploadErrorHandler = function (file, errorCode, message) {
|
92
|
+
file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
|
93
|
+
SWFUpload.speed.removeTracking(file, this.fileSpeedStats);
|
94
|
+
|
95
|
+
if (typeof this.speedSettings.user_upload_error_handler === "function") {
|
96
|
+
return this.speedSettings.user_upload_error_handler.call(this, file, errorCode, message);
|
97
|
+
}
|
98
|
+
};
|
99
|
+
SWFUpload.speed.uploadProgressHandler = function (file, bytesComplete, bytesTotal) {
|
100
|
+
this.updateTracking(file, bytesComplete);
|
101
|
+
file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
|
102
|
+
|
103
|
+
if (typeof this.speedSettings.user_upload_progress_handler === "function") {
|
104
|
+
return this.speedSettings.user_upload_progress_handler.call(this, file, bytesComplete, bytesTotal);
|
105
|
+
}
|
106
|
+
};
|
107
|
+
|
108
|
+
SWFUpload.speed.uploadSuccessHandler = function (file, serverData) {
|
109
|
+
if (typeof this.speedSettings.user_upload_success_handler === "function") {
|
110
|
+
file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
|
111
|
+
return this.speedSettings.user_upload_success_handler.call(this, file, serverData);
|
112
|
+
}
|
113
|
+
};
|
114
|
+
SWFUpload.speed.uploadCompleteHandler = function (file) {
|
115
|
+
file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
|
116
|
+
SWFUpload.speed.removeTracking(file, this.fileSpeedStats);
|
117
|
+
|
118
|
+
if (typeof this.speedSettings.user_upload_complete_handler === "function") {
|
119
|
+
return this.speedSettings.user_upload_complete_handler.call(this, file);
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
123
|
+
// Private: extends the file object with the speed plugin values
|
124
|
+
SWFUpload.speed.extendFile = function (file, trackingList) {
|
125
|
+
var tracking;
|
126
|
+
|
127
|
+
if (trackingList) {
|
128
|
+
tracking = trackingList[file.id];
|
129
|
+
}
|
130
|
+
|
131
|
+
if (tracking) {
|
132
|
+
file.currentSpeed = tracking.currentSpeed;
|
133
|
+
file.averageSpeed = tracking.averageSpeed;
|
134
|
+
file.movingAverageSpeed = tracking.movingAverageSpeed;
|
135
|
+
file.timeRemaining = tracking.timeRemaining;
|
136
|
+
file.timeElapsed = tracking.timeElapsed;
|
137
|
+
file.percentUploaded = tracking.percentUploaded;
|
138
|
+
file.sizeUploaded = tracking.bytesUploaded;
|
139
|
+
|
140
|
+
} else {
|
141
|
+
file.currentSpeed = 0;
|
142
|
+
file.averageSpeed = 0;
|
143
|
+
file.movingAverageSpeed = 0;
|
144
|
+
file.timeRemaining = 0;
|
145
|
+
file.timeElapsed = 0;
|
146
|
+
file.percentUploaded = 0;
|
147
|
+
file.sizeUploaded = 0;
|
148
|
+
}
|
149
|
+
|
150
|
+
return file;
|
151
|
+
};
|
152
|
+
|
153
|
+
// Private: Updates the speed tracking object, or creates it if necessary
|
154
|
+
SWFUpload.prototype.updateTracking = function (file, bytesUploaded) {
|
155
|
+
var tracking = this.fileSpeedStats[file.id];
|
156
|
+
if (!tracking) {
|
157
|
+
this.fileSpeedStats[file.id] = tracking = {};
|
158
|
+
}
|
159
|
+
|
160
|
+
// Sanity check inputs
|
161
|
+
bytesUploaded = bytesUploaded || tracking.bytesUploaded || 0;
|
162
|
+
if (bytesUploaded < 0) {
|
163
|
+
bytesUploaded = 0;
|
164
|
+
}
|
165
|
+
if (bytesUploaded > file.size) {
|
166
|
+
bytesUploaded = file.size;
|
167
|
+
}
|
168
|
+
|
169
|
+
var tickTime = (new Date()).getTime();
|
170
|
+
if (!tracking.startTime) {
|
171
|
+
tracking.startTime = (new Date()).getTime();
|
172
|
+
tracking.lastTime = tracking.startTime;
|
173
|
+
tracking.currentSpeed = 0;
|
174
|
+
tracking.averageSpeed = 0;
|
175
|
+
tracking.movingAverageSpeed = 0;
|
176
|
+
tracking.movingAverageHistory = [];
|
177
|
+
tracking.timeRemaining = 0;
|
178
|
+
tracking.timeElapsed = 0;
|
179
|
+
tracking.percentUploaded = bytesUploaded / file.size;
|
180
|
+
tracking.bytesUploaded = bytesUploaded;
|
181
|
+
} else if (tracking.startTime > tickTime) {
|
182
|
+
this.debug("When backwards in time");
|
183
|
+
} else {
|
184
|
+
// Get time and deltas
|
185
|
+
var now = (new Date()).getTime();
|
186
|
+
var lastTime = tracking.lastTime;
|
187
|
+
var deltaTime = now - lastTime;
|
188
|
+
var deltaBytes = bytesUploaded - tracking.bytesUploaded;
|
189
|
+
|
190
|
+
if (deltaBytes === 0 || deltaTime === 0) {
|
191
|
+
return tracking;
|
192
|
+
}
|
193
|
+
|
194
|
+
// Update tracking object
|
195
|
+
tracking.lastTime = now;
|
196
|
+
tracking.bytesUploaded = bytesUploaded;
|
197
|
+
|
198
|
+
// Calculate speeds
|
199
|
+
tracking.currentSpeed = (deltaBytes * 8 ) / (deltaTime / 1000);
|
200
|
+
tracking.averageSpeed = (tracking.bytesUploaded * 8) / ((now - tracking.startTime) / 1000);
|
201
|
+
|
202
|
+
// Calculate moving average
|
203
|
+
tracking.movingAverageHistory.push(tracking.currentSpeed);
|
204
|
+
if (tracking.movingAverageHistory.length > this.settings.moving_average_history_size) {
|
205
|
+
tracking.movingAverageHistory.shift();
|
206
|
+
}
|
207
|
+
|
208
|
+
tracking.movingAverageSpeed = SWFUpload.speed.calculateMovingAverage(tracking.movingAverageHistory);
|
209
|
+
|
210
|
+
// Update times
|
211
|
+
tracking.timeRemaining = (file.size - tracking.bytesUploaded) * 8 / tracking.movingAverageSpeed;
|
212
|
+
tracking.timeElapsed = (now - tracking.startTime) / 1000;
|
213
|
+
|
214
|
+
// Update percent
|
215
|
+
tracking.percentUploaded = (tracking.bytesUploaded / file.size * 100);
|
216
|
+
}
|
217
|
+
|
218
|
+
return tracking;
|
219
|
+
};
|
220
|
+
SWFUpload.speed.removeTracking = function (file, trackingList) {
|
221
|
+
try {
|
222
|
+
trackingList[file.id] = null;
|
223
|
+
delete trackingList[file.id];
|
224
|
+
} catch (ex) {
|
225
|
+
}
|
226
|
+
};
|
227
|
+
|
228
|
+
SWFUpload.speed.formatUnits = function (baseNumber, unitDivisors, unitLabels, singleFractional) {
|
229
|
+
var i, unit, unitDivisor, unitLabel;
|
230
|
+
|
231
|
+
if (baseNumber === 0) {
|
232
|
+
return "0 " + unitLabels[unitLabels.length - 1];
|
233
|
+
}
|
234
|
+
|
235
|
+
if (singleFractional) {
|
236
|
+
unit = baseNumber;
|
237
|
+
unitLabel = unitLabels.length >= unitDivisors.length ? unitLabels[unitDivisors.length - 1] : "";
|
238
|
+
for (i = 0; i < unitDivisors.length; i++) {
|
239
|
+
if (baseNumber >= unitDivisors[i]) {
|
240
|
+
unit = (baseNumber / unitDivisors[i]).toFixed(2);
|
241
|
+
unitLabel = unitLabels.length >= i ? " " + unitLabels[i] : "";
|
242
|
+
break;
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
return unit + unitLabel;
|
247
|
+
} else {
|
248
|
+
var formattedStrings = [];
|
249
|
+
var remainder = baseNumber;
|
250
|
+
|
251
|
+
for (i = 0; i < unitDivisors.length; i++) {
|
252
|
+
unitDivisor = unitDivisors[i];
|
253
|
+
unitLabel = unitLabels.length > i ? " " + unitLabels[i] : "";
|
254
|
+
|
255
|
+
unit = remainder / unitDivisor;
|
256
|
+
if (i < unitDivisors.length -1) {
|
257
|
+
unit = Math.floor(unit);
|
258
|
+
} else {
|
259
|
+
unit = unit.toFixed(2);
|
260
|
+
}
|
261
|
+
if (unit > 0) {
|
262
|
+
remainder = remainder % unitDivisor;
|
263
|
+
|
264
|
+
formattedStrings.push(unit + unitLabel);
|
265
|
+
}
|
266
|
+
}
|
267
|
+
|
268
|
+
return formattedStrings.join(" ");
|
269
|
+
}
|
270
|
+
};
|
271
|
+
|
272
|
+
SWFUpload.speed.formatBPS = function (baseNumber) {
|
273
|
+
var bpsUnits = [1073741824, 1048576, 1024, 1], bpsUnitLabels = ["Gbps", "Mbps", "Kbps", "bps"];
|
274
|
+
return SWFUpload.speed.formatUnits(baseNumber, bpsUnits, bpsUnitLabels, true);
|
275
|
+
|
276
|
+
};
|
277
|
+
SWFUpload.speed.formatTime = function (baseNumber) {
|
278
|
+
var timeUnits = [86400, 3600, 60, 1], timeUnitLabels = ["d", "h", "m", "s"];
|
279
|
+
return SWFUpload.speed.formatUnits(baseNumber, timeUnits, timeUnitLabels, false);
|
280
|
+
|
281
|
+
};
|
282
|
+
SWFUpload.speed.formatBytes = function (baseNumber) {
|
283
|
+
var sizeUnits = [1073741824, 1048576, 1024, 1], sizeUnitLabels = ["GB", "MB", "KB", "bytes"];
|
284
|
+
return SWFUpload.speed.formatUnits(baseNumber, sizeUnits, sizeUnitLabels, true);
|
285
|
+
|
286
|
+
};
|
287
|
+
SWFUpload.speed.formatPercent = function (baseNumber) {
|
288
|
+
return baseNumber.toFixed(2) + " %";
|
289
|
+
};
|
290
|
+
|
291
|
+
SWFUpload.speed.calculateMovingAverage = function (history) {
|
292
|
+
var vals = [], size, sum = 0.0, mean = 0.0, varianceTemp = 0.0, variance = 0.0, standardDev = 0.0;
|
293
|
+
var i;
|
294
|
+
var mSum = 0, mCount = 0;
|
295
|
+
|
296
|
+
size = history.length;
|
297
|
+
|
298
|
+
// Check for sufficient data
|
299
|
+
if (size >= 8) {
|
300
|
+
// Clone the array and Calculate sum of the values
|
301
|
+
for (i = 0; i < size; i++) {
|
302
|
+
vals[i] = history[i];
|
303
|
+
sum += vals[i];
|
304
|
+
}
|
305
|
+
|
306
|
+
mean = sum / size;
|
307
|
+
|
308
|
+
// Calculate variance for the set
|
309
|
+
for (i = 0; i < size; i++) {
|
310
|
+
varianceTemp += Math.pow((vals[i] - mean), 2);
|
311
|
+
}
|
312
|
+
|
313
|
+
variance = varianceTemp / size;
|
314
|
+
standardDev = Math.sqrt(variance);
|
315
|
+
|
316
|
+
//Standardize the Data
|
317
|
+
for (i = 0; i < size; i++) {
|
318
|
+
vals[i] = (vals[i] - mean) / standardDev;
|
319
|
+
}
|
320
|
+
|
321
|
+
// Calculate the average excluding outliers
|
322
|
+
var deviationRange = 2.0;
|
323
|
+
for (i = 0; i < size; i++) {
|
324
|
+
|
325
|
+
if (vals[i] <= deviationRange && vals[i] >= -deviationRange) {
|
326
|
+
mCount++;
|
327
|
+
mSum += history[i];
|
328
|
+
}
|
329
|
+
}
|
330
|
+
|
331
|
+
} else {
|
332
|
+
// Calculate the average (not enough data points to remove outliers)
|
333
|
+
mCount = size;
|
334
|
+
for (i = 0; i < size; i++) {
|
335
|
+
mSum += history[i];
|
336
|
+
}
|
337
|
+
}
|
338
|
+
|
339
|
+
return mSum / mCount;
|
340
|
+
};
|
341
|
+
|
342
|
+
}
|
@@ -38,11 +38,12 @@
|
|
38
38
|
*/
|
39
39
|
|
40
40
|
|
41
|
-
/*
|
42
|
-
Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis
|
41
|
+
/* SWFObject v2.1 <http://code.google.com/p/swfobject/>
|
42
|
+
Copyright (c) 2007-2008 Geoff Stearns, Michael Williams, and Bobby van der Sluis
|
43
43
|
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
44
44
|
*/
|
45
|
-
var swfobject=function(){var
|
45
|
+
var swfobject=function(){var b="undefined",Q="object",n="Shockwave Flash",p="ShockwaveFlash.ShockwaveFlash",P="application/x-shockwave-flash",m="SWFObjectExprInst",j=window,K=document,T=navigator,o=[],N=[],i=[],d=[],J,Z=null,M=null,l=null,e=false,A=false;var h=function(){var v=typeof K.getElementById!=b&&typeof K.getElementsByTagName!=b&&typeof K.createElement!=b,AC=[0,0,0],x=null;if(typeof T.plugins!=b&&typeof T.plugins[n]==Q){x=T.plugins[n].description;if(x&&!(typeof T.mimeTypes!=b&&T.mimeTypes[P]&&!T.mimeTypes[P].enabledPlugin)){x=x.replace(/^.*\s+(\S+\s+\S+$)/,"$1");AC[0]=parseInt(x.replace(/^(.*)\..*$/,"$1"),10);AC[1]=parseInt(x.replace(/^.*\.(.*)\s.*$/,"$1"),10);AC[2]=/r/.test(x)?parseInt(x.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof j.ActiveXObject!=b){var y=null,AB=false;try{y=new ActiveXObject(p+".7")}catch(t){try{y=new ActiveXObject(p+".6");AC=[6,0,21];y.AllowScriptAccess="always"}catch(t){if(AC[0]==6){AB=true}}if(!AB){try{y=new ActiveXObject(p)}catch(t){}}}if(!AB&&y){try{x=y.GetVariable("$version");if(x){x=x.split(" ")[1].split(",");AC=[parseInt(x[0],10),parseInt(x[1],10),parseInt(x[2],10)]}}catch(t){}}}}var AD=T.userAgent.toLowerCase(),r=T.platform.toLowerCase(),AA=/webkit/.test(AD)?parseFloat(AD.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,q=false,z=r?/win/.test(r):/win/.test(AD),w=r?/mac/.test(r):/mac/.test(AD);/*@cc_on q=true;@if(@_win32)z=true;@elif(@_mac)w=true;@end@*/return{w3cdom:v,pv:AC,webkit:AA,ie:q,win:z,mac:w}}();var L=function(){if(!h.w3cdom){return }f(H);if(h.ie&&h.win){try{K.write("<script id=__ie_ondomload defer=true src=//:><\/script>");J=C("__ie_ondomload");if(J){I(J,"onreadystatechange",S)}}catch(q){}}if(h.webkit&&typeof K.readyState!=b){Z=setInterval(function(){if(/loaded|complete/.test(K.readyState)){E()}},10)}if(typeof K.addEventListener!=b){K.addEventListener("DOMContentLoaded",E,null)}R(E)}();function S(){if(J.readyState=="complete"){J.parentNode.removeChild(J);E()}}function E(){if(e){return }if(h.ie&&h.win){var v=a("span");try{var u=K.getElementsByTagName("body")[0].appendChild(v);u.parentNode.removeChild(u)}catch(w){return }}e=true;if(Z){clearInterval(Z);Z=null}var q=o.length;for(var r=0;r<q;r++){o[r]()}}function f(q){if(e){q()}else{o[o.length]=q}}function R(r){if(typeof j.addEventListener!=b){j.addEventListener("load",r,false)}else{if(typeof K.addEventListener!=b){K.addEventListener("load",r,false)}else{if(typeof j.attachEvent!=b){I(j,"onload",r)}else{if(typeof j.onload=="function"){var q=j.onload;j.onload=function(){q();r()}}else{j.onload=r}}}}}function H(){var t=N.length;for(var q=0;q<t;q++){var u=N[q].id;if(h.pv[0]>0){var r=C(u);if(r){N[q].width=r.getAttribute("width")?r.getAttribute("width"):"0";N[q].height=r.getAttribute("height")?r.getAttribute("height"):"0";if(c(N[q].swfVersion)){if(h.webkit&&h.webkit<312){Y(r)}W(u,true)}else{if(N[q].expressInstall&&!A&&c("6.0.65")&&(h.win||h.mac)){k(N[q])}else{O(r)}}}}else{W(u,true)}}}function Y(t){var q=t.getElementsByTagName(Q)[0];if(q){var w=a("embed"),y=q.attributes;if(y){var v=y.length;for(var u=0;u<v;u++){if(y[u].nodeName=="DATA"){w.setAttribute("src",y[u].nodeValue)}else{w.setAttribute(y[u].nodeName,y[u].nodeValue)}}}var x=q.childNodes;if(x){var z=x.length;for(var r=0;r<z;r++){if(x[r].nodeType==1&&x[r].nodeName=="PARAM"){w.setAttribute(x[r].getAttribute("name"),x[r].getAttribute("value"))}}}t.parentNode.replaceChild(w,t)}}function k(w){A=true;var u=C(w.id);if(u){if(w.altContentId){var y=C(w.altContentId);if(y){M=y;l=w.altContentId}}else{M=G(u)}if(!(/%$/.test(w.width))&&parseInt(w.width,10)<310){w.width="310"}if(!(/%$/.test(w.height))&&parseInt(w.height,10)<137){w.height="137"}K.title=K.title.slice(0,47)+" - Flash Player Installation";var z=h.ie&&h.win?"ActiveX":"PlugIn",q=K.title,r="MMredirectURL="+j.location+"&MMplayerType="+z+"&MMdoctitle="+q,x=w.id;if(h.ie&&h.win&&u.readyState!=4){var t=a("div");x+="SWFObjectNew";t.setAttribute("id",x);u.parentNode.insertBefore(t,u);u.style.display="none";var v=function(){u.parentNode.removeChild(u)};I(j,"onload",v)}U({data:w.expressInstall,id:m,width:w.width,height:w.height},{flashvars:r},x)}}function O(t){if(h.ie&&h.win&&t.readyState!=4){var r=a("div");t.parentNode.insertBefore(r,t);r.parentNode.replaceChild(G(t),r);t.style.display="none";var q=function(){t.parentNode.removeChild(t)};I(j,"onload",q)}else{t.parentNode.replaceChild(G(t),t)}}function G(v){var u=a("div");if(h.win&&h.ie){u.innerHTML=v.innerHTML}else{var r=v.getElementsByTagName(Q)[0];if(r){var w=r.childNodes;if(w){var q=w.length;for(var t=0;t<q;t++){if(!(w[t].nodeType==1&&w[t].nodeName=="PARAM")&&!(w[t].nodeType==8)){u.appendChild(w[t].cloneNode(true))}}}}}return u}function U(AG,AE,t){var q,v=C(t);if(v){if(typeof AG.id==b){AG.id=t}if(h.ie&&h.win){var AF="";for(var AB in AG){if(AG[AB]!=Object.prototype[AB]){if(AB.toLowerCase()=="data"){AE.movie=AG[AB]}else{if(AB.toLowerCase()=="styleclass"){AF+=' class="'+AG[AB]+'"'}else{if(AB.toLowerCase()!="classid"){AF+=" "+AB+'="'+AG[AB]+'"'}}}}}var AD="";for(var AA in AE){if(AE[AA]!=Object.prototype[AA]){AD+='<param name="'+AA+'" value="'+AE[AA]+'" />'}}v.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AF+">"+AD+"</object>";i[i.length]=AG.id;q=C(AG.id)}else{if(h.webkit&&h.webkit<312){var AC=a("embed");AC.setAttribute("type",P);for(var z in AG){if(AG[z]!=Object.prototype[z]){if(z.toLowerCase()=="data"){AC.setAttribute("src",AG[z])}else{if(z.toLowerCase()=="styleclass"){AC.setAttribute("class",AG[z])}else{if(z.toLowerCase()!="classid"){AC.setAttribute(z,AG[z])}}}}}for(var y in AE){if(AE[y]!=Object.prototype[y]){if(y.toLowerCase()!="movie"){AC.setAttribute(y,AE[y])}}}v.parentNode.replaceChild(AC,v);q=AC}else{var u=a(Q);u.setAttribute("type",P);for(var x in AG){if(AG[x]!=Object.prototype[x]){if(x.toLowerCase()=="styleclass"){u.setAttribute("class",AG[x])}else{if(x.toLowerCase()!="classid"){u.setAttribute(x,AG[x])}}}}for(var w in AE){if(AE[w]!=Object.prototype[w]&&w.toLowerCase()!="movie"){F(u,w,AE[w])}}v.parentNode.replaceChild(u,v);q=u}}}return q}function F(t,q,r){var u=a("param");u.setAttribute("name",q);u.setAttribute("value",r);t.appendChild(u)}function X(r){var q=C(r);if(q&&(q.nodeName=="OBJECT"||q.nodeName=="EMBED")){if(h.ie&&h.win){if(q.readyState==4){B(r)}else{j.attachEvent("onload",function(){B(r)})}}else{q.parentNode.removeChild(q)}}}function B(t){var r=C(t);if(r){for(var q in r){if(typeof r[q]=="function"){r[q]=null}}r.parentNode.removeChild(r)}}function C(t){var q=null;try{q=K.getElementById(t)}catch(r){}return q}function a(q){return K.createElement(q)}function I(t,q,r){t.attachEvent(q,r);d[d.length]=[t,q,r]}function c(t){var r=h.pv,q=t.split(".");q[0]=parseInt(q[0],10);q[1]=parseInt(q[1],10)||0;q[2]=parseInt(q[2],10)||0;return(r[0]>q[0]||(r[0]==q[0]&&r[1]>q[1])||(r[0]==q[0]&&r[1]==q[1]&&r[2]>=q[2]))?true:false}function V(v,r){if(h.ie&&h.mac){return }var u=K.getElementsByTagName("head")[0],t=a("style");t.setAttribute("type","text/css");t.setAttribute("media","screen");if(!(h.ie&&h.win)&&typeof K.createTextNode!=b){t.appendChild(K.createTextNode(v+" {"+r+"}"))}u.appendChild(t);if(h.ie&&h.win&&typeof K.styleSheets!=b&&K.styleSheets.length>0){var q=K.styleSheets[K.styleSheets.length-1];if(typeof q.addRule==Q){q.addRule(v,r)}}}function W(t,q){var r=q?"visible":"hidden";if(e&&C(t)){C(t).style.visibility=r}else{V("#"+t,"visibility:"+r)}}function g(s){var r=/[\\\"<>\.;]/;var q=r.exec(s)!=null;return q?encodeURIComponent(s):s}var D=function(){if(h.ie&&h.win){window.attachEvent("onunload",function(){var w=d.length;for(var v=0;v<w;v++){d[v][0].detachEvent(d[v][1],d[v][2])}var t=i.length;for(var u=0;u<t;u++){X(i[u])}for(var r in h){h[r]=null}h=null;for(var q in swfobject){swfobject[q]=null}swfobject=null})}}();return{registerObject:function(u,q,t){if(!h.w3cdom||!u||!q){return }var r={};r.id=u;r.swfVersion=q;r.expressInstall=t?t:false;N[N.length]=r;W(u,false)},getObjectById:function(v){var q=null;if(h.w3cdom){var t=C(v);if(t){var u=t.getElementsByTagName(Q)[0];if(!u||(u&&typeof t.SetVariable!=b)){q=t}else{if(typeof u.SetVariable!=b){q=u}}}}return q},embedSWF:function(x,AE,AB,AD,q,w,r,z,AC){if(!h.w3cdom||!x||!AE||!AB||!AD||!q){return }AB+="";AD+="";if(c(q)){W(AE,false);var AA={};if(AC&&typeof AC===Q){for(var v in AC){if(AC[v]!=Object.prototype[v]){AA[v]=AC[v]}}}AA.data=x;AA.width=AB;AA.height=AD;var y={};if(z&&typeof z===Q){for(var u in z){if(z[u]!=Object.prototype[u]){y[u]=z[u]}}}if(r&&typeof r===Q){for(var t in r){if(r[t]!=Object.prototype[t]){if(typeof y.flashvars!=b){y.flashvars+="&"+t+"="+r[t]}else{y.flashvars=t+"="+r[t]}}}}f(function(){U(AA,y,AE);if(AA.id==AE){W(AE,true)}})}else{if(w&&!A&&c("6.0.65")&&(h.win||h.mac)){A=true;W(AE,false);f(function(){var AF={};AF.id=AF.altContentId=AE;AF.width=AB;AF.height=AD;AF.expressInstall=w;k(AF)})}}},getFlashPlayerVersion:function(){return{major:h.pv[0],minor:h.pv[1],release:h.pv[2]}},hasFlashPlayerVersion:c,createSWF:function(t,r,q){if(h.w3cdom){return U(t,r,q)}else{return undefined}},removeSWF:function(q){if(h.w3cdom){X(q)}},createCSS:function(r,q){if(h.w3cdom){V(r,q)}},addDomLoadEvent:f,addLoadEvent:R,getQueryParamValue:function(v){var u=K.location.search||K.location.hash;if(v==null){return g(u)}if(u){var t=u.substring(1).split("&");for(var r=0;r<t.length;r++){if(t[r].substring(0,t[r].indexOf("="))==v){return g(t[r].substring((t[r].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(A&&M){var q=C(m);if(q){q.parentNode.replaceChild(M,q);if(l){W(l,true);if(h.ie&&h.win){M.style.display="block"}}M=null;l=null;A=false}}}}}();
|
46
|
+
|
46
47
|
|
47
48
|
|
48
49
|
var SWFUpload;
|
@@ -22,5 +22,5 @@ div.uploadStatus{margin:5px;}
|
|
22
22
|
.swfupload_container a.progressCancel{font-size:0;display:block;height:14px;width:14px;background-image:url(../images/cancelbutton.gif);background-repeat:no-repeat;background-position:-14px 0px;float:right;}
|
23
23
|
.swfupload_container a.progressCancel:hover{background-position:0px 0px;}
|
24
24
|
|
25
|
-
.swf-error-msg{
|
25
|
+
.swf-error-msg{margin:1em 0;padding:10px 20px;border:solid 1px #FFDD99;background-color:#FFFFCC;overflow:hidden;}
|
26
26
|
.swf_cancel_button{margin-left: 2px; height: 22px; font-size: 8pt;}
|
data/public/swf/swfupload.swf
CHANGED
Binary file
|
data/rails/init.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
begin
|
2
|
-
require '
|
2
|
+
require 'paperclip'
|
3
3
|
rescue LoadError
|
4
4
|
begin
|
5
|
-
gem '
|
5
|
+
gem 'paperclip'
|
6
6
|
rescue Gem::LoadError
|
7
|
-
puts "Please install the
|
7
|
+
puts "Please install the paperclip gem"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
RAILS_GEM_VERSION = '2.3.
|
1
|
+
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
|
2
2
|
|
3
3
|
require File.join(File.dirname(__FILE__), 'boot')
|
4
4
|
|
@@ -11,7 +11,7 @@ require 'yaml'
|
|
11
11
|
class << GlobalConfig
|
12
12
|
def prepare_options_for_attachment_fu(options)
|
13
13
|
attachment_fu_options = options.symbolize_keys.merge({:storage => options['storage'].to_sym,
|
14
|
-
:max_size => options['max_size'].to_i.megabytes})
|
14
|
+
:max_size => options['max_size'].to_i.megabytes})
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -24,6 +24,6 @@ end
|
|
24
24
|
Rails::Initializer.run do |config|
|
25
25
|
config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
|
26
26
|
config.time_zone = 'UTC'
|
27
|
-
config.gem '
|
27
|
+
config.gem 'paperclip'
|
28
28
|
config.plugin_locators << TestGemLocator
|
29
29
|
end
|
Binary file
|