-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
135 lines (115 loc) · 4.66 KB
/
main.js
File metadata and controls
135 lines (115 loc) · 4.66 KB
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
/* Lorem Help Extension
to help you with the lorem ipsum command
*/
define(function (require, exports, module) {
//'use strict';
const
CommandManager = brackets.getModule('command/CommandManager'),
Menus = brackets.getModule('command/Menus'),
EditorManager = brackets.getModule('editor/EditorManager'),
ExtensionUtils = brackets.getModule('utils/ExtensionUtils'),
DocumentManager = brackets.getModule('document/DocumentManager'),
helpsfile = require('text!loremattrs.json'),
helpsjson = JSON.parse(helpsfile),
COMMAND_ID = 'loremhelp.insert',
loremdia = $('<div>', {class: 'lorem-help-cont full'});
let menu, editMenu, loremdis;
ExtensionUtils.loadStyleSheet(module, 'style.css');
/* Construction of popup dialog and events */
loremdia.append(
$('<ul>', {class: 'full'}).append(
helpsjson.full.map(opt => {
return $('<li>', {'title': opt.title}).append(
$('<a>', {
href: '#',
code: opt.code,
html: opt.state,
})
);
})
),
$('<div>', {class: 'control'}).append(
$('<p>', {text: 'Click a Setting You Wish To Use:'}),
loremdis = $('<input>', {
type: 'text',
class: 'codepreview',
name: 'loremdis',
value: '',
style: 'width: 60%;'
}),
$('<a>', {href: '#', class: 'btn', text: 'Clear'}).on('click', function () {
loremdis.val('');
var lis = $(this).parent().parent().find('ul.full').find('li');
lis.each(function(i, e) {
$(e).find('a').removeClass('selectedf');
});
}),
$('<a>', {href: '#', class: 'btn', text: 'Cancel'}).on('click', function () {
loremdia.hide();
}),
$('<a>', {href: '#', class: 'btn', text: 'Done'}).on('click', function () {
loremdia.hide();
console.log($(this).parent().find('input').eq(0).val());
writeThisChar($(this).parent().find('input').eq(0).val());
})
)
).hide().appendTo('body').find('ul a').on('click', function () {
$(this).toggleClass('selectedf');
if ($(this).hasClass('selectedf')) {
if (this.attributes.code.value != 'lorem') {
if (loremdis.val().endsWith('_')) {
loremdis.val(loremdis.val() + this.attributes.code.value.substring(1, this.attributes.code.value.length));
} else {
loremdis.val(loremdis.val() + this.attributes.code.value);
}
if ($(this).parent().attr('title').match(/\(add a number to the end\)/) != null) {
loremdis.focus();
}
}
else {
if (loremdis.val()[0] == '_' || loremdis.val().length == 0)
loremdis.val('lorem' + loremdis.val());
else
loremdis.val('lorem_' + loremdis.val());
}
} else {
var val = loremdis.val();
val += '_';
val = val.replace(this.attributes.code.value, '^');
console.log(val.substr(0, 5));
if (this.attributes.code.value != 'lorem')
val = val.replace(/\^.*?_/, '_');
else
val = val.replace('^', '');
val = val.substring(0, val.length-1);
if (val === '_') val = '';
loremdis.val(val);
}
});
function showFullListDialog() {
const currentDoc = DocumentManager.getCurrentDocument();
if (currentDoc) {
loremdia.css({
'margin-left': -(622 / 2),
'margin-top': -(520 / 2),
width: 620
}).show();
}
}
/* this function is called within the scope of the click event target */
function writeThisChar(obj) {
const
doc = DocumentManager.getCurrentDocument(),
editor = EditorManager.getCurrentFullEditor(),
pos = editor.getCursorPos();
doc.replaceRange(obj, pos);
editor.focus();
}
CommandManager.register('Lorem Ipsum Helper', COMMAND_ID, showFullListDialog);
editMenu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU);
console.log(editMenu);
if (editMenu) {
editMenu.addMenuDivider();
editMenu.addMenuItem(COMMAND_ID, 'Ctrl-Alt-Shift-L');
}
});