From bb98ae14f2aef74efbd8345e93f62ac67f460f7f Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 23 Mar 2010 14:57:11 -0700 Subject: markup now wroks, some refactorings --- src/jqLite.js | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 src/jqLite.js (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js new file mode 100644 index 00000000..035a7a1b --- /dev/null +++ b/src/jqLite.js @@ -0,0 +1,185 @@ + +/////////////////////////////////// +//JQLite +////////////////////////////////// + +var jqCache = {}; +var jqName = 'ng-' + new Date().getTime(); +var jqId = 1; +function jqNextId() { return jqId++; } + +var addEventListener = window.document.attachEvent ? + function(element, type, fn) { + element.attachEvent('on' + type, fn); + } : function(element, type, fn) { + element.addEventListener(type, fn, false); + }; + +var removeEventListener = window.document.detachEvent ? + function(element, type, fn) { + element.detachEvent('on' + type, fn); + } : function(element, type, fn) { + element.removeEventListener(type, fn, false); + }; + +function jqClearData(element) { + var cacheId = element[jqName], + cache = jqCache[cacheId]; + if (cache) { + foreach(cache.bind || {}, function(fn, type){ + removeEventListener(element, type, fn); + }); + delete jqCache[cacheId]; + delete element[jqName]; + } +}; + +function JQLite(element) { + this[0] = element; +} + +function jqLite(element) { + if (typeof element == 'string') { + var div = document.createElement('div'); + div.innerHTML = element; + element = div.childNodes[0]; + } + return element instanceof JQLite ? element : new JQLite(element); +} + +JQLite.prototype = { + data: function(key, value) { + var element = this[0], + cacheId = element[jqName], + cache = jqCache[cacheId || -1]; + if (isDefined(value)) { + if (!cache) { + element[jqName] = cacheId = jqNextId(); + cache = jqCache[cacheId] = {}; + } + cache[key] = value; + } else { + return cache ? cache[key] : null; + } + }, + + removeData: function(){ + jqClearData(this[0]); + }, + + dealoc: function(){ + (function dealoc(element){ + jqClearData(element); + for ( var i = 0, children = element.childNodes; i < children.length; i++) { + dealoc(children[0]); + } + })(this[0]); + }, + + bind: function(type, fn){ + var element = this[0], + bind = this.data('bind'), + eventHandler; + if (!bind) this.data('bind', bind = {}); + eventHandler = bind[type]; + if (!eventHandler) { + bind[type] = eventHandler = function() { + var self = this; + foreach(eventHandler.fns, function(fn){ + fn.apply(self, arguments); + }); + }; + eventHandler.fns = []; + addEventListener(element, type, eventHandler); + } + eventHandler.fns.push(fn); + }, + + trigger: function(type) { + var cache = this.data('bind'); + if (cache) { + (cache[type] || noop)(); + } + }, + + click: function(fn) { + if (fn) + this.bind('click', fn); + else + this.trigger('click'); + }, + + replaceWith: function(replaceNode) { + this[0].parentNode.replaceChild(jqLite(replaceNode)[0], this[0]); + }, + + remove: function() { + this.dealoc(); + this[0].parentNode.removeChild(this[0]); + }, + + removeAttr: function(name) { + this[0].removeAttribute(name); + }, + + after: function(element) { + this[0].parentNode.insertBefore(jqLite(element)[0], this[0].nextSibling); + }, + + hasClass: function(selector) { + var className = " " + selector + " "; + if ( (" " + this[0].className + " ").replace(/[\n\t]/g, " ").indexOf( className ) > -1 ) { + return true; + } + return false; + }, + + addClass: function( selector ) { + if (!this.hasClass(selector)) { + this[0].className += ' ' + selector; + } + }, + + css: function(name, value) { + var style = this[0].style; + if (isString(name)) { + if (isDefined(value)) { + style[name] = value; + } else { + return style[name]; + } + } else { + extend(style, name); + } + }, + + attr: function(name, value){ + var e = this[0]; + if (isObject(name)) { + foreach(name, function(value, name){ + e.setAttribute(name, value); + }); + } else if (isDefined(value)) { + e.setAttribute(name, value); + } else { + return e.getAttribute(name); + } + }, + + text: function(value) { + if (isDefined(value)) { + this[0].textContent = value; + } + return this[0].textContent; + }, + + html: function(value) { + if (isDefined(value)) { + this[0].innerHTML = value; + } + return this[0].innerHTML; + }, + + parent: function() { return jqLite(this[0].parentNode);}, + clone: function() { return jqLite(this[0].cloneNode(true)); } +}; -- cgit v1.2.3 From 0c42eb9909d554807549cd3394e0ea0c715cc2d1 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 24 Mar 2010 16:13:42 -0700 Subject: input[type=text] now works with binding, validation, formatter, required --- src/jqLite.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 035a7a1b..2ac3f6c9 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -77,22 +77,24 @@ JQLite.prototype = { }, bind: function(type, fn){ - var element = this[0], - bind = this.data('bind'), + var self = this, + element = self[0], + bind = self.data('bind'), eventHandler; if (!bind) this.data('bind', bind = {}); - eventHandler = bind[type]; - if (!eventHandler) { - bind[type] = eventHandler = function() { - var self = this; - foreach(eventHandler.fns, function(fn){ - fn.apply(self, arguments); - }); - }; - eventHandler.fns = []; - addEventListener(element, type, eventHandler); - } - eventHandler.fns.push(fn); + foreach(type.split(' '), function(type){ + eventHandler = bind[type]; + if (!eventHandler) { + bind[type] = eventHandler = function() { + foreach(eventHandler.fns, function(fn){ + fn.apply(self, arguments); + }); + }; + eventHandler.fns = []; + addEventListener(element, type, eventHandler); + } + eventHandler.fns.push(fn); + }); }, trigger: function(type) { @@ -134,6 +136,10 @@ JQLite.prototype = { return false; }, + removeClass: function(selector) { + this[0].className = trim((" " + this[0].className + " ").replace(/[\n\t]/g, " ").replace(" " + selector + " ", "")); + }, + addClass: function( selector ) { if (!this.hasClass(selector)) { this[0].className += ' ' + selector; -- cgit v1.2.3 From f29f6a47c4d81c5b8e365a3dae307159f1b12968 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 24 Mar 2010 16:47:11 -0700 Subject: fixed .value vs attr(value) access --- src/jqLite.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 2ac3f6c9..2132bfc1 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -179,6 +179,13 @@ JQLite.prototype = { return this[0].textContent; }, + val: function(value) { + if (isDefined(value)) { + this[0].value = value; + } + return this[0].value; + }, + html: function(value) { if (isDefined(value)) { this[0].innerHTML = value; -- cgit v1.2.3 From b814c79b58deeeeaa12b03261399ef80c0d6cc9f Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 25 Mar 2010 13:01:08 -0700 Subject: checkbox and radio now working --- src/jqLite.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 2132bfc1..7646bf98 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -71,7 +71,7 @@ JQLite.prototype = { (function dealoc(element){ jqClearData(element); for ( var i = 0, children = element.childNodes; i < children.length; i++) { - dealoc(children[0]); + dealoc(children[i]); } })(this[0]); }, @@ -86,9 +86,11 @@ JQLite.prototype = { eventHandler = bind[type]; if (!eventHandler) { bind[type] = eventHandler = function() { + var value = false; foreach(eventHandler.fns, function(fn){ - fn.apply(self, arguments); + value = value || fn.apply(self, arguments); }); + return value; }; eventHandler.fns = []; addEventListener(element, type, eventHandler); @@ -98,10 +100,9 @@ JQLite.prototype = { }, trigger: function(type) { - var cache = this.data('bind'); - if (cache) { - (cache[type] || noop)(); - } + var evnt = document.createEvent('MouseEvent'); + evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); + this[0].dispatchEvent(evnt); }, click: function(fn) { -- cgit v1.2.3 From 258ca5f16581f0e8befa493644225a02ae2fc002 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 26 Mar 2010 16:27:18 -0700 Subject: moved all uneeded files out, widgets.html works, tests horribly broken --- src/jqLite.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 7646bf98..a5014354 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -38,7 +38,8 @@ function JQLite(element) { this[0] = element; } -function jqLite(element) { + +function jqLiteWrap(element) { if (typeof element == 'string') { var div = document.createElement('div'); div.innerHTML = element; @@ -47,6 +48,8 @@ function jqLite(element) { return element instanceof JQLite ? element : new JQLite(element); } +jqLite = jqLite || jqLiteWrap; + JQLite.prototype = { data: function(key, value) { var element = this[0], @@ -85,12 +88,15 @@ JQLite.prototype = { foreach(type.split(' '), function(type){ eventHandler = bind[type]; if (!eventHandler) { - bind[type] = eventHandler = function() { - var value = false; + bind[type] = eventHandler = function(event) { + var bubbleEvent = false; foreach(eventHandler.fns, function(fn){ - value = value || fn.apply(self, arguments); + bubbleEvent = bubbleEvent || fn.apply(self, arguments); }); - return value; + if (!bubbleEvent) { + event.preventDefault(); + event.stopPropagation(); + } }; eventHandler.fns = []; addEventListener(element, type, eventHandler); -- cgit v1.2.3 From e55c97debaa0ef8487ece219b6eadbc147ece1f9 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 29 Mar 2010 20:25:42 -0700 Subject: dissabled a lot of tests, and made the core test set pass. --- src/jqLite.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index a5014354..449854d5 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -1,5 +1,4 @@ - -/////////////////////////////////// +////////////////////////////////// //JQLite ////////////////////////////////// @@ -38,18 +37,6 @@ function JQLite(element) { this[0] = element; } - -function jqLiteWrap(element) { - if (typeof element == 'string') { - var div = document.createElement('div'); - div.innerHTML = element; - element = div.childNodes[0]; - } - return element instanceof JQLite ? element : new JQLite(element); -} - -jqLite = jqLite || jqLiteWrap; - JQLite.prototype = { data: function(key, value) { var element = this[0], -- cgit v1.2.3 From 35a91085004e31f786df1e0011bc26ed0142ab4d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 31 Mar 2010 13:57:25 -0700 Subject: all tests green, some dissabled --- src/jqLite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 449854d5..3baafd51 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -136,7 +136,7 @@ JQLite.prototype = { addClass: function( selector ) { if (!this.hasClass(selector)) { - this[0].className += ' ' + selector; + this[0].className = trim(this[0].className + ' ' + selector); } }, -- cgit v1.2.3 From a80a61839a66d244c8bb14bbe2975746e02516c8 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 3 Apr 2010 17:04:36 -0700 Subject: injection is now working --- src/jqLite.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 3baafd51..ec77a6fb 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -5,7 +5,7 @@ var jqCache = {}; var jqName = 'ng-' + new Date().getTime(); var jqId = 1; -function jqNextId() { return jqId++; } +function jqNextId() { return (jqId++); } var addEventListener = window.document.attachEvent ? function(element, type, fn) { @@ -31,7 +31,7 @@ function jqClearData(element) { delete jqCache[cacheId]; delete element[jqName]; } -}; +} function JQLite(element) { this[0] = element; -- cgit v1.2.3 From 7a4b48020688060debe9cb0f9c17615d7585cbe7 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 5 Apr 2010 11:46:53 -0700 Subject: added ng:switch widget --- src/jqLite.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index ec77a6fb..f8ed4d7d 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -109,6 +109,10 @@ JQLite.prototype = { this[0].parentNode.replaceChild(jqLite(replaceNode)[0], this[0]); }, + append: function(node) { + this[0].appendChild(jqLite(node)[0]); + }, + remove: function() { this.dealoc(); this[0].parentNode.removeChild(this[0]); @@ -182,6 +186,9 @@ JQLite.prototype = { html: function(value) { if (isDefined(value)) { + for ( var i = 0, children = this[0].childNodes; i < children.length; i++) { + jqLite(children[i]).dealoc(); + } this[0].innerHTML = value; } return this[0].innerHTML; -- cgit v1.2.3 From 2107eafcde390eebbf59e829194626c488de9e29 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 5 Apr 2010 20:53:33 -0700 Subject: added hover service --- src/jqLite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index f8ed4d7d..331db68d 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -78,7 +78,7 @@ JQLite.prototype = { bind[type] = eventHandler = function(event) { var bubbleEvent = false; foreach(eventHandler.fns, function(fn){ - bubbleEvent = bubbleEvent || fn.apply(self, arguments); + bubbleEvent = bubbleEvent || fn.call(self, event); }); if (!bubbleEvent) { event.preventDefault(); -- cgit v1.2.3 From e6460685869e16b5016de975fd0ba15a7e436951 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 5 Apr 2010 21:26:52 -0700 Subject: added ng-controller directive --- src/jqLite.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 331db68d..9aa4f2c7 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -115,7 +115,8 @@ JQLite.prototype = { remove: function() { this.dealoc(); - this[0].parentNode.removeChild(this[0]); + var parentNode = this[0].parentNode; + if (parentNode) parentNode.removeChild(this[0]); }, removeAttr: function(name) { -- cgit v1.2.3 From ee327a1f4f75f57c2a2c6166520c092d4942ffe0 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 6 Apr 2010 14:04:08 -0700 Subject: few fixes to make tests pass with jquery --- src/jqLite.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 9aa4f2c7..e9407987 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -92,6 +92,7 @@ JQLite.prototype = { }); }, + //TODO: remove trigger: function(type) { var evnt = document.createEvent('MouseEvent'); evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); -- cgit v1.2.3 From c4ef1f2fdd73bdaeda879e596d3d96e4e68cb6fd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 8 Apr 2010 13:43:40 -0700 Subject: tests failing jstd to show cory --- src/jqLite.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index e9407987..6fc16e57 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -140,6 +140,11 @@ JQLite.prototype = { this[0].className = trim((" " + this[0].className + " ").replace(/[\n\t]/g, " ").replace(" " + selector + " ", "")); }, + toggleClass: function(selector, condition) { + var self = this; + (condition ? self.addClass : self.removeClass).call(self, selector); + }, + addClass: function( selector ) { if (!this.hasClass(selector)) { this[0].className = trim(this[0].className + ' ' + selector); -- cgit v1.2.3 From 2637d4e90c8a43436d21a4b9e790b00ae461c438 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 12 Apr 2010 14:28:15 -0700 Subject: removed Meta and allowed binding of HTML --- src/jqLite.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 6fc16e57..d4c5492c 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -34,7 +34,15 @@ function jqClearData(element) { } function JQLite(element) { - this[0] = element; + if (element.length && element.item) { + for(var i=0; i < element.length; i++) { + this[i] = element[i]; + } + this.length = element.length; + } else { + this[0] = element; + this.length = 1; + } } JQLite.prototype = { @@ -111,7 +119,11 @@ JQLite.prototype = { }, append: function(node) { - this[0].appendChild(jqLite(node)[0]); + var self = this[0]; + node = jqLite(node); + foreach(node, function(child){ + self.appendChild(child); + }); }, remove: function() { -- cgit v1.2.3 From deb86fe357a901889bc4289087f0b9e69cb8a302 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 16 Apr 2010 14:01:29 -0700 Subject: lots of small fixes --- src/jqLite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index d4c5492c..92bc22a7 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -185,7 +185,7 @@ JQLite.prototype = { } else if (isDefined(value)) { e.setAttribute(name, value); } else { - return e.getAttribute(name); + return e.getAttribute ? e.getAttribute(name) : undefined; } }, -- cgit v1.2.3 From 8e1b670d5b262f70fdbf4c4b01d3109d54a12ac5 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 19 Apr 2010 12:54:39 -0700 Subject: fix ie bug with .text() on jqlite --- src/jqLite.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 92bc22a7..67e1717c 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -191,9 +191,9 @@ JQLite.prototype = { text: function(value) { if (isDefined(value)) { - this[0].textContent = value; + this[0].nodeValue = value; } - return this[0].textContent; + return this[0].nodeValue; }, val: function(value) { -- cgit v1.2.3 From 618a2b423d826ab8366a6907e71a4af0e76d6211 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 19 Apr 2010 14:36:41 -0700 Subject: ie fixes --- src/jqLite.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 67e1717c..4dcd9349 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -100,7 +100,6 @@ JQLite.prototype = { }); }, - //TODO: remove trigger: function(type) { var evnt = document.createEvent('MouseEvent'); evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); @@ -191,9 +190,9 @@ JQLite.prototype = { text: function(value) { if (isDefined(value)) { - this[0].nodeValue = value; + this[0].textContent = value; } - return this[0].nodeValue; + return this[0].textContent; }, val: function(value) { @@ -216,3 +215,20 @@ JQLite.prototype = { parent: function() { return jqLite(this[0].parentNode);}, clone: function() { return jqLite(this[0].cloneNode(true)); } }; + +if (msie) { + extend(JQLite.prototype, { + text: function(value) { + var e = this[0]; + if (isDefined(value)) { + e.innerText = value; + } + // NodeType == 3 is text node + return e.nodeType == 3 ? e.nodeValue : e.innerText; + }, + + trigger: function(type) { + this[0].fireEvent('on' + type); + } + }); +}; -- cgit v1.2.3 From 9f9bdcf3d16de651f85ccfe9e079cb57baca9eb7 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 19 Apr 2010 14:41:36 -0700 Subject: lint --- src/jqLite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 4dcd9349..53f52215 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -231,4 +231,4 @@ if (msie) { this[0].fireEvent('on' + type); } }); -}; +} -- cgit v1.2.3 From 259c2bba4bf1fc4f0d4cf5bcda4ffef0fb5a615a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 19 Apr 2010 17:02:46 -0700 Subject: last failing ie test remaining --- src/jqLite.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 53f52215..2d41a25c 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -29,7 +29,10 @@ function jqClearData(element) { removeEventListener(element, type, fn); }); delete jqCache[cacheId]; - delete element[jqName]; + if (msie) + element[jqName] = ''; // ie does not allow deletion of attributes on elements. + else + delete element[jqName]; } } -- cgit v1.2.3 From 22d93e0a3bc2a6dc0f64c63c68bc8f8489ea9068 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 20 Apr 2010 18:14:13 -0700 Subject: fixes to enable ie --- src/jqLite.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 2d41a25c..1bf6e083 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -37,14 +37,14 @@ function jqClearData(element) { } function JQLite(element) { - if (element.length && element.item) { + if (isElement(element)) { + this[0] = element; + this.length = 1; + } else if (isDefined(element.length) && element.item) { for(var i=0; i < element.length; i++) { this[i] = element[i]; } this.length = element.length; - } else { - this[0] = element; - this.length = 1; } } @@ -92,8 +92,13 @@ JQLite.prototype = { bubbleEvent = bubbleEvent || fn.call(self, event); }); if (!bubbleEvent) { - event.preventDefault(); - event.stopPropagation(); + if (msie) { + event.returnValue = false; + event.cancelBubble = true; + } else { + event.preventDefault(); + event.stopPropagation(); + } } }; eventHandler.fns = []; @@ -109,13 +114,6 @@ JQLite.prototype = { this[0].dispatchEvent(evnt); }, - click: function(fn) { - if (fn) - this.bind('click', fn); - else - this.trigger('click'); - }, - replaceWith: function(replaceNode) { this[0].parentNode.replaceChild(jqLite(replaceNode)[0], this[0]); }, -- cgit v1.2.3 From e78405f6ed82fcd2e9a1cdffb7f1103d52752623 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 21 Apr 2010 12:50:05 -0700 Subject: more if tests pass --- src/jqLite.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 1bf6e083..0867f9c9 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -185,7 +185,9 @@ JQLite.prototype = { } else if (isDefined(value)) { e.setAttribute(name, value); } else { - return e.getAttribute ? e.getAttribute(name) : undefined; + var attributes = e.attributes, + item = attributes ? attributes.getNamedItem(name) : undefined; + return item ? item.value : undefined; } }, @@ -205,8 +207,11 @@ JQLite.prototype = { html: function(value) { if (isDefined(value)) { - for ( var i = 0, children = this[0].childNodes; i < children.length; i++) { - jqLite(children[i]).dealoc(); + var parent = this[0], child; + while(parent.childNodes.length) { + child = parent.childNodes[0]; + jqLite(child).dealoc(); + parent.removeChild(child); } this[0].innerHTML = value; } @@ -229,6 +234,10 @@ if (msie) { }, trigger: function(type) { + + if (nodeName(this) == 'INPUT' && (lowercase(this.attr('type')) == 'radio' || lowercase(this.attr('type')) == 'checkbox')) { + this[0].checked = ! this[0].checked; + } this[0].fireEvent('on' + type); } }); -- cgit v1.2.3 From 8b29156a2ddcc738f9b0cf8dfc48a8648474884d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 21 Apr 2010 14:29:05 -0700 Subject: ie6 now passes --- src/jqLite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 0867f9c9..36248e71 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -187,7 +187,7 @@ JQLite.prototype = { } else { var attributes = e.attributes, item = attributes ? attributes.getNamedItem(name) : undefined; - return item ? item.value : undefined; + return item && item.specified ? item.value : undefined; } }, -- cgit v1.2.3 From 2a9669e1d853d4e18d2eb1f07e84ee5baec838c2 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Apr 2010 15:50:20 -0700 Subject: working on jQuery passing tests --- src/jqLite.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 36248e71..ec1c52d2 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -118,6 +118,10 @@ JQLite.prototype = { this[0].parentNode.replaceChild(jqLite(replaceNode)[0], this[0]); }, + children: function() { + return new JQLite(this[0].childNodes); + }, + append: function(node) { var self = this[0]; node = jqLite(node); -- cgit v1.2.3 From fe434307d15d697a5ffade51bad068f6443965b2 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Apr 2010 17:11:56 -0700 Subject: tests work under jquery and without --- src/jqLite.js | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index ec1c52d2..18589630 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -238,10 +238,6 @@ if (msie) { }, trigger: function(type) { - - if (nodeName(this) == 'INPUT' && (lowercase(this.attr('type')) == 'radio' || lowercase(this.attr('type')) == 'checkbox')) { - this[0].checked = ! this[0].checked; - } this[0].fireEvent('on' + type); } }); -- cgit v1.2.3 From 0396054b4a420972e16d0d9e965eb51ecd6f86a2 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Apr 2010 22:44:48 -0700 Subject: fixed the way IE breaks parests on innerHTML --- src/jqLite.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 18589630..134c1e17 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -211,11 +211,9 @@ JQLite.prototype = { html: function(value) { if (isDefined(value)) { - var parent = this[0], child; - while(parent.childNodes.length) { - child = parent.childNodes[0]; - jqLite(child).dealoc(); - parent.removeChild(child); + var i = 0, childNodes = this[0].childNodes; + for ( ; i < childNodes.length; i++) { + jqLite(childNodes[i]).dealoc(); } this[0].innerHTML = value; } -- cgit v1.2.3 From 2a7cd9f39089af08ff42be6fb247116c35e2d345 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 26 Apr 2010 16:49:34 -0700 Subject: fix ie bug with null and orphans elements --- src/jqLite.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/jqLite.js') diff --git a/src/jqLite.js b/src/jqLite.js index 134c1e17..68172fd8 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -220,7 +220,10 @@ JQLite.prototype = { return this[0].innerHTML; }, - parent: function() { return jqLite(this[0].parentNode);}, + parent: function() { + return jqLite(this[0].parentNode); + }, + clone: function() { return jqLite(this[0].cloneNode(true)); } }; @@ -228,11 +231,14 @@ if (msie) { extend(JQLite.prototype, { text: function(value) { var e = this[0]; - if (isDefined(value)) { - e.innerText = value; - } // NodeType == 3 is text node - return e.nodeType == 3 ? e.nodeValue : e.innerText; + if (e.nodeType == 3) { + if (isDefined(value)) e.nodeValue = value; + return e.nodeValue; + } else { + if (isDefined(value)) e.innerText = value; + return e.innerText; + } }, trigger: function(type) { -- cgit v1.2.3