Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JavaScript Document
- (function( $ ){
- var homeFunc = {
- /* Direction of carousel */
- direction : 'next',
- counter : 0,
- /* Initialise values and functions for home page */
- init : function( options ){
- var settings = {};
- return this.each(function() {
- // If options exist, lets merge them
- // with our default settings
- if ( options ) {
- $.extend( settings, options );
- }
- $(document.getElementById('contentSliderControls')).css('visibility','visible');
- var $prev = document.getElementById('prevSlide'),
- $pause = document.getElementById('pauseSlide'),
- $next = document.getElementById('nextSlide'),
- $lis = $('#contentSlider ul li'),
- $tabLinks = $('#verticalTabs ul li');
- $lis.each(function(i, el) {
- $(el).css('z-index', i).addClass('slide'+i);
- });
- /* Run Carousel
- ****************************************************************/
- homeFunc.timer();
- /* Setup Tabbed area by calling tabbed section
- ****************************************************************/
- homeFunc.tabbedSection($tabLinks);
- /* The pause Click handler
- ****************************************************************/
- $pause.onclick = function(e){
- e.preventDefault();
- if ($('#pauseSlide').length){
- $('#pauseSlide').find('img').attr('src', 'images/icon_home_content_slider_play.gif');
- $(this).attr('id','playSlide');
- var intervalID = null;
- clearInterval(intervalID);
- } else {
- $('#playSlide').find('img').attr('src', 'images/icon_home_content_slider_pause.gif');
- $(this).attr('id','pauseSlide');
- homeFunc.timer('next');
- }
- }
- /* The next Click handler
- ****************************************************************/
- $next.onclick = function(e){
- e.preventDefault();
- homeFunc.direction = 'next';
- if( $('#contentSlider ul li.top').is(':animated') ) {
- homeFunc.animateCarousel('next', 100);
- }else {
- homeFunc.animateCarousel('next');
- }
- }
- /* The previous Click handler
- ****************************************************************/
- $prev.onclick = function(e){
- homeFunc.direction = 'prev';
- e.preventDefault();
- if( $('#contentSlider ul li.top').is(':animated') ) {
- homeFunc.animateCarousel('prev', 100);
- }else {
- homeFunc.animateCarousel('prev');
- }
- }
- }); //End of each function();
- },
- /* Carousel Timer function
- *********************************************************************************************************************************************************************************/
- timer : function(direction){
- setInterval(function() {
- homeFunc.animateCarousel(direction);
- }, 4000, 1);
- },
- /* Vertical Tabbed area functionality
- *********************************************************************************************************************************************************************************/
- tabbedSection : function($tabLinks){
- $tabLinks.click(function(e){
- // On Click remove the current panel class from the previous Panel
- $(".currentP").removeClass("currentP");
- // Find the current tab with the current tab image and remove it
- //$(".currentTab").find('img').remove();
- // On click remove the current tab class from the previous tab
- $(".current").removeClass("current");
- // On click add current tab class to current tab
- $(this).addClass("current");
- // On click add the current tab image to the current tab
- // Store the index of the clicked list item in a variable "href"
- var index = $(this).index() + 1;
- // onClick find the panel with the id of #panel plus the number stored in the "index" variable
- $('#tabPanels').find('#panel' + index).addClass("currentP");
- // prevent the original click event from happening
- e.preventDefault();
- });
- },
- /* Carousel Functionality */
- animateCarousel : function(direction, slideDuration){
- if(homeFunc.counter >= 3){
- homeFunc.counter = 0;
- }else if(homeFunc.counter < 0){
- homeFunc.counter = 3;
- }
- var $top = $('.top'),
- $middle = $('.middle'),
- $bottom = $('.bottom');
- if (slideDuration !== undefined){
- slideDuration = 100;
- }
- if(homeFunc.direction == 'next' || homeFunc.direction === undefined){
- homeFunc.counter ++;
- $('.top, #contentSliderStrap'+homeFunc.counter).animate({opacity: 0}, slideDuration, function() {
- if(homeFunc.counter == 3){
- $('#contentSliderStrap'+homeFunc.counter).removeClass('currentStrap');
- $('#contentSliderStrap1').addClass('currentStrap').animate({opacity: 1}, slideDuration);
- }else {
- $('#contentSliderStrap'+homeFunc.counter).removeClass('currentStrap').next().addClass('currentStrap').animate({opacity: 1}, slideDuration, function() {});
- }
- $top.css({zIndex : 0, opacity: 1});
- $top.removeClass('top').addClass('bottom');
- $middle.css('z-index',2).addClass('top').removeClass('middle');
- $bottom.css('z-index',1).addClass('middle').removeClass('bottom');
- });
- } else if(homeFunc.direction == 'prev'){
- console.log(homeFunc.counter);
- homeFunc.counter --;
- if(homeFunc.counter == 0){
- console.log(homeFunc.counter);
- $('#contentSliderStrap'+homeFunc.counter).removeClass('currentStrap');
- $('#contentSliderStrap3').addClass('currentStrap').animate({opacity: 1}, slideDuration);
- }else {
- $('#contentSliderStrap'+homeFunc.counter).removeClass('currentStrap').prev().addClass('currentStrap').animate({opacity: 1}, slideDuration, function() {});
- }
- $top.animate({ opacity: 0}, slideDuration, function() {
- $top.css({zIndex : 0, opacity: 1});
- $top.removeClass('top').addClass('bottom');
- $middle.css('z-index',2).addClass('top').removeClass('middle');
- $bottom.css('z-index',1).addClass('middle').removeClass('bottom');
- });
- }
- },
- }
- $.fn.homeFunc = function( method ) {
- // Method calling logic
- if ( homeFunc[method] ) {
- return homeFunc[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
- } else if ( typeof method === 'object' || ! method ) {
- return homeFunc.init.apply( this, arguments );
- } else {
- $.error( 'Method ' + method + ' does not exist on jQuery.quizMethods' );
- }
- };
- })( jQuery );
- $('html').homeFunc();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement