App_Settings = { settingsChanged: false, prevMode: {}, init: function (id) { $('#' + id + ' input, #' + id + ' textarea, #' + id + ' select').each(function(i) { var type = $(this).attr('type'); if ('hidden' != type && 'submit' != type && 'button' != type) { $(this).bind('change', function() { App_Settings.settingsChanged = true; }); } }); $('#' + id + ' #btnSubmit').bind('click', function(e) { App_Settings.settingsChanged = false; }); var clickEvents = document.getElementById('btnCancel').onclick; document.getElementById('btnCancel').onclick = null; var btnCancel = $('#' + id + ' #btnCancel'); $(btnCancel).bind('click', function(e) { App_Settings.settingsChanged = false; }); $(btnCancel).bind('click', clickEvents); window.onbeforeunload = function (e) { /** * для ІЕ не перепитую ніяких підтверджень, проблеми з викликати onbeforeunload. Створив на це Task 20457. */ if (!navigator.userAgent.match(/MSIE/) && App_Settings.settingsChanged) { return "You've made the changes to the form.\nYou will lost the changes if you leave the page."; } }; App_Settings.initCkEditorEvents(); }, initCkEditorEvents: function () { if (typeof CKEDITOR != 'undefined') { CKEDITOR.on('instanceReady', function (event) { App_Settings.prevMode[event.editor.name] = event.editor.mode; event.editor.on('mode', function (event) { App_Settings.prevMode[event.editor.name] = event.editor.mode; }); event.editor.on( 'change', function (event) { if (event.editor.mode == App_Settings.prevMode[event.editor.name]) { if (event.editor.checkDirty() == true) { App_Settings.settingsChanged = true; } } }); }); } } };