Skip to content

Commit

Permalink
Added AMD support by checking whether "define" is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
rikkertkoppes committed Aug 22, 2012
1 parent 104949a commit 7783e06
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
30 changes: 30 additions & 0 deletions demo_AMD.html
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>Demo of Usage</title>
<script type="text/javascript" src="require.js"></script>
</head>
<body>
<div id="id"></div>
<script type="text/javascript">
require(['src/uritemplate.js'],function(UriTemplate) {
"use strict";
var
templateText = "{?query*}",
variables = {
query: {
first: "1",
second: 2
}
};
document.getElementById('id').innerHTML =
"<p>When you have a template of the form</p><p><code>var templateText = \"" + templateText
+ "\";</code></p><p>and params of the form </p><p><code>var variables = " + JSON.stringify(variables)
+ ";</code></p><p>, you can use </p><p><code>UriTemplate.parse(templateText).expand(variables); </code></p><p>to produce </p><p><code>"
+ UriTemplate.parse(templateText).expand(variables)
+ "</code></p><p> Look at the source code of this page!</p>";
});
</script>

</body>
</html>
31 changes: 31 additions & 0 deletions require.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/uritemplate.js
Expand Up @@ -523,6 +523,11 @@
// export UriTemplate, when module is present, or pass it to window or global
if (typeof module !== "undefined") {
module.exports = UriTemplate;
}
else if (typeof define !== "undefined") {
define([],function() {
return UriTemplate;
});
}
else if (typeof window !== "undefined") {
window.UriTemplate = UriTemplate;
Expand Down

0 comments on commit 7783e06

Please sign in to comment.