1 | /*global $, reorder, dotclear, jsToolBar */ |
---|
2 | 'use strict'; |
---|
3 | |
---|
4 | $(function() { |
---|
5 | // clean |
---|
6 | $('.remove-if-drag').remove(); |
---|
7 | $('.hidden-if-drag').hide(); |
---|
8 | $('.widgets, .sortable-delete').addClass('if-drag'); |
---|
9 | |
---|
10 | // move |
---|
11 | $('.connected, .sortable-delete').sortable({ |
---|
12 | tolerance: 'move', |
---|
13 | cursor: 'move', |
---|
14 | axis: 'y', |
---|
15 | dropOnEmpty: true, |
---|
16 | handle: '.widget-name', |
---|
17 | placeholder: 'ui-sortable-placeholder', |
---|
18 | items: 'li:not(.sortable-delete-placeholder,.empty-widgets)', |
---|
19 | connectWith: '.connected, .sortable-delete', |
---|
20 | start: function(event, ui) { |
---|
21 | // petit décalage esthétique |
---|
22 | ui.item.css('left', ui.item.position().left + 20); |
---|
23 | }, |
---|
24 | update: function(event, ui) { |
---|
25 | const ul = $(this); |
---|
26 | const widget = ui.item; |
---|
27 | const field = ul.parents('.widgets'); |
---|
28 | |
---|
29 | // met a zéro le décalage |
---|
30 | ui.item.css('left', 'auto'); |
---|
31 | // Fixes issue #2080 |
---|
32 | ui.item.css('width', 'auto'); |
---|
33 | ui.item.css('height', 'auto'); |
---|
34 | |
---|
35 | // signale les zones vides |
---|
36 | if (ul.find('li:not(.empty-widgets)').length == 0) { |
---|
37 | ul.find('li.empty-widgets').show(); |
---|
38 | field.find('ul.sortable-delete').hide(); |
---|
39 | } else { |
---|
40 | ul.find('li.empty-widgets').hide(); |
---|
41 | field.find('ul.sortable-delete').show(); |
---|
42 | } |
---|
43 | |
---|
44 | // remove |
---|
45 | if (widget.parents('ul').is('.sortable-delete')) { |
---|
46 | widget.hide('slow', function() { |
---|
47 | $(this).remove(); |
---|
48 | }); |
---|
49 | } |
---|
50 | |
---|
51 | // réordonne |
---|
52 | reorder(ul); |
---|
53 | |
---|
54 | // expand |
---|
55 | if (widget.find('img.expand').length == 0) { |
---|
56 | dotclear.postExpander(widget); |
---|
57 | dotclear.viewPostContent(widget, 'close'); |
---|
58 | } |
---|
59 | } |
---|
60 | }); |
---|
61 | |
---|
62 | // add |
---|
63 | $('#widgets-ref > li').draggable({ |
---|
64 | tolerance: 'move', |
---|
65 | cursor: 'move', |
---|
66 | connectToSortable: '.connected', |
---|
67 | helper: 'clone', |
---|
68 | revert: 'invalid', |
---|
69 | start: function(event, ui) { |
---|
70 | ui.helper.css({ |
---|
71 | 'width': $('#widgets-ref > li').css('width') |
---|
72 | }); |
---|
73 | }, |
---|
74 | stop: function(event, ui) { |
---|
75 | if (!dotclear.widget_noeditor) { |
---|
76 | ui.helper.find('textarea:not(.noeditor)').each(function() { |
---|
77 | if ($.isFunction(jsToolBar)) { |
---|
78 | const tbWidgetText = new jsToolBar(this); |
---|
79 | tbWidgetText.draw('xhtml'); |
---|
80 | } |
---|
81 | }); |
---|
82 | } |
---|
83 | } |
---|
84 | }); |
---|
85 | |
---|
86 | $('li.ui-draggable, ul.ui-sortable li') |
---|
87 | .not('ul.sortable-delete li, li.empty-widgets') |
---|
88 | .css({ |
---|
89 | 'cursor': 'move' |
---|
90 | }); |
---|
91 | }); |
---|