$(document).ready(function(){ } /* light box ----------------------------------------------*/ var lightBox={ init:function(){ var self=this; self.localvideo={ autoPlay:false, preload:'metadata', webm :true, ogv:false } this.bindUIActions(); },generateVideo:function(src,poster){ var self=this; //here we generate video markup for html5 local video //We assumed that you have mp4 and webm or ogv format in samepath (video/01/01.mp4 & video/01/01.webm) var basePath=src.substr(0, src.lastIndexOf('.mp4')); var headOptions=''; if (self.localvideo.autoPlay){ headOptions+=' autoplay'; } headOptions +='preload="'+self.localvideo.preload+'"'; var markup=''+'
'; return markup; },bindUIActions:function(){ var self=this, $body=$('body'); self.singleBox($('.tj-lightbox')); $('.tj-lightbox-gallery').each(function(){ self.galleyBox($(this)); }); $('body').on('click','.mfp-container',function(e){ if( e.target !== this ) return; $(this).find('.mfp-close').trigger('click'); }); },singleBox:function($elem){ var self=this; $elem.magnificPopup({ type: 'image', closeOnContentClick: false, closeOnBgClick:false, mainClass: 'mfp-fade', iframe: { markup: '
'+ '
'+ ''+ '
'+ '
' }, callbacks:{ elementParse: function(item) { var popType=item.el.attr('data-type')||'image'; if (popType=='localvideo'){ item.type='inline'; var poster=item.el.attr('data-poster')||''; item.src=self.generateVideo(item.src,poster); }else{ item.type=popType; } }, markupParse: function(template, values, item) { values.title = item.el.attr('title'); }, open: function() { sideS.$exteras=$('.move-with-js').add('.mfp-wrap'); $('.popup-mejs').mediaelementplayer(); } }, image: { verticalFit: true } }); },galleyBox:function($elem){ var self=this, $this=$elem, itemsArray=[]; $elem.magnificPopup({ delegate: '.lightbox-gallery-item', closeOnBgClick:false, closeOnContentClick:false, removalDelay: 300, mainClass: 'mfp-fade', iframe: { markup: '
'+ '
'+ ''+ '
'+ '
'+ '
' }, gallery: { enabled: true, tPrev: 'Previous', tNext: 'Next', tCounter: '%curr% / %total%', arrowMarkup: '', }, callbacks:{ elementParse:function(item){ var popType=item.el.attr('data-type') || 'image', source=item.el.attr('href'); if (popType=='localvideo'){ item.src=self.generateVideo(source,item.el.attr('data-poster')||''); item.type='inline'; }else{ item.type=popType; } }, open:function(){ sideS.$exteras=$('.move-with-js').add('.mfp-wrap'); $('.popup-mejs').mediaelementplayer(); }, change: function() { if (this.isOpen) { this.wrap.addClass('mfp-open'); } //console.log($('.popup-mejs')); $('.popup-mejs').mediaelementplayer(); } }, type: 'image' // this is a default type }); itemsArray=[]; } } lightBox.init(); /* accordion This has an option to open the desired tab by default you can add a class of .active to the item you want to be oppened by default ----------------------------------------------*/ var acc,accordion={ settings : { accUIelClass : ".accordion > .item > .head a", openFirstOne : true //change to false if you want them all be closed by default }, init : function(){ acc = this.settings; this.bindUIActions(); //close all bodies except the stated one $(".accordion > .item:not(.active) > .body").hide(); // if none of els are stated active open up the first one if ( $(".accordion > .item.active").length == 0 && acc.openFirstOne ) $(".accordion > .item:first-child > .body").addClass('active').slideDown(); }, bindUIActions : function(){ var self = this, $body = $('body'); $body.on('click', acc.accUIelClass, function(event){ var $this = $(this); $this.parents(".item").addClass("active").siblings().removeClass("active"); $(".accordion > .item:not(.active) > .body").slideUp(); $this.parent().next().slideDown(); event.preventDefault(); return false; }); } } accordion.init(); /* Tabs This has an option to open the desired tab by default you can add a class of .active to li item and .tab-item to make it active ----------------------------------------------*/ var tabS,tabs={ settings : { tabsBodiesExceptActive : $(".tabs > .tabs-body > .tab-item:not(.active)"), tabsUIelClass : ".tabs > ul.tabs-head a" }, init : function(){ tabS = this.settings; this.bindUIActions(); //if we dont have an active one set the first one to be active if ( $(".tabs > .tabs-head > li.active").length == 0) $(".tabs > .tabs-body > .tab-item:first-child, .tabs > .tabs-head > li:first-child").addClass('active'); }, bindUIActions : function(){ var self = this, $body = $('body'); $body.on('click', tabS.tabsUIelClass, function(event){ var $this = $(this).parent(), index = $("ul.tabs-head li").index($this); $this.addClass('active').siblings().removeClass('active'); $(".tabs > .tabs-body > .tab-item").eq(index).addClass('active').siblings().removeClass('active'); //$this.parent().addClass('active').siblings().removeClass("active"); event.preventDefault(); return false; }); } } tabs.init(); /* Team carousel Please refer to the documentation of MasterSlider ----------------------------------------------*/ var teamCarousel = { init : function(){ var slider = new MasterSlider(); slider.setup('teamcarousel' , { loop:true, width:240, height:240, speed:20, view:'fadeBasic', preload:0, space:0, wheel:true }); slider.control('arrows'); slider.control('slideinfo',{insertTo:'#teamcarousel-info'}); } } if ($('#teamcarousel').length>0){ teamCarousel.init(); } var msSlider={ //This is the function that controlls all masterslider instances or atleast it tries to do! init:function($target){ var self=this; //Select the target which can be passed to the function or auto selected from DOM var $elem=$target || $('.tj-ms-slider'); //Call the main function that apply master slider on selected elements $elem.each(function(){ var $this=$(this); //Some basic settings var msOptions={ ewidth:$this.attr('data-width')|| $this.width(), eheight:$this.attr('data-height') || $this.height(), layout:$this.attr('data-layout') || 'boxed', view:$this.attr('data-view') || 'basic', dir:$this.attr('data-dir')||'h', showCounter:$this.attr('data-counter') || false, isGallery:$this.attr('data-gallery') || false, autoHeight:$this.attr('data-autoheight') || false, hasPlay:$this.attr('data-playbtn') || false, galleryWrapper:$this.parents('.tj-ms-gallery'), mouse:($this.attr('data-mouse')||true)==true, fillMode:$this.attr('data-fillmode')||'fill', initialPlay:false } self.runSlider($this,msOptions); }); }, runSlider:function($elem,options){ var self=this; var slider = new MasterSlider(), elemID=$elem.attr('id')||''; slider.setup(elemID , { width:options.ewidth, height:options.eheight, layout:options.layout, view:options.view, dir:options.dir, autoHeight:options.autoHeight, space:0, preload:1, centerControls:false, mouse:options.mouse, fillMode:options.fillMode, overPause:false }); slider.control('arrows',{autohide:false}); if (options.hasPlay){ slider.control('timebar' , {autohide:false,color:"#dc971f"}); } if (options.isGallery){ self.makeGallery($elem,slider); } slider.api.addEventListener(MSSliderEvent.INIT , function(){ var $controlsWrapper=$elem.find('.ms-container'), $controlUI=$('
').appendTo($controlsWrapper); //Play pause button if (options.hasPlay){ var playBtn=$('
').addClass('tj-playbtn').appendTo($controlUI); self.addPlay(slider,playBtn,options); } //Next & Prev buttons $controlUI.append($controlsWrapper.find('.ms-nav-prev')); //First one is prev and last next add anything in betwen(eg.counter) if (options.showCounter){ var counterMarkup='
'+ ''+(slider.api.index()+1)+''+ '/'+ ''+slider.api.count()+''+ '
'; var $counterMarkup=$(counterMarkup).appendTo($controlUI), $current=$counterMarkup.find('.counter-current'); self.sliderCounter($elem,slider,$current); } slider.api.resume(); $controlUI.append($controlsWrapper.find('.ms-nav-next')); $(window).trigger('resize'); }); },sliderCounter:function($elem,slider,$current){ var self=this; slider.api.addEventListener(MSSliderEvent.CHANGE_START , function(){ //slider slide change listener $current.html(''+(slider.api.index()+1)+''); }); },makeGallery:function($elem,slider){ //Do the gallery things here... var direction=($elem.hasClass('tj-vertical-gallery'))?'v':'h'; slider.control('thumblist' , {autohide:false , dir:direction}); },addPlay:function(slider,playbtn,options){ if(options.initialPlay){ slider.api.resume(); playbtn.addClass('btn-pause'); } playbtn.click(function(){ if(slider.api.paused){ slider.api.resume(); playbtn.addClass('btn-pause'); }else{ slider.api.pause(); playbtn.removeClass('btn-pause'); } }); } } /* Responsive behavior handler ----------------------------------------------*/ var responsive={ init:function(){ var self=this; self.mdWidth=992; self.$window=$(window); self.folio={},self.blog={}; self.bindUIActions(); if (self.$window.width()<=self.mdWidth){ self.portfolio('md'); self.absPortfolio('md'); }else{ self.portfolio(); self.absPortfolio(); } }, portfolio:function(state){ var self=this, wHeight=$(window).height(); self.folio.pHead=$('.parallax-head'); self.blog.pHead=$('.header-cover'); self.folio.pContent = $('.parallax-contents'); self.folio.mdDetail = $(".portfolio-md-detail"); var self=this; if (state == 'md'){ self.folio.pHead.css('height',wHeight); self.blog.pHead.css('height',wHeight); self.folio.pContent.css('marginTop',self.$window.height()); self.folio.mdDetail.css('marginTop',-$(".portfolio-md-detail").outerHeight()); }else{ self.folio.pHead.css('height',600); self.blog.pHead.css('height',600); self.folio.pContent.css('marginTop',600); } }, absPortfolio:function(state){ var self=this; if (state == 'md'){ $(".set-height-mobile").height(self.$window.height()-$(".page-side").outerHeight()); }else{ $(".set-height-mobile").css('height','100%'); } }, bindUIActions:function(){ var self=this; $(window).on('debouncedresize',function(){ if ($(this).width()<=self.mdWidth){ self.portfolio('md'); self.absPortfolio('md'); }else{ self.portfolio(); self.absPortfolio(); } }); } } /*Initialize require methods ----------------------------------------------*/ var initRequired={ init:function(){ $(window).load(function(){ portfolios.init(); blogrid.init(); }) msSlider.init(); ajaxFolio.init(); blog.init(); //imageFill.init($('.fill-images')); $('.sync-width').each(function(){ syncWidth($(this),$(this).parent('.sync-width-parent').first()); }); setBg($('.set-bg')); sidebar.init(); responsive.init(); parallaxElems.init(); videobg(); //contact form handler submitContact(); setMinHeight(); inviewAnimate($('.inview-animate')); touchDevices(); this.bindUIActions(); }, bindUIActions:function(){ $(window).on('debouncedresize',function(){ setMinHeight(); }); } } initRequired.init(); }); //Add some fallbacks for touch devices function touchDevices(){ if(isTouchSupported()){ $('body').addClass('touch-device'); }else{ $('.videobg-fallback').on('click',function(e){ e.preventDefault(); return false }); } } //trigger background videos function videobg(){ $('.owl-videobg').owlVideoBg({ autoGenerate:{ posterImageFormat:'png' }, preload:'auto' }); } //Set min-height for pages function setMinHeight(){ var pageWrapper=$('.page-wrapper'); if (pageWrapper.parents('#main-content.abs').length==0){ pageWrapper.css('min-height',$(window).height()); } } //center an element function centerIt(elem,height,offset){ if (offset==undefined){ offset=100; } if(height=='parent'){ height=elem.parents().height(); } var elemHeight=elem.height(), elemMargin; if ((height-elemHeight)>2*offset){ //We have enough space elemMargin=(height-elemHeight)/2; } else{ //Just set basic margin elemMargin=offset; } elem.css('margin-top',elemMargin); } //Inview scale handler function inviewAnimate(elem){ elem.each(function(){ $(this).bind('inview', function(event, isInView, visiblePartX, visiblePartY) { var $this=$(this); if (isInView) { // element is now visible in the viewport $this.addClass('visible-view'); $this.unbind('inview'); if (visiblePartY == 'top') { // top part of element is visible $this.addClass('visible-view'); $this.unbind('inview'); } } }); }); } //Set background image base on child image function setBg($elem){ $elem.each(function(){ var $this=$(this); var bgImg = $this.find('img').first(); $this.css({ 'background' : 'url('+bgImg.attr('src')+') no-repeat 50% 50%', 'background-size':'cover' }); bgImg.hide(); }); } //Sync width child,parent function syncWidth($child,$parent){ $child.css('width',$parent.width()); $(window).on('debouncedresize',function(){ syncWidth($child,$parent); }); } //Ajax contact form function submitContact() { var contactForm = $('form#contact-form'); contactForm.submit(function(e) { e.preventDefault(); if ($("#alert-wrapper").length) { return false; } var alertWrapper = $('
').appendTo(contactForm); $('form#contact-form .alert').remove(); var hasError = false, ajaxError = false; //form input validation contactForm.find('.requiredField').each(function() { if ($.trim($(this).val()) == '') { var labelText = $(this).attr('placeholder'); alertWrapper.append('
You forgot to enter your ' + labelText + '.
'); hasError = true; } else if ($(this).hasClass('email')) { var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; if (!emailReg.test($.trim($(this).val()))) { var labelText = $(this).attr('placeholder'); alertWrapper.append('
You\'ve entered an invalid ' + labelText + '.
'); hasError = true; } } }); //Showing alert popup var showAlert = new TimelineLite({paused: true}); hideAlert = new TimelineLite({paused: true}); showAlert.to(alertWrapper, 0.3, {opacity: 1, top: '30%'}); hideAlert.to(alertWrapper, 0.3, {opacity: 0, top: '60%', onComplete: function() { alertWrapper.remove(); }}); if (hasError) { //Thers is error in form inputs show alerts showAlert.play(); alertWrapper.find('button').on('click', function() { hideAlert.play(); }) } else { //Validation passed send form data to contact.php file via ajax var formInput = $(this).serialize(); $.ajax({ type: 'POST', url: $(this).attr('action'), dataType: 'json', data: formInput, success: function(data) { //Ajax request success if (data.status == "error") { ajaxError = true; contactForm.append('
Sorry There was an error sending your message!
'); } else if (data.status == 'ok') { contactForm.slideUp(300, function() { $(this).before('
Thanks Your email has been delivered.
'); }); } }, error: function() { //Ajax request success ajaxError = true; $('form#contact-form').append('
Sorry There was an error sending your message!
'); } }); } if (ajaxError) { //Ajax request had some errors showAlert.play(); alertWrapper.find('button').on('click', function() { hideAlert.play(); }); } return false; }); } /* Detect touch devices*/ function isTouchSupported(){ //check if device supports touch var msTouchEnabled = window.navigator.msMaxTouchPoints; var generalTouchEnabled = "ontouchstart" in document.createElement("div"); if (msTouchEnabled || generalTouchEnabled) { return true; } return false; } /* * debouncedresize: special jQuery event that happens once after a window resize */ (function($) { var $event = $.event, $special, resizeTimeout; $special = $event.special.debouncedresize = { setup: function() { $( this ).on( "resize", $special.handler ); }, teardown: function() { $( this ).off( "resize", $special.handler ); }, handler: function( event, execAsap ) { // Save the context var context = this, args = arguments, dispatch = function() { // set correct event type event.type = "debouncedresize"; $event.dispatch.apply( context, args ); }; if ( resizeTimeout ) { clearTimeout( resizeTimeout ); } execAsap ? dispatch() : resizeTimeout = setTimeout( dispatch, $special.threshold ); }, threshold: 150 }; })(jQuery);