Dotclear

source: plugins/widgets/js/widgets.js @ 3825:b09d7ce99c2f

Revision 3825:b09d7ce99c2f, 3.8 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Allows textarea settings in widget without HTML editor, even if activated in user prefs.

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

Sites map