-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
50 lines (44 loc) · 1.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
define(['nbd/Class', 'nbd/util/extend', './src/Engine'], function(Class, extend, Engine) {
'use strict';
var Focss = Class.extend({
init: function(root, extensions, scoped) {
scoped = scoped === undefined ? true : !!scoped;
this.engine = new Engine(root, scoped);
extend(this.engine.extensions, extensions);
},
/**
* Insert a focss rule
* @param selector {String} CSS selector/dynamic selector
* @param spec {Object} key/value map of CSS property to expression
* @returns Object Artifacts found while compiling the rule
*/
insert: function(selector, spec) {
if (typeof selector === "object") {
var artifacts = {};
for (var s in selector) {
if (selector.hasOwnProperty(s)) {
extend(artifacts, this.insert(s, selector[s]));
}
}
return artifacts;
}
var rule = this.engine.insert(selector, spec);
return rule.artifacts;
},
/**
* Run the current set of rules against state data
* Previous state data is overridden.
* @param data {Object} state data
*/
process: function(data) {
this.engine.process(data);
},
destroy: function() {
this.engine.destroy();
this.engine = null;
}
}, {
displayName: 'Focss'
});
return Focss;
});