Skip to content

Commit cdc5d7f

Browse files
committed
Merge pull request #10 from mortenn/gh-pages
Helper methods for using URI.js against servers not understanding UTF-8 encoded URIs
2 parents eaf06d6 + fcf110e commit cdc5d7f

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

docs.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ <h1><a href="https://github.com/medialize/URI.js">URI.js</a></h1>
116116

117117
<li><a href="#static-commonPath">URI.commonPath()</a></li>
118118
<li><a href="#static-withinString">URI.withinString()</a></li>
119+
<li><a href="#static-iso8859">URI.iso8859()</a></li>
120+
<li><a href="#static-unicode">URI.unicode()</a></li>
119121
</ul>
120122
</li>
121123
</ul>
@@ -757,6 +759,20 @@ <h3 id="static-withinString">URI.withinString()</h3>
757759
});
758760
</pre>
759761

762+
<h3 id="static-iso8859">URI.iso8859()</h3>
763+
<p>URI.iso8859() tells URI.js to use the older escape/unescape methods, for backwards compatibility with older platforms.</p>
764+
<pre class="prettyprint lang-js">URI.iso8859();
765+
766+
var uri = new URI("http://example.org/foo/æ.html");
767+
// http://example.org/foo/%E6.html</pre>
768+
769+
<h3 id="static-unicode">URI.unicode()</h3>
770+
<p>URI.unicode() restores the default unicode-encoded URLs.</p>
771+
<pre class="prettyprint lang-js">URI.unicode();
772+
773+
var uri = new URI("http://example.org/foo/æ.html");
774+
// http://example.org/foo/%C3%A6.html</pre>
775+
760776
</div>
761777
</body>
762-
</html>
778+
</html>

src/URI.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,18 @@ var URI = function(url, base) {
6565
}
6666

6767
return this;
68-
},
69-
p = URI.prototype;
68+
};
69+
var p = URI.prototype;
70+
71+
URI.iso8859 = function() {
72+
URI.encode = escape;
73+
URI.decode = unescape;
74+
}
75+
76+
URI.unicode = function() {
77+
URI.encode = encodeURIComponent;
78+
URI.decode = decodeURIComponent;
79+
}
7080

7181
// static properties
7282
URI.idn_expression = /[^a-z0-9\.-]/i;
@@ -122,10 +132,10 @@ URI.characters = {
122132
}
123133
};
124134
URI.encodeQuery = function(string) {
125-
return encodeURIComponent(string + "").replace(/%20/g, '+');
135+
return URI.encode(string + "").replace(/%20/g, '+');
126136
};
127137
URI.decodeQuery = function(string) {
128-
return decodeURIComponent((string + "").replace(/\+/g, '%20'));
138+
return URI.decode((string + "").replace(/\+/g, '%20'));
129139
};
130140
URI.recodePath = function(string) {
131141
var segments = (string + "").split('/');
@@ -1260,4 +1270,4 @@ p.equals = function(uri) {
12601270

12611271
window.URI = URI;
12621272

1263-
})();
1273+
})();

0 commit comments

Comments
 (0)