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

Cloned nodes store ref to original on originalNode, inheritedData checks... #2534

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ function JQLite(element) {
}

function JQLiteClone(element) {
return element.cloneNode(true);
var clone = element.cloneNode(true);
clone.originalNode = element
clone.isClone = true
return clone
}

function JQLiteDealoc(element){
Expand Down Expand Up @@ -310,6 +313,9 @@ function JQLiteInheritedData(element, name, value) {

while (element.length) {
if (value = element.data(name)) return value;
if (element[0].isClone) {
if (value = jqLite(element[0].originalNode).inheritedData(name)) return value
}
element = element.parent();
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ describe('jqLite', function() {
dealoc(doc);
}
);

it('should find data on originalNode if a clone', function() {
var element = jqLite('<i>foo</i>');
element.data('myData', 'abc');
var clone = element.clone()
expect(clone.inheritedData('myData')).toBe('abc');
dealoc(element);
})
});


Expand Down