1.0.2 • Published 6 years ago

qb_mergely v1.0.2

Weekly downloads
1
License
(MIT)
Repository
-
Last release
6 years ago

Mergely

http://mergely.com

Mergely is a javascript component to diff/merge files interactively in a browser, providing rich API that enables you to easily integrate Mergely into your existing web application. It is suitable for comparing text files online, e.g. .txt, .html, .xml, .c, .cpp, .java, etc. Mergely has a javascript implementation of the Longest Common Subsequence diff algorithm (LCS) and a customizable markup engine.

Installation

Installation via webpack

The recommended way to install mergely is to use npm and webpack to install mergely and its dependencies. It is highly recommended that you start by cloning mergely-webpack. It has everything that you need to get started.

Angular 6.1.1

You can also use mergely within angular. You can start by cloning mergely-angular.

Installation via .tgz

Unpack mergely.tgz into a folder, e.g. ./lib, and then add the following to the <head> of your target html source file.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/codemirror.min.js"></script>
<link rel="stylesheet" media="all" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/codemirror.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/addon/search/searchcursor.min.js"></script>
<script src="lib/mergely/lib/mergely.js" type="text/javascript"></script>
<link rel="stylesheet" media="all" href="lib/mergely/lib/mergely.css" />

Create a div for the editor in <body>. This example uses a style that provides 8px padding (mergely-full-screen-8):

<div class="mergely-full-screen-8">
  <div class="mergely-resizer">
    <div id="mergely"></div>
  </div>
</div>

Then initialize mergely, setting options as required.

$(document).ready(function () {
    $('#mergely').mergely();
});

Synchronous content initialization

The following example can be used to set the lhs and rhs editors synchronously (i.e. their contents are already known):

$(document).ready(function () {
    // set editor content
    $('#mergely').mergely({
        lhs: function(setValue) {
            setValue('the quick red fox\njumped over the hairy dog');
        },
        rhs: function(setValue) {
            setValue('the quick brown fox\njumped over the lazy dog');
        }
    });
});

Aynchronous initialization

If the editor contents are retrieved asynchronously (recommended), then retrieve the editor contents and set them:

$(document).ready(function () {
    // initialize mergely
    $('#mergely').mergely();
    
    // get async lhsResponse, then set lhs value
    $('#mergely').mergely('lhs', lhsResponse);
    
    // get async rhsResponse, then set rhs value
    $('#mergely').mergely('rhs', rhsResponse);
});

Options

OptionTypeDefault valueDescription
autoresizebooleantrueEnables/disables the auto-resizing of the editor.
autoupdatebooleantrueEnables/disables the auto-updating of the editor when changes are made.
bgcolorstring#eeeeeeThe background color that mergely fills the margin canvas with.
change_timeoutnumber500The timeout, after a text change, before Mergely calcualtes a diff. Only used when readonly enabled.
cmsettingsobject{mode: 'text/plain', readOnly: false}CodeMirror settings (see CodeMirror) that are combined with lhs_cmsettings and rhs_cmsettings.
editor_widthstring400pxStarting width.
editor_heightstring400pxStarting height.
fadeinstringfastA jQuery fadein value to enable the editor to fade in. Set to empty string to disable.
fgcolorstring|number|object{a:'#4ba3fa', c:'#a3a3a3', d:'#ff7f7f', ca:'#4b73ff', cc:'#434343', cd:'#ff4f4f'}The foreground color that mergely marks changes with on the canvas. The value a is additions, c changes, d deletions, and the prefix c indicates current/active change (e.g. cd current delection).
ignorewsbooleanfalseIgnores white-space.
ignorecasebooleanfalseIgnores case when differientiating.
lcsbooleantrueEnables/disables LCS computation for paragraphs (word-by-word changes). Disabling can give a performance gain for large documents.
licensestringlgplThe choice of license to use with Mergely. Valid values are: lgpl, gpl, mpl or lgpl-separate-notice, gpl-separate-notice, mpl-separate-notice (the license requirements are met in a spearate notice file).
line_numbersbooleantrueEnables/disables line numbers. Enabling line numbers will toggle the visibility of the line number margins.
lhs_cmsettingsobject{}The CodeMirror settings (see CodeMirror) for the left-hand side editor.
resize_timeoutnumber500The timeout, after a resize, before Mergely auto-resizes. Only used when autoresize enabled.
rhs_cmsettingsobject{}The CodeMirror settings (see CodeMirror) for the right-hand side editor.
rhs_marginstringrightLocation for the rhs markup margin is either right or left.
sidebarbooleantrueEnables/disables sidebar markers. Disabling can give a performance gain for large documents.
vpcolorstringrgba(0, 0, 200, 0.5)The margin/viewport indicator color.
viewportbooleanfalseEnables/disables the viewport. Enabling the viewport can give a performance gain for large documents.
wrap_linesbooleanfalseEnables/disables line wrapping. Enabling wrapping will wrap text to fit the editors.

Options - Callbacks

OptionParametersDescription
lhsfunction setValue(string)A callback that allows the value of the left-hand editor to be set on initialization synchronously. A handle to a setValue function is passed as an argument to be used to initialize the editor.
loadedA callback to indicate that Mergely has finished initializing and is loaded.
resizedA callback to indicate that the container window has been resized.
rhsfunction setValue(string)A callback that allows the value of the right-hand editor to be set on initialization synchronously. A handle to a setValue function is passed as an argument to be used to initialize the editor.

Methods

clear

Clears the editor contents for the specified side.

Parameters

NameTypeDescription
sidestringThe editor side, either lhs or rhs.

Example

$('#mergely').mergely('clear', 'lhs');

cm

Gets the CodeMirror editor for the specified side.

Parameters

NameTypeDescription
sidestringThe editor side, either lhs or rhs.

Example

$('#mergely').mergely('cm', 'lhs');

diff

Calculates and returns the current .diff file.

Parameters

None.

Example

$('#mergely').mergely('diff');

get

Gets the text editor contents for the specified side.

Parameters

NameTypeDescription
sidestringThe editor side, either lhs or rhs.

Example

$('#mergely').mergely('get', 'lhs');

lhs

Sets the value of the left-hand editor.

Parameters

NameTypeDescription
valuestringThe editor text.

Example

$('#mergely').mergely('lhs', 'This is text');

merge

Merges whole file from the specified side to the opposite side.

Parameters

NameTypeDescription
sidestringThe editor side, either lhs or rhs.

Example

$('#mergely').mergely('merge', 'lhs');

mergeCurrentChange

Merges the current change from the specified side to the opposite side.

Parameters

NameTypeDescription
sidestringThe editor side, either lhs or rhs.

Example

$('#mergely').mergely('mergeCurrentChange', 'lhs');

options

Sets the editor options. Will automatically update with the new settings unless autoupdate is disabled, in which case, you will need to explicitly call update.

Parameters

NameTypeDescription
optionsobjectThe options to set.

Example

$('#mergely').mergely('options', { line_numbers: true });

options

Gets the editor options.

Parameters

None.

Example

$('#mergely').mergely('options');

resize

Resize the editor. Must be called explicitly if autoresize is disabled.

Parameters

None.

Example

$('#mergely').mergely('resize');

rhs

Sets the value of the right-hand editor.

Parameters

NameTypeDescription
valuestringThe editor text.

Example

$('#mergely').mergely('rhs', 'This is text');

scrollTo

Scrolls the side to line number specified by num.

Parameters

NameTypeDescription
sidestringThe editor side, either lhs or rhs.
numnumberThe line number.

Example

$('#mergely').mergely('scrollTo', 'lhs', 100);

scrollToDiff

Scrolls to the next change specified by direction.

Parameters

NameTypeDescription
directionstringThe direction to scroll, either prev or next.

Example

$('#mergely').mergely('scrollToDiff', 'next');

search

Search the editor for text, scrolling to the next available match. Repeating the call will find the next available token.

Parameters

NameTypeDescription
sidestringThe editor side, either lhs or rhs.
textstringThe text to search.

Example

$('#mergely').mergely('search', 'lhs', 'needle');

swap

Swap the content of the left and right editors.

Parameters

None.

Example

$('#mergely').mergely('swap');

unmarkup

Clears the editor markup.

Parameters

None.

Example

$('#mergely').mergely('unmarkup');

update

Manual update; recalculates diff and applies new settings.

Parameters

None.

Example

$('#mergely').mergely('update');
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago