Commit 0a4ffde6d468f11d8121c3f7c1d78c32dbecf1e5
1 parent
13e18eaf
Exists in
master
and in
8 other branches
Refactoring the base url capture function
Showing
2 changed files
with
4 additions
and
19 deletions
Show diff stats
index.html
| ... | ... | @@ -15,29 +15,15 @@ |
| 15 | 15 | var Url = (function(){ |
| 16 | 16 | |
| 17 | 17 | return { |
| 18 | - | |
| 19 | 18 | initBase: function(){ |
| 20 | - var base = window.location.href; | |
| 21 | - var host = window.location.host; | |
| 22 | - var regex = new RegExp(".*" + host + '/', "g"); | |
| 23 | - | |
| 24 | - if(host){ | |
| 25 | - base = base.replace(regex,''); | |
| 26 | - }else{ | |
| 27 | - base = base.replace('index.html',''); | |
| 28 | - } | |
| 29 | - return base | |
| 30 | - }, | |
| 31 | - removeUrlParameters: function(full_url){ | |
| 32 | - var url_base = full_url.split('#').shift(); | |
| 33 | - return url_base; | |
| 19 | + return "//" + window.location.host + window.location.pathname.replace('/index.html',''); | |
| 34 | 20 | }, |
| 35 | - addBaseUrl: function(filename){ | |
| 21 | + addBaseUrl: function(filename){ | |
| 36 | 22 | var base = window.location.href; |
| 37 | 23 | if(base.match(/file:/) || filename.match(/http:/)){ |
| 38 | 24 | base = ''; |
| 39 | 25 | }else{ |
| 40 | - base = this.removeUrlParameters(base) + '/'; | |
| 26 | + base = this.initBase() + '/'; | |
| 41 | 27 | } |
| 42 | 28 | return base + filename; |
| 43 | 29 | } | ... | ... |