From 0f18b09ce40852b0835e00179befa83998628470 Mon Sep 17 00:00:00 2001 From: joyqi Date: Thu, 19 Dec 2013 10:46:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=92=B0=E5=86=99=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=BC=A9=E7=95=A5=E5=90=8D=E8=87=AA=E9=80=82=E5=BA=94?= =?UTF-8?q?=E5=AE=BD=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据issue #133 的提示,将宽度自适应改为完全依照css样式显示的实际宽度来调整 --- admin/js/typecho.js | 23 +++++++++++++++++++++++ admin/write-js.php | 36 ++++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/admin/js/typecho.js b/admin/js/typecho.js index 0e39045e..298bb1a8 100644 --- a/admin/js/typecho.js +++ b/admin/js/typecho.js @@ -1317,3 +1317,26 @@ jQuery.cookie = function (key, value, options) { }; })( jQuery ); + +jQuery.fn.css2 = jQuery.fn.css; +jQuery.fn.css = function() { + if (arguments.length) return jQuery.fn.css2.apply(this, arguments); + var attr = ['font-family','font-size','font-weight','font-style','color', 'box-sizing', + 'text-transform','text-decoration','letter-spacing', 'box-shadow', + 'line-height','text-align','vertical-align','direction','background-color', + 'background-image','background-repeat','background-position', + 'background-attachment','opacity','width','height','top','right','bottom', + 'left','margin-top','margin-right','margin-bottom','margin-left', + 'padding-top','padding-right','padding-bottom','padding-left', + 'border-top-width','border-right-width','border-bottom-width', + 'border-left-width','border-top-color','border-right-color', + 'border-bottom-color','border-left-color','border-top-style', + 'border-right-style','border-bottom-style','border-left-style','position', + 'display','visibility','z-index','overflow-x','overflow-y','white-space', + 'clip','float','clear','cursor','list-style-image','list-style-position', + 'list-style-type','marker-offset']; + var len = attr.length, obj = {}; + for (var i = 0; i < len; i++) + obj[attr[i]] = jQuery.fn.css2.call(this, attr[i]); + return obj; +}; diff --git a/admin/write-js.php b/admin/write-js.php index 5588bbd6..5817cbd1 100644 --- a/admin/write-js.php +++ b/admin/write-js.php @@ -109,20 +109,32 @@ $(document).ready(function() { var slug = $('#slug'); if (slug.length > 0) { - var sw = slug.width(); - if (slug.val().length > 0) { - slug.css('width', 'auto').attr('size', slug.val().length); + var justifySlug = $('
').css(slug.css()).css({ + 'display' : 'none', + 'width' : 'auto' + }).insertAfter(slug), originalWidth = slug.width(); + + function justifySlugWidth() { + var html = slug.val().replace(/&/g, '&') + .replace(//g, '>') + .replace(/'/g, ''') + .replace(/"/g, '"') + .replace(/ /g, ' ') + .replace(/(( )*) /g, '$1 ') + .replace(/\n/g, '
') + .replace(/
[ ]*$/, '
-') + .replace(/
/g, '
 '); + + justifySlug.css('min-width', html.length > 0 + ? 'inherit' : originalWidth); + + justifySlug.html(html); + slug.width(justifySlug.width()); } - slug.bind('input propertychange', function () { - var t = $(this), l = t.val().length; - - if (l > 0) { - t.css('width', 'auto').attr('size', l); - } else { - t.css('width', sw).removeAttr('size'); - } - }).width(); + slug.bind('input propertychange', justifySlugWidth); + justifySlugWidth(); } // 原始的插入图片和文件