Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: chrome/browser/resources/options/inline_editable_list.js

Issue 7565021: Options: Focus the placeholder input element if an item was added through the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 occur.
251 var self = this;
252 window.setTimeout(function() {
253 var list = self.parentNode;
254 if (list && list.focusPlaceholder) {
255 list.focusPlaceholder = false;
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.
256 * @private 271 * @private
257 */ 272 */
258 resetEditableValues_: function() { 273 resetEditableValues_: function() {
259 var editFields = this.editFields_; 274 var editFields = this.editFields_;
260 for (var i = 0; i < editFields.length; i++) { 275 for (var i = 0; i < editFields.length; i++) {
261 var staticLabel = editFields[i].staticVersion; 276 var staticLabel = editFields[i].staticVersion;
262 if (!staticLabel && !this.isPlaceholder) 277 if (!staticLabel && !this.isPlaceholder)
263 continue; 278 continue;
279
264 if (editFields[i].tagName == 'INPUT') { 280 if (editFields[i].tagName == 'INPUT') {
265 editFields[i].value = 281 editFields[i].value =
266 this.isPlaceholder ? '' : staticLabel.textContent; 282 this.isPlaceholder ? '' : staticLabel.textContent;
267 } 283 }
268 // Add more tag types here as new createEditable* methods are added. 284 // Add more tag types here as new createEditable* methods are added.
269 285
270 editFields[i].setCustomValidity(''); 286 editFields[i].setCustomValidity('');
271 } 287 }
272 }, 288 },
273 289
274 /** 290 /**
275 * Sets the static version of any controls created by createEditable* 291 * Sets the static version of any controls created by createEditable*
276 * to match the current value of the editable version. Called on commit so 292 * to match the current value of the editable version. Called on commit so
277 * that there's no flicker of the old value before the model updates. 293 * that there's no flicker of the old value before the model updates.
278 * @private 294 * @private
279 */ 295 */
280 updateStaticValues_: function() { 296 updateStaticValues_: function() {
281 var editFields = this.editFields_; 297 var editFields = this.editFields_;
282 for (var i = 0; i < editFields.length; i++) { 298 for (var i = 0; i < editFields.length; i++) {
283 var staticLabel = editFields[i].staticVersion; 299 var staticLabel = editFields[i].staticVersion;
284 if (!staticLabel) 300 if (!staticLabel)
285 continue; 301 continue;
302
286 if (editFields[i].tagName == 'INPUT') 303 if (editFields[i].tagName == 'INPUT')
287 staticLabel.textContent = editFields[i].value; 304 staticLabel.textContent = editFields[i].value;
288 // Add more tag types here as new createEditable* methods are added. 305 // Add more tag types here as new createEditable* methods are added.
289 } 306 }
290 }, 307 },
291 308
292 /** 309 /**
293 * Called a key is pressed. Handles committing and cancelling edits. 310 * Called a key is pressed. Handles committing and cancelling edits.
294 * @param {Event} e The key down event. 311 * @param {Event} e The key down event.
295 * @private 312 * @private
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 document.activeElement.blur(); 371 document.activeElement.blur();
355 }); 372 });
356 } 373 }
357 handleWindowBlurs(); 374 handleWindowBlurs();
358 375
359 var InlineEditableItemList = cr.ui.define('list'); 376 var InlineEditableItemList = cr.ui.define('list');
360 377
361 InlineEditableItemList.prototype = { 378 InlineEditableItemList.prototype = {
362 __proto__: DeletableItemList.prototype, 379 __proto__: DeletableItemList.prototype,
363 380
381 /**
382 * Focuses the input element of the placeholder if true.
383 * @type {boolean}
384 */
385 focusPlaceholder: false,
386
364 /** @inheritDoc */ 387 /** @inheritDoc */
365 decorate: function() { 388 decorate: function() {
366 DeletableItemList.prototype.decorate.call(this); 389 DeletableItemList.prototype.decorate.call(this);
367 this.setAttribute('inlineeditable', ''); 390 this.setAttribute('inlineeditable', '');
368 this.addEventListener('hasElementFocusChange', 391 this.addEventListener('hasElementFocusChange',
369 this.handleListFocusChange_); 392 this.handleListFocusChange_);
370 }, 393 },
371 394
372 /** 395 /**
373 * Called when the list hierarchy as a whole loses or gains focus; starts 396 * Called when the list hierarchy as a whole loses or gains focus; starts
(...skipping 11 matching lines...) Expand all
385 } 408 }
386 }, 409 },
387 }; 410 };
388 411
389 // Export 412 // Export
390 return { 413 return {
391 InlineEditableItem: InlineEditableItem, 414 InlineEditableItem: InlineEditableItem,
392 InlineEditableItemList: InlineEditableItemList, 415 InlineEditableItemList: InlineEditableItemList,
393 }; 416 };
394 }); 417 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698