Quantcast
Channel: MyBB Community Forums - Tutorials
Viewing all articles
Browse latest Browse all 690

[Tutorial] Read More Break bbcode

$
0
0
After spending many hours searching for an easy way to include a bbcode break for Announcement postings on the portal, I have found one that works really well.

The utilizes jquery. I have attached the files that I modified for my website. The originals can be found, here. The original version included "..." and cut off 100 characters after the break point. I removed the "..." and set the cut off at 0 characters.

1. Download these files and place them on your server. Mine are at /jscripts.

2. Modify Template -> Portal Templates -> Portal
Add the following code underneath {$headerinclude}
Code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script src="jscripts/jquery.expander.js"></script>
<script src="jscripts/jquery.expander.min.js"></script>

<script>
$(document).ready(function() {
  var opts = {collapseTimer: 4000};

  $.each(['beforeExpand', 'afterExpand', 'onCollapse'], function(i, callback) {
    opts[callback] = function(byUser) {
      var by, msg = '<div class="success">' + callback;

      if (callback == 'onCollapse') {
        msg += ' (' + (byUser ? 'user' : 'timer') + ')';
      }
      msg += '</div>';

      $(this).parent().parent().append(msg)
    }
  });

  $('dl.expander dd').eq(0).expander();
  $('dl.expander dd').slice(1).expander(opts);


  $('ul.expander li').expander({
    slicePoint: 0,
    widow: 2,
    expandSpeed: 0,
    userCollapseText: '[^]'
  });

  $('div.expander').expander();
});

</script>

3. Create bbcode
Go to Configuration -> MyCode -> Add New MyCode

Regular Expression:
Code:
\[readmore\](.*?)\[/readmore\]

Replacement Text:
Code:
<div class="expander">$1</div>

Now anything within the readmore tags will be hidden behind a readmore link on the portal page. Also, by only adding the scripts to the Portal page, your announcement thread will still look like normal.

A demo can be seen on my website at: http://www.amongshadows.com

.zip  jquery.expander.zip (Size: 6.55 KB / Downloads: 1)

Viewing all articles
Browse latest Browse all 690

Trending Articles