Dotclear

source: plugins/widgets/widgets.js @ 1650:d62b141eeae6

Revision 1650:d62b141eeae6, 6.4 KB checked in by Lepeltier kévin, 12 years ago (diff)

Ticket #1604 progression

Line 
1dotclear.postExpander = function(line) {
2     var title = $(line).find('.widget-name');
3     
4     var img = document.createElement('img');
5     img.src = dotclear.img_plus_src;
6     img.alt = dotclear.img_plus_alt;
7     img.className = 'expand';
8     $(img).css('cursor','pointer');
9     img.line = line;
10     img.onclick = function() { dotclear.viewPostContent(this.line); };
11     
12     title.prepend(img);
13};
14
15dotclear.viewPostContent = function(line,action) {
16     var action = action || 'toogle';
17     var img = $(line).find('.expand');
18     var isopen = img.attr('alt') == dotclear.img_plus_alt;
19     
20     if( action == 'close' || ( action == 'toogle' && !isopen ) ) {
21          $(line).find('.widgetSettings').hide();
22          img.attr('src', dotclear.img_plus_src);
23          img.attr('alt', dotclear.img_plus_alt);
24     } else if ( action == 'open' || ( action == 'toogle' && isopen ) ) {
25          $(line).find('.widgetSettings').show();
26          img.attr('src', dotclear.img_minus_src);
27          img.attr('alt', dotclear.img_minus_alt);
28     }
29     
30};
31
32$(function() { 
33     $('input[name="wreset"]').click(function() {
34          return window.confirm(dotclear.msg.confirm_widgets_reset);
35     });
36     
37     $('#dndnav > li, #dndextra > li, #dndcustom > li').each(function() {
38          dotclear.postExpander(this);
39          dotclear.viewPostContent(this, 'close');
40     });
41});
42     
43     /*var widgets = document.getElementById('widgets');
44     var w_nav = document.getElementById('dndnav');
45     var w_ext = document.getElementById('dndextra');
46     var w_custom = document.getElementById('dndcustom');
47     
48     $('#dndnav').addClass('hideControls');
49     $('#dndextra').addClass('hideControls');
50     $('#dndcustom').addClass('hideControls');
51     
52     removeElements(document.getElementById('listWidgets'),'input');
53     removeElements(widgets,'p');
54     removeElements(w_nav,'p');
55     removeElements(w_ext,'p');
56     removeElements(w_custom,'p');
57     hideElements(w_nav,'input');
58     hideElements(w_ext,'input');
59     hideElements(w_custom,'input');
60     
61     configControls(w_nav);
62     configControls(w_ext);
63     configControls(w_custom);
64     
65     // Helper to remove some elements
66     function removeElements(p,name) {
67          name = name || 'div';
68          $(p).find(name+'.js-remove').each(function() {
69               this.parentNode.removeChild(this);
70          });
71     }
72     
73     // Helper to hide elements (but keep them)
74     function hideElements(p,name) {
75          name = name || 'div';
76          $(p).find(name+'.js-hide').each(function() {
77               $(this).toggle();
78          });
79     }   
80     
81     function removeEmptyMsg(p) {
82          $(p).find('p.empty-widgets').each(function() {
83               this.parentNode.removeChild(this);
84          });
85     }
86     
87     // Events on dragEnd
88     function navDragEnd() {
89          formControls(this.parentNode,'nav');
90          configControls(this.parentNode);
91          removeEmptyMsg(this.parentNode);
92     }
93     function extraDragEnd() {
94          formControls(this.parentNode,'extra');
95          configControls(this.parentNode);
96          removeEmptyMsg(this.parentNode);
97     }
98     function customDragEnd() {
99          formControls(this.parentNode,'custom');
100          configControls(this.parentNode);
101          removeEmptyMsg(this.parentNode);
102     }
103     
104     // dragEnd helper
105     function formControls(e,pr) {
106          var items = new Array();
107          for (var i=0; i<e.childNodes.length; i++) {
108               if (e.childNodes[i].nodeType == 1 && e.childNodes[i].nodeName.toLowerCase() == 'div') {
109                    items.push(e.childNodes[i]);
110               }
111          }
112         
113          var fields, itype;
114          var r = new RegExp('^w\[[a-z]+]\[[0-9]+][[](.+?)]$','');
115          for (i=0; i<items.length; i++) {
116               // Change field names
117               fields = getFormControls(items[i]);
118               var j;
119               var f;
120               for (j=0; j<fields.length; j++) {
121                    if (r.test(fields[j].name)) {
122                         itype = fields[j].name.replace(r,'$1');
123                         
124                         $(fields[j]).attr('name','w['+pr+']['+i+']['+itype+']');
125                         
126                         if (itype == 'order') {
127                              fields[j].value = i;
128                         }
129                    }
130               }
131          }
132     }
133     
134     function getFormControls(e) {
135          var input = e.getElementsByTagName('input');
136          var textarea = e.getElementsByTagName('textarea');
137          var select = e.getElementsByTagName('select');
138          var items = new Array();
139          var i;
140          for (i=0; i<input.length; i++) { items.push(input[i]); }
141          for (i=0; i<select.length; i++) { items.push(select[i]); }
142          for (i=0; i<textarea.length; i++) { items.push(textarea[i]); }
143         
144          return items;
145     }
146     
147     function configControls(e) {
148          var items = new Array();
149          for (var i=0; i<e.childNodes.length; i++) {
150               if (e.childNodes[i].nodeType == 1 && e.childNodes[i].nodeName.toLowerCase() == 'div') {
151                    items.push(e.childNodes[i]);
152               }
153          }
154         
155          var title, img_ctrl, img, space;
156          for (i in items) {
157               // Append config control
158               title = $('p.widget-name',items[i]).get(0);
159               img_ctrl = title.firstChild;
160               
161               // There already an image
162               if (img_ctrl.nodeName.toLowerCase() == 'img') {
163                    continue;
164               }
165               
166               // Nothing to configure
167               if (title.nextSibling.childNodes.length == 0) {
168                    continue;
169               }
170               
171               img = document.createElement('img');
172               img.src = dotclear.img_plus_src;
173               img.alt = dotclear.img_plus_alt;
174               img.control = title.nextSibling;
175               img.onclick = function() { widgetConfig.call(this); };
176               space = document.createTextNode(' ');
177               title.insertBefore(img,img_ctrl);
178               title.insertBefore(space,img_ctrl);
179          }
180     }
181     
182     function widgetConfig() {
183          if (this.control.style.display == 'block') {
184               this.control.style.display = 'none';
185               this.src = dotclear.img_plus_src;
186               this.alt = dotclear.img_plus_alt;
187          } else {
188               this.control.style.display = 'block';
189               this.src = dotclear.img_minus_src;
190               this.alt = dotclear.img_minus_alt;
191          }
192     }
193});
194
195//
196// For Safari, we need to make a hard copy of the form and submit copy.
197// Yeah, a simple clone of the form is not enough
198// I hate this browser!
199//
200if (document.childNodes && !document.all && !navigator.taintEnabled)
201{
202     $(function() {
203          $('#sidebarsWidgets').submit(function() {
204               // Create a new form and copy each element inside
205               var f = document.createElement('form');
206               f.action = this.action;
207               f.method = this.method;
208               $(f).hide();
209               var fset = document.createElement('fieldset');
210               f.appendChild(fset);
211               
212               document.body.appendChild(f);
213               
214               $(this).find('input').each(function() {
215                    var i = document.createElement('input');
216                    i.type = this.type;
217                    i.name = this.name;
218                    i.value = this.value;
219                    if (this.type == 'checkbox') {
220                         i.checked = this.checked;
221                    }
222                    fset.appendChild(i);
223               });
224               
225               $(this).find('textarea').each(function() {
226                    var i = document.createElement('textarea');
227                    i.name = this.name;
228                    i.value = this.value;
229                    fset.appendChild(i);
230               });
231               
232               $(this).find('select').each(function() {
233                    var i = document.createElement('input');
234                    i.name = this.name;
235                    i.value = this.value;
236                    fset.appendChild(i);
237               });
238               
239               $(fset).append('<input type="hidden" name="wup" value="1"/>');
240               f.submit();
241               
242               return false;
243          });
244     });
245}*/
Note: See TracBrowser for help on using the repository browser.

Sites map