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

Side by Side Diff: chrome/browser/resources/sessions.js

Issue 10010019: JS style nits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2011 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
Dan Beam 2012/04/05 22:24:13 should probably be a cr.define('session', funct
5 localStrings = new LocalStrings(); 5 localStrings = new LocalStrings();
Dan Beam 2012/04/05 22:24:13 seems like these are all global assignments, :\
6 6
7 // UTF8 sequence for an arrow triangle pointing down. 7 // UTF8 sequence for an arrow triangle pointing down.
8 kExpandedArrow = "\u25BE"; 8 kExpandedArrow = '\u25BE';
Dan Beam 2012/04/05 22:24:13 I don't see a reason to have these like this inste
Tyler Breisacher (Chromium) 2012/04/05 22:39:13 I would guess it's because someday, someone will o
9 // UTF8 sequence for an arrow triangle pointing right. 9 // UTF8 sequence for an arrow triangle pointing right.
10 kCollapsedArrow = "\u25B8"; 10 kCollapsedArrow = '\u25B8';
11 11
12 /** 12 /**
13 * Requests the list of sessions from the backend. 13 * Requests the list of sessions from the backend.
14 */ 14 */
15 function requestSessions() { 15 function requestSessions() {
16 chrome.send('requestSessionList', []) 16 chrome.send('requestSessionList');
17 } 17 }
18 18
19 /** 19 /**
20 * Expands or collapses the specified list. 20 * Expands or collapses the specified list.
21 */ 21 */
22 function toggleExpandedState(div) { 22 function toggleExpandedState(div) {
23 if (div.textContent.indexOf(kExpandedArrow) != -1) { 23 if (div.textContent.indexOf(kExpandedArrow) != -1) {
24 div.textContent = div.textContent.replace(kExpandedArrow, kCollapsedArrow); 24 div.textContent = div.textContent.replace(kExpandedArrow, kCollapsedArrow);
25 div.parentNode.querySelector(".indent").hidden = true; 25 div.parentNode.querySelector('.indent').hidden = true;
26 } else { 26 } else {
27 div.textContent = div.textContent.replace(kCollapsedArrow, kExpandedArrow); 27 div.textContent = div.textContent.replace(kCollapsedArrow, kExpandedArrow);
28 div.parentNode.querySelector(".indent").hidden = false; 28 div.parentNode.querySelector('.indent').hidden = false;
29 } 29 }
30 } 30 }
31 31
32 /** 32 /**
33 * Creates a div element to serve as an expandable/collapsable 33 * Creates a div element to serve as an expandable/collapsable
34 * title for a list of windows or tabs. 34 * title for a list of windows or tabs.
Dan Beam 2012/04/05 22:24:13 no @returns
35 */ 35 */
36 function createTitleDiv(className, textContent) { 36 function createTitleDiv(className, textContent) {
37 var div = document.createElement('div'); 37 var div = document.createElement('div');
38 div.className = className + ' expandable'; 38 div.className = className + ' expandable';
39 div.textContent = kExpandedArrow + ' ' + textContent; 39 div.textContent = kExpandedArrow + ' ' + textContent;
40 div.onclick = Function('toggleExpandedState(this)'); 40 div.onclick = Function('toggleExpandedState(this)');
Dan Beam 2012/04/05 22:24:13 wat!
Tyler Breisacher (Chromium) 2012/04/05 22:39:13 Yeah, it should obviously be div.onclick = new
41 return div; 41 return div;
42 } 42 }
43 43
44 /** 44 /**
45 * Utility function to call |transformFn| on each element of |from| 45 * Utility function to call |transformFn| on each element of |from|
46 * and add them to a div which is then added to |container|. 46 * and add them to a div which is then added to |container|.
47 */ 47 */
48 function addItems(container, from, transformFn) { 48 function addItems(container, from, transformFn) {
49 var divBlock = document.createElement('div'); 49 var divBlock = document.createElement('div');
50 divBlock.className = 'indent'; 50 divBlock.className = 'indent';
51 for (var i = 0; i < from.length; i++) { 51 for (var i = 0; i < from.length; i++) {
52 divBlock.appendChild(transformFn(from[i])); 52 divBlock.appendChild(transformFn(from[i]));
53 } 53 }
54 container.appendChild(divBlock); 54 container.appendChild(divBlock);
55 } 55 }
56 56
57 /** 57 /**
58 * Transforms a tab into an HTML element. 58 * Transforms a tab into an HTML element.
Dan Beam 2012/04/05 22:24:13 no @returns
59 */ 59 */
60 function transformTab(tab) { 60 function transformTab(tab) {
61 var tabItem = document.createElement('a'); 61 var tabItem = document.createElement('a');
62 tabItem.setAttribute('href', tab.url); 62 tabItem.setAttribute('href', tab.url);
63 tabItem.textContent = tab.title; 63 tabItem.textContent = tab.title;
64 tabItem.className = 'tab-link'; 64 tabItem.className = 'tab-link';
65 tabItem.style.backgroundImage = url('chrome://favicon/' + tab.url); 65 tabItem.style.backgroundImage = url('chrome://favicon/' + tab.url);
Dan Beam 2012/04/05 22:24:13 was really confused until I figured out url() is a
66 return tabItem; 66 return tabItem;
67 } 67 }
68 68
69 /** 69 /**
70 * Transforms a window into an HTML element. 70 * Transforms a window into an HTML element.
Dan Beam 2012/04/05 22:24:13 no @returns
71 */ 71 */
72 function transformWindow(window) { 72 function transformWindow(window) {
73 var windowDiv = document.createElement('div'); 73 var windowDiv = document.createElement('div');
74 windowDiv.className = "window"; 74 windowDiv.className = 'window';
75 windowDiv.appendChild(createTitleDiv('window-title', 'Window')); 75 windowDiv.appendChild(createTitleDiv('window-title', 'Window'));
76 addItems(windowDiv, window.tabs, transformTab); 76 addItems(windowDiv, window.tabs, transformTab);
77 return windowDiv; 77 return windowDiv;
78 } 78 }
79 79
80 /** 80 /**
81 * Transforms a session into an HTML element. 81 * Transforms a session into an HTML element.
Dan Beam 2012/04/05 22:24:13 no @returns
82 */ 82 */
83 function transformSession(session) { 83 function transformSession(session) {
84 var sessionDiv = document.createElement('div'); 84 var sessionDiv = document.createElement('div');
85 var sessionName = session.name.length == 0 ? 'Session' : session.name; 85 var sessionName = session.name.length == 0 ? 'Session' : session.name;
86 sessionDiv.className = "session"; 86 sessionDiv.className = 'session';
87 sessionDiv.appendChild(createTitleDiv('session-title', sessionName)); 87 sessionDiv.appendChild(createTitleDiv('session-title', sessionName));
88 addItems(sessionDiv, session.windows, transformWindow); 88 addItems(sessionDiv, session.windows, transformWindow);
89 return sessionDiv; 89 return sessionDiv;
90 } 90 }
91 91
92 /** 92 /**
93 * Creates the UI for the sessions tree. 93 * Creates the UI for the sessions tree.
94 */ 94 */
95 function createSessionTreeUI(sessionList) { 95 function createSessionTreeUI(sessionList) {
96 $('sessions-summary-text').textContent = 96 $('sessions-summary-text').textContent =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 * Callback from backend with the list of sessions. Builds the UI. 131 * Callback from backend with the list of sessions. Builds the UI.
132 * @param {array} sessionList The list of sessions. 132 * @param {array} sessionList The list of sessions.
133 * @param {array} magicList List of "interesting" tabs. 133 * @param {array} magicList List of "interesting" tabs.
134 */ 134 */
135 function updateSessionList(sessionList, magicList) { 135 function updateSessionList(sessionList, magicList) {
136 createSessionTreeUI(sessionList); 136 createSessionTreeUI(sessionList);
137 createMagicListUI(magicList); 137 createMagicListUI(magicList);
138 } 138 }
139 139
140 document.addEventListener('DOMContentLoaded', requestSessions); 140 document.addEventListener('DOMContentLoaded', requestSessions);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698