blueberry_components 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/blueberry_components.gemspec +26 -0
- data/lib/blueberry_components.rb +5 -0
- data/lib/blueberry_components/engine.rb +4 -0
- data/lib/blueberry_components/version.rb +3 -0
- data/vendor/assets/javascripts/blueberry_components/redactor.js +3 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/config.js +56 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/lang/cs.js +53 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/plugins/alignment.js +59 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/plugins/clips.js +71 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/plugins/fullscreen.js +159 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/plugins/iconic2.js +39 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/plugins/pagebreak.js +50 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/plugins/source.js +195 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/plugins/table.js +471 -0
- data/vendor/assets/javascripts/blueberry_components/redactor2_rails/plugins/video.js +93 -0
- data/vendor/assets/stylesheets/redactor.css +931 -0
- metadata +125 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
(function($)
|
|
2
|
+
{
|
|
3
|
+
$.Redactor.prototype.iconic2 = function()
|
|
4
|
+
{
|
|
5
|
+
return {
|
|
6
|
+
init: function()
|
|
7
|
+
{
|
|
8
|
+
var icons = {
|
|
9
|
+
'html': '<i class="glyphicon glyphicon-console"></i>',
|
|
10
|
+
'format': '<i class="glyphicon glyphicon-text-size"></i>',
|
|
11
|
+
'lists': '<i class="glyphicon glyphicon-list"></i>',
|
|
12
|
+
'link': '<i class="glyphicon glyphicon-link"></i>',
|
|
13
|
+
'alignment': '<i class="glyphicon glyphicon-align-left"></i>',
|
|
14
|
+
'horizontalrule': '<i class="glyphicon glyphicon-minus"></i>',
|
|
15
|
+
'image': '<i class="glyphicon glyphicon-picture"></i>',
|
|
16
|
+
'video': '<i class="glyphicon glyphicon-facetime-video"></i>',
|
|
17
|
+
'file': '<i class="glyphicon glyphicon-duplicate"></i>',
|
|
18
|
+
'table': '<i class="glyphicon glyphicon-th-large"></i>',
|
|
19
|
+
'fullscreen': '<i class="glyphicon glyphicon-fullscreen"></i>',
|
|
20
|
+
'clips': '<i class="glyphicon glyphicon-tags"></i>'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
$.each(this.button.all(), $.proxy(function(i,s)
|
|
24
|
+
{
|
|
25
|
+
var key = $(s).attr('rel');
|
|
26
|
+
|
|
27
|
+
if (typeof icons[key] !== 'undefined')
|
|
28
|
+
{
|
|
29
|
+
var icon = icons[key];
|
|
30
|
+
var button = this.button.get(key);
|
|
31
|
+
this.button.setIcon(button, icon);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}, this));
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
})(jQuery);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
if (!RedactorPlugins) var RedactorPlugins = {};
|
|
2
|
+
|
|
3
|
+
RedactorPlugins.pagebreak = function()
|
|
4
|
+
{
|
|
5
|
+
return {
|
|
6
|
+
langs: {
|
|
7
|
+
en: {
|
|
8
|
+
"insert-page-break": "Insert Page Break"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
init: function()
|
|
12
|
+
{
|
|
13
|
+
var $btn = this.button.add('pagebreak', this.lang.get('insert-page-break'));
|
|
14
|
+
this.button.addCallback($btn, this.pagebreak.insertPageBreak);
|
|
15
|
+
this.button.setIcon($btn, '<i class="icon"></i>');
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
insertPageBreak: function()
|
|
19
|
+
{
|
|
20
|
+
var $pagebreakNode = $('<hr class="redactor_pagebreak" style="display:none" unselectable="on" contenteditable="false" />'),
|
|
21
|
+
$currentNode = $(this.selection.current());
|
|
22
|
+
|
|
23
|
+
if ($currentNode.length && $.contains(this.$editor.get(0), $currentNode.get(0)))
|
|
24
|
+
{
|
|
25
|
+
// Find the closest element to div.redactor-editor
|
|
26
|
+
while ($currentNode.parent().length && !$currentNode.parent().is('div.redactor-editor'))
|
|
27
|
+
{
|
|
28
|
+
$currentNode = $currentNode.parent();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
$pagebreakNode.insertAfter($currentNode);
|
|
32
|
+
}
|
|
33
|
+
else
|
|
34
|
+
{
|
|
35
|
+
// Just append it to the end
|
|
36
|
+
$pagebreakNode.appendTo(this.$editor);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var $p = $('<p><br/></p>').insertAfter($pagebreakNode);
|
|
40
|
+
|
|
41
|
+
this.$editor.focus();
|
|
42
|
+
|
|
43
|
+
Garnish.requestAnimationFrame($.proxy(function()
|
|
44
|
+
{
|
|
45
|
+
this.code.sync();
|
|
46
|
+
}, this));
|
|
47
|
+
//this.setSelection($p[0], 0, $p[0], 0);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
(function($)
|
|
2
|
+
{
|
|
3
|
+
$.Redactor.prototype.source = function()
|
|
4
|
+
{
|
|
5
|
+
return {
|
|
6
|
+
init: function()
|
|
7
|
+
{
|
|
8
|
+
var button = this.button.addFirst('html', 'HTML');
|
|
9
|
+
this.button.addCallback(button, this.source.toggle);
|
|
10
|
+
|
|
11
|
+
var style = {
|
|
12
|
+
'width': '100%',
|
|
13
|
+
'margin': '0',
|
|
14
|
+
'background': '#111',
|
|
15
|
+
'box-sizing': 'border-box',
|
|
16
|
+
'color': 'rgba(255, 255, 255, .8)',
|
|
17
|
+
'font-size': '14px',
|
|
18
|
+
'outline': 'none',
|
|
19
|
+
'padding': '16px',
|
|
20
|
+
'line-height': '22px',
|
|
21
|
+
'font-family': 'Menlo, Monaco, Consolas, "Courier New", monospace'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.source.$textarea = $('<textarea />');
|
|
25
|
+
this.source.$textarea.css(style).hide();
|
|
26
|
+
|
|
27
|
+
if (this.opts.type === 'textarea')
|
|
28
|
+
{
|
|
29
|
+
this.core.box().append(this.source.$textarea);
|
|
30
|
+
}
|
|
31
|
+
else
|
|
32
|
+
{
|
|
33
|
+
this.core.box().after(this.source.$textarea);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.core.element().on('destroy.callback.redactor', $.proxy(function()
|
|
37
|
+
{
|
|
38
|
+
this.source.$textarea.remove();
|
|
39
|
+
|
|
40
|
+
}, this));
|
|
41
|
+
|
|
42
|
+
},
|
|
43
|
+
toggle: function()
|
|
44
|
+
{
|
|
45
|
+
return (this.source.$textarea.hasClass('open')) ? this.source.hide() : this.source.show();
|
|
46
|
+
},
|
|
47
|
+
setCaretOnShow: function()
|
|
48
|
+
{
|
|
49
|
+
this.source.offset = this.offset.get();
|
|
50
|
+
var scroll = $(window).scrollTop();
|
|
51
|
+
|
|
52
|
+
var width = this.core.editor().innerWidth();
|
|
53
|
+
var height = this.core.editor().innerHeight();
|
|
54
|
+
|
|
55
|
+
// caret position sync
|
|
56
|
+
this.source.start = 0;
|
|
57
|
+
this.source.end = 0;
|
|
58
|
+
var $editorDiv = $("<div/>").append($.parseHTML(this.core.editor().html(), document, true));
|
|
59
|
+
var $selectionMarkers = $editorDiv.find("span.redactor-selection-marker");
|
|
60
|
+
|
|
61
|
+
if ($selectionMarkers.length > 0)
|
|
62
|
+
{
|
|
63
|
+
var editorHtml = $editorDiv.html().replace(/&/g, '&');
|
|
64
|
+
|
|
65
|
+
if ($selectionMarkers.length === 1)
|
|
66
|
+
{
|
|
67
|
+
this.source.start = this.utils.strpos(editorHtml, $editorDiv.find("#selection-marker-1").prop("outerHTML"));
|
|
68
|
+
this.source.end = this.source.start;
|
|
69
|
+
}
|
|
70
|
+
else if ($selectionMarkers.length === 2)
|
|
71
|
+
{
|
|
72
|
+
this.source.start = this.utils.strpos(editorHtml, $editorDiv.find("#selection-marker-1").prop("outerHTML"));
|
|
73
|
+
this.source.end = this.utils.strpos(editorHtml, $editorDiv.find("#selection-marker-2").prop("outerHTML")) - $editorDiv.find("#selection-marker-1").prop("outerHTML").toString().length;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
},
|
|
78
|
+
setCaretOnHide: function(html)
|
|
79
|
+
{
|
|
80
|
+
this.source.start = this.source.$textarea.get(0).selectionStart;
|
|
81
|
+
this.source.end = this.source.$textarea.get(0).selectionEnd;
|
|
82
|
+
|
|
83
|
+
// if selection starts from end
|
|
84
|
+
if (this.source.start > this.source.end && this.source.end > 0)
|
|
85
|
+
{
|
|
86
|
+
var tempStart = this.source.end;
|
|
87
|
+
var tempEnd = this.source.start;
|
|
88
|
+
|
|
89
|
+
this.source.start = tempStart;
|
|
90
|
+
this.source.end = tempEnd;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.source.start = this.source.enlargeOffset(html, this.source.start);
|
|
94
|
+
this.source.end = this.source.enlargeOffset(html, this.source.end);
|
|
95
|
+
|
|
96
|
+
html = html.substr(0, this.source.start) + this.marker.html(1) + html.substr(this.source.start);
|
|
97
|
+
|
|
98
|
+
if (this.source.end > this.source.start)
|
|
99
|
+
{
|
|
100
|
+
var markerLength = this.marker.html(1).toString().length;
|
|
101
|
+
|
|
102
|
+
html = html.substr(0, this.source.end + markerLength) + this.marker.html(2) + html.substr(this.source.end + markerLength);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return html;
|
|
106
|
+
|
|
107
|
+
},
|
|
108
|
+
hide: function()
|
|
109
|
+
{
|
|
110
|
+
this.source.$textarea.removeClass('open').hide();
|
|
111
|
+
this.source.$textarea.off('.redactor-source');
|
|
112
|
+
|
|
113
|
+
var code = this.source.$textarea.val();
|
|
114
|
+
|
|
115
|
+
code = this.paragraphize.load(code);
|
|
116
|
+
code = this.source.setCaretOnHide(code);
|
|
117
|
+
|
|
118
|
+
this.code.start(code);
|
|
119
|
+
this.button.enableAll();
|
|
120
|
+
this.core.editor().show().focus();
|
|
121
|
+
this.selection.restore();
|
|
122
|
+
this.code.sync();
|
|
123
|
+
},
|
|
124
|
+
show: function()
|
|
125
|
+
{
|
|
126
|
+
this.selection.save();
|
|
127
|
+
this.source.setCaretOnShow();
|
|
128
|
+
|
|
129
|
+
var height = this.core.editor().innerHeight();
|
|
130
|
+
var code = this.code.get();
|
|
131
|
+
|
|
132
|
+
code = code.replace(/\n\n\n/g, "\n");
|
|
133
|
+
code = code.replace(/\n\n/g, "\n");
|
|
134
|
+
|
|
135
|
+
this.core.editor().hide();
|
|
136
|
+
this.button.disableAll('html');
|
|
137
|
+
this.source.$textarea.val(code).height(height).addClass('open').show();
|
|
138
|
+
this.source.$textarea.on('keyup.redactor-source', $.proxy(function()
|
|
139
|
+
{
|
|
140
|
+
if (this.opts.type === 'textarea')
|
|
141
|
+
{
|
|
142
|
+
this.core.textarea().val(this.source.$textarea.val());
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
}, this));
|
|
146
|
+
|
|
147
|
+
this.marker.remove();
|
|
148
|
+
|
|
149
|
+
$(window).scrollTop(scroll);
|
|
150
|
+
|
|
151
|
+
if (this.source.$textarea[0].setSelectionRange)
|
|
152
|
+
{
|
|
153
|
+
this.source.$textarea[0].setSelectionRange(this.source.start, this.source.end);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.source.$textarea[0].scrollTop = 0;
|
|
157
|
+
|
|
158
|
+
setTimeout($.proxy(function()
|
|
159
|
+
{
|
|
160
|
+
this.source.$textarea.focus();
|
|
161
|
+
|
|
162
|
+
}, this), 0);
|
|
163
|
+
},
|
|
164
|
+
enlargeOffset: function(html, offset)
|
|
165
|
+
{
|
|
166
|
+
var htmlLength = html.length;
|
|
167
|
+
var c = 0;
|
|
168
|
+
|
|
169
|
+
if (html[offset] === '>')
|
|
170
|
+
{
|
|
171
|
+
c++;
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
{
|
|
175
|
+
for(var i = offset; i <= htmlLength; i++)
|
|
176
|
+
{
|
|
177
|
+
c++;
|
|
178
|
+
|
|
179
|
+
if (html[i] === '>')
|
|
180
|
+
{
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
else if (html[i] === '<' || i === htmlLength)
|
|
184
|
+
{
|
|
185
|
+
c = 0;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return offset + c;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
})(jQuery);
|
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
(function($)
|
|
2
|
+
{
|
|
3
|
+
$.Redactor.prototype.table = function()
|
|
4
|
+
{
|
|
5
|
+
return {
|
|
6
|
+
langs: {
|
|
7
|
+
en: {
|
|
8
|
+
"table": "Table",
|
|
9
|
+
"insert-table": "Insert table",
|
|
10
|
+
"insert-row-above": "Insert row above",
|
|
11
|
+
"insert-row-below": "Insert row below",
|
|
12
|
+
"insert-column-left": "Insert column left",
|
|
13
|
+
"insert-column-right": "Insert column right",
|
|
14
|
+
"add-head": "Add head",
|
|
15
|
+
"delete-head": "Delete head",
|
|
16
|
+
"delete-column": "Delete column",
|
|
17
|
+
"delete-row": "Delete row",
|
|
18
|
+
"delete-table": "Delete table"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
init: function()
|
|
22
|
+
{
|
|
23
|
+
var dropdown = {};
|
|
24
|
+
|
|
25
|
+
dropdown.insert_table = {
|
|
26
|
+
title: this.lang.get('insert-table'),
|
|
27
|
+
func: this.table.insert,
|
|
28
|
+
observe: {
|
|
29
|
+
element: 'table',
|
|
30
|
+
in: {
|
|
31
|
+
attr: {
|
|
32
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
33
|
+
'aria-disabled': true,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
dropdown.insert_row_above = {
|
|
40
|
+
title: this.lang.get('insert-row-above'),
|
|
41
|
+
func: this.table.addRowAbove,
|
|
42
|
+
observe: {
|
|
43
|
+
element: 'table',
|
|
44
|
+
out: {
|
|
45
|
+
attr: {
|
|
46
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
47
|
+
'aria-disabled': true,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
dropdown.insert_row_below = {
|
|
54
|
+
title: this.lang.get('insert-row-below'),
|
|
55
|
+
func: this.table.addRowBelow,
|
|
56
|
+
observe: {
|
|
57
|
+
element: 'table',
|
|
58
|
+
out: {
|
|
59
|
+
attr: {
|
|
60
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
61
|
+
'aria-disabled': true,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
dropdown.insert_column_left = {
|
|
68
|
+
title: this.lang.get('insert-column-left'),
|
|
69
|
+
func: this.table.addColumnLeft,
|
|
70
|
+
observe: {
|
|
71
|
+
element: 'table',
|
|
72
|
+
out: {
|
|
73
|
+
attr: {
|
|
74
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
75
|
+
'aria-disabled': true,
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
dropdown.insert_column_right = {
|
|
82
|
+
title: this.lang.get('insert-column-right'),
|
|
83
|
+
func: this.table.addColumnRight,
|
|
84
|
+
observe: {
|
|
85
|
+
element: 'table',
|
|
86
|
+
out: {
|
|
87
|
+
attr: {
|
|
88
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
89
|
+
'aria-disabled': true,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
dropdown.add_head = {
|
|
96
|
+
title: this.lang.get('add-head'),
|
|
97
|
+
func: this.table.addHead,
|
|
98
|
+
observe: {
|
|
99
|
+
element: 'table',
|
|
100
|
+
out: {
|
|
101
|
+
attr: {
|
|
102
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
103
|
+
'aria-disabled': true,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
dropdown.delete_head = {
|
|
110
|
+
title: this.lang.get('delete-head'),
|
|
111
|
+
func: this.table.deleteHead,
|
|
112
|
+
observe: {
|
|
113
|
+
element: 'table',
|
|
114
|
+
out: {
|
|
115
|
+
attr: {
|
|
116
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
117
|
+
'aria-disabled': true,
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
dropdown.delete_column = {
|
|
124
|
+
title: this.lang.get('delete-column'),
|
|
125
|
+
func: this.table.deleteColumn,
|
|
126
|
+
observe: {
|
|
127
|
+
element: 'table',
|
|
128
|
+
out: {
|
|
129
|
+
attr: {
|
|
130
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
131
|
+
'aria-disabled': true,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
dropdown.delete_row = {
|
|
138
|
+
title: this.lang.get('delete-row'),
|
|
139
|
+
func: this.table.deleteRow,
|
|
140
|
+
observe: {
|
|
141
|
+
element: 'table',
|
|
142
|
+
out: {
|
|
143
|
+
attr: {
|
|
144
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
145
|
+
'aria-disabled': true,
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
dropdown.delete_table = {
|
|
152
|
+
title: this.lang.get('delete-table'),
|
|
153
|
+
func: this.table.deleteTable,
|
|
154
|
+
observe: {
|
|
155
|
+
element: 'table',
|
|
156
|
+
out: {
|
|
157
|
+
attr: {
|
|
158
|
+
'class': 'redactor-dropdown-link-inactive',
|
|
159
|
+
'aria-disabled': true,
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
var button = this.button.addBefore('link', 'table', this.lang.get('table'));
|
|
167
|
+
this.button.addDropdown(button, dropdown);
|
|
168
|
+
},
|
|
169
|
+
insert: function()
|
|
170
|
+
{
|
|
171
|
+
if (this.table.getTable())
|
|
172
|
+
{
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
this.placeholder.hide();
|
|
177
|
+
|
|
178
|
+
var rows = 2;
|
|
179
|
+
var columns = 3;
|
|
180
|
+
var $tableBox = $('<div>');
|
|
181
|
+
var $table = $('<table />');
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
for (var i = 0; i < rows; i++)
|
|
185
|
+
{
|
|
186
|
+
var $row = $('<tr>');
|
|
187
|
+
|
|
188
|
+
for (var z = 0; z < columns; z++)
|
|
189
|
+
{
|
|
190
|
+
var $column = $('<td>' + this.opts.invisibleSpace + '</td>');
|
|
191
|
+
|
|
192
|
+
// set the focus to the first td
|
|
193
|
+
if (i === 0 && z === 0)
|
|
194
|
+
{
|
|
195
|
+
$column.append(this.marker.get());
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
$($row).append($column);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
$table.append($row);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
$tableBox.append($table);
|
|
205
|
+
var html = $tableBox.html();
|
|
206
|
+
|
|
207
|
+
this.buffer.set();
|
|
208
|
+
|
|
209
|
+
var current = this.selection.current();
|
|
210
|
+
if ($(current).closest('li').length !== 0)
|
|
211
|
+
{
|
|
212
|
+
$(current).closest('ul, ol').first().after(html);
|
|
213
|
+
}
|
|
214
|
+
else
|
|
215
|
+
{
|
|
216
|
+
this.air.collapsed();
|
|
217
|
+
this.insert.html(html);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
this.selection.restore();
|
|
221
|
+
this.core.callback('insertedTable', $table);
|
|
222
|
+
},
|
|
223
|
+
getTable: function()
|
|
224
|
+
{
|
|
225
|
+
var $table = $(this.selection.current()).closest('table');
|
|
226
|
+
|
|
227
|
+
if (!this.utils.isRedactorParent($table))
|
|
228
|
+
{
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if ($table.size() === 0)
|
|
233
|
+
{
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return $table;
|
|
238
|
+
},
|
|
239
|
+
restoreAfterDelete: function($table)
|
|
240
|
+
{
|
|
241
|
+
this.selection.restore();
|
|
242
|
+
$table.find('span.redactor-selection-marker').remove();
|
|
243
|
+
|
|
244
|
+
},
|
|
245
|
+
deleteTable: function()
|
|
246
|
+
{
|
|
247
|
+
var $table = this.table.getTable();
|
|
248
|
+
if (!$table)
|
|
249
|
+
{
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
this.buffer.set();
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
var $next = $table.next();
|
|
257
|
+
if (!this.opts.linebreaks && $next.length !== 0)
|
|
258
|
+
{
|
|
259
|
+
this.caret.start($next);
|
|
260
|
+
}
|
|
261
|
+
else
|
|
262
|
+
{
|
|
263
|
+
this.caret.after($table);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
$table.remove();
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
},
|
|
271
|
+
deleteRow: function()
|
|
272
|
+
{
|
|
273
|
+
var $table = this.table.getTable();
|
|
274
|
+
if (!$table)
|
|
275
|
+
{
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
var $current = $(this.selection.current());
|
|
280
|
+
|
|
281
|
+
this.buffer.set();
|
|
282
|
+
|
|
283
|
+
var $current_tr = $current.closest('tr');
|
|
284
|
+
var $focus_tr = $current_tr.prev().length ? $current_tr.prev() : $current_tr.next();
|
|
285
|
+
if ($focus_tr.length)
|
|
286
|
+
{
|
|
287
|
+
var $focus_td = $focus_tr.children('td, th').first();
|
|
288
|
+
if ($focus_td.length)
|
|
289
|
+
{
|
|
290
|
+
$focus_td.prepend(this.marker.get());
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
$current_tr.remove();
|
|
295
|
+
this.table.restoreAfterDelete($table);
|
|
296
|
+
},
|
|
297
|
+
deleteColumn: function()
|
|
298
|
+
{
|
|
299
|
+
var $table = this.table.getTable();
|
|
300
|
+
if (!$table)
|
|
301
|
+
{
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
this.buffer.set();
|
|
306
|
+
|
|
307
|
+
var $current = $(this.selection.current());
|
|
308
|
+
var $current_td = $current.closest('td, th');
|
|
309
|
+
var index = $current_td[0].cellIndex;
|
|
310
|
+
|
|
311
|
+
$table.find('tr').each($.proxy(function(i, elem)
|
|
312
|
+
{
|
|
313
|
+
var $elem = $(elem);
|
|
314
|
+
var focusIndex = index - 1 < 0 ? index + 1 : index - 1;
|
|
315
|
+
if (i === 0)
|
|
316
|
+
{
|
|
317
|
+
$elem.find('td, th').eq(focusIndex).prepend(this.marker.get());
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
$elem.find('td, th').eq(index).remove();
|
|
321
|
+
|
|
322
|
+
}, this));
|
|
323
|
+
|
|
324
|
+
this.table.restoreAfterDelete($table);
|
|
325
|
+
},
|
|
326
|
+
addHead: function()
|
|
327
|
+
{
|
|
328
|
+
var $table = this.table.getTable();
|
|
329
|
+
if (!$table)
|
|
330
|
+
{
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
this.buffer.set();
|
|
335
|
+
|
|
336
|
+
if ($table.find('thead').size() !== 0)
|
|
337
|
+
{
|
|
338
|
+
this.table.deleteHead();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
var tr = $table.find('tr').first().clone();
|
|
343
|
+
tr.find('td').replaceWith($.proxy(function()
|
|
344
|
+
{
|
|
345
|
+
return $('<th>').html(this.opts.invisibleSpace);
|
|
346
|
+
}, this));
|
|
347
|
+
|
|
348
|
+
$thead = $('<thead></thead>').append(tr);
|
|
349
|
+
$table.prepend($thead);
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
},
|
|
354
|
+
deleteHead: function()
|
|
355
|
+
{
|
|
356
|
+
var $table = this.table.getTable();
|
|
357
|
+
if (!$table)
|
|
358
|
+
{
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
var $thead = $table.find('thead');
|
|
363
|
+
if ($thead.size() === 0)
|
|
364
|
+
{
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
this.buffer.set();
|
|
369
|
+
|
|
370
|
+
$thead.remove();
|
|
371
|
+
|
|
372
|
+
},
|
|
373
|
+
addRowAbove: function()
|
|
374
|
+
{
|
|
375
|
+
this.table.addRow('before');
|
|
376
|
+
},
|
|
377
|
+
addRowBelow: function()
|
|
378
|
+
{
|
|
379
|
+
this.table.addRow('after');
|
|
380
|
+
},
|
|
381
|
+
addColumnLeft: function()
|
|
382
|
+
{
|
|
383
|
+
this.table.addColumn('before');
|
|
384
|
+
},
|
|
385
|
+
addColumnRight: function()
|
|
386
|
+
{
|
|
387
|
+
this.table.addColumn('after');
|
|
388
|
+
},
|
|
389
|
+
addRow: function(type)
|
|
390
|
+
{
|
|
391
|
+
var $table = this.table.getTable();
|
|
392
|
+
if (!$table)
|
|
393
|
+
{
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
this.buffer.set();
|
|
398
|
+
|
|
399
|
+
var $current = $(this.selection.current());
|
|
400
|
+
var $current_tr = $current.closest('tr');
|
|
401
|
+
var new_tr = $current_tr.clone();
|
|
402
|
+
|
|
403
|
+
new_tr.find('th').replaceWith(function()
|
|
404
|
+
{
|
|
405
|
+
var $td = $('<td>');
|
|
406
|
+
$td[0].attributes = this.attributes;
|
|
407
|
+
|
|
408
|
+
return $td.append($(this).contents());
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
new_tr.find('td').html(this.opts.invisibleSpace);
|
|
412
|
+
|
|
413
|
+
if (type === 'after')
|
|
414
|
+
{
|
|
415
|
+
$current_tr.after(new_tr);
|
|
416
|
+
}
|
|
417
|
+
else
|
|
418
|
+
{
|
|
419
|
+
$current_tr.before(new_tr);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
},
|
|
424
|
+
addColumn: function (type)
|
|
425
|
+
{
|
|
426
|
+
var $table = this.table.getTable();
|
|
427
|
+
if (!$table)
|
|
428
|
+
{
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
var index = 0;
|
|
433
|
+
var current = $(this.selection.current());
|
|
434
|
+
|
|
435
|
+
this.buffer.set();
|
|
436
|
+
|
|
437
|
+
var $current_tr = current.closest('tr');
|
|
438
|
+
var $current_td = current.closest('td, th');
|
|
439
|
+
|
|
440
|
+
$current_tr.find('td, th').each($.proxy(function(i, elem)
|
|
441
|
+
{
|
|
442
|
+
if ($(elem)[0] === $current_td[0])
|
|
443
|
+
{
|
|
444
|
+
index = i;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
}, this));
|
|
448
|
+
|
|
449
|
+
$table.find('tr').each($.proxy(function(i, elem)
|
|
450
|
+
{
|
|
451
|
+
var $current = $(elem).find('td, th').eq(index);
|
|
452
|
+
|
|
453
|
+
var td = $current.clone();
|
|
454
|
+
td.html(this.opts.invisibleSpace);
|
|
455
|
+
|
|
456
|
+
if (type === 'after')
|
|
457
|
+
{
|
|
458
|
+
$current.after(td);
|
|
459
|
+
}
|
|
460
|
+
else
|
|
461
|
+
{
|
|
462
|
+
$current.before(td);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
}, this));
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
};
|
|
471
|
+
})(jQuery);
|