/
imagemanager.js
55 lines (44 loc) · 1.41 KB
/
imagemanager.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
(function($)
{
$.Redactor.prototype.imagemanager = function()
{
return {
init: function()
{
if (!this.opts.imageManagerJson) return;
this.modal.addCallback('image', this.imagemanager.load);
},
load: function()
{
var $modal = this.modal.getModal();
this.modal.createTabber($modal);
this.modal.addTab(1, 'Upload', 'active');
this.modal.addTab(2, 'Choose');
$('#redactor-modal-image-droparea').addClass('redactor-tab redactor-tab1');
var $box = $('<div id="redactor-image-manager-box" style="overflow: auto; height: 300px;" class="redactor-tab redactor-tab2">').hide();
$modal.append($box);
$.ajax({
dataType: "json",
cache: false,
url: this.opts.imageManagerJson,
success: $.proxy(function(data)
{
$.each(data, $.proxy(function(key, val)
{
// title
var thumbtitle = '';
if (typeof val.title !== 'undefined') thumbtitle = val.title;
var img = $('<img src="' + val.thumb + '" rel="' + val.image + '" title="' + thumbtitle + '" style="width: 100px; height: 75px; cursor: pointer;" />');
$('#redactor-image-manager-box').append(img);
$(img).click($.proxy(this.imagemanager.insert, this));
}, this));
}, this)
});
},
insert: function(e)
{
this.image.insert('<img src="' + $(e.target).attr('rel') + '" alt="' + $(e.target).attr('title') + '">');
}
};
};
})(jQuery);