0f794ee6557b5b69db9547db823051eb389c4d44.svn-base 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

/**
 * Exopite Simple Options Framework Trumbowyg
 */
; (function ($, window, document, undefined) {

    var pluginName = "exopiteSOFColorpicker";

    // The actual plugin constructor
    function Plugin(element, options) {

        this.element = element;
        this._name = pluginName;
        this.$element = $(element);
        this.init();

    }

    Plugin.prototype = {

        init: function () {

            var plugin = this;

            plugin.$element.find('.colorpicker').each(function (index, el) {

                if ($(el).closest('.exopite-sof-cloneable__item').hasClass('exopite-sof-cloneable__muster')) return;
                if ($(el).hasClass('disabled')) return;

                $(el).wpColorPicker({
                    /**
                     * @param {Event} event - standard jQuery event, produced by whichever
                     * control was changed.
                     * @param {Object} ui - standard jQuery UI object, with a color member
                     * containing a Color.js object.
                     */
                    change: function (event, ui) {
                        plugin.change(event, ui, $(this));
                    },
                });

            });

            plugin.$element.closest('.exopite-sof-wrapper').on('exopite-sof-field-group-item-added-after', function (event, $cloned) {

                $cloned.find('.colorpicker').each(function (index, el) {

                    if ($(el).closest('.exopite-sof-cloneable__item').hasClass('exopite-sof-cloneable__muster')) return;
                    if ($(el).hasClass('disabled')) return;

                    $(el).wpColorPicker({
                        change: function (event, ui) {
                            plugin.change(event, ui, $(this));
                        },
                    });

                });

                console.log('color picker clone');

            });

        },

        change: function (event, ui, $this) {
            var color = ui.color.toString();
            if ($this.hasClass('font-color-js')) {
                console.log('has font-color');
                $this.parents('.exopite-sof-font-field').find('.exopite-sof-font-preview').css({ 'color': color });
            }
        },

    };

    $.fn[pluginName] = function (options) {
        return this.each(function () {
            if (!$.data(this, "plugin_" + pluginName)) {
                $.data(this, "plugin_" + pluginName,
                    new Plugin(this, options));
            }
        });
    };

})(jQuery, window, document);

; (function ($) {
    "use strict";

    $(document).ready(function () {

        $('.exopite-sof-field').exopiteSOFColorpicker();

    });

}(jQuery));