Explorar o código

this by class binding for root item by |dom fake selector

Ivan Asmer %!s(int64=7) %!d(string=hai) anos
pai
achega
1ca9ef3f3e
Modificáronse 1 ficheiros con 12 adicións e 4 borrados
  1. 12 4
      static/nb.js

+ 12 - 4
static/nb.js

@@ -16,7 +16,13 @@ DEALINGS IN THE SOFTWARE.
 function nbInit(a,b){
     var root=document, $s=a;
 
+    var dom = null;
+
     function searchElement(root, selector){
+        if (selector.indexOf('|dom') === selector.length - 4){
+            selector = selector.slice(0,selector.length - 4)
+            dom      = true;
+        }
         if (root === document){
             var items = [root.getElementById(selector)]; 
         }
@@ -56,10 +62,10 @@ function nbInit(a,b){
             var items = searchElement(root, selector);
             for (var i=0,item=items[i];i<items.length;i++,item=items[i]){
                 if (direction == "write" &&  Array.isArray($s[selector]) && (item.children.length == 0 || (items.length == $s[selector].length && items.length > 1))){
-                    callback(item, $s, selector, $s[selector][i], undefined, true);
+                    callback(item, $s, selector, $s[selector][i]);
                 }
                 else {
-                    var res = callback(item, $s, selector, undefined, undefined, true);
+                    var res = callback(item, $s, selector);
                     if (typeof res !== "undefined"){
                         result.push(res)
                     }
@@ -91,12 +97,12 @@ function nbInit(a,b){
         nBind(function (item, $s, selector, value, key, thisByClass){
             value = typeof value === 'undefined' ? $s[selector] : value;
             var keyExists = typeof key !== 'undefined';
-            if ((!item.children.length && !Array.isArray(value) && typeof value === 'object') || thisByClass && value){ //hash array on single leaf node -> set attrs on the tag
+            if ((!item.children.length && !Array.isArray(value) && typeof value === 'object') || thisByClass || dom){ //hash array on single leaf node -> set attrs on the tag
                 recursiveObjectSet(item,value);
                 //for (var key in value){
                     //item[key] = value[key];
                 //}
-                if (!thisByClass){
+                if (!thisByClass && !dom){
                     item.nbData = value;
                 }
                 return;
@@ -255,12 +261,14 @@ function nbInit(a,b){
                 target[prop] = null;
             //}
             syncFromDOM(prop);
+            dom = null;
             return target[prop];
         },
         set(target, prop, value){
             //syncFromDOM();
             target[prop] = value
             syncToDOM(prop);
+            dom = null;
             return true;
         },
     })