mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
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.
This commit is contained in:
parent
a4b9a6aca9
commit
e1a050e6b2
3 changed files with 47 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}));
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue