@@ -14,7 +14,7 @@ export const urlHandler = {
1414 // set-up some default vars
1515 skipBack : false ,
1616 targetOrigin :
17- window . location . protocol == 'file:'
17+ window . location . protocol === 'file:'
1818 ? '*'
1919 : window . location . protocol + '//' + window . location . host ,
2020
@@ -25,9 +25,9 @@ export const urlHandler = {
2525 *
2626 * @return {String } the real file path
2727 */
28- getFileName : function ( name , withRenderedSuffix ) {
29- var baseDir = 'patterns' ;
30- var fileName = '' ;
28+ getFileName ( name , withRenderedSuffix ) {
29+ const baseDir = 'patterns' ;
30+ let fileName = '' ;
3131
3232 if ( name === undefined ) {
3333 return fileName ;
@@ -37,28 +37,31 @@ export const urlHandler = {
3737 withRenderedSuffix = true ;
3838 }
3939
40- if ( name == 'all' ) {
40+ if ( name === 'all' ) {
4141 return 'styleguide/html/styleguide.html' ;
42- } else if ( name == 'snapshots' ) {
42+ } else if ( name === 'snapshots' ) {
4343 return 'snapshots/index.html' ;
4444 }
4545
46- var paths = name . indexOf ( 'viewall-' ) != - 1 ? viewAllPaths : patternPaths ;
47- var nameClean = name . replace ( 'viewall-' , '' ) ;
46+ const paths =
47+ name . indexOf ( 'viewall-' ) !== - 1
48+ ? window . viewAllPaths
49+ : window . patternPaths ;
50+ const nameClean = name . replace ( 'viewall-' , '' ) ;
4851
4952 // look at this as a regular pattern
50- var bits = this . getPatternInfo ( nameClean , paths ) ;
51- var patternType = bits [ 0 ] ;
52- var pattern = bits [ 1 ] ;
53+ const bits = this . getPatternInfo ( nameClean , paths ) ;
54+ const patternType = bits [ 0 ] ;
55+ const pattern = bits [ 1 ] ;
5356
5457 if (
5558 paths [ patternType ] !== undefined &&
5659 paths [ patternType ] [ pattern ] !== undefined
5760 ) {
5861 fileName = paths [ patternType ] [ pattern ] ;
5962 } else if ( paths [ patternType ] !== undefined ) {
60- for ( var patternMatchKey in paths [ patternType ] ) {
61- if ( patternMatchKey . indexOf ( pattern ) != - 1 ) {
63+ for ( const patternMatchKey in paths [ patternType ] ) {
64+ if ( patternMatchKey . indexOf ( pattern ) !== - 1 ) {
6265 fileName = paths [ patternType ] [ patternMatchKey ] ;
6366 break ;
6467 }
@@ -69,7 +72,7 @@ export const urlHandler = {
6972 return fileName ;
7073 }
7174
72- var regex = / \/ / g;
75+ const regex = / \/ / g;
7376 if (
7477 name . indexOf ( 'viewall-' ) !== - 1 &&
7578 name . indexOf ( 'viewall-' ) === 0 &&
@@ -84,10 +87,10 @@ export const urlHandler = {
8487 '/' +
8588 fileName . replace ( regex , '-' ) ;
8689 if ( withRenderedSuffix ) {
87- var fileSuffixRendered =
88- config . outputFileSuffixes !== undefined &&
89- config . outputFileSuffixes . rendered !== undefined
90- ? config . outputFileSuffixes . rendered
90+ const fileSuffixRendered =
91+ window . config . outputFileSuffixes !== undefined &&
92+ window . config . outputFileSuffixes . rendered !== undefined
93+ ? window . config . outputFileSuffixes . rendered
9194 : '' ;
9295 fileName = fileName + fileSuffixRendered + '.html' ;
9396 }
@@ -103,19 +106,19 @@ export const urlHandler = {
103106 *
104107 * @return {Array } the pattern type and pattern name
105108 */
106- getPatternInfo : function ( name , paths ) {
107- var patternBits = name . split ( '-' ) ;
109+ getPatternInfo ( name , paths ) {
110+ const patternBits = name . split ( '-' ) ;
108111
109- var i = 1 ;
110- var c = patternBits . length ;
112+ let i = 1 ;
113+ const c = patternBits . length ;
111114
112- var patternType = patternBits [ 0 ] ;
115+ let patternType = patternBits [ 0 ] ;
113116 while ( paths [ patternType ] === undefined && i < c ) {
114117 patternType += '-' + patternBits [ i ] ;
115118 i ++ ;
116119 }
117120
118- var pattern = name . slice ( patternType . length + 1 , name . length ) ;
121+ const pattern = name . slice ( patternType . length + 1 , name . length ) ;
119122
120123 return [ patternType , pattern ] ;
121124 } ,
@@ -125,12 +128,12 @@ export const urlHandler = {
125128 *
126129 * @return {Object } a search of the window.location.search vars
127130 */
128- getRequestVars : function ( ) {
131+ getRequestVars ( ) {
129132 // the following is taken from https://developer.mozilla.org/en-US/docs/Web/API/window.location
130- var oGetVars = new function ( sSearch ) {
133+ const oGetVars = new function ( sSearch ) {
131134 if ( sSearch . length > 1 ) {
132135 for (
133- var aItKey , nKeyId = 0 , aCouples = sSearch . substr ( 1 ) . split ( '&' ) ;
136+ let aItKey , nKeyId = 0 , aCouples = sSearch . substr ( 1 ) . split ( '&' ) ;
134137 nKeyId < aCouples . length ;
135138 nKeyId ++
136139 ) {
@@ -149,21 +152,21 @@ export const urlHandler = {
149152 * @param {String } the shorthand partials syntax for a given pattern
150153 * @param {String } the path given by the loaded iframe
151154 */
152- pushPattern : function ( pattern , givenPath ) {
153- var data = {
154- pattern : pattern ,
155+ pushPattern ( pattern , givenPath ) {
156+ const data = {
157+ pattern,
155158 } ;
156- var fileName = urlHandler . getFileName ( pattern ) ;
157- var path = window . location . pathname ;
159+ const fileName = urlHandler . getFileName ( pattern ) ;
160+ let path = window . location . pathname ;
158161 path =
159162 window . location . protocol === 'file'
160163 ? path . replace ( '/public/index.html' , 'public/' )
161164 : path . replace ( / \/ i n d e x \. h t m l / , '/' ) ;
162- var expectedPath =
165+ const expectedPath =
163166 window . location . protocol + '//' + window . location . host + path + fileName ;
164- if ( givenPath != expectedPath ) {
167+ if ( givenPath !== expectedPath ) {
165168 // make sure to update the iframe because there was a click
166- var obj = JSON . stringify ( {
169+ const obj = JSON . stringify ( {
167170 event : 'patternLab.updatePath' ,
168171 path : fileName ,
169172 } ) ;
@@ -172,17 +175,17 @@ export const urlHandler = {
172175 . contentWindow . postMessage ( obj , urlHandler . targetOrigin ) ;
173176 } else {
174177 // add to the history
175- var addressReplacement =
176- window . location . protocol == 'file:'
178+ const addressReplacement =
179+ window . location . protocol === 'file:'
177180 ? null
178181 : window . location . protocol +
179182 '//' +
180183 window . location . host +
181184 window . location . pathname . replace ( 'index.html' , '' ) +
182185 '?p=' +
183186 pattern ;
184- if ( history . pushState !== undefined ) {
185- history . pushState ( data , null , addressReplacement ) ;
187+ if ( window . history . pushState !== undefined ) {
188+ window . history . pushState ( data , null , addressReplacement ) ;
186189 }
187190 document . getElementById ( 'title' ) . innerHTML = 'Pattern Lab - ' + pattern ;
188191
@@ -200,9 +203,9 @@ export const urlHandler = {
200203 * based on a click forward or backward modify the url and iframe source
201204 * @param {Object } event info like state and properties set in pushState()
202205 */
203- popPattern : function ( e ) {
204- var patternName ;
205- var state = e . state ;
206+ popPattern ( e ) {
207+ let patternName ;
208+ const state = e . state ;
206209
207210 if ( state === null ) {
208211 this . skipBack = false ;
@@ -211,13 +214,13 @@ export const urlHandler = {
211214 patternName = state . pattern ;
212215 }
213216
214- var iFramePath = '' ;
217+ let iFramePath = '' ;
215218 iFramePath = this . getFileName ( patternName ) ;
216219 if ( iFramePath === '' ) {
217220 iFramePath = 'styleguide/html/styleguide.html' ;
218221 }
219222
220- var obj = JSON . stringify ( {
223+ const obj = JSON . stringify ( {
221224 event : 'patternLab.updatePath' ,
222225 path : iFramePath ,
223226 } ) ;
0 commit comments