diff --git a/src/jqLite.js b/src/jqLite.js index 4959a2ed36b9..4c68cdef325f 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -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); diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 70c18d35600f..f121e1a055e0 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -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); diff --git a/test/ng/animatorSpec.js b/test/ng/animatorSpec.js index 439836091587..63fcf5c3ea02 100644 --- a/test/ng/animatorSpec.js +++ b/test/ng/animatorSpec.js @@ -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'); }));