Dotclear

source: plugins/widgets/js/widgets.js @ 3709:c88e69474c34

Revision 3709:c88e69474c34, 3.7 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

use strict and no more linter warnings/errors as far as possible, switch from inline js to separate loaded file

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

Sites map