Ticket #1213: UnsavedChanges.diff

File UnsavedChanges.diff, 3.3 KB (added by douglas, 7 years ago)

Unsaved changes plugin

  • plugins/UnsavedChanges/lang/es.js

     
     1// I18N constants 
     2// LANG: "es", ENCODING: UTF-8 
     3{ 
     4  "You have unsaved changes in the editor": "Usted no ha guardado sus modificaciones" 
     5}; 
  • plugins/UnsavedChanges/lang/fr.js

     
     1// I18N constants 
     2// LANG: "fr", ENCODING: UTF-8 
     3{ 
     4  "You have unsaved changes in the editor": "Vous n'avez pas enregistré vos modifications" 
     5}; 
  • plugins/UnsavedChanges/lang/fr_ca.js

     
     1// I18N constants 
     2// LANG: "fr_ca", ENCODING: UTF-8 
     3{ 
     4  "You have unsaved changes in the editor": "Tu n'as pas enregistré tes modifications" 
     5}; 
  • plugins/UnsavedChanges/unsaved-changes.js

     
     1function UnsavedChanges(editor) { 
     2    // Keep a copy of the editor to perform any necessary functions 
     3    var editor = editor; 
     4 
     5    // Private variable for storing the unmodified contents.  This is necessary 
     6    // because whenDocReady needs a closure to reference this object. 
     7    var defaultValue; 
     8 
     9    // Variable to allow the protector to be bypassed in the case of submit. 
     10    var bypass = false; 
     11 
     12    var protector = function(event) { 
     13        if (bypass) { 
     14            return; 
     15        } 
     16 
     17        if (defaultValue != (editor.getEditorContent ? editor.getEditorContent() : editor.outwardHtml(editor.getHTML()))) { 
     18            // This needs to use _lc for multiple languages 
     19            var dirty_prompt = Xinha._lc('You have unsaved changes in the editor', 'UnsavedChanges'); 
     20            event.returnValue = dirty_prompt; 
     21            return dirty_prompt; 
     22        } 
     23    } 
     24 
     25    this.onBeforeSubmit = function() { 
     26        bypass = true; 
     27    } 
     28 
     29    // Setup to be called when the plugin is loaded. 
     30    // We need a copy of the initial content for detection to work properly, so 
     31    // we will setup a callback for when the document is ready to store an 
     32    // unmodified copy of the content. 
     33    this.onGenerate = function() { 
     34        editor.whenDocReady(function () { 
     35            // Copy the original, unmodified contents to check for changes 
     36            defaultValue = defaultValue || (editor.getEditorContent ? editor.getEditorContent() : editor.outwardHtml(editor.getHTML())); 
     37 
     38            // Set up the blocker 
     39            Xinha._addEvent(window, 'beforeunload', protector); 
     40        }); 
     41    } 
     42 
     43} 
     44 
     45// An object containing metadata for this plugin 
     46UnsavedChanges._pluginInfo = { 
     47    name:'UnsavedChanges', 
     48    version:'3.7', 
     49    developer:'Douglas Mayle', 
     50    developer_url:'http://douglas.mayle.org', 
     51    c_owner:'Douglas Mayle', 
     52    sponsor:'The Open Planning Project', 
     53    sponsor_url:'http://topp.openplans.org', 
     54    license:'LGPL' 
     55} 
     56