X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fprive%2Fjavascript%2Fjquery.autosave.js;fp=www%2Fprive%2Fjavascript%2Fjquery.autosave.js;h=933b636f320033fab388fc0197475cf630d67cc9;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c diff --git a/www/prive/javascript/jquery.autosave.js b/www/prive/javascript/jquery.autosave.js new file mode 100644 index 0000000..933b636 --- /dev/null +++ b/www/prive/javascript/jquery.autosave.js @@ -0,0 +1,45 @@ +/** + * autosave plugin + * + * Copyright (c) 2009 Fil (fil@rezo.net) + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + */ + +/* + * Usage: $("form").autosave({options...}); + * to use with SPIP's action/session.php + */ + +(function($){ + $.fn.autosave = function(opt) { + opt = $.extend(opt,{ + confirm: false, + confirmstring: 'Sauvegarder ?' + }); + $(window) + .bind('unload',function() { + $('form.autosavechanged') + .each(function(){ + if (!opt.confirm || confirm(opt.confirmstring)) { + var contenu = $(this).serialize(); + $.post('spip.php', { + 'action': 'session', + 'var': 'autosave_' + $('input[name=autosave]', this).val(), + 'val': contenu + }); + } + }); + }); + return this + .bind('change keyup', function() { + $(this).addClass('autosavechanged'); + }) + .bind('submit',function() { + $(this).removeClass('autosavechanged'); + }); + } +})(jQuery); +