[PLUGINS] +les plugins de bases
[ptitvelo/web/www.git] / www / plugins / beespip / js / easySlider1.7.js
1 /*
2 * Easy Slider 1.7 - jQuery plugin
3 * written by Alen Grakalic
4 * http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
5 *
6 * Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
7 * Dual licensed under the MIT (MIT-LICENSE.txt)
8 * and GPL (GPL-LICENSE.txt) licenses.
9 *
10 * Built for jQuery library
11 * http://jquery.com
12 *
13 */
14
15 /*
16 * markup example for $("#slider").easySlider();
17 *
18 * <div id="slider">
19 * <ul>
20 * <li><img src="images/01.jpg" alt="" /></li>
21 * <li><img src="images/02.jpg" alt="" /></li>
22 * <li><img src="images/03.jpg" alt="" /></li>
23 * <li><img src="images/04.jpg" alt="" /></li>
24 * <li><img src="images/05.jpg" alt="" /></li>
25 * </ul>
26 * </div>
27 *
28 */
29
30 (function($) {
31
32 $.fn.easySlider = function(options){
33
34 // default configuration properties
35 var defaults = {
36 prevId: 'prevBtn',
37 prevText: 'Previous',
38 nextId: 'nextBtn',
39 nextText: 'Next',
40 controlsShow: true,
41 controlsBefore: '',
42 controlsAfter: '',
43 controlsFade: true,
44 firstId: 'firstBtn',
45 firstText: 'First',
46 firstShow: false,
47 lastId: 'lastBtn',
48 lastText: 'Last',
49 lastShow: false,
50 vertical: false,
51 speed: 800,
52 auto: false,
53 pause: 2000,
54 continuous: false,
55 numeric: false,
56 numericId: 'controls'
57 };
58
59 var options = $.extend(defaults, options);
60
61 this.each(function() {
62 var obj = $(this);
63 var s = $("li", obj).length;
64 var w = $("li", obj).width();
65 var h = $("li", obj).height();
66 var clickable = true;
67 obj.width(w);
68 obj.height(h);
69 obj.css("overflow","hidden");
70 var ts = s-1;
71 var t = 0;
72 $("ul", obj).css('width',s*w);
73
74 if(options.continuous){
75 $("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
76 $("ul", obj).append($("ul li:nth-child(2)", obj).clone());
77 $("ul", obj).css('width',(s+1)*w);
78 };
79
80 if(!options.vertical) $("li", obj).css('float','left');
81
82 if(options.controlsShow){
83 var html = options.controlsBefore;
84 if(options.numeric){
85 html += '<ol id="'+ options.numericId +'"></ol>';
86 } else {
87 if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
88 html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
89 html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
90 if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
91 };
92
93 html += options.controlsAfter;
94 $(obj).after(html);
95 };
96
97 if(options.numeric){
98 for(var i=0;i<s;i++){
99 /* Ajout pour récupérer le texte de la balise h2 */
100 var elem = document.getElementById ("bouton_actu"+ (i+1));
101 var texte_bouton = "";
102 if (elem.textContent === undefined) {
103 texte_bouton += elem.innerText;
104 }
105 else {
106 texte_bouton += elem.textContent;
107 }
108
109 $(document.createElement("li"))
110 .attr('id',options.numericId + (i+1))
111 //.html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
112 .html('<a rel='+ i +' href=\"javascript:void(0);\" title=\"'+texte_bouton+'\">'+ (i+1) +'</a>')
113 .appendTo($("#"+ options.numericId))
114 .click(function(){
115 animate($("a",$(this)).attr('rel'),true);
116 });
117 };
118 } else {
119 $("a","#"+options.nextId).click(function(){
120 animate("next",true);
121 });
122 $("a","#"+options.prevId).click(function(){
123 animate("prev",true);
124 });
125 $("a","#"+options.firstId).click(function(){
126 animate("first",true);
127 });
128 $("a","#"+options.lastId).click(function(){
129 animate("last",true);
130 });
131 };
132
133 function setCurrent(i){
134 i = parseInt(i)+1;
135 $("li", "#" + options.numericId).removeClass("current");
136 $("li#" + options.numericId + i).addClass("current");
137 };
138
139 function adjust(){
140 if(t>ts) t=0;
141 if(t<0) t=ts;
142 if(!options.vertical) {
143 $("ul",obj).css("margin-left",(t*w*-1));
144 } else {
145 $("ul",obj).css("margin-left",(t*h*-1));
146 }
147 clickable = true;
148 if(options.numeric) setCurrent(t);
149 };
150
151 function animate(dir,clicked){
152 if (clickable){
153 clickable = false;
154 var ot = t;
155 switch(dir){
156 case "next":
157 t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;
158 break;
159 case "prev":
160 t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
161 break;
162 case "first":
163 t = 0;
164 break;
165 case "last":
166 t = ts;
167 break;
168 default:
169 t = dir;
170 break;
171 };
172 var diff = Math.abs(ot-t);
173 var speed = diff*options.speed;
174 if(!options.vertical) {
175 p = (t*w*-1);
176 $("ul",obj).animate(
177 { marginLeft: p },
178 { queue:false, duration:speed, complete:adjust }
179 );
180 } else {
181 p = (t*h*-1);
182 $("ul",obj).animate(
183 { marginTop: p },
184 { queue:false, duration:speed, complete:adjust }
185 );
186 };
187
188 if(!options.continuous && options.controlsFade){
189 if(t==ts){
190 $("a","#"+options.nextId).hide();
191 $("a","#"+options.lastId).hide();
192 } else {
193 $("a","#"+options.nextId).show();
194 $("a","#"+options.lastId).show();
195 };
196 if(t==0){
197 $("a","#"+options.prevId).hide();
198 $("a","#"+options.firstId).hide();
199 } else {
200 $("a","#"+options.prevId).show();
201 $("a","#"+options.firstId).show();
202 };
203 };
204
205 if(clicked) clearTimeout(timeout);
206 if(options.auto && dir=="next" && !clicked){;
207 timeout = setTimeout(function(){
208 animate("next",false);
209 },diff*options.speed+options.pause);
210 };
211
212 };
213
214 };
215 // init
216 var timeout;
217 if(options.auto){;
218 timeout = setTimeout(function(){
219 animate("next",false);
220 },options.pause);
221 };
222
223 if(options.numeric) setCurrent(0);
224
225 if(!options.continuous && options.controlsFade){
226 $("a","#"+options.prevId).hide();
227 $("a","#"+options.firstId).hide();
228 };
229
230 });
231
232 };
233
234 })(jQuery);
235
236
237