Sha256: 1d5d3c813e4265940d7498999ef988a61bd10c2fb3ed27ba6234db22263dd88f

Contents?: true

Size: 1.63 KB

Versions: 62

Compression:

Stored size: 1.63 KB

Contents

/**
 * @namespace WORKAREA.unsavedChanges
 */
WORKAREA.registerModule('unsavedChanges', (function () {
    'use strict';

    var unsavedChanges = false,

        reset = function() {
            unsavedChanges = false;
        },

        set = function () {
            unsavedChanges = true;
        },

        testUnsavedChanges = function(event) {
            if ($(event.target).is('[data-unsaved-changes-ignore]')) { return; }
            set();
        },

        promptBeforePageLoad = function(event) {
            var message = I18n.t('workarea.admin.form.unsaved_changed_message');

            if (unsavedChanges && !window.confirm(message)) {
                event.preventDefault();
            }
        },

        promptBeforeUnload = function(event) {
            var message = I18n.t('workarea.admin.form.unsaved_changed_message');

            if (! unsavedChanges) { return; }

            event.preventDefault();
            event.returnValue = message;
            return message;
        };

    // Running this in tests can cause browser dialogs for unsaved changes to
    // remain open and we don't care about that.
    if (!WORKAREA.environment.isTest) {
        $(document).on('change.unsavedChanges wysiwygs:input', '[data-unsaved-changes]', testUnsavedChanges);
        $(document).on('submit.unsavedChanges', '[data-unsaved-changes]', reset);

        document.addEventListener('turbolinks:load', reset);
        document.addEventListener('turbolinks:before-visit', promptBeforePageLoad);

        window.addEventListener('beforeunload', promptBeforeUnload);
    }

    return {
        set: set,
        reset: reset
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

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