Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Swift bridge setup
- function setupWKWebViewJavascriptBridge(callback) {
- if (window.WKWebViewJavascriptBridge) {
- return callback(window.WKWebViewJavascriptBridge);
- }
- if (window.WKWVJBCallbacks) {
- return window.WKWVJBCallbacks.push(callback);
- }
- window.WKWVJBCallbacks = [callback];
- window.webkit.messageHandlers.iOS_Native_InjectJavascript.postMessage(null);
- }
- // Logic
- setupWKWebViewJavascriptBridge(function(bridge) {
- freshBridge = bridge;
- function startSVGLoadingTimer() {
- if (!document.querySelector('svg')) {
- setTimeout(test, 200);
- } else {
- bridge.callHandler('JSSVGLoadedEvent', {},
- function(response) {}
- );
- }
- }
- startSVGLoadingTimer()
- bridge.registerHandler('InitialSetupSVGViewEvent', function(
- data,
- responseCallback
- ) {
- const places = JSON.parse(data);
- places.forEach(element => {
- const place = document.getElementById(element.svgId);
- if (place) {
- const childs = place.childNodes;
- childs.forEach(child => {
- child.style.fill = element.hexColor;
- });
- place.addEventListener('click', handleClick(element.svgId));
- }
- });
- });
- bridge.registerHandler('SelectPlaceSVGViewEvent', function(
- data,
- responseCallback
- ) {
- const places = JSON.parse(data);
- places.forEach(element => {
- const place = document.getElementById(element.svgId);
- if (place) {
- const childs = place.childNodes;
- childs.forEach(child => {
- child.style.fill = element.hexColor;
- });
- }
- });
- });
- });
- const handleClick = id => e => {
- freshBridge.callHandler(
- 'JSPlaceSelectionStateChangedEvent', {
- id: id
- },
- function(response) {}
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement