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

Commit 7560a8d

Browse files
mikecpetebacondarwin
authored andcommitted
fix(ngTouch): check undefined tagName for SVG event target
When target click element is an SVG, event.target.tagName and event.target.blur are undefined in Chrome v40 on iOS 8.1.3
1 parent c68357d commit 7560a8d

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/ngTouch/directive/ngClick.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
/* global ngTouch: false */
3+
/* global ngTouch: false,
4+
nodeName_: false
5+
*/
46

57
/**
68
* @ngdoc directive
@@ -142,7 +144,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
142144
lastLabelClickCoordinates = null;
143145
}
144146
// remember label click coordinates to prevent click busting of trigger click event on input
145-
if (event.target.tagName.toLowerCase() === 'label') {
147+
if (nodeName_(event.target) === 'label') {
146148
lastLabelClickCoordinates = [x, y];
147149
}
148150

@@ -158,7 +160,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
158160
event.preventDefault();
159161

160162
// Blur focused form elements
161-
event.target && event.target.blur();
163+
event.target && event.target.blur && event.target.blur();
162164
}
163165

164166

src/ngTouch/touch.js

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
/* global -ngTouch */
2323
var ngTouch = angular.module('ngTouch', []);
2424

25+
function nodeName_(element) {
26+
return angular.lowercase(element.nodeName || (element[0] && element[0].nodeName));
27+
}

test/ngTouch/directive/ngClickSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ describe('ngClick (touch)', function() {
171171
expect($rootScope.tapped).toBe(true);
172172
}));
173173

174+
it('should click when target element is an SVG', inject(
175+
function($rootScope, $compile, $rootElement) {
176+
element = $compile('<svg ng-click="tapped = true"></svg>')($rootScope);
177+
$rootElement.append(element);
178+
$rootScope.$digest();
179+
180+
browserTrigger(element, 'touchstart');
181+
browserTrigger(element, 'touchend');
182+
browserTrigger(element, 'click', {x:1, y:1});
183+
184+
expect($rootScope.tapped).toEqual(true);
185+
}));
174186

175187
describe('the clickbuster', function() {
176188
var element1, element2;

0 commit comments

Comments
 (0)