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

Commit

Permalink
fix(ngTouch): check undefined tagName for SVG event target
Browse files Browse the repository at this point in the history
When target click element is an SVG, event.target.tagName and event.target.blur are undefined in Chrome v40 on iOS 8.1.3
  • Loading branch information
mikec authored and petebacondarwin committed Apr 27, 2015
1 parent c075126 commit 74eb17d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ngTouch/directive/ngClick.js
@@ -1,6 +1,8 @@
'use strict';

/* global ngTouch: false */
/* global ngTouch: false,
nodeName_: false
*/

/**
* @ngdoc directive
Expand Down Expand Up @@ -142,7 +144,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
lastLabelClickCoordinates = null;
}
// remember label click coordinates to prevent click busting of trigger click event on input
if (event.target.tagName.toLowerCase() === 'label') {
if (nodeName_(event.target) === 'label') {
lastLabelClickCoordinates = [x, y];
}

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

// Blur focused form elements
event.target && event.target.blur();
event.target && event.target.blur && event.target.blur();
}


Expand Down
3 changes: 3 additions & 0 deletions src/ngTouch/touch.js
Expand Up @@ -22,3 +22,6 @@
/* global -ngTouch */
var ngTouch = angular.module('ngTouch', []);

function nodeName_(element) {
return angular.lowercase(element.nodeName || (element[0] && element[0].nodeName));
}
12 changes: 12 additions & 0 deletions test/ngTouch/directive/ngClickSpec.js
Expand Up @@ -171,6 +171,18 @@ describe('ngClick (touch)', function() {
expect($rootScope.tapped).toBe(true);
}));

it('should click when target element is an SVG', inject(
function($rootScope, $compile, $rootElement) {
element = $compile('<svg ng-click="tapped = true"></svg>')($rootScope);
$rootElement.append(element);
$rootScope.$digest();

browserTrigger(element, 'touchstart');
browserTrigger(element, 'touchend');
browserTrigger(element, 'click', {x:1, y:1});

expect($rootScope.tapped).toEqual(true);
}));

describe('the clickbuster', function() {
var element1, element2;
Expand Down

0 comments on commit 74eb17d

Please sign in to comment.