Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions ElementContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,40 @@

function ElementContainer(ele) {
this.element = ele;
this.oldBorder = ele.style.border;
this.oldBgColor = ele.style.background;
this.offsets = this.getOffset();
//this.oldBorder = ele.style.border;
//this.oldBgColor = ele.style.background;
//this.offsets = this.getOffset();

this.overlay = document.createElement('div');
this.overlay.setAttribute('class','xpathElementOverlay');
this.overlay.style.left = this.offsets.left+'px';
/*this.overlay.style.left = this.offsets.left+'px';
this.overlay.style.top = this.offsets.top+'px';
this.overlay.style.width = this.element.offsetWidth+'px';
this.overlay.style.height = this.element.offsetHeight+'px';
this.overlay.style.height = this.element.offsetHeight+'px';*/
this.overlay.style.display = 'none';
document.body.appendChild(this.overlay);
}

ElementContainer.prototype.highlight = function() {
this.element.style.border = 'solid 1px black';
//this.element.style.border = 'solid 1px black';
//this.element.style.background = 'yellow';
this.overlay.style.display = 'none';
};

ElementContainer.prototype.select = function() {
this.element.style.border = 'solid 1px red';
this.offsets = this.getOffset();
this.overlay.style.left = this.offsets.left+'px';
this.overlay.style.top = this.offsets.top+'px';
this.overlay.style.width = this.element.offsetWidth+'px';
this.overlay.style.height = this.element.offsetHeight+'px';

//this.element.style.border = 'solid 1px red';
//this.element.style.background = 'red';
this.overlay.style.display = '';
};

ElementContainer.prototype.clear = function() {
this.element.style.border = this.oldBorder;
//this.element.style.border = this.oldBorder;
//this.element.style.background = this.oldBgColor;
document.body.removeChild(this.overlay);
};
Expand All @@ -43,8 +49,8 @@ ElementContainer.prototype.getOffset = function() {
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
_x += el.offsetLeft; //- el.scrollLeft;
_y += el.offsetTop; //- el.scrollTop;
el = el.offsetParent;
}
return { top: _y, left: _x };
Expand Down