refactor setAuthorStyle

This commit is contained in:
Chia-liang Kao 2013-06-06 12:30:48 +08:00
parent cd277e5810
commit eae9faa28c
1 changed files with 52 additions and 45 deletions

View File

@ -208,6 +208,57 @@ function Ace2Inner(){
};
editorInfo.ace_getAuthorInfos= getAuthorInfos;
function setAuthorStyle(author, info)
{
if (!dynamicCSS) {
return;
}
var authorSelector = getAuthorColorClassSelector(getAuthorClassName(author));
if (!info)
{
dynamicCSS.removeSelectorStyle(authorSelector);
parentDynamicCSS.removeSelectorStyle(authorSelector);
}
else
{
if (info.bgcolor)
{
var bgcolor = info.bgcolor;
if ((typeof info.fade) == "number")
{
bgcolor = fadeColor(bgcolor, info.fade);
}
var authorStyle = dynamicCSS.selectorStyle(authorSelector);
var parentAuthorStyle = parentDynamicCSS.selectorStyle(authorSelector);
var anchorStyle = dynamicCSS.selectorStyle(authorSelector + ' > a')
// author color
authorStyle.backgroundColor = bgcolor;
parentAuthorStyle.backgroundColor = bgcolor;
// text contrast
if(colorutils.luminosity(colorutils.css2triple(bgcolor)) < 0.5)
{
authorStyle.color = '#ffffff';
parentAuthorStyle.color = '#ffffff';
}else{
authorStyle.color = null;
parentAuthorStyle.color = null;
}
// anchor text contrast
if(colorutils.luminosity(colorutils.css2triple(bgcolor)) < 0.55)
{
anchorStyle.color = colorutils.triple2css(colorutils.complementary(colorutils.css2triple(bgcolor)));
}else{
anchorStyle.color = null;
}
}
}
}
function setAuthorInfo(author, info)
{
if ((typeof author) != "string")
@ -217,56 +268,12 @@ function Ace2Inner(){
if (!info)
{
delete authorInfos[author];
if (dynamicCSS)
{
dynamicCSS.removeSelectorStyle(getAuthorColorClassSelector(getAuthorClassName(author)));
parentDynamicCSS.removeSelectorStyle(getAuthorColorClassSelector(getAuthorClassName(author)));
}
}
else
{
authorInfos[author] = info;
if (info.bgcolor)
{
if (dynamicCSS)
{
var bgcolor = info.bgcolor;
if ((typeof info.fade) == "number")
{
bgcolor = fadeColor(bgcolor, info.fade);
}
var authorStyle = dynamicCSS.selectorStyle(getAuthorColorClassSelector(
getAuthorClassName(author)));
var parentAuthorStyle = parentDynamicCSS.selectorStyle(getAuthorColorClassSelector(
getAuthorClassName(author)));
var anchorStyle = dynamicCSS.selectorStyle(getAuthorColorClassSelector(
getAuthorClassName(author))+' > a')
// author color
authorStyle.backgroundColor = bgcolor;
parentAuthorStyle.backgroundColor = bgcolor;
// text contrast
if(colorutils.luminosity(colorutils.css2triple(bgcolor)) < 0.5)
{
authorStyle.color = '#ffffff';
parentAuthorStyle.color = '#ffffff';
}else{
authorStyle.color = null;
parentAuthorStyle.color = null;
}
// anchor text contrast
if(colorutils.luminosity(colorutils.css2triple(bgcolor)) < 0.55)
{
anchorStyle.color = colorutils.triple2css(colorutils.complementary(colorutils.css2triple(bgcolor)));
}else{
anchorStyle.color = null;
}
}
}
}
setAuthorStyle(author, info);
}
function getAuthorClassName(author)