PageSourceSearch

https://aspj.jp/wp-content/plugins/wp-user-frontend/assets/js/upload.js

js aspj.jp collected 2026-10-05 22:13:33 UTC 7,230 bytes, 214 lines download raw bytes

1;(function($) {
2
3    /**
4     * Upload handler helper
5     *
6     * @param string {browse_button} browse_button ID of the pickfile
7     * @param string {container} container ID of the wrapper
8     * @param int {max} maximum number of file uplaods
9     * @param string {type}
10     */
11    window.WPUF_Uploader = function (browse_button, container, max, type, allowed_type, max_file_size) {
12        this.removed_files = [],
13        this.container = container;
14        this.browse_button = browse_button;
15        this.max = max || 1;
16        this.count = $('#' + container).find('.wpuf-attachment-list > li').length; //count how many items are there
17        this.perFileCount = 0; //file count on each upload
18
19        //if no element found on the page, bail out
20        if( !$('#'+browse_button).length ) {
21            return;
22        }
23
24        //instantiate the uploader
25        this.uploader = new plupload.Uploader({
26            runtimes: 'html5,html4',
27            browse_button: browse_button,
28            container: container,
29            multipart: true,
30            multipart_params: {
31                action: 'wpuf_file_upload',
32                form_id: $( '#' + browse_button ).data('form_id')
33            },
34            max_file_count : 2,
35            multiple_queues: false,
36            multi_selection: ( ( browse_button == 'wpuf-avatar-pickfiles' || browse_button == 'wpuf-featured_image-pickfiles' ) ? false : true ),
37            urlstream_upload: true,
38            file_data_name: 'wpuf_file',
39            max_file_size: max_file_size + 'kb',
40            url: wpuf_frontend_upload.plupload.url + '&type=' + type,
41            flash_swf_url: wpuf_frontend_upload.flash_swf_url,
42            filters: [{
43                title: 'Allowed Files',
44                extensions: allowed_type
45            }]
46        });
47
48        //attach event handlers
49        this.uploader.bind('Init', $.proxy(this, 'init'));
50        this.uploader.bind('FilesAdded', $.proxy(this, 'added'));
51        this.uploader.bind('QueueChanged', $.proxy(this, 'upload'));
52        this.uploader.bind('UploadProgress', $.proxy(this, 'progress'));
53        this.uploader.bind('Error', $.proxy(this, 'error'));
54        this.uploader.bind('FileUploaded', $.proxy(this, 'uploaded'));
55
56        this.uploader.init();
57
58        $('#' + container).on('click', 'a.attachment-delete', $.proxy(this.removeAttachment, this));
59    };
60
61    WPUF_Uploader.prototype = {
62
63        init: function (up, params) {
64            this.showHide();
65            $('#' + this.container).prepend('<div class="wpuf-file-warning"></div>');
66        },
67
68        showHide: function () {
69
70            if ( this.count >= this.max) {
71
72                if ( this.count > this.max ) {
73                    $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning );
74                } else {
75                    $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning );
76                }
77
78                $('#' + this.container).find('.file-selector').hide();
79
80                return;
81            };
82            $('#' + this.container + ' .wpuf-file-warning').html( '' );
83            $('#' + this.container).find('.file-selector').show();
84        },
85
86        added: function (up, files) {
87            var $container = $('#' + this.container).find('.wpuf-attachment-upload-filelist');
88
89            this.showHide();
90
91            $.each(files, function(i, file) {
92                $container.append(
93                    '<div class="upload-item" id="' + file.id + '"><div class="progress progress-striped active"><div class="bar"></div></div><div class="filename original">' +
94                    file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +
95                    '</div></div>');
96            });
97
98            up.refresh();
98 // Reposition Flash/Silverlight
99            up.start();
100        },
101
102        upload: function (uploader) {
103
104
105            this.count = uploader.files.length - this.removed_files.length ;
106            this.showHide();
107
108
109        },
110
111        progress: function (up, file) {
112            var item = $('#' + file.id);
113
114            $('.bar', item).css({ width: file.percent + '%' });
115            $('.percent', item).html( file.percent + '%' );
116        },
117
118        error: function (up, error) {
119            $('#' + this.container).find('#' + error.file.id).remove();
120
121            var msg = '';
122            switch(error.code) {
123                case -600:
124                    msg = wpuf_frontend_upload.size_error;
125                    break;
126
127                case -601:
128                    msg = wpuf_frontend_upload.type_error;
129                    break;
130
131                default:
132                    msg = 'Error #' + error.code + ': ' + error.message;
133                    break;
134            }
135
136            alert(msg);
137
138            this.count -= 1;
139            this.showHide();
140            this.uploader.refresh();
141        },
142
143        uploaded: function (up, file, response) {
144            // var res = $.parseJSON(response.response);
145            var self = this;
146
147            $('#' + file.id + " b").html("100%");
148            $('#' + file.id).remove();
149
150            if(response.response !== 'error') {
151
152                this.perFileCount++;
153                var $container = $('#' + this.container).find('.wpuf-attachment-list');
154                $container.append(response.response);
155
156                if ( this.perFileCount > this.max ) {
157                    var attach_id = $('.wpuf-image-wrap:last a.attachment-delete',$container).data('attach_id');
158                    self.removeExtraAttachment(attach_id);
159                    $('.wpuf-image-wrap',$container).last().remove();
160                    this.perFileCount--;
161                }
162
163            } else {
164                alert(response.error);
165
166                this.count -= 1;
167                this.showHide();
168            }
169        },
170
171        removeAttachment: function(e) {
172            e.preventDefault();
173
174            var self = this,
175            el = $(e.currentTarget);
176
177            if ( confirm(wpuf_frontend_upload.confirmMsg) ) {
178                var data = {
179                    'attach_id' : el.data('attach_id'),
180                    'nonce' : wpuf_frontend_upload.nonce,
181                    'action' : 'wpuf_file_del'
182                };
183                this.removed_files.push(data);
184                jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() {
185                    self.perFileCount--;
186                    el.parent().parent().remove();
187
188                    self.count -= 1;
189                    self.showHide();
190                    self.uploader.refresh();
191                });
192            }
193        },
194
195        removeExtraAttachment : function( attach_id ) {
196
197
198            var self = this;
199
200            var data = {
201                'attach_id' : attach_id,
202                'nonce' : wpuf_frontend_upload.nonce,
203                'action' : 'wpuf_file_del'
204            };
205            this.removed_files.push(data);
206            jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() {
207                self.count -= 1;
208                self.showHide();
209                self.uploader.refresh();
210            });
211        }
212
213    };
214})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.