Skip to content

Instantly share code, notes, and snippets.

@Sentinel-7
Created December 19, 2017 07:04
Show Gist options
  • Save Sentinel-7/47e4a2351102f86d7d967880e18cd96a to your computer and use it in GitHub Desktop.
Save Sentinel-7/47e4a2351102f86d7d967880e18cd96a to your computer and use it in GitHub Desktop.
AceTv plugin для подсветки кода
//там ещё RTE подключается для определенные категорий ресуров)
//создаем плагин AceTv, событие на «OnDocFormRender» с кодом:
$script = '';
$resource = ($resource instanceof modResource)
?
$modx->getObject('modResource',$resource->get('id'))
: $modx->getObject('modResource',(int)$resource);
// ACE
// Настройка под определенный тв-параметр в шаблоне
$templates_enable = array( // [id-шаблона] => array('tv[id-тв]')
'3' => array('tv14'),
'4' => array('tv14')
);
if ( $resource instanceof modResource && array_key_exists($resource->get('template'), $templates_enable) ) {
$script .= 'if (MODx.ux.Ace.replaceTextAreas) {';
foreach ($templates_enable[$resource->get('template')] as $tv) {
$script .= 'MODx.ux.Ace.replaceTextAreas(Ext.query("textarea#' . $tv . '"));';
}
$script .= '}';
}
$modx->regClientStartupHTMLBlock('<script>Ext.onReady(function(){' . $script . '})</script>');
//id шаблонов и тв-параметров находятся в скобках в дереве элементов.
$resource = ($resource instanceof modResource)
?
$modx->getObject('modResource',$resource->get('id'))
: $modx->getObject('modResource',(int)$resource);
if ( $resource instanceof modResource ) {
$modx->regClientStartupHTMLBlock('
<script>
Ext.onReady(function(){
if (MODx.ux.Ace.replaceTextAreas) {
MODx.ux.Ace.replaceTextAreas(Ext.query(".x-form-textarea"));
}
})
</script>
');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment