• lieutenantdan

    (@lieutenantdan)


    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

  • The topic ‘Custom tinyMCE button returning more then wanted’ is closed to new replies.