~ubuntu-branches/debian/sid/wordpress/sid

« back to all changes in this revision

Viewing changes to debian/missing-sources/plupload-1.5.4/javascript/jquery.plupload.queue/jquery.plupload.queue.js

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2013-09-04 23:18:58 UTC
  • mfrom: (1.2.28)
  • Revision ID: package-import@ubuntu.com-20130904231858-nljmn1buzswh63jk
Tags: 3.6+dfsg-1
* New upstream release.
* Improve wp-settings to verify that $_SERVER['HTTP_X_FORWARDED_PROTO']
  exists before accessing it (avoids a PHP notice).
  Thanks to Paul Dreik <slask@pauldreik.se> for the report and the patch.
* Document in README.Debian the need to login to /wp-admin/ to complete
  an upgrade.
* Drop useless debian/README.source
* Drop 008CVE2008-2392.patch since upstream now disables unfiltered
  uploads by default. See http://core.trac.wordpress.org/ticket/10692
* Drop 009CVE2008-6767.patch since the backto parameter is validated
  against a whitelist, and externally triggered upgrades are not a
  security problem as long as they work.
* Update debian/missing-sources with latest versions.
* Update upstream l10n.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * jquery.plupload.queue.js
3
 
 *
4
 
 * Copyright 2009, Moxiecode Systems AB
5
 
 * Released under GPL License.
6
 
 *
7
 
 * License: http://www.plupload.com/license
8
 
 * Contributing: http://www.plupload.com/contributing
9
 
 */
10
 
 
11
 
// JSLint defined globals
12
 
/*global plupload:false, jQuery:false, alert:false */
13
 
 
14
 
(function($) {
15
 
        var uploaders = {};
16
 
 
17
 
        function _(str) {
18
 
                return plupload.translate(str) || str;
19
 
        }
20
 
 
21
 
        function renderUI(id, target) {
22
 
                // Remove all existing non plupload items
23
 
                target.contents().each(function(i, node) {
24
 
                        node = $(node);
25
 
 
26
 
                        if (!node.is('.plupload')) {
27
 
                                node.remove();
28
 
                        }
29
 
                });
30
 
 
31
 
                target.prepend(
32
 
                        '<div class="plupload_wrapper plupload_scroll">' +
33
 
                                '<div id="' + id + '_container" class="plupload_container">' +
34
 
                                        '<div class="plupload">' +
35
 
                                                '<div class="plupload_header">' +
36
 
                                                        '<div class="plupload_header_content">' +
37
 
                                                                '<div class="plupload_header_title">' + _('Select files') + '</div>' +
38
 
                                                                '<div class="plupload_header_text">' + _('Add files to the upload queue and click the start button.') + '</div>' +
39
 
                                                        '</div>' +
40
 
                                                '</div>' +
41
 
 
42
 
                                                '<div class="plupload_content">' +
43
 
                                                        '<div class="plupload_filelist_header">' +
44
 
                                                                '<div class="plupload_file_name">' + _('Filename') + '</div>' +
45
 
                                                                '<div class="plupload_file_action">&nbsp;</div>' +
46
 
                                                                '<div class="plupload_file_status"><span>' + _('Status') + '</span></div>' +
47
 
                                                                '<div class="plupload_file_size">' + _('Size') + '</div>' +
48
 
                                                                '<div class="plupload_clearer">&nbsp;</div>' +
49
 
                                                        '</div>' +
50
 
 
51
 
                                                        '<ul id="' + id + '_filelist" class="plupload_filelist"></ul>' +
52
 
 
53
 
                                                        '<div class="plupload_filelist_footer">' +
54
 
                                                                '<div class="plupload_file_name">' +
55
 
                                                                        '<div class="plupload_buttons">' +
56
 
                                                                                '<a href="#" class="plupload_button plupload_add">' + _('Add files') + '</a>' +
57
 
                                                                                '<a href="#" class="plupload_button plupload_start">' + _('Start upload') + '</a>' +
58
 
                                                                        '</div>' +
59
 
                                                                        '<span class="plupload_upload_status"></span>' +
60
 
                                                                '</div>' +
61
 
                                                                '<div class="plupload_file_action"></div>' +
62
 
                                                                '<div class="plupload_file_status"><span class="plupload_total_status">0%</span></div>' +
63
 
                                                                '<div class="plupload_file_size"><span class="plupload_total_file_size">0 b</span></div>' +
64
 
                                                                '<div class="plupload_progress">' +
65
 
                                                                        '<div class="plupload_progress_container">' +
66
 
                                                                                '<div class="plupload_progress_bar"></div>' +
67
 
                                                                        '</div>' +
68
 
                                                                '</div>' +
69
 
                                                                '<div class="plupload_clearer">&nbsp;</div>' +
70
 
                                                        '</div>' +
71
 
                                                '</div>' +
72
 
                                        '</div>' +
73
 
                                '</div>' +
74
 
                                '<input type="hidden" id="' + id + '_count" name="' + id + '_count" value="0" />' +
75
 
                        '</div>'
76
 
                );
77
 
        }
78
 
 
79
 
        $.fn.pluploadQueue = function(settings) {
80
 
                if (settings) {
81
 
                        this.each(function() {
82
 
                                var uploader, target, id;
83
 
 
84
 
                                target = $(this);
85
 
                                id = target.attr('id');
86
 
 
87
 
                                if (!id) {
88
 
                                        id = plupload.guid();
89
 
                                        target.attr('id', id);
90
 
                                }
91
 
 
92
 
                                uploader = new plupload.Uploader($.extend({
93
 
                                        dragdrop : true,
94
 
                                        container : id
95
 
                                }, settings));
96
 
 
97
 
                                uploaders[id] = uploader;
98
 
 
99
 
                                function handleStatus(file) {
100
 
                                        var actionClass;
101
 
 
102
 
                                        if (file.status == plupload.DONE) {
103
 
                                                actionClass = 'plupload_done';
104
 
                                        }
105
 
 
106
 
                                        if (file.status == plupload.FAILED) {
107
 
                                                actionClass = 'plupload_failed';
108
 
                                        }
109
 
 
110
 
                                        if (file.status == plupload.QUEUED) {
111
 
                                                actionClass = 'plupload_delete';
112
 
                                        }
113
 
 
114
 
                                        if (file.status == plupload.UPLOADING) {
115
 
                                                actionClass = 'plupload_uploading';
116
 
                                        }
117
 
 
118
 
                                        var icon = $('#' + file.id).attr('class', actionClass).find('a').css('display', 'block');
119
 
                                        if (file.hint) {
120
 
                                                icon.attr('title', file.hint);  
121
 
                                        }
122
 
                                }
123
 
 
124
 
                                function updateTotalProgress() {
125
 
                                        $('span.plupload_total_status', target).html(uploader.total.percent + '%');
126
 
                                        $('div.plupload_progress_bar', target).css('width', uploader.total.percent + '%');
127
 
                                        $('span.plupload_upload_status', target).text(
128
 
                                                _('Uploaded %d/%d files').replace(/%d\/%d/, uploader.total.uploaded+'/'+uploader.files.length)
129
 
                                        );
130
 
                                }
131
 
 
132
 
                                function updateList() {
133
 
                                        var fileList = $('ul.plupload_filelist', target).html(''), inputCount = 0, inputHTML;
134
 
 
135
 
                                        $.each(uploader.files, function(i, file) {
136
 
                                                inputHTML = '';
137
 
 
138
 
                                                if (file.status == plupload.DONE) {
139
 
                                                        if (file.target_name) {
140
 
                                                                inputHTML += '<input type="hidden" name="' + id + '_' + inputCount + '_tmpname" value="' + plupload.xmlEncode(file.target_name) + '" />';
141
 
                                                        }
142
 
 
143
 
                                                        inputHTML += '<input type="hidden" name="' + id + '_' + inputCount + '_name" value="' + plupload.xmlEncode(file.name) + '" />';
144
 
                                                        inputHTML += '<input type="hidden" name="' + id + '_' + inputCount + '_status" value="' + (file.status == plupload.DONE ? 'done' : 'failed') + '" />';
145
 
        
146
 
                                                        inputCount++;
147
 
 
148
 
                                                        $('#' + id + '_count').val(inputCount);
149
 
                                                }
150
 
 
151
 
                                                fileList.append(
152
 
                                                        '<li id="' + file.id + '">' +
153
 
                                                                '<div class="plupload_file_name"><span>' + file.name + '</span></div>' +
154
 
                                                                '<div class="plupload_file_action"><a href="#"></a></div>' +
155
 
                                                                '<div class="plupload_file_status">' + file.percent + '%</div>' +
156
 
                                                                '<div class="plupload_file_size">' + plupload.formatSize(file.size) + '</div>' +
157
 
                                                                '<div class="plupload_clearer">&nbsp;</div>' +
158
 
                                                                inputHTML +
159
 
                                                        '</li>'
160
 
                                                );
161
 
 
162
 
                                                handleStatus(file);
163
 
 
164
 
                                                $('#' + file.id + '.plupload_delete a').click(function(e) {
165
 
                                                        $('#' + file.id).remove();
166
 
                                                        uploader.removeFile(file);
167
 
 
168
 
                                                        e.preventDefault();
169
 
                                                });
170
 
                                        });
171
 
 
172
 
                                        $('span.plupload_total_file_size', target).html(plupload.formatSize(uploader.total.size));
173
 
 
174
 
                                        if (uploader.total.queued === 0) {
175
 
                                                $('span.plupload_add_text', target).text(_('Add files.'));
176
 
                                        } else {
177
 
                                                $('span.plupload_add_text', target).text(uploader.total.queued + ' files queued.');
178
 
                                        }
179
 
 
180
 
                                        $('a.plupload_start', target).toggleClass('plupload_disabled', uploader.files.length == (uploader.total.uploaded + uploader.total.failed));
181
 
 
182
 
                                        // Scroll to end of file list
183
 
                                        fileList[0].scrollTop = fileList[0].scrollHeight;
184
 
 
185
 
                                        updateTotalProgress();
186
 
 
187
 
                                        // Re-add drag message if there is no files
188
 
                                        if (!uploader.files.length && uploader.features.dragdrop && uploader.settings.dragdrop) {
189
 
                                                $('#' + id + '_filelist').append('<li class="plupload_droptext">' + _("Drag files here.") + '</li>');
190
 
                                        }
191
 
                                }
192
 
 
193
 
                                uploader.bind("UploadFile", function(up, file) {
194
 
                                        $('#' + file.id).addClass('plupload_current_file');
195
 
                                });
196
 
 
197
 
                                uploader.bind('Init', function(up, res) {
198
 
                                        renderUI(id, target);
199
 
 
200
 
                                        // Enable rename support
201
 
                                        if (!settings.unique_names && settings.rename) {
202
 
                                                $('#' + id + '_filelist div.plupload_file_name span', target).live('click', function(e) {
203
 
                                                        var targetSpan = $(e.target), file, parts, name, ext = "";
204
 
 
205
 
                                                        // Get file name and split out name and extension
206
 
                                                        file = up.getFile(targetSpan.parents('li')[0].id);
207
 
                                                        name = file.name;
208
 
                                                        parts = /^(.+)(\.[^.]+)$/.exec(name);
209
 
                                                        if (parts) {
210
 
                                                                name = parts[1];
211
 
                                                                ext = parts[2];
212
 
                                                        }
213
 
 
214
 
                                                        // Display input element
215
 
                                                        targetSpan.hide().after('<input type="text" />');
216
 
                                                        targetSpan.next().val(name).focus().blur(function() {
217
 
                                                                targetSpan.show().next().remove();
218
 
                                                        }).keydown(function(e) {
219
 
                                                                var targetInput = $(this);
220
 
 
221
 
                                                                if (e.keyCode == 13) {
222
 
                                                                        e.preventDefault();
223
 
 
224
 
                                                                        // Rename file and glue extension back on
225
 
                                                                        file.name = targetInput.val() + ext;
226
 
                                                                        targetSpan.text(file.name);
227
 
                                                                        targetInput.blur();
228
 
                                                                }
229
 
                                                        });
230
 
                                                });
231
 
                                        }
232
 
 
233
 
                                        $('a.plupload_add', target).attr('id', id + '_browse');
234
 
 
235
 
                                        up.settings.browse_button = id + '_browse';
236
 
 
237
 
                                        // Enable drag/drop
238
 
                                        if (up.features.dragdrop && up.settings.dragdrop) {
239
 
                                                up.settings.drop_element = id + '_filelist';
240
 
                                                $('#' + id + '_filelist').append('<li class="plupload_droptext">' + _("Drag files here.") + '</li>');
241
 
                                        }
242
 
 
243
 
                                        $('#' + id + '_container').attr('title', 'Using runtime: ' + res.runtime);
244
 
 
245
 
                                        $('a.plupload_start', target).click(function(e) {
246
 
                                                if (!$(this).hasClass('plupload_disabled')) {
247
 
                                                        uploader.start();
248
 
                                                }
249
 
 
250
 
                                                e.preventDefault();
251
 
                                        });
252
 
 
253
 
                                        $('a.plupload_stop', target).click(function(e) {
254
 
                                                e.preventDefault();
255
 
                                                uploader.stop();
256
 
                                        });
257
 
 
258
 
                                        $('a.plupload_start', target).addClass('plupload_disabled');
259
 
                                });
260
 
 
261
 
                                uploader.init();
262
 
 
263
 
                                uploader.bind("Error", function(up, err) {
264
 
                                        var file = err.file, message;
265
 
 
266
 
                                        if (file) {
267
 
                                                message = err.message;
268
 
 
269
 
                                                if (err.details) {
270
 
                                                        message += " (" + err.details + ")";
271
 
                                                }
272
 
 
273
 
                                                if (err.code == plupload.FILE_SIZE_ERROR) {
274
 
                                                        alert(_("Error: File too large: ") + file.name);
275
 
                                                }
276
 
 
277
 
                                                if (err.code == plupload.FILE_EXTENSION_ERROR) {
278
 
                                                        alert(_("Error: Invalid file extension: ") + file.name);
279
 
                                                }
280
 
                                                
281
 
                                                file.hint = message;
282
 
                                                $('#' + file.id).attr('class', 'plupload_failed').find('a').css('display', 'block').attr('title', message);
283
 
                                        }
284
 
                                });
285
 
 
286
 
                                uploader.bind('StateChanged', function() {
287
 
                                        if (uploader.state === plupload.STARTED) {
288
 
                                                $('li.plupload_delete a,div.plupload_buttons', target).hide();
289
 
                                                $('span.plupload_upload_status,div.plupload_progress,a.plupload_stop', target).css('display', 'block');
290
 
                                                $('span.plupload_upload_status', target).text('Uploaded ' + uploader.total.uploaded + '/' + uploader.files.length + ' files');
291
 
 
292
 
                                                if (settings.multiple_queues) {
293
 
                                                        $('span.plupload_total_status,span.plupload_total_file_size', target).show();
294
 
                                                }
295
 
                                        } else {
296
 
                                                updateList();
297
 
                                                $('a.plupload_stop,div.plupload_progress', target).hide();
298
 
                                                $('a.plupload_delete', target).css('display', 'block');
299
 
                                        }
300
 
                                });
301
 
 
302
 
                                uploader.bind('QueueChanged', updateList);
303
 
 
304
 
                                uploader.bind('FileUploaded', function(up, file) {
305
 
                                        handleStatus(file);
306
 
                                });
307
 
 
308
 
                                uploader.bind("UploadProgress", function(up, file) {
309
 
                                        // Set file specific progress
310
 
                                        $('#' + file.id + ' div.plupload_file_status', target).html(file.percent + '%');
311
 
 
312
 
                                        handleStatus(file);
313
 
                                        updateTotalProgress();
314
 
 
315
 
                                        if (settings.multiple_queues && uploader.total.uploaded + uploader.total.failed == uploader.files.length) {
316
 
                                                $(".plupload_buttons,.plupload_upload_status", target).css("display", "inline");
317
 
                                                $(".plupload_start", target).addClass("plupload_disabled");
318
 
                                                $('span.plupload_total_status,span.plupload_total_file_size', target).hide();
319
 
                                        }
320
 
                                });
321
 
 
322
 
                                // Call setup function
323
 
                                if (settings.setup) {
324
 
                                        settings.setup(uploader);
325
 
                                }
326
 
                        });
327
 
 
328
 
                        return this;
329
 
                } else {
330
 
                        // Get uploader instance for specified element
331
 
                        return uploaders[$(this[0]).attr('id')];
332
 
                }
333
 
        };
334
 
})(jQuery);