source: imaps-frontend/node_modules/nano-css/addon/pipe.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d565449]1'use strict';
2
3var addonCssom = require('./cssom').addon;
4
5exports.addon = function (renderer) {
6 if (!renderer.putRule) {
7 addonCssom(renderer);
8 }
9
10 if (process.env.NODE_ENV !== 'production') {
11 require('./__dev__/warnOnMissingDependencies')('pipe', renderer, ['createRule']);
12 }
13
14 var counter = 0;
15
16 renderer.pipe = function () {
17 var rules = {};
18 var className = renderer.pfx + 'pipe-' + (counter++).toString(36);
19 var attr = 'data-' + className;
20 var scope1 = '.' + className;
21 var scope2 = '[' + attr + ']';
22
23 var obj = {
24 attr: attr,
25 className: className,
26 css: function (css) {
27 for (var selectorTemplate in css) {
28 var declarations = css[selectorTemplate];
29 var rule = rules[selectorTemplate];
30
31 if (!rule) {
32 var selector = selectorTemplate.replace('&', scope1) + ',' + selectorTemplate.replace('&', scope2);
33
34 rules[selectorTemplate] = rule = renderer.putRule(selector);
35 }
36
37 for (var prop in declarations)
38 rule.style.setProperty(prop, declarations[prop]);
39 }
40
41 // GC
42 for (var selectorTemplate2 in rules) {
43 if (!(selectorTemplate2 in css)) {
44 rules[selectorTemplate2].remove();
45 delete rules[selectorTemplate2];
46 }
47 }
48 },
49 remove: function () {
50 for (var selectorTemplate in rules)
51 renderer.sh.deleteRule(rule.index);
52 }
53 };
54
55 return obj;
56 };
57};
Note: See TracBrowser for help on using the repository browser.