From b9fa6ec7a2cca12bd9b7f7e9200fc604873e1d77 Mon Sep 17 00:00:00 2001 From: joyqi Date: Sun, 20 Oct 2013 01:11:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=BC=96=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/file-upload-js.php | 4 ++-- admin/js/markdown.js | 16 +++++++++++++--- admin/js/typecho.js | 2 +- admin/write-js.php | 7 ++++--- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/admin/file-upload-js.php b/admin/file-upload-js.php index 266b9476..0af29d38 100644 --- a/admin/file-upload-js.php +++ b/admin/file-upload-js.php @@ -167,8 +167,8 @@ $(document).ready(function() { function attachInsertEvent (el) { $('.insert', el).click(function () { - var p = $(this).parents('li'); - Typecho.insertFileToEditor(p.data('url'), p.data('image')); + var t = $(this), p = t.parents('li'); + Typecho.insertFileToEditor(t.text(), p.data('url'), p.data('image')); return false; }); } diff --git a/admin/js/markdown.js b/admin/js/markdown.js index ad3e333b..9d6f9317 100644 --- a/admin/js/markdown.js +++ b/admin/js/markdown.js @@ -3037,6 +3037,7 @@ else link: "Hyperlink Ctrl+L", linkdescription: "enter link description here", linkdialog: "

Insert Hyperlink

http://example.com/ \"optional title\"

", + linkname: null, quote: "Blockquote
Ctrl+Q", quoteexample: "Blockquote", @@ -3047,6 +3048,7 @@ else image: "Image Ctrl+G", imagedescription: "enter image description here", imagedialog: "

Insert Image

http://example.com/images/diagram.jpg \"optional title\"
Need
free image hosting?

", + imagename: null, olist: "Numbered List
    Ctrl+O", ulist: "Bulleted List
      Ctrl+U", @@ -3113,7 +3115,15 @@ else if (options.helpButton) { options.strings.help = options.strings.help || options.helpButton.title; } - var getString = function (identifier) { return options.strings[identifier] || defaultsStrings[identifier]; } + var getString = function (identifier) { + var string = options.strings[identifier] || defaultsStrings[identifier]; + + if ('imagename' == identifier || 'linkname' == identifier) { + options.strings[identifier] = null; + } + + return string; + } idPostfix = idPostfix || ""; @@ -4795,10 +4805,10 @@ else if (!chunk.selection) { if (isImage) { - chunk.selection = that.getString("imagedescription"); + chunk.selection = that.getString("imagename") || that.getString("imagedescription"); } else { - chunk.selection = that.getString("linkdescription"); + chunk.selection = that.getString("linkname") || that.getString("linkdescription"); } } } diff --git a/admin/js/typecho.js b/admin/js/typecho.js index 30b1622b..e4ef5e13 100644 --- a/admin/js/typecho.js +++ b/admin/js/typecho.js @@ -1,6 +1,6 @@ (function (w) { w.Typecho = { - insertFileToEditor : function (url, isImage) {} + insertFileToEditor : function (file, url, isImage) {} }; })(window); diff --git a/admin/write-js.php b/admin/write-js.php index 031b5a2b..7ca3d348 100644 --- a/admin/write-js.php +++ b/admin/write-js.php @@ -105,9 +105,8 @@ $(document).ready(function() { } // 原始的插入图片和文件 - Typecho.insertFileToEditor = function (url, isImage) { + Typecho.insertFileToEditor = function (file, url, isImage) { var textarea = $('#text'), sel = textarea.getSelection(), - file = url.split('/').pop(), html = isImage ? '' + file + '' : '' + file + '', offset = (sel ? sel.start : 0) + html.length; @@ -250,10 +249,12 @@ $(document).ready(function () { var imageButton = $('#wmd-image-button'), linkButton = $('#wmd-image-button'); - Typecho.insertFileToEditor = function (url, isImage) { + Typecho.insertFileToEditor = function (file, url, isImage) { var button = isImage ? imageButton : linkButton; + options.strings[isImage ? 'imagename' : 'linkname'] = file; button.trigger('click'); + var checkDialog = setInterval(function () { if ($('.wmd-prompt-dialog').length > 0) { $('.wmd-prompt-dialog input').val(url).select();