Bonjour à tous !

J'ai étudié le script "iNettuts" pour le modifier et l'adapter à mon site.
J'ai donc pris la version qui inclue l'enregistrement dans la base de données. J'ai ensuite rajouté un champ "textarea" pour pouvoir modifier le texte "lorem ...." à ma guise. Ça marche parfaitement, ça enregistre etc.

Il y a juste un truc que je n'arrive pas à faire, et ça a l'air con mais je bloque x)

Lorsque je clique sur le bouton "edit" pour pouvoir afficher les champs d'édition, le champ du titre récupère la valeur dans la input, mais pas le champ textarea.

Voilà l'archive zip si vous le souhaitez : http://nadim.doueiri.free.fr/inettuts.zip

Donc le code du script js :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/*
 * Script from NETTUTS.com [by Mario Jimenez] V.2 (ENHANCED, WITH DATABASE!!!)
 * @requires jQuery($), jQuery UI & sortable/draggable UI modules & jQuery COOKIE plugin
 */
 
var iNettuts = {
 
    jQuery : $,
 
    settings : {
        columns : '.column',
        widgetSelector: '.widget',
        handleSelector: '.widget-head',
        contentSelector: '.widget-content',
 
        /* If you don't want preferences to be saved change this value to
            false, otherwise change it to the name of the cookie: */
        saveToCookie: 'inettuts-widget-preferences',
 
        widgetDefault : {
            movable: true,
            removable: true,
            collapsible: true,
            editable: true,
            colorClasses : ['color-yellow', 'color-red', 'color-blue', 'color-white', 'color-orange', 'color-green']
        },
        widgetIndividual : {}
    },
 
    init : function () {
        this.attachStylesheet('inettuts.js.css');
        this.sortWidgets();
        //this.addWidgetControls();
        //this.makeSortable();
    },
 
    getWidgetSettings : function (id) {
        var $ = this.jQuery,
            settings = this.settings;
        return (id&&settings.widgetIndividual[id]) ? $.extend({},settings.widgetDefault,settings.widgetIndividual[id]) : settings.widgetDefault;
    },
 
    addWidgetControls : function () {
        var iNettuts = this,
            $ = this.jQuery,
            settings = this.settings;
 
        $(settings.widgetSelector, $(settings.columns)).each(function () {
            var thisWidgetSettings = iNettuts.getWidgetSettings(this.id);
            if (thisWidgetSettings.removable) {
                $('<a href="#" class="remove">CLOSE</a>').mousedown(function (e) {
                    /* STOP event bubbling */
                    e.stopPropagation();    
                }).click(function () {
                    if(confirm('This widget will be removed, ok?')) {
                        $(this).parents(settings.widgetSelector).animate({
                            opacity: 0    
                        },function () {
                            $(this).wrap('<div/>').parent().slideUp(function () {
                                $(this).remove();
                            });
                        });
                    }
                    return false;
                }).appendTo($(settings.handleSelector, this));
            }
 
            if (thisWidgetSettings.editable) {
                $('<a href="#" class="edit">EDIT</a>').mousedown(function (e) {
                    /* STOP event bubbling */
                    e.stopPropagation();    
                }).toggle(function () {
                    $(this).css({backgroundPosition: '-66px 0', width: '55px'})
                        .parents(settings.widgetSelector)
                            .find('.edit-box').show().find('input').focus();
                    return false;
                },function () {
                    $(this).css({backgroundPosition: '', width: '24px'})
                        .parents(settings.widgetSelector)
                            .find('.edit-box').hide();
                    return false;
                }).appendTo($(settings.handleSelector,this));
                $('<div class="edit-box" style="display:none;"/>')
                    .append('<ul><li class="item"><label>Change the title?</label><input value="' + $('h3',this).text() + '"/></li>')
					.append('<ul><li class="item"><label>The text :</label><textarea value="' + $('h4',this).text() + '"/></li>')
                    .append((function(){
                        var colorList = '<li class="item"><label>Available colors:</label><ul class="colors">';
                        $(thisWidgetSettings.colorClasses).each(function () {
                            colorList += '<li class="' + this + '"/>';
                        });
                        return colorList + '</ul>';
                    })())
                    .append('</ul>')
                    .insertAfter($(settings.handleSelector,this));
            }
 
            if (thisWidgetSettings.collapsible) {
                $('<a href="#" class="collapse">COLLAPSE</a>').mousedown(function (e) {
                    /* STOP event bubbling */
                    e.stopPropagation();    
                }).click(function(){
                    $(this).parents(settings.widgetSelector).toggleClass('collapsed');
                    /* Save prefs to cookie: */
                    iNettuts.savePreferences();
                    return false;    
                }).prependTo($(settings.handleSelector,this));
            }
        });
 
        $('.edit-box').each(function () {
            $('input',this).keyup(function () {
                $(this).parents(settings.widgetSelector).find('h3').text( $(this).val().length>20 ? $(this).val().substr(0,20)+'...' : $(this).val() );
                iNettuts.savePreferences();
            });
			$('textarea',this).keyup(function () {
                $(this).parents(settings.widgetSelector).find('h4').text( $(this).val().length>400 ? $(this).val().substr(0,400)+'...' : $(this).val() );
                iNettuts.savePreferences();
            });
            $('ul.colors li',this).click(function () {
 
                var colorStylePattern = /\bcolor-[\w]{1,}\b/,
                    thisWidgetColorClass = $(this).parents(settings.widgetSelector).attr('class').match(colorStylePattern)
                if (thisWidgetColorClass) {
                    $(this).parents(settings.widgetSelector)
                        .removeClass(thisWidgetColorClass[0])
                        .addClass($(this).attr('class').match(colorStylePattern)[0]);
                    /* Save prefs to cookie: */
                    iNettuts.savePreferences();
                }
                return false;
 
            });
        });
 
    },
 
    attachStylesheet : function (href) {
        var $ = this.jQuery;
        return $('<link href="' + href + '" rel="stylesheet" type="text/css" />').appendTo('head');
    },
 
    makeSortable : function () {
        var iNettuts = this,
            $ = this.jQuery,
            settings = this.settings,
            $sortableItems = (function () {
                var notSortable = '';
                $(settings.widgetSelector,$(settings.columns)).each(function (i) {
                    if (!iNettuts.getWidgetSettings(this.id).movable) {
                        if(!this.id) {
                            this.id = 'widget-no-id-' + i;
                        }
                        notSortable += '#' + this.id + ',';
                    }
                });
                return $('> li:not(' + notSortable + ')', settings.columns);
            })();
 
        $sortableItems.find(settings.handleSelector).css({
            cursor: 'move'
        }).mousedown(function (e) {
            $sortableItems.css({width:''});
            $(this).parent().css({
                width: $(this).parent().width() + 'px'
            });
        }).mouseup(function () {
            if(!$(this).parent().hasClass('dragging')) {
                $(this).parent().css({width:''});
            } else {
                $(settings.columns).sortable('disable');
            }
        });
 
        $(settings.columns).sortable({
            items: $sortableItems,
            connectWith: $(settings.columns),
            handle: settings.handleSelector,
            placeholder: 'widget-placeholder',
            forcePlaceholderSize: true,
            revert: 300,
            delay: 100,
            opacity: 0.8,
            containment: 'document',
            start: function (e,ui) {
                $(ui.helper).addClass('dragging');
            },
            stop: function (e,ui) {
                $(ui.item).css({width:''}).removeClass('dragging');
                $(settings.columns).sortable('enable');
                /* Save prefs to cookie: */
                iNettuts.savePreferences();
            }
        });
    },
 
    savePreferences : function () {
        var iNettuts = this,
            $ = this.jQuery,
            settings = this.settings,
            cookieString = '';
 
        if(!settings.saveToCookie) {return;}
 
        /* Assemble the cookie string */
        $(settings.columns).each(function(i){
            cookieString += (i===0) ? '' : '|';
            $(settings.widgetSelector,this).each(function(i){
                cookieString += (i===0) ? '' : ';';
                /* ID of widget: */
                cookieString += $(this).attr('id') + ',';
                /* Color of widget (color classes) */
                cookieString += $(this).attr('class').match(/\bcolor-[\w]{1,}\b/) + ',';
                /* Title of widget (replaced used characters) */
                cookieString += $('h3:eq(0)',this).text().replace(/\|/g,'[-PIPE-]').replace(/,/g,'[-COMMA-]') + ',';
				/* Text of widget (replaced used characters) */
                cookieString += $('h4:eq(0)',this).text().replace(/\|/g,'[-PIPE-]').replace(/,/g,'[-COMMA-]') + ',';
                /* Collapsed/not collapsed widget? : */
                cookieString += $(settings.contentSelector,this).css('display') === 'none' ? 'collapsed' : 'not-collapsed';
            });
        });
 
        /* AJAX call to store string on database */
        $.post("iNettuts_rpc.php","value="+cookieString);
 
    },
 
    sortWidgets : function () {
        var iNettuts = this,
            $ = this.jQuery,
            settings = this.settings;
 
        if(!settings.saveToCookie) {
            $('body').css({background:'#000'});
            $(settings.columns).css({visibility:'visible'});
            return;
        }
 
        $.post("iNettuts_rpc.php", "",
            function(data){
 
              var cookie=data;
 
              if (cookie=="") {
                  $('body').css({background:'#000'});
                  $(settings.columns).css({visibility:'visible'});
                  iNettuts.addWidgetControls();
                  iNettuts.makeSortable();
                  return;
              }
 
              /* For each column */
              $(settings.columns).each(function(i){
 
                  var thisColumn = $(this),
                      widgetData = cookie.split('|')[i].split(';');
 
                  $(widgetData).each(function(){
                      if(!this.length) {return;}
                      var thisWidgetData = this.split(','),
                          clonedWidget = $('#' + thisWidgetData[0]),
                          colorStylePattern = /\bcolor-[\w]{1,}\b/,
                          thisWidgetColorClass = $(clonedWidget).attr('class').match(colorStylePattern);
 
                      /* Add/Replace new colour class: */
                      if (thisWidgetColorClass) {
                          $(clonedWidget).removeClass(thisWidgetColorClass[0]).addClass(thisWidgetData[1]);
                      }
 
                      /* Add/replace new title (Bring back reserved characters): */
                      $(clonedWidget).find('h3:eq(0)').html(thisWidgetData[2].replace(/\[-PIPE-\]/g,'|').replace(/\[-COMMA-\]/g,','));
 
					  /* Add/replace new text (Bring back reserved characters): */
                      $(clonedWidget).find('h4:eq(0)').html(thisWidgetData[3].replace(/\[-PIPE-\]/g,'|').replace(/\[-COMMA-\]/g,','));
 
                      /* Modify collapsed state if needed: */
                      if(thisWidgetData[4]==='collapsed') {
                          /* Set CSS styles so widget is in COLLAPSED state */
                          $(clonedWidget).addClass('collapsed');
                      }
 
                      $('#' + thisWidgetData[0]).remove();
                      $(thisColumn).append(clonedWidget);
                  });
              });
 
 
              /* All done, remove loading gif and show columns: */
              $('body').css({background:'#000'});
              $(settings.columns).css({visibility:'visible'});
 
              iNettuts.addWidgetControls();
              iNettuts.makeSortable();
 
            });
 
    }
 
};
 
iNettuts.init();
Ce que je cherche donc à faire, est seulement d'afficher la valeur numéro 3 qui est dans l'entrée de la table mysql, dans le textarea. Elle est affichée en dessous en simple texte, et lorsqu'on tape quelque chose dans le textarea, le texte en bas est mis à jour, c'est parfait. J'arrive seulement pas à récupérer le texte pour l'afficher dedans, je suis sûr que c'est un truc tout con sur lequel je suis passé ..

Merci de votre aide ! Si vous avez des questions n'hésitez pas !