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

Commit

Permalink
fix(ngAnimate): allow event listeners on document in IE
Browse files Browse the repository at this point in the history
Fixes #13548
  • Loading branch information
Narretz committed Jan 6, 2016
1 parent 495d40d commit 7947bc9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/ngAnimate/animateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
return mergeAnimationOptions(element, options, {});
}

// IE9-11 has no method "contains" in SVG element and in Node.prototype. Bug #10259.
var contains = Node.prototype.contains || function(arg) {
// jshint bitwise: false
return this === arg || !!(this.compareDocumentPosition(arg) & 16);
// jshint bitwise: true
};

function findCallbacks(parent, element, event) {
var targetNode = getDomNode(element);
var targetParentNode = getDomNode(parent);
Expand All @@ -179,9 +186,9 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
var entries = callbackRegistry[event];
if (entries) {
forEach(entries, function(entry) {
if (entry.node.contains(targetNode)) {
if (contains.call(entry.node, targetNode)) {
matches.push(entry.callback);
} else if (event === 'leave' && entry.node.contains(targetParentNode)) {
} else if (event === 'leave' && contains.call(entry.node, targetParentNode)) {
matches.push(entry.callback);
}
});
Expand Down
39 changes: 38 additions & 1 deletion test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,9 @@ describe("animations", function() {
});

return function($document, $rootElement, $animate) {
jqLite($document[0].body).append($rootElement);
if ($document !== $rootElement) {
jqLite($document[0].body).append($rootElement);
}
$animate.enabled(true);
};
}));
Expand Down Expand Up @@ -1946,5 +1948,40 @@ describe("animations", function() {
expect(capturedElement).toBe(element);
}));

they('should trigger a callback for a $prop animation if the listener is on the document',
['enter', 'leave'], function($event) {
module(function($provide) {
$provide.factory('$rootElement', function($document) {
// Since we listen on document, $document must be the $rootElement for animations to work
return $document;
});
});

inject(function($animate, $rootScope, $document) {

var callbackTriggered = false;


$animate.on($event, $document[0], function() {
callbackTriggered = true;
});

var container = jqLite('<div></div>');
jqLite($document[0].body).append(container);
element = jqLite('<div></div>');

if ($event === 'leave') {
container.append(element);
}

$animate[$event](element, container);
$rootScope.$digest();

$animate.flush();

expect(callbackTriggered).toBe(true);
});
});

});
});

0 comments on commit 7947bc9

Please sign in to comment.