/*
---
description: Form.PasswordStrength class, and basic dom methods
license: MIT-style
authors:
- Al Kent
requires:
- core/1.3.1: '*'
provides:
- Form.PasswordStrength
- Element.Events.keyupandchange
- String.strength
...
*/
if (!this.Form) this.Form = {};
Form.PasswordStrength = new Class({
Implements: [Options, Events],
options: {
//onUpdate: $empty,
threshold: 66,
primer: '',
height: 5,
opacity: 1,
bgcolor: 'transparent'
},
element: null,
fx: null,
initialize: function(el, options){
this.element = document.id(el);
this.setOptions(options);
if (this.options.primer) this.options.threshold = this.options.primer.strength();
var coord = this.element.getCoordinates();
var bar = new Element('div', {
styles: {
'position': 'absolute',
'top': coord.top + coord.height,
'left': coord.left,
'width': coord.width,
'height': this.options.height,
'opacity': this.options.opacity,
'background-color': this.options.bgcolor
}
}).inject(document.body, 'bottom');
var meter = new Element('div', {
styles: {
'width': 0,
'height': '100%'
}
}).inject(bar);
this.fx = new Fx.Morph(meter, {
duration: 'short',
link: 'cancel',
unit: '%'
});
this.element.addEvent('keyupandchange', this.animate.bind(this));
if (this.element.get('value')) this.animate();
},
animate: function(){
var value = this.element.get('value');
var color, strength = value.strength(), ratio = (strength / this.options.threshold).round(2).limit(0, 1);
if (ratio < 0.5) color = ('rgb(255, ' + (255 * ratio * 2).round() + ', 0)').rgbToHex();
else color = ('rgb(' + (255 * (1 - ratio) * 2).round() + ', 255, 0)').rgbToHex();
this.fx.start({
'width': 100 * ratio,
'background-color': color
});
this.fireEvent('update', [this.element, strength, this.options.threshold]);
}
});
Element.Events.keyupandchange = {
base: 'keyup',
condition: function(event){
var prev = this.retrieve('prev', null);
var cur = this.get('value');
if (typeOf(prev) != 'null' && prev == cur) return false;
this.store('prev', cur);
return true;
}
};
String.implement({
strength: function(){
var n = 0;
if (this.match(/\d/)) n += 10;
if (this.match(/[a-z]+/)) n += 26;
if (this.match(/[A-Z]+/)) n += 26;
if (this.match(/[^\da-zA-Z]/)) n += 33;
return (n == 0) ? 0 : (this.length * n.log() / (2).log()).round();
}
});
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| calendar-setup-uncompressed.js | 2013-03-01 19:57 | 8.75 KB | 76129f60960:kunden | -xw-x----- | |
| calendar-setup.js | 2013-03-01 19:57 | 3.02 KB | 76129f60960:kunden | -xw-x----- | |
| calendar-uncompressed.js | 2013-03-01 19:57 | 48.07 KB | 76129f60960:kunden | -xw-x----- | |
| calendar.js | 2013-03-01 19:57 | 29.6 KB | 76129f60960:kunden | -xw-x----- | |
| caption-uncompressed.js | 2013-03-01 19:57 | 1.47 KB | 76129f60960:kunden | -xw-x----- | |
| caption.js | 2013-03-01 19:57 | 729 B | 76129f60960:kunden | -xw-x----- | |
| combobox-uncompressed.js | 2013-03-01 19:57 | 4.76 KB | 76129f60960:kunden | -xw-x----- | |
| combobox.js | 2013-03-01 19:57 | 1.84 KB | 76129f60960:kunden | -xw-x----- | |
| core-uncompressed.js | 2013-03-01 19:57 | 13.16 KB | 76129f60960:kunden | -xw-x----- | |
| core.js | 2013-03-01 19:57 | 4.67 KB | 76129f60960:kunden | -xw-x----- | |
| highlighter-uncompressed.js | 2013-03-01 19:57 | 2.87 KB | 76129f60960:kunden | -xw-x----- | |
| highlighter.js | 2013-03-01 19:57 | 1.77 KB | 76129f60960:kunden | -xw-x----- | |
| index.html | 2013-03-01 19:57 | 30 B | 76129f60960:kunden | -xw-x----- | |
| modal-uncompressed.js | 2013-03-01 19:57 | 12.83 KB | 76129f60960:kunden | -xw-x----- | |
| modal.js | 2013-03-01 19:57 | 9.5 KB | 76129f60960:kunden | -xw-x----- | |
| mooRainbow-uncompressed.js | 2013-03-01 19:57 | 18.84 KB | 76129f60960:kunden | -xw-x----- | |
| mooRainbow.js | 2013-03-01 19:57 | 13.35 KB | 76129f60960:kunden | -xw-x----- | |
| mootools-core-uncompressed.js | 2013-03-01 19:57 | 156.73 KB | 76129f60960:kunden | -xw-x----- | |
| mootools-core.js | 2013-03-01 19:57 | 94.1 KB | 76129f60960:kunden | -xw-x----- | |
| mootools-more-uncompressed.js | 2013-03-01 19:57 | 343.17 KB | 76129f60960:kunden | -xw-x----- | |
| mootools-more.js | 2013-03-01 19:57 | 232.75 KB | 76129f60960:kunden | -xw-x----- | |
| mootree-uncompressed.js | 2013-03-01 19:57 | 21.39 KB | 76129f60960:kunden | -xw-x----- | |
| mootree.js | 2013-03-01 19:57 | 5.95 KB | 76129f60960:kunden | -xw-x----- | |
| multiselect.js | 2013-03-01 19:57 | 1.08 KB | 76129f60960:kunden | -xw-x----- | |
| passwordstrength.js | 2013-03-01 19:57 | 2.36 KB | 76129f60960:kunden | -xw-x----- | |
| progressbar-uncompressed.js | 2013-03-01 19:57 | 2.3 KB | 76129f60960:kunden | -xw-x----- | |
| progressbar.js | 2013-03-01 19:57 | 1.44 KB | 76129f60960:kunden | -xw-x----- | |
| swf-uncompressed.js | 2013-03-01 19:57 | 11.09 KB | 76129f60960:kunden | -xw-x----- | |
| swf.js | 2013-03-01 19:57 | 7.06 KB | 76129f60960:kunden | -xw-x----- | |
| switcher-uncompressed.js | 2013-03-01 19:57 | 1.92 KB | 76129f60960:kunden | -xw-x----- | |
| switcher.js | 2013-03-01 19:57 | 1.29 KB | 76129f60960:kunden | -xw-x----- | |
| tabs.js | 2013-03-01 19:57 | 2.45 KB | 76129f60960:kunden | -xw-x----- | |
| uploader-uncompressed.js | 2013-03-01 19:57 | 6.13 KB | 76129f60960:kunden | -xw-x----- | |
| uploader.js | 2013-03-01 19:57 | 4.91 KB | 76129f60960:kunden | -xw-x----- | |
| validate-uncompressed.js | 2013-03-01 19:57 | 5.03 KB | 76129f60960:kunden | -xw-x----- | |
| validate.js | 2013-03-01 19:57 | 2.85 KB | 76129f60960:kunden | -xw-x----- | |