forked from katrinkerber/statamic-ckeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.ckeditor.php
More file actions
executable file
·56 lines (42 loc) · 1.5 KB
/
hooks.ckeditor.php
File metadata and controls
executable file
·56 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
class Hooks_ckeditor extends Hooks {
public function control_panel__add_to_head()
{
if (URL::getCurrent(false) == '/publish') {
return $this->css->link('contents.css');
}
}
public function control_panel__add_to_foot()
{
if (URL::getCurrent(false) == '/publish') {
$html = $this->js->link('ckeditor.js');
$html .= "<script>
function initiateCKEditors() {
$('.ckeditor').each(function(){
CKEDITOR.replace( $(this).attr('name') );
});
}
// initiate CKEditor for field(s) in a newly added grid row
function newRowEditor() {
// get the right grid field for the clicked 'add row' button
var thisGridTable = $(this).siblings('table.grid');
setTimeout(function() {
// select ckeditor cell in new row
var newRowCell = thisGridTable.find('tbody tr:last td.cell-ckeditor');
// double-check that new row doesn't contain editor already
if ( newRowCell.not(':has(div.cke)') ) {
newRowCell.find('textarea.ckeditor').each(function(){
CKEDITOR.replace( $(this).attr('name') );
});
}
}, 50);
}
$(document).ready(function() {
initiateCKEditors();
$('.grid-add-row').click(newRowEditor);
});
</script>";
return $html;
}
}
}