We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36549
    • 572 Posts
    Thanks for getting back to me, i've been taking a look at the Tinymce site (http://www.tinymce.com/wiki.php/Configuration:valid_elements) so it now makes more sense.
    I didn't want to use deprecated code so finally got it working by replacing this:
    -span[!title|!class<test test2]

    with this:
    span[style<text-decoration: underline;?text-decoration: line-through;]

    This way i can include just the underline and strikethrough options and disallow all other span classes.

      www.9thwave.co.uk
         WEB | DESIGN | PRINT
      • 42562
      • 1,145 Posts
      Very good.
      In case you get tired of inline styles flying hither thither, you have the option of routing all those attributes to specific classes.
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        @donshakespeare: would it be possible to get MODx.loadRTE support built into TinyMCE Wrapper? People are asking us about using it within ContentBlocks, but it does not load at all because that method is not defined.

        This is the general approach we use in CB (and a whole bunch of other addons too) to load editors, which does not work with TinyMCE Wrapper: https://www.modmore.com/redactor/documentation/custom-component-usage/
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 42562
          • 1,145 Posts
          Thanks for the note, Mark.
          I don't know anything about MODx.loadRTE, is it a standard MODx item?

          Does CB use textareas or contenteditables?

          Once RTE is enabled, are all the rte areas affected collectively?
            TinymceWrapper: Complete back/frontend content solution.
            Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
            5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            It's a MODX... thing. Not sure exactly what it is, a function/method? But it's been around for some years.
              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
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              It's not documented I guess, but yeah it's a pretty standard MODX thing I'd say. It's also used in the MODX core to allow RTE integrations:

              1) https://github.com/modxcms/revolution/blob/2.x/manager/controllers/default/resource/resource.class.php#L205
              2) https://github.com/modxcms/revolution/blob/2.x/manager/assets/modext/widgets/resource/modx.panel.resource.js#L86

              For the rich text field in ContentBlocks the base field is a text area.
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 42562
                • 1,145 Posts
                Re: Mark,

                You did not fully explain what you would do to call TinymceWrapper if I added MODx.loadRTE support.
                TinymceWrapper is designed to attempt to keep the TinyMCE inits absolutely independent. I am not sure that this MODx.loadRTE method would not complicate issues, namely by hijacking the selector part of the init. I want everything to be in the init chunk, bare and visible.

                Here are two solutions for you:

                1) You will have to do something like what Bruno is doing already for MIGX.
                The TinymceWrapper plugin is already activated - TinyMCE will already be loaded.
                All you have to do is allow a user to specify what chunkName they want in some setting of your CB extra.
                e.g
                tinymce.init({
                mode: "exact",
                elements: "contentblocks-field-[[+cb_id]]_textarea", 
                // selector: "textarea[id^=contentblocks-field-].cb-richtext",
                [[$TinymceWrapperCommonCode]]
                plugins:"autoresize,preview,paste,contextmenu,image,wordcount,fullscreen,code,link,charmap,searchreplace,textpattern,emoticons,insertdatetime",
                paste_word_valid_elements: "a,div,b,strong,i,em,h1,h2,h3,p,blockquote,ol,ul,pre",
                valid_elements: "iframe[*],object[*],audio[*],-span[!title|!class<test test2],a[href|target|class|rel|title|data-ajax|data-iframe],strong,b,-p[class<text-align-left?text-align-center?text-align-right],br,-h1[class|data-ajax|data-iframe],-h2[class|data-ajax|data-iframe],-h3[class|data-ajax|data-iframe],-img[!src|!alt|!class=round_img|data-ajax|data-iframe],em,-blockquote,pre[class],-ol,-ul,-li,-code[class]",
                valid_children: "-li[ul],-li[ol],-li[div],-strong[*],-em[*],-h1[*],-h2[*],-h3[*],-a[strong|em|h1|h2|h3|p|div],blockquote[p|ol|ul],pre,div",
                resize:true,
                autoresize_min_height:100,
                autoresize_max_height:400,
                toolbar: "newdocument | fullscreen preview | undo redo | blockquote | bold | italic | aligncenter | bullist numlist | link unlink | image | styleselect | charmap emoticons insertdatetime | searchreplace",
                contextmenu: "removeformat | link | image | code",
                setup: function(editor) {
                      editor.on('mouseleave', function(evt) {
                      tinyMCE.activeEditor.save();
                      //console.log("saved");//debug stuff
                    });
                    }
                });

                Now once a user adds a CB richtext, and a textarea is created on the fly, you would fire that piece of chunk code as well, either each time, or have it in the background listening for new richtext textareas.

                2) Simply give each new richtext textarea a common class, something like what MODx does for its richTVs
                At this time, as far as I can see in CB, there is no way to tell the difference between a richtext textarea and a plain textarea. Bruno put this demarcation in MIGX recently.
                This is good practice for future Extras to integrate with CB.
                <textarea id="contentblocks-field-1_textarea" class="cb-richtext"></textarea>
                
                <textarea id="contentblocks-field-2_textarea" class="cb-richtext"></textarea>
                
                <textarea id="contentblocks-field-3_textarea" class="cb-richtext"></textarea>
                

                With this HTML in place, TinymceWrapper or any other Extra/Plugin will be able to target the textareas without any qualm.

                Cheers.
                  TinymceWrapper: Complete back/frontend content solution.
                  Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                  5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                  • 18373 ☆ A M B ☆
                  • 3,141 Posts
                  With all respect to Bruno for his approach in MIGX, we're not planning to hardcode references to specific plugins in the ContentBlocks core. There's a perfectly fine quasi standard here that all other rich text editors adhere to, and the MIGX approach has already caused us many headaches when we made a change in Redactor, that also needed to be updated in MIGX for it to work again. The last time that happened (when we released Redactor 2), I sent a pull request to MIGX to simply call MODx.loadRTE: https://github.com/Bruno17/MIGX/pull/215/files#diff-68fa408924027b102400dcda4ec64488R15

                  And no problems since smiley

                  To be clear, there are also no hardcoded references to Redactor in ContentBlocks, so this is not a scheme to promote Redactor.

                  If you implement MODx.loadRTE support in TinyMCE Wrapper, you will not only get support for ContentBlocks, but also for a whole bunch of other addons that follow the standard, including MoreGallery, FaqMan, Gallery, GoodNews and probably dozens more that I can't think of right now.

                  Here's (based on your code) how you could implement it:

                  MODx.loadRTE = function(element) {
                  tinymce.init({
                  mode: "exact",
                  elements: element, 
                  // selector: "textarea[id^=contentblocks-field-].cb-richtext",
                  [[$TinymceWrapperCommonCode]]
                  plugins:"autoresize,preview,paste,contextmenu,image,wordcount,fullscreen,code,link,charmap,searchreplace,textpattern,emoticons,insertdatetime",
                  paste_word_valid_elements: "a,div,b,strong,i,em,h1,h2,h3,p,blockquote,ol,ul,pre",
                  valid_elements: "iframe[*],object[*],audio[*],-span[!title|!class<test test2],a[href|target|class|rel|title|data-ajax|data-iframe],strong,b,-p[class<text-align-left?text-align-center?text-align-right],br,-h1[class|data-ajax|data-iframe],-h2[class|data-ajax|data-iframe],-h3[class|data-ajax|data-iframe],-img[!src|!alt|!class=round_img|data-ajax|data-iframe],em,-blockquote,pre[class],-ol,-ul,-li,-code[class]",
                  valid_children: "-li[ul],-li[ol],-li[div],-strong[*],-em[*],-h1[*],-h2[*],-h3[*],-a[strong|em|h1|h2|h3|p|div],blockquote[p|ol|ul],pre,div",
                  resize:true,
                  autoresize_min_height:100,
                  autoresize_max_height:400,
                  toolbar: "newdocument | fullscreen preview | undo redo | blockquote | bold | italic | aligncenter | bullist numlist | link unlink | image | styleselect | charmap emoticons insertdatetime | searchreplace",
                  contextmenu: "removeformat | link | image | code",
                  setup: function(editor) {
                        editor.on('mouseleave', function(evt) {
                        tinyMCE.activeEditor.save();
                        //console.log("saved");//debug stuff
                      });
                      }
                  });
                  };


                  Obviously I don't know how you should fit in with the rest of your extra, that's your job, but that's all - just define the MODx.loadRTE function and accept the element it provides.

                  With this HTML in place, TinymceWrapper or any other Extra/Plugin will be able to target the textareas without any qualm.
                  That would not solve knowing when a RTE needs to be instantiated; as you already mentioned some of them may be generated on the fly. That's exactly the problem MODx.loadRTE solves: it gives developers of addons the option to say where and when they want a RTE, without having to know about the specifics of how that editor needs to be initialised - that's provided by the RTE itself.

                  (I did add an extra class to the richtext field in ContentBlocks so it can be distinguished from the textarea field; this will be released in 1.3 - thanks) [ed. note: markh last edited this post 10 years, 9 months ago.]
                    Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                    Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                    • 42562
                    • 1,145 Posts
                    Fair enough.
                    Now you have shown how MODx.loadRTE will be called, this should be easy to do.

                    Hold my beer...
                      TinymceWrapper: Complete back/frontend content solution.
                      Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                      5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                      • 42562
                      • 1,145 Posts
                      Right off my head, this is my solution.

                      Provide space to run custom code.
                      User can place the MODx.loadRTE = function(element) {... there and run it however they want.
                        TinymceWrapper: Complete back/frontend content solution.
                        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.