Dotclear

source: plugins/widgets/js/widgets.js @ 3845:29f6bacd00ef

Revision 3845:29f6bacd00ef, 3.9 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

I forgot the widgets :-p

Line 
1/*global $, dotclear, jsToolBar */
2'use strict';
3
4dotclear.postExpander = function(line) {
5
6  var title = $(line).find('.widget-name');
7  title.find('.form-note').remove();
8
9  var order = title.find('input[name*=order]');
10  var link = $('<a href="#" alt="expand" class="aexpand"/>').append(title.text());
11  var tools = title.find('.toolsWidget');
12  var br = title.find('br');
13  title.empty().append(order).append(link).append(tools).append(br);
14
15  var b = document.createElement('button');
16  b.setAttribute('type', 'button');
17  b.className = 'details-cmd';
18  b.value = dotclear.img_plus_txt;
19  b.setAttribute('aria-label', dotclear.img_plus_alt);
20  var t = document.createTextNode(dotclear.img_plus_txt);
21  b.appendChild(t);
22  b.onclick = function(e) {
23    e.preventDefault();
24    dotclear.viewPostContent($(this).parents('li'));
25  };
26  link.click(function(e) {
27    e.preventDefault();
28    dotclear.viewPostContent($(this).parents('li'));
29  });
30  title.prepend(b);
31};
32
33dotclear.viewPostContent = function(line, action) {
34  action = action || 'toogle';
35  var img = line.find('.details-cmd');
36  var isopen = img.attr('aria-label') == dotclear.img_plus_alt;
37
38  if (action == 'close' || (action == 'toogle' && !isopen)) {
39    line.find('.widgetSettings').hide();
40    img.html(dotclear.img_plus_txt);
41    img.attr('value', dotclear.img_plus_txt);
42    img.attr('aria-label', dotclear.img_plus_alt);
43  } else if (action == 'open' || (action == 'toogle' && isopen)) {
44    line.find('.widgetSettings').show();
45    img.html(dotclear.img_minus_txt);
46    img.attr('value', dotclear.img_minus_txt);
47    img.attr('aria-label', dotclear.img_minus_alt);
48  }
49
50};
51
52function reorder(ul) {
53  // réordonne
54  if (ul.attr('id')) {
55    var $list = ul.find('li').not('.empty-widgets');
56    $list.each(function(i) {
57      var $this = $(this);
58
59      // trouve la zone de réception
60      var name = ul.attr('id').split('dnd').join('');
61
62      // modifie le name en conséquence
63      $this.find('*[name^=w]').each(function() {
64        var tab = $(this).attr('name').split('][');
65        tab[0] = 'w[' + name;
66        tab[1] = i;
67        $(this).attr('name', tab.join(']['));
68      });
69
70      // ainsi que le champ d'ordre sans js (au cas ou)
71      $this.find('input[name*=order]').val(i);
72
73      // active ou désactive les fléches
74      if (i == 0) {
75        $this.find('input.upWidget').prop('disabled', true);
76        $this.find('input.upWidget').prop('src', 'images/disabled_up.png');
77      } else {
78        $this.find('input.upWidget').removeAttr('disabled');
79        $this.find('input.upWidget').prop('src', 'images/up.png');
80      }
81      if (i == $list.length - 1) {
82        $this.find('input.downWidget').prop('disabled', true);
83        $this.find('input.downWidget').prop('src', 'images/disabled_down.png');
84      } else {
85        $this.find('input.downWidget').removeAttr('disabled');
86        $this.find('input.downWidget').prop('src', 'images/down.png');
87      }
88
89    });
90  }
91}
92
93$(function() {
94  // reset
95  $('input[name="wreset"]').click(function() {
96    return window.confirm(dotclear.msg.confirm_widgets_reset);
97  });
98
99  // plier/déplier
100  $('#dndnav > li, #dndextra > li, #dndcustom > li').each(function() {
101    dotclear.postExpander(this);
102    dotclear.viewPostContent($(this), 'close');
103  });
104
105  // remove
106  $('input[name*=_rem]').click(function(e) {
107    e.preventDefault();
108    $(this).parents('li').remove();
109  });
110
111  // move
112  $('input[name*=_down]').click(function(e) {
113    e.preventDefault();
114    var $this = $(this);
115    var $li = $this.parents('li');
116    $li.next().after($li);
117    reorder($this.parents('ul.connected'));
118  });
119  $('input[name*=_up]').click(function(e) {
120    e.preventDefault();
121    var $this = $(this);
122    var $li = $this.parents('li');
123    $li.prev().before($li);
124    reorder($this.parents('ul.connected'));
125  });
126
127  // HTML text editor
128  if ($.isFunction(jsToolBar)) {
129    $('#sidebarsWidgets textarea').each(function() {
130      var tbWidgetText = new jsToolBar(this);
131      tbWidgetText.draw('xhtml');
132    });
133  }
134
135});
Note: See TracBrowser for help on using the repository browser.

Sites map