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

Side by Side Diff: chrome/browser/resources/print_preview/settings/media_size_settings.js

Issue 447963005: Get printer's paper size custom_display_name_localized property into account. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Encapsulates all settings and logic related to the media size selection UI. 9 * Encapsulates all settings and logic related to the media size selection UI.
10 * @param {!print_preview.ticket_items.MediaSize} ticketItem Used to read and 10 * @param {!print_preview.ticket_items.MediaSize} ticketItem Used to read and
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 this.ticketItem_.capability.option.length == select.length && 63 this.ticketItem_.capability.option.length == select.length &&
64 this.ticketItem_.capability.option.every(function(option, index) { 64 this.ticketItem_.capability.option.every(function(option, index) {
65 return select.options[index].value == JSON.stringify(option); 65 return select.options[index].value == JSON.stringify(option);
66 }); 66 });
67 var indexToSelect = select.selectedIndex; 67 var indexToSelect = select.selectedIndex;
68 if (!sameContent) { 68 if (!sameContent) {
69 select.innerHTML = ''; 69 select.innerHTML = '';
70 // TODO: Better heuristics for the display name and options grouping. 70 // TODO: Better heuristics for the display name and options grouping.
71 this.ticketItem_.capability.option.forEach(function(option, index) { 71 this.ticketItem_.capability.option.forEach(function(option, index) {
72 var selectOption = document.createElement('option'); 72 var selectOption = document.createElement('option');
73 selectOption.text = option.custom_display_name || option.name; 73 var displayName = option.custom_display_name;
74 if (!displayName && option.custom_display_name_localized) {
75 var getLocaleToCompare = function(locale, languageOnly) {
Vitaly Buka (NO REVIEWS) 2014/08/07 23:05:52 why not to put this function inside the next one?
Aleksey Shlyapnikov 2014/08/08 00:25:49 Less nesting, easier to read.
76 var code = languageOnly ? locale.split('-')[0] : locale;
77 return code.toLowerCase();
78 };
79 var getItemForLocale = function(items, locale, languageOnly) {
80 locale = getLocaleToCompare(locale, languageOnly);
81 for (var i = 0; i < items.length; i++) {
82 if (getLocaleToCompare(items[i].locale) == locale)
Vitaly Buka (NO REVIEWS) 2014/08/07 23:05:53 forEach
Aleksey Shlyapnikov 2014/08/08 00:25:49 Nope, it won't work here. I need to stop and retur
83 return items[i].value;
84 }
85 return '';
86 };
87 var items = option.custom_display_name_localized;
88 displayName =
89 getItemForLocale(items, navigator.language, false) ||
90 getItemForLocale(items, navigator.language, true);
91 }
92 selectOption.text = displayName || option.name;
74 selectOption.value = JSON.stringify(option); 93 selectOption.value = JSON.stringify(option);
75 select.add(selectOption); 94 select.add(selectOption);
76 if (option.is_default) { 95 if (option.is_default) {
77 indexToSelect = index; 96 indexToSelect = index;
78 } 97 }
79 }); 98 });
80 } 99 }
81 // Try to select current ticket item. 100 // Try to select current ticket item.
82 var valueToSelect = JSON.stringify(this.ticketItem_.getValue()); 101 var valueToSelect = JSON.stringify(this.ticketItem_.getValue());
83 for (var i = 0, option; option = select.options[i]; i++) { 102 for (var i = 0, option; option = select.options[i]; i++) {
(...skipping 29 matching lines...) Expand all
113 fadeOutOption(this.getElement()); 132 fadeOutOption(this.getElement());
114 } 133 }
115 } 134 }
116 }; 135 };
117 136
118 // Export 137 // Export
119 return { 138 return {
120 MediaSizeSettings: MediaSizeSettings 139 MediaSizeSettings: MediaSizeSettings
121 }; 140 };
122 }); 141 });
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