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:
Joe Fiorini
2015-07-14 13:16:19 -04:00
parent 6555eb8923
commit df8859beb7
3 changed files with 32 additions and 16 deletions

View File

@@ -86,6 +86,7 @@ var tower = angular.module('Tower', [
dashboard.name,
moment.name,
templateUrl.name,
'templates',
'AuthService',
'Utilities',
'LicenseHelper',

View File

@@ -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();
}
};

View File

@@ -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');
});
}
};