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

Author style hook
pull/1789/merge
John McLear 2013-06-09 16:37:31 -07:00
commit 3e22ebf843
1 changed files with 66 additions and 45 deletions

View File

@ -208,27 +208,35 @@ function Ace2Inner(){
};
editorInfo.ace_getAuthorInfos= getAuthorInfos;
function setAuthorInfo(author, info)
function setAuthorStyle(author, info)
{
if ((typeof author) != "string")
{
throw new Error("setAuthorInfo: author (" + author + ") is not a string");
if (!dynamicCSS) {
return;
}
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)
{
delete authorInfos[author];
if (dynamicCSS)
{
dynamicCSS.removeSelectorStyle(getAuthorColorClassSelector(getAuthorClassName(author)));
parentDynamicCSS.removeSelectorStyle(getAuthorColorClassSelector(getAuthorClassName(author)));
}
dynamicCSS.removeSelectorStyle(authorSelector);
parentDynamicCSS.removeSelectorStyle(authorSelector);
}
else
{
authorInfos[author] = info;
if (info.bgcolor)
{
if (dynamicCSS)
{
var bgcolor = info.bgcolor;
if ((typeof info.fade) == "number")
@ -236,12 +244,9 @@ function Ace2Inner(){
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')
var authorStyle = dynamicCSS.selectorStyle(authorSelector);
var parentAuthorStyle = parentDynamicCSS.selectorStyle(authorSelector);
var anchorStyle = dynamicCSS.selectorStyle(authorSelector + ' > a')
// author color
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)