Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

#124 - Improvement in getPosition Method #127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
31 changes: 15 additions & 16 deletions src/js/OTHelpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ streamElements = {} # keep track of DOM elements for each stream
# Helper methods
#
getPosition = (pubDiv) ->
# Get the position of element
if !pubDiv then return {}
computedStyle = if window.getComputedStyle then getComputedStyle(pubDiv, null) else {}
width = pubDiv.offsetWidth
height = pubDiv.offsetHeight
curtop = pubDiv.offsetTop
curleft = pubDiv.offsetLeft
while(pubDiv = pubDiv.offsetParent)
curleft += pubDiv.offsetLeft
curtop += pubDiv.offsetTop
return {
top:curtop
left:curleft
width:width
height:height
}
if !pubDiv
return {}
boundingRects = if pubDiv.getBoundingClientRect then pubDiv.getBoundingClientRect().toJSON() else null
if boundingRects
# for browsers that do not support width and height
if !boundingRects.width
boundingRects.width = boundingRects.right - (boundingRects.left)
if !boundingRects.height
boundingRects.height = boundingRects.bottom - (boundingRects.top)
position =
width: pubDiv.offsetWidth
height: pubDiv.offsetHeight
top: pubDiv.offsetTop
left: pubDiv.offsetLeft
boundingRects or position

replaceWithVideoStream = (element, streamId, properties) ->
typeClass = if streamId == PublisherStreamId then PublisherTypeClass else SubscriberTypeClass
Expand Down
29 changes: 15 additions & 14 deletions www/opentok.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,26 @@ var OTPublisherError, OTReplacePublisher, TBError, TBGenerateDomHelper, TBGetScr
streamElements = {};

getPosition = function(pubDiv) {
var computedStyle, curleft, curtop, height, width;
var boundingRects, position;
if (!pubDiv) {
return {};
}
computedStyle = window.getComputedStyle ? getComputedStyle(pubDiv, null) : {};
width = pubDiv.offsetWidth;
height = pubDiv.offsetHeight;
curtop = pubDiv.offsetTop;
curleft = pubDiv.offsetLeft;
while ((pubDiv = pubDiv.offsetParent)) {
curleft += pubDiv.offsetLeft;
curtop += pubDiv.offsetTop;
boundingRects = pubDiv.getBoundingClientRect ? pubDiv.getBoundingClientRect().toJSON() : null;
if (boundingRects) {
if (!boundingRects.width) {
boundingRects.width = boundingRects.right - boundingRects.left;
}
if (!boundingRects.height) {
boundingRects.height = boundingRects.bottom - boundingRects.top;
}
}
return {
top: curtop,
left: curleft,
width: width,
height: height
position = {
width: pubDiv.offsetWidth,
height: pubDiv.offsetHeight,
top: pubDiv.offsetTop,
left: pubDiv.offsetLeft
};
return boundingRects || position;
};

replaceWithVideoStream = function(element, streamId, properties) {
Expand Down