Skip to content

Commit 59997ef

Browse files
committed
Reverted commit 9bf8974 to fix the toolbar on the wiki.
Included fix for enabling and disabling buttons per language on wiki. Also fixes non-working italic button (fixes jerone#83).
1 parent 7f1d75c commit 59997ef

1 file changed

Lines changed: 73 additions & 60 deletions

File tree

Github_Comment_Enhancer/Github_Comment_Enhancer.user.js

Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
// Source: https://github.com/gollum/gollum/blob/9c714e768748db4560bc017cacef4afa0c751a63/lib/gollum/public/gollum/javascript/editor/langs/markdown.js
3939
var MarkDown = (function MarkDown() {
4040
return {
41-
"bold": {
41+
"function-bold": {
4242
search: /^(\s*)([\s\S]*?)(\s*)$/g,
4343
replace: "$1**$2**$3",
4444
shortcut: "ctrl+b"
@@ -48,55 +48,55 @@
4848
replace: "$1_$2_$3",
4949
shortcut: "ctrl+i"
5050
},
51-
"underline": {
51+
"function-underline": {
5252
search: /^(\s*)([\s\S]*?)(\s*)$/g,
5353
replace: "$1<ins>$2</ins>$3",
5454
shortcut: "ctrl+u"
5555
},
56-
"strikethrough": {
56+
"function-strikethrough": {
5757
search: /^(\s*)([\s\S]*?)(\s*)$/g,
5858
replace: "$1~~$2~~$3",
5959
shortcut: "ctrl+s"
6060
},
6161

62-
"h1": {
62+
"function-h1": {
6363
search: /(.+)([\n]?)/g,
6464
replace: "# $1$2",
6565
forceNewline: true,
6666
shortcut: "ctrl+1"
6767
},
68-
"h2": {
68+
"function-h2": {
6969
search: /(.+)([\n]?)/g,
7070
replace: "## $1$2",
7171
forceNewline: true,
7272
shortcut: "ctrl+2"
7373
},
74-
"h3": {
74+
"function-h3": {
7575
search: /(.+)([\n]?)/g,
7676
replace: "### $1$2",
7777
forceNewline: true,
7878
shortcut: "ctrl+3"
7979
},
80-
"h4": {
80+
"function-h4": {
8181
search: /(.+)([\n]?)/g,
8282
replace: "#### $1$2",
8383
forceNewline: true,
8484
shortcut: "ctrl+4"
8585
},
86-
"h5": {
86+
"function-h5": {
8787
search: /(.+)([\n]?)/g,
8888
replace: "##### $1$2",
8989
forceNewline: true,
9090
shortcut: "ctrl+5"
9191
},
92-
"h6": {
92+
"function-h6": {
9393
search: /(.+)([\n]?)/g,
9494
replace: "###### $1$2",
9595
forceNewline: true,
9696
shortcut: "ctrl+6"
9797
},
9898

99-
"link": {
99+
"function-link": {
100100
exec: function(button, selText, commentForm, next) {
101101
var selTxt = selText.trim(),
102102
isUrl = selTxt && /(?:https?:\/\/)|(?:www\.)/.test(selTxt),
@@ -108,7 +108,7 @@
108108
},
109109
shortcut: "ctrl+l"
110110
},
111-
"image": {
111+
"function-image": {
112112
exec: function(button, selText, commentForm, next) {
113113
var selTxt = selText.trim(),
114114
isUrl = selTxt && /(?:https?:\/\/)|(?:www\.)/.test(selTxt),
@@ -121,13 +121,13 @@
121121
shortcut: "ctrl+g"
122122
},
123123

124-
"ul": {
124+
"function-ul": {
125125
search: /(.+)([\n]?)/g,
126126
replace: String.format("{0} $1$2", listCharacter),
127127
forceNewline: true,
128128
shortcut: "alt+ctrl+u"
129129
},
130-
"ol": {
130+
"function-ol": {
131131
exec: function(button, selText, commentForm, next) {
132132
var repText = "";
133133
if (!selText) {
@@ -145,39 +145,39 @@
145145
},
146146
shortcut: "alt+ctrl+o"
147147
},
148-
"checklist": {
148+
"function-checklist": {
149149
search: /(.+)([\n]?)/g,
150150
replace: String.format("{0} [ ] $1$2", listCharacter),
151151
forceNewline: true,
152152
shortcut: "alt+ctrl+t"
153153
},
154154

155-
"code": {
155+
"function-code": {
156156
exec: function(button, selText, commentForm, next) {
157157
var rt = selText.indexOf("\n") > -1 ? "$1\n```\n$2\n```$3" : "$1`$2`$3";
158158
next(selText.replace(/^(\s*)([\s\S]*?)(\s*)$/g, rt));
159159
},
160160
shortcut: "ctrl+k"
161161
},
162-
"code-syntax": {
162+
"function-code-syntax": {
163163
exec: function(button, selText, commentForm, next) {
164164
var rt = "$1\n```" + button.dataset.value + "\n$2\n```$3";
165165
next(selText.replace(/^(\s*)([\s\S]*?)(\s*)$/g, rt));
166166
}
167167
},
168168

169-
"blockquote": {
169+
"function-blockquote": {
170170
search: /(.+)([\n]?)/g,
171171
replace: "> $1$2",
172172
forceNewline: true,
173173
shortcut: "ctrl+q"
174174
},
175-
"rule": {
175+
"function-rule": {
176176
append: String.format("\n{0}\n", lineCharacter),
177177
forceNewline: true,
178178
shortcut: "ctrl+r"
179179
},
180-
"table": {
180+
"function-table": {
181181
append: "\n" +
182182
"| Head | Head | Head |\n" +
183183
"| :--- | :----: | ----: |\n" +
@@ -187,31 +187,31 @@
187187
shortcut: "alt+shift+t"
188188
},
189189

190-
"clear": {
190+
"function-clear": {
191191
exec: function(button, selText, commentForm, next) {
192192
commentForm.value = "";
193193
next("");
194194
},
195195
shortcut: "alt+ctrl+x"
196196
},
197197

198-
"snippets-tab": {
198+
"function-snippets-tab": {
199199
exec: function(button, selText, commentForm, next) {
200200
next("\t");
201201
}
202202
},
203-
"snippets-useragent": {
203+
"function-snippets-useragent": {
204204
exec: function(button, selText, commentForm, next) {
205205
next("`" + navigator.userAgent + "`");
206206
}
207207
},
208-
"snippets-contributing": {
208+
"function-snippets-contributing": {
209209
exec: function(button, selText, commentForm, next) {
210210
next("Please, always consider reviewing the [guidelines for contributing](../blob/master/CONTRIBUTING.md) to this repository.");
211211
}
212212
},
213213

214-
"emoji": {
214+
"function-emoji": {
215215
exec: function(button, selText, commentForm, next) {
216216
next(button.dataset.value);
217217
}
@@ -221,49 +221,52 @@
221221

222222
var editorHTML = (function editorHTML() {
223223
return '<div id="gollum-editor-function-buttons" style="float: left;">' +
224+
225+
/* Bold, italic, underline & Strikethrough; */
224226
' <div class="button-group btn-group">' +
225-
' <a href="#" data-function="bold" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Bold (ctrl+b)">' +
227+
' <a href="#" id="function-bold" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Bold (ctrl+b)">' +
226228
' <b style="font-weight: bolder;">B</b>' +
227229
' </a>' +
228-
' <a href="#" data-function="italic" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Italic (ctrl+i)">' +
230+
' <a href="#" id="function-italic" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Italic (ctrl+i)">' +
229231
' <em>i</em>' +
230232
' </a>' +
231-
' <a href="#" data-function="underline" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Underline (ctrl+u)">' +
233+
' <a href="#" id="function-underline" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Underline (ctrl+u)">' +
232234
' <ins>U</ins>' +
233235
' </a>' +
234-
' <a href="#" data-function="strikethrough" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Strikethrough (ctrl+s)">' +
236+
' <a href="#" id="function-strikethrough" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Strikethrough (ctrl+s)">' +
235237
' <s>S</s>' +
236238
' </a>' +
237239
' </div>' +
238240

241+
/* Headers (1 - 6); */
239242
' <div class="button-group btn-group">' +
240243
' <div class="select-menu js-menu-container js-select-menu tooltipped tooltipped-ne" aria-label="Headers">' +
241-
' <span class="btn btn-sm minibutton select-menu-button icon-only js-menu-target" aria-label="Headers" style="padding-left:7px; padding-right:7px; width:auto; border-bottom-right-radius:3px; border-top-right-radius:3px;">' +
242-
' <span class="js-select-button">h#</span>' +
243-
' </span>' +
244+
' <a id="function-h1" class="btn btn-sm minibutton select-menu-button icon-only js-menu-target function-button function-dummy" aria-label="Headers" style="padding-left:7px; padding-right:7px; width:auto; border-bottom-right-radius:3px; border-top-right-radius:3px;">' +
245+
' <span class="js-select-button">h#</span>' +
246+
' </a>' +
244247
' <div class="select-menu-modal-holder js-menu-content js-navigation-container" style="top:26px; z-index:22;">' +
245248
' <div class="select-menu-modal" style="width:auto; overflow:visible;">' +
246249
' <div class="select-menu-header">' +
247250
' <span class="select-menu-title">Choose header</span>' +
248251
' <span class="octicon octicon-remove-close js-menu-close"></span>' +
249252
' </div>' +
250253
' <div class="button-group btn-group" style="min-width:175px;">' +
251-
' <a href="#" data-function="h1" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 1 (ctrl+1)">' +
254+
' <a href="#" id="function-h1" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 1 (ctrl+1)">' +
252255
' <b class="select-menu-item-text js-select-button-text">h1</b>' +
253256
' </a>' +
254-
' <a href="#" data-function="h2" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 2 (ctrl+2)">' +
257+
' <a href="#" id="function-h2" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 2 (ctrl+2)">' +
255258
' <b class="select-menu-item-text js-select-button-text">h2</b>' +
256259
' </a>' +
257-
' <a href="#" data-function="h3" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 3 (ctrl+3)">' +
260+
' <a href="#" id="function-h3" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 3 (ctrl+3)">' +
258261
' <b class="select-menu-item-text js-select-button-text">h3</b>' +
259262
' </a>' +
260-
' <a href="#" data-function="h4" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 4 (ctrl+4)">' +
263+
' <a href="#" id="function-h4" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 4 (ctrl+4)">' +
261264
' <b class="select-menu-item-text js-select-button-text">h4</b>' +
262265
' </a>' +
263-
' <a href="#" data-function="h5" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 5 (ctrl+5)">' +
266+
' <a href="#" id="function-h5" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 5 (ctrl+5)">' +
264267
' <b class="select-menu-item-text js-select-button-text">h5</b>' +
265268
' </a>' +
266-
' <a href="#" data-function="h6" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 6 (ctrl+6)">' +
269+
' <a href="#" id="function-h6" class="btn btn-sm minibutton function-button js-navigation-item js-menu-close tooltipped tooltipped-s" aria-label="Header 6 (ctrl+6)">' +
267270
' <b class="select-menu-item-text js-select-button-text">h6</b>' +
268271
' </a>' +
269272
' </div>' +
@@ -272,29 +275,33 @@
272275
' </div>' +
273276
' </div>' +
274277

278+
/* Link & image; */
275279
' <div class="button-group btn-group">' +
276-
' <a href="#" data-function="link" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Link (ctrl+l)">' +
280+
' <a href="#" id="function-link" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Link (ctrl+l)">' +
277281
' <span class="octicon octicon-link"></span>' +
278282
' </a>' +
279-
' <a href="#" data-function="image" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Image (ctrl+g)">' +
283+
' <a href="#" id="function-image" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Image (ctrl+g)">' +
280284
' <span class="octicon octicon-file-media"></span>' +
281285
' </a>' +
282286
' </div>' +
287+
288+
/* Lists (unordered, ordered & task); */
283289
' <div class="button-group btn-group">' +
284-
' <a href="#" data-function="ul" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Unordered List (alt+ctrl+u)">' +
290+
' <a href="#" id="function-ul" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Unordered List (alt+ctrl+u)">' +
285291
' <span class="octicon octicon-list-unordered"></span>' +
286292
' </a>' +
287-
' <a href="#" data-function="ol" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Ordered List (alt+ctrl+o)">' +
293+
' <a href="#" id="function-ol" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Ordered List (alt+ctrl+o)">' +
288294
' <span class="octicon octicon-list-ordered"></span>' +
289295
' </a>' +
290-
' <a href="#" data-function="checklist" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Task List (alt+ctrl+t)">' +
296+
' <a href="#" id="function-checklist" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Task List (alt+ctrl+t)">' +
291297
' <span class="octicon octicon-checklist"></span>' +
292298
' </a>' +
293299
' </div>' +
294300

301+
/* Code (syntax); */
295302
' <div class="button-group btn-group">' +
296303
' <div class="select-menu js-menu-container js-select-menu tooltipped tooltipped-ne" aria-label="Code (ctrl+k)">' +
297-
' <a href="#" data-function="code" class="btn btn-sm minibutton function-button">' +
304+
' <a href="#" id="function-code" class="btn btn-sm minibutton function-button">' +
298305
' <span class="octicon octicon-code"></span>' +
299306
' </a>' +
300307
' <div class="select-menu-modal-holder js-menu-content js-navigation-container" style="top:26px; z-index:22;">' +
@@ -313,27 +320,29 @@
313320
' </div>' +
314321
' </div>' +
315322
' </div>' +
316-
' <a href="#" class="btn btn-sm minibutton select-menu-button js-menu-target" style="width:20px; margin-left:-1px;"></a>' +
323+
' <a href="#" id="function-code" class="btn btn-sm minibutton select-menu-button js-menu-target function-button function-dummy" style="width:20px; margin-left:-1px;"></a>' +
317324
' </div>' +
318325
' </div>' +
319326

327+
/* Blockquote, horizontal rule & table; */
320328
' <div class="button-group btn-group">' +
321-
' <a href="#" data-function="blockquote" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Blockquote (ctrl+q)">' +
329+
' <a href="#" id="function-blockquote" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Blockquote (ctrl+q)">' +
322330
' <span class="octicon octicon-quote"></span>' +
323331
' </a>' +
324-
' <a href="#" data-function="rule" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Horizontal Rule (ctrl+r)">' +
332+
' <a href="#" id="function-rule" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Horizontal Rule (ctrl+r)">' +
325333
' <span class="octicon octicon-horizontal-rule"></span>' +
326334
' </a>' +
327-
' <a href="#" data-function="table" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Table (alt+shift+t)">' +
335+
' <a href="#" id="function-table" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Table (alt+shift+t)">' +
328336
' <span class="octicon octicon-three-bars"></span>' +
329337
' </a>' +
330338
' </div>' +
331339

340+
/* Snippets; */
332341
' <div class="button-group btn-group">' +
333342
' <div class="select-menu js-menu-container js-select-menu tooltipped tooltipped-ne" aria-label="Snippets">' +
334-
' <span class="btn btn-sm minibutton select-menu-button js-menu-target" aria-label="Snippets" style="padding-left:7px; padding-right:7px; width:auto; border-bottom-right-radius:3px; border-top-right-radius:3px;">' +
343+
' <a href="#" class="btn btn-sm minibutton select-menu-button js-menu-target" aria-label="Snippets" style="padding-left:7px; padding-right:7px; width:auto; border-bottom-right-radius:3px; border-top-right-radius:3px;">' +
335344
' <span class="octicon octicon-pin"></span>' +
336-
' </span>' +
345+
' </a>' +
337346
' <div class="select-menu-modal-holder js-menu-content js-navigation-container" style="top:26px; z-index:22;">' +
338347
' <div class="select-menu-modal" style="overflow:visible;">' +
339348
' <div class="select-menu-header">' +
@@ -347,13 +356,13 @@
347356
' </div>' +
348357
' <div class="select-menu-list" style="overflow:visible;">' +
349358
' <div data-filterable-type="substring" data-filterable-for="context-snippets-filter-field">' +
350-
' <a href="#" data-function="snippets-tab" class="function-button select-menu-item js-navigation-item tooltipped tooltipped-w" aria-label="Add tab character" style="table-layout:initial;">' +
359+
' <a href="#" id="function-snippets-tab" class="function-button select-menu-item js-navigation-item tooltipped tooltipped-w" aria-label="Add tab character" style="table-layout:initial;">' +
351360
' <span class="select-menu-item-text js-select-button-text">Add tab character</span>' +
352361
' </a>' +
353-
' <a href="#" data-function="snippets-useragent" class="function-button select-menu-item js-navigation-item tooltipped tooltipped-w" aria-label="Add UserAgent" style="table-layout:initial;">' +
362+
' <a href="#" id="function-snippets-useragent" class="function-button select-menu-item js-navigation-item tooltipped tooltipped-w" aria-label="Add UserAgent" style="table-layout:initial;">' +
354363
' <span class="select-menu-item-text js-select-button-text">Add UserAgent</span>' +
355364
' </a>' +
356-
' <a href="#" data-function="snippets-contributing" class="function-button select-menu-item js-navigation-item tooltipped tooltipped-w" aria-label="Add contributing message" style="table-layout:initial;">' +
365+
' <a href="#" id="function-snippets-contributing" class="function-button select-menu-item js-navigation-item tooltipped tooltipped-w" aria-label="Add contributing message" style="table-layout:initial;">' +
357366
' <span class="select-menu-item-text">' +
358367
' <span class="js-select-button-text">Contributing</span>' +
359368
' <span class="description">Add contributing message</span>' +
@@ -367,11 +376,12 @@
367376
' </div>' +
368377
' </div>' +
369378

379+
/* Emoji; */
370380
' <div class="button-group btn-group">' +
371381
' <div class="select-menu js-menu-container js-select-menu tooltipped tooltipped-ne" aria-label="Emoji">' +
372-
' <span class="btn btn-sm minibutton select-menu-button js-menu-target" aria-label="Emoji" style="padding-left:7px; padding-right:7px; width:auto; border-bottom-right-radius:3px; border-top-right-radius:3px;">' +
382+
' <a href="#" class="btn btn-sm minibutton select-menu-button js-menu-target" aria-label="Emoji" style="padding-left:7px; padding-right:7px; width:auto; border-bottom-right-radius:3px; border-top-right-radius:3px;">' +
373383
' <span class="octicon octicon-octoface"></span>' +
374-
' </span>' +
384+
' </a>' +
375385
' <div class="select-menu-modal-holder js-menu-content js-navigation-container" style="top:26px; z-index:22;">' +
376386
' <div class="select-menu-modal" style="overflow:visible;">' +
377387
' <div class="select-menu-header">' +
@@ -393,8 +403,9 @@
393403

394404
'</div>' +
395405

406+
/* Clear; */
396407
'<div style="float:right;">' +
397-
' <a href="#" data-function="clear" class="btn btn-sm minibutton function-button tooltipped tooltipped-nw" aria-label="Clear (alt+ctrl+x)">' +
408+
' <a href="#" id="function-clear" class="btn btn-sm minibutton function-button tooltipped tooltipped-nw" aria-label="Clear (alt+ctrl+x)">' +
398409
' <span class="octicon octicon-trashcan"></span>' +
399410
' </a>' +
400411
'</div>';
@@ -506,9 +517,11 @@
506517
}
507518

508519
var buttonEvent = function(e) {
509-
e.preventDefault();
510-
executeAction(MarkDown[this.dataset.function], this.commentForm, this);
511-
return false;
520+
if (!this.classList.contains("function-dummy")) {
521+
e.preventDefault();
522+
executeAction(MarkDown[this.id], this.commentForm, this);
523+
return false;
524+
}
512525
};
513526

514527
var codeSyntaxTop = ["JavaScript", "Java", "Ruby", "PHP", "Python", "CSS", "C++", "C#", "C", "HTML"]; // https://github.com/blog/2047-language-trends-on-github
@@ -613,7 +626,7 @@
613626
syntaxSuggestion.setAttribute("href", "#");
614627
syntaxSuggestion.classList.add("function-button", "select-menu-item", "js-navigation-item");
615628
syntaxSuggestion.dataset.value = syntax;
616-
syntaxSuggestion.dataset.function = "code-syntax";
629+
syntaxSuggestion.id = "function-code-syntax";
617630
syntaxSuggestions.appendChild(syntaxSuggestion);
618631

619632
var syntaxSuggestionText = document.createElement("span");
@@ -666,7 +679,7 @@
666679
var buttons = suggester.querySelectorAll(".function-button");
667680
Array.prototype.forEach.call(buttons, function(button) {
668681
button.commentForm = commentForm;
669-
button.dataset.function = "emoji";
682+
button.id = "function-emoji";
670683
button.addEventListener("click", buttonEvent, false);
671684
unsafeWindow.$(button).on("navigation:keydown", function(e) {
672685
if (e.hotkey === "enter") {

0 commit comments

Comments
 (0)