2017-11-10 00:43:36 +00:00
/ * *
* Our main Javascript file .
* /
2023-05-07 19:18:02 +00:00
let Promise = require ( "bluebird" ) ;
2017-11-10 01:11:24 +00:00
2023-05-07 19:18:02 +00:00
let lib = require ( "./lib.js" ) ( ) ;
2017-11-10 01:11:24 +00:00
2017-11-10 00:43:36 +00:00
//
2023-05-07 19:18:02 +00:00
// I'm not a huge fan of globals, but the alternative was passing this variable into
// nearly every module, which gave me headaches trying to keep track of the dependency.
// I am storing things in modules (such as the wordlist) where I can...
2017-11-10 00:43:36 +00:00
//
2023-05-07 19:18:02 +00:00
window . Diceware = { } ;
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
// Functions that relate to displaying dice
display = require ( "./display.js" ) ( )
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
// Wordlist handling
wordlist = require ( "./wordlist.js" ) ( )
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
// Misc utilities
util = require ( "./util.js" ) ( ) ;
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
//
// How many dice per roll?
//
window . Diceware . num _dice _per _roll = 5 ;
2017-11-10 00:43:36 +00:00
/ * *
2023-05-07 19:18:02 +00:00
* Set the handlers
2017-11-10 00:43:36 +00:00
* /
2023-05-07 19:18:02 +00:00
function set _handlers ( ) {
2020-01-16 00:49:50 +00:00
2017-11-10 00:43:36 +00:00
//
// Handler to mark the clicked number of dice button as active.
//
jQuery ( ".dice_button" ) . on ( "click" , function ( e ) {
jQuery ( ".dice_button" ) . removeClass ( "active" ) ;
jQuery ( e . target ) . addClass ( "active" ) ;
} ) ;
2023-05-07 19:18:02 +00:00
jQuery ( "#roll_dice" ) . on ( "click" , display . rollDiceHandler ) ;
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
} // End of set_handlers()
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
/ * *
* Run our pre - flight checks .
* /
function run _preflight _checks ( ) {
2017-11-10 00:43:36 +00:00
//
// If we're not on a mobile, bring in the GitHub ribbon.
//
2023-05-07 19:18:02 +00:00
if ( ! util . is _mobile ( ) ) {
2017-11-10 00:43:36 +00:00
jQuery ( "#github_ribbon" ) . fadeIn ( 1000 ) ;
}
2017-11-10 01:11:24 +00:00
if ( ! lib . iCanHasGoodCrypto ( ) ) {
2017-11-10 00:43:36 +00:00
jQuery ( ".source .bad_crypto" ) . clone ( ) . hide ( ) . fadeIn ( 800 ) . appendTo ( ".message" ) ;
}
2023-05-07 19:18:02 +00:00
} // End of run_preflight_checks()
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
/ * *
* Our main function when being used via the UI . We call this to set up our jQuery hooks .
*
* /
function go ( ) {
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
console . log ( "Thanks for checking out my code! You can find the Git repo at https://github.com/dmuth/diceware, my blog at https://www.dmuth.org/, or you can bug me on Twitter at https://twitter.com/dmuth" ) ;
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
console . log ( "Version: $Id$" ) ;
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
//
// Set our handlers
//
set _handlers ( )
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
//
// Run our pre-flight checks
//
run _preflight _checks ( )
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
//
// Get the filename of the wordlist that we're loading.
//
let file = wordlist . get _filename ( )
console . log ( ` Looks like we're loading ${ file [ "filename" ] } ! ` ) ;
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
//
// Load the wordlist.
//
let debug = location . search . indexOf ( "debug" ) ;
window . Diceware . get _data = util . extract _get _data ( location . search ) ;
console . log ( "GET Data: " + JSON . stringify ( window . Diceware . get _data ) ) ; // Debugging
2017-11-10 00:43:36 +00:00
2023-05-07 19:18:02 +00:00
wordlist . load ( file , window . Diceware . get _data , debug )
2017-11-10 00:43:36 +00:00
} // End of go()
//
// Run go() automatically, as that is the webpack way.
//
2023-05-07 19:18:02 +00:00
go ( ) ;
2017-11-10 00:43:36 +00:00