js/startup.js
changeset 0 52d30e6014a0
equal deleted inserted replaced
-1:000000000000 0:52d30e6014a0
       
     1 /*######################################################################
       
     2 ### YubiKey global namespace
       
     3 ######################################################################*/
       
     4 var Y = {
       
     5 
       
     6 	// Information for the currently inserted key.
       
     7 	keyinfo: {},
       
     8 
       
     9 	// Declared windows, for easy referencing
       
    10 	window: {},
       
    11 
       
    12 
       
    13 	// Convert a string to hexadecimal.
       
    14 	//
       
    15 	toHex: function( string ) {
       
    16 		var hex = '';
       
    17 		for( var i = 0; i < string.length; i++ )
       
    18 			hex += string.charCodeAt(i).toString(16);
       
    19 		return hex;
       
    20 	},
       
    21 
       
    22 
       
    23 	// Return a random string of +length+.
       
    24 	//
       
    25 	randString: function( length ) {
       
    26 		var text = '';
       
    27 		var set  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
       
    28 
       
    29 		for( var i = 0; i < length; i++ )
       
    30 			text += set.charAt( Math.floor(Math.random() * set.length) );
       
    31 		return text;
       
    32 	},
       
    33 
       
    34 
       
    35 	// Generic delayed callback that returns the timer handle.
       
    36 	//
       
    37 	delay: (function() {
       
    38 		var timer = null;
       
    39 		return function( callback, ms, clear_previous ) {
       
    40 			if ( clear_previous) clearTimeout( timer );
       
    41 			timer = setTimeout( callback, ms );
       
    42 			return timer;
       
    43 		};
       
    44 	})(),
       
    45 
       
    46 	// Stop the default webkit behavior (viewer) when you drag a file into a window.
       
    47 	//
       
    48 	disableDragDrop: function( window ) {
       
    49 		window.ondragover = function(e) { e.preventDefault(); return false };
       
    50 		window.ondrop     = function(e) { e.preventDefault(); return false };
       
    51 	},
       
    52 
       
    53 	// Node's filesystem interface.
       
    54 	fs: require( 'fs' ),
       
    55 
       
    56 	// Manage child processes.
       
    57 	spawn: require( 'child_process' ).spawn
       
    58 };
       
    59 
       
    60 
       
    61 // Make the 'Y' namespace available elsewhere.
       
    62 global.Y = Y;
       
    63