Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 const DeletableItem = options.DeletableItem; | 6 const DeletableItem = options.DeletableItem; |
| 7 const DeletableItemList = options.DeletableItemList; | 7 const DeletableItemList = options.DeletableItemList; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Creates a new list item with support for inline editing. | 10 * Creates a new list item with support for inline editing. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 // Make sure we are still in edit mode by the time we execute. | 144 // Make sure we are still in edit mode by the time we execute. |
| 145 if (self.editing) { | 145 if (self.editing) { |
| 146 focusElement.focus(); | 146 focusElement.focus(); |
| 147 focusElement.select(); | 147 focusElement.select(); |
| 148 } | 148 } |
| 149 }, 50); | 149 }, 50); |
| 150 } | 150 } |
| 151 } else { | 151 } else { |
| 152 if (!this.editCancelled_ && this.hasBeenEdited && | 152 if (!this.editCancelled_ && this.hasBeenEdited && |
| 153 this.currentInputIsValid) { | 153 this.currentInputIsValid) { |
| 154 if (this.isPlaceholder) | |
| 155 this.parentNode.focusPlaceholder = true; | |
| 156 | |
| 154 this.updateStaticValues_(); | 157 this.updateStaticValues_(); |
| 155 cr.dispatchSimpleEvent(this, 'commitedit', true); | 158 cr.dispatchSimpleEvent(this, 'commitedit', true); |
| 156 } else { | 159 } else { |
| 157 this.resetEditableValues_(); | 160 this.resetEditableValues_(); |
| 158 cr.dispatchSimpleEvent(this, 'canceledit', true); | 161 cr.dispatchSimpleEvent(this, 'canceledit', true); |
| 159 } | 162 } |
| 160 } | 163 } |
| 161 }, | 164 }, |
| 162 | 165 |
| 163 /** | 166 /** |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 textEl.setAttribute('displaymode', 'static'); | 238 textEl.setAttribute('displaymode', 'static'); |
| 236 container.appendChild(textEl); | 239 container.appendChild(textEl); |
| 237 } | 240 } |
| 238 | 241 |
| 239 var inputEl = this.ownerDocument.createElement('input'); | 242 var inputEl = this.ownerDocument.createElement('input'); |
| 240 inputEl.type = 'text'; | 243 inputEl.type = 'text'; |
| 241 inputEl.value = text; | 244 inputEl.value = text; |
| 242 if (!this.isPlaceholder) { | 245 if (!this.isPlaceholder) { |
| 243 inputEl.setAttribute('displaymode', 'edit'); | 246 inputEl.setAttribute('displaymode', 'edit'); |
| 244 inputEl.staticVersion = textEl; | 247 inputEl.staticVersion = textEl; |
| 248 } else { | |
| 249 // At this point |this| is not attached to the parent list yet, so give | |
| 250 // a short timeout in order for the attachment to occurr. | |
|
csilv
2011/08/04 00:14:35
typo: "occur"
James Hawkins
2011/08/04 01:06:05
Done.
| |
| 251 var self = this; | |
| 252 window.setTimeout(function() { | |
| 253 var list = self.parentNode; | |
| 254 if (list && list.focusPlaceholder) { | |
| 255 self.parentNode.focusPlaceholder = false; | |
|
csilv
2011/08/04 00:14:35
could this be simplified as:
list.focusPlacehold
James Hawkins
2011/08/04 01:06:05
Done.
| |
| 256 inputEl.focus(); | |
| 257 } | |
| 258 }, 50); | |
| 245 } | 259 } |
| 260 | |
| 246 inputEl.addEventListener('focus', this.handleFocus_.bind(this)); | 261 inputEl.addEventListener('focus', this.handleFocus_.bind(this)); |
| 247 container.appendChild(inputEl); | 262 container.appendChild(inputEl); |
| 248 this.editFields_.push(inputEl); | 263 this.editFields_.push(inputEl); |
| 249 | 264 |
| 250 return container; | 265 return container; |
| 251 }, | 266 }, |
| 252 | 267 |
| 253 /** | 268 /** |
| 254 * Resets the editable version of any controls created by createEditable* | 269 * Resets the editable version of any controls created by createEditable* |
| 255 * to match the static text. | 270 * to match the static text. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 document.activeElement.blur(); | 369 document.activeElement.blur(); |
| 355 }); | 370 }); |
| 356 } | 371 } |
| 357 handleWindowBlurs(); | 372 handleWindowBlurs(); |
| 358 | 373 |
| 359 var InlineEditableItemList = cr.ui.define('list'); | 374 var InlineEditableItemList = cr.ui.define('list'); |
| 360 | 375 |
| 361 InlineEditableItemList.prototype = { | 376 InlineEditableItemList.prototype = { |
| 362 __proto__: DeletableItemList.prototype, | 377 __proto__: DeletableItemList.prototype, |
| 363 | 378 |
| 379 /** | |
| 380 * Focuses the input element of the placeholder if true. | |
| 381 * @type {boolean} | |
| 382 */ | |
| 383 focusPlaceholder: false, | |
| 384 | |
| 364 /** @inheritDoc */ | 385 /** @inheritDoc */ |
| 365 decorate: function() { | 386 decorate: function() { |
| 366 DeletableItemList.prototype.decorate.call(this); | 387 DeletableItemList.prototype.decorate.call(this); |
| 367 this.setAttribute('inlineeditable', ''); | 388 this.setAttribute('inlineeditable', ''); |
| 368 this.addEventListener('hasElementFocusChange', | 389 this.addEventListener('hasElementFocusChange', |
| 369 this.handleListFocusChange_); | 390 this.handleListFocusChange_); |
| 370 }, | 391 }, |
| 371 | 392 |
| 372 /** | 393 /** |
| 373 * Called when the list hierarchy as a whole loses or gains focus; starts | 394 * Called when the list hierarchy as a whole loses or gains focus; starts |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 385 } | 406 } |
| 386 }, | 407 }, |
| 387 }; | 408 }; |
| 388 | 409 |
| 389 // Export | 410 // Export |
| 390 return { | 411 return { |
| 391 InlineEditableItem: InlineEditableItem, | 412 InlineEditableItem: InlineEditableItem, |
| 392 InlineEditableItemList: InlineEditableItemList, | 413 InlineEditableItemList: InlineEditableItemList, |
| 393 }; | 414 }; |
| 394 }); | 415 }); |
| OLD | NEW |