1/* =========================================================== 2 * jquery-simple-text-rotator.js v1 3 * =========================================================== 4 * Copyright 2013 Pete Rojwongsuriya. 5 * http://www.thepetedesign.com 6 * 7 * A very simple and light weight jQuery plugin that 8 * allows you to rotate multiple text without changing 9 * the layout 10 * https://github.com/peachananr/simple-text-rotator 11 * 12 * ========================================================== */ 13 14!function($){ 15 16 var defaults = { 17 animation: "dissolve", 18 separator: ",", 19 speed: 2000 20 }; 21 22 $.fx.step.textShadowBlur = function(fx) { 23 $(fx.elem).prop('textShadowBlur', fx.now).css({textShadow: '0 0 ' + Math.floor(fx.now) + 'px black'}); 24 }; 25 26 $.fn.textrotator = function(options){ 27 var settings = $.extend({}, defaults, options); 28 29 return this.each(function(){ 30 var el = $(this) 31 var array = []; 32 $.each(el.text().split(settings.separator), function(key, value) { 33 array.push(value); 34 }); 35 el.text(array[0]); 36 37 // animation option 38 var rotate = function() { 39 switch (settings.animation) { 40 case 'dissolve': 41 el.animate({ 42 textShadowBlur:20, 43 opacity: 0 44 }, 500 , function() { 45 index = $.inArray(el.text(), array) 46 if((index + 1) == array.length) index = -1 47 el.text(array[index + 1]).animate({ 48 textShadowBlur:0, 49 opacity: 1 50 }, 500 ); 51 }); 52 break; 53 54 case 'flip': 55 if(el.find(".back").length > 0) { 56 el.html(el.find(".back").html()) 57 } 58 59 var initial = el.text() 60 var index = $.inArray(initial, array) 61 if((index + 1) == array.length) index = -1 62 63 el.html(""); 64 $("<span class='front'>" + initial + "</span>").appendTo(el); 65 $("<span class='back'>" + array[index + 1] + "</span>").appendTo(el); 66 el.wrapInner("<span class='rotating' />").find(".rotating").hide().addClass("flip").show().css({ 67 "-webkit-transform": " rotateY(-180deg)", 68 "-moz-transform": " rotateY(-180deg)", 69 "-o-transform": " rotateY(-180deg)", 70 "transform": " rotateY(-180deg)" 71 }) 72 73 break; 74 75 case 'flipUp': 76 if(el.find(".back").length > 0) { 77 el.html(el.find(".back").html()) 78 } 79 80 var initial = el.text() 81 var index = $.inArray(initial, array) 82 if((index + 1) == array.length) index = -1 83 84 el.html(""); 85 $("<span class='front'>" + initial + "</span>").appendTo(el); 86 $("<span class='back'>" + array[index + 1] + "</span>").appendTo(el); 87 el.wrapInner("<span class='rotating' />").find(".rotating").hide().addClass("flip up").show().css({ 88 "-webkit-transform": " rotateX(-180deg)", 89 "-moz-transform": " rotateX(-180deg)", 90 "-o-transform": " rotateX(-180deg)", 91 "transform": " rotateX(-180deg)" 92 }) 93 94 break; 95 96 case 'flipCube': 97 if(el.find(".back").length > 0) { 98 el.html(el.find(".back").html()) 99 } 100 101 var initial = el.text() 102 var index = $.inArray(initial, array) 103 if((index + 1) == array.length) index = -1 104 105 el.html(""); 106 $("<span class='front'>" + initial + "</span>").appendTo(el); 107 $("<span class='back'>" + array[index + 1] + "</span>").appendTo(el); 108 el.wrapInner("<span class='rotating' />").find(".rotating").hide().addClass("flip cube").show().css({ 109 "-webkit-transform": " rotateY(180deg)", 110 "-moz-transform": " rotateY(180deg)", 111 "-o-transform": " rotateY(180deg)", 112 "transform": " rotateY(180deg)" 113 }) 114 115 break; 116 117 case 'flipCubeUp': 118 if(el.find(".back").length > 0) { 119 el.html(el.find(".back").html()) 120 } 121 122 var initial = el.text() 123 var index = $.inArray(initial, array) 124 if((index + 1) == array.length) index = -1 125 126 el.html(""); 127 $("<span class='front'>" + initial + "</span>").appendTo(el); 128 $("<span class='back'>" + array[index + 1] + "</span>").appendTo(el); 129 el.wrapInner("<span class='rotating' />").find(".rotating").hide().addClass("flip cube up").show().css({ 130 "-webkit-transform": " rotateX(180deg)", 131 "-moz-transform": " rotateX(180deg)", 132 "-o-transform": " rotateX(180deg)", 133 "transform": " rotateX(180deg)" 134 }) 135 136 break; 137 138 case 'spin': 139 if(el.find(".rotating").length > 0) { 140 el.html(el.find(".rotating").html()) 141 } 142 index = $.inArray(el.text(), array) 143 if((index + 1) == array.length) index = -1 144 145 el.wrapInner("<span class='rotating spin' />").find(".rotating").hide().text(array[index + 1]).show().css({ 146 "-webkit-transform": " rotate(0) scale(1)", 147 "-moz-transform": "rotate(0) scale(1)", 148 "-o-transform": "rotate(0) scale(1)", 149 "transform": "rotate(0) scale(1)" 150 }) 151 break; 152 153 case 'fade': 154 el.fadeOut(settings.speed, function() { 155 index = $.inArray(el.text(), array) 156 if((index + 1) == array.length) index = -1 157 el.text(array[index + 1]).fadeIn(settings.speed); 158 }); 159 break; 160 } 161 }; 162 setInterval(rotate, settings.speed); 163 }); 164 } 165 166}(window.jQuery); 167 168
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.