mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 16:47:45 -02: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:
@@ -86,6 +86,7 @@ var tower = angular.module('Tower', [
|
||||
dashboard.name,
|
||||
moment.name,
|
||||
templateUrl.name,
|
||||
'templates',
|
||||
'AuthService',
|
||||
'Utilities',
|
||||
'LicenseHelper',
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
export default
|
||||
[ 'templateUrl',
|
||||
function(templateUrl) {
|
||||
'$rootScope',
|
||||
function(templateUrl, $rootScope) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: templateUrl('shared/icon/icon'),
|
||||
scope: {
|
||||
},
|
||||
link: function(scope, element, attrs) {
|
||||
|
||||
function buildSvgs() {
|
||||
var svg = $('svg', element);
|
||||
var iconPath = '#' + attrs.name;
|
||||
|
||||
if ($(iconPath).length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make a copy of the <symbol> tag to insert its contents into this
|
||||
// element's svg tag
|
||||
var content = $(iconPath).clone();
|
||||
@@ -25,6 +32,13 @@ export default
|
||||
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');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user