Browse Source

'set' operation added

Herbert Vojčík 10 years ago
parent
commit
f935a8ec0a
1 changed files with 16 additions and 4 deletions
  1. 16 4
      jquery.xontent.js

+ 16 - 4
jquery.xontent.js

@@ -1,9 +1,21 @@
 (function ($) {
 
-    $.fn.xontent = function () {
-        return this.map(function (index, el) {
-            return xontent(el).toArray();
-        });
+    $.fn.xontent = function (op, arg) {
+        if (!op) {
+            return this.map(function (index, el) {
+                return xontent(el).toArray();
+            });
+        }
+
+        if (op === "set") {
+            if (arg instanceof $) {
+                $(this).data('xontent', arg);
+            } else if (arg instanceof DocumentFragment) {
+                $(this).data('xontent', $(arg));
+            }
+        }
+
+        return $(this);
     };
 
     function xontent(el) {