wysihtml-rails 0.5.5 → 0.6.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -6
  3. data/lib/wysihtml/rails/version.rb +1 -1
  4. data/vendor/assets/javascripts/wysihtml.js +5944 -8553
  5. data/vendor/assets/javascripts/wysihtml/all_commands.js +23 -0
  6. data/vendor/assets/javascripts/wysihtml/extra_commands/alignCenterStyle.js +17 -0
  7. data/vendor/assets/javascripts/wysihtml/extra_commands/alignJustifyStyle.js +17 -0
  8. data/vendor/assets/javascripts/wysihtml/extra_commands/alignLeftStyle.js +17 -0
  9. data/vendor/assets/javascripts/wysihtml/extra_commands/alignRightStyle.js +17 -0
  10. data/vendor/assets/javascripts/wysihtml/extra_commands/bgColorStyle.js +48 -0
  11. data/vendor/assets/javascripts/wysihtml/extra_commands/bold.js +16 -0
  12. data/vendor/assets/javascripts/wysihtml/extra_commands/command_formatCode.js +52 -0
  13. data/vendor/assets/javascripts/wysihtml/extra_commands/command_insertImage.js +108 -0
  14. data/vendor/assets/javascripts/wysihtml/extra_commands/fontSize.js +13 -0
  15. data/vendor/assets/javascripts/wysihtml/extra_commands/fontSizeStyle.js +35 -0
  16. data/vendor/assets/javascripts/wysihtml/extra_commands/foreColor.js +13 -0
  17. data/vendor/assets/javascripts/wysihtml/extra_commands/foreColorStyle.js +52 -0
  18. data/vendor/assets/javascripts/wysihtml/extra_commands/insertBlockQuote.js +16 -0
  19. data/vendor/assets/javascripts/wysihtml/extra_commands/insertOrderedList.js +11 -0
  20. data/vendor/assets/javascripts/wysihtml/extra_commands/insertUnorderedList.js +11 -0
  21. data/vendor/assets/javascripts/wysihtml/extra_commands/italic.js +17 -0
  22. data/vendor/assets/javascripts/wysihtml/extra_commands/justifyCenter.js +18 -0
  23. data/vendor/assets/javascripts/wysihtml/extra_commands/justifyFull.js +17 -0
  24. data/vendor/assets/javascripts/wysihtml/extra_commands/justifyLeft.js +17 -0
  25. data/vendor/assets/javascripts/wysihtml/extra_commands/justifyRight.js +17 -0
  26. data/vendor/assets/javascripts/wysihtml/extra_commands/subscript.js +17 -0
  27. data/vendor/assets/javascripts/wysihtml/extra_commands/superscript.js +17 -0
  28. data/vendor/assets/javascripts/wysihtml/extra_commands/underline.js +17 -0
  29. data/vendor/assets/javascripts/{parser_rules → wysihtml/parser_rules}/advanced.js +4 -4
  30. data/vendor/assets/javascripts/{parser_rules → wysihtml/parser_rules}/advanced_and_extended.js +25 -25
  31. data/vendor/assets/javascripts/{parser_rules → wysihtml/parser_rules}/advanced_unwrap.js +5 -5
  32. data/vendor/assets/javascripts/{parser_rules → wysihtml/parser_rules}/simple.js +2 -2
  33. data/vendor/assets/javascripts/wysihtml/table_editing.js +1163 -0
  34. data/vendor/assets/javascripts/wysihtml/toolbar.js +850 -0
  35. metadata +35 -9
  36. data/vendor/assets/javascripts/wysihtml-toolbar.js +0 -19308
@@ -0,0 +1,23 @@
1
+ //= require ./extra_commands/alignCenterStyle.js
2
+ //= require ./extra_commands/alignJustifyStyle.js
3
+ //= require ./extra_commands/alignLeftStyle.js
4
+ //= require ./extra_commands/alignRightStyle.js
5
+ //= require ./extra_commands/bgColorStyle.js
6
+ //= require ./extra_commands/bold.js
7
+ //= require ./extra_commands/command_formatCode.js
8
+ //= require ./extra_commands/command_insertImage.js
9
+ //= require ./extra_commands/fontSize.js
10
+ //= require ./extra_commands/fontSizeStyle.js
11
+ //= require ./extra_commands/foreColor.js
12
+ //= require ./extra_commands/foreColorStyle.js
13
+ //= require ./extra_commands/insertBlockQuote.js
14
+ //= require ./extra_commands/insertOrderedList.js
15
+ //= require ./extra_commands/insertUnorderedList.js
16
+ //= require ./extra_commands/italic.js
17
+ //= require ./extra_commands/justifyCenter.js
18
+ //= require ./extra_commands/justifyFull.js
19
+ //= require ./extra_commands/justifyLeft.js
20
+ //= require ./extra_commands/justifyRight.js
21
+ //= require ./extra_commands/subscript.js
22
+ //= require ./extra_commands/superscript.js
23
+ //= require ./extra_commands/underline.js
@@ -0,0 +1,17 @@
1
+ wysihtml.commands.alignCenterStyle = (function() {
2
+ var nodeOptions = {
3
+ styleProperty: "textAlign",
4
+ styleValue: "center",
5
+ toggle: true
6
+ };
7
+
8
+ return {
9
+ exec: function(composer, command) {
10
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
11
+ },
12
+
13
+ state: function(composer, command) {
14
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
15
+ }
16
+ };
17
+ })();
@@ -0,0 +1,17 @@
1
+ wysihtml.commands.alignJustifyStyle = (function() {
2
+ var nodeOptions = {
3
+ styleProperty: "textAlign",
4
+ styleValue: "justify",
5
+ toggle: true
6
+ };
7
+
8
+ return {
9
+ exec: function(composer, command) {
10
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
11
+ },
12
+
13
+ state: function(composer, command) {
14
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
15
+ }
16
+ };
17
+ })();
@@ -0,0 +1,17 @@
1
+ wysihtml.commands.alignLeftStyle = (function() {
2
+ var nodeOptions = {
3
+ styleProperty: "textAlign",
4
+ styleValue: "left",
5
+ toggle: true
6
+ };
7
+
8
+ return {
9
+ exec: function(composer, command) {
10
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
11
+ },
12
+
13
+ state: function(composer, command) {
14
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
15
+ }
16
+ };
17
+ })();
@@ -0,0 +1,17 @@
1
+ wysihtml.commands.alignRightStyle = (function() {
2
+ var nodeOptions = {
3
+ styleProperty: "textAlign",
4
+ styleValue: "right",
5
+ toggle: true
6
+ };
7
+
8
+ return {
9
+ exec: function(composer, command) {
10
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
11
+ },
12
+
13
+ state: function(composer, command) {
14
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
15
+ }
16
+ };
17
+ })();
@@ -0,0 +1,48 @@
1
+ /* Sets text background color by inline styles */
2
+ wysihtml.commands.bgColorStyle = (function() {
3
+ return {
4
+ exec: function(composer, command, color) {
5
+ var colorVals = wysihtml.quirks.styleParser.parseColor("background-color:" + (color.color || color), "background-color"),
6
+ colString;
7
+
8
+ if (colorVals) {
9
+ colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(', ') : "rgba(" + colorVals.join(', ')) + ')';
10
+ wysihtml.commands.formatInline.exec(composer, command, {styleProperty: 'backgroundColor', styleValue: colString});
11
+ }
12
+ },
13
+
14
+ state: function(composer, command, color) {
15
+ var colorVals = color ? wysihtml.quirks.styleParser.parseColor("background-color:" + (color.color || color), "background-color") : null,
16
+ colString;
17
+
18
+ if (colorVals) {
19
+ colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(', ') : "rgba(" + colorVals.join(', ')) + ')';
20
+ }
21
+
22
+ return wysihtml.commands.formatInline.state(composer, command, {styleProperty: 'backgroundColor', styleValue: colString});
23
+ },
24
+
25
+ remove: function(composer, command) {
26
+ return wysihtml.commands.formatInline.remove(composer, command, {styleProperty: 'backgroundColor'});
27
+ },
28
+
29
+ stateValue: function(composer, command, props) {
30
+ var st = this.state(composer, command),
31
+ colorStr,
32
+ val = false;
33
+
34
+ if (st && wysihtml.lang.object(st).isArray()) {
35
+ st = st[0];
36
+ }
37
+
38
+ if (st) {
39
+ colorStr = st.getAttribute('style');
40
+ if (colorStr) {
41
+ val = wysihtml.quirks.styleParser.parseColor(colorStr, "background-color");
42
+ return wysihtml.quirks.styleParser.unparseColor(val, props);
43
+ }
44
+ }
45
+ return false;
46
+ }
47
+ };
48
+ })();
@@ -0,0 +1,16 @@
1
+ wysihtml.commands.bold = (function() {
2
+ var nodeOptions = {
3
+ nodeName: "B",
4
+ toggle: true
5
+ };
6
+
7
+ return {
8
+ exec: function(composer, command) {
9
+ wysihtml.commands.formatInline.exec(composer, command, nodeOptions);
10
+ },
11
+
12
+ state: function(composer, command) {
13
+ return wysihtml.commands.formatInline.state(composer, command, nodeOptions);
14
+ }
15
+ };
16
+ })();
@@ -0,0 +1,52 @@
1
+ /* Formats block for as a <pre><code class="classname"></code></pre> block
2
+ * Useful in conjuction for sytax highlight utility: highlight.js
3
+ *
4
+ * Usage:
5
+ *
6
+ * editorInstance.composer.commands.exec("formatCode", "language-html");
7
+ */
8
+ wysihtml.commands.formatCode = (function() {
9
+ return {
10
+ exec: function(composer, command, classname) {
11
+ var pre = this.state(composer)[0],
12
+ code, range, selectedNodes;
13
+
14
+ if (pre) {
15
+ // caret is already within a <pre><code>...</code></pre>
16
+ composer.selection.executeAndRestore(function() {
17
+ code = pre.querySelector("code");
18
+ wysihtml.dom.replaceWithChildNodes(pre);
19
+ if (code) {
20
+ wysihtml.dom.replaceWithChildNodes(code);
21
+ }
22
+ });
23
+ } else {
24
+ // Wrap in <pre><code>...</code></pre>
25
+ range = composer.selection.getRange();
26
+ selectedNodes = range.extractContents();
27
+ pre = composer.doc.createElement("pre");
28
+ code = composer.doc.createElement("code");
29
+
30
+ if (classname) {
31
+ code.className = classname;
32
+ }
33
+
34
+ pre.appendChild(code);
35
+ code.appendChild(selectedNodes);
36
+ range.insertNode(pre);
37
+ composer.selection.selectNode(pre);
38
+ }
39
+ },
40
+
41
+ state: function(composer) {
42
+ var selectedNode = composer.selection.getSelectedNode(), node;
43
+ if (selectedNode && selectedNode.nodeName && selectedNode.nodeName == "PRE"&&
44
+ selectedNode.firstChild && selectedNode.firstChild.nodeName && selectedNode.firstChild.nodeName == "CODE") {
45
+ return [selectedNode];
46
+ } else {
47
+ node = wysihtml.dom.getParentElement(selectedNode, { query: "pre code" });
48
+ return node ? [node.parentNode] : false;
49
+ }
50
+ }
51
+ };
52
+ })();
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Inserts an <img>
3
+ * If selection is already an image link, it removes it
4
+ *
5
+ * @example
6
+ * // either ...
7
+ * wysihtml.commands.insertImage.exec(composer, "insertImage", "http://www.google.de/logo.jpg");
8
+ * // ... or ...
9
+ * wysihtml.commands.insertImage.exec(composer, "insertImage", { src: "http://www.google.de/logo.jpg", title: "foo" });
10
+ */
11
+ wysihtml.commands.insertImage = (function() {
12
+ var NODE_NAME = "IMG";
13
+ return {
14
+ exec: function(composer, command, value) {
15
+ value = typeof(value) === "object" ? value : { src: value };
16
+
17
+ var doc = composer.doc,
18
+ image = this.state(composer),
19
+ textNode,
20
+ parent;
21
+
22
+ // If image is selected and src ie empty, set the caret before it and delete the image
23
+ if (image && !value.src) {
24
+ composer.selection.setBefore(image);
25
+ parent = image.parentNode;
26
+ parent.removeChild(image);
27
+
28
+ // and it's parent <a> too if it hasn't got any other relevant child nodes
29
+ wysihtml.dom.removeEmptyTextNodes(parent);
30
+ if (parent.nodeName === "A" && !parent.firstChild) {
31
+ composer.selection.setAfter(parent);
32
+ parent.parentNode.removeChild(parent);
33
+ }
34
+
35
+ // firefox and ie sometimes don't remove the image handles, even though the image got removed
36
+ wysihtml.quirks.redraw(composer.element);
37
+ return;
38
+ }
39
+
40
+ // If image selected change attributes accordingly
41
+ if (image) {
42
+ for (var key in value) {
43
+ if (value.hasOwnProperty(key)) {
44
+ image.setAttribute(key === "className" ? "class" : key, value[key]);
45
+ }
46
+ }
47
+ return;
48
+ }
49
+
50
+ // Otherwise lets create the image
51
+ image = doc.createElement(NODE_NAME);
52
+
53
+ for (var i in value) {
54
+ image.setAttribute(i === "className" ? "class" : i, value[i]);
55
+ }
56
+
57
+ composer.selection.insertNode(image);
58
+ if (wysihtml.browser.hasProblemsSettingCaretAfterImg()) {
59
+ textNode = doc.createTextNode(wysihtml.INVISIBLE_SPACE);
60
+ composer.selection.insertNode(textNode);
61
+ composer.selection.setAfter(textNode);
62
+ } else {
63
+ composer.selection.setAfter(image);
64
+ }
65
+ },
66
+
67
+ state: function(composer) {
68
+ var doc = composer.doc,
69
+ selectedNode,
70
+ text,
71
+ imagesInSelection;
72
+
73
+ if (!wysihtml.dom.hasElementWithTagName(doc, NODE_NAME)) {
74
+ return false;
75
+ }
76
+
77
+ selectedNode = composer.selection.getSelectedNode();
78
+ if (!selectedNode) {
79
+ return false;
80
+ }
81
+
82
+ if (selectedNode.nodeName === NODE_NAME) {
83
+ // This works perfectly in IE
84
+ return selectedNode;
85
+ }
86
+
87
+ if (selectedNode.nodeType !== wysihtml.ELEMENT_NODE) {
88
+ return false;
89
+ }
90
+
91
+ text = composer.selection.getText();
92
+ text = wysihtml.lang.string(text).trim();
93
+ if (text) {
94
+ return false;
95
+ }
96
+
97
+ imagesInSelection = composer.selection.getNodes(wysihtml.ELEMENT_NODE, function(node) {
98
+ return node.nodeName === "IMG";
99
+ });
100
+
101
+ if (imagesInSelection.length !== 1) {
102
+ return false;
103
+ }
104
+
105
+ return imagesInSelection[0];
106
+ }
107
+ };
108
+ })();
@@ -0,0 +1,13 @@
1
+ wysihtml.commands.fontSize = (function() {
2
+ var REG_EXP = /wysiwyg-font-size-[0-9a-z\-]+/g;
3
+
4
+ return {
5
+ exec: function(composer, command, size) {
6
+ wysihtml.commands.formatInline.exec(composer, command, {className: "wysiwyg-font-size-" + size, classRegExp: REG_EXP, toggle: true});
7
+ },
8
+
9
+ state: function(composer, command, size) {
10
+ return wysihtml.commands.formatInline.state(composer, command, {className: "wysiwyg-font-size-" + size});
11
+ }
12
+ };
13
+ })();
@@ -0,0 +1,35 @@
1
+ /* Set font size by inline style */
2
+ wysihtml.commands.fontSizeStyle = (function() {
3
+ return {
4
+ exec: function(composer, command, size) {
5
+ size = size.size || size;
6
+ if (!(/^\s*$/).test(size)) {
7
+ wysihtml.commands.formatInline.exec(composer, command, {styleProperty: "fontSize", styleValue: size, toggle: false});
8
+ }
9
+ },
10
+
11
+ state: function(composer, command, size) {
12
+ return wysihtml.commands.formatInline.state(composer, command, {styleProperty: "fontSize", styleValue: size || undefined});
13
+ },
14
+
15
+ remove: function(composer, command) {
16
+ return wysihtml.commands.formatInline.remove(composer, command, {styleProperty: "fontSize"});
17
+ },
18
+
19
+ stateValue: function(composer, command) {
20
+ var styleStr,
21
+ st = this.state(composer, command);
22
+
23
+ if (st && wysihtml.lang.object(st).isArray()) {
24
+ st = st[0];
25
+ }
26
+ if (st) {
27
+ styleStr = st.getAttribute("style");
28
+ if (styleStr) {
29
+ return wysihtml.quirks.styleParser.parseFontSize(styleStr);
30
+ }
31
+ }
32
+ return false;
33
+ }
34
+ };
35
+ })();
@@ -0,0 +1,13 @@
1
+ wysihtml.commands.foreColor = (function() {
2
+ var REG_EXP = /wysiwyg-color-[0-9a-z]+/g;
3
+
4
+ return {
5
+ exec: function(composer, command, color) {
6
+ wysihtml.commands.formatInline.exec(composer, command, {className: "wysiwyg-color-" + color, classRegExp: REG_EXP, toggle: true});
7
+ },
8
+
9
+ state: function(composer, command, color) {
10
+ return wysihtml.commands.formatInline.state(composer, command, {className: "wysiwyg-color-" + color});
11
+ }
12
+ };
13
+ })();
@@ -0,0 +1,52 @@
1
+ /* Sets text color by inline styles */
2
+ wysihtml.commands.foreColorStyle = (function() {
3
+ return {
4
+ exec: function(composer, command, color) {
5
+ var colorVals, colString;
6
+
7
+ if (!color) { return; }
8
+
9
+ colorVals = wysihtml.quirks.styleParser.parseColor("color:" + (color.color || color), "color");
10
+
11
+ if (colorVals) {
12
+ colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(", ") : "rgba(" + colorVals.join(', ')) + ')';
13
+ wysihtml.commands.formatInline.exec(composer, command, {styleProperty: "color", styleValue: colString});
14
+ }
15
+ },
16
+
17
+ state: function(composer, command, color) {
18
+ var colorVals = color ? wysihtml.quirks.styleParser.parseColor("color:" + (color.color || color), "color") : null,
19
+ colString;
20
+
21
+
22
+ if (colorVals) {
23
+ colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(", ") : "rgba(" + colorVals.join(', ')) + ')';
24
+ }
25
+
26
+ return wysihtml.commands.formatInline.state(composer, command, {styleProperty: "color", styleValue: colString});
27
+ },
28
+
29
+ remove: function(composer, command) {
30
+ return wysihtml.commands.formatInline.remove(composer, command, {styleProperty: "color"});
31
+ },
32
+
33
+ stateValue: function(composer, command, props) {
34
+ var st = this.state(composer, command),
35
+ colorStr,
36
+ val = false;
37
+
38
+ if (st && wysihtml.lang.object(st).isArray()) {
39
+ st = st[0];
40
+ }
41
+
42
+ if (st) {
43
+ colorStr = st.getAttribute("style");
44
+ if (colorStr) {
45
+ val = wysihtml.quirks.styleParser.parseColor(colorStr, "color");
46
+ return wysihtml.quirks.styleParser.unparseColor(val, props);
47
+ }
48
+ }
49
+ return false;
50
+ }
51
+ };
52
+ })();