![JAR search and dependency download from the Maven repository](/logo.png)
a.hyperscala-ui_2.11.0.10.3.source-code.bounding.js Maven / Gradle / Ivy
var bounding = {
entries: {},
monitor: function(selector, frequency, selectorFunction) {
bounding.remove(selector); // Make sure this id isn't already being monitored
var entry = {
frequency: frequency
};
bounding.entries[selector] = bounding;
entry.intervalId = setInterval(function() {
var selection;
if (selectorFunction == null) {
selection = $(selector);
} else {
selection = selectorFunction();
}
bounding.check(selector, selection);
}, frequency);
},
check: function(selector, selection) {
var selectorEntry = bounding.entries[selector];
if (selection.length > 0) {
selection.each(function() { // Iterate over each entry
var element = $(this);
var id = element.attr('id');
var entry = selectorEntry[id];
if (entry == null) {
entry = {};
selectorEntry[id] = entry;
}
var localX = parseInt(element.css('left'));
if (isNaN(localX)) {
localX = 0;
}
var localY = parseInt(element.css('top'));
if (isNaN(localY)) {
localY = 0;
}
var absoluteX = element.offset().left;
var absoluteY = element.offset().top;
var width = element.outerWidth();
var height = element.outerHeight();
// Check if anything has changed
if (entry.localX != localX || entry.localY != localY || entry.absoluteX != absoluteX || entry.absoluteY != absoluteY || entry.width != width || entry.height != height) {
// Send a message to the server
realtime.send({
id: id,
type: 'bounding',
localX: localX,
localY: localY,
absoluteX: absoluteX,
absoluteY: absoluteY,
width: width,
height: height
});
// Update local values
entry.localX = localX;
entry.localY = localY;
entry.absoluteX = absoluteX;
entry.absoluteY = absoluteY;
entry.width = width;
entry.height = height;
}
});
} else {
// console.log('Selector ' + selector + ' has no elements.');
// monitor.remove(id);
}
},
remove: function(id) {
var entry = bounding.entries[id];
if (entry != null) {
var intervalId = entry.intervalId;
if (intervalId != null) {
clearInterval(intervalId);
}
bounding.entries[id] = null;
}
}
};
© 2015 - 2025 Weber Informatics LLC | Privacy Policy