20.11.2018, 21:23
(This post was last modified: 20.11.2018, 21:24 by Erwin van der Zwart.)
Hi,
Here is a full working sample to auto close widgets based on the back to startpage JS script:
BR,
Erwin
Here is a full working sample to auto close widgets based on the back to startpage JS script:
Code:
$(function(){
var SE_Timeout = 15000; // adjust this timer value if needed (15 seconds in miliseconds)
var eventlist = 'click mousedown mouseout touchend';
var OpenWidget = 0;
setInterval(function() {
var WidgetNumber = 0;
$('.layer-widget').each(function( index, element ) {
if ( $(this).is(':visible') == true) {
fields = $(this)[0].id.split(/-/);
WidgetNumber = Number(fields[1]);
}
});
if (WidgetNumber > 0 && OpenWidget != WidgetNumber){
OpenWidget = WidgetNumber;
}
}, 1000);
// Timer function no usage detected
function No_Usage_Detected(callback, timeout, _this) {
var timer;
return function(e) {
var _that = this;
if (timer)
clearTimeout(timer);
timer = setTimeout(function() {
callback.call(_this || _that, e);
}, timeout);
}
}
// Close widget function when timer elapsed
var SE_CloseWidget = No_Usage_Detected(function(e) {
$("#widget-" + OpenWidget).addClass("hide");
}, SE_Timeout);
// Add event listener to document to detect user input
$(document).on(eventlist, function() {
SE_CloseWidget();
});
// Add event listener to all iframes to detect user input inside iframes
$('iframe').load(function() {
var iframe = $('iframe').contents().find('html');
iframe.on(eventlist, function(event) {
SE_CloseWidget();
});
});
});
Erwin