Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9086179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:25:30+00:00 2026-06-16T21:25:30+00:00

I am new with TinyMCE, but I managed to make a button, which buts

  • 0

I am new with TinyMCE, but I managed to make a button, which buts a <pre><code>...</code></pre> tag with some code.

In there users can only write source code, but if they use a button like bold, then it gets bold..

I have been trying to figure out a way to disable that, and found out that it was possible to disable buttons when you was over a special tag.

So I was wondering, if anyone knew how that was possible??

I have this plugin, which example do it:
https://code.google.com/p/tinymce-pre-plugin/
If you look at the video you can see what I mean, he goes over the <pre><code>...</code></pre> tag right after 0:40.

You can see the source of the plugin file here:

(function() {
    tinymce.PluginManager.requireLangPack('pre');

    tinymce.create('tinymce.plugins.PrePlugin', {       
        init : function(ed, url) {          
            var t = this;
            t.editor = ed;

            ed.addCommand('mcePre', function() {
                ed.windowManager.open({
                    file : url + '/dialog.htm',
                    width : 500 + parseInt(ed.getLang('pre.delta_width', 0)),
                    height : 300 + parseInt(ed.getLang('pre.delta_height', 0)),
                    inline : 1
                }, {
                    plugin_url : url
                });
            });

            ed.addButton('pre', {
                title : 'pre.desc',
                cmd : 'mcePre',
                image : url + '/img/pre.gif'
            });

            ed.onNodeChange.add(function(ed, cm, n) {
                cm.setActive('pre', n.nodeName == 'CODE');

                if(n.nodeName == 'CODE') t._setDisabled(1);
                else t._setDisabled(0);

                var notEmptyNode = n.innerHTML.replace(new RegExp('<\/?[^>]+>', 'gi'), '').replace(new RegExp('&nbsp;', 'gi'), '').match(/.*?[\S].*?/);
                if(notEmptyNode && n.nodeName != 'CODE')
                cm.setDisabled('pre', true);

            });
        },

        createControl : function(n, cm) {
            return null;
        },

        getInfo : function() {
            return {
                longname : 'Pre plugin',
                author : 'Marchenko Alexandr',
                authorurl : 'http://webdiz.com.ua',
                infourl : 'http://webdiz.com.ua',
                version : "1.0"
            };
        },


        _block : function(ed, e) {
            var k = e.keyCode;

            // Don't block arrow keys, pg up/down, and F1-F12
            if (k == 46 || (k > 32 && k < 41) || (k > 111 && k < 124))
                return;

            if (e.preventDefault) {
                e.preventDefault();
                e.stopPropagation();
            }
            else {
                e.returnValue = false;
                e.cancelBubble = true;
            }
            return false;
        },

        _setDisabled : function(s) {
            var t = this, ed = t.editor;

            tinymce.each(ed.controlManager.controls, function(c) {
                if(c.settings.cmd != 'mcePre') {
                    c.setDisabled(s);
                }
            });

            if (s !== t.disabled) {
                if (s) {
                    ed.onKeyDown.addToTop(t._block);
                    ed.onKeyPress.addToTop(t._block);
                    ed.onKeyUp.addToTop(t._block);
                    ed.onPaste.addToTop(t._block);
                } else {
                    ed.onKeyDown.remove(t._block);
                    ed.onKeyPress.remove(t._block);
                    ed.onKeyUp.remove(t._block);
                    ed.onPaste.remove(t._block);
                }

                t.disabled = s;
            }
        }
    });

    // Register plugin
    tinymce.PluginManager.add('pre', tinymce.plugins.PrePlugin);
})();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:25:31+00:00Added an answer on June 16, 2026 at 9:25 pm

    I found out.

    This is the code which does this:

    ed.onNodeChange.add(function(ed, cm, n) {
        cm.setActive('pre', n.nodeName == 'PRE');
    
        if(n.nodeName == 'PRE') t._setDisabled(1);
        else t._setDisabled(0);
    
        var notEmptyNode = n.innerHTML.replace(new RegExp('<\/?[^>]+>', 'gi'), '').replace(new RegExp('&nbsp;', 'gi'), '').match(/.*?[\S].*?/);
        if(notEmptyNode && n.nodeName != 'PRE')
        cm.setDisabled('pre', true);
    
    });
    

    Change PRE to whatever tag should be set for, but it disable all buttons, only the active buttons stays, but also no text can be written then.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

new to c#. I'm trying to make a simple system where I can search
As you can see from the code below we, use TinyMce a lot in
I've added a custom button to TinyMCE which brings up a bespoke link-picker. When
NOTE: ORIGINAL PROBLEM WAS FIXED, but there's still some issues using the plugin on
I have the following javascript code: var editor = new tinymce.Editor(id, settings); On window
i am building a plugin for tinymce editor which adds some microdata to selected
when i click Fullscreen button on tinyMCE, it opens in new window. All i
New programmer here, I am trying to understand and break down this code below
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
I'm having trouble getting tinyMCE to work with the new jQuery 1.4.2 on IE6.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.