This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit.js
147 lines (127 loc) · 4.45 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
//# sourceMappingURL=init.map
// Generated by CoffeeScript 1.10.0
/*
Copyright (c) 2014, dev-rke
*/
(function() {
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
codiad.ToDo = (function() {
/*
basic plugin environment initialization
*/
function ToDo(global, jQuery) {
this.disableToDo = bind(this.disableToDo, this);
this.updateToDo = bind(this.updateToDo, this);
this.initToDoListContainer = bind(this.initToDoListContainer, this);
this.init = bind(this.init, this);
this.codiad = global.codiad;
this.amplify = global.amplify;
this.jQuery = jQuery;
this.scripts = document.getElementsByTagName('script');
this.path = this.scripts[this.scripts.length - 1].src.split('?')[0];
this.curpath = this.path.split('/').slice(0, -1).join('/') + '/';
this.jQuery((function(_this) {
return function() {
return _this.init();
};
})(this));
}
/*
main plugin initialization
*/
ToDo.prototype.init = function() {
return this.initToDoListContainer();
};
/*
init button and menu on bottom menu
and append handler
*/
ToDo.prototype.initToDoListContainer = function() {
var todoButton, todoMenu;
todoButton = '<div class="divider"></div>\n<a id="todoButton">\n <span class="icon-check"></span>TODO\n</a>';
todoMenu = '<ul id="todoMenu" class="options-menu"></ul>';
this.jQuery('#editor-bottom-bar').append(todoButton);
this.$todoButton = this.jQuery('#todoButton');
this.$todoMenu = this.jQuery(todoMenu);
this.codiad.editor.initMenuHandler(this.$todoButton, this.$todoMenu);
this.$todoMenu.on('click', 'li a', (function(_this) {
return function(element) {
var line;
line = _this.jQuery(element.currentTarget).data('line');
if (line) {
_this.codiad.active.gotoLine(line);
return _this.codiad.editor.focus();
}
};
})(this));
this.amplify.subscribe('active.onFocus', (function(_this) {
return function() {
return _this.updateToDo();
};
})(this));
this.updateInterval = null;
this.amplify.subscribe('active.onOpen', (function(_this) {
return function() {
var activeInstance;
_this.updateToDo();
activeInstance = _this.codiad.editor.getActive();
if (!activeInstance) {
return;
}
return activeInstance.getSession().on('change', function(e) {
clearTimeout(_this.updateInterval);
return _this.updateInterval = setTimeout(_this.updateToDo, 1000);
});
};
})(this));
return this.amplify.subscribe('active.onClose', (function(_this) {
return function() {
return _this.disableToDo();
};
})(this));
};
/*
update todo button and menu
*/
ToDo.prototype.updateToDo = function() {
var content, editorInstance, editorToDo, i, index, len, line, loc, matches, session;
editorInstance = this.codiad.editor.getActive();
if (!editorInstance) {
return;
}
content = this.codiad.editor.getContent();
loc = content.split(/\r?\n/);
matches = [];
editorToDo = [];
for (index = i = 0, len = loc.length; i < len; index = ++i) {
line = loc[index];
if (line.indexOf("TODO") > -1 && line.match(/TODO\s*:(.*)/)) {
matches.push('<li><a data-line="' + (index + 1) + '">' + line.match(/TODO\s*:(.*)/)[1] + '</a></li>');
editorToDo.push({
row: index,
column: 1,
text: line.match(/(TODO\s*:.*)/)[1],
type: "info"
});
}
}
if (matches.length > 0) {
this.$todoMenu.empty().append($(matches.join("")));
session = editorInstance.getSession();
session.setAnnotations(editorToDo.concat(session.getAnnotations()));
return this.$todoButton.find('span').removeClass('icon-check').addClass('icon-clipboard');
} else {
return this.disableToDo();
}
};
/*
disable ToDoList
*/
ToDo.prototype.disableToDo = function() {
this.$todoMenu.empty().append("<li><a>Nothing to do</a></li>");
return this.$todoButton.find('span').removeClass('icon-clipboard').addClass('icon-check');
};
return ToDo;
})();
new codiad.ToDo(this, jQuery);
}).call(this);