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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 | 70 |
71 /** | 71 /** |
72 * Called right before the page is hidden. | 72 * Called right before the page is hidden. |
73 */ | 73 */ |
74 willHidePage: function() { | 74 willHidePage: function() { |
75 var wallpaperGrid = $('wallpaper-grid'); | 75 var wallpaperGrid = $('wallpaper-grid'); |
76 wallpaperGrid.blur(); | 76 wallpaperGrid.blur(); |
77 }, | 77 }, |
78 | 78 |
79 /** | 79 /** |
80 * Set attributions of wallpaper with given url. | |
81 * @param {string} url url of the selected wallpaper. | |
82 * @private | |
83 */ | |
84 setWallpaperAttribution_: function(url) { | |
85 for (var i = 0; i < this.wallpapers_.length; i++) { | |
86 if (this.wallpapers_[i].url == url) { | |
87 $('author-name').textContent = this.wallpapers_[i].author; | |
88 $('author-website').textContent = this.wallpapers_[i].website; | |
89 return; | |
90 } | |
91 } | |
92 $('author-name').textContent = ''; | |
93 $('author-website').textContent = ''; | |
94 }, | |
95 | |
96 /** | |
80 * Handles image selection change. | 97 * Handles image selection change. |
81 * @private | 98 * @private |
82 */ | 99 */ |
83 handleImageSelected_: function() { | 100 handleImageSelected_: function() { |
84 var wallpaperGrid = $('wallpaper-grid'); | 101 var wallpaperGrid = $('wallpaper-grid'); |
85 var index = wallpaperGrid.selectionModel.selectedIndex; | 102 var url = wallpaperGrid.selectedItemUrl; |
86 $('author-name').innerText = this.wallpapers_[index].author; | 103 if (url && |
87 $('author-website').innerText = this.wallpapers_[index].website; | |
88 | |
89 // Ignore deselection, selection change caused by program itself and | |
90 // selection of one of the action buttons. | |
91 if (index != -1 && | |
92 !wallpaperGrid.inProgramSelection) { | 104 !wallpaperGrid.inProgramSelection) { |
93 chrome.send('selectWallpaper', [index.toString()]); | 105 this.setWallpaperAttribution_(url); |
106 chrome.send('selectWallpaper', [url]); | |
94 } | 107 } |
95 }, | 108 }, |
96 | 109 |
97 /** | 110 /** |
98 * Handles double click on the image grid. | 111 * Handles double click on the image grid. |
99 * @param {Event} e Double click Event. | 112 * @param {Event} e Double click Event. |
100 */ | 113 */ |
101 handleImageDblClick_: function(e) { | 114 handleImageDblClick_: function(e) { |
102 // Close page unless the click target is the grid itself. | 115 // Close page unless the click target is the grid itself. |
103 if (e.target instanceof HTMLImageElement) | 116 if (e.target instanceof HTMLImageElement) |
104 OptionsPage.closeOverlay(); | 117 OptionsPage.closeOverlay(); |
105 }, | 118 }, |
106 | 119 |
107 /** | 120 /** |
108 * Selects user image with the given index. | 121 * Selects corresponding wallpaper thumbnail with the given url. |
flackr
2012/04/19 20:13:07
Here too
bshe
2012/04/19 21:05:25
Done.
| |
109 * @param {int} index index of the image to select. | 122 * @param {string} url URL of the wallpaper thumbnail to select. |
110 * @private | 123 * @private |
111 */ | 124 */ |
112 setSelectedImage_: function(index) { | 125 setSelectedImage_: function(url) { |
113 var wallpaperGrid = $('wallpaper-grid'); | 126 $('wallpaper-grid').selectedItemUrl = url; |
114 wallpaperGrid.selectedItemIndex = index; | 127 this.setWallpaperAttribution_(url); |
115 $('author-name').innerText = this.wallpapers_[index].author; | |
116 $('author-website').innerText = this.wallpapers_[index].website; | |
117 }, | 128 }, |
118 | 129 |
119 /** | 130 /** |
120 * Appends default images to the image grid. Should only be called once. | 131 * Appends default images to the image grid. Should only be called once. |
121 * @param {Array.<{author: string, url: string, website: string}>} | 132 * @param {Array.<{author: string, url: string, website: string}>} |
122 * wallpapers An array of wallpaper objects. | 133 * wallpapers An array of wallpaper objects. |
123 * @private | 134 * @private |
124 */ | 135 */ |
125 setDefaultImages_: function(wallpapers) { | 136 setDefaultImages_: function(wallpapers) { |
126 var wallpaperGrid = $('wallpaper-grid'); | 137 var wallpaperGrid = $('wallpaper-grid'); |
(...skipping 20 matching lines...) Expand all Loading... | |
147 }; | 158 }; |
148 }); | 159 }); |
149 | 160 |
150 // Export | 161 // Export |
151 return { | 162 return { |
152 SetWallpaperOptions: SetWallpaperOptions | 163 SetWallpaperOptions: SetWallpaperOptions |
153 }; | 164 }; |
154 | 165 |
155 }); | 166 }); |
156 | 167 |
OLD | NEW |