4
4
5
5
/**
6
6
* Controller for the MdChip component. Responsible for handling keyboard
7
- * events and editting the chip if needed.
7
+ * events and editing the chip if needed.
8
8
*
9
9
* @param $scope
10
10
* @param $element
@@ -42,7 +42,7 @@ function MdChipCtrl ($scope, $element, $mdConstant, $timeout, $mdUtil) {
42
42
/**
43
43
* @type {boolean }
44
44
*/
45
- this . isEditting = false ;
45
+ this . isEditing = false ;
46
46
47
47
/**
48
48
* @type {MdChipsCtrl }
@@ -65,14 +65,14 @@ MdChipCtrl.prototype.init = function(controller) {
65
65
66
66
if ( this . enableChipEdit ) {
67
67
this . $element . on ( 'keydown' , this . chipKeyDown . bind ( this ) ) ;
68
- this . $element . on ( 'mousedown ' , this . chipMouseDown . bind ( this ) ) ;
68
+ this . $element . on ( 'dblclick ' , this . chipMouseDoubleClick . bind ( this ) ) ;
69
69
this . getChipContent ( ) . addClass ( '_md-chip-content-edit-is-enabled' ) ;
70
70
}
71
71
} ;
72
72
73
73
74
74
/**
75
- * @return {Object }
75
+ * @return {Object } first element with the md-chip-content class
76
76
*/
77
77
MdChipCtrl . prototype . getChipContent = function ( ) {
78
78
var chipContents = this . $element [ 0 ] . getElementsByClassName ( 'md-chip-content' ) ;
@@ -81,28 +81,29 @@ MdChipCtrl.prototype.getChipContent = function() {
81
81
82
82
83
83
/**
84
- * @return {Object }
84
+ * @return {Object } first content element of the chips content element
85
85
*/
86
86
MdChipCtrl . prototype . getContentElement = function ( ) {
87
- return angular . element ( this . getChipContent ( ) . children ( ) [ 0 ] ) ;
87
+ return angular . element ( this . getChipContent ( ) . contents ( ) [ 0 ] ) ;
88
88
} ;
89
89
90
90
91
91
/**
92
- * @return {number }
92
+ * @return {number } index of this chip
93
93
*/
94
94
MdChipCtrl . prototype . getChipIndex = function ( ) {
95
95
return parseInt ( this . $element . attr ( 'index' ) ) ;
96
96
} ;
97
97
98
98
99
99
/**
100
- * Presents an input element to edit the contents of the chip.
100
+ * Update the chip's contents, focus the chip if it's selected, and exit edit mode.
101
+ * If the contents were updated to be empty, remove the chip and re-focus the input element.
101
102
*/
102
103
MdChipCtrl . prototype . goOutOfEditMode = function ( ) {
103
- if ( ! this . isEditting ) return ;
104
+ if ( ! this . isEditing ) return ;
104
105
105
- this . isEditting = false ;
106
+ this . isEditing = false ;
106
107
this . $element . removeClass ( '_md-chip-editing' ) ;
107
108
this . getChipContent ( ) [ 0 ] . contentEditable = 'false' ;
108
109
var chipIndex = this . getChipIndex ( ) ;
@@ -127,7 +128,7 @@ MdChipCtrl.prototype.goOutOfEditMode = function() {
127
128
128
129
/**
129
130
* Given an HTML element. Selects contents of it.
130
- * @param node
131
+ * @param { Element } node
131
132
*/
132
133
MdChipCtrl . prototype . selectNodeContents = function ( node ) {
133
134
var range , selection ;
@@ -149,7 +150,7 @@ MdChipCtrl.prototype.selectNodeContents = function(node) {
149
150
* Presents an input element to edit the contents of the chip.
150
151
*/
151
152
MdChipCtrl . prototype . goInEditMode = function ( ) {
152
- this . isEditting = true ;
153
+ this . isEditing = true ;
153
154
this . $element . addClass ( '_md-chip-editing' ) ;
154
155
this . getChipContent ( ) [ 0 ] . contentEditable = 'true' ;
155
156
this . getChipContent ( ) . on ( 'blur' , function ( ) {
@@ -164,15 +165,15 @@ MdChipCtrl.prototype.goInEditMode = function() {
164
165
* Handles the keydown event on the chip element. If enable-chip-edit attribute is
165
166
* set to true, space or enter keys can trigger going into edit mode. Enter can also
166
167
* trigger submitting if the chip is already being edited.
167
- * @param event
168
+ * @param { KeyboardEvent } event
168
169
*/
169
170
MdChipCtrl . prototype . chipKeyDown = function ( event ) {
170
- if ( ! this . isEditting &&
171
+ if ( ! this . isEditing &&
171
172
( event . keyCode === this . $mdConstant . KEY_CODE . ENTER ||
172
173
event . keyCode === this . $mdConstant . KEY_CODE . SPACE ) ) {
173
174
event . preventDefault ( ) ;
174
175
this . goInEditMode ( ) ;
175
- } else if ( this . isEditting &&
176
+ } else if ( this . isEditing &&
176
177
event . keyCode === this . $mdConstant . KEY_CODE . ENTER ) {
177
178
event . preventDefault ( ) ;
178
179
this . goOutOfEditMode ( ) ;
@@ -181,12 +182,10 @@ MdChipCtrl.prototype.chipKeyDown = function(event) {
181
182
182
183
183
184
/**
184
- * Handles the double click event
185
+ * Enter edit mode if we're not already editing and the enable-chip-edit attribute is enabled.
185
186
*/
186
- MdChipCtrl . prototype . chipMouseDown = function ( ) {
187
- if ( this . getChipIndex ( ) == this . parentController . selectedChip &&
188
- this . enableChipEdit &&
189
- ! this . isEditting ) {
187
+ MdChipCtrl . prototype . chipMouseDoubleClick = function ( ) {
188
+ if ( this . enableChipEdit && ! this . isEditing ) {
190
189
this . goInEditMode ( ) ;
191
190
}
192
191
} ;
0 commit comments