Merge pull request #1797 from clkao/author-style-hook

Author style hook
This commit is contained in:
John McLear 2013-06-09 16:37:31 -07:00
commit 3e22ebf843

View file

@ -208,27 +208,35 @@ 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));
var authorStyleSet = hooks.callAll('aceSetAuthorStyle', {
dynamicCSS: dynamicCSS,
parentDynamicCSS: parentDynamicCSS,
info: info,
author: author,
authorSelector: authorSelector,
});
// Prevent default behaviour if any hook says so
if (_.any(authorStyleSet, function(it) { return it }))
{
return
}
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 +244,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 +272,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)