Hi,
I attempting to port another simple mod of mine (HLBM) here. This mod will need to change this line:
<div class="post_wrapper ', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', '">
To:
<div class="post_wrapper ', $message['approved'] && $message['member']['is_buddy'] ? 'buddybg' : ($message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg'), '">
I cannot see is_buddy anywhere in display controller. Is there any is_buddy in Elk? Can this be done via hook? How?
is_buddy is loaded in loadMemberContext, so, yes it's available.
Not that I can see.
I think it may be in the $message array, $message['is_buddy'] perhaps?
The only way I can think to do it without edits would be with some JS. In a hook you keep track of the is buddy flags and output a JS object with the id's, and then have some JS function that on load reads that and changes the backgrounds. Thats just a thought.
Thank you
@emanuele and
@Spuds . I think I get the idea a bit. Javascript may be the only solution to avoid modifying the message tempalte.
I am thinking rather than injecting script in the header, it will be better to add it via template layer somewhere after the message itself at the bottom.
Current idea of template code:
function template_HLBM_below()
{
// I don't think $message can be used here. Help!!! I cannot get it to work.
if ($message['approved'] && $message['member']['is_buddy']) {
echo '
<script>
function changeColor(buddybg) {
var hlbm = document.getElementById('forumposts').getElementsByClassName('post_wrapper windowbg');
hlbm.style.color = buddybg;
// Not finish. Then what? What about windowbg2? Repeat this again?
// Or use this one instead???
document.getElementById('forumposts').className = post_wrapper windowbg
document.getElementById('forumposts').className.replace(post_wrapper buddybg)
// If correct, repeat for windowbg2???
document.getElementById('forumposts').className = post_wrapper windowbg2
document.getElementById('forumposts').className.replace(post_wrapper buddybg)
}
</script>';
}
}
The javascript is supposed to get the class windowbg and windowbg2 if the message is approved and is a buddy message. But I cannot test it as I don't think $message can be simply used just like that. Anything that can make it global and use here?
Add a hook in elkarte_settings for
integrate_prepare_display_context
Example:
colorize_buddy|SUBSDIR/ColorizeBuddy.subs.php
<?php
function colorize_buddy(&$output, &$message)
{
global $user_info;
if (in_array($message['id_member'], $user_info['buddies']))
{
addInlineJavascript('
$( "#msg'. $message['id_msg'] . '" ).parent().css( "background-color", "#ccc" );
', true);
}
}
Or:
<?php
function colorize_buddy(&$output, &$message)
{
global $user_info;
if (in_array($message['id_member'], $user_info['buddies']))
{
addInlineJavascript('
$( "#msg'. $message['id_msg'] . '" ).parent().addClass("buddybg");
', true);
}
}
So that styling can go to the css. ;)
I would be tempted to do something more complex, but probably is not worth at the moment. O:-)
Though, that could be an interesting spot to "do some changes"... O:-) O:-) O:-) O:-)
You are all very wonderful and helpful indeed. Thank you very much guys.
After testing the code, I realize that the code is targeting this code's parent:
<a class="post_anchor" id="msg' . $message['id'] . '"></a>
Unfortunately, if the said buddy message is on the top of the display page, it ends up wrongly changing this code's parent:
<a id="msg', $context['first_message'], '">
How to avoid it?
Ah, sorry.. didn't knew the anchor wasn't present there... You can also use the ID #info_xx (that's the post's header) and jump from there to the parent three levels up.
$( "#info_'. $message['id_msg'] . '" ).parent().parent().parent().css( "background-color", "#ccc" );
Work like a charm. Thank you TE.
Addon is ready and already posted in the addon board.
https://github.com/emanuele45/Dialogo/commit/909193e7169e3def9ec20abbaa0dca440dc43d7d
O:-)
I'd push this to 1.0.2.
And, with a bit of tweaking, it may help
@phantom as well with his Topic Author (http://www.elkarte.net/community/index.php?topic=2208.0). :D
Great!
But how do I make use of this? And just out of my curiosity, why is $message['classes'] positioned before the default class? Shouldn't it be after to override it?
You don't need the JS part anymore, just modify the $Output Array..
function colorize_buddy(&$output, &$message)
{
global $user_info;
if (in_array($message['id_member'], $user_info['buddies']))
$output['classes'] = array("buddybg");
}
Untested though :D
Ok. That easier. But will that replaces the default class or adds a new class? I kinda think it adds a new class but shouldn't it be after and not before the default class (windowbg / windowbg2 / approvebg) for it to work?
Just to be picky:
function colorize_buddy(&$output, &$message)
{
global $user_info;
if (in_array($message['id_member'], $user_info['buddies']))
$output['classes'][] = "buddybg";
}
:D
Adds new.
AFAIK the order of the classes are used is not relevant.
What is relevant is the order the classes are declared in the stylesheet (i.e. in index.css for example). ;)