Alpha Video Training
Results 1 to 5 of 5

Thread: HTML Editor: How To Delete Specific Tools

  1. #1
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,334

    Default HTML Editor: How To Delete Specific Tools

    I cannot believe how often this gets asked and the complete lack of information on the subject.

    You can remove any control for the HTML Editor. The only catch is that you need to do it using JavaScript & jQuery.

    In order to effectively remove or hide tools, you do need to know a little bit about their layout:
    Code:
    var tools = jQuery('[id$="FIELD_NAME.TOOLBAR"]').children();
    Replace "FIELD_NAME" with the name of your textarea. It's the same name that you would use in {grid.Object}.getValue('D','FIELD_NAME');

    This is what's inside tools:
    • tools[0] = Style
    • tools[1] = Spacer1
    • tools[2] = Font Face
    • tools[3] = Spacer2
    • tools[4] = Font Size
    • tools[5] = Spacer3
    • tools[6] = Bold
    • tools[7] = Italic
    • tools[8] = Underline
    • tools[9] = Strikethrough
    • tools[10] = Superscript
    • tools[11] = Subscript
    • tools[12] = Spacer4
    • tools[13] = Font Color
    • tools[14] = Highlight
    • tools[15] = Background
    • tools[16] = Spacer5
    • tools[17] = Text Align Left
    • tools[18] = Text Align Center
    • tools[19] = Text Align Right
    • tools[20] = Justified
    • tools[21] = Spacer6
    • tools[22] = Outdent
    • tools[23] = Indent
    • tools[24] = Spacer7
    • tools[25] = Bullet List
    • tools[26] = Numbered List
    • tools[27] = Spacer8
    • tools[28] = Insert Symbol
    • tools[29] = Table
    • tools[30] = Link


    If you have no File/Image Insert buttons, then...
    • tools[31] = Spacer9
    • tools[32] = Clear Formatting
    • tools[33] = Spacer10
    • tools[34] = Toggle Code


    If you have File Insert but no Image Insert, then...
    • tools[31] = Insert File
    • tools[32] = Spacer9
    • tools[33] = Clear Formatting
    • tools[34] = Spacer10
    • tools[35] = Toggle Code


    If you have Image Insert but no File Insert, then...
    • tools[31] = Insert Image
    • tools[32] = Spacer9
    • tools[33] = Clear Formatting
    • tools[34] = Spacer10
    • tools[35] = Toggle Code


    If you have both File Insert and Image Insert, then...
    • tools[31] = Insert Image
    • tools[32] = Insert File
    • tools[33] = Spacer9
    • tools[34] = Clear Formatting
    • tools[35] = Spacer10
    • tools[36] = Toggle Code


    File Insert and Image Insert can be controlled in Alpha.

    The HTML Editor is dynamically generated pretty much every time it's displayed. There are no reliable IDs that you can fall back on to get the individual tools. Thus, you must use jQuery Selectors to "get" individual tools:
    Code:
    var Bold              = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Bold"]');
    var Italic            = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Italic"]');
    var Underline         = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Underline"]');
    var Strikethrough     = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Strikethrough"]');
    var Superscript       = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Superscript"]');
    var Subscript         = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Subscript"]');
    
    var FontColor         = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Font Color"]');
    var Highlight         = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Highlight Color"]');
    var Background        = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Background Color"]');
    
    var TextAlignLeft     = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Left"]');
    var TextAlignCenter   = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Center"]');
    var TextAlignRight    = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Right"]');
    var Justified         = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Justified"]');
    
    var Outdent           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Outdent"]');
    var Indent            = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Indent"]');
    
    var BulletList        = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Unordered List"]');
    var NumberedList      = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Ordered List"]');
    
    var InsertSymbol      = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Insert Symbol"]');
    var Table             = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Table"]');
    var Link              = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Insert Link"]');
    
    var ClearFormatting   = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Clear Format"]');
    var ToggleCode        = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Toggle Code"]');
    
    var InsertImage       = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Insert Image"]');
    var InsertFile        = jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Insert File"]');
    There are 3 special cases for Controls: Style, Fonts, and Font Size. They have no title. So, instead, we have to use table and nth() to get each control. These selectors only work if none of these tools have been removed. Once you delete one of these 3 tools from the DOM, their lookup logic changes:
    Code:
    var Style             = jQuery('[id$="FIELD_NAME.TOOLBAR"]>table:nth(0)');
    var Fonts             = jQuery('[id$="FIELD_NAME.TOOLBAR"]>table:nth(1)');
    var FontSize          = jQuery('[id$="FIELD_NAME.TOOLBAR"]>table:nth(2)');
    Spacers are another special case. They're accomplished using spans. Here's how you'd access each one before any of them are removed from the DOM:
    Code:
    var Spacer1           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(0)');
    var Spacer2           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(1)');
    var Spacer3           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(2)');
    var Spacer4           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(3)');
    var Spacer5           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(4)');
    var Spacer6           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(5)');
    var Spacer7           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(6)');
    var Spacer8           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(7)');
    var Spacer9           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(8)');
    var Spacer10          = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(9)');
    Hiding --- this hides the tools but they're still in the DOM:
    Code:
    //controls with titles:
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Insert Symbol"]').hide();
    
    //Hide tools in the HTML Editor
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>table:nth(0)').hide();
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>table:nth(2)').hide();
    
    
    //Hide spacers in the HTML Editor
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(0)').hide();
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(2)').hide();
    Deleting --- this completely removes these tools from the DOM:
    Code:
    // controls with titles:
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>[title="Toggle Code"]').remove();
    
    // Font Size & Styles, but not Fonts
    // Delete in descending nth order, less you want crazy bugs
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>table:nth(2)').remove(); //deletes Font Size
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>table:nth(0)').remove(); //deletes Styles
    
    // Individual Spacers
    // Delete in descending nth order, less you want crazy bugs
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(9)').remove(); //deletes spacer 10
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(5)').remove(); //deletes spacer 6
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(2)').remove(); //deletes spacer 3
    After deleting spacers and any of Font Size, Fonts, or Styles, it changes the nth() property for other spacers. In the above, we delete spacer 10, 6, and 3. This is how you'd access the remaining spacers in the toolbar:
    Code:
    var Spacer1           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(0)');
    var Spacer2           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(1)');
    var Spacer4           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(2)');
    var Spacer5           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(3)');
    var Spacer7           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(4)');
    var Spacer8           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(5)');
    var Spacer9           = jQuery('[id$="FIELD_NAME.TOOLBAR"]>span:nth(6)');
    Lastly, here are two tips for deleting sets of controls:
    Code:
    //Hide Styles, Fonts, and Font Sizes in one line:
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>table').hide();
    
    //Delete all the spacers:
    jQuery('[id$="FIELD_NAME.TOOLBAR"]>span').remove();
    Happy Scripting!
    ---
    Sarah

  2. #2
    Member
    Real Name
    Tom Williams
    Join Date
    Oct 2007
    Posts
    424

    Default Re: HTML Editor: How To Delete Specific Tools

    Sarah,

    The information you have provided in this thread is INVALUABLE. It really needs to have some kind of special access in the Hierarchy of the Forum and Documentation in general. This stuff is impossible to guess at.

    I found this thread only because you helped me in a reply to one of my posts. I then continued to search for what the other possible elements were that was related to this issue and I found this post. My lucky day, you just posted it earlier in the day.

    I have just three questions at this point:

    1. Is there an opposite method to "remove()", like "insert()" or "add()" etc. (ie. needed to place the "Toggle Code" back into view)

    2. I "REALLY NEED" to access a PRINTER link if it has one. What might be the syntax to access this printer if one is available.

    3. Where did you locate the definitive information listed above, I can't imagine you may have taken your own time to compile it. If
    so, I feel I owe you some money.

    Thanks in advance!
    Tom W.

  3. #3
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,334

    Default Re: HTML Editor: How To Delete Specific Tools

    1: Yes. You could show/hide the toggle source button instead of removing it. Inserting? jQuery probably has functions for that. They're probably called "add()". jQuery API Documentation. I'll check in the morning. Though, I don't really recommend extending the toolbar... It's destroyed & created a lot.

    2: There is no printer button in the A5.HTMLEditor.

    3: Half a day. But at least a month to finally figure out & understand what Alpha was doing with toolbars and everything. Still don't know about extending the toolbar. I really don't recommend it...

  4. #4
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,334

    Default Re: HTML Editor: How To Delete Specific Tools

    Quote Originally Posted by Fulltimer View Post
    1. Is there an opposite method to "remove()", like "insert()" or "add()" etc. (ie. needed to place the "Toggle Code" back into view)
    InsertAfter and InsertBefore allow you to insert elements. So... for example:

    Code:
    jQuery('<span>Outdent:</span>').insertBefore('[id$="FIELD_NAME.TOOLBAR"]>[title="Outdent"]');
    ---
    Sarah

  5. #5
    Member mastermind315's Avatar
    Real Name
    Elliot Rosa
    Join Date
    Apr 2008
    Location
    Aguada, Puerto Rico
    Posts
    341

    Default Re: HTML Editor: How To Delete Specific Tools

    Hi Sarah and thanks for this great post, where do I need to put the code in order to make it work?

Similar Threads

  1. HTML Editor
    By Phil Rolf in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 03-01-2011, 11:37 AM
  2. HTML Editor
    By njguy in forum Archived Wishlist
    Replies: 0
    Last Post: 06-30-2010, 10:52 PM
  3. Using HTML editor for simple HTML
    By Mr GreenJeans in forum Alpha Five Version 9 - Desktop Applications
    Replies: 11
    Last Post: 06-25-2010, 06:55 PM
  4. Using HTML editor for simple HTML
    By Mr GreenJeans in forum Application Server Version 9 - Web/Browser Applications
    Replies: 0
    Last Post: 06-23-2010, 03:26 PM
  5. HTML Editor
    By Sharon Goh in forum Alpha Five Version 6
    Replies: 1
    Last Post: 08-19-2004, 04:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •