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

Commit

Permalink
fix(jqLite): Added optional name arg in removeData
Browse files Browse the repository at this point in the history
jQuery's API for removeData allows a second 'name' argument to just
remove the property by that name from an element's data. The absence
of this argument was causing some features not to work correctly when
combining multiple directives, such as ng-click, ng-show, and ng-animate.
  • Loading branch information
jeffbcross authored and mhevery committed May 31, 2013
1 parent a4b9a6a commit e1a050e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,16 @@ function JQLiteUnbind(element, type, fn) {
}
}

function JQLiteRemoveData(element) {
function JQLiteRemoveData(element, name) {
var expandoId = element[jqName],
expandoStore = jqCache[expandoId];

if (expandoStore) {
if (name) {
delete jqCache[expandoId].data[name];
return;
}

if (expandoStore.handle) {
expandoStore.events.$destroy && expandoStore.handle({}, '$destroy');
JQLiteUnbind(element);
Expand Down
19 changes: 19 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,25 @@ describe('jqLite', function() {
expect(jqLite(c).data('prop')).toBeUndefined();
});

it('should only remove the specified value when providing a property name to removeData', function () {
var selected = jqLite(a);

expect(selected.data('prop1')).toBeUndefined();

selected.data('prop1', 'value');
selected.data('prop2', 'doublevalue');

expect(selected.data('prop1')).toBe('value');
expect(selected.data('prop2')).toBe('doublevalue');

selected.removeData('prop1');

expect(selected.data('prop1')).toBeUndefined();
expect(selected.data('prop2')).toBe('doublevalue');

selected.removeData('prop2');
});

it('should emit $destroy event if element removed via remove()', function() {
var log = '';
var element = jqLite(a);
Expand Down
22 changes: 22 additions & 0 deletions test/ng/animatorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,33 @@ describe("$animator", function() {
});

child.css('display','none');
element.data('foo', 'bar');
animator.show(element);
window.setTimeout.expect(1).process();

animator.hide(element);

expect(element.hasClass('animation-cancelled')).toBe(true);
expect(element.data('foo')).toEqual('bar');
}));

it("should NOT clobber all data on an element when animation is finished",
inject(function($animator, $rootScope) {
$animator.enabled(true);

animator = $animator($rootScope, {
ngAnimate : '{hide: \'custom-delay\', show: \'custom-delay\'}'
});

child.css('display','none');
element.data('foo', 'bar');

animator.show(element);
window.setTimeout.expect(1).process();

animator.hide(element);

expect(element.data('foo')).toEqual('bar');
}));


Expand Down

0 comments on commit e1a050e

Please sign in to comment.