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

Side by Side Diff: chrome/browser/resources/options2/search_page.js

Issue 9316086: Fix JavaScript errors in options2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new violations found after rebase Created 8 years, 10 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 | « chrome/browser/resources/options2/search_engine_manager_engine_list.js ('k') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 OptionsPage = options.OptionsPage; 6 const OptionsPage = options.OptionsPage;
7 7
8 /** 8 /**
9 * Encapsulated handling of a search bubble. 9 * Encapsulated handling of a search bubble.
10 * @constructor 10 * @constructor
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // Update the position in the CSS. Cache the last values for 88 // Update the position in the CSS. Cache the last values for
89 // best performance. 89 // best performance.
90 if (left != this.lastLeft) { 90 if (left != this.lastLeft) {
91 this.style.left = left + 'px'; 91 this.style.left = left + 'px';
92 this.lastLeft = left; 92 this.lastLeft = left;
93 } 93 }
94 if (top != this.lastTop) { 94 if (top != this.lastTop) {
95 this.style.top = top + 'px'; 95 this.style.top = top + 'px';
96 this.lastTop = top; 96 this.lastTop = top;
97 } 97 }
98 } 98 },
99 } 99 };
100 100
101 /** 101 /**
102 * Encapsulated handling of the search page. 102 * Encapsulated handling of the search page.
103 * @constructor 103 * @constructor
104 */ 104 */
105 function SearchPage() { 105 function SearchPage() {
106 OptionsPage.call(this, 'search', templateData.searchPageTabTitle, 106 OptionsPage.call(this, 'search', templateData.searchPageTabTitle,
107 'searchPage'); 107 'searchPage');
108 } 108 }
109 109
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 controls = controls.concat(page.associatedControls); 387 controls = controls.concat(page.associatedControls);
388 } 388 }
389 return controls; 389 return controls;
390 }, 390 },
391 391
392 /** 392 /**
393 * Performs a string replacement based on a regex and replace string. 393 * Performs a string replacement based on a regex and replace string.
394 * @param {RegEx} regex A regular expression for finding search matches. 394 * @param {RegEx} regex A regular expression for finding search matches.
395 * @param {String} replace A string to apply the replace operation. 395 * @param {String} replace A string to apply the replace operation.
396 * @param {Element} element An HTML container element. 396 * @param {Element} element An HTML container element.
397 * @returns {Boolean} true if the element was changed. 397 * @return {boolean} true if the element was changed.
398 * @private 398 * @private
399 */ 399 */
400 performReplace_: function(regex, replace, element) { 400 performReplace_: function(regex, replace, element) {
401 var found = false; 401 var found = false;
402 var div, child, tmp; 402 var div, child, tmp;
403 403
404 // Walk the tree, searching each TEXT node. 404 // Walk the tree, searching each TEXT node.
405 var walker = document.createTreeWalker(element, 405 var walker = document.createTreeWalker(element,
406 NodeFilter.SHOW_TEXT, 406 NodeFilter.SHOW_TEXT,
407 null, 407 null,
(...skipping 10 matching lines...) Expand all
418 // Create a temporary div element and set the innerHTML to the new 418 // Create a temporary div element and set the innerHTML to the new
419 // value. 419 // value.
420 div = document.createElement('div'); 420 div = document.createElement('div');
421 div.innerHTML = newValue; 421 div.innerHTML = newValue;
422 422
423 // Insert all the child nodes of the temporary div element into the 423 // Insert all the child nodes of the temporary div element into the
424 // document, before the original node. 424 // document, before the original node.
425 child = div.firstChild; 425 child = div.firstChild;
426 while (child = div.firstChild) { 426 while (child = div.firstChild) {
427 node.parentNode.insertBefore(child, node); 427 node.parentNode.insertBefore(child, node);
428 }; 428 }
429 429
430 // Delete the old text node and advance the walker to the next 430 // Delete the old text node and advance the walker to the next
431 // node. 431 // node.
432 tmp = node; 432 tmp = node;
433 node = walker.nextNode(); 433 node = walker.nextNode();
434 tmp.parentNode.removeChild(tmp); 434 tmp.parentNode.removeChild(tmp);
435 } else { 435 } else {
436 node = walker.nextNode(); 436 node = walker.nextNode();
437 } 437 }
438 } 438 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 removeSearchBubbles_: function() { 489 removeSearchBubbles_: function() {
490 var elements = document.querySelectorAll('.search-bubble'); 490 var elements = document.querySelectorAll('.search-bubble');
491 var length = elements.length; 491 var length = elements.length;
492 for (var i = 0; i < length; i++) 492 for (var i = 0; i < length; i++)
493 elements[i].dispose(); 493 elements[i].dispose();
494 }, 494 },
495 495
496 /** 496 /**
497 * Builds a list of top-level pages to search. Omits the search page and 497 * Builds a list of top-level pages to search. Omits the search page and
498 * all sub-pages. 498 * all sub-pages.
499 * @returns {Array} An array of pages to search. 499 * @return {Array} An array of pages to search.
500 * @private 500 * @private
501 */ 501 */
502 getSearchablePages_: function() { 502 getSearchablePages_: function() {
503 var name, page, pages = []; 503 var name, page, pages = [];
504 for (name in OptionsPage.registeredPages) { 504 for (name in OptionsPage.registeredPages) {
505 if (name != this.name) { 505 if (name != this.name) {
506 page = OptionsPage.registeredPages[name]; 506 page = OptionsPage.registeredPages[name];
507 if (!page.parentPage) 507 if (!page.parentPage)
508 pages.push(page); 508 pages.push(page);
509 } 509 }
510 } 510 }
511 return pages; 511 return pages;
512 }, 512 },
513 513
514 /** 514 /**
515 * Builds a list of sub-pages (and overlay pages) to search. Ignore pages 515 * Builds a list of sub-pages (and overlay pages) to search. Ignore pages
516 * that have no associated controls. 516 * that have no associated controls.
517 * @returns {Array} An array of pages to search. 517 * @return {Array} An array of pages to search.
518 * @private 518 * @private
519 */ 519 */
520 getSearchableSubPages_: function() { 520 getSearchableSubPages_: function() {
521 var name, pageInfo, page, pages = []; 521 var name, pageInfo, page, pages = [];
522 for (name in OptionsPage.registeredPages) { 522 for (name in OptionsPage.registeredPages) {
523 page = OptionsPage.registeredPages[name]; 523 page = OptionsPage.registeredPages[name];
524 if (page.parentPage && page.associatedSection) 524 if (page.parentPage && page.associatedSection)
525 pages.push(page); 525 pages.push(page);
526 } 526 }
527 for (name in OptionsPage.registeredOverlayPages) { 527 for (name in OptionsPage.registeredOverlayPages) {
528 page = OptionsPage.registeredOverlayPages[name]; 528 page = OptionsPage.registeredOverlayPages[name];
529 if (page.associatedSection && page.pageDiv != undefined) 529 if (page.associatedSection && page.pageDiv != undefined)
530 pages.push(page); 530 pages.push(page);
531 } 531 }
532 return pages; 532 return pages;
533 }, 533 },
534 534
535 /** 535 /**
536 * A function to handle key press events. 536 * A function to handle key press events.
537 * @return {Event} a keydown event. 537 * @return {Event} a keydown event.
538 * @private 538 * @private
539 */ 539 */
540 keyDownEventHandler_: function(event) { 540 keyDownEventHandler_: function(event) {
541 const ESCAPE_KEY_CODE = 27; 541 const ESCAPE_KEY_CODE = 27;
542 const FORWARD_SLASH_KEY_CODE = 191; 542 const FORWARD_SLASH_KEY_CODE = 191;
543 543
544 switch(event.keyCode) { 544 switch (event.keyCode) {
545 case ESCAPE_KEY_CODE: 545 case ESCAPE_KEY_CODE:
546 if (event.target == this.searchField) { 546 if (event.target == this.searchField) {
547 this.setSearchText_(''); 547 this.setSearchText_('');
548 this.searchField.blur(); 548 this.searchField.blur();
549 event.stopPropagation(); 549 event.stopPropagation();
550 event.preventDefault(); 550 event.preventDefault();
551 } 551 }
552 break; 552 break;
553 case FORWARD_SLASH_KEY_CODE: 553 case FORWARD_SLASH_KEY_CODE:
554 if (!/INPUT|SELECT|BUTTON|TEXTAREA/.test(event.target.tagName) && 554 if (!/INPUT|SELECT|BUTTON|TEXTAREA/.test(event.target.tagName) &&
(...skipping 16 matching lines...) Expand all
571 // Trim beginning and ending whitespace. 571 // Trim beginning and ending whitespace.
572 return text.replace(/^\s+|\s+$/g, ''); 572 return text.replace(/^\s+|\s+$/g, '');
573 }; 573 };
574 574
575 // Export 575 // Export
576 return { 576 return {
577 SearchPage: SearchPage 577 SearchPage: SearchPage
578 }; 578 };
579 579
580 }); 580 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options2/search_engine_manager_engine_list.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698