Tak jak w temacie.
var retry = 0;
function checkIfStarted()
{
var demo = document.getElementById( "demo" );
if( demo.contentWindow["$status"]["started"] ) // We can assume that no adblocker has been avoiding script execution.
{
// Relay mouse-up and mouse-move to iFrame
// This listeners are only invoked outside the iframe
// so we do not need to check if they have been invoked within
// the iframe to avoid double invokation.
// Tested with: Chrome
var position = { x: 0, y: 0 };
var onMouseUp = function ( e )
{
demo.contentWindow.dispatchEvent( new MouseEvent( e.type, e ) );
};
var onMouseMove = function ( e )
{
var r = demo.getBoundingClientRect();
position.x = e.pageX - ( r.left + document.body.scrollLeft );
position.y = e.pageY - ( r.top + document.body.scrollTop ) + 30;// - 50; // WELL, well,...
demo.contentWindow['injectMouseMove']( position ); // exposed over defrac
};
window.addEventListener( "mouseup", onMouseUp );
window.addEventListener( "mousemove", onMouseMove );
cular.pageEvents.on("dispose", function() {
window.removeEventListener( "mouseup", onMouseUp );
window.removeEventListener( "mousemove", onMouseMove );
});
console.log( "Initialized from outside." );
}
else
{
if( ++retry == 5 ) // Tried five times to make sure we did not run into timing issues.
{
alert( "Please disable your Adblocker for this site" );
}
else
{
self.setTimeout( checkIfStarted, 500 );
}
}
}
function waitForStatus()
{
var demo = document.getElementById( "demo" );
if( !demo || !demo.contentWindow || !demo.contentWindow["$status"] )
self.setTimeout( waitForStatus, 500 );
else
self.setTimeout( checkIfStarted, 500 );
}
self.setTimeout( waitForStatus, 500 );