OLD | NEW |
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 | 6 |
7 var OptionsPage = options.OptionsPage; | 7 var OptionsPage = options.OptionsPage; |
8 var UserImagesGrid = options.UserImagesGrid; | 8 var UserImagesGrid = options.UserImagesGrid; |
9 | 9 |
10 ///////////////////////////////////////////////////////////////////////////// | 10 ///////////////////////////////////////////////////////////////////////////// |
(...skipping 27 matching lines...) Expand all Loading... |
38 var wallpaperGrid = $('wallpaper-grid'); | 38 var wallpaperGrid = $('wallpaper-grid'); |
39 UserImagesGrid.decorate(wallpaperGrid); | 39 UserImagesGrid.decorate(wallpaperGrid); |
40 | 40 |
41 wallpaperGrid.addEventListener('change', | 41 wallpaperGrid.addEventListener('change', |
42 this.handleImageSelected_.bind(this)); | 42 this.handleImageSelected_.bind(this)); |
43 wallpaperGrid.addEventListener('dblclick', | 43 wallpaperGrid.addEventListener('dblclick', |
44 this.handleImageDblClick_.bind(this)); | 44 this.handleImageDblClick_.bind(this)); |
45 wallpaperGrid.addEventListener('activate', | 45 wallpaperGrid.addEventListener('activate', |
46 function() { OptionsPage.closeOverlay() }); | 46 function() { OptionsPage.closeOverlay() }); |
47 | 47 |
| 48 $('use-random-wallpaper').onclick = this.handleCheckboxClick_.bind(this); |
48 $('set-wallpaper-overlay-confirm').onclick = function() { | 49 $('set-wallpaper-overlay-confirm').onclick = function() { |
49 OptionsPage.closeOverlay(); | 50 OptionsPage.closeOverlay(); |
50 }; | 51 }; |
51 | 52 |
52 // @type {Array.<author: string, url: string, website: string>} | 53 // @type {Array.<author: string, url: string, website: string>} |
53 this.wallpapers_ = []; | 54 this.wallpapers_ = []; |
54 | 55 |
55 chrome.send('onSetWallpaperPageInitialized'); | 56 chrome.send('onSetWallpaperPageInitialized'); |
56 }, | 57 }, |
57 | 58 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 /** | 97 /** |
97 * Handles image selection change. | 98 * Handles image selection change. |
98 * @private | 99 * @private |
99 */ | 100 */ |
100 handleImageSelected_: function() { | 101 handleImageSelected_: function() { |
101 var wallpaperGrid = $('wallpaper-grid'); | 102 var wallpaperGrid = $('wallpaper-grid'); |
102 var url = wallpaperGrid.selectedItemUrl; | 103 var url = wallpaperGrid.selectedItemUrl; |
103 if (url && | 104 if (url && |
104 !wallpaperGrid.inProgramSelection) { | 105 !wallpaperGrid.inProgramSelection) { |
105 this.setWallpaperAttribution_(url); | 106 this.setWallpaperAttribution_(url); |
106 chrome.send('selectWallpaper', [url]); | 107 chrome.send('selectDefaultWallpaper', [url]); |
107 } | 108 } |
108 }, | 109 }, |
109 | 110 |
110 /** | 111 /** |
111 * Handles double click on the image grid. | 112 * Handles double click on the image grid. |
112 * @param {Event} e Double click Event. | 113 * @param {Event} e Double click Event. |
113 */ | 114 */ |
114 handleImageDblClick_: function(e) { | 115 handleImageDblClick_: function(e) { |
| 116 var wallpaperGrid = $('wallpaper-grid'); |
| 117 if (wallpaperGrid.disabled) |
| 118 return; |
115 // Close page unless the click target is the grid itself. | 119 // Close page unless the click target is the grid itself. |
116 if (e.target instanceof HTMLImageElement) | 120 if (e.target instanceof HTMLImageElement) |
117 OptionsPage.closeOverlay(); | 121 OptionsPage.closeOverlay(); |
118 }, | 122 }, |
119 | 123 |
120 /** | 124 /** |
121 * Selects corresponding wallpaper thumbnail with the given URL. | 125 * Handles click on the "I'm feeling lucky" checkbox. |
122 * @param {string} url URL of the wallpaper thumbnail to select. | |
123 * @private | 126 * @private |
124 */ | 127 */ |
125 setSelectedImage_: function(url) { | 128 handleCheckboxClick_: function() { |
126 $('wallpaper-grid').selectedItemUrl = url; | 129 var wallpaperGrid = $('wallpaper-grid'); |
127 this.setWallpaperAttribution_(url); | 130 if ($('use-random-wallpaper').checked) { |
| 131 wallpaperGrid.disabled = true; |
| 132 chrome.send('selectRandomWallpaper'); |
| 133 wallpaperGrid.classList.add('grayout'); |
| 134 } else { |
| 135 wallpaperGrid.disabled = false; |
| 136 wallpaperGrid.classList.remove('grayout'); |
| 137 // Set the wallpaper type to User::DEFAULT. |
| 138 this.handleImageSelected_(); |
| 139 } |
128 }, | 140 }, |
129 | 141 |
130 /** | 142 /** |
| 143 * Selects corresponding wallpaper thumbnail with the given URL and toggle |
| 144 * the "I'm feeling lucky" checkbox. |
| 145 * @param {string} url URL of the wallpaper thumbnail to select. |
| 146 * @param {boolean} isRandom True if user checked "I'm feeling lucky" |
| 147 * checkbox. |
| 148 * @private |
| 149 */ |
| 150 setSelectedImage_: function(url, isRandom) { |
| 151 var wallpaperGrid = $('wallpaper-grid'); |
| 152 wallpaperGrid.selectedItemUrl = url; |
| 153 this.setWallpaperAttribution_(url); |
| 154 if (isRandom) { |
| 155 // Do not call chrome.send('selectRandomWallpaper'), it is not |
| 156 // neccessary to generate a new random index here. |
| 157 $('use-random-wallpaper').checked = true; |
| 158 wallpaperGrid.disabled = true; |
| 159 wallpaperGrid.classList.add('grayout'); |
| 160 } |
| 161 }, |
| 162 |
| 163 /** |
131 * Appends default images to the image grid. Should only be called once. | 164 * Appends default images to the image grid. Should only be called once. |
132 * @param {Array.<{author: string, url: string, website: string}>} | 165 * @param {Array.<{author: string, url: string, website: string}>} |
133 * wallpapers An array of wallpaper objects. | 166 * wallpapers An array of wallpaper objects. |
134 * @private | 167 * @private |
135 */ | 168 */ |
136 setDefaultImages_: function(wallpapers) { | 169 setDefaultImages_: function(wallpapers) { |
137 var wallpaperGrid = $('wallpaper-grid'); | 170 var wallpaperGrid = $('wallpaper-grid'); |
138 // TODO(bshe): Ideally we should save author and website with the actual | 171 // TODO(bshe): Ideally we should save author and website with the actual |
139 // image (URL) and not use index related storage. This way this data is | 172 // image (URL) and not use index related storage. This way this data is |
140 // stored in one place rather than depending on the index to be | 173 // stored in one place rather than depending on the index to be |
(...skipping 17 matching lines...) Expand all Loading... |
158 }; | 191 }; |
159 }); | 192 }); |
160 | 193 |
161 // Export | 194 // Export |
162 return { | 195 return { |
163 SetWallpaperOptions: SetWallpaperOptions | 196 SetWallpaperOptions: SetWallpaperOptions |
164 }; | 197 }; |
165 | 198 |
166 }); | 199 }); |
167 | 200 |
OLD | NEW |