Skip to content

Instantly share code, notes, and snippets.

@asmt3
Last active October 12, 2016 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmt3/bbf543f4cea0f92fc3694ad7962efc03 to your computer and use it in GitHub Desktop.
Save asmt3/bbf543f4cea0f92fc3694ad7962efc03 to your computer and use it in GitHub Desktop.
app.directive('ggchrome', ['$http', '$q', '$timeout',
function($http, $q, $timeout) {
return {
link: function(scope, element, attr) {
var chromeBase = 'https://chrome.justgiving.com/clientonly/';
var container = element;
var footer = '';
var headcontent = '';
var header = '';
var scripts = '';
var chromeParts = {
headcontent: $http.get(chromeBase+ '/headcontent'),
header: $http.get(chromeBase+ '/header'),
footer: $http.get(chromeBase+ '/footer'),
scripts: $http.get(chromeBase+ '/scripts')
}
var addChrome = function(responses){
// Content
document.head.innerHTML += responses.headcontent.data
container.find('header').html(responses.header.data)
container.find('footer').html(responses.footer.data);
// Scripts
var bundle = document.createElement('script');
bundle.type = 'text/javascript';
bundle.src = responses.scripts.data;
container.append(bundle)
// Make visible on next loop
$timeout(function(){
container.find('header').css('visibility', 'visible');
container.find('footer').css('visibility', 'visible');
})
}
$q.all(chromeParts).then(addChrome)
}
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment