Skip to content

Instantly share code, notes, and snippets.

@matdave
Last active June 4, 2017 14:01
Show Gist options
  • Save matdave/531d29b5d44178357bc4d94575096670 to your computer and use it in GitHub Desktop.
Save matdave/531d29b5d44178357bc4d94575096670 to your computer and use it in GitHub Desktop.
MODX Rich Introtext w/ Toggle
<?php
/*
** richIntro
** Plugin checks if introtext is filled in yet, and hides it if not. Run 'onDocFormRender'
** http://g.recordit.co/VOYqBC3CnS.gif
*/
$introtext = empty($resource->get('introtext'));
if($introtext){
$modx->regClientStartupHTMLBlock('<script>Ext.onReady(function() {
var introtext = Ext.getCmp("modx-resource-introtext");
introtext.hide();});
</script>');
}else{
$modx->regClientStartupHTMLBlock('<script>Ext.onReady(function() {
if(MODx.loadRTE) MODx.loadRTE("modx-resource-introtext");
});</script>');
}
$modx->regClientStartupHTMLBlock('<style type="text/css">#x-form-el-modx-resource-introtext{width: 100%; overflow:hidden;}</style>');
$modx->regClientStartupHTMLBlock('<script>Ext.onReady(function() {
var group = Ext.getCmp("modx-resource-main-right");
var checkbox = new Ext.form.Checkbox({boxLabel:"Hide Introtext", id:"hide-introtext", hideLabel:true, checked: '.($introtext ? 'true':'false').', listeners:{
\'check\': function(t,n,o){
var introtext = Ext.getCmp("modx-resource-introtext");
if(n){
introtext.setValue("");
introtext.hide();
if(MODx.unloadRTE) MODx.unloadRTE("modx-resource-introtext");
}else{
introtext.show();
if(MODx.loadRTE) MODx.loadRTE("modx-resource-introtext");
}
}
}
});
group.items.add(checkbox);
});
</script>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment