(function ($) {
var $element = null;
var PasswordValidation = function (element, options, event) {
if(options == 'show') {
this._showPopover(element);
return;
} else if(options == 'hide'){
this._hidePopover(element);
return;
}
this.lowerCaseValidateMsg = '
'+ i18n.msg('pwd.validator.lowerCaseMsg')+'
';
this.upperCaseValidateMsg = ''+ i18n.msg('pwd.validator.upperCaseMsg')+'
';
this.numberRequiredValidateMsg = ''+ i18n.msg('pwd.validator.numberMsg')+'
';
this.minSizeValidateMsg = ''+ i18n.msg('pwd.validator.minSizeMsg')+'
';
this.simbolRequiredValidateMsg = 'Simbolos
';
this.invalidCaractersValidateMsg = ''+ i18n.msg('pwd.validator.invalidCharsMsg')+'
';
this.nameValidateMsg = ''+ i18n.msg('pwd.validator.nameMsg')+'
';
this.popoverId = null;
if(event) {
event.stopPropagation();
event.preventDefault();
}
this.$element = $(element);
this.$newElement = null;
this.options = options;
this.name = '';
this.init();
return this;
};
PasswordValidation.prototype._showPopover = function(element) {
$(element).popover('show');
};
PasswordValidation.prototype._hidePopover = function(element) {
$(element).popover('hide');
};
PasswordValidation.prototype._isShown = function() {
return $('.popover').hasClass('in');
};
PasswordValidation.prototype.init = function() {
var that = this,
id = that.$element.attr('id');
var contentPopover = '';
if(that.options) {
if(that.options.minSize) {
var contentMinSize = that.minSizeValidateMsg.replace('', that.options.minSize);
contentPopover = contentPopover + contentMinSize;
contentPopover = contentPopover.replace('', id);
}
if(that.options.lowerCaseRequired) {
contentPopover = contentPopover + that.lowerCaseValidateMsg;
contentPopover = contentPopover.replace('', id);
}
if(that.options.upperCaseRequired) {
contentPopover = contentPopover + that.upperCaseValidateMsg;
contentPopover = contentPopover.replace('', id);
}
if(that.options.numberRequired) {
contentPopover = contentPopover + that.numberRequiredValidateMsg;
contentPopover = contentPopover.replace('', id);
}
if(that.options.simbolRequired) {
contentPopover = contentPopover + that.simbolRequiredValidateMsg;
contentPopover = contentPopover.replace('', id);
}
if(!that.options.acceptInvalidCaracters) {
contentPopover = contentPopover + that.invalidCaractersValidateMsg;
contentPopover = contentPopover.replace('', id);
}
if(that.options.verifyName) {
contentPopover = contentPopover + that.nameValidateMsg;
contentPopover = contentPopover.replace('', id);
that.name = that.options.verifyName;
}
}
that.$element.on('shown.bs.popover', function () {
that.checkPassword(that.$element.val());
});
var selector = that.$element.attr('id');
that.popoverId = that.$element.popover({
title : i18n.msg('pwd.validator.title'),
content : contentPopover,
trigger : 'manual',
container: 'body',
html: true
});
that.$element.off('keyup').on('keyup', function(event) {
that.checkPassword(that.$element.val());
});
that.$element.focus(function(){
if(!that._isShown() == true) {
that.$element.popover({
title : i18n.msg('pwd.validator.title'),
content : contentPopover,
trigger : 'manual',
container: 'body',
html: true
});
that.$element.popover('show');
}
});
};
PasswordValidation.prototype._changeToValid = function(div) {
if($(div).hasClass('invalid')){
$(div).removeClass('invalid');
$(div).addClass('valid');
}
};
PasswordValidation.prototype._changeToInValid = function(div) {
if($(div).hasClass('valid')) {
$(div).removeClass('valid');
$(div).addClass('invalid');
}
};
PasswordValidation.prototype.checkPassword = function(pswd) {
var that = this;
var isValid = true;
//validate the length
if ( that.options.minSize && pswd.length >= that.options.minSize ) {
that._changeToValid('#minsizeValidate_' + this.$element.attr('id'));
} else {
that._changeToInValid('#minsizeValidate_' + this.$element.attr('id'));
isValid = false;
}
//validate letter
if ( pswd.match(/[a-z]/) ) {
that._changeToValid('#lowerCaseValidate_' + this.$element.attr('id'));
} else {
that._changeToInValid('#lowerCaseValidate_' + this.$element.attr('id'));
isValid = false;
}
//validate capital letter
if ( pswd.match(/[A-Z]/) ) {
that._changeToValid('#upperCaseValidate_' + this.$element.attr('id'));
} else {
that._changeToInValid('#upperCaseValidate_' + this.$element.attr('id'));
isValid = false;
}
//validate number
if ( pswd.match(/\d/) ) {
that._changeToValid('#numberValidate_' + this.$element.attr('id'));
} else {
that._changeToInValid('#numberValidate_' + this.$element.attr('id'));
isValid = false;
}
that.$element.attr('valid', isValid);
}
PasswordValidation.prototype.checkPasswordChar = function(pswdChar) {
var result = false;
try {
if (pswdChar.match(/[a-z]/) || pswdChar.match(/[A-Z]/) || pswdChar.match(/\d/)
|| pswdChar.match(/[\u007E]/)
|| pswdChar.match(/[\u0021]/)
|| pswdChar.match(/[\u0040]/)
|| pswdChar.match(/[\u0023]/)
|| pswdChar.match(/[\u0024]/)
|| pswdChar.match(/[\u0025]/)
|| pswdChar.match(/[\u005E]/)
|| pswdChar.match(/[\u0026]/)
|| pswdChar.match(/[\u002A]/)
|| pswdChar.match(/[\u005F]/)
|| pswdChar.match(/[\u002D]/)
|| pswdChar.match(/[\u002B]/)
|| pswdChar.match(/[\u003D]/)
|| pswdChar.match(/[\u0060]/)
|| pswdChar.match(/[\u007C]/)
|| pswdChar.match(/[\u005C]/)
|| pswdChar.match(/[\u0028]/)
|| pswdChar.match(/[\u0029]/)
|| pswdChar.match(/[\u007B]/)
|| pswdChar.match(/[\u007D]/)
|| pswdChar.match(/[\u005B]/)
|| pswdChar.match(/[\u005D]/)
|| pswdChar.match(/[\u003A]/)
|| pswdChar.match(/[\u003B]/)
|| pswdChar.match(/[\u0022]/)
|| pswdChar.match(/[\u0027]/)
|| pswdChar.match(/[\u003C]/)
|| pswdChar.match(/[\u003E]/)
|| pswdChar.match(/[\u002C]/)
|| pswdChar.match(/[\u002E]/)
|| pswdChar.match(/[\u003F]/)
|| pswdChar.match(/[\u002F]/)) {
result = true;
}
} catch (e) {}
return result;
};
PasswordValidation.prototype.checkPasswordFullName = function(pswd) {
var fullName = this.name.split(" ");
var containsName = false;
if (fullName.length>=1 && fullName[0]!=""){
for ( var i = 0; !containsName && (i < fullName.length); i++) {
if(fullName[i] != null && fullName[i] != undefined && fullName[i] != "" && fullName[i] != " ") {
containsName = (pswd.toLowerCase().match(fullName[i].toLowerCase())!=null);
}
}
}
return containsName;
};
PasswordValidation.prototype.updateVerticalPosition = function(top) {
var position = top;
};
PasswordValidation.prototype.hide = function(pswd) {
};
function Plugin(option, event) {
return this.each(function () {
var $this = $(this)
new PasswordValidation(this, option);
})
};
$.fn.passwordValidation = Plugin
$.fn.passwordValidation.Constructor = PasswordValidation
})(jQuery);