Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Tu mas injectovanie javascriptu dynamicky reku
- var injectLocale = function(lang, callback, error) {
- var script = document.createElement('script'),
- body = document.getElementsByTagName('body')[0],
- removed = false;
- script.type = 'text/javascript';
- if (script.readyState) { // IE
- script.onreadystatechange = function () {
- if (script.readyState === 'complete' ||
- script.readyState === 'loaded') {
- script.onreadystatechange = null;
- $timeout(
- function () {
- if (removed) return;
- removed = true;
- body.removeChild(script);
- if(typeof callback == 'function') {
- callback();
- }
- }, 30, false);
- }
- };
- } else { // Others
- script.onload = function () {
- if (removed) return;
- removed = true;
- body.removeChild(script);
- if(typeof callback == 'function') {
- callback();
- }
- };
- script.onerror = function () {
- // Insert "failure to download locale script" log here
- if (removed) return;
- removed = true;
- body.removeChild(script);
- if(typeof error == 'function') {
- error();
- }
- };
- }
- script.src = fileLocation({locale:lang});
- script.async = false;
- body.appendChild(script);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement