Changeset 2401:06f7d3a90bd0
- Timestamp:
- 10/06/13 00:26:27 (12 years ago)
- Branch:
- widgets
- Location:
- plugins/widgets
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/widgets/dragdrop.js
r2395 r2401 59 59 60 60 // réordonne 61 if( ul.attr('id') ) { 62 ul.find('li').each(function(i) { 63 64 // trouve la zone de réception 65 var name = ul.attr('id').split('dnd').join(''); 66 67 // modifie le name en conséquence 68 $(this).find('*[name^=w]').each(function(){ 69 tab = $(this).attr('name').split(']['); 70 tab[0] = "w["+name; 71 tab[1] = i; 72 $(this).attr('name', tab.join('][')); 73 }); 74 75 // ainssi que le champ d'ordre sans js (au cas ou) 76 $(this).find('input[title=ordre]').val(i); 77 78 }); 79 } 61 reorder(ul); 80 62 81 63 // expand -
plugins/widgets/index.php
r2400 r2401 147 147 } 148 148 149 # Move ? 150 $move = false; 151 if ( isset($_POST['w']) && is_array($_POST['w']) ) { 152 foreach ($_POST['w'] as $nsid => $nsw) { 153 foreach ($nsw as $i => $v) { 154 if (!empty($v['down'])) { 155 $oldorder = $_POST['w'][$nsid][$i]['order']; 156 $neworder = $oldorder + 1; 157 if( isset($_POST['w'][$nsid][$neworder]) ) { 158 $_POST['w'][$nsid][$i]['order'] = $neworder; 159 $_POST['w'][$nsid][$neworder]['order'] = $oldorder; 160 $move = true; 161 } 162 } 163 if (!empty($v['up'])) { 164 $oldorder = $_POST['w'][$nsid][$i]['order']; 165 $neworder = $oldorder - 1; 166 if( isset($_POST['w'][$nsid][$neworder]) ) { 167 $_POST['w'][$nsid][$i]['order'] = $neworder; 168 $_POST['w'][$nsid][$neworder]['order'] = $oldorder; 169 $move = true; 170 } 171 } 172 } 173 } 174 } 175 149 176 # Update sidebars 150 if (!empty($_POST['wup']) || $removing )177 if (!empty($_POST['wup']) || $removing || $move ) 151 178 { 152 179 if (!isset($_POST['w']) || !is_array($_POST['w'])) { … … 384 411 foreach ($widgets->elements() as $w) 385 412 { 413 $upDisabled = $i == 0 ? '" disabled="" src="images/disabled_' : '" src="images/'; 414 $downDisabled = $i == count($widgets->elements())-1 ? '" disabled="" src="images/disabled_' : '" src="images/'; 415 386 416 $iname = 'w['.$pr.']['.$i.']'; 387 417 388 418 $res .= 389 419 '<li>'.form::hidden(array($iname.'[id]'),html::escapeHTML($w->id())). 390 '<p class="widget-name">'.form::field(array($iname.'[order]'),2,3,(string) $i,'hidden-if-drag','',0,'title="'.__('order').'"').' '.$w->name(). 420 '<p class="widget-name">'.form::field(array($iname.'[order]'),2,3,(string) $i,'hidden','',0,'title="'.__('order').'"'). 421 ' '.$w->name(). 391 422 ($w->desc() != '' ? ' <span class="form-note">'.__($w->desc()).'</span>' : ''). 392 '<input type="image" src="images/trash.png" class="removeWidget remove-if-drag" name="'.$iname.'[_rem]" value="'.__('Remove widget').'" />'. 423 '<span class="toolsWidget remove-if-drag">'. 424 '<input type="image" class="upWidget'.$upDisabled.'up.png" name="'.$iname.'[up]" value="'.__('Up the widget').'" />'. 425 '<input type="image" class="downWidget'.$downDisabled.'down.png" name="'.$iname.'[down]" value="'.__('Down the widget').'" />'.' '. 426 '<input type="image" class="removeWidget" src="images/trash.png" name="'.$iname.'[_rem]" value="'.__('Remove widget').'" />'. 427 '</span>'. 393 428 '<br class="clear"/></p>'. 394 429 '<div class="widgetSettings hidden-if-drag">'.$w->formSettings($iname,$j).'</div>'. -
plugins/widgets/style.css
r2400 r2401 102 102 display: none; 103 103 } 104 . removeWidget {104 .toolsWidget { 105 105 float: right; 106 106 } -
plugins/widgets/widgets.js
r2400 r2401 17 17 order = title.find('input[name*=order]'); 18 18 link = $('<a href="#" alt="expand" class="aexpand"/>').append(title.text()); 19 rem = title.find('input[name*=_rem]');19 tools = title.find('.toolsWidget'); 20 20 br = title.find('br'); 21 title.empty().append(order).append(link).append( rem).append(br);21 title.empty().append(order).append(link).append(tools).append(br); 22 22 23 23 var img = document.createElement('img'); … … 52 52 }; 53 53 54 $(function() { 54 function reorder(ul) { 55 // réordonne 56 if( ul.attr('id') ) { 57 $list = ul.find('li').not('.empty-widgets'); 58 $list.each(function(i) { 59 $this = $(this); 60 61 // trouve la zone de réception 62 var name = ul.attr('id').split('dnd').join(''); 63 64 // modifie le name en conséquence 65 $this.find('*[name^=w]').each(function(){ 66 tab = $(this).attr('name').split(']['); 67 tab[0] = "w["+name; 68 tab[1] = i; 69 $(this).attr('name', tab.join('][')); 70 }); 71 72 // ainsi que le champ d'ordre sans js (au cas ou) 73 $this.find('input[title=ordre]').val(i); 74 75 // active ou désactive les fléches 76 if( i == 0 ) { 77 $this.find('input.upWidget').prop('disabled', true); 78 $this.find('input.upWidget').prop('src', 'images/disabled_up.png' ); 79 } else { 80 $this.find('input.upWidget').removeAttr('disabled'); 81 $this.find('input.upWidget').prop('src', 'images/up.png' ); 82 } 83 if( i == $list.length-1 ) { 84 $this.find('input.downWidget').prop('disabled', true); 85 $this.find('input.downWidget').prop('src', 'images/disabled_down.png' ); 86 } else { 87 $this.find('input.downWidget').removeAttr('disabled'); 88 $this.find('input.downWidget').prop('src', 'images/down.png' ); 89 } 90 91 }); 92 } 93 } 94 95 $(function() { 55 96 // reset 56 97 $('input[name="wreset"]').click(function() { … … 65 106 66 107 // remove 67 $('input[name*=rem]').change(function () { 68 if ($(this).attr("checked")) { 69 $(this).parents('li').remove(); 70 } 108 $('input[name*=rem]').click(function (e) { 109 e.preventDefault(); 110 $(this).parents('li').remove(); 71 111 }); 72 112 113 // move 114 $('input[name*=down]').click(function (e) { 115 e.preventDefault(); 116 $this = $(this); 117 $li = $this.parents('li'); 118 $li.next().after($li); 119 reorder($this.parents('ul.connected')); 120 }); 121 $('input[name*=up]').click(function (e) { 122 e.preventDefault(); 123 $this = $(this); 124 $li = $this.parents('li'); 125 $li.prev().before($li); 126 reorder($this.parents('ul.connected')); 127 }); 73 128 });
Note: See TracChangeset
for help on using the changeset viewer.