WordPress.org

Ready to get started?Download WordPress

Forums

Custom tinyMCE button returning more then wanted (1 post)

  1. lieutenantdan
    Member
    Posted 1 year ago #

    I've got a menu that pops up when a user pushs the button and when they choose a menu item it has an attribute of "code" that contains the code, the jQuery grabs it and inserts shortcode based on the code attribute, yet I get unexpected results, not sure whats happening...

    HTML Menu

    <ul id="menu" style="position: absolute; display: none; z-index: 15; width: 200px;">
        <li><a href="#" id="code" code="one-half">One Half</a></li>
        <li><a href="#" id="code" code="one-half-last">One Half Last</a></li>
    </ul>

    JQuery

    jQuery(document).ready( function($) {
    (function() {
        tinymce.create('tinymce.plugins.flightbutton', {
            init : function(ed, url) {
                ed.addButton('flightbutton', {
                    title : 'Add an element',
                    image : url + '/icon.png',
                    onclick : function() {
    					var button = $(".mce_flightbutton");
    					var position = button.offset();
    
    					$('#menu').css({'top':position.top + 25,'left':position.left}).fadeIn('slow');
    					//alert("TOP: " + position.top + "  LEFT: " + position.left);
    
    						$(".ui-corner-all").live("click", function() {
                        	   var code = $(this).attr('code');	// Get code for shortcode
    						   if(code == "undefined"){} else {
    							   ed.selection.setContent('[' + code + ']' + ed.selection.getContent() + '[/' + code + ']');
    					           $('#menu').fadeOut();
    						   }
    						   code = '';
                            });
    						//self.close();
                       // });
                    }
                });
            },
            createControl : function(n, cm) {
                return null;
            },
        });
        tinymce.PluginManager.add('flightbutton', tinymce.plugins.flightbutton);
    })();
    
    });

    Image

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.