~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-includes/js/swfupload/handlers.dev.js

  • Committer: Chris Jones
  • Date: 2010-01-19 13:17:33 UTC
  • Revision ID: cmsj@tenshu.net-20100119131733-rf31jv9k1v0xzo2h
[CJ] Import wordpress 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
        // Get rid of unused form
9
9
        jQuery('.media-blank').remove();
10
10
        // Collapse a single item
11
 
        if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) {
 
11
        if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) {
12
12
                jQuery('.describe-toggle-on').show();
13
13
                jQuery('.describe-toggle-off').hide();
14
14
                jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
16
16
        // Create a progress bar containing the filename
17
17
        jQuery('#media-items').append('<div id="media-item-' + fileObj.id + '" class="media-item child-of-' + post_id + '"><div class="progress"><div class="bar"></div></div><div class="filename original"><span class="percent"></span> ' + fileObj.name + '</div></div>');
18
18
        // Display the progress div
19
 
        jQuery('#media-item-' + fileObj.id + ' .progress').show();
 
19
        jQuery('.progress', '#media-item-' + fileObj.id).show();
20
20
 
21
21
        // Disable submit and enable cancel
22
22
        jQuery('#insert-gallery').attr('disabled', 'disabled');
29
29
 
30
30
function uploadProgress(fileObj, bytesDone, bytesTotal) {
31
31
        // Lengthen the progress bar
32
 
        var w = jQuery('#media-items').width() - 2;
33
 
        jQuery('#media-item-' + fileObj.id + ' .bar').width( w * bytesDone / bytesTotal );
34
 
        jQuery('#media-item-' + fileObj.id + ' .percent').html( Math.ceil(bytesDone / bytesTotal * 100) + '%' );
 
32
        var w = jQuery('#media-items').width() - 2, item = jQuery('#media-item-' + fileObj.id);
 
33
        jQuery('.bar', item).width( w * bytesDone / bytesTotal );
 
34
        jQuery('.percent', item).html( Math.ceil(bytesDone / bytesTotal * 100) + '%' );
35
35
 
36
36
        if ( bytesDone == bytesTotal )
37
 
                jQuery('#media-item-' + fileObj.id + ' .bar').html('<strong class="crunching">' + swfuploadL10n.crunching + '</strong>');
 
37
                jQuery('.bar', item).html('<strong class="crunching">' + swfuploadL10n.crunching + '</strong>');
38
38
}
39
39
 
40
40
function prepareMediaItem(fileObj, serverData) {
 
41
        var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id);
41
42
        // Move the progress bar to 100%
42
 
        jQuery('#media-item-' + fileObj.id + ' .bar').remove();
43
 
        jQuery('#media-item-' + fileObj.id + ' .progress').hide();
 
43
        jQuery('.bar', item).remove();
 
44
        jQuery('.progress', item).hide();
44
45
 
45
 
        var f = ( typeof shortform == 'undefined' ) ? 1 : 2;
46
46
        // Old style: Append the HTML returned by the server -- thumbnail and form inputs
47
47
        if ( isNaN(serverData) || !serverData ) {
48
 
                jQuery('#media-item-' + fileObj.id).append(serverData);
 
48
                item.append(serverData);
49
49
                prepareMediaItemInit(fileObj);
50
50
        }
51
51
        // New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
52
52
        else {
53
 
                jQuery('#media-item-' + fileObj.id).load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
 
53
                item.load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
54
54
        }
55
55
}
56
 
                
 
56
 
57
57
function prepareMediaItemInit(fileObj) {
58
 
 
 
58
        var item = jQuery('#media-item-' + fileObj.id);
59
59
        // Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename
60
 
        jQuery('#media-item-' + fileObj.id + ' .thumbnail').clone().attr('className', 'pinkynail toggle').prependTo('#media-item-' + fileObj.id);
 
60
        jQuery('.thumbnail', item).clone().attr('className', 'pinkynail toggle').prependTo(item);
61
61
 
62
62
        // Replace the original filename with the new (unique) one assigned during upload
63
 
        jQuery('#media-item-' + fileObj.id + ' .filename.original').replaceWith(jQuery('#media-item-' + fileObj.id + ' .filename.new'));
 
63
        jQuery('.filename.original', item).replaceWith( jQuery('.filename.new', item) );
64
64
 
65
65
        // Also bind toggle to the links
66
 
        jQuery('#media-item-' + fileObj.id + ' a.toggle').click(function(){
67
 
                jQuery(this).siblings('.slidetoggle').slideToggle(150, function(){
68
 
                        var o = jQuery(this).offset();
69
 
                        window.scrollTo(0, o.top-36);
 
66
        jQuery('a.toggle', item).click(function(){
 
67
                jQuery(this).siblings('.slidetoggle').slideToggle(350, function(){
 
68
                        var w = jQuery(window).height(), t = jQuery(this).offset().top, h = jQuery(this).height(), b;
 
69
 
 
70
                        if ( w && t && h ) {
 
71
                b = t + h;
 
72
 
 
73
                if ( b > w && (h + 48) < w )
 
74
                    window.scrollBy(0, b - w + 13);
 
75
                else if ( b > w )
 
76
                    window.scrollTo(0, t - 36);
 
77
            }
70
78
                });
71
 
                jQuery(this).parent().children('.toggle').toggle();
 
79
                jQuery(this).siblings('.toggle').andSelf().toggle();
72
80
                jQuery(this).siblings('a.toggle').focus();
73
81
                return false;
74
82
        });
75
83
 
76
84
        // Bind AJAX to the new Delete button
77
 
        jQuery('#media-item-' + fileObj.id + ' a.delete').click(function(){
 
85
        jQuery('a.delete', item).click(function(){
78
86
                // Tell the server to delete it. TODO: handle exceptions
79
 
                jQuery.ajax({url:'admin-ajax.php',type:'post',success:deleteSuccess,error:deleteError,id:fileObj.id,data:{
80
 
                        id : this.id.replace(/[^0-9]/g,''),
81
 
                        action : 'delete-post',
82
 
                        _ajax_nonce : this.href.replace(/^.*wpnonce=/,'')}
83
 
                        });
 
87
                jQuery.ajax({
 
88
                        url: 'admin-ajax.php',
 
89
                        type: 'post',
 
90
                        success: deleteSuccess,
 
91
                        error: deleteError,
 
92
                        id: fileObj.id,
 
93
                        data: {
 
94
                                id : this.id.replace(/[^0-9]/g, ''),
 
95
                                action : 'trash-post',
 
96
                                _ajax_nonce : this.href.replace(/^.*wpnonce=/,'')
 
97
                        }
 
98
                });
 
99
                return false;
 
100
        });
 
101
 
 
102
        // Bind AJAX to the new Undo button
 
103
        jQuery('a.undo', item).click(function(){
 
104
                // Tell the server to untrash it. TODO: handle exceptions
 
105
                jQuery.ajax({
 
106
                        url: 'admin-ajax.php',
 
107
                        type: 'post',
 
108
                        id: fileObj.id,
 
109
                        data: {
 
110
                                id : this.id.replace(/[^0-9]/g,''),
 
111
                                action: 'untrash-post',
 
112
                                _ajax_nonce: this.href.replace(/^.*wpnonce=/,'')
 
113
                        },
 
114
                        success: function(data, textStatus){
 
115
                                var item = jQuery('#media-item-' + fileObj.id);
 
116
 
 
117
                                if ( type = jQuery('#type-of-' + fileObj.id).val() )
 
118
                                        jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-0+1);
 
119
                                if ( item.hasClass('child-of-'+post_id) )
 
120
                                        jQuery('#attachments-count').text(jQuery('#attachments-count').text()-0+1);
 
121
 
 
122
                                jQuery('.filename .trashnotice', item).remove();
 
123
                                jQuery('.filename .title', item).css('font-weight','normal');
 
124
                                jQuery('a.undo', item).addClass('hidden');
 
125
                                jQuery('a.describe-toggle-on, .menu_order_input', item).show();
 
126
                                item.css( {backgroundColor:'#ceb'} ).animate( {backgroundColor: '#fff'}, { queue: false, duration: 500, complete: function(){ jQuery(this).css({backgroundColor:''}); } }).removeClass('undo');
 
127
                        }
 
128
                });
84
129
                return false;
85
130
        });
86
131
 
87
132
        // Open this item if it says to start open (e.g. to display an error)
88
 
        jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).parent().children('.toggle').toggle();
 
133
        jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).siblings('.toggle').toggle();
89
134
}
90
135
 
91
136
function itemAjaxError(id, html) {
101
146
        if ( data == '0' )
102
147
                return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?');
103
148
 
104
 
        var item = jQuery('#media-item-' + this.id);
 
149
        var id = this.id, item = jQuery('#media-item-' + id);
105
150
 
106
151
        // Decrement the counters.
107
 
        if ( type = jQuery('#type-of-' + this.id).val() )
108
 
                jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-1);
 
152
        if ( type = jQuery('#type-of-' + id).val() )
 
153
                jQuery('#' + type + '-counter').text( jQuery('#' + type + '-counter').text() - 1 );
109
154
        if ( item.hasClass('child-of-'+post_id) )
110
 
                jQuery('#attachments-count').text(jQuery('#attachments-count').text()-1);
 
155
                jQuery('#attachments-count').text( jQuery('#attachments-count').text() - 1 );
111
156
 
112
 
        if ( jQuery('.type-form #media-items>*').length == 1 && jQuery('#media-items .hidden').length > 0 ) {
 
157
        if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) {
113
158
                jQuery('.toggle').toggle();
114
159
                jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden');
115
160
        }
116
161
 
117
162
        // Vanish it.
118
 
        jQuery('#media-item-' + this.id + ' .filename:empty').remove();
119
 
        jQuery('#media-item-' + this.id + ' .filename').append(' <span class="file-error">'+swfuploadL10n.deleted+'</span>').siblings('a.toggle').remove();
120
 
        jQuery('#media-item-' + this.id).children('.describe').css({backgroundColor:'#fff'}).end()
121
 
                        .animate({backgroundColor:'#ffc0c0'}, {queue:false,duration:50})
122
 
                        .animate({minHeight:0,height:36}, 400, null, function(){jQuery(this).children('.describe').remove()})
123
 
                        .animate({backgroundColor:'#fff'}, 400)
124
 
                        .animate({height:0}, 800, null, function(){jQuery(this).remove();updateMediaForm();});
 
163
        jQuery('.toggle', item).toggle();
 
164
        jQuery('.slidetoggle', item).slideUp(200).siblings().removeClass('hidden');
 
165
        item.css( {backgroundColor:'#faa'} ).animate( {backgroundColor:'#f4f4f4'}, {queue:false, duration:500} ).addClass('undo');
 
166
 
 
167
        jQuery('.filename:empty', item).remove();
 
168
        jQuery('.filename .title', item).css('font-weight','bold');
 
169
        jQuery('.filename', item).append('<span class="trashnotice"> ' + swfuploadL10n.deleted + ' </span>').siblings('a.toggle').hide();
 
170
        jQuery('.filename', item).append( jQuery('a.undo', item).removeClass('hidden') );
 
171
        jQuery('.menu_order_input', item).hide();
125
172
 
126
173
        return;
127
174
}
131
178
}
132
179
 
133
180
function updateMediaForm() {
134
 
        storeState();
 
181
        var one = jQuery('form.type-form #media-items').children(), items = jQuery('#media-items').children();
 
182
 
135
183
        // Just one file, no need for collapsible part
136
 
        if ( jQuery('.type-form #media-items>*').length == 1 ) {
137
 
                jQuery('#media-items .slidetoggle').slideDown(500).parent().eq(0).children('.toggle').toggle();
138
 
                jQuery('.type-form .slidetoggle').siblings().addClass('hidden');
 
184
        if ( one.length == 1 ) {
 
185
                jQuery('.slidetoggle', one).slideDown(500).siblings().addClass('hidden').filter('.toggle').toggle();
139
186
        }
140
187
 
141
188
        // Only show Save buttons when there is at least one file.
142
 
        if ( jQuery('#media-items>*').not('.media-blank').length > 0 )
 
189
        if ( items.not('.media-blank').length > 0 )
143
190
                jQuery('.savebutton').show();
144
191
        else
145
192
                jQuery('.savebutton').hide();
146
193
 
147
194
        // Only show Gallery button when there are at least two files.
148
 
        if ( jQuery('#media-items>*').length > 1 )
 
195
        if ( items.length > 1 )
149
196
                jQuery('.insert-gallery').show();
150
197
        else
151
198
                jQuery('.insert-gallery').hide();
245
292
}
246
293
 
247
294
function uploadError(fileObj, errorCode, message) {
248
 
        
 
295
 
249
296
        switch (errorCode) {
250
297
                case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:
251
298
                        wpFileError(fileObj, swfuploadL10n.missing_upload_url);
279
326
}
280
327
 
281
328
// remember the last used image size, alignment and url
282
 
var storeState;
283
 
(function($){
284
 
 
285
 
storeState = function(){
286
 
        var align = getUserSetting('align') || '', imgsize = getUserSetting('imgsize') || '';
287
 
 
288
 
        $('tr.align input[type="radio"]').click(function(){
289
 
                setUserSetting('align', $(this).val());
290
 
        }).filter(function(){
291
 
                if ( $(this).val() == align )
292
 
                        return true;
293
 
                return false;
294
 
        }).attr('checked','checked');
295
 
 
296
 
        $('tr.image-size input[type="radio"]').click(function(){
297
 
                setUserSetting('imgsize', $(this).val());
298
 
        }).filter(function(){
299
 
                if ( $(this).attr('disabled') || $(this).val() != imgsize )
300
 
                        return false;
301
 
                return true;
302
 
        }).attr('checked','checked');
303
 
 
304
 
        $('tr.url button').click(function(){
 
329
jQuery(document).ready(function($){
 
330
        $('input[type="radio"]', '#media-items').live('click', function(){
 
331
                var tr = $(this).closest('tr');
 
332
 
 
333
                if ( $(tr).hasClass('align') )
 
334
                        setUserSetting('align', $(this).val());
 
335
                else if ( $(tr).hasClass('image-size') )
 
336
                        setUserSetting('imgsize', $(this).val());
 
337
        });
 
338
 
 
339
        $('button.button', '#media-items').live('click', function(){
305
340
                var c = this.className || '';
306
 
                c = c.replace(/.*?(url[^ '"]+).*/, '$1');
307
 
                if (c) setUserSetting('urlbutton', c);
308
 
                $(this).siblings('.urlfield').val( $(this).attr('title') );
309
 
        });
310
 
 
311
 
        $('tr.url .urlfield').each(function(){
312
 
                var b = getUserSetting('urlbutton');
313
 
                $(this).val( $(this).siblings('button.'+b).attr('title') );
314
 
        });
315
 
}
316
 
})(jQuery);
 
341
                c = c.match(/url([^ '"]+)/);
 
342
                if ( c && c[1] ) {
 
343
                        setUserSetting('urlbutton', c[1]);
 
344
                        $(this).siblings('.urlfield').val( $(this).attr('title') );
 
345
                }
 
346
        });
 
347
});