Skip to content

Commit 0fc006c

Browse files
author
pipeline
committed
EJ2 3584 Master Theme Switcher
1 parent f22605f commit 0fc006c

File tree

8 files changed

+139
-11
lines changed

8 files changed

+139
-11
lines changed

index.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<link rel="shortcut icon" href="favicon.ico" />
1111
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
1212
<link href="src/common/lib/highlightjs/styles/default.css" rel="stylesheet" />
13-
<link href="styles/material.css" rel="stylesheet" />
13+
<link href="styles/material.css" rel="stylesheet" id="themelink" />
1414
<link href="styles/index.css" rel="stylesheet" />
1515
<script src="src/common.min.js" type="text/javascript"></script>
1616
</head>
@@ -28,7 +28,16 @@
2828
<div class="sb-logo" title="Essential JS 2 (Preview)"></div>
2929
</a>
3030
</div>
31-
<div class="header-right"></div>
31+
<div class="header-right">
32+
<div id="themeswitcher" class="themeicon"><img id="themeswitcher-icon" src='styles/images/sb_icons/SB_Switcher_icon_material.png'></div>
33+
<div id="selectdiv" class='e-hidden'>
34+
<ul id="themelist" class="options">
35+
<li class="e-list" id="material"><span class='switch-text'>Material</span><span class='switch-icon material'></span></a></li>
36+
<li class="e-list" id="fabric"><span class='switch-text'>Fabric</span><span class='switch-icon fabric'></span></a></li>
37+
</ul>
38+
39+
</div>
40+
</div>
3241
</div>
3342
<div class="sb-content" role="main">
3443
<div id="left-panel" class="left-panel">

spec/samplebrowser.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('sample browser', (): void => {
5151
expect(window.customError).not.toHaveBeenCalled();
5252
done();
5353
};
54-
window.location.href = '#' + control.directory + '/' + element.url + '.html';
54+
window.location.href = '#/material/' + control.directory + '/' + element.url + '.html';
5555
});
5656
});
5757
}

src/common/index.ts

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* default script manupulation for sample browser
44
*/
55
import '../../node_modules/es6-promise/dist/es6-promise';
6-
import { Ajax, Browser, extend, detach, select, addClass, isVisible, createElement, selectAll } from '@syncfusion/ej2-base';
6+
import { Ajax, Browser, enableRipple, extend, detach, select, addClass, isVisible, createElement, selectAll } from '@syncfusion/ej2-base';
77
import { Button } from '@syncfusion/ej2-buttons';
88
import { DataManager, Query } from '@syncfusion/ej2-data';
99
import { SelectEventArgs, ListView } from '@syncfusion/ej2-lists';
@@ -16,6 +16,9 @@ declare let require: (url: string) => Object;
1616
const tabList: string[] = ['htab', 'ttab'];
1717
const urlSplit: RegExp = /\b(?!html)\b([A-Za-z-]+)/g;
1818
let execFunction: { [key: string]: Object } = {};
19+
let selectedTheme: string = location.hash.split('/')[1];
20+
let availableThemes: string[] = ['material', 'fabric'];
21+
let isHashChanged: boolean = true;
1922

2023
interface DestroyMethod extends HTMLElement {
2124
destroy: Function;
@@ -139,6 +142,16 @@ function getSampleList(): Controls[] | { [key: string]: Object }[] {
139142
return samplesJSON.samplesList;
140143
}
141144
function loadJSON(): void {
145+
//material is default theme.
146+
if (availableThemes.indexOf(selectedTheme) === -1) {
147+
selectedTheme = 'material';
148+
}
149+
loadTheme(selectedTheme);
150+
if (selectedTheme === 'fabric') {
151+
enableRipple(false);
152+
} else {
153+
enableRipple(true);
154+
}
142155
overlay();
143156
routeDefault();
144157
showBackButton();
@@ -201,6 +214,8 @@ function loadJSON(): void {
201214
}
202215
localStorage.removeItem('ej2-switch');
203216
setResponsive();
217+
select('#themeswitcher').addEventListener('click', toggleTheme);
218+
select('#themelist').addEventListener('click', changeTheme);
204219
}
205220

206221
function loadPage(page: string): void {
@@ -231,7 +246,7 @@ function routeDefault(): void {
231246
// loadPage('showcase');
232247

233248
//Redirected page until showcase page implemented
234-
window.location.href = '#/chart/line.html';
249+
window.location.href = '#/' + selectedTheme + '/chart/line.html';
235250
isInitRedirected = true;
236251
});
237252
bypassed.add((request: Object) => {
@@ -253,14 +268,25 @@ function navigateURL(arg: Controls & Samples, isInteracted: boolean): void {
253268
let cCtrl: string = (isInteracted ? currentListControl : currentControl);
254269
if (!arg.hasOwnProperty('samples')) {
255270
let sample: string = arg.url;
256-
hasher.setHash(cCtrl + '/' + sample + '.html');
271+
let targetHash: string = selectedTheme + '/' + cCtrl + '/' + sample + '.html';
272+
if (location.hash === ('#/' + targetHash)) {
273+
isHashChanged = false;
274+
}
275+
hasher.setHash(targetHash);
257276
if (isVisible(select('.slide-nav'))) {
258277
onCloseClick();
259278
}
260279
} else {
261280
currentListControl = arg.directory;
262281
}
263282
}
283+
function loadTheme(theme: string): void {
284+
let doc: HTMLFormElement = <HTMLFormElement>document.getElementById('themelink');
285+
selectedTheme = theme;
286+
doc.href = 'styles/' + selectedTheme + '.css';
287+
select('#themeswitcher-icon').setAttribute('src', 'styles/images/sb_icons/SB_Switcher_icon_' + theme + '.png');
288+
document.getElementById(theme).style.background = '#DEDFE0';
289+
}
264290
function addRoutes(samplesList: Controls[]): void {
265291
for (let node of samplesList) {
266292
let dataManager: DataManager = new DataManager(node.samples);
@@ -270,12 +296,12 @@ function addRoutes(samplesList: Controls[]): void {
270296
let control: string = node.directory;
271297
let sample: string = subNode.url;
272298
let sampleName: string = node.name + ' / ' + subNode.name;
273-
let urlString: string = '/' + control + '/' + sample + '.html';
299+
let selectedTheme: string = location.hash.split('/')[1] ? location.hash.split('/')[1] : 'material';
300+
let urlString: string = '/' + selectedTheme + '/' + control + '/' + sample + '.html';
274301
samplesAr.push('#' + urlString);
275302
addRoute(urlString, () => {
276303
let controlID: string = node.uid;
277304
let sampleID: string = subNode.uid;
278-
document.getElementById('plnkr').classList.add('disabled');
279305
select('#switch').classList.remove('hidden');
280306
document.getElementById('source-panel').style.display = 'block';
281307
let ajaxHTML: Ajax = new Ajax('src/' + control + '/' + sample + '.html', 'GET', true);
@@ -324,6 +350,7 @@ function addRoutes(samplesList: Controls[]): void {
324350
toggleButtonState('prev-sample', false);
325351
}
326352
document.getElementById('html-tab-scroll').style.width = '';
353+
select('#control-content').classList.remove('error-content');
327354
document.getElementById('control-content').innerHTML = htmlString;
328355
let controlEle: Element = document.querySelector('.control-section');
329356
let controlString: string = controlEle.innerHTML;
@@ -358,13 +385,14 @@ function addRoutes(samplesList: Controls[]): void {
358385

359386
function onSampleSelect(arg: SelectEventArgs): void {
360387
if (arg.data.category !== 'ShowCase') {
388+
isHashChanged = true;
361389
navigateURL(<any>arg.data, arg.isInteracted);
362390
// let currentItem: HTMLElement = <HTMLElement>arg.item;
363391
// this.element.scrollTop = currentItem.offsetTop;
364392
if (arg.isInteracted) {
365393
showBackButton();
366394
}
367-
if (!(<Controls & { [key: string]: Object }>arg.data).samples) {
395+
if (!(<Controls & { [key: string]: Object }>arg.data).samples && isHashChanged) {
368396
overlay();
369397
}
370398
} else {
@@ -392,6 +420,7 @@ function onOpenClick(arg: MouseEvent): void {
392420
slideOut();
393421
}
394422
arg.stopPropagation();
423+
closeThemeSelection();
395424
}
396425

397426
function dispatchResize(): void {
@@ -410,6 +439,7 @@ function onCloseClick(arg?: MouseEvent): void {
410439
if (isVisible(ele) && isVisible(select('.slide-nav'))) {
411440
slideOut();
412441
}
442+
closeThemeSelection();
413443
}
414444

415445
function onNextButtonClick(arg: MouseEvent): void {
@@ -449,7 +479,7 @@ function onPrevButtonClick(arg: MouseEvent): void {
449479
function checkLevel(prevhref: string, curhref: string): void {
450480
let prevHrefSplit: string[] = prevhref.match(urlSplit);
451481
let curhrefSplit: string[] = curhref.match(urlSplit);
452-
if (prevHrefSplit[0] !== curhrefSplit[0]) {
482+
if (prevHrefSplit[1] !== curhrefSplit[1]) {
453483
isSameParent = false;
454484
sampleTree.back();
455485
} else {
@@ -458,7 +488,11 @@ function checkLevel(prevhref: string, curhref: string): void {
458488
isExternalNavigation = true;
459489
}
460490
function parseHash(newHash: string, oldHash: string): void {
461-
let control: string = newHash.split('/')[0];
491+
let newTheme: string = newHash.split('/')[0];
492+
let control: string = newHash.split('/')[1];
493+
if (newTheme !== selectedTheme && availableThemes.indexOf(newTheme) !== -1) {
494+
location.reload();
495+
}
462496
if (newHash.length && !select('#' + control + '-common') && checkSampleLength(control)) {
463497
let scriptElement: HTMLScriptElement = document.createElement('script');
464498
scriptElement.src = 'src/' + control + '/common.js';
@@ -562,4 +596,22 @@ function plunker(results: string): void {
562596
document.getElementById('plnkr').addEventListener('click', () => { form.submit(); });
563597
}
564598

599+
function toggleTheme(): void {
600+
let target: any = document.getElementById('selectdiv');
601+
target.classList.toggle('e-hidden');
602+
select('#themeswitcher').classList.toggle('active');
603+
}
604+
function changeTheme(arg: MouseEvent): void {
605+
let target: Element = <Element>arg.target;
606+
let themeName: string = target.textContent || target.className.split(' ')[1];
607+
themeName = themeName.toLowerCase();
608+
let hash: string[] = location.hash.split('/');
609+
hash[1] = themeName;
610+
location.hash = hash.join('/');
611+
}
612+
function closeThemeSelection(): void {
613+
if (!select('#selectdiv').classList.contains('e-hidden')) {
614+
toggleTheme();
615+
}
616+
}
565617
loadJSON();
17.7 KB
Loading
17.7 KB
Loading

styles/images/sb_icons/fabric.png

633 Bytes
Loading
684 Bytes
Loading

styles/index.css

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,67 @@ body {
5151
}
5252
.header-right {
5353
float: right;
54+
height: 100%;
55+
padding-right: 16px;
56+
}
57+
.themeicon {
58+
height: 100%;
59+
width: 60px;
60+
cursor: pointer;
61+
margin-left: 30px;
62+
}
63+
.options li {
64+
line-height: 28px;
65+
padding: 10px 16px;
66+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
67+
color: #333333;
68+
font-size: 14px;
69+
}
70+
.options {
71+
list-style: none;
72+
padding-left: 0px;
73+
border:1px solid #EAEAEA;
74+
background: white;
75+
margin-bottom: 0px;
76+
}
77+
.switch-icon {
78+
display: block;
79+
float: right;
80+
height: 28px;
81+
width: 28px;
82+
}
83+
.switch-icon.material {
84+
background: url(images/sb_icons/material.png) no-repeat 100% 100%;
85+
}
86+
.switch-icon.fabric {
87+
background: url(images/sb_icons/fabric.png) no-repeat 100% 100%;
88+
}
89+
#selectdiv {
90+
width:230px;
91+
position:absolute;
92+
z-index:1000;
93+
right:16px;
94+
box-shadow: 0px 0px 25px -5px #9a9a9a;
95+
}
96+
.options li:hover {
97+
background-color: #f1f1f1;
98+
cursor: pointer;
99+
100+
}
101+
#themeswitcher img{
102+
padding-top: 3px;
103+
}
104+
#themeswitcher.active {
105+
background: #3397DA;
106+
}
107+
#themeswitcher :hover {
108+
background: #3397DA;
109+
}
110+
#themeswitcher .e-input {
111+
margin-left: 5px;
112+
}
113+
#themeswitcher .e-input-group-icon.e-ddl-icon {
114+
margin-right: 4px;
54115
}
55116
.list-search {
56117
display: none;
@@ -540,6 +601,12 @@ body {
540601
}
541602
}
542603

604+
@media screen and (max-width: 345px) {
605+
#themeswitcher {
606+
margin-left: 9px;
607+
}
608+
}
609+
543610
@media screen and (min-width: 150px) and (max-width: 480px) {
544611
.nav-btn .btn-default,
545612
.nav-btn .btn-default:active:hover,

0 commit comments

Comments
 (0)