Last active
April 28, 2016 17:46
-
-
Save stevewithington/3db029bd903908b29199 to your computer and use it in GitHub Desktop.
Mura CMS: How to allow for responsive YouTube video embeds in the home page carousel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
1. Create a "Class Extension" for Link / Video | |
2. Replace the existing dspCarouselByFeedName() method in the theme's contentRenderer.cfc with the one below | |
3. Go add some Link/Video content types to your content collection. | |
For example, copy the YouTube "embed" video src link (Share > Embed) [e.g., https://www.youtube.com/embed/_l09H-3zzgA] | |
and paste that into the "URL" field when creating a content item. | |
---> | |
<cffunction name="dspCarouselByFeedName" output="false"> | |
<cfargument name="feedName" type="string" default="Slideshow" /> | |
<cfargument name="showCaption" type="boolean" default="true" /> | |
<cfargument name="cssID" type="string" default="myCarousel" /> | |
<cfargument name="size" type="string" default="custom" hint="If you want to use a custom height/width, then use 'custom' ... otherwise, you can use 'small, medium, large' OR any other predefined custom image size 'name' you created via the back-end administrator." /> | |
<cfargument name="width" type="numeric" default="1280" hint="width in pixels" /> | |
<cfargument name="height" type="numeric" default="500" hint="height in pixels" /> | |
<cfargument name="interval" type="any" default="5000" hint="Use either milliseconds OR use 'false' to NOT auto-advance to next slide." /> | |
<cfargument name="autoStart" type="boolean" default="true" /> | |
<cfargument name="showIndicators" type="boolean" default="true" /> | |
<cfscript> | |
var local = {}; | |
local.imageArgs = {}; | |
if ( not ListFindNoCase('small,medium,large,custom', arguments.size) and variables.$.getBean('imageSize').loadBy(name=arguments.size,siteID=variables.$.event('siteID')).getIsNew() ) { | |
arguments.size = 'custom'; | |
}; | |
if ( not Len(Trim(arguments.size)) or LCase(arguments.size) eq 'custom' ) { | |
local.imageArgs.width = Val(arguments.width); | |
local.imageArgs.height = Val(arguments.height); | |
} else { | |
local.imageArgs.size = arguments.size; | |
}; | |
</cfscript> | |
<cfsavecontent variable="local.str"><cfoutput> | |
<!--- BEGIN: Bootstrap Carousel ---> | |
<!--- IMPORTANT: This will only output items that have associated images ---> | |
<cfset local.feed = variables.$.getBean('feed').loadBy(name=arguments.feedName)> | |
<cfset local.iterator = local.feed.getIterator()> | |
<cfif local.feed.getIsNew()> | |
<div class="container"> | |
<div class="alert alert-info alert-block"> | |
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button> | |
<h4>Ooops!</h4> | |
The <strong>#HTMLEditFormat(arguments.feedName)#</strong> Content Collection/Local Index does not exist. | |
</div> | |
</div> | |
<cfelseif local.iterator.hasNext()> | |
<div id="#arguments.cssID#" class="carousel slide" data-interval="#arguments.interval#"> | |
<!--- Indicators ---> | |
<cfif arguments.showIndicators> | |
<ol class="carousel-indicators"> | |
<cfset local.iterator.reset()> | |
<cfset local.idx = 0> | |
<cfloop condition="local.iterator.hasNext()"> | |
<cfset local.item=iterator.next()> | |
<cfif local.item.getSubtype() eq 'Video' or ListFindNoCase('jpg,jpeg,gif,png', ListLast(local.item.getImageURL(), '.'))> | |
<li data-target="###arguments.cssID#" data-slide-to="#idx#" class="<cfif local.idx eq 0>active</cfif>"></li> | |
<cfset local.idx++> | |
</cfif> | |
</cfloop> | |
</ol> | |
</cfif> | |
<!--- Wrapper for slides ---> | |
<div class="row carousel-inner"> | |
<cfset local.iterator.reset()> | |
<cfset local.idx = 0> | |
<cfloop condition="local.iterator.hasNext()"> | |
<cfset local.item=iterator.next()> | |
<cfif ListFindNoCase('jpg,jpeg,gif,png', ListLast(local.item.getImageURL(), '.'))> | |
<div class="row item<cfif local.idx eq 0> active</cfif>"> | |
<img src="#local.item.getImageURL(argumentCollection=local.imageArgs)#" alt="#HTMLEditFormat(local.item.getTitle())#"> | |
<cfif arguments.showCaption> | |
<div class="container"> | |
<div class="carousel-caption"> | |
<h3><a href="#local.item.getURL()#">#HTMLEditFormat(local.item.getTitle())#</a></h3> | |
#local.item.getSummary()# | |
<p><a class="btn btn-larg btn-primary" href="#local.item.getURL()#">Read More</a></p> | |
</div> | |
</div> | |
</cfif> | |
</div> | |
<cfset local.idx++> | |
</cfif> | |
<cfif local.item.getSubType() eq 'Video'> | |
<div class="embed-responsive embed-responsive-16x9 row item<cfif local.idx eq 0> active</cfif>"> | |
<iframe class="embed-responsive-item" src="#local.item.getBody()#"></iframe> | |
</div> | |
<cfset local.idx++> | |
</cfif> | |
</cfloop> | |
</div> | |
<cfif local.idx> | |
<!--- Controls ---> | |
<cfif local.idx gt 1> | |
<a class="left carousel-control" href="###arguments.cssID#" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a> | |
<a class="right carousel-control" href="###arguments.cssID#" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a> | |
<!--- AutoStart ---> | |
<cfif arguments.autoStart> | |
<script>jQuery(document).ready(function($){$('###arguments.cssID#').carousel({interval:#arguments.interval#});});</script> | |
</cfif> | |
</cfif> | |
<cfelse> | |
<div class="alert alert-info alert-block"> | |
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button> | |
<h4>Oh snap!</h4> | |
Your feed has no items <em>with images</em>. | |
</div> | |
</cfif> | |
</div> | |
<cfelse> | |
<div class="alert alert-info alert-block"> | |
<button type="button" class="close" data-dismiss="alert"><i class="fa fa-remove"></i></button> | |
<h4>Heads up!</h4> | |
Your feed has no items. | |
</div> | |
</cfif> | |
<!--- // END: Bootstrap Carousel ---> | |
</cfoutput></cfsavecontent> | |
<cfreturn local.str /> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment