1/** 2 * @name jQuery.touchSlider 3 * @version 201209_2 4 * @since 201106 5 * @param Object settings íê²½ë³ì ì¤ë¸ì í¸ 6 * roll - ìí (default true) 7 * flexible - ì ë ë ì´ìì (default false) 8 * view - ë¤ì¤ ì»¬ë¼ (default 1) 9 * speed - ì ëë©ì´ì ìë (default 75) 10 * range - ëê¹ íì ë²ì (default 0.15) 11 * page - ì´ê¸° íì´ì§ (default 1) 12 * transition - CSS3 transition ì¬ì© (default false) 13 * btn_prev - prev ë²í¼ (jQuery Object, default null) 14 * btn_next - next ë²í¼ (jQuery Object, default null) 15 * paging - page ë²í¼ (jQuery Object, default null) 16 * initComplete - ì´ê¸°í ì½ë°± 17 * counter - ì¬ë¼ì´ë ì½ë°±, ì¹´ì´í° 18 * 19 * @example 20 $("#target").touchSlider({ 21 flexible : true 22 }); 23*/ 24 25(function ($) { 26 27 $.fn.touchSlider = function (settings) { 28 29 settings.supportsCssTransitions = (function (style) { 30 var prefixes = ['Webkit','Moz','Ms']; 31 for(var i=0, l=prefixes.length; i < l; i++ ) { 32 if( typeof style[prefixes[i] + 'Transition'] !== 'undefined') { 33 return true; 34 } 35 } 36 return false; 37 })(document.createElement('div').style); 38 39 settings = jQuery.extend({ 40 roll : true, 41 flexible : false, 42 btn_prev : null, 43 btn_next : null, 44 paging : null, 45 speed : 75, 46 view : 1, 47 range : 0.15, 48 page : 1, 49 transition : false, 50 initComplete : null, 51 counter : null, 52 multi : false 53 }, settings); 54 55 var opts = []; 56 opts = $.extend({}, $.fn.touchSlider.defaults, settings); 57 58 return this.each(function () { 59 60 $.fn.extend(this, touchSlider); 61 62 var _this = this; 63 64 this.opts = opts; 65 this._view = this.opts.view; 66 this._speed = this.opts.speed; 67 this._tg = $(this); 68 this._list = this._tg.children().children(); 69 this._width = parseInt(this._tg.css("width")); 70 this._item_w = parseInt(this._list.css("width")); 71 this._len = this._list.length; 72 this._range = this.opts.range * this._width; 73 this._pos = []; 74 this._start = []; 75 this._startX = 0; 76 this._startY = 0; 77 this._left = 0; 78 this._top = 0; 79 this._drag = false; 80 this._scroll = false; 81 this._btn_prev; 82 this._btn_next; 83 84 this.init(); 85 86 $(this) 87 .bind("touchstart", this.touchstart) 88 .bind("touchmove", this.touchmove) 89 .bind("touchend", this.touchend) 90 .bind("dragstart", this.touchstart) 91 .bind("drag", this.touchmove) 92 .bind("dragend", this.touchend) 93 94 $(window).bind("orientationchange resize", function () { 95 _this.resize(_this); 96 }); 97 }); 98 99 }; 100 101 var touchSlider = { 102 103 init : function () { 104 var _this = this; 105 106 $(this).children().css({ 107 "width":this._width + "px", 108 "overflow":"visible" 109 }); 110 111 if(this.opts.flexible) this._item_w = this._width / this._view; 112 if(this.opts.roll) this._len = Math.ceil(this._len / this._view) * this._view; 113 114 var page_gap = (this.opts.page > 1 && this.opts.page <= this._len) ? (this.opts.page - 1) * this._item_w : 0; 115 116 for(var i=0; i<this._len; ++i) { 117 this._pos[i] = this._item_w * i - page_gap; 118 this._start[i] = this._pos[i]; 119 this._list.eq(i).css({ 120 "float" : "none", 121 "display" : "block", 122 "position" : "absolute", 123 "top" : "0", 124 "left" : this._pos[i] + "px", 125 "width" : this._item_w + "px" 126 }); 127 if(this.opts.supportsCssTransitions && this.opts.transition) { 128 this._list.eq(i).css({ 129 "-moz-transition" : "0ms", 130 "-moz-transform" : "", 131 "-ms-transition" : "0ms", 132 "-ms-transform" : "", 133 "-webkit-transition" : "0ms", 134 "-webkit-transform" : "", 135 "transition" : "0ms", 136 "transform" : "" 137 }); 138 } 139 } 140 141 if(this.opts.btn_prev && this.opts.btn_next) { 142 this.opts.btn_prev.bind("click", function() { 143 _this.animate(1, true); 144 return false; 145 }) 146 this.opts.btn_next.bind("click", function() { 147 _this.animate(-1, true); 148 return false; 149 }); 150 } 151 152 if(this.opts.paging) { 153 $(this._list).each(function (i, el) {
154 //var btn_page = _this.opts.paging.eq(0).clone(); 155 var btn_page = _this.opts.paging.eq(i); 156 //_this.opts.paging.before(btn_page); 157 158 btn_page.bind("click", function(e) { 159 _this.go_page(i, e); 160 return false; 161 }); 162 }); 163 164 //this.opts.paging.remove(); 165 } 166 167 this.counter(); 168 this.initComplete(); 169 }, 170 171 initComplete : function () { 172 if(typeof(this.opts.initComplete) == "function") { 173 this.opts.initComplete(this); 174 } 175 }, 176 177 resize : function (e) { 178 if(e.opts.flexible) { 179 var tmp_w = e._item_w; 180 181 e._width = parseInt(e._tg.css("width")); 182 e._item_w = e._width / e._view; 183 e._range = e.opts.range * e._width; 184 185 for(var i=0; i<e._len; ++i) { 186 e._pos[i] = e._pos[i] / tmp_w * e._item_w; 187 e._start[i] = e._start[i] / tmp_w * e._item_w; 188 e._list.eq(i).css({ 189 "left" : e._pos[i] + "px", 190 "width" : e._item_w + "px" 191 }); 192 if(this.opts.supportsCssTransitions && this.opts.transition) { 193 e._list.eq(i).css({ 194 "-moz-transition" : "0ms", 195 "-moz-transform" : "", 196 "-ms-transition" : "0ms", 197 "-ms-transform" : "", 198 "-webkit-transition" : "0ms", 199 "-webkit-transform" : "", 200 "transition" : "0ms", 201 "transform" : "" 202 }); 203 } 204 } 205 } 206 207 this.counter(); 208 }, 209 210 touchstart : function (e) { 211 if((e.type == "touchstart" && e.originalEvent.touches.length <= 1) || e.type == "dragstart") { 212 this._startX = e.pageX || e.originalEvent.touches[0].pageX; 213 this._startY = e.pageY || e.originalEvent.touches[0].pageY; 214 this._scroll = false; 215 216 this._start = []; 217 for(var i=0; i<this._len; ++i) { 218 this._start[i] = this._pos[i]; 219 } 220 } 221 }, 222 223 touchmove : function (e) { 224 if((e.type == "touchmove" && e.originalEvent.touches.length <= 1) || e.type == "drag") { 225 this._left = (e.pageX || e.originalEvent.touches[0].pageX) - this._startX; 226 this._top = (e.pageY || e.originalEvent.touches[0].pageY) - this._startY; 227 var w = this._left < 0 ? this._left * -1 : this._left; 228 var h = this._top < 0 ? this._top * -1 : this._top; 229 230 if (w < h || this._scroll) { 231 this._left = 0; 232 this._drag = false; 233 this._scroll = true; 234 } else { 235 e.preventDefault(); 236 this._drag = true; 237 this._scroll = false; 238 this.position(e); 239 } 240 241 for(var i=0; i<this._len; ++i) { 242 var tmp = this._start[i] + this._left; 243 244 if(this.opts.supportsCssTransitions && this.opts.transition) { 245 var trans = "translate3d(" + tmp + "px,0,0)"; 246 this._list.eq(i).css({ 247 "left" : "", 248 "-moz-transition" : "0ms", 249 "-moz-transform" : trans, 250 "-ms-transition" : "0ms", 251 "-ms-transform" : trans, 252 "-webkit-transition" : "0ms", 253 "-webkit-transform" : trans, 254 "transition" : "0ms", 255 "transform" : trans 256 }); 257 } else { 258 this._list.eq(i).css("left", tmp + "px"); 259 } 260 261 this._pos[i] = tmp; 262 } 263 } 264 }, 265 266 touchend : function (e) { 267 if((e.type == "touchend" && e.originalEvent.touches.length <= 1) || e.type == "dragend") { 268 if(this._scroll) { 269 this._drag = false; 270 this._scroll = false; 271 return false; 272 } 273 274 this.animate(this.direction()); 275 this._drag = false; 276 this._scroll = false; 277 } 278 }, 279 280 position : function (d) { 281 var gap = this._view * this._item_w; 282 283 if(d == -1 || d == 1) { 284 this._startX = 0; 285 this._start = []; 286 for(var i=0; i<this._len; ++i) { 287 this._start[i] = this._pos[i]; 288 } 289 this._left = d * gap; 290 } else { 291 if(this._left > gap) this._left = gap; 292 if(this._left < - gap) this._left = - gap; 293 } 294 295 if(this.opts.roll) { 296 var tmp_pos = []; 297 for(var i=0; i<this._len; ++i) { 298 tmp_pos[i] = this._pos[i]; 299 } 300 tmp_pos.sort(function(a,b){return a-b;}); 301 302 303 var max_chk = tmp_pos[this._len-this._view]; 304 var p_min = $.inArray(tmp_pos[0], this._pos); 305 var p_max = $.inArray(max_chk, this._pos); 306 307 308 if(this._view <= 1) max_chk = this._len - 1; 309 if(this.opts.multi) { 310 if((d == 1 && tmp_pos[0] >= 0) || (this._drag && tmp_pos[0] >= 100)) { 311 for(var i=0; i<this._view; ++i, ++p_min, ++p_max) { 312 this._start[p_max] = this._start[p_min] - gap; 313 this._list.eq(p_max).css("left", this._start[p_max] + "px"); 314 } 315 } else if((d == -1 && tmp_pos[0] <= 0) || (this._drag && tmp_pos[0] <= -100)) { 316 for(var i=0; i<this._view; ++i, ++p_min, ++p_max) { 317 this._start[p_min] = this._start[p_max] + gap; 318 this._list.eq(p_min).css("left", this._start[p_min] + "px"); 319 } 320 } 321 } else { 322 if((d == 1 && tmp_pos[0] >= 0) || (this._drag && tmp_pos[0] > 0)) { 323 for(var i=0; i<this._view; ++i, ++p_min, ++p_max) { 324 this._start[p_max] = this._start[p_min] - gap; 325 this._list.eq(p_max).css("left", this._start[p_max] + "px"); 326 } 327 } else if((d == -1 && tmp_pos[max_chk] <= 0) || (this._drag && tmp_pos[max_chk] <= 0)) { 328 for(var i=0; i<this._view; ++i, ++p_min, ++p_max) { 329 this._start[p_min] = this._start[p_max] + gap; 330 this._list.eq(p_min).css("left", this._start[p_min] + "px"); 331 } 332 } 333 } 334 } else { 335 if(this.limit_chk()) this._left = this._left / 2; 336 } 337 }, 338 339 animate : function (d, btn_click) { 340 if(this._drag || !this._scroll || btn_click) { 341 var _this = this; 342 var speed = this._speed; 343 344 if(btn_click) this.position(d); 345 346 var gap = d * (this._item_w * this._view); 347 if(this._left == 0 || (!this.opts.roll && this.limit_chk()) ) gap = 0; 348 349 this._list.each(function (i, el) { 350 _this._pos[i] = _this._start[i] + gap; 351 352 if(_this.opts.supportsCssTransitions && _this.opts.transition) { 353 var transition = speed + "ms"; 354 var transform = "translate3d(" + _this._pos[i] + "px,0,0)"; 355 356 if(btn_click) transition = "0ms"; 357 358 $(this).css({ 359 "left" : "", 360 "-moz-transition" : transition, 361 "-moz-transform" : transform, 362 "-ms-transition" : transition, 363 "-ms-transform" : transform, 364 "-webkit-transition" : transition, 365 "-webkit-transform" : transform, 366 "transition" : transition, 367 "transform" : transform 368 });
369 } else { 370 $(this).stop(); 371 $(this).animate({"left": _this._pos[i] + "px"}, speed); 372 } 373 }); 374 375 this.counter(); 376 } 377 }, 378 379 direction : function () { 380 var r = 0; 381 382 if(this._left < -(this._range)) r = -1; 383 else if(this._left > this._range) r = 1; 384 385 if(!this._drag || this._scroll) r = 0; 386 387 return r; 388 }, 389 390 limit_chk : function () { 391 var last_p = parseInt((this._len - 1) / this._view) * this._view; 392 return ( (this._start[0] == 0 && this._left > 0) || (this._start[last_p] == 0 && this._left < 0) ); 393 }, 394 395 go_page : function (i, e) { 396 var crt = ($.inArray(0, this._pos) / this._view) + 1; 397 var cal = crt - (i + 1); 398 399 while(cal != 0) { 400 if(cal < 0) { 401 this.animate(-1, true); 402 cal++; 403 } else if(cal > 0) { 404 this.animate(1, true); 405 cal--; 406 } 407 } 408 }, 409 410 counter : function () { 411 if(typeof(this.opts.counter) == "function") { 412 var param = { 413 total : Math.ceil(this._len / this._view), 414 current : ($.inArray(0, this._pos) / this._view) + 1 415 }; 416 this.opts.counter(param); 417 } 418 } 419 420 }; 421 422})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.