We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • This is a welcomed addition to the MODX extras and very much needed, I think I found a new extra to review for CMSTricks thanks for the great work danya.
      Benjamin Marte
      Interactive Media Developer
      Follow Me on Twitter | Visit my site | Learn MODX
      • 39194
      • 149 Posts
      It would be fine, benmarte, thank you.
        • 42393
        • 143 Posts
        I've never created a custom toolbar for FCK/CK but I did so successfully here. I followed instructions from CKEditor pages but there is a slightly different hook here.

        My goal was to have a button that adds a 'emphasis1' class to the P tag of selected text.

        /manager/assets/components/ckeditor/ckeditor/plugins/p_emphasis1/plugin.js:
        contains a CKEDITOR.plugins.add() script

        /manager/assets/components/ckeditor/ckeditor/plugins/p_emphasis1/images/icon.gif:
        16x16 image

        Following instructions elsewhere, I modified /manager/assets/components/ckeditor/ckeditor/config.js but no toolbar item displayed. Then I looked at the source of modx.htmleditor.js and saw this:
        extraPlugins: MODx.config['ckeditor.extra_plugins'] || ''

        OK, so it doesn't get toolbar info from the config file, it gets it from system settings. I added the following to the ckeditor.extra_plugins JSON string:
        , { "name": "classes", "items": [ "Emphasis" ] }
        Note the comma of course needs to be in there following the last group (styles) so that another group is added to the existing JSON. I missed that and the toolbar disappeared. Duh..

        On opening a resource I see my button and it works.

        I dunno if this is documented anywhere so I'm providing the info here for anyone else who follows...

        Thanks for the plugin!
          Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
          • 39194
          • 149 Posts
          Starbuck, thanks for the tips. Of course, we should not modify config.js, because we loose changes while package updating.
          We need to make style combo easy to configurate, and maybe add new feature to ckeditor - class combo (just like in TinyMCE). I'll handle it later..
          • There is a plugin for CKEditor that parses a given .css file and puts all of its classnames into the drop-down select.
              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
              • 42393
              • 143 Posts
              There are actually a couple of those class list builders. I was just looking at them. They disturb me because they parse CSS files using regex to filter out what's not wanted. With existing CSS files I think that means spending a lot of time carefully crafting reg-expressions to do that work. A simpler approach would be to create a separate CSS file which isn't intended to be referenced by the site, only by the editor. That can be stripped down to include only names that are wanted.

              On one hand I'll gripe with this: We're talking about coding for a plugin within a plugin within a CMS. At some point the work of actually building websites needs to take precedence.
              On the other hand, since I'm in there, I'll trying one or two of those plugins and post results here ASAP. smiley
                Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
                • 42393
                • 143 Posts
                OK, here's another little HowTo : Update the Styles dropdown with your own styles...

                Get this: http://ckeditor.com/addon/stylesheetparser
                and this: http://ckeditor.com/addon/stylescombo

                Put them under here:
                /manager/assets/components/ckeditor/ckeditor/plugins
                as /stylesheetparser and /stylescombo

                Create a very simple style sheet. I called mine 'ckeditor.css' and here's a sample from it:
                p.emphasis1 {
                  color: #75abff; }
                h2.pagetitle {
                  font-size: 160%;
                  margin-top: 30px;
                  text-align: center; }

                It's important to note that what you're doing is creating a manager-only style which hints at what your real style might look like. This doesn't need to be the actual site style.

                Now you need to edit /manager/assets/components/ckeditor/modx.htmleditor.js
                Look for the block that begins:
                MODx.ux.CKEditor = Ext.extend(Ext.ux.CKEditor, {
                    editorConfig: {
                These are editor parameters that get passed to CKEditor instead of using the app's config file. Currently the last line is
                coreStyles_strike: {element: 's', overrides: 'strike'}
                Add a comma to that and one more line:
                contentsCss: MODx.config['site_url'] + '/assets/templates/ckeditor.css'
                Note that's just my location for the CSS, change as you wish.

                Put your CSS in the location specified above.

                Now go to Manager > System > System Settings. Open the ckeditor settings. Set the key ckeditor.extra_plugins to value stylesheetparser,stylescombo.

                You should now be able to refresh a resource and check the Styles dropdown to see your styles.

                Let's connect the dots.

                1. You put scripts on your system
                2. Created CSS
                3. Placed it in your environment
                4. Told the ckeditor addon where to find your CSS
                5. The addon tells the stylesheet parser where to find the CSS
                6. You told the ckeditor addon to load the ckeditor plugins
                7. The stylesheet parser plugin parses your CSS into internal code
                8. The internal code is then used by the stylescombo plugin to populate the plugin

                Notes (subject to change):

                1. If you don't see the Styles list change: You may have misplaced the CSS, or you may have CSS which gets filtered out. See below. I recommend you use my example to start and then customize one step at a time, refreshing your resource page after each step to ensure the changes are good.
                2. Notice how the p.foo style applies the foo class to the p tag. It's not pretty but that's the pattern. This is another reason why it wouldn't do to load your default styles.
                3. In order to parse the CSS, the stylesheetparser seems to actually load it. Don't put common styles in there like 'body' or these will override your Manager styles. The styles are not added to the Styles list but the CSS is active.
                4. You'll see that the Styles list shows the style name using the style. It does this obviously because it has loaded the style sheet. Again, don't use style names which conflict with Manager styles or the moono skin used by the ckeditor addon.
                5. stylesheetparser/plugin.js does use regular expressions to filter styles from your CSS before parsing into that internal format. There is a skipSelectors filter to filter Out styles ( /(^body\.|^\.)/i ), and a validSelectors regex to filter In styles ( /\w+\.\w+/ ).
                6. Don't modify that script to change the values. Use the config settings as above. Add values:
                  stylesheetParser_skipSelectors: (your regex),
                  stylesheetParser_validSelectors: (your regex)

                  Frankly, I tried using my own expressions and was unsuccessful. The .js has examples at the bottom of the file. More info is here. There you'll see those notes how the CSS parser is limited (doesn't allow for nice names and other issues), and how that has prompted some to skip the parser and write their own style info direct for stylescombo.
                7. As an enhancement to the ckeditor addon, I think more of the editorConfig values should be moved out of the .js and put into system settings - I'm sure that's already in the roadmap. It's probably safe to say the keys mentioned here could be added.
                8. You don't need the CSS, you can create the intermediary files yourself.
                9. On that page you'll also see that there is a way to clear the default list of styles from the dropdown before adding your own. To do that here, add this editorConfig value right before contentsCSS:
                  stylesSet: [],
                10. Conversely, the p.foo styles described here are block styles. I don't know yet how to define inline styles like 'strong'. So unless someone posts a solution, you may not want to remove the defaults unless you really never use them.

                I said in my last note that I was uncomfortable with the regex, etc. Now that I've done this and understand it, I don't have a problem with it. YMMV
                  Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
                  • 40045
                  • 534 Posts
                  That's cool @starbuck! Would love to use this!

                  Somebody had some success using MIGX grids with richtextTV's and CKE?
                    • 39501
                    • 163 Posts
                    Quote from: exside at Jan 21, 2013, 08:24 PM
                    Somebody had some success using MIGX grids with richtextTV's and CKE?

                    I installed CKE today, but the rich text fields didn't show up in MIGX sad Did you get anywhere with it?
                      • 40045
                      • 534 Posts
                      Unfortunately not =/, seems nobody else is trying to do this (except us...), the described problem is also present with all other custom editors, which makes them sadly unusable^^