Skip to content

Commit

Permalink
- Fixed: Editor mode handling.
Browse files Browse the repository at this point in the history
- Fixed: Plugin loads files of editor only if they are really needed.
- Added: "Markdown" syntax for mime type "text/x-markdown".
Version 1.6.2-pl
  • Loading branch information
bezumkin committed Aug 9, 2015
1 parent c1c9cda commit f1d56d0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 41 deletions.
2 changes: 1 addition & 1 deletion _build/build.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

define('PKG_NAME','Ace');
define('PKG_NAMESPACE','ace');
define('PKG_VERSION','1.6.1');
define('PKG_VERSION','1.6.2');
define('PKG_RELEASE','pl');
define('PKG_AUTO_INSTALL', true);

Expand Down
1 change: 1 addition & 0 deletions assets/components/ace/ace/mode-markdown.js

Large diffs are not rendered by default.

43 changes: 23 additions & 20 deletions assets/components/ace/modx.texteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,14 @@ MODx.ux.Ace = Ext.extend(Ext.ux.Ace, {
}
});

MODx.ux.Ace.replaceComponent = function(id, mimeType, modxTags, mode) {
MODx.ux.Ace.replaceComponent = function(id, mimeType, modxTags) {
var textArea = Ext.getCmp(id);
if (!textArea) {
// Workaround for File Update panel (fix issue, caused by wrong event order)
return setTimeout(function() {
var textArea = Ext.getCmp(id);
if (textArea)
MODx.ux.Ace.replaceComponent(id, mimeType, modxTags, mode);
MODx.ux.Ace.replaceComponent(id, mimeType, modxTags);
});
}
var textEditor = MODx.load({
Expand All @@ -445,7 +445,6 @@ MODx.ux.Ace.replaceComponent = function(id, mimeType, modxTags, mode) {
name: textArea.name,
value: textArea.getValue(),
mimeType: mimeType,
mode: mode || 'text',
modxTags: modxTags
});

Expand All @@ -471,7 +470,7 @@ MODx.ux.Ace.replaceComponent = function(id, mimeType, modxTags, mode) {
textArea.on('destroy', function() {dropTarget.destroy();});
};

MODx.ux.Ace.replaceTextAreas = function(textAreas, mimeType, mode) {
MODx.ux.Ace.replaceTextAreas = function(textAreas, mimeType) {
textAreas.forEach(function(textArea){
var editor = MODx.load({
xtype: 'modx-texteditor',
Expand All @@ -480,7 +479,6 @@ MODx.ux.Ace.replaceTextAreas = function(textAreas, mimeType, mode) {
name: textArea.name,
value: textArea.value,
mimeType: mimeType || 'text/html',
mode: mode || 'text',
modxTags: true
});

Expand Down Expand Up @@ -708,6 +706,9 @@ MODx.ux.Ace.createModxMixedMode = function(Mode) {

this.HighlightRules = ModxMixedHighlightRules;

if (typeof this.$behaviour == 'undefined') {
var Behaviour = ace.require("ace/mode/behaviour").Behaviour;
}
this.$behaviour = Object.create(this.$behaviour || new Behaviour());

this.$behaviour.add("brackets", "insertion", function (state, action, editor, session, text) {
Expand Down Expand Up @@ -822,21 +823,23 @@ MODx.ux.Ace.createModxMixedMode = function(Mode) {
};

MODx.ux.Ace.mimeTypes = {
'text/x-php' : 'php'
,'application/x-php' : 'php'
,'text/x-sql' : 'sql'
,'text/x-scss' : 'scss'
,'text/x-less' : 'less'
,'text/xml' : 'xml'
,'application/xml' : 'xml'
,'image/svg+xml' : 'svg'
,'text/html' : 'html'
,'application/xhtml+xml' : 'html'
,'text/javascript' : 'javascript'
,'application/javascript': 'javascript'
,'application/json' : 'json'
,'text/css' : 'css'
,'text/plain' : 'text'
'text/x-smarty' : 'smarty',
'text/html' : 'html',
'application/xhtml+xml' : 'html',
'text/css' : 'css',
'text/x-scss' : 'scss',
'text/x-less' : 'less',
'image/svg+xml' : 'svg',
'application/xml' : 'xml',
'text/xml' : 'xml',
'text/javascript' : 'javascript',
'application/javascript': 'javascript',
'application/json' : 'json',
'text/x-php' : 'php',
'application/x-php' : 'php',
'text/x-sql' : 'sql',
'text/x-markdown' : 'markdown',
'text/plain' : 'text',
};

MODx.ux.Ace.initialized = false;
Expand Down
6 changes: 6 additions & 0 deletions core/components/ace/documents/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Changelog for Ace integration into MODx Revolution.

Ace 1.6.2
====================================
- Fixed: Editor mode handling.
- Fixed: Plugin loads files of editor only if they are really needed.
- Added: "Markdown" syntax for mime type "text/x-markdown".

Ace 1.6.1
====================================
- Fixed : Work with enabled system setting "compress_js".
Expand Down
41 changes: 21 additions & 20 deletions core/components/ace/elements/plugins/ace.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* @author Danil Kostin <danya.postfactum(at)gmail.com>
*
* @package ace
*
* @var array $scriptProperties
*/
if ($modx->event->name == 'OnRichTextEditorRegister') {
$modx->event->output('Ace');
Expand All @@ -19,12 +21,8 @@
return;
}

$ace = $modx->getService('ace', 'Ace', $modx->getOption('ace.core_path', null, $modx->getOption('core_path').'components/ace/').'model/ace/');

$ace->initialize();

$extensionMap = array(
'tpl' => 'text/html',
'tpl' => 'text/x-smarty',
'htm' => 'text/html',
'html' => 'text/html',
'css' => 'text/css',
Expand All @@ -37,24 +35,23 @@
'json' => 'application/json',
'php' => 'application/x-php',
'sql' => 'text/x-sql',
'md' => 'text/x-markdown',
'txt' => 'text/plain',
);

// Defines wether we should highlight modx tags
$modxTags = false;
$mode = '';
switch ($modx->event->name) {
case 'OnSnipFormPrerender':
$field = 'modx-snippet-snippet';
$mimeType = 'application/x-php';
break;
case 'OnTempFormPrerender':
$field = 'modx-template-content';
$mimeType = 'text/html';
$modxTags = true;
if ($modx->getOption('pdotools_fenom_parser')) {
$mode = 'smarty';
}
$mimeType = $modx->getOption('pdotools_fenom_parser')
? 'text/x-smarty'
: 'text/html';
break;
case 'OnChunkFormPrerender':
$field = 'modx-chunk-snippet';
Expand All @@ -65,9 +62,9 @@
$mimeType = 'text/html';
}
$modxTags = true;
if ($modx->getOption('pdotools_fenom_default')) {
$mode = 'smarty';
}
$mimeType = $modx->getOption('pdotools_fenom_default')
? 'text/x-smarty'
: 'text/html';
break;
case 'OnPluginFormPrerender':
$field = 'modx-plugin-plugincode';
Expand All @@ -80,7 +77,9 @@
case 'OnFileEditFormPrerender':
$field = 'modx-file-content';
$extension = pathinfo($scriptProperties['file'], PATHINFO_EXTENSION);
$mimeType = isset($extensionMap[$extension]) ? $extensionMap[$extension] : 'text/plain';
$mimeType = isset($extensionMap[$extension])
? $extensionMap[$extension]
: 'text/plain';
$modxTags = $extension == 'tpl';
break;
case 'OnDocFormPrerender':
Expand All @@ -89,6 +88,9 @@
}
$field = 'ta';
$mimeType = $modx->getObject('modContentType', $modx->controller->resourceArray['content_type'])->get('mime_type');
if ($mimeType == 'text/html' && $modx->getOption('pdotools_fenom_parser')) {
$mimeType = 'text/x-smarty';
}
if ($modx->getOption('use_editor')){
$richText = $modx->controller->resourceArray['richtext'];
$classKey = $modx->controller->resourceArray['class_key'];
Expand All @@ -97,25 +99,24 @@
}
}
$modxTags = true;
if ($modx->getOption('pdotools_fenom_parser')) {
$mode = 'smarty';
}
break;
default:
return;
}

$modxTags = (int) $modxTags;
$script = "";
$script = '';
if ($field) {
$script .= "MODx.ux.Ace.replaceComponent('$field', '$mimeType', $modxTags, '$mode');";
$script .= "MODx.ux.Ace.replaceComponent('$field', '$mimeType', $modxTags);";
}

if ($modx->event->name == 'OnDocFormPrerender' && !$modx->getOption('use_editor')) {
$script .= "MODx.ux.Ace.replaceTextAreas(Ext.query('.modx-richtext'));";
}

if ($script) {
//$modx->controller->addHtml('<style>.ace_editor {width: 100% !important;}</style>');
/** @var Ace $ace */
$ace = $modx->getService('ace', 'Ace', $modx->getOption('ace.core_path', null, $modx->getOption('core_path').'components/ace/').'model/ace/');
$ace->initialize();
$modx->controller->addHtml('<script>Ext.onReady(function() {' . $script . '});</script>');
}

0 comments on commit f1d56d0

Please sign in to comment.