Sha256: 770b7e6a346005eb76d9632db351ca907831999e48f1f3e7aabc11302d8bc38c

Contents?: true

Size: 1.87 KB

Versions: 62

Compression:

Stored size: 1.87 KB

Contents

/**
 * Handles the content block preview iframe functionality which is updated each
 * time the related form is updated.
 *
 * @namespace WORKAREA.contentEditorForms
 */
WORKAREA.registerModule('contentEditorForms', (function () {
    'use strict';

    var updatePreview = function (previewId, response) {
            $('.content-block__iframe', previewId)
            .attr('src', WORKAREA.routes.storefront.draftContentBlockPath({
                id: response.id
            }));
        },

        buildParams = function (form, preview) {
            var params = _.union(form, _.map(preview, function (value, name) {
                return { name: name, value: value };
            }));

            return _.reduce(params, function (result, value) {
                if (value.name !== '_method') { result.push(value); }
                return result;
            }, []);
        },

        postFormData = _.debounce(function (event) {
            var $form, previewData, formParams, formData;

            if ($(event.target).is('[data-publish-with-release-menu]')) {
                return;
            }

            $form = $(event.target).closest('form'),
            previewData = $form.data('contentEditorForm'),
            formParams = $form.serializeArray(),
            formData = buildParams(formParams, previewData.params);

            $.post(WORKAREA.routes.admin.contentBlockDraftsPath(), formData)
            .done(_.partial(updatePreview, previewData.previewId));
        }, WORKAREA.config.contentEditorForms.previewDebounceValue),

        /**
         * @method
         * @name init
         * @memberof WORKAREA.contentEditorForms
         */
        init = function ($scope) {
            $('[data-content-editor-form]', $scope)
            .on('input change wysiwygs:input', postFormData);
        };

    return {
        init: init,
        buildParams: buildParams
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.26 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.4.45 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.25 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.23 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.4.44 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.22 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.4.43 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.21 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.4.42 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.20 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.4.41 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.19 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.4.40 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.18 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.4.39 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.17 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.4.38 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.5.16 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js
workarea-admin-3.4.37 app/assets/javascripts/workarea/admin/modules/content_editor_forms.js