Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      // Tu mas injectovanie javascriptu dynamicky reku
  2.  
  3.  
  4.       var injectLocale = function(lang, callback, error) {
  5.             var script = document.createElement('script'),
  6.                 body = document.getElementsByTagName('body')[0],
  7.                 removed = false;
  8.  
  9.             script.type = 'text/javascript';
  10.  
  11.             if (script.readyState) { // IE
  12.                 script.onreadystatechange = function () {
  13.                     if (script.readyState === 'complete' ||
  14.                         script.readyState === 'loaded') {
  15.                         script.onreadystatechange = null;
  16.                         $timeout(
  17.                             function () {
  18.                                 if (removed) return;
  19.                                 removed = true;
  20.                                 body.removeChild(script);
  21.                                 if(typeof callback == 'function') {
  22.                                     callback();
  23.                                 }
  24.                             }, 30, false);
  25.                     }
  26.                 };
  27.             } else { // Others
  28.                 script.onload = function () {
  29.                     if (removed) return;
  30.                     removed = true;
  31.                     body.removeChild(script);
  32.                     if(typeof callback == 'function') {
  33.                         callback();
  34.                     }
  35.                 };
  36.                 script.onerror = function () {
  37.  
  38.                     // Insert "failure to download locale script" log here
  39.  
  40.                     if (removed) return;
  41.                     removed = true;
  42.                     body.removeChild(script);
  43.  
  44.                     if(typeof error == 'function') {
  45.                         error();
  46.                     }
  47.                 };
  48.             }
  49.  
  50.             script.src = fileLocation({locale:lang});
  51.             script.async = false;
  52.             body.appendChild(script);
  53.         };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement