Share Your Knowledge!

This fast-growing section of our site is the new one-stop shop for educational materials for ExpressionEngine with rich and expert content, from both EllisLab and the community. Submit your article, tip, or solution today!

  • Responsive Videos

    in: Front-end Development, Tips

    We all LOVE videos! But they can be a real difficult thing to do responsively. So here is some code to help you make videos responsive in your next ExpressionEngine CMS site.

    The HTML

    <figure class="video">
    	<div class="video-player">
    		<iframe src="//player.vimeo.com/video/39394380?color=f0a400" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
    	<figcaption><a href="http://leihu.com">James Mathias</a> &mdash; Made By Few</figcaption>

    I use a figure, so that I can add a caption, the important part is the div.video-player around the iframe. Here I use a class of .video on the figure as a best practice for potential CSS targeting.

    Speaking of CSS, here is the LESS object.

    	height: 0;
    	overflow: hidden;
    	padding-bottom: 56.25%; /* 16/9 ratio */
    	padding-top: 30px; /* IE6 workaround */
    	position: relative;
    		// set dimensions and position of elements inside .video-player
    		embed, iframe, img, object, video{
    			height: 100%;
    			left: 0;
    			position: absolute;
    			top: 0;
    			width: 100%;

    That’s all you need. Remember don’t put a width or height attribute on the iframe, the browser will do this math for you!

    You can demo and play with this code here: https://jsfiddle.net/jmathias/g7mwrmxw/

    Now go fill your ExpressionEngine CMS sites with videos, to the brim!

    | Read in 2 minutes
  • Toggling Content

    in: Front-end Development, Tips

    Occasionally you have some information that is needed, but not the most important, and you may want to hide it away, and let the visitor decide when they want to see it. So you toggle that content! Here’s a simple and fast way to add this functionality to your website, it’s reusable and can appear multiple times in a single HTML document.

    Let’s start with the JavaScript. I used jQuery.

    		var txtIs = $(this).attr('data-open');
    		var hideIs = $(this).attr('data-close');
    		var objIs = $(this).attr('data-rel');
    		var toggleObj = $('[data-rev='+objIs+']');
    		if($.trim($(this).text()) === txtIs){
    		// stop THIS href from loading
    		// in the source window
    }); // close (document).ready

    This will listen for .toggle-link clicks and then open and close (toggle) the proper .toggle-content for you.

    Here is the HTML

    <h1>Content Header <a href="#" class="toggle-link" data-rel="toggle-test" data-close="Hide" data-open="Show">Show</a></h1>
    <div class="toggle-content" data-rev="toggle-test">
    	<p>This content is hidden, until the toggle-link is clicked.</p>

    The important bit to remember here is that the values of data-rel and data-rev need to match, and need to be unique from any other pairs in the same HTML document.

    The value of data-close determines what the link’s text will be when the content is visible. And the value of data-open determines the text when the content is hidden. The text in the link should match the value of data-open.

    And lastly, just a little CSS to get our open and closed states.

    	display: none;
    	display: block;

    You can demo and play with this code here: https://jsfiddle.net/jmathias/bqf3ht3y/

    So there you have it another tool for your next ExpressionEngine CMS site.

    | Read in 2 minutes
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases