Last active
July 3, 2020 10:58
-
-
Save sakurai-youhei/e72d5627ae3051dfd4271a41826a2d95 to your computer and use it in GitHub Desktop.
Brython with Cordova
This file contains hidden or 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
document.addEventListener('deviceready', brython, false); |
This file contains hidden or 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
(function() { | |
var original_ajax_load_script = __BRYTHON__.ajax_load_script; | |
__BRYTHON__.ajax_load_script = function(script) { | |
try { | |
original_ajax_load_script(script); | |
} catch { | |
custom_ajax_load_script(script); | |
} | |
}; | |
function custom_ajax_load_script(script) { | |
var url = script.url, | |
name = script.name; | |
var xhr = new XMLHttpRequest(); | |
xhr.addEventListener("loadend", function(evt) { | |
if(this.status === 0){ | |
var src = this.responseText; | |
if(script.is_ww){ | |
__BRYTHON__.webworkers[name] = src; | |
}else{ | |
__BRYTHON__.tasks.splice(0, 0, [$B.run_script, src, name, true]); | |
} | |
__BRYTHON__.loop(); | |
} else { | |
throw Error(url + " not found"); | |
} | |
}); | |
var qs = __BRYTHON__.$options.cache ? '' : (url.search(/\?/) > -1 ? '&' : '?') + Date.now(); | |
xhr.open("GET", url + qs, true); | |
xhr.send(); | |
} | |
})(); |
This file contains hidden or 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
<script src="js/monkeypatch-brython.js"></script> | |
<script src="js/deviceready-brython.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment