1/** 2 * Quote Rotator - Simple jQuery plugin which cause a set of list 3 * items to fade-in and fade-out. 4 * 5 * Homepage: http://coryschires.com/jquery-quote-rotator-plugin/ 6 * Source Code: https://github.com/coryschires/quote-rotator 7 * 8 * Copyright (c) 2011 Cory Schires (coryschires.com) 9 * Dual licensed under the MIT and GPL licenses: 10 * http://www.opensource.org/licenses/mit-license.php 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * Version: 1.0.0 14 */ 15 16(function($) { 17 18 $.quote_rotator = { 19 defaults: { 20 rotation_speed: 9000, 21 pause_on_hover: true, 22 randomize_first_quote: false, 23 buttons: false 24 } 25 } 26 27 $.fn.extend({ 28 quote_rotator: function(config) { 29 30 var config = $.extend({}, $.quote_rotator.defaults, config); 31 32 return this.each(function() { 33 var rotation; 34 var quote_list = $(this); 35 var list_items = quote_list.find('li'); 36 var rotation_active = true; 37 var rotation_speed = config.rotation_speed < 2000 ? 2000 : config.rotation_speed; 38 39 var add_active_class = function() { 40 var active_class_not_already_applied = quote_list.find('li.active').length === 0; 41 if (config.randomize_first_quote) { 42 var random_list_item = $(list_items[Math.floor( Math.random() * (list_items.length) )]); 43 random_list_item.addClass('active'); 44 } else if (active_class_not_already_applied) { 45 quote_list.find('li:first').addClass('active'); 46 } 47 }(); 48 49 var get_next_quote = function(quote) { 50 return quote.next('li').length ? quote.next('li') : quote_list.find('li:first'); 51 } 52 53 var get_previous_quote = function(quote) { 54 return quote.prev('li').length ? quote.prev('li') : quote_list.find('li:last'); 55 } 56 57 var rotate_quotes = function(direction) { 58 var active_quote = quote_list.find('li.active'); 59 var next_quote = direction === 'forward' ? get_next_quote(active_quote) : get_previous_quote(active_quote) 60 61 active_quote.animate({ 62 opacity: 0 63 }, 1000, function() { 64 active_quote.hide(); 65 list_items.css('opacity', 1); 66 next_quote.fadeIn(1000); 67 }); 68 69 active_quote.removeClass('active'); 70 next_quote.addClass('active'); 71 }; 72 73 var start_automatic_rotation = function() { 74 rotation = setInterval(function() { 75 if (rotation_active) { rotate_quotes('forward'); } 76 }, rotation_speed); 77 }; 78 79 var pause_rotation_on_hover = function() { 80 quote_list.hover(function() { 81 rotation_active = false; 82 }, function() { 83 rotation_active = true; 84 }); 85 }; 86 87 var include_next_previous_buttons = function() { 88 quote_list.append( 89 '<div class="qr_buttons">\ 90 <button class="qr_previous">'+ config.buttons.previous +'</button>\ 91 <button class="qr_next">'+ config.buttons.next +'</button>\ 92 </div>' 93 ); 94 quote_list.find('button').click(function() { 95 clearInterval(rotation); 96 rotate_quotes( $(this).hasClass('qr_next') ? 'forward' : 'backward' ); 97 start_automatic_rotation(); 98 }); 99 }; 100 101 if (config.buttons) { include_next_previous_buttons(); } 102 if (config.pause_on_hover) { pause_rotation_on_hover(); } 103 104 list_items.not('.active').hide(); 105 106 start_automatic_rotation(); 107 }) 108 } 109 }) 110 111})(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.