url.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. //>>built
  7. define("dojo/_base/url",["./kernel"],function(_1){
  8. var _2=new RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$"),_3=new RegExp("^((([^\\[:]+):)?([^@]+)@)?(\\[([^\\]]+)\\]|([^\\[:]*))(:([0-9]+))?$"),_4=function(){
  9. var n=null,_5=arguments,_6=[_5[0]];
  10. for(var i=1;i<_5.length;i++){
  11. if(!_5[i]){
  12. continue;
  13. }
  14. var _7=new _4(_5[i]+""),_8=new _4(_6[0]+"");
  15. if(_7.path==""&&!_7.scheme&&!_7.authority&&!_7.query){
  16. if(_7.fragment!=n){
  17. _8.fragment=_7.fragment;
  18. }
  19. _7=_8;
  20. }else{
  21. if(!_7.scheme){
  22. _7.scheme=_8.scheme;
  23. if(!_7.authority){
  24. _7.authority=_8.authority;
  25. if(_7.path.charAt(0)!="/"){
  26. var _9=_8.path.substring(0,_8.path.lastIndexOf("/")+1)+_7.path;
  27. var _a=_9.split("/");
  28. for(var j=0;j<_a.length;j++){
  29. if(_a[j]=="."){
  30. if(j==_a.length-1){
  31. _a[j]="";
  32. }else{
  33. _a.splice(j,1);
  34. j--;
  35. }
  36. }else{
  37. if(j>0&&!(j==1&&_a[0]=="")&&_a[j]==".."&&_a[j-1]!=".."){
  38. if(j==(_a.length-1)){
  39. _a.splice(j,1);
  40. _a[j-1]="";
  41. }else{
  42. _a.splice(j-1,2);
  43. j-=2;
  44. }
  45. }
  46. }
  47. }
  48. _7.path=_a.join("/");
  49. }
  50. }
  51. }
  52. }
  53. _6=[];
  54. if(_7.scheme){
  55. _6.push(_7.scheme,":");
  56. }
  57. if(_7.authority){
  58. _6.push("//",_7.authority);
  59. }
  60. _6.push(_7.path);
  61. if(_7.query){
  62. _6.push("?",_7.query);
  63. }
  64. if(_7.fragment){
  65. _6.push("#",_7.fragment);
  66. }
  67. }
  68. this.uri=_6.join("");
  69. var r=this.uri.match(_2);
  70. this.scheme=r[2]||(r[1]?"":n);
  71. this.authority=r[4]||(r[3]?"":n);
  72. this.path=r[5];
  73. this.query=r[7]||(r[6]?"":n);
  74. this.fragment=r[9]||(r[8]?"":n);
  75. if(this.authority!=n){
  76. r=this.authority.match(_3);
  77. this.user=r[3]||n;
  78. this.password=r[4]||n;
  79. this.host=r[6]||r[7];
  80. this.port=r[9]||n;
  81. }
  82. };
  83. _4.prototype.toString=function(){
  84. return this.uri;
  85. };
  86. return _1._Url=_4;
  87. });