SimplePortal

Customization => Custom Coding => Topic started by: stikkki on March 26, 2009, 09:21:47 AM

Title: Make news block fade
Post by: stikkki on March 26, 2009, 09:21:47 AM
im building a forum for a charity organisation and i would like the news block to fade like the news fader on the forum rather than the news changing on page refresh
Title: Re: Make news block fade
Post by: Nathaniel on April 08, 2009, 03:46:56 AM
Put the following code into a Custom PHP block:
Code: [Select]
global $context, $settings;

echo '
<div id="sp_news_fader_', $id, '" class="sp_center sp_fullwidth"><b>', $context['news_lines'][0], '</b></div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
// The fading delay (in ms.)
var smfFadeDelay = ', empty($settings['newsfader_time']) ? 5000 : $settings['newsfader_time'], ';
// Fade from... what text color? To which background color?
var smfFadeFrom = {"r": 0, "g": 0, "b": 0}, smfFadeTo = {"r": 255, "g": 255, "b": 255};
// Surround each item with... anything special?
var smfFadeBefore = "<b>", smfFadeAfter = "</b>";

var foreColor, backEl, backColor;

if (typeof(document.getElementById(\'sp_news_fader_', $id, '\').currentStyle) != "undefined")
{
foreColor = document.getElementById(\'sp_news_fader_', $id, '\').currentStyle.color.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
smfFadeFrom = {"r": parseInt(foreColor[1]), "g": parseInt(foreColor[2]), "b": parseInt(foreColor[3])};

backEl = document.getElementById(\'sp_news_fader_', $id, '\');
while (backEl.currentStyle.backgroundColor == "transparent" && typeof(backEl.parentNode) != "undefined")
backEl = backEl.parentNode;

backColor = backEl.currentStyle.backgroundColor.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
smfFadeTo = {"r": eval("0x" + backColor[1]), "g": eval("0x" + backColor[2]), "b": eval("0x" + backColor[3])};
}
else if (typeof(window.opera) == "undefined" && typeof(document.defaultView) != "undefined")
{
foreColor = document.defaultView.getComputedStyle(document.getElementById(\'sp_news_fader_', $id, '\'), null).color.match(/rgb\((\d+), (\d+), (\d+)\)/);
smfFadeFrom = {"r": parseInt(foreColor[1]), "g": parseInt(foreColor[2]), "b": parseInt(foreColor[3])};

backEl = document.getElementById(\'sp_news_fader_', $id, '\');
while (document.defaultView.getComputedStyle(backEl, null).backgroundColor == "transparent" && typeof(backEl.parentNode) != "undefined" && typeof(backEl.parentNode.tagName) != "undefined")
backEl = backEl.parentNode;

backColor = document.defaultView.getComputedStyle(backEl, null).backgroundColor.match(/rgb\((\d+), (\d+), (\d+)\)/);
smfFadeTo = {"r": parseInt(backColor[1]), "g": parseInt(backColor[2]), "b": parseInt(backColor[3])};
}

// List all the lines of the news for display.
var smfFadeContent = new Array(
"', implode('",
"', $context['fader_news_lines']), '"
);
// ]]></script>
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/fader.js"></script>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
smfFadeScroller = document.getElementById(\'sp_news_fader_', $id, '\');
// ]]></script>';
Title: Re: Make news block fade
Post by: stikkki on April 10, 2009, 09:26:58 AM
this didnt work and actually didnt change the news even on refresh
Title: Re: Make news block fade
Post by: dougsbrat on April 10, 2009, 10:25:18 AM
I tried it and its great!  ;D thanks

be sure you have more than one news message for it to fade to, else one will be as shown with no fade.


I have another request for this...
is it possible for the block size to be fixed?
because:
when using the fade and the news items are not the same height (text lines or image) then the block size changes as each is shown, causing the lower blocks to move too  :'(


thanks for a good block
Title: Re: Make news block fade
Post by: stikkki on April 10, 2009, 11:01:44 AM
be sure you have more than one news message for it to fade to, else one will be as shown with no fade.

lol im not that think

i have 3 news items set up
i created a php block, added the above code and placed it in top block position but it only displays the first news item

http://www.somersetstaffies.org.uk/index.php
Title: Re: Make news block fade
Post by: dougsbrat on April 10, 2009, 12:31:22 PM
I gues I am   ;D cause I only had one news item and took a minute to figure it out.

BTW I use
SMF 1.1.8 and see you have 2.0
perhaps its that or a server setting?
Title: Re: Make news block fade
Post by: Nathaniel on April 11, 2009, 03:21:56 AM
Use the code below for SMF 2 RC1:
Code: [Select]
   global $context, $settings;

   echo '
                        <div id="smfNewsFader"><div id="smfFadeScroller" class="sp_center sp_fullwidth"><span>', $context['news_lines'][0], '</span></div></div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
// The fading delay (in ms.)
var smfFadeDelay = ', empty($settings['newsfader_time']) ? 5000 : $settings['newsfader_time'], ';
// Fade from... what text color? To which background color?
var smfFadeFrom = {"r": 0, "g": 0, "b": 0}, smfFadeTo = {"r": 255, "g": 255, "b": 255};
// Surround each item with... anything special?
var smfFadeBefore = "<b>", smfFadeAfter = "</b>";

var foreColor, foreEl, backEl, backColor;

if (typeof(document.getElementById(\'smfFadeScroller\').currentStyle) != "undefined")
{
foreColor = document.getElementById(\'smfFadeScroller\').currentStyle.color.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
smfFadeFrom = {"r": parseInt(foreColor[1]), "g": parseInt(foreColor[2]), "b": parseInt(foreColor[3])};

backEl = document.getElementById(\'smfFadeScroller\');
while (backEl.currentStyle.backgroundColor == "transparent" && typeof(backEl.parentNode) != "undefined")
backEl = backEl.parentNode;

backColor = backEl.currentStyle.backgroundColor.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
smfFadeTo = {"r": eval("0x" + backColor[1]), "g": eval("0x" + backColor[2]), "b": eval("0x" + backColor[3])};
}
else if (typeof(window.opera) == "undefined" && typeof(document.defaultView) != "undefined")
{

foreEl = document.getElementById(\'smfFadeScroller\');

while (document.defaultView.getComputedStyle(foreEl, null).getPropertyCSSValue("color") == null && typeof(foreEl.parentNode) != "undefined" && typeof(foreEl.parentNode.tagName) != "undefined")
foreEl = foreEl.parentNode;

foreColor = document.defaultView.getComputedStyle(foreEl, null).getPropertyValue("color").match(/rgb\((\d+), (\d+), (\d+)\)/);
smfFadeFrom = {"r": parseInt(foreColor[1]), "g": parseInt(foreColor[2]), "b": parseInt(foreColor[3])};

backEl = document.getElementById(\'smfFadeScroller\');

while (document.defaultView.getComputedStyle(backEl, null).getPropertyCSSValue("background-color") == null && typeof(backEl.parentNode) != "undefined" && typeof(backEl.parentNode.tagName) != "undefined")
backEl = backEl.parentNode;

backColor = document.defaultView.getComputedStyle(backEl, null).getPropertyValue("background-color");//.match(/rgb\((\d+), (\d+), (\d+)\)/);
smfFadeTo = {"r": parseInt(backColor[1]), "g": parseInt(backColor[2]), "b": parseInt(backColor[3])};
}

// List all the lines of the news for display.
var smfFadeContent = new Array(
"', implode('",
"', $context['fader_news_lines']), '"
);
// ]]></script>
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/scripts/fader.js"></script>';
Title: Re: Make news block fade
Post by: stikkki on April 11, 2009, 08:44:39 AM
sorry i should of said it was 2.0

that worked fine LHVWB, thanx
Title: Re: Make news block fade
Post by: geekfairy on May 03, 2009, 10:34:36 PM
This works beautifully :)

Is there any way to not show titles/names of certain blocks?

I'm using this one to show some banners but would prefer it not to have to have a title sitting on the top of the block.
Title: Re: Make news block fade
Post by: Nathaniel on May 04, 2009, 12:33:08 AM
Check the 'No Title' checkbox under the 'Style Options' area, when you edit a block.
Title: Re: Make news block fade
Post by: geekfairy on May 04, 2009, 12:38:41 AM
 :-[ I thought I'd seen it there somewhere.

Not feeling well today...that's my only excuse  :P

Oh, and thankyou! :)

Title: Re: Make news block fade
Post by: geekfairy on May 04, 2009, 04:31:34 AM
Is there a way to fix the height of the news block? I am finding that in Firefox, the first time a page is loaded the news block jumps as it fades to nothing and the next banner fades in. I only have three banners on there right now and once it has cycled through once it is fine.

I had the same problem with the SMF news fader and that was solved by editing the template files to fix the height of the news box. What would I need to edit to do the same with this block?

Thanks :)
Title: Re: Make news block fade
Post by: Nathaniel on May 04, 2009, 05:09:32 AM
Use the style options, you should be able to add 'height:20px;' to the style parameter for the body of the block.
Title: Re: Make news block fade
Post by: geekfairy on May 04, 2009, 05:25:10 AM
Perfect  :D

Thanks so much. I'm really loving SP  :D
Title: Re: Make news block fade
Post by: Chit-Chat ChatterBox Boss on May 15, 2009, 02:07:38 PM
Sweet thanks!
Title: Re: Make news block fade
Post by: AngelinaBelle on June 16, 2009, 12:06:53 AM
Put the following code into a Custom PHP block:
Brilliant! Works like a charm.  Thanks!
Title: Re: Make news block fade
Post by: primetime on July 10, 2009, 05:37:00 PM
Works great!!
Title: Re: Make news block fade
Post by: amlucent on July 18, 2009, 03:25:59 AM
When I use the code for SMF 2.0 it only fades on the board index..  I have my news block set to show up on "all pages"... can I make it fade everywhere?
Title: Re: Make news block fade
Post by: Gurbet_42 on January 05, 2010, 03:38:16 PM
Not fades on 2.0 RC but fades on forum.
Title: Re: Make news block fade
Post by: Nothingness on January 17, 2010, 05:06:44 AM
I'm getting error "Syntax error in block code. Please check the code." when adding the code. I am on 2.0 RC2
SimplePortal 2.3.1
Title: Re: Make news block fade
Post by: Nothingness on January 18, 2010, 06:11:33 PM
Bump.
Title: Re: Make news block fade
Post by: Nothingness on January 20, 2010, 12:18:47 PM
If no one knows the answer or the fix to this just simply answer with a no instead of not replying at all.
Title: Re: Make news block fade
Post by: [SiNaN] on January 29, 2010, 12:43:30 PM
For SMF 1.1 version:

Code: [Select]
global $context, $settings;

if (!empty($context['fader_news_lines']))
{
echo '
<div style="text-align: center;">';

// Prepare all the javascript settings.
echo '
<div id="smfFadeScroller" style="width: 90%; padding: 2px;"><b>', $context['news_lines'][0], '</b></div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
// The fading delay (in ms.)
var smfFadeDelay = ', empty($settings['newsfader_time']) ? 5000 : $settings['newsfader_time'], ';
// Fade from... what text color? To which background color?
var smfFadeFrom = {"r": 0, "g": 0, "b": 0}, smfFadeTo = {"r": 255, "g": 255, "b": 255};
// Surround each item with... anything special?
var smfFadeBefore = "<b>", smfFadeAfter = "</b>";

var foreColor, backEl, backColor;

if (typeof(document.getElementById(\'smfFadeScroller\').currentStyle) != "undefined")
{
foreColor = document.getElementById(\'smfFadeScroller\').currentStyle.color.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
smfFadeFrom = {"r": parseInt(foreColor[1]), "g": parseInt(foreColor[2]), "b": parseInt(foreColor[3])};

backEl = document.getElementById(\'smfFadeScroller\');
while (backEl.currentStyle.backgroundColor == "transparent" && typeof(backEl.parentNode) != "undefined")
backEl = backEl.parentNode;

backColor = backEl.currentStyle.backgroundColor.match(/#([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/);
smfFadeTo = {"r": eval("0x" + backColor[1]), "g": eval("0x" + backColor[2]), "b": eval("0x" + backColor[3])};
}
else if (typeof(window.opera) == "undefined" && typeof(document.defaultView) != "undefined")
{
foreColor = document.defaultView.getComputedStyle(document.getElementById(\'smfFadeScroller\'), null).color.match(/rgb\((\d+), (\d+), (\d+)\)/);
smfFadeFrom = {"r": parseInt(foreColor[1]), "g": parseInt(foreColor[2]), "b": parseInt(foreColor[3])};

backEl = document.getElementById(\'smfFadeScroller\');
while (document.defaultView.getComputedStyle(backEl, null).backgroundColor == "transparent" && typeof(backEl.parentNode) != "undefined" && typeof(backEl.parentNode.tagName) != "undefined")
backEl = backEl.parentNode;

backColor = document.defaultView.getComputedStyle(backEl, null).backgroundColor.match(/rgb\((\d+), (\d+), (\d+)\)/);
smfFadeTo = {"r": parseInt(backColor[1]), "g": parseInt(backColor[2]), "b": parseInt(backColor[3])};
}

// List all the lines of the news for display.
var smfFadeContent = new Array(
"', implode('",
"', $context['fader_news_lines']), '"
);
// ]]></script>
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/fader.js"></script>
</div>';
}

For SMF 2.0 RC2 version:

Code: [Select]
global $context, $settings;

if (!empty($context['fader_news_lines']))
{
echo '
<div id="newsfader">
<ul class="reset" id="smfFadeScroller">';

foreach ($context['news_lines'] as $news)
echo '
<li>', $news, '</li>';

echo '
</ul>
</div>
<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/fader.js"></script>
<script type="text/javascript"><!-- // --><![CDATA[
var oNewsFader = new smf_NewsFader({
sSelf: \'oNewsFader\',
sFaderControlId: \'smfFadeScroller\',
sItemTemplate: ', JavaScriptEscape('<strong>%1$s</strong>'), ',
iFadeDelay: ', empty($settings['newsfader_time']) ? 5000 : $settings['newsfader_time'], '
});
// ]]></script>';
}
Title: Re: Make news block fade
Post by: Gurbet_42 on January 29, 2010, 05:57:07 PM
Thanks   [SiNaN].
Title: Re: Make news block fade
Post by: Nothingness on February 03, 2010, 11:12:56 PM
Preview works but why am I getting "Syntax error in block code. Please check the code." when I apply the block.
Title: Re: Make news block fade
Post by: [SiNaN] on February 04, 2010, 03:41:40 AM
It might be a bug related to PHP validation, and your news content. You can disable PHP validation from Admin > SimplePortal > Configuration > General Settings > Disable PHP Validation. I suggest that you enable it back after you create the block.
Title: Re: Make news block fade
Post by: grafitus on February 04, 2010, 05:50:26 AM
Thanks for code [SiNaN]. I've tried, it works. :P
Title: Re: Make news block fade
Post by: Old Fossil on February 04, 2010, 06:52:03 AM
Thanks for code [SiNaN]. I've tried, it works. :P

+1 It sure looks good too.
Title: Re: Make news block fade
Post by: Nothingness on February 04, 2010, 10:00:13 AM
Perfect, thank you [SiNaN]. It works. So this error will be fixed in the next update, no?
Title: Re: Make news block fade
Post by: [SiNaN] on February 04, 2010, 10:20:56 AM
It isn't easy to detect PHP syntax error and this is a rare case. But I'll keep that in mind, if I have a better solution.
Title: Re: Make news block fade
Post by: raffo on May 19, 2010, 10:27:45 AM
it works, but with some problems:

1) when the page loads, users see for a while all the news in the block, that after about 300 milliseconds resize itself

2) it always starts from the first news... it'd be nice to start from a random one adn goes to others always randomly (without repeting before finishing all of them)

3) the news block is too much high... is possible to make a little shorter in height? i inserted height:20px; to style of body, but then the news are unreadable, because appears a scroll sidebar on the side

4) when one news is longer than others, the block continues to resize every single news... :(

thanks
Title: Re: Make news block fade
Post by: Old Fossil on May 19, 2010, 10:35:12 AM
Raffo can you let us have a link to the forum please.

Title: Re: Make news block fade
Post by: raffo on May 19, 2010, 10:41:25 AM
here it's...

i 'll mantain it for some hours... :)
thanks

http://*********
Title: Re: Make news block fade
Post by: Old Fossil on May 19, 2010, 10:46:16 AM
The newsfaders resizing is automatic ie when a smiley or bold text is used.

Have you thought about making the text scroll across the page instead?

Have a look at the portal on www.mkaware.co.uk ( Announcements).

If you want to do it like that then I can point you in the right direction.
Title: Re: Make news block fade
Post by: raffo on May 19, 2010, 10:55:34 AM
thanks, but i don't like the scrolling...

my problem was noticed when i choose the normal SMF news fading... it works only on forum and it is perfect... but it doesn't work on homepage of SP...

using, instead, just the top block of SP, in portal and forum, makes what we are talking about now... :(
Title: Re: Make news block fade
Post by: Old Fossil on May 19, 2010, 10:57:26 AM
No worries it's a preference thing.

Using the top block as you mentioned is another way of course.

Title: Re: Make news block fade
Post by: raffo on May 19, 2010, 11:02:28 AM
so, there isn't a way to replicate in the custom PHP block the same code that SMF use in forum news?
Title: Re: Make news block fade
Post by: Old Fossil on May 19, 2010, 11:04:09 AM
Will have to wait and hope someone who knows coding can help.

Sorry bud.  :-[
Title: Re: Make news block fade
Post by: raffo on May 19, 2010, 11:06:02 AM
thanks man! :)
Title: Re: Make news block fade
Post by: Tricky on August 04, 2011, 08:06:37 AM
Thanks [SiNaN] just what i was looking for
SimplePortal 2.3.8 © 2008-2024, SimplePortal