diff --git a/admin/file-upload-js.php b/admin/file-upload-js.php index 035e098c..d7a363f2 100644 --- a/admin/file-upload-js.php +++ b/admin/file-upload-js.php @@ -27,6 +27,25 @@ $(document).ready(function() { loading = $('') .appendTo(document.body); + function updateAttacmentNumber () { + var btn = $('#tab-files-btn'), + balloon = $('.balloon', btn), + count = $('#file-list li').length; + + if (count > 0) { + if (!balloon.length) { + btn.html($.trim(btn.html()) + ' '); + balloon = $('').appendTo(btn); + } + + balloon.html(count); + } else if (0 == count && balloon.length > 0) { + balloon.remove(); + } + } + + updateAttacmentNumber(); + function fileUploadStart (file, id) { $('
  • ' + file + '
  • ').prependTo('#file-list'); @@ -45,12 +64,14 @@ $(document).ready(function() { attachInsertEvent(li); attachDeleteEvent(li); + updateAttacmentNumber(); } - $('.upload-file').fileUpload({ - url : 'index('/action/upload' - . (isset($fileParentContent) ? '?cid=' . $fileParentContent->cid : '')); ?>', - types : index('/action/upload' + . (isset($fileParentContent) ? '?cid=' . $fileParentContent->cid : '')); ?>', + types : allowedattachmenttypes; $attachmenttypescount = count($attachmenttypes); $types = array(); @@ -61,13 +82,14 @@ $(document).ready(function() { echo json_encode($types); ?>, - typesError : '', - onUpload : fileUploadStart, - onError : function (id) { - $('#' + id).remove(); - alert(errorWord); - }, - onComplete : fileUploadComplete + typesError : '', + onUpload : fileUploadStart, + onError : function (id) { + $('#' + id).remove(); + alert(errorWord); + }, + onComplete : fileUploadComplete + }); }); $('#upload-panel').filedrop({ @@ -178,6 +200,7 @@ $(document).ready(function() { function () { $(el).fadeOut(function () { $(this).remove(); + updateAttacmentNumber(); }); }); } diff --git a/admin/write-js.php b/admin/write-js.php index fef470fd..da0a935a 100644 --- a/admin/write-js.php +++ b/admin/write-js.php @@ -186,12 +186,19 @@ $(document).ready(function() { }); // 控制附件和参数的转换 + var fileUploadInit = false; $("#edit-secondary .typecho-option-tabs li").click(function() { $("#edit-secondary .typecho-option-tabs li").removeClass('active'); $(this).addClass("active"); $(".tab-content").hide(); - var selected_tab = $(this).find("a").attr("href"); - $(selected_tab).show(); + var selected_tab = $(this).find("a").attr("href"), + selected_el = $(selected_tab).show(); + + if (!fileUploadInit) { + selected_el.trigger('init'); + fileUploadInit = true; + } + return false; }); diff --git a/admin/write-page.php b/admin/write-page.php index 4a6f7cb1..f260728e 100644 --- a/admin/write-page.php +++ b/admin/write-page.php @@ -52,8 +52,8 @@ Typecho_Widget::widget('Widget_Contents_Page_Edit')->to($page);