This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code tidy up and minor JavaScript bug fixes:
* Trigger the preview to update when using shortcut buttons * [#7]: Target the respective toolbar instead of using a class selector * [#8]: Convert to start using PSR-2
- Loading branch information
1 parent
ef02b54
commit 653c997
Showing
9 changed files
with
258 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,96 @@ | ||
<?php | ||
/** | ||
* Configure the input field for markdown | ||
*/ | ||
class MarkdownTextareaField extends TextareaField | ||
{ | ||
/** | ||
* Define the actions allowed on this field | ||
* @var array | ||
*/ | ||
private static $allowed_actions = array( | ||
'preview', | ||
'parse' | ||
); | ||
|
||
/** | ||
* @var int Visible number of text lines. | ||
* Default on TextareaField is too small | ||
*/ | ||
protected $rows = 15; | ||
|
||
class MarkdownTextareaField extends TextareaField { | ||
|
||
/** | ||
* Define the actions allowed on this field | ||
* @var array | ||
*/ | ||
private static $allowed_actions = array( | ||
'preview', | ||
'parse' | ||
); | ||
|
||
/** | ||
* @var int Visible number of text lines. | ||
* Default on TextareaField is too small | ||
*/ | ||
protected $rows = 15; | ||
|
||
/** | ||
* Toggle rendering markdown with extra syntax enabled. | ||
* @link http://michelf.ca/projects/php-markdown/extra | ||
* @var boolean | ||
*/ | ||
protected $enable_extra = false; | ||
/** | ||
* Toggle rendering markdown with extra syntax enabled. | ||
* @link http://michelf.ca/projects/php-markdown/extra | ||
* @var boolean | ||
*/ | ||
protected $enable_extra = false; | ||
|
||
/** | ||
/** | ||
* Returns the field holder used by templates | ||
* @return string HTML to be used | ||
* | ||
* @param array $properties | ||
* @return string HTML to be used | ||
*/ | ||
public function FieldHolder($properties = array()) { | ||
$this->extraClasses['stacked'] = 'stacked'; | ||
public function FieldHolder($properties = array()) | ||
{ | ||
$this->extraClasses['stacked'] = 'stacked'; | ||
|
||
Requirements::css('markdowntextareafield/templates/css/styles.css'); | ||
Requirements::css(MARKDOWN_DIR . '/templates/css/styles.css'); | ||
|
||
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); | ||
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); | ||
Requirements::javascript('markdowntextareafield/thirdparty/textinputs_jquery.js'); | ||
Requirements::javascript('markdowntextareafield/templates/javascript/script.js'); | ||
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); | ||
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); | ||
Requirements::javascript(MARKDOWN_DIR . '/thirdparty/textinputs_jquery.js'); | ||
Requirements::javascript(MARKDOWN_DIR . '/templates/javascript/script.js'); | ||
|
||
return parent::FieldHolder($properties); | ||
return parent::FieldHolder($properties); | ||
} | ||
|
||
/** | ||
* Turn on extra syntax support | ||
* @return MarkdownTextareaField | ||
*/ | ||
public function enableExtra() { | ||
$this->enable_extra = true; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* Body for the preview iframe with just the typography styles included | ||
* @return string html | ||
*/ | ||
public function preview() { | ||
Requirements::clear(); | ||
// Should contain text styles of the page by Silverstripe theme conventions. | ||
Requirements::css('themes/' . Config::inst()->get('SSViewer', 'theme') . '/css/editor.css'); | ||
return $this->renderWith('PreviewFrame'); | ||
} | ||
/** | ||
* Turn on extra syntax support | ||
* @return MarkdownTextareaField | ||
*/ | ||
public function enableExtra() | ||
{ | ||
$this->enable_extra = true; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Parse markdown into html | ||
* @return string html | ||
*/ | ||
public function parse() { | ||
$parser = new MarkdownParser($this->request['markdown']); | ||
/** | ||
* Body for the preview iframe with just the typography styles included | ||
* @return string html | ||
*/ | ||
public function preview() | ||
{ | ||
Requirements::clear(); | ||
// Should contain text styles of the page by Silverstripe theme conventions. | ||
Requirements::css('themes/' . Config::inst()->get('SSViewer', 'theme') . '/css/editor.css'); | ||
return $this->renderWith('PreviewFrame'); | ||
} | ||
|
||
return ($this->enable_extra) ? $parser->parseExtra() : $parser->parse(); | ||
} | ||
/** | ||
* Parse markdown into html | ||
* @return string html | ||
*/ | ||
public function parse() | ||
{ | ||
$parser = new MarkdownParser($this->request['markdown']); | ||
|
||
/** | ||
* Get buttons described in buttons.yml and wrap them in ViewableData | ||
* @return ArrayList list of buttons and theyr configurations | ||
*/ | ||
public function ToolbarButtons() { | ||
$buttons = new ArrayList(); | ||
return ($this->enable_extra) ? $parser->parseExtra() : $parser->parse(); | ||
} | ||
|
||
foreach($this->config()->get('buttons') as $button) { | ||
$buttons->push(new ArrayData($button)); | ||
} | ||
/** | ||
* Get buttons described in buttons.yml and wrap them in ViewableData | ||
* @return ArrayList list of buttons and theyr configurations | ||
*/ | ||
public function ToolbarButtons() | ||
{ | ||
$buttons = new ArrayList(); | ||
|
||
return $buttons; | ||
} | ||
foreach ($this->config()->get('buttons') as $button) { | ||
$buttons->push(new ArrayData($button)); | ||
} | ||
|
||
return $buttons; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Preview</title> | ||
<meta charset="UTF-8"> | ||
<title>Preview</title> | ||
</head> | ||
<body> | ||
</body> | ||
</html> | ||
</html> |
Oops, something went wrong.