Permalink
Browse files

AMD support

  • Loading branch information...
1 parent 7c81b67 commit 3d78b9ae46491e057f5296ee0a8d968fefc86dd0 @craveytrain committed Aug 11, 2013
Showing with 2,099 additions and 4 deletions.
  1. +2,053 −0 lib/require.js
  2. +23 −0 require.html
  3. +23 −4 src/azucar.js
View
View
@@ -0,0 +1,23 @@
+<!doctype html>
+<html class="no-js" lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>Tests</title>
+
+</head>
+<body>
+<h1>This is my page</h1>
+<h2>There are many others like it, but this one is mine</h2>
+
+<ul>
+ <li>1</li>
+ <li>2</li>
+ <li>3</li>
+ <li>4</li>
+ <li>5</li>
+</ul>
+
+<script data-main="src/azucar" src="lib/require.js"></script>
+
+</body>
+</html>
View
@@ -1,6 +1,25 @@
-'use strict';
-/*jshint unused: false */
-var $ = (function (doc, _ElemProto, domNode) {
+(function (root, factory) {
+ 'use strict';
+
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as an anonymous module.
+ define('azucar', [], function() {
+ // Also create a global in case some scripts
+ // that are loaded still are looking for
+ // a global even when an AMD loader is in use.
+
+ /* jshint boss:true */
+ return (root.$ = factory());
+ });
+ } else {
+ // Browser globals
+ root.$ = factory();
+ }
+}(this, function factory() {
+ 'use strict';
+ var doc = document;
+ var _ElemProto = Element.prototype;
+ var domNode = doc.createElement('p');
var $ = doc.querySelectorAll.bind(doc);
// Setup single node sugar
@@ -74,4 +93,4 @@ var $ = (function (doc, _ElemProto, domNode) {
return createArray(collection, length);
}
};
-}(document, Element.prototype, document.createElement('p')));
+}));

0 comments on commit 3d78b9a

Please sign in to comment.