Skip to content

Commit

Permalink
feat(onboarding): fixed code style for onboarding autoplay changes
Browse files Browse the repository at this point in the history
  • Loading branch information
peichins committed Nov 20, 2019
1 parent d3be300 commit 43e3612
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
8 changes: 5 additions & 3 deletions src/app/citizenScience/listen/spectrogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ angular.module("bawApp.spectrogram", [])
return {
restrict: "A",
link: function ($scope, element, attributes) {
element.bind("load", function() {
$rootScope.$broadcast("spectrogram-loaded", $scope);

element[0].addEventListener("load", event => {
$rootScope.$broadcast("spectrogram-loaded", $scope);
});
element.bind("error", function(){

element[0].addEventListener("error", event => {
console.log("spectrogram could not be loaded");
});

}
};
}]);
44 changes: 21 additions & 23 deletions src/app/onboarding/onboarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ angular.module("bawApp.components.onboarding", ["bawApp.citizenScience.common",
*/
addCallbacks: function (callbacks, add = true) {
if (add) {
Object.keys(callbacks).forEach(cb => {
Object.keys(callbacks).forEach(callback => {
// if there is already a callback function, nest the old and new in a new function.
if (add && self.callbacks.hasOwnProperty(cb)) {
self.callbacks[cb].push(callbacks[cb]);
if (add && self.callbacks.hasOwnProperty(callback)) {
self.callbacks[callback].push(callbacks[callback]);
} else {
self.callbacks[cb] = [callbacks[cb]];
self.callbacks[callback] = [callbacks[callback]];
}
});
}
Expand Down Expand Up @@ -210,7 +210,13 @@ angular.module("bawApp.components.onboarding", ["bawApp.citizenScience.common",

var self = this;

$scope.status = "loading";
const statuses = {
loading: "loading",
ready: "ready",
open: "open"
};

$scope.status = statuses.loading;

$scope.launchTour = function launchTour () {

Expand All @@ -224,8 +230,8 @@ angular.module("bawApp.components.onboarding", ["bawApp.citizenScience.common",

// use timeouts to ensure that digest cycles are complete before starting
$timeout(() => {
for (let i = 0; i < onboardingService.callbacks.onBeforeStart.length; i++) {
onboardingService.callbacks.onBeforeStart[i].call();
for (const onBeforeStartFunction of onboardingService.callbacks.onBeforeStart) {
onBeforeStartFunction.call();
}
$timeout(() => {
ngIntroService.start();
Expand All @@ -249,16 +255,10 @@ angular.module("bawApp.components.onboarding", ["bawApp.citizenScience.common",
return onboardingService.isReady();
}, function (isReady) {
if (isReady) {
$scope.status = "ready";
$scope.status = statuses.ready;
if (!onboardingService.hasViewedAll()) {
ngIntroService.hideHints();
$scope.launchTour();
// $timeout.cancel(self.autoplayTimeout);
// ngIntroService.hideHints();
// self.autoplayTimeout = $timeout(function () {
// ngIntroService.hideHints();
// $scope.launchTour();
// }, 500);
}
}
});
Expand All @@ -282,25 +282,23 @@ angular.module("bawApp.components.onboarding", ["bawApp.citizenScience.common",

self.onClose = function () {
$timeout(function () {
$scope.status = "ready";
$scope.status = statuses.ready;
}, 1000);
};

self.init = function () {

$scope.status = "open";
$scope.status = statuses.open;

// set all the callbacks
Object.keys(onboardingService.callbacks).forEach((cb) => {
Object.keys(onboardingService.callbacks).forEach(callback => {
// each value is an array of functions, so we wrap them in a function and call each one.
if (angular.isFunction(ngIntroService[cb])) {
ngIntroService[cb](function (arg) {
for (let i = 0; i < onboardingService.callbacks[cb].length; i++) {
onboardingService.callbacks[cb][i](arg);
if (angular.isFunction(ngIntroService[callback])) {
ngIntroService[callback](function (arg) {
for (let i = 0; i < onboardingService.callbacks[callback].length; i++) {
onboardingService.callbacks[callback][i](arg);
}
});
} else {
console.log("no function", cb);
}

});
Expand Down

0 comments on commit 43e3612

Please sign in to comment.