diff --git a/index.html b/index.html index ca0c794..83da05c 100644 --- a/index.html +++ b/index.html @@ -14,32 +14,46 @@ */ var Url = (function(){ + var _base = ''; + return { initBase: function(){ - var base = window.location.href; + _base = window.location.href; var host = window.location.host; var regex = new RegExp(".*" + host + '/', "g"); if(host){ - base = base.replace(regex,''); + _base = _base.replace(regex,''); }else{ - base = base.replace('index.html',''); + _base = _base.replace('index.html',''); + } + return this; + }, + getBase: function(){ + + if(!_base){ + this.initBase(); } - return base + + return _base; }, removeUrlParameters: function(full_url){ + full_url = full_url || _base; var url_base = full_url.split('#').shift(); return url_base; }, addBaseUrl: function(filename){ - var base = window.location.href; + base = window.location.href; if(base.match(/file:/) || filename.match(/http:/)){ base = ''; }else{ base = this.removeUrlParameters(base) + '/'; } return base + filename; + }, + toString: function(){ + return this.getBase(); } } @@ -75,12 +89,21 @@ function loadJavaScriptAsync(file_path){ } - function loadRequireJS(){ + function loadRequireJS(onLoad){ var head = document.getElementsByTagName('head')[0]; var script_element = document.createElement('script'); script_element.type = 'text/javascript'; script_element.src = makeJSURL('js/require.js'); - script_element.setAttribute('data-main', makeJSURL('js/requirejs-config.js')); + // script_element.setAttribute('data-main', makeJSURL('js/requirejs-config.js')); + if(onLoad instanceof Function){ + script_element.onreadystatechange = function(){ + if (this.readyState == 'complete'){ + onload(); + } + } + script_element.addEventListener('load', onLoad); + } + head.appendChild(script_element); } loadCSSFiles(); @@ -197,7 +220,7 @@