WIP: Note editing, markdown to html
[oweals/karmaworld.git] / karmaworld / apps / wysihtml5 / static / wysihtml5 / wysihtml-0.4.17 / src / commands / bgColorStyle.js
1 /* In case background adjustment to any color defined by user is preferred, we cannot use classes and must use inline styles. */
2 (function(wysihtml5) {
3   var REG_EXP = /(\s|^)background-color\s*:\s*[^;\s]+;?/gi;
4
5   wysihtml5.commands.bgColorStyle = {
6     exec: function(composer, command, color) {
7       var colorVals  = wysihtml5.quirks.styleParser.parseColor((typeof(color) == "object") ? "background-color:" + color.color : "background-color:" + color, "background-color"),
8           colString;
9
10       if (colorVals) {
11         colString = "background-color: rgb(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ');';
12         if (colorVals[3] !== 1) {
13           colString += "background-color: rgba(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ',' + colorVals[3] + ');';
14         }
15         wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, colString, REG_EXP);
16       }
17     },
18
19     state: function(composer, command) {
20       return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "background-color", REG_EXP);
21     },
22
23     stateValue: function(composer, command, props) {
24       var st = this.state(composer, command),
25           colorStr,
26           val = false;
27
28       if (st && wysihtml5.lang.object(st).isArray()) {
29         st = st[0];
30       }
31
32       if (st) {
33         colorStr = st.getAttribute('style');
34         if (colorStr) {
35           val = wysihtml5.quirks.styleParser.parseColor(colorStr, "background-color");
36           return wysihtml5.quirks.styleParser.unparseColor(val, props);
37         }
38       }
39       return false;
40     }
41
42   };
43 })(wysihtml5);