resource_loader.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Created by silent on 14-1-26.
  3. */
  4. var publicResourceLoader=null;
  5. (function(){
  6. var scripts=document.querySelectorAll('script[type="text/javascript"][src]'),matches,resourceUrl='';
  7. for(var i=0;i<scripts.length;i++){
  8. if(matches=scripts[i].src.match(/^.*?(?=static\/js\/resource_loader\.js)/)){
  9. resourceUrl=matches[0];
  10. }
  11. }
  12. function PublicResourceLoader(config){
  13. this.css=config.css;
  14. this.scripts=config.scripts;
  15. this.head=document.getElementsByTagName('head')[0];
  16. this.loadCSS();
  17. this.loadScript();
  18. }
  19. PublicResourceLoader.prototype={
  20. construct:PublicResourceLoader,
  21. loadCSS:function(){
  22. var that=this;
  23. this.css.forEach(function(csslink){
  24. document.write(' <link href="'+csslink+'" rel="stylesheet" />')
  25. });
  26. },
  27. loadScript:function(){
  28. var that=this;
  29. this.scripts.forEach(function(scriptlink){
  30. document.write('<script type="text/javascript" src="'+scriptlink+'"></script>')
  31. });
  32. },
  33. getPath:function(){
  34. return resourceUrl;
  35. }
  36. };
  37. publicResourceLoader =new PublicResourceLoader({
  38. css:[resourceUrl+'static/css/index.css?version='+Math.random()],
  39. scripts:[
  40. resourceUrl+'static/js/jquery.min.js',
  41. resourceUrl+'static/js/server.js?version='+Math.random(),
  42. resourceUrl+'static/js/adSceneInGames.js?version='+Math.random(),
  43. resourceUrl+'static/js/game_index.js?version='+Math.random()
  44. ]
  45. });
  46. }());