-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsampleRight.js
140 lines (126 loc) · 5.19 KB
/
sampleRight.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*******************************************************************************
* @license
* Copyright (c) 2011, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
* License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html).
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*globals define XMLHttpRequest window */
define(['orion/compare/builder/compare'],
function(Compare) {
var document = window.document;
/** Buttons */
var bCompare = document.getElementById("doCompare"); //$NON-NLS-0$
var bLoadSample = document.getElementById("loadSample"); //$NON-NLS-0$
var bCompareType = document.getElementById("compareTypeSelect"); //$NON-NLS-0$
var bContentTypeTD = document.getElementById("contentTypes"); //$NON-NLS-0$
var bContentType = document.getElementById("contentTypeSelect"); //$NON-NLS-0$
var compareType = "byTwoContents"; //$NON-NLS-0$
var contentType = "js"; //$NON-NLS-0$
var contentOnLeft = "Sample Orion compare contents on left side\n\nYou can replace the contents here and and click on [Refresh Compare] to see the new result\n"; //$NON-NLS-0$
var contentOnRight = "Sample Orion compare contents on right side\n\nYou can replace the contents here and and click on [Refresh Compare] to see the new result\n"; //$NON-NLS-0$
var contentOnLeftURL = "Put file URL here\n"; //$NON-NLS-0$
var contentOnRightURL = "Put file URL here\n"; //$NON-NLS-0$
var options = {
parentDivId: "compareParentDiv", //$NON-NLS-0$
commandSpanId: "compareCmdDiv", //$NON-NLS-0$
newFile: {
Name: "left." + contentType, //$NON-NLS-0$
readonly: false,
Content: contentOnLeft
},
oldFile: {
Name: "right." + contentType, //$NON-NLS-0$
readonly: false,
Content: contentOnRight
}
};
var compare = new Compare(options);
function getFile(file) {
try {
var objXml = new XMLHttpRequest();
objXml.open("GET",file,false); //$NON-NLS-0$
objXml.send(null);
return objXml.responseText;
} catch (e) {
return null;
}
}
function onLoadSample() {
var sampleLeft = getFile("./standalone/sampleLeft.js");
var sampleRight = getFile("./standalone/sampleRight.js");
if(sampleLeft && sampleRight) {
bCompareType.selectedIndex = 0;
compareType = bCompareType.options[bCompareType.selectedIndex].value;
bContentType.selectedIndex = 0;
contentType = bContentType.options[bContentType.selectedIndex].value;
bContentTypeTD.style.display = "block"; //$NON-NLS-0$
var widget = compare.getCompareView().getWidget();
widget.options.oldFile.Content = sampleRight;
widget.options.newFile.Content = sampleLeft;
widget.options.oldFile.URL = null;
widget.options.newFile.URL = null;
widget.options.oldFile.Name = "sampRight.js";
widget.options.newFile.Name = "sampleLeft.js";
widget.options.mapper = null;
compare.refresh();
}
}
function doCompare() {
var widget = compare.getCompareView().getWidget();
if(widget.type === "twoWay"){ //$NON-NLS-0$
var editors = widget._editors;
var oldContents = editors[0].getTextView().getText();
var newContents = editors[1].getTextView().getText();
if(compareType === "byTwoContents"){ //$NON-NLS-0$
widget.options.oldFile.Content = oldContents;
widget.options.newFile.Content = newContents;
widget.options.oldFile.URL = null;
widget.options.newFile.URL = null;
} else {
widget.options.oldFile.URL = oldContents;
widget.options.newFile.URL = newContents;
bCompareType.selectedIndex = 0;
compareType = bCompareType.options[bCompareType.selectedIndex].value;
bContentTypeTD.style.display = "block"; //$NON-NLS-0$
}
widget.options.mapper = null;
compare.refresh();
//widget.refresh();
}
}
function onCompareType(evt) {
compareType = bCompareType.options[bCompareType.selectedIndex].value;
var widget = compare.getCompareView().getWidget();
if(compareType === "byTwoContents"){ //$NON-NLS-0$
widget.options.oldFile.Content = contentOnRight;
widget.options.newFile.Content = contentOnLeft;
widget.options.oldFile.URL = null;
widget.options.newFile.URL = null;
bContentTypeTD.style.display = "block"; //$NON-NLS-0$
} else {
widget.options.oldFile.Content = contentOnRightURL;
widget.options.newFile.Content = contentOnLeftURL;
widget.options.oldFile.URL = null;
widget.options.newFile.URL = null;
bContentTypeTD.style.display = "none"; //$NON-NLS-0$
}
widget.options.mapper = null;
widget.refresh();
}
function onContentType(evt) {
contentType = bContentType.options[bContentType.selectedIndex].value;
var widget = compare.getCompareView().getWidget();
widget.options.oldFile.Name = "right." + contentType;
widget.options.newFile.Name = "left." + contentType;
}
/* Adding events */
bCompare.onclick = doCompare;
bLoadSample.onclick = onLoadSample;
bCompareType.onchange = onCompareType;
bContentType.onchange = onContentType;
});