Created
August 10, 2017 09:19
-
-
Save ig0r74/1cd74e05ddb5b1ebef2f1325adc7ca8f to your computer and use it in GitHub Desktop.
ACE Editot TV-type. Plugin listen OnDocFormRender event and must be execute after Ace plugin, so set priority something like 10 or higher. TV type must be textarea.
This file contains hidden or 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
| <?php | |
| //Apply ace editor to TV with id 5 and 7 | |
| $tvs = array( | |
| array( | |
| 'id' => 5, | |
| 'height' => '600px', | |
| 'mimeType' => 'application/json' | |
| ), | |
| array( | |
| 'id' => 7, | |
| 'height' => '300px', | |
| 'mimeType' => 'text/html' | |
| ) | |
| ); | |
| if ($modx->event->name != 'OnDocFormRender') { | |
| return; | |
| } | |
| if ($modx->getOption('which_element_editor', null, 'Ace') !== 'Ace') { | |
| return; | |
| } | |
| $script = ''; | |
| foreach ($tvs as $tv) { | |
| $id = is_array($tv) ? $tv['id'] : $tv; | |
| $height = isset($tv['height']) ? $tv['height'] : ''; | |
| $mimeType = isset($tv['mimeType']) ? $tv['mimeType'] : ''; | |
| $tvId = '#tv' . $id; | |
| $setHeightScript = !empty($height) ? 'this.style.height="' . $height . '";' : ''; | |
| $aceScript = 'MODx.ux.Ace.replaceTextAreas([this], "' . $mimeType . '");'; | |
| $script .= 'Ext.each(Ext.query("' . $tvId . '"), function() { ' . $setHeightScript . $aceScript . '});' . PHP_EOL; | |
| } | |
| if ($script) { | |
| $modx->controller->addHtml('<script>Ext.onReady(function() {' . $script . '});</script>'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment