We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42212
    • 14 Posts
    I have my custom component with that two extjs elements in frontend (/manager/):
    {
        xtype: 'textarea'
        ,fieldLabel: _('narkfaqs.question_text')
        ,name: 'question_text'
        ,height: '100'
        ,id: 'question_text'
        ,anchor: '100%'
    },{
        xtype: 'textarea'
        ,fieldLabel: _('narkfaqs.answer_text')
        ,name: 'answer_text'
        ,height: '100'
        ,id: 'answer_text'
        ,anchor: '100%'
    }


    And i have installed TinyMCE package.

    I'm need bind tinyMCE editor to that two fields, but i don't find solution of the problem...

    But, i look Gallery component and did not understand how his work...

    Please help me!.. [ed. note: adminoid last edited this post 11 years, 1 month ago.]
      • 42212
      • 14 Posts
      I solved it!
      In JS:
      NarkFaqs.window.UpdateNarkFaq = function(config) {
          config = config || {};
          Ext.applyIf(config,{
              title: _('narkfaqs.narkfaq_update')
              ,url: NarkFaqs.config.connectorUrl
              ,baseParams: {
                  action: 'mgr/narkfaq/update'
              }
              ,fields: [{
                  xtype: 'hidden'
                  ,name: 'id'
              },{
                  xtype: 'textfield'
                  ,fieldLabel: _('narkfaqs.question_author')
                  ,name: 'question_author'
                  ,anchor: '100%'
              },{
                  xtype: 'textfield'
                  ,fieldLabel: _('narkfaqs.question_header')
                  ,name: 'question_header'
                  ,anchor: '100%'
              },{
                  xtype: 'textfield'
                  ,fieldLabel: _('narkfaqs.linkid')
                  ,name: 'linkid'
                  ,anchor: '100%'
              },{
                  xtype: 'textarea'
                  ,fieldLabel: _('narkfaqs.question_text')
                  ,name: 'question_text'
                  ,id: 'question_text'
                  ,height: '100'
                  ,anchor: '100%'
              },{
                  xtype: 'textarea'
                  ,fieldLabel: _('narkfaqs.answer_text')
                  ,name: 'answer_text'
                  ,id: 'answer_text'
                  ,height: '100'
                  ,anchor: '100%'
              },{
                  xtype: 'xcheckbox'
                  ,name: 'published'
                  ,boxLabel: _('narkfaqs.published')
              }]
          });
          NarkFaqs.window.UpdateNarkFaq.superclass.constructor.call(this,config);
          this.on('activate',function(w,e) { // Add this
              MODx.loadRTE('question_text'); // Add this // Load by id [,id: 'question_text']
              MODx.loadRTE('answer_text');   // Add this // Load by id [,id: 'answer_text']
          },this);                           // Add this                        
      };


      Execute php:
      $plugin=$this->modx->getObject('modPlugin',array('name'=>'TinyMCE'));
      
      $tinyPath = $this->modx->getOption('core_path').'components/tinymce/';
      
      $tinyProperties=$plugin->getProperties();
      require_once $tinyPath.'tinymce.class.php';
      $tiny = new TinyMCE($this->modx, $tinyProperties);
      
      $tinyProperties['language'] = $this->modx->getOption('cultureKey',null,$this->modx->getOption('manager_language',null,'en'));
      $tinyProperties['frontend'] = true;
      $tinyProperties['cleanup'] = true;
      //$tinyProperties['width'] = 300;
      $tinyProperties['height'] = 100;
      
      $tinyProperties['tiny.custom_buttons1'] = 'undo,redo,separator,pastetext,search,replace,separator,cleanup,removeformat,tablecontrols,separator,modxlink,unlink,anchor,separator,image,media,separator,code';
      $tinyProperties['tiny.custom_buttons2'] = 'formatselect,separator,forecolor,backcolor,separator,bold,italic,underline,separator,strikethrough,sub,sup,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,outdent,indent,separator,rj_insertcode,blockquote,separator,hr,charmap';
      $tinyProperties['tiny.custom_buttons3'] = '';
      
      $tiny->setProperties($tinyProperties);
      $tiny->initialize();
      • Congratulations! You should win a super-sized bucket of aspirin and three weeks in Maui! Oh, did I ever say that I hate Javascript?
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
        • Wish there was a way to flag certain posts as favorites, as this is something I am SURE I will need to use soon.
          • I have a bookmark folder in my Firefox just for "forum posts".
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 42212
              • 14 Posts
              Sorry! This way no good...

              MODx.loadRTE('question_text');


              make one editor with text of field and remember that text.
              Need to constantly destroy editor after close edit window.
              I solved this problem as follows:
              Execute PHP:
              function __construct(modX &$modx,array $config = array()) {
              
                  // some code...
              
                  $this->activateRTE();
              }
              
              public function activateRTE(){
              
                  $plugin=$this->modx->getObject('modPlugin',array('name'=>'TinyMCE'));
                  $tinyPath = $this->modx->getOption('core_path').'components/tinymce/';
                  $tinyProperties=$plugin->getProperties();
                  require_once $tinyPath.'tinymce.class.php';
                  $tiny = new TinyMCE($this->modx, $tinyProperties);
              
                  $tinyProperties['language'] = $this->modx->getOption('cultureKey',null,$this->modx->getOption('manager_language',null,'ru'));
                  $tinyProperties['cleanup'] = true;
                  $tinyProperties['width'] = '100%';
                  $tinyProperties['height'] = 100;
              
                  $tinyProperties['tiny.custom_buttons1'] = 'undo,redo,separator,pastetext,search,replace,separator,cleanup,removeformat,tablecontrols,separator,modxlink,unlink,anchor,separator,image,media,separator,code';
                  $tinyProperties['tiny.custom_buttons2'] = 'formatselect,separator,forecolor,backcolor,separator,bold,italic,underline,separator,strikethrough,sub,sup,separator,justifyleft,justifycenter,justifyright,justifyfull';
                  $tinyProperties['tiny.custom_buttons3'] = '';
              
                  $tiny->setProperties($tinyProperties);
                  $tiny->initialize();
              
              }


              And JavaScript with ModExt edit window object:
              // some code...
              NarkFaqs.window.UpdateNarkFaq = function(config) {
                  config = config || {};
              
                  Ext.applyIf(config,{
                      title: _('narkfaqs.narkfaq_update')
                      ,url: NarkFaqs.config.connectorUrl
                      ,width: 510
                      // some code...
                      ,fields: [
                          // some code...
                          {
                              xtype: 'textarea'
                              ,fieldLabel: _('narkfaqs.question_text')
                              ,name: 'question_text'
                              ,id: 'question_text'
                              ,height: '100'
                              ,anchor: '100%'
                          },{
                              xtype: 'textarea'
                              ,fieldLabel: _('narkfaqs.answer_text')
                              ,name: 'answer_text'
                              ,id: 'answer_text'
                              ,height: '100'
                              ,anchor: '100%'
                          }
                          // some code...
                      ]
                  });
                  NarkFaqs.window.UpdateNarkFaq.superclass.constructor.call(this,config);
                  // Added from that line...
                  this.on('activate',function(w,e) {
                      MODx.loadRTE('question_text');
                      MODx.loadRTE('answer_text');
                  },this);
                  this.on('deactivate',function(w,e) {
                      tinyMCE.execCommand('mceRemoveControl',true,'question_text');
                      tinyMCE.execCommand('mceRemoveControl',true,'answer_text');
                  },this);
                  // To that line
              
              };
              // some code...

                • 45890
                • 1 Posts
                Брат, будешь в Самаре - звони! Не забудь, я должен тебе пиво! Много. Потому как задача добавления RTE в профиль юзера выносила мне мозг два дня. Спасибо, брат!