This repository has been archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.js
executable file
·276 lines (256 loc) · 9.56 KB
/
init.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
* Copyright (c) Codiad & Andr3as, distributed
* as-is and without warranty under the MIT License.
* See http://opensource.org/licenses/MIT for more information.
* This information must remain intact.
*/
(function(global, $){
var codiad = global.codiad,
scripts = document.getElementsByTagName('script'),
path = scripts[scripts.length-1].src.split('?')[0],
curpath = path.split('/').slice(0, -1).join('/')+'/';
$(function() {
codiad.Ignore.init();
});
codiad.Ignore = {
path: curpath,
ignoreData: [],
ignorePath: "",
entries: 0,
line: "",
init: function() {
var _this = this;
//Load data
this.load();
$.get(this.path+"template.html", function(html){
_this.line = html;
});
//Subscribe
amplify.subscribe("filemanager.onIndex", function(path){
var buf = [];
var fPath, result, ext, name;
$.each(codiad.filemanager.indexFiles, function(i, item){
fPath = item.name;
name = _this.getName(fPath);
ext = _this.getExtension(fPath);
result = true;
$.each(_this.ignoreData, function(index, rule){
if (rule.range == "file") {
if (fPath == rule.name) {
result = false;
}
} else if (rule.range == "name") {
if (name == rule.name) {
result = false;
}
} else if (rule.range == "type") {
var tExt = new RegExp(rule.name.replace("*", "").replace(".", "\\.") + "$");
if (tExt.test(fPath)) {
result = false;
}
}
if (!result) {
return false;
}
});
if (result) {
buf.push(item);
}
});
codiad.filemanager.indexFiles = buf;
});
amplify.subscribe('settings.dialog.save', function(){
if ($('.ignore_display').length > 0) {
codiad.Ignore.saveDialog();
}
});
},
//////////////////////////////////////////////////////////
//
// Show dialog with a log of every rule
//
//////////////////////////////////////////////////////////
showDialog: function() {
var path = this.path.substring(this.path.indexOf(window.location.pathname)) + "dialog.php?action=log";
codiad.settings.show(path);
},
//////////////////////////////////////////////////////////
//
// Test if ignorePath is a directory
//
//////////////////////////////////////////////////////////
isDir: function() {
$.getJSON(this.path+"controller.php?action=isDir&path="+this.ignorePath, function(json){
var type = "";
if (json.result) {
$('#fileType').remove();
type = "directory";
} else {
type = "file";
}
$('#filePath').text("Ignore just this "+type);
$('#fileGeneral').text("Ignore this "+type+" in every project");
});
},
//////////////////////////////////////////////////////////
//
// Show dialog to choose ignore range
//
// Parameter
//
// path - {String} - File path
//
//////////////////////////////////////////////////////////
ignore: function(path) {
codiad.modal.load(300, this.path+"dialog.php?action=ignore");
this.ignorePath = path;
},
//////////////////////////////////////////////////////////
//
// Add new ignore rule of ignore dialog
//
//////////////////////////////////////////////////////////
setIgnore: function() {
var obj = {};
obj.range = $('.ignore_range').val();
if (obj.range == "file") {
obj.name = this.ignorePath;
} else if (obj.range == "name") {
obj.name = this.getName(this.ignorePath);
} else {
obj.name = "*."+this.getExtension(this.ignorePath);
}
this.ignoreData.push(obj);
this.save();
codiad.filemanager.rescan(this.getDir(this.ignorePath));
codiad.modal.unload();
},
//////////////////////////////////////////////////////////
//
// Load current rules
//
//////////////////////////////////////////////////////////
load: function() {
var _this = this;
$.getJSON(this.path+"controller.php?action=load", function(json){
_this.ignoreData = json;
});
},
//////////////////////////////////////////////////////////
//
// Save current rules
//
//////////////////////////////////////////////////////////
save: function() {
var _this = this;
$.post(this.path+"controller.php?action=save", {data: JSON.stringify(_this.ignoreData)}, function(data){
var json = JSON.parse(data);
if (json.status == "error") {
codiad.message.error(json.message);
}
});
},
//////////////////////////////////////////////////////////
//
// Add current rules to log dialog
//
//////////////////////////////////////////////////////////
loadDialog: function() {
var _this = this;
var line;
$.each(this.ignoreData, function(i, item) {
line = _this.addRule();
$('.ignore_rule_name[data-line="'+line+'"]').val(item.name);
$('.ignore_range[data-line="'+line+'"]').val(item.range);
});
},
//////////////////////////////////////////////////////////
//
// Add new rule to log dialog
//
//////////////////////////////////////////////////////////
addRule: function() {
var number = this.entries++;
var line = this.line.replace(new RegExp("__line__", "g"), number);
$('#ignore_list').append(line);
this.setDelete();
return number;
},
//////////////////////////////////////////////////////////
//
// Save rule of log dialog
//
//////////////////////////////////////////////////////////
saveDialog: function() {
var _this = this;
var buf = [];
var line;
$('.ignore_line').each(function(i, item){
var obj = {"name": "", "range": ""};
line = $(item).attr("data-line");
obj.name = $('.ignore_rule_name[data-line="'+line+'"]').val();
obj.range = $('.ignore_range[data-line="'+line+'"]').val();
buf.push(obj);
});
this.ignoreData = buf;
this.save();
codiad.filemanager.rescan(codiad.project.getCurrent());
},
//////////////////////////////////////////////////////////
//
// Activate delete button of log dialog
//
//////////////////////////////////////////////////////////
setDelete: function(){
$('.ignore_remove').click(function(){
var line = $(this).attr("data-line");
$('.ignore_line[data-line="'+line+'"]').remove();
return false;
});
},
//////////////////////////////////////////////////////////
//
// Display help dialog
//
//////////////////////////////////////////////////////////
help: function() {
codiad.modal.load(400, this.path+"dialog.php?action=help");
},
//////////////////////////////////////////////////////////
//
// Get directory of file
//
// Parameter
//
// path - {String} - File path
//
//////////////////////////////////////////////////////////
getDir: function(path) {
return path.substring(0, path.lastIndexOf("/"));
},
//////////////////////////////////////////////////////////
//
// Get file name
//
// Parameter
//
// path - {String} - File path
//
//////////////////////////////////////////////////////////
getName: function(path) {
return path.substring(path.lastIndexOf("/")+1);
},
//////////////////////////////////////////////////////////
//
// Get extension of file
//
// Parameter
//
// path - {String} - File path
//
//////////////////////////////////////////////////////////
getExtension: function(path) {
return path.substring(path.lastIndexOf(".")+1);
}
};
})(this, jQuery);