Skip to content

Commit a57a31d

Browse files
committed
Support getting the theme from the dom
1 parent a160d48 commit a57a31d

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ You can set `Pace.options` before bringing in the file:
2020
Pace = {
2121
options: {
2222
// Disable the 'elements' source
23-
elements: false
23+
elements: false,
24+
25+
theme: 'barber-shop'
2426
}
2527
}
2628
```
@@ -41,6 +43,19 @@ define(['pace'], function(pace){
4143
});
4244
```
4345

46+
Themes
47+
------
48+
49+
Pace includes a bunch of themes to get you started. Specify the theme of your choice as
50+
an option, and include the appropriate css file.
51+
52+
You can specify the theme as an option, but to keep things simple, we also support
53+
specifying it as a seperate data attribute:
54+
55+
```html
56+
<script data-pace-theme='barber-shop' src='pace.js'></script>
57+
```
58+
4459
Collectors
4560
----------
4661

pace.coffee

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,15 @@ extend = (out, sources...) ->
7878
out[key] = val
7979
out
8080

81-
getOptionsFromDOM = ->
82-
el = document.querySelector '[data-pace-options]'
83-
data = el.getAttribute 'data-pace-options'
81+
getFromDOM = (key='options', json=true) ->
82+
el = document.querySelector "[data-pace-#{ key }]"
83+
84+
return unless el
85+
86+
data = el.getAttribute "data-pace-#{ key }"
8487

88+
return data if not json
89+
8590
try
8691
return JSON.parse data
8792
catch e
@@ -90,7 +95,10 @@ getOptionsFromDOM = ->
9095
window.Pace ?= {}
9196
Pace.options ?= {}
9297

93-
options = extend Pace?.options, getOptionsFromDOM(), defaultOptions
98+
options = extend Pace?.options, getFromDOM(), defaultOptions
99+
100+
if domTheme = getFromDOM('theme', false)
101+
options.theme = domTheme
94102

95103
class Bar
96104
constructor: ->

0 commit comments

Comments
 (0)