forked from Redactor2/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilemanager.js
executable file
·65 lines (52 loc) · 1.49 KB
/
filemanager.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
(function($)
{
$.Redactor.prototype.filemanager = function()
{
return {
langs: {
en: {
"upload": "Upload",
"choose": "Choose"
}
},
init: function()
{
if (!this.opts.fileManagerJson)
{
return;
}
this.modal.addCallback('file', this.filemanager.load);
},
load: function()
{
var $box = $('<div style="overflow: auto; height: 300px; display: none;" class="redactor-modal-tab" data-title="Choose">').hide();
this.modal.getModal().append($box);
$.ajax({
dataType: "json",
cache: false,
url: this.opts.fileManagerJson,
success: $.proxy(function(data)
{
var ul = $('<ul id="redactor-modal-list">');
$.each(data, $.proxy(function(key, val)
{
var a = $('<a href="#" data-params="' + encodeURI(JSON.stringify(val)) + '" class="redactor-file-manager-link">' + val.title + ' <span style="font-size: 11px; color: #888;">' + val.name + '</span> <span style="position: absolute; right: 10px; font-size: 11px; color: #888;">(' + val.size + ')</span></a>');
var li = $('<li />');
a.on('click', $.proxy(this.filemanager.insert, this));
li.append(a);
ul.append(li);
}, this));
$box.append(ul);
}, this)
});
},
insert: function(e)
{
e.preventDefault();
var $el = $(e.target).closest('.redactor-file-manager-link');
var json = $.parseJSON(decodeURI($el.attr('data-params')));
this.file.insert(json, null);
}
};
};
})(jQuery);