|
Cookbook /
NotsavedWarning-TalkSummary: Talk page for NotsavedWarning
Maintainer: Petko
Alternative solutionI've implemented pretty much the exact same functionality [alert box if moving away from a modified edit form] with the following JavaScript. It checks for the form element type as I was getting false positives from using <button> instead of <input type="submit">. I also don't bother with the check for page preview if the contents are not modified, as navigating back will in that case show the previewed contents. --Eemeli Aro March 12, 2009, at 05:06 AM function addEvent( obj, evt, fn ) {
if (obj.addEventListener) obj.addEventListener( evt, fn, false );
else if (obj.attachEvent) obj.attachEvent( 'on'+evt, fn );
}
function removeEvent( obj, evt, fn ) {
if (obj.removeEventListener) obj.removeEventListener( evt, fn, false );
else if (obj.detachEvent) obj.detachEvent( 'on'+evt, fn );
}
var ef;
function verifyExitOnEdit(e) {
if (!ef) return;
var evt = e || window.event;
var msg = "All changes will be lost.";
for ( var i in ef.elements ) {
if ( ( ef.elements[i].type in { 'text':'', 'textarea':'' } )
&& ( ef.elements[i].value != ef.elements[i].defaultValue )
) {
if (evt) evt.returnValue = msg;
return msg;
}
}
}
addEvent( window, 'load', function() {
var et = document.getElementById('text');
if (et) {
ef = et.form;
addEvent( window, 'beforeunload', verifyExitOnEdit );
addEvent( ef, 'submit', function() {
removeEvent( window, 'beforeunload', verifyExitOnEdit ); } );
}
} );
ExcelPaste compatibilityUsing the convert tabs to table functionality (from the GUI edit button simon July 28, 2009, at 11:58 PM
The Notsaved recipe has indeed troubles with ExcelPaste and I am not sure how to fix them. The GUI button actually submits the form to PmWiki (we could disable this warning) but the changes aren't saved. Worse, when an edit form reappears, Notsaved has no way of knowing that the form comes from ExcelPaste and not from the real saved page content, so if the author moves away without changing the form, no warnings will appear. --Petko August 21, 2009, at 06:17 PM International charactersHow can german umlauts ("ÄÖÜäöüß") be used in message? Make sure you save your config.php file in the same encoding as the wiki: UTF-8 if the wiki has UTF-8 enabled, or ANSI/Latin-1 if the wiki is in ISO8859-1 (default installation). --Petko August 21, 2009, at 06:17 PM Talk page for the NotsavedWarning recipe (users). |