Log in

View Full Version : How to add a widget to a popup window


MickDoneDee
04-14-2009, 04:24 AM
I'll preface this by saying I'm not a coder but, through trial and error, I managed to get this to work.

The shape of most widgets make them difficult to place neatly anywhere on a vbulletin forum. The only alternative is to make them popup in a new window which has the same dimensions as the popup.

The java-based widget I wanted to add to my cricket forum can be found at Cricinfo (http://www.cricinfo.com/widgets/). Go to my World A Team cricket forum (http://world-a-team.com/cricket-forum.php) to see a demo. Click the "Live Scores" link on the navbar. The popup window opens first. The widget inside the window is a little slower to load. You must have java enabled in your browser.

What you will need to edit or create:

1. Create a standard phrase. I created Varname: live_scores; Text: Live Scores. So, the phrase variable in the navbar template is $vbphrase[live_scores].

2. Create a plugin. Plugin Title: live_scores; Hook Location: misc_start; Plugin PHP Code:

// ############################### start live scores ###############################
if ($_REQUEST['do'] == 'livescores')
{
eval('print_output("' . fetch_template('live_scores') . '");');
}

3. Create a template. I created a template called live_scores and copied contents of shell_blank template into it. I also replaced $header; $navbar; $html; $footer from between the <body> tags with the widget javascript. I also replaced $pagetitle between the <title> tags with $vbphrase[live_scores].

4. Edit navbar template. I used the code for the Buddy List popup as a template for the widget popup and replaced references to buddylist with livescores. I also ammended the Width and Height values to match the widget W&H values. Buddy List popup code looks like this:
<td class="vbmenu_control"><a href="#" onclick="window.open('misc.php?$session[sessionurl]do=buddylist&amp;focus=1','buddylist','statusbar=no,me nubar=no,toolbar=no,scrollbars=yes,resizable=yes,w idth=250,height=300'); return false;">$vbphrase[open_buddy_list]</a></td>I copied and modified it to look like:
<!-- Live Scores -->
<td class="vbmenu_control"><a href="#" onclick="window.open('misc.php?$session[sessionurl]do=livescores&amp;focus=1','livescores','statusbar=no, menubar=no,toolbar=no,scrollbars=no,resizable=no,w idth=400,height=270'); return false;">$vbphrase[live_scores]</a></td>
<!-- End Live Scores -->Make sure you place the new popup code inside this conditional: <if condition="$show['popups']">. An explanation of why can be found at vBulletin.com (http://www.vbulletin.com/docs/html/main/templates_vbmenu_showpopups). The conditional is already in the navbar template. Search the template for it and place the code below it.

5. Edit misc.php. Add your template to get it pre-cached. I added the code red and bolded:
// pre-cache templates used by specific actions

'showsmilies' => array(
'help_smilies',
'help_smilies_smilie',
'help_smilies_category',
),
'livescores' => array(
'live_scores',
)
);Please add your suggestions if anything can be improved.