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

Commit e1a050e

Browse files
jeffbcrossmhevery
authored andcommitted
fix(jqLite): Added optional name arg in removeData
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.
1 parent a4b9a6a commit e1a050e

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/jqLite.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,16 @@ function JQLiteUnbind(element, type, fn) {
204204
}
205205
}
206206

207-
function JQLiteRemoveData(element) {
207+
function JQLiteRemoveData(element, name) {
208208
var expandoId = element[jqName],
209209
expandoStore = jqCache[expandoId];
210210

211211
if (expandoStore) {
212+
if (name) {
213+
delete jqCache[expandoId].data[name];
214+
return;
215+
}
216+
212217
if (expandoStore.handle) {
213218
expandoStore.events.$destroy && expandoStore.handle({}, '$destroy');
214219
JQLiteUnbind(element);

test/jqLiteSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,25 @@ describe('jqLite', function() {
246246
expect(jqLite(c).data('prop')).toBeUndefined();
247247
});
248248

249+
it('should only remove the specified value when providing a property name to removeData', function () {
250+
var selected = jqLite(a);
251+
252+
expect(selected.data('prop1')).toBeUndefined();
253+
254+
selected.data('prop1', 'value');
255+
selected.data('prop2', 'doublevalue');
256+
257+
expect(selected.data('prop1')).toBe('value');
258+
expect(selected.data('prop2')).toBe('doublevalue');
259+
260+
selected.removeData('prop1');
261+
262+
expect(selected.data('prop1')).toBeUndefined();
263+
expect(selected.data('prop2')).toBe('doublevalue');
264+
265+
selected.removeData('prop2');
266+
});
267+
249268
it('should emit $destroy event if element removed via remove()', function() {
250269
var log = '';
251270
var element = jqLite(a);

test/ng/animatorSpec.js

+22
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,33 @@ describe("$animator", function() {
345345
});
346346

347347
child.css('display','none');
348+
element.data('foo', 'bar');
348349
animator.show(element);
349350
window.setTimeout.expect(1).process();
351+
350352
animator.hide(element);
351353

352354
expect(element.hasClass('animation-cancelled')).toBe(true);
355+
expect(element.data('foo')).toEqual('bar');
356+
}));
357+
358+
it("should NOT clobber all data on an element when animation is finished",
359+
inject(function($animator, $rootScope) {
360+
$animator.enabled(true);
361+
362+
animator = $animator($rootScope, {
363+
ngAnimate : '{hide: \'custom-delay\', show: \'custom-delay\'}'
364+
});
365+
366+
child.css('display','none');
367+
element.data('foo', 'bar');
368+
369+
animator.show(element);
370+
window.setTimeout.expect(1).process();
371+
372+
animator.hide(element);
373+
374+
expect(element.data('foo')).toEqual('bar');
353375
}));
354376

355377

0 commit comments

Comments
 (0)