refactor setAuthorStyle

This commit is contained in:
Chia-liang Kao 2013-06-06 12:30:48 +08:00
parent cd277e5810
commit eae9faa28c

View file

@ -208,27 +208,21 @@ function Ace2Inner(){
}; };
editorInfo.ace_getAuthorInfos= getAuthorInfos; editorInfo.ace_getAuthorInfos= getAuthorInfos;
function setAuthorInfo(author, info) function setAuthorStyle(author, info)
{ {
if ((typeof author) != "string") if (!dynamicCSS) {
{ return;
throw new Error("setAuthorInfo: author (" + author + ") is not a string");
} }
var authorSelector = getAuthorColorClassSelector(getAuthorClassName(author));
if (!info) if (!info)
{ {
delete authorInfos[author]; dynamicCSS.removeSelectorStyle(authorSelector);
if (dynamicCSS) parentDynamicCSS.removeSelectorStyle(authorSelector);
{
dynamicCSS.removeSelectorStyle(getAuthorColorClassSelector(getAuthorClassName(author)));
parentDynamicCSS.removeSelectorStyle(getAuthorColorClassSelector(getAuthorClassName(author)));
}
} }
else else
{ {
authorInfos[author] = info;
if (info.bgcolor) if (info.bgcolor)
{
if (dynamicCSS)
{ {
var bgcolor = info.bgcolor; var bgcolor = info.bgcolor;
if ((typeof info.fade) == "number") if ((typeof info.fade) == "number")
@ -236,12 +230,9 @@ function Ace2Inner(){
bgcolor = fadeColor(bgcolor, info.fade); bgcolor = fadeColor(bgcolor, info.fade);
} }
var authorStyle = dynamicCSS.selectorStyle(getAuthorColorClassSelector( var authorStyle = dynamicCSS.selectorStyle(authorSelector);
getAuthorClassName(author))); var parentAuthorStyle = parentDynamicCSS.selectorStyle(authorSelector);
var parentAuthorStyle = parentDynamicCSS.selectorStyle(getAuthorColorClassSelector( var anchorStyle = dynamicCSS.selectorStyle(authorSelector + ' > a')
getAuthorClassName(author)));
var anchorStyle = dynamicCSS.selectorStyle(getAuthorColorClassSelector(
getAuthorClassName(author))+' > a')
// author color // author color
authorStyle.backgroundColor = bgcolor; authorStyle.backgroundColor = bgcolor;
@ -267,6 +258,22 @@ function Ace2Inner(){
} }
} }
} }
function setAuthorInfo(author, info)
{
if ((typeof author) != "string")
{
throw new Error("setAuthorInfo: author (" + author + ") is not a string");
}
if (!info)
{
delete authorInfos[author];
}
else
{
authorInfos[author] = info;
}
setAuthorStyle(author, info);
} }
function getAuthorClassName(author) function getAuthorClassName(author)