Use window.prerenderReady to know when a page is fully loaded

stable
David Barragán Merino 2015-05-28 20:15:29 +02:00
parent 3fd2939c2c
commit 2a968bddd9
3 changed files with 50 additions and 8 deletions

View File

@ -191,7 +191,8 @@ PublicRegisterMessageDirective = ($config, $navUrls, templates) ->
template: templateFn
}
module.directive("tgPublicRegisterMessage", ["$tgConfig", "$tgNavUrls", "$tgTemplate", PublicRegisterMessageDirective])
module.directive("tgPublicRegisterMessage", ["$tgConfig", "$tgNavUrls", "$tgTemplate",
PublicRegisterMessageDirective])
LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $events, $translate) ->
@ -227,11 +228,17 @@ LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $
$el.on "submit", "form", submit
window.prerenderReady = true
$scope.$on "$destroy", ->
$el.off()
return {link:link}
module.directive("tgLogin", ["$tgAuth", "$tgConfirm", "$tgLocation", "$tgConfig", "$routeParams",
"$tgNavUrls", "$tgEvents", "$translate", LoginDirective])
#############################################################################
## Register Directive
#############################################################################
@ -270,11 +277,17 @@ RegisterDirective = ($auth, $confirm, $location, $navUrls, $config, $analytics,
$el.on "submit", "form", submit
$scope.$on "$destroy", ->
$el.off()
window.prerenderReady = true
return {link:link}
module.directive("tgRegister", ["$tgAuth", "$tgConfirm", "$tgLocation", "$tgNavUrls", "$tgConfig",
"$tgAnalytics", "$translate", RegisterDirective])
#############################################################################
## Forgot Password Directive
#############################################################################
@ -306,11 +319,17 @@ ForgotPasswordDirective = ($auth, $confirm, $location, $navUrls, $translate) ->
$el.on "submit", "form", submit
$scope.$on "$destroy", ->
$el.off()
window.prerenderReady = true
return {link:link}
module.directive("tgForgotPassword", ["$tgAuth", "$tgConfirm", "$tgLocation", "$tgNavUrls", "$translate",
ForgotPasswordDirective])
#############################################################################
## Change Password from Recovery Directive
#############################################################################
@ -350,10 +369,15 @@ ChangePasswordFromRecoveryDirective = ($auth, $confirm, $location, $params, $nav
$el.on "submit", "form", submit
$scope.$on "$destroy", ->
$el.off()
return {link:link}
module.directive("tgChangePasswordFromRecovery", ["$tgAuth", "$tgConfirm", "$tgLocation", "$routeParams",
"$tgNavUrls", "$translate", ChangePasswordFromRecoveryDirective])
"$tgNavUrls", "$translate",
ChangePasswordFromRecoveryDirective])
#############################################################################
## Invitation
@ -380,7 +404,9 @@ InvitationDirective = ($auth, $confirm, $location, $params, $navUrls, $analytics
onSuccessSubmitLogin = (response) ->
$analytics.trackEvent("auth", "invitationAccept", "invitation accept with existing user", 1)
$location.path($navUrls.resolve("project", {project: $scope.invitation.project_slug}))
text = $translate.instant("INVITATION_LOGIN_FORM.SUCCESS", {"project_name": $scope.invitation.project_name})
text = $translate.instant("INVITATION_LOGIN_FORM.SUCCESS", {
"project_name": $scope.invitation.project_name
})
$confirm.notify("success", text)
@ -428,11 +454,15 @@ InvitationDirective = ($auth, $confirm, $location, $params, $navUrls, $analytics
$el.on "submit", "form.register-form", submitRegister
$el.on "click", ".button-register", submitRegister
$scope.$on "$destroy", ->
$el.off()
return {link:link}
module.directive("tgInvitation", ["$tgAuth", "$tgConfirm", "$tgLocation", "$routeParams",
"$tgNavUrls", "$tgAnalytics", "$translate", InvitationDirective])
#############################################################################
## Change Email
#############################################################################
@ -471,10 +501,14 @@ ChangeEmailDirective = ($repo, $model, $auth, $confirm, $location, $params, $nav
event.preventDefault()
submit()
$scope.$on "$destroy", ->
$el.off()
return {link:link}
module.directive("tgChangeEmail", ["$tgRepo", "$tgModel", "$tgAuth", "$tgConfirm", "$tgLocation", "$routeParams",
"$tgNavUrls", "$translate", ChangeEmailDirective])
module.directive("tgChangeEmail", ["$tgRepo", "$tgModel", "$tgAuth", "$tgConfirm", "$tgLocation",
"$routeParams", "$tgNavUrls", "$translate", ChangeEmailDirective])
#############################################################################
## Cancel account
@ -510,7 +544,10 @@ CancelAccountDirective = ($repo, $model, $auth, $confirm, $location, $params, $n
$el.on "submit", "form", submit
$scope.$on "$destroy", ->
$el.off()
return {link:link}
module.directive("tgCancelAccount", ["$tgRepo", "$tgModel", "$tgAuth", "$tgConfirm", "$tgLocation", "$routeParams",
"$tgNavUrls", CancelAccountDirective])
module.directive("tgCancelAccount", ["$tgRepo", "$tgModel", "$tgAuth", "$tgConfirm", "$tgLocation",
"$routeParams","$tgNavUrls", CancelAccountDirective])

View File

@ -66,7 +66,9 @@ Loader = ($rootscope) ->
if diff < config.minTime
timeoutValue = config.minTime - diff
timeout(timeoutValue, -> $rootscope.$broadcast("loader:end"))
timeout timeoutValue, ->
$rootscope.$broadcast("loader:end")
window.prerenderReady = true # Needed by Prerender Server
startLoadTime = 0
requestCount = 0

View File

@ -11,6 +11,9 @@ html(lang="en")
link(rel="stylesheet", href="/styles/main.css")
link(rel="icon", type="image/png", href="/images/favicon.png")
//- PRERENDER SERVICE: This is to know when the page is completely loaded.
script(type='text/javascript').
window.prerenderReady = false;
body(tg-main)
include partials/includes/components/notification-message