| 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,.empty-widgets)", | 
|---|
| 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:not(.empty-widgets)').length == 0 ) { | 
|---|
| 46 |                     ul.find('li.empty-widgets').show(); | 
|---|
| 47 |                     field.find('ul.sortable-delete').hide(); | 
|---|
| 48 |                } else { | 
|---|
| 49 |                     ul.find('li.empty-widgets').hide(); | 
|---|
| 50 |                     field.find('ul.sortable-delete').show(); | 
|---|
| 51 |                } | 
|---|
| 52 |                 | 
|---|
| 53 |                // remove | 
|---|
| 54 |                if( widget.parents('ul').is('.sortable-delete') ) { | 
|---|
| 55 |                     widget.hide('slow', function() { | 
|---|
| 56 |                          $(this).remove(); | 
|---|
| 57 |                     }); | 
|---|
| 58 |                } | 
|---|
| 59 |                 | 
|---|
| 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 |                } | 
|---|
| 80 |                 | 
|---|
| 81 |                // expand | 
|---|
| 82 |                if(widget.find('img.expand').length == 0) { | 
|---|
| 83 |                     dotclear.postExpander(widget); | 
|---|
| 84 |                     dotclear.viewPostContent(widget, 'close'); | 
|---|
| 85 |                } | 
|---|
| 86 |                 | 
|---|
| 87 |           } | 
|---|
| 88 |      }); | 
|---|
| 89 |       | 
|---|
| 90 |      // add | 
|---|
| 91 |      $( "#widgets-ref > li" ).draggable({ | 
|---|
| 92 |           tolerance: "move", | 
|---|
| 93 |           cursor: "move", | 
|---|
| 94 |           connectToSortable: ".connected", | 
|---|
| 95 |           helper: "clone", | 
|---|
| 96 |           revert: "invalid", | 
|---|
| 97 |           start: function( event, ui ) { | 
|---|
| 98 |                ui.helper.css({'width': $('#widgets-ref > li').css('width')}); | 
|---|
| 99 |           } | 
|---|
| 100 |      }); | 
|---|
| 101 |       | 
|---|
| 102 |      $("li.ui-draggable, ul.ui-sortable li") | 
|---|
| 103 |           .not('ul.sortable-delete li, li.empty-widgets') | 
|---|
| 104 |           .css({'cursor':'move'}); | 
|---|
| 105 | }); | 
|---|