Skip to content

Commit

Permalink
Update to 0.3
Browse files Browse the repository at this point in the history
Integrated clipboard.js and changed the generated pass field visibility toggle to a copy-to-clipboard button. Updated generated passfield from readonly to plain text for mobile compatibility for selecting and copying pass.
  • Loading branch information
jeremycaris committed Mar 30, 2019
1 parent 9e6f341 commit 071b5fb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 29 deletions.
10 changes: 8 additions & 2 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@
font-style: italic;
width: 100%;
text-align: center;
color: dimgray;
color: grey;
}

#passgrinder .toggle-password {
#passgrinder .toggle-password, #passgrinder .toggle-copy {
cursor: pointer;
}

#passgrinder #pg-result {
display: none;
}

@media all and (max-width: 767px) {
#passgrinder #pg-message #success {
display: none;
}
}
Binary file added assets/images/passgrinder-fb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions assets/js/clipboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 29 additions & 23 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ jQuery( document ).ready( function($) {
});



// Auto select all on generated pass field on click
jQuery( document ).ready( function($) {
$('#pg-result-pass').on('touchstart click', function(){
$(this).select();
});
});



// Hide generated password field and response on reset
jQuery( document ).ready( function($) {
Expand All @@ -78,6 +87,7 @@ jQuery( document ).ready( function($) {
$( '#passgrinder-form' ).submit(function(e){
e.preventDefault();


// Hash the password/s
var md5;
if ( $.md5($('#pg-password').val(), null, true) !== '' ) {
Expand Down Expand Up @@ -107,43 +117,39 @@ jQuery( document ).ready( function($) {

// Form post action and response handling
$.post(settings.ajaxurl, data, function(response) {
// console.log('Encoded: '+pg_z85);
// console.log( data );
console.log( "PassGrinder: " );
console.log( response );

$("#pg-result").show();
$("#pg-result-pass").val(pg_z85);

// Copy pass to clipboard automatically
var input = $("#pg-result-pass"), userstate;
if (input.attr("type") === "password") { // Check for current field type (password or test)
input.attr("type", "text"); // If password, change to text so we can copy it
userstate = 1; // Indicate previous user-set state so we know whether or not to change back
}
$("#pg-result-pass").select();
document.execCommand("copy");
if (userstate == 1) {
input.attr("type", "password");
userstate = null;
}
// Clipboard.js, copy on click
var clipboard = new ClipboardJS('.toggle-copy');

clipboard.on('success', function() {
$('#pg-message #success').html( 'Copied to the clipboard!' );
});

clipboard.on('error', function() {
$('#pg-message #fail').html( 'Something went wrong. Please manually copy your password.' );
});

// Send response
if ( response.success == true ) {
$('#pg-message #success').html( response.data );

// Auto reset form after 5 minutes
if ( $("#pg-result-pass").val() ) { // Double check that it is necessary
setTimeout( function() {
$("#passgrinder-form").trigger('reset');
$('#pg-message #reset').html("PassGrinder has automatically reset to protect your password.");
console.log( "PassGrinder: Automatically reset" );
}, 300000);
}
} else {
$('#pg-message #fail').html( response.data );
}

// Auto reset form after time
if ( $("#pg-result-pass").val() ) {
setTimeout( function() {
$("#passgrinder-form").trigger('reset');
$('#pg-message #reset').html("Form has automatically reset to protect your password.");
console.log( "PassGrinder: For automatically reset" );
}, 30000);
}

});

});
Expand Down
9 changes: 6 additions & 3 deletions inc/class-passgrinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function enqueue() {
// Load z85 encoding
wp_enqueue_script( 'passgrinder-z85', plugin_dir_url(__FILE__) . '../assets/js/encodeZ85.js' );

// Load clipboard.js
wp_enqueue_script( 'passgrinder-clipboardjs', plugin_dir_url(__FILE__) . '../assets/js/clipboard.min.js' );


// set variables for script
wp_localize_script( 'passgrinder', 'settings', array(
Expand All @@ -54,7 +57,7 @@ public function eval_helper() {

// send success or error
if ( $pass !== "" ) {
wp_send_json_success( __( 'Copied to the clipboard!', 'passgrinder' ) );
wp_send_json_success( __( 'Successfully generated your password!', 'passgrinder' ) );
} else {
wp_send_json_error( __( 'Something went wrong. Please refresh and try again!', 'passgrinder' ) );
}
Expand Down Expand Up @@ -139,9 +142,9 @@ public function shortcode_form($atts) {
<div id="pg-result" class="form-group row">
<div class="input-group col">
<input type="password" id="pg-result-pass" name="pg-result-pass" class="form-control" value="" placeholder="Your Generated Password" readonly />
<input type="text" id="pg-result-pass" name="pg-result-pass" class="form-control" value="" placeholder="Your Generated Password" />
<div class="input-group-append">
<div class="input-group-text toggle-password"><i class="fa fa-eye"></i></div>
<div class="input-group-text toggle-copy" data-clipboard-target="#pg-result-pass"><i class="fa fa-copy"></i></div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion passgrinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Description:
Author: Jeremy Caris
Author URI: https://passgrinder.com/
Version: 0.2
Version: 0.3
Category: utility
*/
Expand Down

0 comments on commit 071b5fb

Please sign in to comment.