From 6706355138f27e6b71bca82fb60f4f122d0b9a8e Mon Sep 17 00:00:00 2001 From: joyqi Date: Mon, 21 Oct 2013 19:15:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E6=8B=96=E5=8A=A8?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/js/typecho.js | 73 +++++++++++++++++++++++++++++++++++++++++++- admin/write-js.php | 3 ++ admin/write-page.php | 1 - admin/write-post.php | 1 - 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/admin/js/typecho.js b/admin/js/typecho.js index e4ef5e13..86796265 100644 --- a/admin/js/typecho.js +++ b/admin/js/typecho.js @@ -1,6 +1,14 @@ (function (w) { w.Typecho = { - insertFileToEditor : function (file, url, isImage) {} + insertFileToEditor : function (file, url, isImage) {}, + editorResize : function (id, url) { + $('#' + id).resizeable({ + minHeight : 100, + afterResize : function (h) { + $.post(url, {size : h}); + } + }) + } }; })(window); @@ -23,6 +31,69 @@ }); }; + $.fn.resizeable = function (options) { + var s = $.extend({ + minHeight : 100, + afterResize : null + }, options); + + return this.each(function () { + var r = $('').insertAfter(this), + staticOffset, iLastMousePos = 0, iMin = s.minHeight, t = this; + + function startDrag(e) { + textarea = $(e.data.el); + textarea.blur(); + iLastMousePos = mousePosition(e).y; + + staticOffset = textarea.height() - iLastMousePos; + textarea.css('opacity', 0.25); + + $(document).mousemove(performDrag).mouseup(endDrag); + return false; + } + + function performDrag(e) { + var iThisMousePos = mousePosition(e).y, + iMousePos = staticOffset + iThisMousePos; + if (iLastMousePos >= (iThisMousePos)) { + iMousePos -= 5; + } + + iLastMousePos = iThisMousePos; + iMousePos = Math.max(iMin, iMousePos); + textarea.height(iMousePos + 'px'); + + if (iMousePos < iMin) { + endDrag(e); + } + return false; + } + + function endDrag(e) { + var h = textarea.outerHeight(); + $(document).unbind('mousemove', performDrag).unbind('mouseup', endDrag); + + textarea.css('opacity', 1); + textarea.focus(); + textarea = null; + + staticOffset = null; + iLastMousePos = 0; + + if (s.afterResize) { + s.afterResize.call(t, h); + } + } + + function mousePosition(e) { + return { x: e.clientX + document.documentElement.scrollLeft, y: e.clientY + document.documentElement.scrollTop }; + } + + r.bind('mousedown', {el : this}, startDrag); + }); + }; + // 表格选择插件 $.fn.tableSelectable = function (options) { var table = this, s = $.extend({ diff --git a/admin/write-js.php b/admin/write-js.php index a96c69d8..89c1a6f8 100644 --- a/admin/write-js.php +++ b/admin/write-js.php @@ -34,6 +34,9 @@ $(document).ready(function() { minute : (new Date()).getMinutes() }); + // text 自动拉伸 + Typecho.editorResize('text', 'index('/action/ajax?do=editorResize'); ?>'); + // tag autocomplete 提示 var tags = $('#tags'), tagsPre = []; diff --git a/admin/write-page.php b/admin/write-page.php index cd65c9d1..90dfd96b 100644 --- a/admin/write-page.php +++ b/admin/write-page.php @@ -29,7 +29,6 @@ Typecho_Widget::widget('Widget_Contents_Page_Edit')->to($page);

-

diff --git a/admin/write-post.php b/admin/write-post.php index c1aad8e7..f2bbdcb6 100644 --- a/admin/write-post.php +++ b/admin/write-post.php @@ -34,7 +34,6 @@ Typecho_Widget::widget('Widget_Contents_Post_Edit')->to($post);

-