[1659] | 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 | |
---|
[1648] | 14 | dotclear.postExpander = function(line) { |
---|
| 15 | var title = $(line).find('.widget-name'); |
---|
[1659] | 16 | title.find('.form-note').remove(); |
---|
| 17 | order = title.find('input[name*=order]'); |
---|
| 18 | link = $('<a href="#" alt="expand" class="aexpand"/>').append(title.text()); |
---|
[2401] | 19 | tools = title.find('.toolsWidget'); |
---|
[2400] | 20 | br = title.find('br'); |
---|
[2401] | 21 | title.empty().append(order).append(link).append(tools).append(br); |
---|
[1648] | 22 | |
---|
| 23 | var img = document.createElement('img'); |
---|
| 24 | img.src = dotclear.img_plus_src; |
---|
| 25 | img.alt = dotclear.img_plus_alt; |
---|
| 26 | img.className = 'expand'; |
---|
| 27 | $(img).css('cursor','pointer'); |
---|
[1659] | 28 | img.onclick = function() { dotclear.viewPostContent($(this).parents('li')); }; |
---|
| 29 | link.click(function(e) { |
---|
| 30 | e.preventDefault(); |
---|
| 31 | dotclear.viewPostContent($(this).parents('li')); |
---|
| 32 | }); |
---|
[1648] | 33 | |
---|
| 34 | title.prepend(img); |
---|
| 35 | }; |
---|
| 36 | |
---|
| 37 | dotclear.viewPostContent = function(line,action) { |
---|
| 38 | var action = action || 'toogle'; |
---|
[1659] | 39 | var img = line.find('.expand'); |
---|
[1648] | 40 | var isopen = img.attr('alt') == dotclear.img_plus_alt; |
---|
| 41 | |
---|
| 42 | if( action == 'close' || ( action == 'toogle' && !isopen ) ) { |
---|
[1659] | 43 | line.find('.widgetSettings').hide(); |
---|
[1648] | 44 | img.attr('src', dotclear.img_plus_src); |
---|
| 45 | img.attr('alt', dotclear.img_plus_alt); |
---|
| 46 | } else if ( action == 'open' || ( action == 'toogle' && isopen ) ) { |
---|
[1659] | 47 | line.find('.widgetSettings').show(); |
---|
[1648] | 48 | img.attr('src', dotclear.img_minus_src); |
---|
| 49 | img.attr('alt', dotclear.img_minus_alt); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | }; |
---|
| 53 | |
---|
[2401] | 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() { |
---|
[1651] | 96 | // reset |
---|
[0] | 97 | $('input[name="wreset"]').click(function() { |
---|
| 98 | return window.confirm(dotclear.msg.confirm_widgets_reset); |
---|
| 99 | }); |
---|
| 100 | |
---|
[1651] | 101 | // plier/déplier |
---|
[1648] | 102 | $('#dndnav > li, #dndextra > li, #dndcustom > li').each(function() { |
---|
| 103 | dotclear.postExpander(this); |
---|
[1659] | 104 | dotclear.viewPostContent($(this), 'close'); |
---|
[1648] | 105 | }); |
---|
[0] | 106 | |
---|
[1651] | 107 | // remove |
---|
[2408] | 108 | $('input[name*=_rem]').click(function (e) { |
---|
[2401] | 109 | e.preventDefault(); |
---|
| 110 | $(this).parents('li').remove(); |
---|
[1651] | 111 | }); |
---|
[0] | 112 | |
---|
[2401] | 113 | // move |
---|
[2408] | 114 | $('input[name*=_down]').click(function (e) { |
---|
[2401] | 115 | e.preventDefault(); |
---|
| 116 | $this = $(this); |
---|
| 117 | $li = $this.parents('li'); |
---|
| 118 | $li.next().after($li); |
---|
| 119 | reorder($this.parents('ul.connected')); |
---|
| 120 | }); |
---|
[2408] | 121 | $('input[name*=_up]').click(function (e) { |
---|
[2401] | 122 | e.preventDefault(); |
---|
| 123 | $this = $(this); |
---|
| 124 | $li = $this.parents('li'); |
---|
| 125 | $li.prev().before($li); |
---|
| 126 | reorder($this.parents('ul.connected')); |
---|
| 127 | }); |
---|
[1651] | 128 | }); |
---|