Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- // Set objects
- var $generator = $('.generator');
- $complicate = $('.complicate', $generator),
- $generate = $('.generate', $generator),
- $passwordFinnal = $('#passwordFinnal', $generator),
- $passwordPlain = $('#passwordPlain', $generator),
- $copy = $('.input--wrap-icon', $generator),
- $indicator = $('.generator-indicator span', $generator);
- // Show copy
- var showCopy = function(val) {
- // Show
- if(val) {
- $copy.show();
- }
- // Hide
- else {
- $copy.hide();
- }
- }
- // Change indicator
- var changeIndicator = function(password) {
- // Set strength
- var strength = 0;
- // Length 5 characters or more
- if(password.length >= 7) {
- strength++;
- }
- // Contains lowercase characters
- if(password.match(/[a-z]+/)) {
- strength++;
- }
- // Contains digits
- if(password.match(/[0-9]+/)) {
- strength++;
- }
- // Contains uppercase characters
- if(password.match(/[A-Z]+/)) {
- strength++;
- }
- // Contains special characters
- if(password.match(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/)) {
- strength++;
- }
- // Set indicator width
- $indicator.css('width', (strength * 20) + '%');
- }
- // Show generator
- $generator.show();
- // Hide complicate button and copy
- $('.complicate', $generator).add($copy).hide();
- // Generate and complicate
- $generate.add($complicate).on('click', function() {
- // Save self
- var $self = $(this);
- // Create ajax request
- $.get('http://leximo.criticalworks.cz/projects/inste.cz/generator-hesel/?password=' + $passwordPlain.val() + '&complicate=' + $self.hasClass('complicate'), function(data, status, response){
- // Error happened
- if(status == 'error') {
- // Throw errior into console
- console.log(response);
- // All is fine
- } else {
- // Check data
- if(data) {
- // Append password
- $passwordFinnal.val(data);
- // Change indicator
- changeIndicator(data);
- // Show copy
- showCopy(data.length > 0);
- // Keep plain passqword
- if(!$self.hasClass('complicate')) {
- $passwordPlain.val(data);
- }
- // Show complicate button
- $complicate.show();
- }
- // Data are empty
- else {
- console.log('retrieved password is empty')
- }
- }
- });
- });
- // Show complicate button
- $passwordFinnal.on('keyup change', function() {
- // Set val
- var val = $(this).val();
- // Change indicator
- changeIndicator(val);
- // Show copy
- showCopy(val.length > 0);
- // Show
- if(val.length >= 10) {
- $complicate.show();
- }
- // Hide
- else {
- $complicate.hide();
- }
- });
- // Copy to clipboard
- $copy.on('click', function() {
- // Create temp
- var $temp = $('<input>');
- // Append tempt to body
- $('body').append($temp);
- // Select text
- $temp.val($passwordFinnal.val()).select();
- // Copy
- document.execCommand('copy');
- // Remove temp
- $temp.remove();
- // Alert
- alert("Heslo bylo zkopírováno");
- });
- })($);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement