From 464c2fa825d6599938013fdc9423cf5bc3c39165 Mon Sep 17 00:00:00 2001 From: Nathan Williams Date: Tue, 23 Jun 2015 17:00:41 -0400 Subject: [PATCH 1/2] Add inputs configuration option and set position on wrapper element. --- README.md | 6 +++++- jquery.strengthify.js | 7 ++++--- strengthify.css | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c37d7e5..7fb43f3 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,9 @@ Configuration The path and the title of the different strength categories can be configured with the first parameter of `.strengthify`. +The inputs property is an array of words to add to zxcvbn's dictionary +or a function that returns the array to use. + Default: ```JSON @@ -52,7 +55,8 @@ Default: "So-so", "Good", "Perfect" - ] + ], + "inputs": [] } ``` diff --git a/jquery.strengthify.js b/jquery.strengthify.js index 21f5fa8..5667d38 100644 --- a/jquery.strengthify.js +++ b/jquery.strengthify.js @@ -41,7 +41,8 @@ 'So-so', 'Good', 'Perfect' - ] + ], + inputs: [] }, options = $.extend(defaults, paramOptions); @@ -60,10 +61,10 @@ }).done(function() { me.bind('keyup input', function() { var password = $(this).val(), - // hide strengthigy if no input is provided + // hide strengthify if no input is provided opacity = (password === '') ? 0 : 1, // calculate result - result = zxcvbn(password), + result = zxcvbn(password, typeof options.inputs === 'function' ? options.inputs() : options.inputs), css = '', // cache jQuery selections $container = $('.strengthify-container'), diff --git a/strengthify.css b/strengthify.css index 9340270..041e9aa 100644 --- a/strengthify.css +++ b/strengthify.css @@ -6,6 +6,10 @@ * Copyright (c) 2013 Morris Jobke */ +.strengthify-wrapper { + position: relative; +} + .strengthify-wrapper > * { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: alpha(opacity=0); From 807547dd6684fe772c50312f8be163465e0f9cc7 Mon Sep 17 00:00:00 2001 From: Nathan Williams Date: Tue, 23 Jun 2015 19:12:29 -0400 Subject: [PATCH 2/2] Initialize meter if password value is prefilled or typed before loading completes. --- jquery.strengthify.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jquery.strengthify.js b/jquery.strengthify.js index 5667d38..0be04ad 100644 --- a/jquery.strengthify.js +++ b/jquery.strengthify.js @@ -59,8 +59,8 @@ dataType: 'script', url: options.zxcvbn }).done(function() { - me.bind('keyup input', function() { - var password = $(this).val(), + function update() { + var password = me.val(), // hide strengthify if no input is provided opacity = (password === '') ? 0 : 1, // calculate result @@ -126,7 +126,11 @@ $container.css('width', 0); } - }); + }; + me.bind('keyup input', update); + if (me.val()) { + update(); + } }); return me;