/* * Author : Fbolaji * date: 23-07-2014 * description: carouselize - carousel to handle video, flash or image in each slides. * video take priority if all the media types are authored for one item. * */ var EP2 = EP2 || {}; //Used by blue hive flash function controlFlash(string, flashId) { try { var f = findFlash(flashId); return f.controlFlash(string); } catch(e) { return 0; } } function flashEvent(string){ } function getProperty(value, flashId){ var f = findFlash(flashId); try{ return f.getProperty(value); } catch(e) { console.log("Error in getProperty: " + e); } } function propertyReturned(property, value){ flashDuration = value; return flashDuration; } function findFlash(flashId){ return document.getElementById(flashId); } !function($, window, document, undefined) { "use strict"; EP2.fetchedData = {}; EP2.mergedData = {}; EP2.carouselize = function (options) { var defaults = { el: 'carouselize', // element id selector .. no class selector allowed ajaxUrl: '/cs/ContentServer?pagename='+ EP2.Globals.siteName +'/service/CarouselJsonService', bootStrapJSON: {} }; this.options = $.extend({}, defaults, options); this.element = this.options.el; this.$el = $('#'+this.options.el); this.site = EP2.Globals.siteName || 'EP2_ENGInE'; this.recId = parseInt($('body').attr('data-carousel')); this.ajaxUrl = this.options.ajaxUrl + '&site=' + this.site +'&recId=' + this.recId; this.bootStrapJSON = this.options.bootStrapJSON; this.init(); }; EP2.carouselize.prototype = { init: function () { /*var hideElements = '.disclaimer, .innerBox'; this.$el.find('.innerBox').hide('fast'); */ this.renderSlideList(); //console.log(this.ajaxUrl); }, setupAjaxCallbacks: function () {//setting for ajax interaction //whenever ajax is trigger, the ajax setting activated $(document).ajaxStart(function () { if(!$('#ajax-status').length){ $('body').append('
'); } $('#ajax-status div').html('
'); $('#ajax-status').show(); }).ajaxStop(function (event, xhr, ajaxOptions, thrownError) { $('#ajax-status').fadeOut(); }).ajaxError(function (event, xhr, ajaxOptions, thrownError) { $('#ajax-status span').text("Sorry, we are currently unable to load the content you have requested. Please try again later."); $('#ajax-status').show().delay(700).fadeOut(); }); }, renderSlideList: function(){ var $this = this, $thisEle = this.$el, $templateToRender ="", staticData = this.bootStrapJSON, listRequest = this.ajaxUrl, templateHTML = function(){ // HTML element template to render for(var i=0; i'+ $tctas[j].btnText +''; } else{ $tctasBtnBuild += ''; } } } if($btnLink !== ""){ if($btnTarget!==""){ $btn = ''; }else{ $btn = ''; } }else{ $btn =''; } if(cssBlockStyle == "GreyBlock"){ cssBlockColor = "blockTransparent"; }else if(cssBlockStyle == "Block"){ cssBlockColor = "blockSlate"; }else{ cssBlockColor = "transparent"; } $ctaBlock = '

'+ EP2.mergedData.CarouselItems[i].headline +'

'+ EP2.mergedData.CarouselItems[i].subline +'

'+$btn +$tctasBtnBuild +'
'; if(!$.isEmptyObject(EP2.mergedData.CarouselItems[i].disclaimers)){ $disclaimer = '

'+$disclaimer['left-text']+'

'+$disclaimer['right-text']+'

'; }else{ $disclaimer =""; } if(EP2.mergedData.CarouselItems[i].media.imageUrl !== undefined && mediatype === "image"){ $img = ''+EP2.mergedData.CarouselItems[i].media.title+''; whichMedia= '
'+ $img + $ctaBlock + $disclaimer + '
'; } else if(EP2.mergedData.CarouselItems[i].media.video !== undefined && mediatype === "video"){ $vid =''; whichMedia = '
'+ $vid + $ctaBlock + $disclaimer + '
'; } else if(EP2.mergedData.CarouselItems[i].media.flash !== undefined && mediatype === "flash"){ $flash = '
'; whichMedia = '
'+ $flash + $ctaBlock + $disclaimer + '
'; } else if(EP2.mergedData.CarouselItems[i].posterImageUrl !== undefined) { $img = ''+EP2.mergedData.CarouselItems[i].buttonText+''; whichMedia= '
'+ $img + $ctaBlock + $disclaimer + '
'; } //console.log( $vid, $flash, $img ); $templateToRender += whichMedia; } $thisEle.empty().append($templateToRender); //console.log("fetched:", EP2.fetchedData, "merged:",EP2.mergedData); $this.prepareControls(); }; EP2.mergedData = $.extend({}, staticData); //ajax call if( this.ajaxUrl !== null){ this.setupAjaxCallbacks(); $.getJSON( this.ajaxUrl, function(data){ EP2.fetchedData = data; //console.log('fetching carousel data ..'); }).done(function( data ) { EP2.mergedData = data; //console.log("fetched carousel json data :", data); //EP2.mergedData = $.extend({}, EP2.fetchedData); templateHTML(); //console.log("done!", EP2.mergedData); if (EP2.mergedData.CarouselItems.length == 1) { $thisEle.off('mouseover'); $thisEle.off('mouseleave'); $thisEle.find('article .innerBox').delay(500).fadeIn(); $('.nextPrevBtn').addClass('visuallyhidden'); } }).fail(function(){ console.log('fetching carousel data ..failed'); }); }else{ EP2.mergedData = staticData; templateHTML(); } /*if($.isEmptyObject(EP2.mergedData)){ console.log("no data to populate.."); return; }*/ }, prepareControls : function(){ this.pagerElements = '
previousnext
'; this.$el.children().wrapAll('