|
13 | 13 | /*global $, hljs, Diff2Html*/ |
14 | 14 |
|
15 | 15 | (function() { |
16 | | - |
17 | 16 | var highlightJS = require('./highlight.js-internals.js').HighlightJS; |
18 | 17 |
|
19 | 18 | var diffJson = null; |
20 | | - var defaultTarget = "body"; |
| 19 | + var defaultTarget = 'body'; |
21 | 20 | var currentSelectionColumnId = -1; |
22 | 21 |
|
23 | 22 | function Diff2HtmlUI(config) { |
|
42 | 41 |
|
43 | 42 | function synchronisedScroll($target, config) { |
44 | 43 | if (config.synchronisedScroll) { |
45 | | - |
46 | | - $target.find(".d2h-file-side-diff").scroll(function() { |
| 44 | + $target.find('.d2h-file-side-diff').scroll(function() { |
47 | 45 | var $this = $(this); |
48 | | - $this.closest(".d2h-file-wrapper").find(".d2h-file-side-diff") |
| 46 | + $this.closest('.d2h-file-wrapper').find('.d2h-file-side-diff') |
49 | 47 | .scrollLeft($this.scrollLeft()); |
50 | 48 | }); |
51 | | - |
52 | 49 | } |
53 | 50 | } |
54 | 51 |
|
|
57 | 54 |
|
58 | 55 | var hashTag = this._getHashTag(); |
59 | 56 |
|
60 | | - var $showBtn = $target.find(".d2h-show"); |
61 | | - var $hideBtn = $target.find(".d2h-hide"); |
62 | | - var $fileList = $target.find(".d2h-file-list"); |
| 57 | + var $showBtn = $target.find('.d2h-show'); |
| 58 | + var $hideBtn = $target.find('.d2h-hide'); |
| 59 | + var $fileList = $target.find('.d2h-file-list'); |
63 | 60 |
|
64 | 61 | if (hashTag === 'files-summary-show') show(); |
65 | 62 | else if (hashTag === 'files-summary-hide') hide(); |
|
88 | 85 | var $target = that._getTarget(targetId); |
89 | 86 |
|
90 | 87 | // collect all the diff files and execute the highlight on their lines |
91 | | - var $files = $target.find(".d2h-file-wrapper"); |
| 88 | + var $files = $target.find('.d2h-file-wrapper'); |
92 | 89 | $files.map(function(_i, file) { |
93 | 90 | var oldLinesState; |
94 | 91 | var newLinesState; |
95 | 92 | var $file = $(file); |
96 | | - var language = $file.data("lang"); |
| 93 | + var language = $file.data('lang'); |
97 | 94 |
|
98 | 95 | // collect all the code lines and execute the highlight on them |
99 | | - var $codeLines = $file.find(".d2h-code-line-ctn"); |
| 96 | + var $codeLines = $file.find('.d2h-code-line-ctn'); |
100 | 97 | $codeLines.map(function(_j, line) { |
101 | 98 | var $line = $(line); |
102 | 99 | var text = line.textContent; |
103 | 100 | var lineParent = line.parentNode; |
104 | 101 |
|
105 | 102 | var lineState; |
106 | | - if (lineParent.className.indexOf("d2h-del") !== -1) { |
| 103 | + if (lineParent.className.indexOf('d2h-del') !== -1) { |
107 | 104 | lineState = oldLinesState; |
108 | 105 | } else { |
109 | 106 | lineState = newLinesState; |
110 | 107 | } |
111 | 108 |
|
112 | 109 | var result = hljs.getLanguage(language) ? hljs.highlight(language, text, true, lineState) : hljs.highlightAuto(text); |
113 | 110 |
|
114 | | - if (lineParent.className.indexOf("d2h-del") !== -1) { |
| 111 | + if (lineParent.className.indexOf('d2h-del') !== -1) { |
115 | 112 | oldLinesState = result.top; |
116 | | - } else if (lineParent.className.indexOf("d2h-ins") !== -1) { |
| 113 | + } else if (lineParent.className.indexOf('d2h-ins') !== -1) { |
117 | 114 | newLinesState = result.top; |
118 | 115 | } else { |
119 | 116 | oldLinesState = result.top; |
|
127 | 124 | result.value = highlightJS.mergeStreams(originalStream, highlightJS.nodeStream(resultNode), text); |
128 | 125 | } |
129 | 126 |
|
130 | | - $line.addClass("hljs"); |
| 127 | + $line.addClass('hljs'); |
131 | 128 | $line.addClass(result.language); |
132 | 129 | $line.html(result.value); |
133 | 130 | }); |
|
143 | 140 | $target = $(targetId); |
144 | 141 | } else { |
145 | 142 | console.error("Wrong target provided! Falling back to default value 'body'."); |
146 | | - console.log("Please provide a jQuery object or a valid DOM query string."); |
| 143 | + console.log('Please provide a jQuery object or a valid DOM query string.'); |
147 | 144 | $target = $(defaultTarget); |
148 | 145 | } |
149 | 146 |
|
|
195 | 192 | }); |
196 | 193 | }; |
197 | 194 |
|
198 | | - |
199 | 195 | Diff2HtmlUI.prototype._getSelectedText = function() { |
200 | 196 | var sel = window.getSelection(); |
201 | 197 | var range = sel.getRangeAt(0); |
|
220 | 216 |
|
221 | 217 | // Expose diff2html in the browser |
222 | 218 | global.Diff2HtmlUI = Diff2HtmlUI; |
223 | | - |
224 | 219 | })(); |
225 | 220 |
|
226 | 221 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
|
233 | 228 | */ |
234 | 229 |
|
235 | 230 | (function() { |
236 | | - |
237 | 231 | function HighlightJS() { |
238 | 232 | } |
239 | 233 |
|
|
258 | 252 | var result = []; |
259 | 253 | (function _nodeStream(node, offset) { |
260 | 254 | for (var child = node.firstChild; child; child = child.nextSibling) { |
261 | | - if (child.nodeType == 3) |
| 255 | + if (child.nodeType === 3) { |
262 | 256 | offset += child.nodeValue.length; |
263 | | - else if (child.nodeType == 1) { |
| 257 | + } else if (child.nodeType === 1) { |
264 | 258 | result.push({ |
265 | 259 | event: 'start', |
266 | 260 | offset: offset, |
|
293 | 287 | if (!original.length || !highlighted.length) { |
294 | 288 | return original.length ? original : highlighted; |
295 | 289 | } |
296 | | - if (original[0].offset != highlighted[0].offset) { |
| 290 | + if (original[0].offset !== highlighted[0].offset) { |
297 | 291 | return (original[0].offset < highlighted[0].offset) ? original : highlighted; |
298 | 292 | } |
299 | 293 |
|
|
310 | 304 | return highlighted; |
311 | 305 | ... which is collapsed to: |
312 | 306 | */ |
313 | | - return highlighted[0].event == 'start' ? original : highlighted; |
| 307 | + return highlighted[0].event === 'start' ? original : highlighted; |
314 | 308 | } |
315 | 309 |
|
316 | 310 | function open(node) { |
|
326 | 320 | } |
327 | 321 |
|
328 | 322 | function render(event) { |
329 | | - (event.event == 'start' ? open : close)(event.node); |
| 323 | + (event.event === 'start' ? open : close)(event.node); |
330 | 324 | } |
331 | 325 |
|
332 | 326 | while (original.length || highlighted.length) { |
333 | 327 | var stream = selectStream(); |
334 | 328 | result += escape(value.substr(processed, stream[0].offset - processed)); |
335 | 329 | processed = stream[0].offset; |
336 | | - if (stream == original) { |
337 | | - |
| 330 | + if (stream === original) { |
338 | 331 | /* |
339 | 332 | On any opening or closing tag of the original markup we first close |
340 | 333 | the entire highlighted node stack, then render the original tag along |
|
345 | 338 | do { |
346 | 339 | render(stream.splice(0, 1)[0]); |
347 | 340 | stream = selectStream(); |
348 | | - } while (stream == original && stream.length && stream[0].offset == processed); |
| 341 | + } while (stream === original && stream.length && stream[0].offset === processed); |
349 | 342 | nodeStack.reverse().forEach(open); |
350 | 343 | } else { |
351 | | - if (stream[0].event == 'start') { |
| 344 | + if (stream[0].event === 'start') { |
352 | 345 | nodeStack.push(stream[0].node); |
353 | 346 | } else { |
354 | 347 | nodeStack.pop(); |
|
362 | 355 | /* **** Highlight.js Private API **** */ |
363 | 356 |
|
364 | 357 | module.exports.HighlightJS = new HighlightJS(); |
365 | | - |
366 | 358 | })(); |
367 | 359 |
|
368 | 360 | },{}]},{},[1]); |
0 commit comments