소스 검색

'set' operation added

Herbert Vojčík 12 년 전
부모
커밋
f935a8ec0a
1개의 변경된 파일16개의 추가작업 그리고 4개의 파일을 삭제
  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) {