Last active
October 12, 2016 22:38
-
-
Save asmt3/bbf543f4cea0f92fc3694ad7962efc03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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