Dotclear

source: admin/js/_media.js @ 1039:b5eab1d920f7

Revision 1039:b5eab1d920f7, 3.0 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

The media enhanced uploader may now be temporarily enabled or disabled, fixes #1284

Line 
1$(function() {
2     // Replace remove links by a POST on hidden form
3     fileRemoveAct();
4     
5     function fileRemoveAct() {
6          $('a.media-remove').click(function() {
7               var m_name = $(this).parents('ul').find('li:first>a').text();
8               if (window.confirm(dotclear.msg.confirm_delete_media.replace('%s',m_name))) {
9                    var f = $('#media-remove-hide').get(0);
10                    f.elements['remove'].value = this.href.replace(/^(.*)&remove=(.*?)(&|$)/,'$2');
11                    this.href = '';
12                    f.submit();
13               }
14               return false;
15          });
16     }
17     
18     if (!$.browser.opera) {
19          var upldr = $('<a href="#" id="cu-enable">' + dotclear.msg.activate_enhanced_uploader + '</a>').click( function() {
20               candyUploadInit();
21               return false;
22          });
23          $('#media-upload').append($('<div></div>').append(upldr));
24          if ((dotclear.candyUpload_force_init == '1') || (($.cookie('dc_candy_upl') == 1))) {
25               candyUploadInit();
26          }
27     }
28     
29     function candyUploadInit()
30     {
31          var candy_upload_success = false;
32          var candy_upload_form_url = $('#media-upload').attr('action') + '&file_sort=date-desc&d=' + $('#media-upload input[name=d]').val();
33          var candy_upload_limit = $('#media-upload input[name=MAX_FILE_SIZE]').val();
34          $('#media-upload').candyUpload({
35               upload_url: dotclear.candyUpload.base_url + '/media.php',
36               flash_movie: dotclear.candyUpload.movie_url,
37               file_size_limit: candy_upload_limit + 'b',
38               params: 'swfupload=1&amp;' + dotclear.candyUpload.params,
39               
40               callbacks: {
41                    createControls: function() {
42                         var _this = this;
43                         this.ctrl.btn_browse.hide();
44                         this.ctrl.msg.html(dotclear.msg.load_enhanced_uploader);
45                         var l = $('<a href="#">' + dotclear.msg.disable_enhanced_uploader + '</a>').click(function() {
46                              _this.upldr.destroy();
47                              _this.ctrl.block.empty().remove();
48                              $('#media-upload').show();
49                              delete _this;
50                              $.cookie('dc_candy_upl','',{expires:-1});
51                              return false;
52                         });
53                         this.ctrl.disable = $('<div class="cu-disable"></div>').append(l).appendTo(this.ctrl.block);
54                    },
55                    flashReady: function() {
56                         var _this = this;
57                         this.ctrl.msg.fadeOut('fast',function() {
58                              $(this).text(_this.locales.no_file_in_queue).fadeIn('fast');
59                              _this.ctrl.btn_browse.fadeIn('fast',function() {
60                                   _this.upldr.container.children().css({
61                                        width: $('.cu-btn-browse').width(),
62                                        height: $('.cu-btn-browse').height()
63                                   });
64                              });
65                         });
66                    },
67                    uploadSuccess: function(o,data) {
68                         if (data == 'ok') {
69                              candy_upload_success = true;
70                              this.fileMsg(o.id,this.locales.file_uploaded);
71                         } else {
72                              this.fileErrorMsg(o.id,data);
73                         }
74                         
75                         // uploads finished and at least one success
76                         if (candy_upload_success && $('div.cu-file:has(span.cu-filecancel a)',this.ctrl.files).length == 0) {
77                              $.cookie('dc_candy_upl','1',{expires: 30});
78                              $.get(candy_upload_form_url,function(data) {
79                                   var media = $('div.media-list');
80                                   media.after($('div.media-list',data)).remove();
81                                   fileRemoveAct();
82                              });
83                         }
84                    },
85                    fileQueued: function() {
86                         positionFooter();
87                    }
88               }
89          });
90     }
91});
Note: See TracBrowser for help on using the repository browser.

Sites map