Skip to main content
Jump to: navigation, search

Orion/How Tos/Compare widget Build

Compare build and demo

  • In order to make the Orion compare widget easier to consume, a RequireJS build and a demo have been introduced.
  • The build is targeted at users who already use the RequireJS module loader.
  • The build is are available both minified and non-minified.
  • The demo is a zip file containing minified, non-minified builds and the common css file together with demo html files, by which you can run the demo offline.

Getting the build and demo

  • After version 3.0 M1, the Orion build page will include the compare build but for now you can download the file and unzip it to get both the build and demo.

The build

  • built-compare.min.js and built-compare.js are the minified and non-minified versions of the standalone build.
  • built-compare.css is the built css file and is needed by both builds.

The demo

  • demo_simple.html demos the simplest ability to compare two text contents side by side. You can also change the contents on both side and compare again.
  • demo_lightweight.html adds a load sample and walk all the diffs features. You can easily walk through all the diffs in word level by an animation.
  • demo.html is the fully loaded one by which you can select the content type, on which the widget chooses a syntax highlighter for you. Also the widget becomes toggleable between side by side and unified. Also there are buttons rendered automatically by the widget for the convenience of diff navigations.

Orion compare page

  • The built compare files will also be available directly from the Orion compare web page releases section.

Using the Build

The next sections will show the simplest way to embed a compare widget by different options, from simple to fully loaded.

  • These instructions are going to use the builds available on If you have downloaded the built-compare.min.js and built-compare.css files to your local server, just update the corresponding paths.

Embed the plain text compare widget

  • To consume the build to compare two plain text you only need to provide two text strings and the DOM element id where your widget will live.
  • Your final file should look like this. You can simply copy and paste it into an html file and see the result.
  • You can also use the demo_simple.html in the downloaded to see how the code works.
  • You can also use the demo_lightweight.html in the downloaded to load the sample and see the animation on walking through all the diffs.
<!doctype html>
	<title>Orion Compare Demo</title>
	<style type="text/css">
		.compareContainer {
			position: absolute;
			top: 2px;
			bottom: 0;
			width: 99%;
			overflow-y: auto;
			border:1px solid #bebebe;
    <link rel="stylesheet" type="text/css" href=""/>
	<script src=""></script>
	/*global require window */
	require([""], function(Compare) {
	    var options = {
	        parentDivId: "compareParentDiv",
	        newFile: {
	            Content: "contents on left\n"
	        oldFile: {
	            Content: "contents on right\n"
	    //Constructing the Compare widget instance starts the compare view automatically
		var compare = new Compare(options);
        <div id="compareParentDiv" class="compareContainer"></div>

Embed the compare widget with syntax highlighting

  • To consume the build to compare two text with file types you only need to add the file name with extension in the compare option.
  • On top of the code from the previous section, you only need to change the options part.
  • You can also use the demo.html in the downloaded to load the sample and see how syntax highlighting works.
var options = {
    parentDivId: "compareParentDiv",
    newFile: {
    	Name: "left.js",
        Content: "var left = something;\nvar same = 123;\nvar left1 = foo\n"
    oldFile: {
    	Name: "right.js",
        Content: "var right = something;\nvar same = 123;\nvar right1 = bar\n"

Compare Options

Below is the current list of options(along with their default values) and parameters supported in the 3.0 release. Note that these may change in future releases.

 * @class This object describes options of a file. Two instances of this object construct the core parameters of a compare view. 
 * @name
 * @property {String} Content the text contents of the file unit. Requied.
 * @property {String} Name the file name. Required for syntax highlight.
 * @property {Boolean} [readonly=true] whether or not the file is in readonly mode. Optional.
 * @class This object describes the options for <code>compare</code>.
 * @name
 * @property {String} parentDivID Required. the parent element id for the compare view. Required. The parentDivID is required to prefix the ids of sub components in case of side by side view.
 * @property {} [oldFile] Required. the options of the file that is original. Required. In the two way compare case, this file is dispalyed on the left hand side.
 * @property {} [newFile] Required. the options of the file that is compared against the original. Required. In the two way compare case, this file is dispalyed on the right hand side.
 * @property {Boolean} [showTitle=false] Optional. whether or not to show the two file names on each side of the compare view.
 * @property {Boolean} [showLineStatus=false] Optional. whether or not to show the current line and column number fo the caret on each side of the view. Not avaible for inline/unified compare view.
 * Creates a compare view instance by given view options and othe parameters.
 * @param {} viewOptions Required. The comapre view option.
 * @param {String} commandSpanId Optional. The dom element id to render all the commands that toggles compare view and navigates diffs. If not defined, no command is rendered.
 * @param {String} [viewType="twoWay"] optional. The type of the compare view. Can be either "twoWay" or "inline". Id not defined default is "twoWay".
 * "twoWay" represents a side by side comapre editor while "inline" represents a unified comapre view.
 * @param {Boolean} [toggleable=false] optional. Weather or not the compare view is toggleable. A toggleable comapre view provides a toggle button which toggles between the "twoWay" and "inline" view.

Back to the top