[SPIP] ~2.1.12 -->2.1.25
[velocampus/web/www.git] / www / prive / javascript / jquery.autosave.js
1 /**
2 * autosave plugin
3 *
4 * Copyright (c) 2009-2014 Fil (fil@rezo.net)
5 * Dual licensed under the MIT and GPL licenses:
6 * http://www.opensource.org/licenses/mit-license.php
7 * http://www.gnu.org/licenses/gpl.html
8 *
9 */
10
11 /*
12 * Usage: $("form").autosave({options...});
13 * to use with SPIP's action/session.php
14 */
15
16 (function($){
17 $.fn.autosave = function(opt) {
18 opt = $.extend(opt,{
19 confirm: false,
20 confirmstring: 'Sauvegarder ?'
21 });
22 $(window)
23 .bind('unload',function() {
24 $('form.autosavechanged')
25 .each(function(){
26 if (!opt.confirm || confirm(opt.confirmstring)) {
27 var contenu = $(this).serialize();
28 $.post('spip.php', {
29 'action': 'session',
30 'var': 'autosave_' + $('input[name=autosave]', this).val(),
31 'val': contenu
32 });
33 }
34 });
35 });
36 return this
37 .bind('change keyup', function() {
38 $(this).addClass('autosavechanged');
39 })
40 .bind('submit',function() {
41 $(this).removeClass('autosavechanged');
42 });
43 }
44 })(jQuery);
45