Dotclear

source: plugins/widgets/dragdrop.js @ 1766:a3e16ad9e270

Revision 1766:a3e16ad9e270, 2.4 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

Un peu de javascript grâce à Lipki sur les pages User préférences et Widets. Le curseur move est visible dès le survol.

Line 
1/*
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12*/
13
14$(function() {
15     
16     // clean
17     $('.remove-if-drag').remove();
18     $('.hidden-if-drag').hide();
19     $('.widgets, .sortable-delete').addClass('if-drag');
20     
21     // move
22     $( ".connected, .sortable-delete" ).sortable({
23          tolerance: "move",
24          cursor: "move",
25          axis: "y",
26          dropOnEmpty: true,
27          handle: ".widget-name",
28          placeholder: "ui-sortable-placeholder",
29          items: "li:not(.sortable-delete-placeholder)",
30          connectWith: ".connected, .sortable-delete",
31          start: function( event, ui ) {
32               // petit décalage esthétique
33               ui.item.css('left', ui.item.position().left + 20);
34          },
35          update: function(event, ui) {
36               
37               ul = $(this);
38               widget = ui.item;
39               field = ul.parents('.widgets');
40               
41               // met a zéro le décalage
42               ui.item.css('left', 'auto');
43               
44               // signale les zones vides
45               if( ul.find('li').length == 0 )
46                     field.find('.empty-widgets').show();
47               else field.find('.empty-widgets').hide();
48               
49               // remove
50               if( widget.parents('ul').is('.sortable-delete') ) {
51                    widget.hide('slow', function() {
52                         $(this).remove();
53                    });
54               }
55               
56               // réordonne
57               if( ul.attr('id') ) {
58                    ul.find('li').each(function(i) {
59                         
60                         // trouve la zone de réception
61                         var name = ul.attr('id').split('dnd').join('');
62                         
63                         // modifie le name en conséquence
64                         $(this).find('*[name^=w]').each(function(){
65                              tab = $(this).attr('name').split('][');
66                              tab[0] = "w["+name;
67                              tab[1] = i;
68                              $(this).attr('name', tab.join(']['));
69                         });
70                         
71                         // ainssi que le champ d'ordre sans js (au cas ou)
72                         $(this).find('input[title=ordre]').val(i);
73                         
74                    });
75               }
76               
77               // expand
78               if(widget.find('img.expand').length == 0) {
79                    dotclear.postExpander(widget);
80                    dotclear.viewPostContent(widget, 'close');
81               }
82               
83          }
84     });
85     
86     // add
87     $( "#widgets-ref > li" ).draggable({
88          tolerance: "move",
89          cursor: "move",
90          connectToSortable: ".connected",
91          helper: "clone",
92          revert: "invalid",
93          start: function( event, ui ) {
94               ui.helper.css({'width': $('#widgets-ref > li').css('width')});
95          }
96     });
97     $("li.ui-draggable, ul.ui-sortable li").css({'cursor':'move'});
98});
Note: See TracBrowser for help on using the repository browser.

Sites map