Skip to content

Commit f37103a

Browse files
committed
Added visual effects to the sidebar.
1 parent e8ff90b commit f37103a

File tree

5 files changed

+50
-16
lines changed

5 files changed

+50
-16
lines changed

src/ui/sidebar/sidebar.gss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
min-width: 60px;
2525
}
2626

27+
.{$prefix}sidebar-icon.active {
28+
border-right: 2px solid red;
29+
background: rgba(64,64,64,0.1);
30+
}
31+
32+
.{$prefix}sidebar-icon.active > .mdl-button {
33+
opacity: 1;
34+
}
35+
2736
#{$prefix}sidebar-icons {
2837
width: 60px;
2938
float: left;
@@ -32,6 +41,7 @@
3241
}
3342

3443
#{$prefix}sidebar-icons .mdl-button {
44+
opacity: 0.8;
3545
box-shadow:
3646
0 3px 5px -1px rgba(0, 0, 0, 0.2),
3747
0 6px 10px 0 rgba(0, 0, 0, 0.14),

src/ui/sidebar/sidebar.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ cwc.ui.Sidebar.prototype.decorate = function(node) {
8989

9090
this.events_.listen('speaker_notes-button', goog.events.EventType.CLICK,
9191
(e) => {
92+
this.setActive_(e.target);
9293
this.showContent('Description',
9394
this.helper.getInstance('file').getFileDescription());
94-
this.log_.info('button', e.target.closest('.mdl-button'));
9595
});
9696
};
9797

@@ -126,7 +126,7 @@ cwc.ui.Sidebar.prototype.addCustomButton = function(id, icon, tooltip = '',
126126

127127
if (func) {
128128
this.events_.listen(button, goog.events.EventType.CLICK, function() {
129-
this.log_.info('Trigger custom action ...');
129+
this.setActive_(button);
130130
func();
131131
}.bind(this));
132132
}
@@ -152,13 +152,12 @@ cwc.ui.Sidebar.prototype.renderContent = function(title, template, values) {
152152
* @param {!string} content
153153
*/
154154
cwc.ui.Sidebar.prototype.showContent = function(title, content) {
155-
this.showContent_(false);
156155
if (this.contentName === title) {
156+
this.showContent_(false);
157157
this.contentName = '';
158158
return;
159159
}
160160

161-
this.showContent_(false);
162161
goog.soy.renderElement(
163162
this.nodeContent,
164163
cwc.soy.ui.Sidebar.content, {
@@ -191,6 +190,9 @@ cwc.ui.Sidebar.prototype.clear = function() {
191190
* @private
192191
*/
193192
cwc.ui.Sidebar.prototype.showContent_ = function(visible) {
193+
if (!visible) {
194+
this.clearActive_();
195+
}
194196
goog.style.setElementShown(this.nodeContent, visible);
195197
this.helper.getInstance('layout').adjustSize();
196198
};
@@ -205,3 +207,27 @@ cwc.ui.Sidebar.prototype.clearCustomButtons_ = function() {
205207
}
206208
this.customButtonIds = [];
207209
};
210+
211+
212+
/**
213+
* @param {Element} button
214+
* @private
215+
*/
216+
cwc.ui.Sidebar.prototype.setActive_ = function(button) {
217+
this.clearActive_();
218+
goog.dom.classlist.enable(
219+
button.closest('.' + this.prefix + 'icon'), 'active', true);
220+
};
221+
222+
223+
/**
224+
* @private
225+
*/
226+
cwc.ui.Sidebar.prototype.clearActive_ = function() {
227+
let elements = cwc.ui.Helper.getElements(this.prefix + 'icon');
228+
if (elements) {
229+
elements.forEach((elem) => {
230+
goog.dom.classlist.enable(elem, 'active', false);
231+
});
232+
}
233+
};

src/ui/sidebar/sidebar.soy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
{@param icon: string}
7575
{@param? tooltip: string}
7676

77-
<div id="{$prefix}{$id}">
77+
<div id="{$prefix}{$id}" class="{$prefix}icon">
7878
<button id="{$prefix}{$id}-button" class="mdl-button mdl-js-button mdl-button--icon">
7979
<i class="material-icons">{$icon}</i>
8080
</button>

src/utils/storage.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,9 @@ cwc.utils.Storage = function(storageType = cwc.utils.StorageType.NONE) {
118118
this.storage_ = this.getStorageByType(this.storageType_);
119119

120120
/** @private {!boolean} */
121-
this.syncChrome_ = this.storageType_ == cwc.utils.StorageType.CHROME_STORAGE ?
122-
true : false;
121+
this.syncChrome_ = this.storageType_ === cwc.utils.StorageType.CHROME_STORAGE;
123122

124-
// Preload Chrome Storage, if needed.
123+
// Pre-load Chrome Storage, if needed.
125124
if (this.syncChrome_ && !this.chromeStorageLoaded_) {
126125
this.loadChromeStorage();
127126
}
@@ -135,8 +134,7 @@ cwc.utils.Storage = function(storageType = cwc.utils.StorageType.NONE) {
135134
cwc.utils.Storage.prototype.prepare = function(callback) {
136135
this.log_.info('Preparing', this.storageType_, 'storage ...');
137136
if (callback) {
138-
if (this.storageType_ === cwc.utils.StorageType.CHROME_STORAGE &&
139-
!this.chromeStorageLoaded_) {
137+
if (this.syncChrome_ && !this.chromeStorageLoaded_) {
140138
this.loadChromeStorage(undefined, callback);
141139
} else {
142140
callback(this);
@@ -189,13 +187,13 @@ cwc.utils.Storage.prototype.getStorageByType = function(type) {
189187
* @param {Function=} callbackFunc
190188
*/
191189
cwc.utils.Storage.prototype.loadChromeStorage = function(type, callbackFunc) {
192-
this.log_.info('Loading Chrome storage ...');
193190
let storageKey = type ? this.getKeyname('', type) : null;
194-
let callback = function(data) {
191+
this.log_.info('Loading Chrome storage', storageKey || '');
192+
chrome.storage.local.get(storageKey, function(data) {
193+
this.log_.info('Loaded', data, 'data.');
195194
this.handleLoadChromeStorage_(data, storageKey, callbackFunc);
196195
this.chromeStorageLoaded_ = true;
197-
};
198-
chrome.storage.local.get(storageKey, callback.bind(this));
196+
}.bind(this));
199197
};
200198

201199

@@ -213,7 +211,7 @@ cwc.utils.Storage.prototype.handleLoadChromeStorage_ = function(data,
213211
if ((storageKey && key == storageKey) ||
214212
(!storageKey && key.startsWith(this.prefix_))) {
215213
if (goog.isObject(data[key])) {
216-
this.log_.info('Syncing', data[key].length, key,
214+
this.log_.info('Syncing', data[key].length || '', key,
217215
'items to session storage.');
218216
for (let item in data[key]) {
219217
if (Object.prototype.hasOwnProperty.call(data[key], item)) {

static_files/resources/tutorial/simple/blocks/tutorial-1.cwc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"version": 1
1717
}
1818
},
19-
"description": "",
19+
"description": "Basic tutorial example with and sidebar.",
2020
"files": {},
2121
"flags": {},
2222
"format": "Coding with Chrome File Format 2",

0 commit comments

Comments
 (0)