daisydiff.js.diff.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testcasegenerator Show documentation
Show all versions of testcasegenerator Show documentation
Generates test cases from the crawl session.
The newest version!
var imagePath = 'images/';
var selectedElement=null;
function htmlDiffInit() {
dojo.event.connect(document, "onkeydown", handleShortcut);
dojo.event.connect(window, "onresize", updateOverlays);
dojo.addOnLoad(resetSelectedElement);
}
function updateOverlays(){
updateOverlaysForElems(document.getElementsByClassName("diff-removed-tag"));
updateOverlaysForElems(document.getElementsByClassName("diff-added-tag"));
updateOverlaysForElems(Array.prototype.filter.call(document.getElementsByTagName("img"),
function(elem) {
return elem.getAttribute('changeType') == "diff-removed-image"
|| elem.getAttribute('changeType') == "diff-added-image";
}))
}
function updateOverlaysForElems(elems) {
var bodyBound = document.body.getBoundingClientRect();
var bodyLeft = bodyBound.left;
var bodyTop = bodyBound.top;
for (var i = 0; i < elems.length; i++) {
var changed = elems[i];
if(changed.offsetWidth == 0 || changed.offsetHeight == 0) {
continue;
}
var filter;
var prevOverlay = document.getElementById("daisydiff-overlay-id-" + changed.getAttribute("overlayId"));
var prevDivFound = false;
if(prevOverlay != null) {
filter = prevOverlay;
} else {
filter = document.createElement("div");
filter.className = changed.getAttribute("changeType");
filter.id = "daisydiff-overlay-id-" + changed.getAttribute("overlayId");
}
var rect = changed.getBoundingClientRect();
filter.style.width = rect.width + "px";
filter.style.height = rect.height + "px";
filter.style.left = rect.left - bodyLeft + "px";
filter.style.top = rect.top - bodyTop + "px";
if(prevOverlay == null) document.body.appendChild(filter);
}
}
function tipA(content){
Tip(content, DURATION, 6000, CLICKCLOSE, true, FOLLOWMOUSE, false, ABOVE, true, OFFSETX , 1, STICKY, true, FADEIN, 100, FADEOUT, 100, PADDING, 5);
return false;
}
function tipR(content){
Tip(content, DURATION, 6000, CLICKCLOSE, true, FOLLOWMOUSE, false, ABOVE, true, OFFSETX , 1, STICKY, true, FADEIN, 100, FADEOUT, 100, PADDING, 5);
return false;
}
function tipC(content){
Tip(content, DURATION, 8000, CLICKCLOSE, true, FOLLOWMOUSE, false, ABOVE, true, STICKY, true, OFFSETX, 1, FADEIN, 100, FADEOUT, 100, PADDING, 5);
return false;
}
function constructToolTipC(elem){
//constructing the tooltip, so this must be the new selected element!
selectedElement=elem;
var changes_html = elem.getAttribute("changes");
var previous_id = elem.getAttribute("previous");
var next_id = elem.getAttribute("next");
var change_id = elem.getAttribute("changeId");
return changes_html+
""+
" "+
" "+
" "+
" "+
" "+
" #"+change_id+" "+
" "+
" "+
" "+
" "+
" "+
"
";
}
function constructToolTipA(elem){
//constructing the tooltip, so this must be the new selected element!
selectedElement=elem;
var previous_id = elem.getAttribute("previous");
var next_id = elem.getAttribute("next");
var change_id = elem.getAttribute("changeId");
return ""+
" "+
" "+
" "+
" "+
" "+
" #"+change_id+" "+
" "+
" "+
" "+
" "+
" "+
"
";
}
function constructToolTipR(elem){
//constructing the tooltip, so this must be the new selected element!
selectedElement=elem;
var previous_id = elem.getAttribute("previous");
var next_id = elem.getAttribute("next");
var change_id = elem.getAttribute("changeId");
return ""+
" "+
" "+
" "+
" "+
" "+
" #"+change_id+" "+
" "+
" "+
" "+
" "+
" "+
"
";
}
function tip2(anchor){
var destinationLink = document.getElementById(anchor);
if(destinationLink.className =='diff-html-changed'){
tipC2(destinationLink, constructToolTipC(destinationLink));
}else if(destinationLink.className =='diff-html-added'){
tipA2(destinationLink, constructToolTipA(destinationLink));
}else if(destinationLink.className =='diff-html-removed'){
tipR2(destinationLink, constructToolTipR(destinationLink));
}else{
//the anchor points to a 'first-...' or 'last-...' link; make it selected
selectedElement=destinationLink;
}
}
function tipC2(destinationLink, content){
Tip(content, FIX, FixCalcXY(destinationLink, 2,20), BALLOONSTEMWIDTH, 0, BALLOONSTEMHEIGHT, 0, DURATION, 20000, CLICKCLOSE, true, FOLLOWMOUSE, false, STICKY, true, OFFSETX, 1, FADEIN, 100, FADEOUT, 100, PADDING, 5);
}
function tipR2(destinationLink, content){
Tip(content, FIX, FixCalcXY(destinationLink, 2,20), BALLOONSTEMWIDTH, 0, BALLOONSTEMHEIGHT, 0, DURATION, 20000, CLICKCLOSE, true, FOLLOWMOUSE, false, STICKY, true, OFFSETX, 1, FADEIN, 100, FADEOUT, 100, PADDING, 5);
}
function tipA2(destinationLink, content){
Tip(content, FIX, FixCalcXY(destinationLink, 2,20), BALLOONSTEMWIDTH, 0, BALLOONSTEMHEIGHT, 0, DURATION, 20000, CLICKCLOSE, true, FOLLOWMOUSE, false, STICKY, true, OFFSETX, 1, FADEIN, 100, FADEOUT, 100, PADDING, 5);
}
function FixCalcXY(el, xoffset, yoffset){
//fix for images inside the span
var imagesContained = el.getElementsByTagName("img");
var imageHeight=0;
if(!window.event && imagesContained.length > 0){
imageHeight=imagesContained[0].offsetHeight;
}
var xy = dojo.html.getAbsolutePosition(el, true);
return [xy.x+xoffset, xy.y+yoffset-imageHeight];
}
function changeClass(changeId, newCl){
var allSpans = document.getElementsByTagName('span');
// Walk through the list
for (var i=0;i and n
var target;
if(isPrev){
target=selectedElement.getAttribute("previous");
}else if(isNext){
target=selectedElement.getAttribute("next");
}
//custom hack for span support
var destinationLink = document.getElementById(target);
// If we didn't find a destination, give up and let the browser do
// its thing
if (!destinationLink){
return;
}
scrollToTarget(destinationLink);
}
function scrollToEvent(e) {
// This is an event handler; get the clicked on element,
// in a cross-browser fashion
if (window.event) {
target = window.event.srcElement;
} else if (e) {
target = e.target;
} else {
throw("unsupported browser");
return true;
}
// Make sure that the target is an element, not a text node
// within an element
if (target.nodeType == 3 || target.nodeName.toLowerCase()=="img") {
target = target.parentNode;
}
// Paranoia; check this is an A tag
if (target.nodeName.toLowerCase() != 'a'){
throw("target is not an anchor");
return true;
}
// Find the tag corresponding to this href
// First strip off the hash (first character)
anchor = target.hash.substr(1);
//custom hack for span support
var destinationLink = document.getElementById(anchor);
var continueEvent = scrollToTarget(destinationLink);
// And stop the actual click happening
if (!continueEvent && window.event) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (!continueEvent && e && e.preventDefault && e.stopPropagation) {
e.preventDefault();
e.stopPropagation();
}
return continueEvent;
}
function scrollToTarget(destinationLink){
// If we didn't find a destination, give up and let the browser do
// its thing
if (!destinationLink){
throw("unknown destination");
return true;
}
var xy = FixCalcXY(destinationLink, 0,-10);
//scroll
window.scrollTo( xy[0], xy[1]);
setTimeout("tip2('"+destinationLink.id+"')", 0);
//if, because otherwise it's not threadsafe-ish
if(destinationLink.className != "diff-html-selected"){
if(selectedElement.getAttribute("oldClass") && selectedElement.getAttribute("oldClass").length>0 && selectedElement.getAttribute("oldClass")!=selectedElement.className){
changeClass(selectedElement.id, selectedElement.getAttribute("oldClass"));
}
setTimeout("changeClass('"+destinationLink.id+"', 'diff-html-selected')", 1);
destinationLink.setAttribute("oldClass",destinationLink.className)
setTimeout("changeClass('"+destinationLink.id+"', '"+destinationLink.className+"')", 2000);
}
return false;
}