修改撰写页面缩略名自适应宽度

根据issue #133 的提示,将宽度自适应改为完全依照css样式显示的实际宽度来调整
This commit is contained in:
joyqi
2013-12-19 10:46:23 +08:00
parent a065afc55c
commit 0f18b09ce4
2 changed files with 47 additions and 12 deletions
+23
View File
@@ -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;
};
+24 -12
View File
@@ -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 = $('<div />').css(slug.css()).css({
'display' : 'none',
'width' : 'auto'
}).insertAfter(slug), originalWidth = slug.width();
function justifySlugWidth() {
var html = slug.val().replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/'/g, '&#039;')
.replace(/"/g, '&quot;')
.replace(/ /g, '&nbsp;')
.replace(/((&nbsp;)*)&nbsp;/g, '$1 ')
.replace(/\n/g, '<br />')
.replace(/<br \/>[ ]*$/, '<br />-')
.replace(/<br \/> /g, '<br />&nbsp;');
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();
}
// 原始的插入图片和文件