1 | $(function() { |
---|
2 | |
---|
3 | // clean |
---|
4 | $('.js-remove').remove(); |
---|
5 | $('.js-hide').hide(); |
---|
6 | $('.widgetSettings').hide(); |
---|
7 | |
---|
8 | // move |
---|
9 | $( ".connected, .sortable-delete" ).sortable({ |
---|
10 | tolerance: "move", |
---|
11 | cursor: "move", |
---|
12 | axis: "y", |
---|
13 | dropOnEmpty: true, |
---|
14 | handle: ".widget-name", |
---|
15 | placeholder: "ui-sortable-placeholder", |
---|
16 | connectWith: ".connected, .sortable-delete", |
---|
17 | start: function( event, ui ) { |
---|
18 | ui.item.css('left', ui.item.position().left + 30); |
---|
19 | }, |
---|
20 | update: function(event, ui) { |
---|
21 | |
---|
22 | // mes a zéro le décalage |
---|
23 | ui.item.css('left', 'auto'); |
---|
24 | |
---|
25 | if( $(this).find('li').length == 0 ) { |
---|
26 | $(this).parents('.widgets').find('.empty-widgets').show(); |
---|
27 | } else { |
---|
28 | $(this).parents('.widgets').find('.empty-widgets').hide(); |
---|
29 | } |
---|
30 | |
---|
31 | // réordonne |
---|
32 | if( $(this).attr('id') ) { |
---|
33 | $(this).find('input[title=ordre]').each(function(i){ |
---|
34 | tab = $(this).val(i); |
---|
35 | }); |
---|
36 | } |
---|
37 | |
---|
38 | // switch |
---|
39 | if( $(this).attr('id') != ui.item.parents('ul').attr('id') ) { |
---|
40 | //oldname = $(this).attr('id').split('dnd').join(''); |
---|
41 | var name = ui.item.parents('ul').attr('id').split('dnd').join(''); |
---|
42 | ui.item.find('*[name^=w]').each(function(){ |
---|
43 | tab = $(this).attr('name').split(']['); |
---|
44 | tab[0] = "w["+name; |
---|
45 | $(this).attr('name', tab.join('][')); |
---|
46 | }); |
---|
47 | } |
---|
48 | |
---|
49 | } //, |
---|
50 | //change: function( event, ui ) { |
---|
51 | //ui.helper.css('height', $('#dndnav .widget-name').css('height')); |
---|
52 | //} |
---|
53 | }); |
---|
54 | |
---|
55 | // add |
---|
56 | $( "#widgets > li" ).draggable({ |
---|
57 | tolerance: "move", |
---|
58 | cursor: "move", |
---|
59 | connectToSortable: ".connected", |
---|
60 | helper: "clone", |
---|
61 | revert: "invalid", |
---|
62 | start: function( event, ui ) { |
---|
63 | ui.helper.css({'width': $('#widgets > li').css('width')}); |
---|
64 | //ui.helper.css({'min-height': $('#dndnav .widget-name').css('height')}); |
---|
65 | //ui.helper.find('.form-note').hide(); |
---|
66 | //ui.helper.find('.widget-name').css({'min-height': $('#dndnav .widget-name').css('height')}); |
---|
67 | } |
---|
68 | }); |
---|
69 | |
---|
70 | //$( "#widgets, .connected, .sortable-delete" ).disableSelection(); |
---|
71 | |
---|
72 | }); |
---|