public/js/stand-alone-button.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.17

Size

Lines of Code 36
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 36
rs 10
wmc 7
mnd 1
bc 1
fnc 6
bpm 0.1666
cpm 1.1666
noi 1
1
(function( $ ){
2
3
  $.fn.filemanager = function(type, options) {
4
    type = type || 'file';
5
6
    this.on('click', function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
7
      var route_prefix = (options && options.prefix) ? options.prefix : '/filemanager';
8
      var target_input = $('#' + $(this).data('input'));
9
      var target_preview = $('#' + $(this).data('preview'));
10
      window.open(route_prefix + '?type=' + type, 'FileManager', 'width=900,height=600');
11
      window.SetUrl = function (items) {
12
        var file_path = items.map(function (item) {
13
          return item.url;
14
        }).join(',');
15
16
        // set the value of the desired input to image url
17
        target_input.val('').val(file_path).trigger('change');
18
19
        // clear previous preview
20
        target_preview.html('');
21
22
        // set or change the preview image src
23
        items.forEach(function (item) {
24
          target_preview.append(
25
            $('<img>').css('height', '5rem').attr('src', item.thumb_url)
26
          );
27
        });
28
29
        // trigger change event
30
        target_preview.trigger('change');
31
      };
32
      return false;
33
    });
34
  }
35
36
})(jQuery);
37