(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define([
            "jquery",
            "underscore",
            "pat-base",
            "pat-registry",
            "pat-parser",
            "jqueryui",
            "jquery-hotkeys",
            "rangy",
            "rangy-serializer",
            "raptor"
        ], function() {
            return factory.apply(this, arguments);
        });
    } else {
        factory($, _, Base, root.patterns, root.patterns.Parser);
    }
}(this, function($, _, Base, registry, Parser) {
    'use strict';
    var parser = new Parser('raptor');
    // Allows the user to directly configure Raptor via JSON
    parser.add_argument('config', {});
    parser.add_argument('toolbar-type', 'standard', ['standard', 'fixed', 'floating']);
    parser.add_argument('toolbar-external');
    parser.add_argument('toolbar-loading', 'auto', ['auto', 'click']);
    
    // Note, these relate to the File Manager plugin which is a premium plugin and not included in with this pattern.
    parser.add_argument('image-path');
    parser.add_argument('image-picker-url');
    parser.add_argument('image-pick-icon');

    parser.add_argument('buttons',
            [ 'alignCenter', 'alignJustify', 'alignLeft', 'alignRight',
              'historyRedo', 'historyUndo', 'hrCreate', 'linkCreate',
              'linkRemove', 'listOrdered', 'listUnordered', 'tableCreate',
              'textBold', 'textItalic', 'textStrike', 'textUnderline'
            ], [
            'alignCenter', 'alignJustify', 'alignLeft', 'alignRight',
            'cancel', 'classMenu', 'cleanBlock', 'clearFormatting',
            'colorMenuBasic', 'dockToElement', 'dockToScreen', 'embed',
            'floatLeft', 'floatNone', 'floatRight', 'fontFamilyMenu',
            'guides', 'historyRedo', 'historyUndo', 'hrCreate',
            'insertFile', 'languageMenu', 'linkCreate', 'linkRemove',
            'listOrdered', 'listUnordered', 'logo', 'save',
            'snippetMenu', 'specialCharacters', 'statistics', 'tableCreate',
            'tableDeleteColumn', 'tableDeleteRow', 'tableInsertColumn', 'tableInsertRow',
            'tagMenu', 'textBlockQuote', 'textBold', 'textItalic',
            'textSizeDecrease', 'textSizeIncrease', 'textStrike', 'textSub',
            'textSuper', 'textUnderline', 'viewSource', 'fileManager'
            ],
        true);

    return Base.extend({
        name: 'raptor',
        trigger: ".pat-raptor",

        init: function patRaptorInit() {
            var config = {
                layouts: {
                        toolbar: {},
                        hoverPanel: {
                            uiOrder: [
                                ['clickButtonToEdit']
                            ]
                        },
                        fileManager: {
                            uiOrder: [
                                ['insert', 'download', 'view']
                            ]
                        },
                        elementHoverPanel: {
                            elements: 'img',
                            uiOrder: [['imageResize', 'imageSwap', 'close']]
                        },
                    },
                plugins: { dock: {} }
            };
            this.options = parser.parse(this.$el);

            switch (this.options.toolbar.type) {
                case "floating":
                    config.plugins.dock.dockToElement = false;
                    config.plugins.dock.docked = false;
                    break;
                case "fixed":
                    config.plugins.dock.dockToElement = false;
                    config.plugins.dock.docked = true;
                    break;
                case "standard":
                    config.plugins.dock.dockToElement = true;
                    config.plugins.dock.docked = true;
                    break;
            }
            config.plugins.dock.dockTo = this.options.toolbar.external;
            $.extend(true, config, this.options.config);
            if (this.options.buttons instanceof Array && this.options.buttons.length) {
                config.layouts.toolbar.uiOrder = [this.options.buttons];
            }
            this.registerEventHandlers();

            var $form = this.$el.closest('form');
            var autosubmit = $form.hasClass('pat-autosubmit');
            var autoload = this.options.toolbar.loading === "auto";
            _.extend(config, {
                'bind': {
                    'enabled': function() {
                        if (autosubmit && autoload) {
                            // Raptor editor registers a handler for the submit event on
                            // this form. That handler fires a change event which is caught
                            // by patterns and causes an endless loop in which the form is
                            // continuously submitted. We nip that in the bud here.
                            $form.off("submit.raptor");
                        }
                    }
                },
            });
            config.disabledPlugins = ['saveJson'];
            _.extend(config.plugins, {
                'fileManager': {
                    'uriPublic': this.options.image.path,
                    'uriAction': this.options.image['picker-url'],
                    'uriIcon': this.options.image['pick-icon']
                },
                'imageSwap': {
                    'chooser': 'fileManager'
                }
            });
            config.autoEnable = (autoload) ? true : false;
            // Bit of a hack. Shitty Raptor doesn't allow you to remove buttons from a
            // preset, only override them. So if you want fewer buttons then
            // the preset provides, you're out of luck. So we register here an
            // empty preset as default to work around that.
            Raptor.registerPreset({'name': 'pat-raptor'}, true);
            this.$el.raptor(config);
        },

        registerEventHandlers: function () {
            $(document).on("pat-inject-hook-raptor", function (ev) {
                $.each(Raptor.instances, function (idx, instance) {
                    if (instance.element[0] == this.$el[0]) {
                        Raptor.instances[0].dirty = false;
                    }
                }.bind(this));
            }.bind(this));
        }

    });
}));



@@ -1051,16 +1051,80 @@
 attern.%0A
+    parser.add_argument('plugins', %5B%5D, %5B'image-picker'%5D, true);%0A
     pars
@@ -1151,16 +1151,20 @@
 ge-path'
+, ''
 );%0A    p
@@ -1200,16 +1200,20 @@
 ker-url'
+, ''
 );%0A    p
@@ -1248,16 +1248,20 @@
 ck-icon'
+, ''
 );%0A%0A    
@@ -5191,433 +5191,36 @@
     
-config.disabledPlugins = %5B'saveJson'%5D;%0A            _.extend(config.plugins, %7B%0A                'fileManager': %7B%0A                    'uriPublic': this.options.image.path,%0A                    'uriAction': this.options.image%5B'picker-url'%5D,%0A                    'uriIcon': this.options.image%5B'pick-icon'%5D%0A                %7D,%0A                'imageSwap': %7B%0A                    'chooser': 'fileManager'%0A                %7D%0A            %7D
+this.configurePlugins(config
 );%0A 
@@ -5310,15 +5310,8 @@
 ack.
- Shitty
  Rap
@@ -5687,16 +5687,635 @@
     %7D,%0A%0A
+        configurePlugins: function (config) %7B%0A            config.disabledPlugins = %5B'saveJson'%5D;%0A            if (!!~this.options.plugins.indexOf(%22image-picker%22)) %7B%0A                _.extend(config.plugins, %7B%0A                    'fileManager': %7B%0A                        'uriPublic': this.options.image.path,%0A                        'uriAction': this.options.image%5B'picker-url'%5D,%0A                        'uriIcon': this.options.image%5B'pick-icon'%5D%0A                    %7D,%0A                    'imageSwap': %7B%0A                        'chooser': 'fileManager'%0A                    %7D%0A                %7D);%0A            %7D%0A        %7D,%0A%0A
         

Add a 'plugins' argument