//Featured Content Glider: By http://www.dynamicdrive.com //Created: Dec 22nd, 07' //Updated (Oct 26th, 09 - Ahmed Masud): Added Fading Support: use "fade-in-place" for fade-in //Updated (Jan 29th, 08): Added four possible slide directions: "updown", "downup", "leftright", or "rightleft" //Updated (Feb 1st, 08): Changed glide behavior to reverse direction when previous button is clicked //Updated (Feb 12th, 08): Added ability to retrieve gliding contents from an external file using Ajax ("remotecontent" variable added to configuration) //Updated (July 21st, 09): Updated to work in jQuery 1.3.x /* * JavaScript Debug - v0.3 - 6/8/2009 * http://benalman.com/projects/javascript-debug.log-console-log/ * * Copyright (c) 2009 "Cowboy" Ben Alman * Licensed under the MIT license * http://benalman.com/about/license/ * * With lots of help from Paul Irish! * http://paulirish.com/ */ // window.debug=(function(){var c=this,e=Array.prototype.slice,b=c.console,i={},f,g,j=9,d=["error","warn","info","debug.log","log"],m="assert clear count dir dirxml group groupEnd profile profileEnd time timeEnd trace".split(" "),k=m.length,a=[];while(--k>=0){(function(n){i[n]=function(){j!==0&&b&&b[n]&&b[n].apply(b,arguments)}})(m[k])}k=d.length;while(--k>=0){(function(n,o){i[o]=function(){var q=e.call(arguments),p=[o].concat(q);a.push(p);h(p);if(!b||!l(n)){return}b.firebug?b[o].apply(c,q):b[o]?b[o](q):b.log(q)}})(k,d[k])}function h(n){if(f&&(g||!b||!b.log)){f.apply(c,n)}}i.setLevel=function(n){j=typeof n==="number"?n:9};function l(n){return j>0?j>n:d.length+j<=n}i.setCallback=function(){var o=e.call(arguments),n=a.length,p=n;f=o.shift()||null;g=typeof o[0]==="boolean"?o.shift():false;p-=typeof o[0]==="number"?o.shift():n;while(pFetching Content. Please wait...', glide:function(config, showpage, isprev) { var selected=parseInt(showpage); if (selected>=config.$contentdivs.length) { //if no content exists at this index position debug.log("No content exists at page "+(selected+1)+"! Loading 1st page instead."); selected=0; } var $target=config.$contentdivs.eq(selected) var $prevtarget = config.$prevtarget; var $glider=config.$glider; if ( $prevtarget ) { $prevtarget.blur(); } // Test for toggler not being initialized yet, or user clicks on the currently selected page): if (config.$togglerdiv.attr('lastselected')==null || parseInt(config.$togglerdiv.attr('lastselected'))!=selected) { var $selectedlink=config.$toc.eq(selected); config.$next.attr('loadpage', (selectedServer Response: '+ajaxrequest.responseText); }, success:function(content) { config.$glider.html(content); featuredContentPresenter.setuptoggler($, config); } }) }, adjustglidersize:function(config) { if ( config.adjustglidersize ) { var minHeight = 0; debug.log("Adjusting Glider Height to "); config.$contentdivs.each(function(index, item) { var height = jQuery(this).attr('offsetHeight'); if ( height > minHeight ) minHeight = height; }); if ( config.$glider.height() > minHeight ) minHeight = config.$glider.height(); minHeight = minHeight + (isNaN(config.adjustdelta ) ? 0 : config.adjustdelta); config.$glider.css("height", minHeight) debug.log("... " + minHeight + "px"); } }, aligncontents:function($, config){ config.$contentdivs=$("#"+config.gliderid+" ."+config.contentclass); // incase we want to calculate how big our slides acutally are // can be controlled using max-height css attribute // Position content divs so they're out of view: this.adjustglidersize(config); config.$contentdivs .css(config.leftortop, config.startpoint) .css("visibility", 'visible'); config.$contentdivs.each(function(index) { if ( $(this).attr("onfocus") ) { $(this).bind("focus", $(this).attr("onfocus")); } if ( $(this).attr("onblur") ) { $(this).bind("blur", $(this).attr("onblur")); } }); if ( !config.scaleglider ) config.$contentdivs.css({height: config.$glider.height()}) if ( config.direction = "fade-in-place" ) { config.$contentdivs.css ("opacity", 0); } }, setuptoggler:function($, config){ this.aligncontents($, config); config.$togglerdiv.hide(); config.$toc.each(function(index) { $(this).attr('pagenumber', index+'pg'); if (index > (config.$contentdivs.length-1)) { $(this).css({display: 'none'}) //hide redundant "toc" links } }); var $nextandprev=$("#"+config.togglerid+" .next, #"+config.togglerid+" .prev"); $nextandprev.click(function(event) { //Assign click behavior to 'next' and 'prev' links featuredContentPresenter.glide(config, this.getAttribute('loadpage'), this.getAttribute('buttontype')); event.preventDefault(); //cancel default link action }) if ( config.toggletype == "hover" ) { config.$toc.hover(function(event) { featuredContentPresenter.glide(config, this.getAttribute('pagenumber')); config.pauserotation = true; }, function(event) { config.pauserotation = false; }); } else { config.$toc.click(function(event){ //Assign click behavior to 'toc' links featuredContentPresenter.glide(config, this.getAttribute('pagenumber')); event.preventDefault(); }) } config.$togglerdiv.fadeIn(1000, function(){ featuredContentPresenter.glide(config, config.selected); if (config.autorotate==true) { //auto rotate contents? config.stepcount=0; //set steps taken // Total steps limit: num of contents x num of user specified cycles) config.totalsteps=config.$contentdivs.length*config.autorotateconfig[1]; featuredContentPresenter.autorotate(config); } }) config.$togglerdiv.click(function(){ featuredContentPresenter.cancelautorotate(config.togglerid); }) }, autorotate:function(config){ var rotatespeed=config.speed+config.autorotateconfig[0]; window[config.togglerid+"timer"]=setInterval(function(){ if (config.totalsteps>0 && config.stepcount>=config.totalsteps) { clearInterval(window[config.togglerid+"timer"]); } else{ if (!config.pauserotation) { config.$next.triggerHandler('click'); config.stepcount++; } } }, rotatespeed) }, cancelautorotate:function(togglerid){ if (window[togglerid+"timer"]); clearInterval(window[togglerid+"timer"]); }, getCookie:function(Name){ //construct RE to search for target name/value pair var re=new RegExp(Name+"=[^;]+", "i"); if (document.cookie.match(re)) { //if cookie found return document.cookie.match(re)[0].split("=")[1]; //return its value } return null }, setCookie:function(name, value){ document.cookie = name+"="+value; }, init:function(config){ jQuery(document).ready(function($){ config.$glider=$("#"+config.gliderid); config.$togglerdiv=$("#"+config.togglerid); config.$toc=config.$togglerdiv.find('.toc'); config.$next=config.$togglerdiv.find('.next'); config.$prev=config.$togglerdiv.find('.prev'); config.$prev.attr('buttontype', 'previous'); config.pauserotation = false; var selected=(config.persiststate)? featuredContentPresenter.getCookie(config.gliderid) : config.selected; //test for cookie value containing null (1st page load) or "undefined" string config.selected=(isNaN(parseInt(selected))) ? config.selected : selected; if (typeof(config.direction)!= "undefined" ) { //set which CSS property to manipulate based on "direction" config.leftortop=(/up/i.test(config.direction))? "top" : "left"; //Get glider height or width based on "direction" config.heightorwidth=(/up/i.test(config.direction)) ? config.$glider.height() : config.$glider.width(); //set initial position of contents based on "direction" config.startpoint=(/^(left|up)/i.test(config.direction))? -config.heightorwidth : config.heightorwidth; } else { config.direction = "fade-in-place"; } if ( config.direction == "fade-in-place" ) { config.startpoint = 0; } if (typeof config.remotecontent!="undefined" && config.remotecontent.length>0) { featuredContentPresenter.getremotecontent($, config); } else { featuredContentPresenter.setuptoggler($, config); } $(window).bind('unload', function(){ //clean up and persist config.$togglerdiv.unbind('click'); config.$toc.unbind('click'); config.$next.unbind('click'); config.$prev.unbind('click'); if (config.persiststate) { featuredContentPresenter.setCookie(config.gliderid, config.$togglerdiv.attr('lastselected')); } config=null; }) }) } }