Dotclear

source: admin/js/_blog_theme.js @ 3880:e6d1f6d9d7df

Revision 3880:e6d1f6d9d7df, 2.5 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use let and const rather than var (ES2015/ES6), use template string where is more efficient

Line 
1/*global $, dotclear */
2'use strict';
3
4$(function() {
5  // expend theme info
6  $('.module-sshot').not('.current-theme .module-sshot').each(function() {
7    const bar = $('<div>').addClass('bloc-toggler');
8    $(this).after(
9      $(bar).toggleWithLegend($(this).parent().children('.toggle-bloc'), {
10        img_on_txt: dotclear.img_plus_theme_txt,
11        img_on_alt: dotclear.img_plus_theme_alt,
12        img_off_txt: dotclear.img_minus_theme_txt,
13        img_off_alt: dotclear.img_minus_theme_alt,
14        legend_click: true
15      }));
16    $(this).children('img').click(function() {
17      // Click on theme thumbnail
18      $(this).parent().parent().children('.bloc-toggler').click();
19    });
20  });
21
22  // dirty short search blocker
23  $('div.modules-search form input[type=submit]').click(function() {
24    const mlen = $('input[name=m_search]', $(this).parent()).val();
25    if (mlen.length > 2) {
26      return true;
27    } else {
28      return false;
29    }
30  });
31
32  // checkboxes selection
33  $('.checkboxes-helpers').each(function() {
34    dotclear.checkboxesHelpers(this);
35  });
36
37  // actions tests
38  $('.modules-form-actions').each(function() {
39    const rxActionType = /^[^\[]+/;
40    const rxActionValue = /([^\[]+)\]$/;
41    const checkboxes = $(this).find('input[type=checkbox]');
42
43    // check if submit is a global action or one line action
44    $('input[type=submit]', this).click(function() {
45      const keyword = $(this).attr('name');
46      if (!keyword) {
47        return true;
48      }
49      const maction = keyword.match(rxActionType);
50      const action = maction[0];
51      const mvalues = keyword.match(rxActionValue);
52
53      // action on multiple modules
54      if (!mvalues) {
55        let checked = false;
56
57        // check if there is checkboxes in form
58        if (checkboxes.length > 0) {
59          // check if there is at least one checkbox checked
60          $(checkboxes).each(function() {
61            if (this.checked) {
62              checked = true;
63            }
64          });
65          if (!checked) {
66            //alert(dotclear.msg.no_selection);
67            return false;
68          }
69        }
70
71        // confirm delete
72        if (action == 'delete') {
73          return window.confirm(dotclear.msg.confirm_delete_themes);
74        }
75
76        // action on one module
77      } else {
78        const module = mvalues[1];
79
80        // confirm delete
81        if (action == 'delete') {
82          return window.confirm(dotclear.msg.confirm_delete_theme.replace('%s', module));
83        }
84      }
85
86      return true;
87    });
88  });
89});
Note: See TracBrowser for help on using the repository browser.

Sites map