1console.clear(); 2(function($) { 3 $.fn.flipster = function(options) { 4 var isMethodCall = typeof options === 'string' ? true : false; 5 6 if (isMethodCall) { 7 var method = options; 8 var args = Array.prototype.slice.call(arguments, 1); 9 } else { 10 var defaults = { 11 itemContainer: 'ul', // Container for the flippin' items. 12 itemSelector: 'li', // Selector for children of itemContainer to flip 13 style: 'coverflow', // Switch between 'coverflow' or 'carousel' display styles 14 start: 'center', // Starting item. Set to 0 to start at the first, 'center' to start in the middle or the index of the item you want to start with. 15 16 enableKeyboard: true, // Enable left/right arrow navigation 17 enableMousewheel: true, // Enable scrollwheel navigation (up = left, down = right) 18 enableTouch: true, // Enable swipe navigation for touch devices 19 20 enableNav: false, // If true, flipster will insert an unordered list of the slides 21 enableNavButtons: false, // If true, flipster will insert Previous / Next buttons 22 prevText: 'Previous', // Changes the text for the Previous button 23 nextText: 'next', // Changes the text for the Next button 24 onItemSwitch: function() {}, // Callback function when items are switches 25 disableRotation: false 26 }; 27 var settings = $.extend({}, defaults, options); 28 var win = $(window); 29 } 30 31 return this.each(function() { 32 33 var _flipster = $(this); 34 var methods; 35 36 if (isMethodCall) { 37 methods = _flipster.data('methods'); 38 return methods[method].apply(this, args); 39 } 40 41 var _flipItemsOuter; 42 var _flipItems; 43 var _flipNav; 44 var _flipNavItems; 45 var _current = 0; 46 47 var _startTouchX = 0; 48 var _actionThrottle = 0; 49 var _throttleTimeout; 50 var compatibility; 51 52 // public methods 53 methods = { 54 jump: jump, 55 destroy: destroy 56 }; 57 _flipster.data('methods', methods); 58 59 function removeThrottle() { 60 _actionThrottle = 0; 61 } 62 63 function resize() { 64 _flipItemsOuter.width('auto').height('auto'); 65 _flipItemsOuter.height(calculateBiggestFlipItemHeight()); 66 _flipster.css("height", "auto"); 67 if (settings.style === 'carousel') { 68 _flipItemsOuter.width(_flipItems.width()); 69 } 70 } 71 72 function calculateBiggestFlipItemHeight() { 73 var biggestHeight = 0; 74 _flipItems.each(function() { 75 if ($(this).height() > biggestHeight) 76 biggestHeight = $(this).height(); 77 }); 78 return biggestHeight; 79 } 80 81 function buildNav() { 82 if (settings.enableNav && _flipItems.length > 1) { 83 var navCategories = [], 84 navItems = [], 85 navList = []; 86 87 _flipItems.each(function() { 88 var category = $(this).data("flip-category"), 89 itemId = $(this).attr("id"), 90 itemTitle = $(this).attr("title"); 91 92 if (typeof category !== 'undefined') { 93 if ($.inArray(category, navCategories) < 0) { 94 navCategories.push(category); 95 navList[category] = '<li class="flip-nav-category"><a href="#" class="flip-nav-category-link" data-flip-category="' + category + '">' + category + '</a>\n<ul class="flip-nav-items">\n'; 96 } 97 } 98 99 if ($.inArray(itemId, navItems) < 0 && typeof itemTitle !== 'undefined') { 100 101 navItems.push(itemId); 102 link = '<a href="#' + itemId + '" class="flip-nav-item-link">' + itemTitle + '</a></li>\n'; 103 104 if (typeof category !== 'undefined') { 105 navList[category] = navList[category] + '<li class="flip-nav-item">' + link; 106 } else { 107 navList[itemId] = '<li class="flip-nav-item no-category">' + link; 108 } 109 } 110 }); 111 112 navDisplay = '<ul class="flipster-nav">\n'; 113 for (var catIndex in navCategories) { 114 navList[navCategories[catIndex]] = navList[navCategories[catIndex]] + "</ul>\n</li>\n"; 115 } 116 for (var navIndex in navList) { 117 navDisplay += navList[navIndex]; 118 } 119 navDisplay += '</ul>'; 120 121 _flipNav = $(navDisplay).prependTo(_flipster); 122 _flipNavItems = _flipNav.find("a").on("click", function(e) { 123 var target; 124 if ($(this).hasClass("flip-nav-category-link")) { 125 target = _flipItems.filter("[data-flip-category='" + $(this).data("flip-category") + "']"); 126 } else { 127 target = $(this.hash); 128 } 129 130 if (target.length) { 131 jump(target); 132 e.preventDefault(); 133 } 134 }); 135 } 136 } 137 138 function updateNav() { 139 if (settings.enableNav && _flipItems.length > 1) {
140 currentItem = $(_flipItems[_current]); 141 _flipNav.find(".flip-nav-current").removeClass("flip-nav-current"); 142 _flipNavItems.filter("[href='#" + currentItem.attr("id") + "']").addClass("flip-nav-current"); 143 _flipNavItems.filter("[data-flip-category='" + currentItem.data("flip-category") + "']").parent().addClass("flip-nav-current"); 144 } 145 } 146 147 function buildNavButtons() { 148 149 if (settings.enableNavButtons && _flipItems.length > 1) { 150 _flipster.find(".flipto-prev, .flipto-next").remove(); 151 _flipster.append("<a href='#' class='flipto-prev'>" + settings.prevText + "</a> <a href='#' class='flipto-next'>" + settings.nextText + "</a>"); 152 153 _flipster.children('.flipto-prev').on("click", function(e) { 154 jump("left"); 155 e.preventDefault(); 156 }); 157 158 _flipster.children('.flipto-next').on("click", function(e) { 159 jump("right"); 160 e.preventDefault(); 161 }); 162 } 163 } 164 165 function center() { 166 var currentItem = $(_flipItems[_current]).addClass("flip-current"); 167 168 _flipItems.removeClass("flip-prev flip-next flip-current flip-past flip-future no-transition"); 169 170 if (settings.style === 'carousel') { 171 172 _flipItems.addClass("flip-hidden"); 173 174 var nextItem = $(_flipItems[_current + 1]), 175 futureItem = $(_flipItems[_current + 2]), 176 prevItem = $(_flipItems[_current - 1]), 177 pastItem = $(_flipItems[_current - 2]); 178 179 if (_current === 0) { 180 prevItem = _flipItems.last(); 181 pastItem = prevItem.prev(); 182 } else if (_current === 1) { 183 pastItem = _flipItems.last(); 184 } else if (_current === _flipItems.length - 2) { 185 futureItem = _flipItems.first(); 186 } else if (_current === _flipItems.length - 1) { 187 nextItem = _flipItems.first(); 188 futureItem = $(_flipItems[1]); 189 } 190 191 futureItem.removeClass("flip-hidden").addClass("flip-future"); 192 pastItem.removeClass("flip-hidden").addClass("flip-past"); 193 nextItem.removeClass("flip-hidden").addClass("flip-next"); 194 prevItem.removeClass("flip-hidden").addClass("flip-prev"); 195 196 } else { 197 var spacer = currentItem.outerWidth() / 2; 198 var totalLeft = 0; 199 var totalWidth = _flipItemsOuter.width(); 200 var currentWidth = currentItem.outerWidth(); 201 var currentLeft = (_flipItems.index(currentItem) * currentWidth) / 2 + spacer / 2; 202 203 _flipItems.removeClass("flip-hidden"); 204 205 for (i = 0; i < _flipItems.length; i++) { 206 var thisItem = $(_flipItems[i]); 207 var thisWidth = thisItem.outerWidth(); 208 209 if (i < _current) { 210 thisItem.addClass("flip-past") 211 .css({ 212 "z-index": i, 213 "left": (i * thisWidth / 2) + "px" 214 }); 215 } else if (i > _current) { 216 thisItem.addClass("flip-future") 217 .css({ 218 "z-index": _flipItems.length - i, 219 "left": (i * thisWidth / 2) + spacer + "px" 220 }); 221 } 222 } 223 224 currentItem.css({ 225 "z-index": _flipItems.length + 1, 226 "left": currentLeft + "px" 227 }); 228 229 totalLeft = (currentLeft + (currentWidth / 2)) - (totalWidth / 2); 230 var newLeftPos = -1 * (totalLeft) + "px"; 231 /* Untested Compatibility */ 232 233 if (compatibility) { 234 _flipItemsOuter.animate({"left": newLeftPos}, 333); 235 } else { 236 _flipItemsOuter.css("left", newLeftPos); 237 } 238 } 239 240 currentItem 241 .addClass("flip-current") 242 .removeClass("flip-prev flip-next flip-past flip-future flip-hidden"); 243 244 resize(); 245 updateNav(); 246 settings.onItemSwitch.call(this); 247 } 248 249 function jump(to) { 250 if (_flipItems.length > 1) { 251 if (to === "left") { 252 if (_current > 0) { 253 _current--; 254 } else { 255 _current = _flipItems.length - 1; 256 } 257 } else if (to === "right") { 258 if (_current < _flipItems.length - 1) { 259 _current++; 260 } else { 261 _current = 0; 262 } 263 } else if (typeof to === 'number') { 264 _current = to; 265 } else { 266 // if object is sent, get its index 267 _current = _flipItems.index(to); 268 } 269 center(); 270 } 271 } 272
273 function init() { 274 /* Untested Compatibility */ 275 276 // Basic setup 277 _flipster.addClass("flipster flipster-active flipster-" + settings.style).css("visibility", "hidden"); 278 if (settings.disableRotation) 279 _flipster.addClass('no-rotate'); 280 _flipItemsOuter = _flipster.find(settings.itemContainer).addClass("flip-items"); 281 _flipItems = _flipItemsOuter.find(settings.itemSelector).addClass("flip-item flip-hidden").wrapInner("<div class='flip-content' />"); 282 283 //Browsers that don't support CSS3 transforms get compatibility: 284 var isIEmax8 = ('\v' === 'v'); //IE <= 8 285 var checkIE = document.createElement("b"); 286 checkIE.innerHTML = "<!--[if IE 9]><i></i><![endif]-->"; //IE 9 287 var isIE9 = checkIE.getElementsByTagName("i").length === 1; 288 if (isIEmax8 || isIE9) { 289 compatibility = true; 290 _flipItemsOuter.addClass("compatibility"); 291 } 292 293 294 // Insert navigation if enabled. 295 buildNav(); 296 buildNavButtons(); 297 298 299 // Set the starting item 300 if (settings.start && _flipItems.length > 1) { 301 // Find the middle item if start = center 302 if (settings.start === 'center') { 303 if (!_flipItems.length % 2) { 304 _current = _flipItems.length / 2 + 1; 305 } else { 306 _current = Math.floor(_flipItems.length / 2); 307 } 308 } else { 309 _current = settings.start; 310 } 311 } 312 313 314 // initialize containers 315 resize(); 316 317 318 // Necessary to start flipster invisible and then fadeIn so height/width can be set accurately after page load 319 _flipster.hide().css("visibility", "visible").fadeIn(400, function() { 320 center(); 321 }); 322 323 324 // Attach event bindings. 325 win.resize(function() { 326 resize(); 327 center(); 328 }); 329 330 331 // Navigate directly to an item by clicking 332 _flipItems.on("click", function(e) { 333 if (!$(this).hasClass("flip-current")) { 334 e.preventDefault(); 335 } 336 jump(_flipItems.index(this)); 337 }); 338 339 340 // Keyboard Navigation 341 if (settings.enableKeyboard && _flipItems.length > 1) { 342 win.on("keydown.flipster", function(e) { 343 _actionThrottle++; 344 if (_actionThrottle % 7 !== 0 && _actionThrottle !== 1) 345 return; //if holding the key down, ignore most events 346 347 var code = e.which; 348 if (code === 37) { 349 e.preventDefault(); 350 jump('left'); 351 } else if (code === 39) { 352 e.preventDefault(); 353 jump('right'); 354 } 355 }); 356 357 win.on("keyup.flipster", function(e) { 358 _actionThrottle = 0; //reset action throttle on key lift to avoid throttling new interactions 359 }); 360 } 361 362 363 // Mousewheel Navigation 364 if (settings.enableMousewheel && _flipItems.length > 1) { // TODO: Fix scrollwheel on Firefox 365 _flipster.on("mousewheel.flipster", function(e) { 366 _throttleTimeout = window.setTimeout(removeThrottle, 500); //throttling should expire if scrolling pauses for a moment. 367 _actionThrottle++; 368 if (_actionThrottle % 4 !== 0 && _actionThrottle !== 1) 369 return; //throttling like with held-down keys 370 window.clearTimeout(_throttleTimeout); 371 372 if (e.originalEvent.wheelDelta / 120 > 0) { 373 jump("left"); 374 } else { 375 jump("right"); 376 } 377 378 e.preventDefault(); 379 }); 380 } 381 382 383 // Touch Navigation 384 if (settings.enableTouch && _flipItems.length > 1) { 385 _flipster.on("touchstart.flipster", function(e) { 386 _startTouchX = e.originalEvent.targetTouches[0].screenX; 387 }); 388 389 _flipster.on("touchmove.flipster", function(e) { 390 e.preventDefault(); 391 var nowX = e.originalEvent.targetTouches[0].screenX; 392 var touchDiff = nowX - _startTouchX; 393 if (touchDiff > _flipItems[0].clientWidth / 1.75) { 394 jump("left"); 395 _startTouchX = nowX; 396 }
396 else if (touchDiff < -1 * (_flipItems[0].clientWidth / 1.75)) { 397 jump("right"); 398 _startTouchX = nowX; 399 } 400 }); 401 402 _flipster.on("touchend.flipster", function(e) { 403 _startTouchX = 0; 404 }); 405 } 406 } 407 408 409 function destroy() { 410 411 _flipItems.each(function() { 412 $(this).find('.flip-content > *').unwrap(); 413 }); 414 415 win.off("keydown.flipster"); 416 win.off("keyup.flipster"); 417 _flipster 418 .removeClass("flipster flipster-active flipster-" + settings.style + " no-rotate") 419 .off("click.flipster mousewheel.flipster touchstart.flipster touchmove.flipster touchend.flipster") 420 .find(".flipster-nav, .flipto-prev, .flipto-next").remove(); 421 _flipItemsOuter 422 .removeAttr('style') 423 .removeClass("flip-items compatibility"); 424 _flipItems 425 .off('click') 426 .removeAttr('style') 427 .removeClass("flip-prev flip-next flip-current flip-past flip-hidden flip-future no-transition"); 428 429 _flipster.addClass('flipster'); 430 } 431 432 433 // Initialize if flipster is not already active. 434 if (!_flipster.hasClass("flipster-active")) { 435 init(); 436 } 437 }); 438 }; 439})(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.