diff options
| author | Teddy Wing | 2013-03-28 19:07:10 -0400 | 
|---|---|---|
| committer | Teddy Wing | 2013-03-28 19:09:02 -0400 | 
| commit | 22b2c8a09d168cd47cfb50a781e41ae88c12fc31 (patch) | |
| tree | 0e953e9feed7f9746441c5e8c7d574bf12ec3950 /better-scrumdo.js | |
| parent | 1e77fb46da9e4d226dc58a63ceabbb613864496a (diff) | |
| download | ScrumDo-Trellic-22b2c8a09d168cd47cfb50a781e41ae88c12fc31.tar.bz2 | |
Disable keyboard commands on input focus
When a text input or textarea is focused, disable keyboard shortcuts
so that you can actually type things without having the interface do
all sorts of things.
Update TODO.
Diffstat (limited to 'better-scrumdo.js')
| -rw-r--r-- | better-scrumdo.js | 124 | 
1 files changed, 67 insertions, 57 deletions
| diff --git a/better-scrumdo.js b/better-scrumdo.js index ce4196c..3f0a789 100644 --- a/better-scrumdo.js +++ b/better-scrumdo.js @@ -207,6 +207,7 @@ $(function() {  			if (this.current) {  				this.open_edit_modal();  				this.wait_for_edit_modal_to_load(function() { +					KeyCommandManager.toggle_keyboard_events_on_input_focus();  					$('textarea#id_summary').focus();  				});  			} @@ -241,6 +242,7 @@ $(function() {  				// Focus task summary field  				that = this;  				setTimeout(function() { +					KeyCommandManager.toggle_keyboard_events_on_input_focus();  					that.current.find('.tasks_area input[name="summary"]').focus();  				}, 500);  			} @@ -320,6 +322,70 @@ var KeyCodes = {  }; +var cKeyCommandManager = function() { +	var self = this; +	 +	this.toggle_keyboard_events_on_input_focus = function() { +		$('input[type="text"], textarea') +			.off('focus', this.disable_keyboard_shortcuts) +			.off('blur', this.enable_keyboard_shortcuts); +			 +		$('input[type="text"], textarea') +			.on('focus', this.disable_keyboard_shortcuts) +			.on('blur', this.enable_keyboard_shortcuts); +	}; +	 +	this.bind_keyboard_commands = function(e) { +		var key = (e.which || e.keyCode); +		 +		// console.log(e); +		 +		var responds_to = []; +		// for (var k in KeyCodes){} +		 +		switch (key) { +			case KeyCodes.i: +				Story.edit(); +				break; +			case KeyCodes.a: +				Story.assign(); +				break; +			case KeyCodes.p: +				Story.point(); +				break; +			case KeyCodes.t: +				Story.tasks(); +				break; +			case KeyCodes.b: +				Story.toggle_project_panel(); +				break; +			case KeyCodes.esc: +				Story.close_edit_modal(); +				break; +			case KeyCodes.l: +				if (e.shiftKey) { +					Story.list_view(); +				} +				break; +		} +	}; +	 +	this.disable_keyboard_shortcuts = function() { +		console.log('KEYBOARD COMMANDS DISABLED'); +		$(document).off('keydown', self.bind_keyboard_commands); +	}; +	 +	this.enable_keyboard_shortcuts = function() { +		console.log('KEYBOARD COMMANDS ENABLED'); +		$(document).on('keydown', self.bind_keyboard_commands); +	}; +	 +	 +	return this; +}; +var KeyCommandManager = new cKeyCommandManager(); + +  // Set the current story  $(function() {  	var $story_el = $('.scrum_board_story_block'); @@ -362,63 +428,7 @@ $(function() {  				break;  		}  	}); -}); - - -// Story actions - keyboard shortcuts -$(function() { -	// Disable keyboard shortcuts when an input element is focused -	$('input[type="text"], textarea').on('focus', function() { -		// Disable -		disable_keyboard_shortcuts(); -	}).on('blur', function() { -		// Enable -		enable_keyboard_shortcuts(); -	}); -	 -	var bind_keyboard_commands = function(e) { -		var key = (e.which || e.keyCode); -	 -		// console.log(e); -		var responds_to = []; -		// for (var k in KeyCodes){} -		switch (key) { -			case KeyCodes.i: -				Story.edit(); -				break; -			case KeyCodes.a: -				Story.assign(); -				break; -			case KeyCodes.p: -				Story.point(); -				break; -			case KeyCodes.t: -				Story.tasks(); -				break; -			case KeyCodes.b: -				Story.toggle_project_panel(); -				break; -			case KeyCodes.esc: -				Story.close_edit_modal(); -				break; -			case KeyCodes.l: -				if (e.shiftKey) { -					Story.list_view(); -				} -				break; -		} -	}; -	 -	var disable_keyboard_shortcuts = function() { -		console.log('DISABLED'); -		$(document).off('keydown', bind_keyboard_commands); -	}; -	 -	var enable_keyboard_shortcuts = function() { -		console.log('ENABLED'); -		$(document).on('keydown', bind_keyboard_commands); -	}; -	enable_keyboard_shortcuts(); +	KeyCommandManager.enable_keyboard_shortcuts();  }); | 
