From 1b625ad37a6af7f52b308b89254cbac0833d5271 Mon Sep 17 00:00:00 2001 From: Douglas Muth Date: Fri, 17 Feb 2017 23:40:34 -0500 Subject: [PATCH] Moved 100+ lines from Diceware.go() into Diceware.rollDiceHandler(). --- main.js | 246 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 124 insertions(+), 122 deletions(-) diff --git a/main.js b/main.js index b33aed3..92b0413 100644 --- a/main.js +++ b/main.js @@ -336,6 +336,128 @@ Diceware.is_mobile = function() { } // End of is_mobile() +/** +* Our handler for what to do when the "Roll Dice" button is clicked". +* It generates the passphrase and updates the HTML. +*/ +Diceware.rollDiceHandler = function(e) { + + // + // Clear out more space when mobile + // + // In the future, I should just use a media query in CSS + // + var target_height = 300; + if (Diceware.is_mobile()) { + target_height = 400; + } + + jQuery(".results").animate({height: target_height}, 400); + + // + // If we're running on an iPhone or similar, scroll down so that we can + // see the dice rolls and passphrase. + // + if (Diceware.is_mobile()) { + var aTag = $("a[name='roll_dice_button']"); + $("html,body").animate({scrollTop: aTag.offset().top}, "slow"); + } + + // + // Remove any old results + // + jQuery(".results").empty(); + + // + // Make our dice rolls + // + var num_dice = jQuery(".dice_button.active").html(); + var num_passwords = Number(Math.pow(6, (5 * num_dice))); + var passphrase = new Array(); + + var rolls = new Array(); + for (var i=0; i