Skip to content

Commit

Permalink
fix(preloader): wait while amChart is loading
Browse files Browse the repository at this point in the history
  • Loading branch information
SashaSkywalker committed Mar 5, 2016
1 parent 61cb13d commit e6100f4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/app/theme/directives/zoomIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
link: function ($scope, elem) {
var delay = 1000;

if ($rootScope.$pageLoaded) {
if ($rootScope.$pageFinishedLoading) {
delay = 100;
}

Expand Down
16 changes: 14 additions & 2 deletions src/app/theme/services/preloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@
/** @ngInject */
function preloader($q) {
return {
load: function (src) {
loadImg: function (src) {
var d = $q.defer();
var img = new Image();
img.src = src;
img.onload = d.resolve;
img.onload = function(){
console.log("img " + src + " loaded");
d.resolve();
};
return d.promise;
},
loadAmCharts : function(){
var d = $q.defer();
console.log("amchart");
AmCharts.ready(function(){
console.log("amchart loaded");
d.resolve();
});
return d.promise;
}
}
Expand Down
19 changes: 5 additions & 14 deletions src/app/theme/theme.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,19 @@
function themeRun($timeout, $rootScope, layoutSizes, layoutPaths, preloader, $q) {

$q.all([
preloader.load(layoutPaths.images.root + 'blur-bg.jpg'),
preloader.load(layoutPaths.images.root + 'blur-bg-blurred.jpg')
preloader.loadImg(layoutPaths.images.root + 'blur-bg.jpg'),
preloader.loadImg(layoutPaths.images.root + 'blur-bg-blurred.jpg'),
preloader.loadAmCharts(),
$timeout(3000)
]).then(function(){
if(!$rootScope.$pageFinishedLoading){
$rootScope.$pageFinishedLoading = true;
}
if(!$rootScope.$pageLoaded){
$rootScope.$pageLoaded = true;
}
});

$timeout(function () {
if(!$rootScope.$pageFinishedLoading){
$rootScope.$pageFinishedLoading = true;
}
}, 2000);

$timeout(function () {
if(!$rootScope.$pageLoaded){
$rootScope.$pageLoaded = true;
}
}, 4000);
}, 7000);

$rootScope.$isMenuCollapsed = window.innerWidth <= layoutSizes.resWidthCollapseSidebar;
}
Expand Down

0 comments on commit e6100f4

Please sign in to comment.