Easily add multiple lightbox style popup videos to your page using Flowplayer and jQuery Tools Overlay

Adding a video to your page is easy enough by embedding directly or by using something like flashembed to embed Flash. What we needed to do was have multiple links on a page that would each open specific videos, whilst still keep the same generic JavaScript somewhere in a separate page template file. The accompanying CSS also had to stay in a separate CSS file and also needed to be generic. Our videos were all in .FLV format and needed to pop over the content in a nice overlay so as not to disturb the flow of the page.

Blacktrash have a nice demo of the kind of functionality we needed but it wasn’t quite generic enough to manage our very different sized videos. The code below, based on this example using Flowplayer and jQuery Tools Overlay, is simple enough that you can easily add multiple videos to a page. The size of the video player is determined by the html5 style attributes “data-width” and “data-height” on each “a” link which are picked up by jQuery and used to resize the player. If you do not specify these then the default is used, as given by the CSS.


<html>
<head>
<!-- include the flowplayer, jQuery and jQuery Tools libraries -->
<script src="http://releases.flowplayer.org/js/flowplayer-3.2.11.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="http://cdn.jquerytools.org/1.2.6/all/jquery.tools.min.js" type="text/javascript" charset="utf-8"></script>

<!-- set up the flowplayer to play videos in an overlay using jQuery Tools Overlay -->
<script type="text/javascript">
  $(function () {
    var player;
    $("a[rel]").overlay({
      mask: {
        color: '#000',
        opacity: 0.2
      },
      onLoad: function () {
		// create player object and load in the href of the link clicked as the source of the video
	    player = $f("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.15.swf",this.getTrigger().attr("href"));
		player.load();
		// set the height and width based on data-height and data-width
		$("#player").height(this.getTrigger().attr("data-height"));
		$("#player").width(this.getTrigger().attr("data-width"));
      },
      onClose: function () {
        player.unload();
      }
    });
  });
</script>

<!-- set up the CSS to hide the overlay by default and set up default height and width for the player -->
<style>
#overlay {
      display: none;
      padding: 40px;
    }
    .close {
      background:url(http://flowplayer.org/media/img/overlay/close.png) no-repeat;
      position:absolute;
      top:2px;
      right:5px;
      display:block;
      width:35px;
      height:35px;
      cursor:pointer;
    }
    #player {
      display: block;
      width: 600px;
      height: 300px;
      margin: 0;
    }
    #player *:focus {
      outline-style: none;
    }
</style>
</head>
<body>

<!-- each link contains a reference to the video to be played in flowplayer, the JavaScript above ensures they are played in an overlay -->
<a rel="#overlay" href="http://www.sitename.com/video/video1.flv">Video 1</a>
<a rel="#overlay" href="http://www.sitename.com/video/video800x600.flv" data-height="600" data-width="800">800x600 Video</a>

<!-- the overlay <div> itself is empty apart from a &amp;nbsp; and hidden using CSS to make sure it isn't shown on screen -->
<div id="overlay"><a class="close"></a><div id="player">&amp;nbsp;</div></div>

</body>
</html>

You can do a lot more with flowplayer and overlays so this is just a starting point but the approach is generic enough that any of the web team can add nice popup videos to a page just by adding a simple “a” link.

Fixing the DotNetNuke javascipt menu bug in IE8 (dnn.dom.positioning.js)

For some reason my dnnNAV menus which worked on one site weren’t working on another. In IE8 the menus were rolling over fine but could not be clicked on to go to other pages. The javascript error was with the dnn.dom.positioning.js file, which I had not touched on either site.

Turns out the error is due to how the z-index element is used in the javascript. As found from the DotNetNuke forums, where surprisingly someone had an answer:

This error occurs because javascript is trying to retrieve the z-index order of the sub menu, which IE8 returns the default value of auto.

As a workaround edit the menu style sheet as follows.

Change the css file menu.css wich is in the folder “/Portals/_default/skins/MinimalExtropy/css/” :

/*  SUB Menu Normal */
.main_dnnmenu_submenu {
z-index:1;
border:1px solid #C0D6E5;
}

Press CTRL+F5 in the end to force the refresh of the css