/*
 *  Uppercase Toggle
 */
(function () {
    var uppercase = (function () {
        'use strict';

        var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
        var pluginname = 'uppercase';

        global.add(pluginname, function ( editor, url ) {

            // save toolbar for larger scope
            var toolbar;

            /**
             * add the button
             */
            editor.addButton(pluginname, {
                tooltip: theme_wordings.tinymce.uppercase,
                icon: false,
                text: 'Aa',
                onclick: function ( event ) {
                    editor.formatter.register(pluginname, {
                       inline: 'span',
                       styles: {'text-transform': pluginname}
                     });

                    editor.focus();
                    editor.formatter.toggle(pluginname);
                    editor.nodeChanged();
                }
            });

            /**
             * Create the toolbar with the controls for row
             * Also in this example the toolbar will apear only when the focused element is a div and the parent has the class greyd_fontsize-mceItem
             */
            editor.on('wptoolbar', function ( args ) {
                if ( args.element.parentElement.nodeName === 'DIV' && args.element.parentElement.className.indexOf(pluginname+'-mceItem') !== -1 ) {
                    args.toolbar = toolbar;
                    args.selection = parent[0];
                }
            });

            /**
             * Assign buttons for our toolbar
             */
            editor.once('preinit', function () {
                if ( editor.wp && editor.wp._createToolbar ) {
                    toolbar = editor.wp._createToolbar([
                        pluginname
                    ]);
                }
            });
        });

        // return
        function Plugin () {
        }

        return Plugin;

    }());
})();