From b73d024213909de319a72a7a00481c437f583185 Mon Sep 17 00:00:00 2001
From: Commander-lol <ljcapitanio@gmail.com>
Date: Sat, 1 Nov 2014 22:20:08 +0000
Subject: [PATCH] =?UTF-8?q?tinyDOM=20can=20now=20tell=20between=20query=20?=
 =?UTF-8?q?strings=20and=20DOM=20abjects=20passed=20to=20mu,=20allowing=20?=
 =?UTF-8?q?better=20chaining=20with=20=CE=BC(this)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 js/tinyDOM.js  | 25 ++++++++++++++++---------
 test.html      | 19 ++++++++++++++++++-
 tests/get.html |  7 +++++++
 3 files changed, 41 insertions(+), 10 deletions(-)
 create mode 100644 tests/get.html

diff --git a/js/tinyDOM.js b/js/tinyDOM.js
index e629bef..a87ff40 100644
--- a/js/tinyDOM.js
+++ b/js/tinyDOM.js
@@ -5,17 +5,24 @@
 	}
 
 	var tinyDOMFunction = function(selector) {
-		var elements = document.querySelectorAll(selector);
+		if(selector === null || typeof(selector) === 'undefined'){
+			this.length = 0;
+		} else if(typeof(selector) === 'string'){
+			var elements = document.querySelectorAll(selector);
 
-		this.length = elements.length;
-		for(var i = 0; i < elements.length; i++){
-			var e = elements.item(i);
-			if(typeof(e.td_prop) === 'undefined'){
-				e.td_prop = {
-					isHidden: false
-				};
+			this.length = elements.length;
+			for(var i = 0; i < elements.length; i++){
+				var e = elements.item(i);
+				if(typeof(e.td_prop) === 'undefined'){
+					e.td_prop = {
+						isHidden: false
+					};
+				}
+				this[i] = elements.item(i);
 			}
-			this[i] = elements.item(i);
+		} else {
+			this[0] = selector;
+			this.length = 1;
 		}
 
 		return this;
diff --git a/test.html b/test.html
index dccc04d..4f9a54c 100644
--- a/test.html
+++ b/test.html
@@ -8,14 +8,19 @@
 	<body>
 		<h1> this is a title </h1>
 		<div id="test">
+			<p>
 			These are <span class="important">words</span>! They are kind of important words too,
 			so it would be <span class='important'>bad</span> if any of them dissapeared.
+			</p>
+			<p id='emptydiv'>
+				
+			</p>
 		</div>
 
 		<button id="btn-hide">HIDE THINGS</button>
 		<button id="btn-show">SHOW THINGS</button>
 
-		<section class='information' data-href='/info/test.php'>
+		<section class='information' data-href='tests/get.html'>
 			<h2>About tinyDOM functions</h2>
 			<p>
 				tinyDOM operates on dom elements to make it a bit easier
@@ -52,5 +57,17 @@
 	μ('h1').on('click', function(){
 		console.log(this);
 	});
+
+	μ('.information').on('click', function(){
+		var url = μ(this).data('href');
+		console.log(μ(this).data('href'));
+		μ.ajax({
+			url: url,
+			success: function(data){
+				console.log(data);
+				μ('#emptydiv').first().innerHTML = data;
+			}
+		});
+	});
 	</script>
 </html>
diff --git a/tests/get.html b/tests/get.html
new file mode 100644
index 0000000..67f22f2
--- /dev/null
+++ b/tests/get.html
@@ -0,0 +1,7 @@
+<div>
+	<p>
+		This is a piece of text retrieved via some sort of external request.
+		It is, after all, just a fragment of html and would be a terrible 
+		page in and of itself.
+	</p>
+</div>		
\ No newline at end of file
-- 
GitLab