X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-demo.git;a=blobdiff_plain;f=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fvendor%2FsvgDirs.js;fp=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fvendor%2FsvgDirs.js;h=c07c883d6acaa614f049281bdd126a3a23f77eba;hp=0000000000000000000000000000000000000000;hb=5b1e6cc132f44262a873fa8296a2a3e1017b0278;hpb=f7d2f9ac4168ee5064580c666d508667a73cefc0 diff --git a/afb-client/bower_components/foundation-apps/js/angular/vendor/svgDirs.js b/afb-client/bower_components/foundation-apps/js/angular/vendor/svgDirs.js new file mode 100755 index 0000000..c07c883 --- /dev/null +++ b/afb-client/bower_components/foundation-apps/js/angular/vendor/svgDirs.js @@ -0,0 +1,101 @@ +'use strict'; + +(function(){ + var svgDirectives = {}; + + angular.forEach([ + 'clipPath', + 'colorProfile', + 'src', + 'cursor', + 'fill', + 'filter', + 'marker', + 'markerStart', + 'markerMid', + 'markerEnd', + 'mask', + 'stroke' + ], + function(attr) { + svgDirectives[attr] = [ + '$rootScope', + '$location', + '$interpolate', + '$sniffer', + 'urlResolve', + 'computeSVGAttrValue', + 'svgAttrExpressions', + function( + $rootScope, + $location, + $interpolate, + $sniffer, + urlResolve, + computeSVGAttrValue, + svgAttrExpressions) { + return { + restrict: 'A', + link: function(scope, element, attrs) { + var initialUrl; + + //Only apply to svg elements to avoid unnecessary observing + //Check that is in html5Mode and that history is supported + if ((!svgAttrExpressions.SVG_ELEMENT.test(element[0] && + element[0].toString())) || + !$location.$$html5 || + !$sniffer.history) return; + + //Assumes no expressions, since svg is unforgiving of xml violations + initialUrl = attrs[attr]; + attrs.$observe(attr, updateValue); + $rootScope.$on('$locationChangeSuccess', updateValue); + + function updateValue () { + var newVal = computeSVGAttrValue(initialUrl); + //Prevent recursive updating + if (newVal && attrs[attr] !== newVal) attrs.$set(attr, newVal); + } + } + }; + }]; + }); + + angular.module('ngSVGAttributes', []). + factory('urlResolve', [function() { + //Duplicate of urlResolve & urlParsingNode in angular core + var urlParsingNode = document.createElement('a'); + return function urlResolve(url) { + urlParsingNode.setAttribute('href', url); + return urlParsingNode; + }; + }]). + value('svgAttrExpressions', { + FUNC_URI: /^url\((.*)\)$/, + SVG_ELEMENT: /SVG[a-zA-Z]*Element/, + HASH_PART: /#.*/ + }). + factory('computeSVGAttrValue', [ + '$location', '$sniffer', 'svgAttrExpressions', 'urlResolve', + function($location, $sniffer, svgAttrExpressions, urlResolve) { + return function computeSVGAttrValue(url) { + var match, fullUrl; + if (match = svgAttrExpressions.FUNC_URI.exec(url)) { + //hash in html5Mode, forces to be relative to current url instead of base + if (match[1].indexOf('#') === 0) { + fullUrl = $location.absUrl(). + replace(svgAttrExpressions.HASH_PART, '') + + match[1]; + } + //Presumably links to external SVG document + else { + fullUrl = urlResolve(match[1]); + } + } + return fullUrl ? 'url(' + fullUrl + ')' : null; + }; + } + ] + ). + directive(svgDirectives); +}());