Skip to content

Commit

Permalink
Merge pull request #10 from mortenn/gh-pages
Browse files Browse the repository at this point in the history
Helper methods for using URI.js against servers not understanding UTF-8 encoded URIs
  • Loading branch information
rodneyrehm committed Jan 12, 2012
2 parents eaf06d6 + fcf110e commit cdc5d7f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
18 changes: 17 additions & 1 deletion docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ <h1><a href="https://github.com/medialize/URI.js">URI.js</a></h1>

<li><a href="#static-commonPath">URI.commonPath()</a></li>
<li><a href="#static-withinString">URI.withinString()</a></li>
<li><a href="#static-iso8859">URI.iso8859()</a></li>
<li><a href="#static-unicode">URI.unicode()</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -757,6 +759,20 @@ <h3 id="static-withinString">URI.withinString()</h3>
});
</pre>

<h3 id="static-iso8859">URI.iso8859()</h3>
<p>URI.iso8859() tells URI.js to use the older escape/unescape methods, for backwards compatibility with older platforms.</p>
<pre class="prettyprint lang-js">URI.iso8859();

var uri = new URI("http://example.org/foo/æ.html");
// http://example.org/foo/%E6.html</pre>

<h3 id="static-unicode">URI.unicode()</h3>
<p>URI.unicode() restores the default unicode-encoded URLs.</p>
<pre class="prettyprint lang-js">URI.unicode();

var uri = new URI("http://example.org/foo/æ.html");
// http://example.org/foo/%C3%A6.html</pre>

</div>
</body>
</html>
</html>
20 changes: 15 additions & 5 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,18 @@ var URI = function(url, base) {
}

return this;
},
p = URI.prototype;
};
var p = URI.prototype;

URI.iso8859 = function() {
URI.encode = escape;
URI.decode = unescape;
}

URI.unicode = function() {
URI.encode = encodeURIComponent;
URI.decode = decodeURIComponent;
}

// static properties
URI.idn_expression = /[^a-z0-9\.-]/i;
Expand Down Expand Up @@ -122,10 +132,10 @@ URI.characters = {
}
};
URI.encodeQuery = function(string) {
return encodeURIComponent(string + "").replace(/%20/g, '+');
return URI.encode(string + "").replace(/%20/g, '+');
};
URI.decodeQuery = function(string) {
return decodeURIComponent((string + "").replace(/\+/g, '%20'));
return URI.decode((string + "").replace(/\+/g, '%20'));
};
URI.recodePath = function(string) {
var segments = (string + "").split('/');
Expand Down Expand Up @@ -1260,4 +1270,4 @@ p.equals = function(uri) {

window.URI = URI;

})();
})();

0 comments on commit cdc5d7f

Please sign in to comment.