| 56 | | |
| 57 | | function UnsavedChanges(editor) { |
| 58 | | // Keep a copy of the editor to perform any necessary functions |
| 59 | | var editor = editor; |
| 60 | | |
| 61 | | // Private variable for storing the unmodified contents. This is necessary |
| 62 | | // because whenDocReady needs a closure to reference this object. |
| 63 | | var defaultValue; |
| 64 | | |
| 65 | | // Variable to allow the protector to be bypassed in the case of submit. |
| 66 | | var bypass = false; |
| 67 | | |
| 68 | | var protector = function(event) { |
| 69 | | if (bypass) { |
| 70 | | return; |
| 71 | | } |
| 72 | | |
| 73 | | if (defaultValue != editor.getEditorContent()) { |
| 74 | | // This needs to use _lc for multiple languages |
| 75 | | var dirty_prompt = Xinha._lc('You have unsaved changes in the editor', 'UnsavedChanges'); |
| 76 | | event.returnValue = dirty_prompt; |
| 77 | | return dirty_prompt; |
| 78 | | } |
| 79 | | } |
| 80 | | |
| 81 | | this.onBeforeSubmit = function() { |
| 82 | | bypass = true; |
| 83 | | } |
| 84 | | |
| 85 | | // Setup to be called when the plugin is loaded. |
| 86 | | // We need a copy of the initial content for detection to work properly, so |
| 87 | | // we will setup a callback for when the document is ready to store an |
| 88 | | // unmodified copy of the content. |
| 89 | | this.onGenerate = function() { |
| 90 | | editor.whenDocReady(function () { |
| 91 | | // Copy the original, unmodified contents to check for changes |
| 92 | | defaultValue = defaultValue || editor.getEditorContent(); |
| 93 | | |
| 94 | | // Set up the blocker |
| 95 | | Xinha._addEvent(window, 'beforeunload', protector); |
| 96 | | }); |
| 97 | | } |
| 98 | | |
| 99 | | } |
| 100 | | |
| 101 | | // An object containing metadata for this plugin |
| 102 | | UnsavedChanges._pluginInfo = { |
| 103 | | name:'UnsavedChanges', |
| 104 | | version:'3.7', |
| 105 | | developer:'Douglas Mayle', |
| 106 | | developer_url:'http://douglas.mayle.org', |
| 107 | | c_owner:'Douglas Mayle', |
| 108 | | sponsor:'The Open Planning Project', |
| 109 | | sponsor_url:'http://topp.openplans.org', |
| 110 | | license:'LGPL' |
| 111 | | } |
| 112 | | |