/* * Copyright (c) 2008 Massimiliano Balestrieri (at gmail) *cut .compressed * Licensed under GPL (GPL-LICENSE.txt) licenses. */ jQuery.iYCodaSlider = { build : function(options) { return this.each( function(nr) { if(!options){options = {};} var config = {}; config.el = this; config.test = options.test || 0; config.contents = jQuery(".ui_ycodaslider_content",this); config.boxes = false; config.scroller = false; config.pagelinks = false; config.nbox = config.contents.size(); if(config.test == 0 && config.nbox < 1) return; config.easefunc = options.easefunc || "easeInOutExpo"; config.css = options.css || jQuery.iYCodaSlider.basicCss(); config.cssprint = options.cssprint || false; config.skin = options.skin || false; config.textprev = options.textprev || '<'; config.textnext = options.textnext || '>'; config.classPageLink = config.classPageLink || 'ui_ycodaslider_pages'; config.colorPageLink = config.colorPageLink || '#fff'; config.colorActivePageLink = config.colorActivePageLink || '#ec9c13'; config.width = options.width || 200; config.speed = options.speed || 750; config.height = options.height || 200; config.heightContainer = options.heightcont;//24px altezza toolbar config.margin = options.margin || 10; config.baseleft = jQuery.iYCodaSlider.ps(config.width) + jQuery.iYCodaSlider.ps(config.margin); //loadcss - controllo che carichi il css solo al primo scroller if(nr == 0){ jQuery.iYCodaSlider.getCSS(config.css); jQuery.iYCodaSlider.getCSS(config.cssprint); if(config.skin) jQuery.iYCodaSlider.getCSS(config.skin); } var anchor = parseInt(jQuery.iYCodaSlider.getAnchor()); anchor = anchor > 0 ? anchor : false; //alert(anchor); config.current = 0; config.nstep = config.nbox; config.step = 0; //alert(config.baseleft); jQuery.iYCodaSlider.initBoxes(config); jQuery.iYCodaSlider.initNav(config); //alert(config.nstep); if(anchor && anchor <= config.nbox && anchor != config.step){ jQuery.iYCodaSlider.setInitBox(config, anchor); jQuery.iYCodaSlider.classLink(config, (anchor-1)); }else{ jQuery.iYCodaSlider.classLink(config,0); } } ); }, basicCss : function() { }, getCSS : function( url ) { $('head').append(''); }, initBoxes : function(config) { //CREO IL CONTAINER E SWAPPO scroller e container $(config.el) .attr("class" , "ui_ycodaslider_scroller" ); $(config.el) .wrap('
'); config.scroller = $(config.el); config.el = $(config.el).parent(); //SETTO IL CONTAINER $(config.el) .css({"padding-bottom":"0","height" : config.heightContainer});//controllare //SETTO LO SCROLLER config.scroller .css({"height" : config.height, "width" : config.width}); if(config.test == 0){ config.scroller .css({"overflow" : "hidden"}); } //costringo i contenuti a essere larghi quanto le "maschere" config.contents .css({"height" : config.height, "width" : config.width}) .wrap(''); config.boxes = jQuery(".ui_ycodaslider_section",$(config.el)); config.boxes .css({"position" : "absolute","overflow" : "hidden", "height" : config.height, "width" : config.width}); config.boxes .each( function(nr){ var left = config.baseleft * nr; $(this).css("left", left); if(config.test == 1){ if(config.current == nr) $(this).css("background-color", "blue"); else $(this).css("background-color", "yellow"); } } ); }, initNav : function(config) { $(''+"\n").appendTo(config.el); var nav = jQuery('.ui_ycodaslider_nav',config.el); $(''+config.textprev+''+"\n").appendTo(nav); var tasti = ''+"\n"; $(tasti).appendTo(nav); config.pagelinks = jQuery(".ui_ycodaslider_pages",nav); $(''+config.textnext+''+"\n").appendTo(nav); $(".ui_ycodaslider_pages",config.el).click( function(){ jQuery.iYCodaSlider.moveIntoBox(config,$(this).text());//return false; } ); $(".ui_ycodaslider_next",config.el).click( function(){ jQuery.iYCodaSlider.moveBox(config,"next");return false; } ); $(".ui_ycodaslider_prev",config.el).click( function(){ jQuery.iYCodaSlider.moveBox(config,"prev");return false; } ); }, setInitBox : function (config, page) { config.step = (page - 1); config.boxes .each( function(nr){ var p = jQuery.iYCodaSlider.getCoord(config, nr, false); $(this).css({left:p.left, width:p.width, "background":p.background}); } ); }, moveIntoBox : function (config, page, recursive) { var accell = false; //alert(config.step); //config.step = (page - 1); if(!recursive){ var differenza = Math.abs(config.step - (page-1)); accell = parseInt(config.speed / differenza); //alert(accell); //alert(page); jQuery.iYCodaSlider.classLink(config, (page-1)); } if(config.step == (page-1)){ recursive = false; return; }else{ recursive = true; differenza = Math.abs(config.step - page); config.step < page ? config.step++ : config.step--; } config.boxes .each( function(nr){ var p = jQuery.iYCodaSlider.getCoord(config, nr, accell); /*$(this).animate( {left:p.left, width:p.width },//, overflow:"hidden""background":p.background p.speed, null );*/ $(this).animate( {'left':p.left,'width':p.width},//, 'overflow':'hidden' p.speed, config.easefunc ); //jq_apri(); } ); if(recursive) jQuery.iYCodaSlider.moveIntoBox(config, page, true); }, classLink : function(config, page) { config.pagelinks.each( function(nr){ //alert(page-1); //alert(nr); if(nr == page){ $(this).css("color",config.colorActivePageLink); }else{ $(this).css("color",config.colorPageLink); } } ).end(); }, moveBox : function(config, direction, recursive) { var accell = false; if(direction == "next" && (recursive || config.step >= (config.nstep-1))){ recursive = true; accell = config.speed / config.nstep; config.step--; if(config.step == 0){ recursive = false; } }else if(direction == "prev" && (recursive || config.step <= 0)){ recursive = true; accell = config.speed / config.nstep; config.step++; if(config.step == (config.nstep - 1)){ recursive = false; } }else{ direction == "next" ? config.step++ : config.step--; } config.boxes .each( function(nr){ var p = jQuery.iYCodaSlider.getCoord(config, nr, accell); if(p.left == 0 && p.width != 0) jQuery.iYCodaSlider.classLink(config, (nr)); /*$(this).animate( {'left':p.left, 'width':p.width},//, 'overflow':'hidden' p.speed, null );*/ $(this).animate( {'left':p.left,'width':p.width},//, 'overflow':'hidden' p.speed, config.easefunc ); } ); if(recursive) jQuery.iYCodaSlider.moveBox(config, direction, true); }, getCoord : function(config ,nr, accell){ var step = config.step; var box = config.boxes.eq(nr); var pwidth = 0; if(step <= nr){ pwidth = config.width; }else{ pwidth = 0; } //var pbackground = "yellow"; //if(step == nr){ // pbackground = "blue"; //} //if(config.test == 0){ // pbackground = "none"; //} var pleft = box.css("left"); if(step >= nr){ pleft = 0; }else{ pleft = config.baseleft * (nr - step); } var pspeed = config.speed; if(accell){ pspeed = accell;//config.speed / config.nstep; } //if(step == 0 && nr == 0) alert(pspeed); if(pspeed < 300){ pspeed = 300; } if(pspeed > 600){ pspeed = 600; } return { width : pwidth, left : pleft, //background : pbackground, speed : pspeed }; }, getAnchor: function() { if(window.location.href.indexOf("#") != -1){ var url = window.location.href; var uanchor = window.location.href.split("#"); if(uanchor[1]){ return uanchor[1]; } } }, ps: function(num){ if(typeof(num) == 'number'){ return num; } num = num.replace("px",""); num = num.replace("%",""); num = num.replace("em",""); return parseInt(num); } }; jQuery.fn.YCodaSlider = jQuery.iYCodaSlider.build;