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

Commit b7e4e92

Browse files
matskoIgorMinar
authored andcommitted
chore(jqLite): expose the _data lookup function to angular.element
1 parent 31c450b commit b7e4e92

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/jqLite.js

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ var jqCache = JQLite.cache = {},
107107
? function(element, type, fn) {element.removeEventListener(type, fn, false); }
108108
: function(element, type, fn) {element.detachEvent('on' + type, fn); });
109109

110+
/*
111+
* !!! This is an undocumented "private" function !!!
112+
*/
113+
var jqData = JQLite._data = function(node) {
114+
//jQuery always returns an object on cache miss
115+
return this.cache[node[this.expando]] || {};
116+
};
117+
110118
function jqNextId() { return ++jqId; }
111119

112120

test/jqLiteSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ describe('jqLite', function() {
9797
});
9898
});
9999

100+
describe('_data', function() {
101+
it('should provide access to the data present on the element', function() {
102+
var element = jqLite('<i>foo</i>');
103+
var data = ['value'];
104+
element.data('val', data);
105+
expect(angular.element._data(element[0]).data.val).toBe(data);
106+
dealoc(element);
107+
});
108+
109+
it('should provide access to the events present on the element', function() {
110+
var element = jqLite('<i>foo</i>');
111+
expect(angular.element._data(element[0]).events).toBeUndefined();
112+
113+
element.on('click', function() { });
114+
expect(angular.element._data(element[0]).events.click).toBeDefined();
115+
});
116+
});
100117

101118
describe('inheritedData', function() {
102119

0 commit comments

Comments
 (0)