source: imaps-frontend/node_modules/nano-css/addon/prefixer.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.1 KB
Line 
1'use strict';
2
3var prefix = require('inline-style-prefixer').prefix;
4
5var CAMEL_REGEX = /-[a-z\u00E0-\u00F6\u00F8-\u00FE]/g;
6
7var matchCallback = function (match) {
8 return match.slice(1).toUpperCase();
9};
10
11exports.addon = function (renderer) {
12 var decl = renderer.decl;
13 var origPut = renderer.put;
14
15 renderer.camel = function (prop) {
16 return prop.replace(CAMEL_REGEX, matchCallback);
17 };
18
19 renderer.prefix = function (prop, value) {
20 var obj = {};
21 obj[renderer.camel(prop)] = value;
22 obj = prefix(obj);
23
24 var result = {};
25
26 for (var propPrefixed in obj) {
27 value = obj[propPrefixed];
28 if (propPrefixed.slice(0, 2) === 'ms') {
29 propPrefixed = 'M' + propPrefixed.slice(1);
30 }
31 propPrefixed = renderer.kebab(propPrefixed);
32
33 if (value instanceof Array) {
34 result[propPrefixed] = value.join(';' + propPrefixed + ':');
35 } else {
36 result[propPrefixed] = value;
37 }
38 }
39
40 return result;
41 };
42
43 renderer.decl = function (prop, value) {
44 var result = renderer.prefix(prop, value);
45
46 var returned = '';
47 Object.keys(result).forEach(function (key) {
48 var str = decl(key, value);
49 returned += str;
50 });
51
52 return returned;
53 };
54
55 function newPut(selector, decls, atrule) {
56 var indexed = selector.indexOf('::placeholder');
57 if (indexed > -1) {
58 var split = selector.split(',');
59 if (split.length > 1) {
60 split.forEach(function(sp) {
61 newPut(sp.trim(), decls, atrule);
62 });
63 return;
64 }
65 var bareSelect = selector.substring(0, indexed);
66 [
67 '::-webkit-input-placeholder',
68 '::-moz-placeholder',
69 ':-ms-input-placeholder',
70 ':-moz-placeholder'
71 ].forEach(function(ph) {
72 origPut(bareSelect + ph, decls, atrule);
73 });
74 }
75 origPut(selector, decls, atrule);
76 }
77
78 renderer.put = newPut;
79};
Note: See TracBrowser for help on using the repository browser.