-
Notifications
You must be signed in to change notification settings - Fork 14
/
ng-finder.src.js
104 lines (101 loc) · 4.46 KB
/
ng-finder.src.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(function(angular, factory) {
if (typeof define === 'function' && define.amd) {
define('ngFinder', ['jquery', 'angular', 'elfinder'], function($, angular) {
return factory(angular);
});
} else {
return factory(angular);
}
}(angular || null, function(angular) {
/**
* <div class="el-finder" toolbar="mkdir,mkfile,upload|open,download|info|copy,cut"></div>
*/
angular.module('ngFinder', [])
.directive('elFinder', function() {
return {
restrict: 'C',
scope: {
'url' : '=url',
'onSelect' : '&select'
},
controller: ['$scope', function($scope) {
// for TinyMCE integration
$scope.selectFile = function(url) {
var aFieldName = $scope.$parent.fieldName,
aWin = $scope.$parent.window;
aWin.document.forms[0].elements[aFieldName].value = url;
$('#elfinder').hide();
}
}],
link: function(scope, element, attrs) {
var menus = {
toolbar: attrs.toolbar || 'mkdir,mkfile,upload|open,download|info|copy,cut,paste|rename,rm|view|help',
navbar: attrs.contextmenuNavbar || 'open,|,copy,cut,paste,|,rm,|,info',
cwd: attrs.contextmenuCwd || 'reload,back,|,upload,mkdir,mkfile,paste,|,info',
files: attrs.contextmenuFiles || 'open,download,|,copy,cut,paste,|,rm,edit,rename,|,info'
}
var options = {
allowShortcuts: false,
// lang: 'ru', // language (OPTIONAL)
rememberLastDir : true,
uiOptions: {
toolbar : menus.toolbar.split('|').map(function(item) { return item.split(',');})
},
contextmenu : {
navbar : menus.navbar.split(','),
cwd : menus.cwd.split(','),
files : menus.files.split(',')
},
url : scope.url || '/elfinder',
commandsOptions : {
getfile: {
onlyURL: false
}
}
};
if (attrs.select) {
options.contextmenu.files.unshift('getfile');
options.onlyMimes = ["image"];
options.getFileCallback = function(file) {
$('#elfinder').hide();
scope.onSelect({ '$file': file });
}
}
$(element).elfinder(options);
$('.elfinder-toolbar', element).addClass('btn-toolbar');
$('.elfinder-buttonset', element).addClass('btn-group');
$('.elfinder-button', element).addClass('btn btn-default');
// glyphicons
var replaceClasses = {
'back': 'arrow-left',
'forward': 'arrow-right',
'mkdir': 'plus-sign',
'mkfile': 'file',
'upload': 'upload',
'open': 'folder-open',
'download': 'download-alt',
'getfile': 'download',
'info': 'info-sign',
'quicklook': 'eye-open',
'rm': 'trash',
'rename': 'pencil',
'edit': 'pencil',
'resize': 'fullscreen',
'view': 'th',
'sort': 'sort',
'help': 'question-sign'
};
// font awesome
$('.elfinder-button-icon-copy', element).removeClass('elfinder-button-icon').addClass('icon-cut');
$('.elfinder-button-icon-cut', element).removeClass('elfinder-button-icon').addClass('icon-copy');
$('.elfinder-button-icon-paste', element).removeClass('elfinder-button-icon').addClass('icon-paste');
angular.forEach(replaceClasses, function(newClass, oldClass) {
$('.elfinder-button-icon-' + oldClass, element)
.removeClass('elfinder-button-icon')
.addClass('icon-' + newClass);
});
}
};
});
return angular.module('ngFinder');
}));