Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8f10dca

Browse files
committed
refactor(jqLite): remove legacy code to support IE8 and older
1 parent 566f101 commit 8f10dca

File tree

1 file changed

+21
-90
lines changed

1 file changed

+21
-90
lines changed

src/jqLite.js

+21-90
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ JQLite.expando = 'ng339';
102102

103103
var jqCache = JQLite.cache = {},
104104
jqId = 1,
105-
addEventListenerFn = (window.document.addEventListener
106-
? function(element, type, fn) {element.addEventListener(type, fn, false);}
107-
: function(element, type, fn) {element.attachEvent('on' + type, fn);}),
108-
removeEventListenerFn = (window.document.removeEventListener
109-
? function(element, type, fn) {element.removeEventListener(type, fn, false); }
110-
: function(element, type, fn) {element.detachEvent('on' + type, fn); });
105+
addEventListenerFn = function(element, type, fn) {
106+
element.addEventListener(type, fn, false);
107+
},
108+
removeEventListenerFn = function(element, type, fn) {
109+
element.removeEventListener(type, fn, false);
110+
};
111111

112112
/*
113113
* !!! This is an undocumented "private" function !!!
114114
*/
115-
var jqData = JQLite._data = function(node) {
115+
JQLite._data = function(node) {
116116
//jQuery always returns an object on cache miss
117117
return this.cache[node[this.expando]] || {};
118118
};
@@ -169,7 +169,7 @@ function jqLiteAcceptsData(node) {
169169
}
170170

171171
function jqLiteBuildFragment(html, context) {
172-
var elem, tmp, tag, wrap,
172+
var tmp, tag, wrap,
173173
fragment = context.createDocumentFragment(),
174174
nodes = [], i;
175175

@@ -319,7 +319,7 @@ function jqLiteExpandoStore(element, key, value) {
319319
}
320320
expandoStore[key] = value;
321321
} else {
322-
return expandoStore && expandoStore[key];
322+
return key ? expandoStore && expandoStore[key] : expandoStore;
323323
}
324324
}
325325

@@ -456,23 +456,11 @@ function jqLiteRemove(element, keepData) {
456456
//////////////////////////////////////////
457457
var JQLitePrototype = JQLite.prototype = {
458458
ready: function(fn) {
459-
var fired = false;
460-
461-
function trigger() {
462-
if (fired) return;
463-
fired = true;
464-
fn();
465-
}
466-
467459
// check if document already is loaded
468460
if (document.readyState === 'complete'){
469-
setTimeout(trigger);
461+
setTimeout(fn);
470462
} else {
471-
this.on('DOMContentLoaded', trigger); // works for modern browsers and IE9
472-
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
473-
// jshint -W064
474-
JQLite(window).on('load', trigger); // fallback to window.onload for others
475-
// jshint +W064
463+
this.on('DOMContentLoaded', fn);
476464
}
477465
},
478466
toString: function() {
@@ -562,22 +550,7 @@ forEach({
562550
if (isDefined(value)) {
563551
element.style[name] = value;
564552
} else {
565-
var val;
566-
567-
if (msie <= 8) {
568-
// this is some IE specific weirdness that jQuery 1.6.4 does not sure why
569-
val = element.currentStyle && element.currentStyle[name];
570-
if (val === '') val = 'auto';
571-
}
572-
573-
val = val || element.style[name];
574-
575-
if (msie <= 8) {
576-
// jquery weirdness :-/
577-
val = (val === '') ? undefined : val;
578-
}
579-
580-
return val;
553+
return element.style[name];
581554
}
582555
},
583556

@@ -708,33 +681,10 @@ forEach({
708681

709682
function createEventHandler(element, events) {
710683
var eventHandler = function (event, type) {
711-
if (!event.preventDefault) {
712-
event.preventDefault = function() {
713-
event.returnValue = false; //ie
714-
};
715-
}
716-
717-
if (!event.stopPropagation) {
718-
event.stopPropagation = function() {
719-
event.cancelBubble = true; //ie
720-
};
721-
}
722-
723-
if (!event.target) {
724-
event.target = event.srcElement || document;
725-
}
726-
727-
if (isUndefined(event.defaultPrevented)) {
728-
var prevent = event.preventDefault;
729-
event.preventDefault = function() {
730-
event.defaultPrevented = true;
731-
prevent.call(event);
732-
};
733-
event.defaultPrevented = false;
734-
}
735684

685+
// jQuery specific api
736686
event.isDefaultPrevented = function() {
737-
return event.defaultPrevented || event.returnValue === false;
687+
return event.defaultPrevented;
738688
};
739689

740690
// Copy event handlers in case event handlers array is modified during execution.
@@ -743,21 +693,10 @@ function createEventHandler(element, events) {
743693
for (var i = 0, ii = eventHandlersCopy.length; i < ii; i++) {
744694
eventHandlersCopy[i].call(element, event);
745695
}
746-
747-
// Remove monkey-patched methods (IE),
748-
// as they would cause memory leaks in IE8.
749-
if (msie <= 8) {
750-
// IE7/8 does not allow to delete property on native object
751-
event.preventDefault = null;
752-
event.stopPropagation = null;
753-
event.isDefaultPrevented = null;
754-
} else {
755-
// It shouldn't affect normal browsers (native methods are defined on prototype).
756-
delete event.preventDefault;
757-
delete event.stopPropagation;
758-
delete event.isDefaultPrevented;
759-
}
760696
};
697+
698+
// TODO: this is a hack for angularMocks/clearDataCache that makes it possible to deregister all
699+
// events on `element`
761700
eventHandler.elem = element;
762701
return eventHandler;
763702
}
@@ -778,8 +717,9 @@ forEach({
778717
return;
779718
}
780719

781-
var events = jqLiteExpandoStore(element, 'events'),
782-
handle = jqLiteExpandoStore(element, 'handle');
720+
var expandoStore = jqLiteExpandoStore(element);
721+
var events = expandoStore && expandoStore.events;
722+
var handle = expandoStore && expandoStore.handle;
783723

784724
if (!events) jqLiteExpandoStore(element, 'events', events = {});
785725
if (!handle) jqLiteExpandoStore(element, 'handle', handle = createEventHandler(element, events));
@@ -919,16 +859,7 @@ forEach({
919859
},
920860

921861
next: function(element) {
922-
if (element.nextElementSibling) {
923-
return element.nextElementSibling;
924-
}
925-
926-
// IE8 doesn't have nextElementSibling
927-
var elm = element.nextSibling;
928-
while (elm != null && elm.nodeType !== 1) {
929-
elm = elm.nextSibling;
930-
}
931-
return elm;
862+
return element.nextElementSibling;
932863
},
933864

934865
find: function(element, selector) {

0 commit comments

Comments
 (0)