Ivan Asmer 8 år sedan
förälder
incheckning
b381186ba0
1 ändrade filer med 26 tillägg och 1 borttagningar
  1. 26 1
      static/nb.js

+ 26 - 1
static/nb.js

@@ -13,7 +13,32 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OU
 DEALINGS IN THE SOFTWARE. 
 */
 
-function nbInit($s){
+function nbInit(a,b){
+    var root=document, $s=a;
+
+    function searchElement(root, selector){
+        var items = [root.getElementById(selector)]; 
+        items     = items[0]     ? items :  root.querySelectorAll(selector);
+        items     = items.length ? items :  root.getElementsByName(selector); 
+        items     = items.length ? items :  root.getElementsByClassName(selector); 
+        return items;
+    }
+
+    if (a instanceof HTMLElement){
+        root = a;
+        $s   = b;
+    }
+    else if (typeof a === "string"){
+        root = searchElement(document, a)[0];
+        $s   = b;
+    }
+    if (b instanceof HTMLElement){
+        root = b;
+    }
+    else if (typeof b === "string"){
+        root = searchElement(document, a)[0];
+    }
+
     function nBind(callback, prop, direction){
         direction = direction || "write";
         for (var selector in $s){