Add dropdown

This example shows how to add a dropdown to the button.

Code

<!--element -->
<textarea id="content"></textarea>

<!-- plugin code -->
<script>
(function($R)
{
    $R.add('plugin', 'mydropdown', {
        translations: {
            en: {
                "mydropdown": "My Dropdown"
            }
        },
        init: function(app)
        {
            this.app = app;
            this.lang = app.lang;
            this.toolbar = app.toolbar;
        },
        start: function()
        {
            // create dropdown object
            var dropdownData = {
                item1: {
                    title: 'My dropdown item 1',
                    api: 'plugin.mydropdown.method1'
                },
                item2: {
                    title: 'My dropdown item 2',
                    api: 'plugin.mydropdown.method2'
                }
            };

            // create the button data
            var buttonData = {
                title: this.lang.get('mydropdown')
            };

            // create the button
            var $button = this.toolbar.addButton('mydropdown', buttonData);

            // set dropdown
            var dropdown = $button.setDropdown(dropdownData);
		},
		method1: function()
		{
    		alert('Item 1 is toggled!');
		},
		method2: function()
		{
    		alert('Item 2 is toggled!');
		}
    });
})(Redactor);
</script>

<!-- call -->
<script>
$R('#content', { plugins: ['mydropdown'] });
</script>