User:Cacycle/diff.js: Difference between revisions

Content deleted Content added
1.0.14 (September 11, 2014 arrow only moved block title, no change indicator fix
1.0.15 (September 12, 2014) customizable block mark symbols, fix dynamic highlighting and scrolling, fix bubbling
Line 3:
// ==UserScript==
// @name wDiff
// @version 1.0.1415
// @date September 1112, 2014
// @description improved word-based diff library with block move detection
// @homepage https://en.wikipedia.org/wiki/User:Cacycle/diff
Line 118:
//
 
// enable block move layout with color codedhighlighted blocks and marks at their original positionpositions
if (wDiff.showBlockMoves === undefined) { wDiff.showBlockMoves = true; }
 
// minimal number of real words for a moved block (0 for always showing color codedhighlighted blocks)
if (wDiff.blockMinLength === undefined) { wDiff.blockMinLength = 3; }
 
Line 204:
//
 
if (wDiff.styleContainersymbolMarkLeft === undefined) { wDiff.styleContainersymbolMarkLeft = ''; }
if (wDiff.styleTabsymbolMarkRight === undefined) { wDiff.styleTabsymbolMarkRight = ''; }
if (wDiff.stylesheet === undefined) {
wDiff.stylesheet =
'.wDiffTab:before { content: "→"; color: #bbb; font-size: smaller; }' +
'.wDiffNewline:before { content: " "; }' +
'.wDiffMarkRight:before { content: "' + wDiff.symbolMarkRight + '"; }' +
'.wDiffMarkLeft:before { content: "' + wDiff.symbolMarkLeft + '"; }' +
'.wDiffDelete { font-weight: bold; background-color: #ffe49c; color: #222; border-radius: 0.25em; padding: 0.2em 1px; }' +
'.wDiffInsert { font-weight: bold; background-color: #bbddff; color: #222; border-radius: 0.25em; padding: 0.2em 1px; }' +
Line 216 ⟶ 218:
'.wDiffMarkLeft { font-weight: bold; background-color: #ffe49c; color: #666; border-radius: 0.25em; padding: 0.2em; margin: 0 1px; }' +
'.wDiffMarkRight { font-weight: bold; background-color: #ffe49c; color: #666; border-radius: 0.25em; padding: 0.2em; margin: 0 1px; }' +
'.wDiffFragment { white-space: pre-wrap; background: #fff; border: #bbb solid; border-width: 1px 1px 1px 0.5em; border-radius: 0.5em; font-family: sans-serif; font-size: 88%; line-height: 1.6; box-shadow: 2px 2px 2px #ddd; padding: 1em; margin: 0; }' +
'.wDiffContainer { }' +
'.wDiffNoChange { white-space: pre-wrap; background: #f0f0f0; border: #bbb solid; border-width: 1px 1px 1px 0.5em; border-radius: 0.5em; font-family: sans-serif; font-size: 88%; line-height: 1.6; box-shadow: 2px 2px 2px #ddd; padding: 0.5em; margin: 1em 0; }' +
'.wDiffSeparator { margin-bottom: 1em; }' +
'.wDiffBlock { }' +
'.wDiffBlock0 { background-color: #ffff60; }' +
Line 241 ⟶ 239:
'.wDiffMark8 { color: #90d090; }' +
'.wDiffBlockHighlight { background-color: #777; color: #fff; border: solid #777; border-width: 1px 0; }' +
'.wDiffMarkHighlight { background-color: #777; color: #fff; }'; +
'.wDiffContainer { }' +
'.wDiffFragment { white-space: pre-wrap; background: #fff; border: #bbb solid; border-width: 1px 1px 1px 0.5em; border-radius: 0.5em; font-family: sans-serif; font-size: 88%; line-height: 1.6; box-shadow: 2px 2px 2px #ddd; padding: 1em; margin: 0; }' +
'.wDiffNoChange { white-space: pre-wrap; background: #f0f0f0; border: #bbb solid; border-width: 1px 1px 1px 0.5em; border-radius: 0.5em; font-family: sans-serif; font-size: 88%; line-height: 1.6; box-shadow: 2px 2px 2px #ddd; padding: 0.5em; margin: 1em 0; }' +
'.wDiffSeparator { margin-bottom: 1em; }' +
'.wDiffOmittedChars { }';
}
 
Line 248 ⟶ 251:
//
 
if (wDiff.styleContainer === undefined) { wDiff.styleContainer = ''; }
if (wDiff.styleDelete === undefined) { wDiff.styleDelete = ''; }
if (wDiff.styleInsert === undefined) { wDiff.styleInsert = ''; }
Line 258 ⟶ 260:
if (wDiff.styleMarkRight === undefined) { wDiff.styleMarkRight = ''; }
if (wDiff.styleMarkColor === undefined) { wDiff.styleMarkColor = []; }
if (wDiff.styleNewlinestyleContainer === undefined) { wDiff.styleNewlinestyleContainer = ''; }
if (wDiff.styleTab === undefined) { wDiff.styleTab = ''; }
if (wDiff.styleFragment === undefined) { wDiff.styleFragment = ''; }
if (wDiff.styleNoChange === undefined) { wDiff.styleNoChange = ''; }
if (wDiff.styleSeparator === undefined) { wDiff.styleSeparator = ''; }
if (wDiff.styleOmittedChars === undefined) { wDiff.styleOmittedChars = ''; }
if (wDiff.styleTab === undefined) { wDiff.styleTab = ''; }
if (wDiff.styleNewline === undefined) { wDiff.styleNewline = ''; }
 
//
Line 273 ⟶ 276:
if (wDiff.blockEvent === undefined) { wDiff.blockEvent = ' onmouseover="wDiff.BlockHandler(undefined, this, \'mouseover\');"'; }
 
if (wDiff.htmlContainerStart === undefined) { wDiff.htmlContainerStart = '<div class="wDiffContainer" id="wDiffContainer" style="' + wDiff.styleContainer + '">'; }
if (wDiff.htmlContainerEnd === undefined) { wDiff.htmlContainerEnd = '</div>'; }
 
Line 282 ⟶ 285:
if (wDiff.htmlInsertEnd === undefined) { wDiff.htmlInsertEnd = '</span><!--wDiffInsert-->'; }
 
if (wDiff.htmlBlockLeftStart === undefined) { wDiff.htmlBlockLeftStart = '<span class="wDiffBlockLeft wDiffBlock{class}" style="' + wDiff.styleBlockLeft + '{block}" title="' + wDiff.symbolMarkLeft + '" id="wDiffBlock{number}"' + wDiff.blockEvent + '>'; }
if (wDiff.htmlBlockLeftEnd === undefined) { wDiff.htmlBlockLeftEnd = '</span><!--wDiffBlockLeft-->'; }
 
if (wDiff.htmlBlockRightStart === undefined) { wDiff.htmlBlockRightStart = '<span class="wDiffBlockRight wDiffBlock{class}" style="' + wDiff.styleBlockRight + '{block}" title="' + wDiff.symbolMarkRight + '" id="wDiffBlock{number}"' + wDiff.blockEvent + '>'; }
if (wDiff.htmlBlockRightEnd === undefined) { wDiff.htmlBlockRightEnd = '</span><!--wDiffBlockRight-->'; }
 
Line 338 ⟶ 341:
 
// getElementsByClassName
var container = elementdocument.parentNodegetElementById('wDiffContainer');
var spans = container.getElementsByTagName('span');
for (var i = 0; i < spans.length; i ++) {
Line 373 ⟶ 376:
// scroll element under mouse cursor
var top;
if (window.pageXOffsetpageYOffset !== undefined) {
top = window.pageXOffsetpageYOffset;
}
else {
top = document.documentElement.scrollTop;
}
 
Line 392 ⟶ 395:
line = parseInt(window.getComputedStyle(corrElement).getPropertyValue('line-height'));
}
 
window.scroll(0, corrElementPos + top - cursor + line / 2);
}
Line 955 ⟶ 959:
(text.tokens[frontTest].token == text.tokens[backTest].token)
) {
frontTest = text.tokens[frontTest].prev;
backTest = text.tokens[backTest].prev;
if (wDiff.regExpBubbleStop.test(text.tokens[frontTest].token) === true) {
frontStop = frontTest;
Line 964 ⟶ 966:
frontStop = frontTest;
}
frontTest = text.tokens[frontTest].prev;
backTest = text.tokens[backTest].prev;
}