-
Notifications
You must be signed in to change notification settings - Fork 0
/
elFinderPicker.js
83 lines (72 loc) · 2 KB
/
elFinderPicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
(function ($) {
const settings = {
url: '',
};
let callback, meta, popup;
window.elFinderPicker = {
open: function (cb, v, m) {
callback = cb;
meta = m;
if (popup) {
popup.show();
} else {
popup = $(
" <div class='elfinder-picker'>" +
" <div class='elfinder-picker-backdrop'></div>" +
" <div class='elfinder-picker-content'>" +
" <h3 class='elfinder-picker-title'>File Manager</h3>" +
" <div class='elfinder-picker-close'>×</div>" +
" <iframe class='elfinder-picker-iframe' src='" +
settings.url +
"' allowfullscreen data-mode='select'></iframe>" +
' </div>' +
'</div>'
);
$(document.body).append(popup);
popup
.find('.elfinder-picker-close, .elfinder-picker-backdrop')
.click(function () {
popup.hide();
});
}
return popup;
},
config: function (config) {
const fields = ['url'];
fields.forEach(function (field) {
if (config[field]) {
settings[field] = config[field];
}
});
},
oninsert: function (file) {
let url, reg, info;
meta = meta || { filetype: 'file' };
// URL normalization
url = file.url;
reg = /\/[^/]+?\/\.\.\//;
while (url.match(reg)) {
url = url.replace(reg, '/');
}
// Make file info
info = file.name;
// Provide file and text for the link dialog
if (meta.filetype == 'file') {
callback(url, { text: info, title: info });
}
// Provide image and alt text for the image dialog
if (meta.filetype == 'image') {
callback(url, { alt: info });
}
// Provide alternative source and posted for the media dialog
if (meta.filetype == 'media') {
callback(url);
}
this.close();
},
close: function () {
popup.hide();
},
};
})(jQuery);