33 * default script manupulation for sample browser
44 */
55import '../../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' ;
77import { Button } from '@syncfusion/ej2-buttons' ;
88import { DataManager , Query } from '@syncfusion/ej2-data' ;
99import { SelectEventArgs , ListView } from '@syncfusion/ej2-lists' ;
@@ -16,6 +16,9 @@ declare let require: (url: string) => Object;
1616const tabList : string [ ] = [ 'htab' , 'ttab' ] ;
1717const urlSplit : RegExp = / \b (? ! h t m l ) \b ( [ A - Z a - z - ] + ) / g;
1818let execFunction : { [ key : string ] : Object } = { } ;
19+ let selectedTheme : string = location . hash . split ( '/' ) [ 1 ] ;
20+ let availableThemes : string [ ] = [ 'material' , 'fabric' ] ;
21+ let isHashChanged : boolean = true ;
1922
2023interface DestroyMethod extends HTMLElement {
2124 destroy : Function ;
@@ -139,6 +142,16 @@ function getSampleList(): Controls[] | { [key: string]: Object }[] {
139142 return samplesJSON . samplesList ;
140143}
141144function 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
206221function 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+ }
264290function 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
359386function 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
397426function 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
415445function onNextButtonClick ( arg : MouseEvent ) : void {
@@ -449,7 +479,7 @@ function onPrevButtonClick(arg: MouseEvent): void {
449479function 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}
460490function 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+ }
565617loadJSON ( ) ;
0 commit comments