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, dashboard.name,
moment.name, moment.name,
templateUrl.name, templateUrl.name,
'templates',
'AuthService', 'AuthService',
'Utilities', 'Utilities',
'LicenseHelper', 'LicenseHelper',

View File

@@ -1,30 +1,44 @@
export default export default
[ 'templateUrl', [ 'templateUrl',
function(templateUrl) { '$rootScope',
function(templateUrl, $rootScope) {
return { return {
restrict: 'E', restrict: 'E',
templateUrl: templateUrl('shared/icon/icon'), templateUrl: templateUrl('shared/icon/icon'),
scope: { scope: {
}, },
link: function(scope, element, attrs) { 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 function buildSvgs() {
// element's svg tag var svg = $('svg', element);
var content = $(iconPath).clone(); var iconPath = '#' + attrs.name;
// Copy classes & viewBox off the <symbol> so that we preserve any styling if ($(iconPath).length === 0) {
// when we copy the item inline return;
var classes = $(iconPath).attr('class'); }
// viewBox needs to be access via native // Make a copy of the <symbol> tag to insert its contents into this
// javascript's setAttribute function // element's svg tag
var viewBox = $(iconPath)[0].getAttribute('viewBox'); var content = $(iconPath).clone();
svg[0].setAttribute('viewBox', viewBox); // Copy classes & viewBox off the <symbol> so that we preserve any styling
svg.attr('class', classes) // when we copy the item inline
.html(content.contents()); 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();
} }
}; };

View File

@@ -1,4 +1,4 @@
export default ['$http', function($http) { export default ['$http', '$rootScope', function($http, $rootScope) {
return { return {
restrict: 'E', restrict: 'E',
link: function(scope, element, attrs) { link: function(scope, element, attrs) {
@@ -6,6 +6,7 @@ export default ['$http', function($http) {
$http.get(path).then(function(response) { $http.get(path).then(function(response) {
element.append(response.data); element.append(response.data);
$rootScope.$emit('include-svg.svg-ready');
}); });
} }
}; };