mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Bundle angular templates for app
We were already bundling angular templates for node tests; this commit reuses the same setup to include them in the app; this means any new-style template (those under js folder) will be included in angular's template cache when the app loads, thereby skipping the ajax request for that template. Huzzah!
This commit is contained in:
parent
6555eb8923
commit
df8859beb7
@ -86,6 +86,7 @@ var tower = angular.module('Tower', [
|
||||
dashboard.name,
|
||||
moment.name,
|
||||
templateUrl.name,
|
||||
'templates',
|
||||
'AuthService',
|
||||
'Utilities',
|
||||
'LicenseHelper',
|
||||
|
||||
@ -1,30 +1,44 @@
|
||||
export default
|
||||
[ 'templateUrl',
|
||||
function(templateUrl) {
|
||||
'$rootScope',
|
||||
function(templateUrl, $rootScope) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: templateUrl('shared/icon/icon'),
|
||||
scope: {
|
||||
},
|
||||
link: function(scope, element, attrs) {
|
||||
var svg = $('svg', element);
|
||||
var iconPath = '#' + attrs.name;
|
||||
|
||||
// Make a copy of the <symbol> tag to insert its contents into this
|
||||
// element's svg tag
|
||||
var content = $(iconPath).clone();
|
||||
function buildSvgs() {
|
||||
var svg = $('svg', element);
|
||||
var iconPath = '#' + attrs.name;
|
||||
|
||||
// Copy classes & viewBox off the <symbol> so that we preserve any styling
|
||||
// when we copy the item inline
|
||||
var classes = $(iconPath).attr('class');
|
||||
if ($(iconPath).length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// viewBox needs to be access via native
|
||||
// javascript's setAttribute function
|
||||
var viewBox = $(iconPath)[0].getAttribute('viewBox');
|
||||
// Make a copy of the <symbol> tag to insert its contents into this
|
||||
// element's svg tag
|
||||
var content = $(iconPath).clone();
|
||||
|
||||
svg[0].setAttribute('viewBox', viewBox);
|
||||
svg.attr('class', classes)
|
||||
.html(content.contents());
|
||||
// Copy classes & viewBox off the <symbol> so that we preserve any styling
|
||||
// when we copy the item inline
|
||||
var classes = $(iconPath).attr('class');
|
||||
|
||||
// viewBox needs to be access via native
|
||||
// javascript's setAttribute function
|
||||
var viewBox = $(iconPath)[0].getAttribute('viewBox');
|
||||
|
||||
svg[0].setAttribute('viewBox', viewBox);
|
||||
svg.attr('class', classes)
|
||||
.html(content.contents());
|
||||
}
|
||||
|
||||
$rootScope.$on('include-svg.svg-ready', function() {
|
||||
buildSvgs();
|
||||
});
|
||||
|
||||
buildSvgs();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export default ['$http', function($http) {
|
||||
export default ['$http', '$rootScope', function($http, $rootScope) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
link: function(scope, element, attrs) {
|
||||
@ -6,6 +6,7 @@ export default ['$http', function($http) {
|
||||
|
||||
$http.get(path).then(function(response) {
|
||||
element.append(response.data);
|
||||
$rootScope.$emit('include-svg.svg-ready');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user