Browse Source

AMD support

Herbert Vojčík 10 years ago
parent
commit
5875041940
2 changed files with 17 additions and 2 deletions
  1. 6 0
      README.md
  2. 11 2
      jquery.xontent.js

+ 6 - 0
README.md

@@ -62,3 +62,9 @@ You can call `$('#foo').xontent('set', payload)` to set the payload
 which `$('#foo').xontent()` will return.
 which `$('#foo').xontent()` will return.
 The payload may be a _DocumentFragment_ itself,
 The payload may be a _DocumentFragment_ itself,
 or a jQuery object that encapsulates it.
 or a jQuery object that encapsulates it.
+
+AMD (new in 0.1.2)
+----
+
+You can load xontent with AMD loader such as requirejs.
+If loaded via AMD, xontent installs itself to AMD-loaded jQuery.

+ 11 - 2
jquery.xontent.js

@@ -1,4 +1,13 @@
-(function ($) {
+;
+(function (factory) {
+    if (typeof define === "function" && define.amd) {
+        define(['jquery'], factory);
+    } else if (typeof jQuery !== "undefined") {
+        factory(jQuery);
+    } else {
+        throw new Error("xontent panic: jQuery not found");
+    }
+})(function ($) {
 
 
     $.fn.xontent = function (op, arg) {
     $.fn.xontent = function (op, arg) {
         if (!op) {
         if (!op) {
@@ -66,4 +75,4 @@
         return xontent(el);
         return xontent(el);
     }
     }
 
 
-}(jQuery));
+});