1/** 2 * bootstrap-strength-meter.js 3 * https://github.com/davidstutz/bootstrap-strength-meter 4 * 5 * Copyright 2013 David Stutz 6 */ 7!function($) { 8 9 "use strict";// jshint ;_; 10 11 var StrengthMeter = { 12 13 progressBar: function(input, options) { 14 15 var defaults = { 16 container: input.parent(), 17 base: 80, 18 hierarchy: { 19 '0': 'progress-bar-danger', 20 '25': 'progress-bar-warning', 21 '50': 'progress-bar-success' 22 }, 23 passwordScore: { 24 options: [], 25 append: true 26 } 27 }; 28 29 var settings = $.extend(true, {}, defaults, options); 30 31 if (typeof options === 'object' && 'hierarchy' in options) { 32 settings.hierarchy = options.hierarchy; 33 } 34 35 var template = '<div class="progress"><div class="progress-bar" role="progressbar"></div></div>'; 36 var progress; 37 var progressBar; 38 var passcheckTimeout; 39 var core = { 40 41 /** 42 * Initialize the plugin. 43 */ 44 init: function() { 45 progress = settings.container.append($(template)); 46 progressBar = $('.progress-bar', progress); 47 48 progressBar.attr('aria-valuemin', 0) 49 .attr('aria-valuemay', 100); 50 51 input.on('keyup', core.keyup) 52 .keyup(); 53 }, 54 queue: function(event){ 55 var password = $(event.target).val(); 56 var value = 0; 57 58 if (password.length > 0) { 59 var score = new Score(password); 60 value = score.calculateEntropyScore(settings.passwordScore.options, settings.passwordScore.append); 61 } 62 63 core.update(value); 64 }, 65 66 /** 67 * Update progress bar. 68 * 69 * @param {string} value 70 */ 71 update: function(value) { 72 var width = Math.floor((value/settings.base)*100); 73 74 if (width > 100) { 75 width = 100; 76 } 77 78 progressBar 79 .attr('area-valuenow', width) 80 .css('width', width + '%'); 81 82 for (var value in settings.hierarchy) { 83 if (width > value) { 84 progressBar 85 .removeClass() 86 .addClass('progress-bar') 87 .addClass(settings.hierarchy[value]); 88 } 89 } 90 }, 91 92 /** 93 * Event binding on password input. 94 * 95 * @param {Object} event 96 */ 97 keyup: function(event) { 98 if(passcheckTimeout)clearTimeout(passcheckTimeout); 99 passcheckTimeout = setTimeout( function(){ 100 core.queue(event); 101 },500); 102 } 103 }; 104
105 core.init(); 106 }, 107 text: function(input, options) { 108 109 var defaults = { 110 container: input.parent(), 111 hierarchy: { 112 '0': ['text-danger', 'ridiculous'], 113 '10': ['text-danger', 'very weak'], 114 '20': ['text-warning', 'weak'], 115 '30': ['text-warning', 'good'], 116 '40': ['text-success', 'strong'], 117 '50': ['text-success', 'very strong'] 118 }, 119 passwordScore: { 120 options: [], 121 append: true 122 } 123 }; 124 125 var settings = $.extend(true, {}, defaults, options); 126 127 if (typeof options === 'object' && 'hierarchy' in options) { 128 settings.hierarchy = options.hierarchy; 129 } 130 131 var core = { 132 133 /** 134 * Initialize the plugin. 135 */ 136 init: function() { 137 input.on('keyup', core.keyup) 138 .keyup(); 139 }, 140 141 /** 142 * Update text element. 143 * 144 * @param {string} value 145 */ 146 update: function(value) { 147 for (var border in settings.hierarchy) { 148 if (value >= border) { 149 var text = settings.hierarchy[border][1]; 150 var color = settings.hierarchy[border][0]; 151 152 settings.container.text(text) 153 .removeClass() 154 .addClass(color); 155 } 156 } 157 }, 158 159 /** 160 * Event binding on input element. 161 * 162 * @param {Object} event 163 */ 164 keyup: function(event) { 165 var password = $(event.target).val(); 166 var value = 0; 167 168 if (password.length > 0) { 169 var score = new Score(password); 170 value = score.calculateEntropyScore(settings.passwordScore.options, settings.passwordScore.append); 171 } 172 173 core.update(value); 174 } 175 }; 176
177 core.init(); 178 }, 179 180 tooltip: function(input, options) { 181 182 var defaults = { 183 hierarchy: { 184 '0': 'ridiculous', 185 '10': 'very weak', 186 '20': 'weak', 187 '30': 'good', 188 '40': 'strong', 189 '50': 'very strong' 190 }, 191 tooltip: { 192 placement: 'right' 193 }, 194 passwordScore: { 195 options: [], 196 append: true 197 } 198 }; 199 200 var settings = $.extend(true, {}, defaults, options); 201 202 if (typeof options === 'object' && 'hierarchy' in options) { 203 settings.hierarchy = options.hierarchy; 204 } 205 206 var core = { 207 208 /** 209 * Initialize the plugin. 210 */ 211 init: function() { 212 input.tooltip(settings.tooltip); 213 214 input.on('keyup', core.keyup) 215 .keyup(); 216 }, 217 218 /** 219 * Update tooltip. 220 * 221 * @param {string} value 222 */ 223 update: function(value) { 224 for (var border in settings.hierarchy) { 225 if (value >= border) { 226 var text = settings.hierarchy[border]; 227 228 input.attr('data-original-title', text) 229 .tooltip('show'); 230 } 231 } 232 }, 233 234 /** 235 * Event binding on input element. 236 * 237 * @param {Object} event 238 */ 239 keyup: function(event) { 240 var password = $(event.target).val(); 241 var value = 0; 242 243 if (password.length > 0) { 244 var score = new Score(password); 245 value = score.calculateEntropyScore(settings.passwordScore.options, settings.passwordScore.append); 246 } 247 248 core.update(value); 249 } 250 }; 251
252 core.init(); 253 } 254 }; 255 256 $.fn.strengthMeter = function(type, options) { 257 type = (type === undefined) ? 'tooltip' : type; 258 259 if (!type in StrengthMeter) { 260 return; 261 } 262 263 var instance = this.data('strengthMeter'); 264 var elem = this; 265 266 return elem.each(function() { 267 var strengthMeter; 268 269 if (instance) { 270 return; 271 } 272 273 strengthMeter = StrengthMeter[type](elem, options); 274 elem.data('strengthMeter', strengthMeter); 275 }); 276 }; 277 278}(window.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.