From d15d0543630f2f0f5f36f4f2f00827a7ab5e4155 Mon Sep 17 00:00:00 2001 From: joyqi Date: Tue, 26 Nov 2013 12:30:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/file-upload-js.php | 45 ++++++++++++++++++++++++++++++---------- admin/write-js.php | 11 ++++++++-- admin/write-page.php | 4 ++-- admin/write-post.php | 4 ++-- 4 files changed, 47 insertions(+), 17 deletions(-) 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);