1/* 2* File: jquery.barfiller.js 3* Version: 1.0.1 4* Description: A plugin that fills bars with a percentage you set. 5* Author: 9bit Studios 6* Copyright 2012, 9bit Studios 7* http://www.9bitstudios.com 8* Free to use and abuse under the MIT license. 9* http://www.opensource.org/licenses/mit-license.php 10*/ 11 12(function ($) { 13 14 $.fn.barfiller = function (options) { 15 16 var defaults = $.extend({ 17 barColor: '#16b597', 18 tooltip: true, 19 duration: 1000, 20 animateOnResize: true, 21 symbol: "%" 22 }, options); 23 24 25 /****************************** 26 Private Variables 27 *******************************/ 28 29 var object = $(this); 30 var settings = $.extend(defaults, options); 31 var barWidth = object.width(); 32 var fill = object.find('.fill'); 33 var toolTip = object.find('.tip'); 34 var fillPercentage = fill.attr('data-percentage'); 35 var resizeTimeout; 36 var transitionSupport = false; 37 var transitionPrefix; 38 39 /****************************** 40 Public Methods 41 *******************************/ 42 43 var methods = { 44 45 init: function() { 46 return this.each(function () { 47 if(methods.getTransitionSupport()) { 48 transitionSupport = true; 49 transitionPrefix = methods.getTransitionPrefix(); 50 } 51 52 methods.appendHTML(); 53 methods.setEventHandlers(); 54 methods.initializeItems(); 55 }); 56 }, 57 58 /****************************** 59 Append HTML 60 *******************************/ 61 62 appendHTML: function() { 63 fill.css('background', settings.barColor); 64 65 if(!settings.tooltip) { 66 toolTip.css('display', 'none'); 67 } 68 toolTip.text(fillPercentage + settings.symbol); 69 }, 70 71 72 /****************************** 73 Set Event Handlers 74 *******************************/ 75 setEventHandlers: function() { 76 if(settings.animateOnResize) { 77 $(window).on("resize", function(event){ 78 clearTimeout(resizeTimeout); 79 resizeTimeout = setTimeout(function() { 80 methods.refill(); 81 }, 300); 82 }); 83 } 84 }, 85 86 /****************************** 87 Initialize 88 *******************************/ 89 90 initializeItems: function() { 91 var pctWidth = methods.calculateFill(fillPercentage); 92 object.find('.tipWrap').css({ display: 'inline' }); 93 94 if(transitionSupport) 95 methods.transitionFill(pctWidth); 96 else 97 methods.animateFill(pctWidth); 98 }, 99 100 getTransitionSupport: function() { 101 102 var thisBody = document.body || document.documentElement, 103 thisStyle = thisBody.style; 104 var support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined; 105 return support; 106 }, 107 108 getTransitionPrefix: function() { 109 if(/mozilla/.test(navigator.userAgent.toLowerCase()) && !/webkit/.test(navigator.userAgent.toLowerCase())) { 110 return '-moz-transition'; 111 } 112 if(/webkit/.test(navigator.userAgent.toLowerCase())) { 113 return '-webkit-transition'; 114 } 115 if(/opera/.test(navigator.userAgent.toLowerCase())) { 116 return '-o-transition'; 117 } 118 if (/msie/.test(navigator.userAgent.toLowerCase())) { 119 return '-ms-transition'; 120 } 121 else { 122 return 'transition'; 123 } 124 }, 125 126 getTransition: function(val, time, type) { 127 128 var CSSObj; 129 if(type === 'width') { 130 CSSObj = { width : val }; 131 } 132 else if (type === 'left') { 133 CSSObj = { left: val }; 134 } 135 136 time = time/1000; 137 CSSObj[transitionPrefix] = type+' '+time+'s ease-in-out'; 138 return CSSObj; 139 140 }, 141 142 refill: function() { 143 fill.css('width', 0); 144 toolTip.css('left', 0); 145 barWidth = object.width(); 146 methods.initializeItems(); 147 }, 148 149 calculateFill: function(percentage) { 150 percentage = percentage * 0.01; 151 var finalWidth = barWidth * percentage;
152 return finalWidth; 153 }, 154 155 transitionFill: function(barWidth) { 156 157 var toolTipOffset = barWidth - toolTip.width(); 158 fill.css( methods.getTransition(barWidth, settings.duration, 'width')); 159 toolTip.css( methods.getTransition(toolTipOffset, settings.duration, 'left')); 160 161 }, 162 163 animateFill: function(barWidth) { 164 var toolTipOffset = barWidth - toolTip.width(); 165 fill.stop().animate({width: '+=' + barWidth}, settings.duration); 166 toolTip.stop().animate({left: '+=' + toolTipOffset}, settings.duration); 167 } 168 169 }; 170 171 if (methods[options]) { // $("#element").pluginName('methodName', 'arg1', 'arg2'); 172 return methods[options].apply(this, Array.prototype.slice.call(arguments, 1)); 173 } else if (typeof options === 'object' || !options) { // $("#element").pluginName({ option: 1, option:2 }); 174 return methods.init.apply(this); 175 } else { 176 $.error( 'Method "' + method + '" does not exist in barfiller plugin!'); 177 } 178 }; 179 180})(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.