Created
May 31, 2015 06:15
-
-
Save oogatta/c16a45b59dfd38a6bbb2 to your computer and use it in GitHub Desktop.
angular android link workaround without any dependency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('androidLinkWorkaround', [function androidLinkWorkaroundFactory() { | |
var elements = []; | |
var isAndroid = function () { | |
return /(Android);?[\s\/]+([\d.]+)?/.test(navigator.userAgent); | |
}; | |
return { | |
on: function (targetSelectors, exclusionRootSelector) { | |
if ( !isAndroid() ) { | |
return; | |
} | |
targetSelectors.forEach(function (targetSelector) { | |
elements = elements.concat(Array.prototype.filter.call( | |
document.querySelectorAll(targetSelector), | |
function (element) { | |
return ( Array.prototype.indexOf.call( | |
document.querySelectorAll(exclusionRootSelector + ' ' + targetSelector), | |
element | |
) === -1 ); | |
}) | |
); | |
elements.forEach(function (link) { | |
angular.element(link).css('visibility', 'hidden'); | |
}); | |
}); | |
}, | |
off: function () { | |
if ( !isAndroid() ) { | |
return; | |
} | |
elements.forEach(function (link) { | |
angular.element(link).css('visibility', 'visible'); | |
}); | |
elements = []; | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment