Skip to content

Commit fcedd35

Browse files
committed
Enable word wrapping and update README
1 parent 5350a73 commit fcedd35

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class MyPage extends Page {
2626
public function getCMSFields() {
2727
$fields=parent::getCMSFields();
2828

29-
$fields->addFieldToTab("Root.Main", new MarkdownEditor('MarkdownContent', 'Page Content (Markdown)'));
29+
$editor = new MarkdownEditor('MarkdownContent', 'Page Content (Markdown)');
30+
$editor->setRows(15); //optional, set number of rows in CMS
31+
$editor->setWrapMode(true); //optional, turn on word wrapping
32+
$fields->addFieldToTab("Root.Main", $editor);
3033

3134
return $fields;
3235
}

code/forms/MarkdownEditor.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<?php
22
class MarkdownEditor extends TextareaField {
33
protected $rows=30;
4+
5+
protected $wrap_mode=false;
6+
7+
/**
8+
* Sets the "Wrap Mode" on the ACE editor markdown field.
9+
* @param boolean $mode True if word wrap should be enabled, false if not
10+
*/
11+
public function setWrapMode($mode = false) {
12+
$this->wrap_mode=$mode;
13+
return $this;
14+
}
415

516
/**
617
* Returns the field holder used by templates
@@ -29,8 +40,9 @@ public function getAttributes() {
2940
parent::getAttributes(),
3041
array(
3142
'style'=>'width: 97%; max-width: 100%; height: '.($this->rows * 16).'px; resize: none;', // prevents horizontal scrollbars
43+
'wrap-mode'=>($this->wrap_mode) ? "true" : "false"
3244
)
3345
);
34-
}
46+
}
3547
}
3648
?>

javascript/MarkdownEditor.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
TextArea: null,
55
Div: null,
66
Editor: null,
7-
Frame: null,
8-
WrapMode: false,
7+
Frame: null,
98
SoftTabs: true,
109
onmatch: function() {
1110
$(this).setFrame({
@@ -18,7 +17,7 @@
1817

1918
var div=$('<div id="'+$(this).attr('ID')+'_Editor" class="markdowneditor_editor"/>').css('height', $(this).getFrame().height).css('width', $(this).getFrame().width).text($(this).val());
2019
div.insertAfter($(this));
21-
$(this).setDiv(div);
20+
$(this).setDiv(div);
2221

2322
var editor=ace.edit(div.get(0));
2423
editor.getSession().setMode('ace/mode/markdown');
@@ -31,7 +30,7 @@
3130
var code=$(this).val();
3231
$(this).setUseSoftTabs($(this).usesSoftTabs(code));
3332
$(this).setTabSize($(this).getSoftTabs() ? $(this).guessTabSize(code):8);
34-
$(this).setUseWrapMode($(this).getWrapMode());
33+
$(this).setUseWrapMode($(this).attr("wrap-mode") == "true");
3534
$(this).setupFormBindings();
3635
$(this).setupHacks();
3736
},

0 commit comments

Comments
 (0)