From 64111998f2399deb93a89c3ed93f780975d1b8ad Mon Sep 17 00:00:00 2001 From: joyqi Date: Mon, 14 Oct 2013 14:09:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=99=84=E4=BB=B6=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E5=90=8D=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/file-upload-js.php | 207 +++--------------------------------- admin/javascript/typecho.js | 28 ++++- 2 files changed, 39 insertions(+), 196 deletions(-) diff --git a/admin/file-upload-js.php b/admin/file-upload-js.php index 3aa418b6..c51d1bae 100644 --- a/admin/file-upload-js.php +++ b/admin/file-upload-js.php @@ -9,167 +9,10 @@ if (isset($post) && $post instanceof Typecho_Widget && $post->have()) { - - - - - + diff --git a/admin/javascript/typecho.js b/admin/javascript/typecho.js index e32b21be..a0f2aa70 100644 --- a/admin/javascript/typecho.js +++ b/admin/javascript/typecho.js @@ -84,18 +84,21 @@ url : null, onUpload : null, onComplete : null, + types : null, + typesError : 'file type error', single : false }, options), p = this.parent().css('position', 'relative'), input = $('').css({ opacity : 0, + cursor : 'pointer', position : 'absolute', width : this.outerWidth(), height : this.outerHeight, left : this.offset().left - p.offset().left, top : this.offset().top - p.offset().top }).insertAfter(this), queue = {}, prefix = 'queue-', - index = 0; + index = 0, types = []; window.fileUploadComplete = function (id, url) { if (s.single) { @@ -112,6 +115,13 @@ } }; + if (!!s.types) { + var list = s.types.split(';'); + for (var i = 0; i < list.length; i ++) { + types.push(list[i].split('.').pop()); + } + } + function upload (frame, id) { var form = $('
'), replace = input.clone(true).val(''), @@ -126,6 +136,15 @@ form.submit(); } + function checkTypes (file) { + if (!types.length) { + return true; + } + + var type = file.split('.').pop(); + return $.inArray(types, type) >= 0; + } + input.change(function () { var t = $(this), file = t.val(); @@ -135,6 +154,11 @@ file = file.split(/\\|\//).pop(); } + if (!checkTypes(file)) { + alert(s.typesError.replace('%s', file)); + return; + } + if (s.single) { t.prop('disabled', true); } @@ -142,7 +166,7 @@ var id = prefix + index; index ++; - queue[id] = $('').appendTo(document.body); if (s.onUpload) {