-
-
Save amaitland/48adad9c7f2c57f6c17fad39b2747d00 to your computer and use it in GitHub Desktop.
Register event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CefSharp.RegisterEvent = async function (boundObjName, boundObjMethodName, targetObj, evtName) | |
{ | |
await CefSharp.BindObjectAsync(boundObjName); | |
let addEvent = function () | |
{ | |
var isElement = targetObj instanceof HTMLElement; | |
var elem = isElement ? targetObj : document.getElementById(targetObj); | |
elem.addEventListener(evtName, function (e) | |
{ | |
var evtArgs = { id: e.target.id, tagName: e.target.tagName }; | |
window[boundObjName][boundObjMethodName](evtName, evtArgs); | |
}); | |
}; | |
switch (document.readyState) | |
{ | |
case "loading": | |
{ | |
// Document still loading | |
document.addEventListener("DOMContentLoaded", function (event) | |
{ | |
addEvent(); | |
}); | |
break; | |
} | |
case "interactive": | |
case "complete": | |
{ | |
addEvent(); | |
break; | |
} | |
} | |
}; | |
(function () | |
{ | |
var elem = document.getElementById('test-button'); | |
elem.removeAttribute('disabled'); | |
//boundEvent is the object name to be registered | |
//raiseEvent is the method on the bound object to be called (as a string) | |
//elem is the button | |
//click is the event that will be subscribed to. | |
CefSharp.RegisterEvent('boundEvent', 'raiseEvent', elem, 'click'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment