author | ymh <ymh.work@gmail.com> |
Tue, 20 Mar 2018 15:02:40 +0100 | |
changeset 573 | 25f3d28f51b2 |
parent 537 | d2e6ee099125 |
permissions | -rw-r--r-- |
28 | 1 |
// Copied and modified from https://gist.github.com/walter/3e852e8ebc87535a3c91 |
2 |
import Ember from 'ember'; |
|
3 |
import config from 'bo-client/config/environment'; |
|
4 |
||
5 |
||
6 |
export function initialize(application) { |
|
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
28
diff
changeset
|
7 |
var OptionsReader = function OptionsReader() { |
28 | 8 |
this.readOptionsKeys = function() { |
9 |
var _mapType = function(val) { |
|
10 |
return "" === val ? null : "true" === val ? true : "false" === val ? false : (-1 !== val.indexOf(",") && (val = val.split(",")), val); |
|
11 |
}; |
|
12 |
||
13 |
// Grab all the meta tags from the DOM. |
|
14 |
var metaTags = Ember.$("meta"); |
|
15 |
var options = Ember.Object.create(); |
|
16 |
var re = new RegExp(config.modulePrefix + '\.'); |
|
17 |
||
18 |
// Process each of the discovered meta tags. |
|
19 |
for(var i=0; i < metaTags.length; i++) { |
|
20 |
var key = Ember.$(metaTags[i]).attr('name'); |
|
21 |
var value = Ember.$(metaTags[i]).attr('content'); |
|
22 |
||
23 |
// Does the meta tag start with our MODULE_PREFIX? |
|
24 |
if (re.test(key)) { |
|
25 |
var propertyName = Ember.String.camelize(key.substring(config.modulePrefix.length+1)); |
|
26 |
options[propertyName] = _mapType(value); |
|
27 |
} |
|
28 |
} |
|
29 |
return options; |
|
30 |
}; |
|
31 |
}; |
|
32 |
||
33 |
var optionsReader = new OptionsReader(); |
|
34 |
||
35 |
application.register('service:options', optionsReader.readOptionsKeys(), {singleton: true, instantiate: false}); |
|
36 |
||
37 |
} |
|
38 |
||
39 |
export default { |
|
40 |
name: 'options', |
|
41 |
initialize |
|
42 |
}; |