ReadyMenuSecondController.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. app.controller('ReadyMenuSecondController',['$scope','$location','$timeout','$window','$interval',function($scope,$location,$timeout,$window,$interval){
  2. $scope.currentPath = $location.path();
  3. if($scope.currentPath.indexOf('loss') > -1){
  4. $scope.filterBy = 'loss';
  5. } else if($scope.currentPath.indexOf('gain') > -1){
  6. $scope.filterBy = 'gain';
  7. } else if($scope.currentPath.indexOf('balance') > -1){
  8. $scope.filterBy = 'balance';
  9. }
  10. var firebaseDiets = firebase.database().ref().child('diets');
  11. $interval(function(){
  12. if(firebase.auth().currentUser){
  13. $scope.firebaseShoppingCart = firebase.database().ref().child('users').child(firebase.auth().currentUser.uid).child('shoppingCart');
  14. }
  15. },1000)
  16. $scope.diets = {};
  17. firebaseDiets.on('value', snap => {
  18. $timeout(function(){
  19. $scope.diets = snap.val();
  20. })
  21. })
  22. $scope.weekCount = "1";
  23. // $scope.selectArr = [
  24. // {val: '1', name: 'week 1', isSelected:'true'},
  25. // {val: '2', name: 'week 2', isSelected:'false'},
  26. // {val: '3', name: 'week 3', isSelected:'false'},
  27. // {val: '4', name: 'week 4', isSelected:'false'},
  28. // ]
  29. // scroll
  30. var JQWindow = angular.element($window);
  31. JQWindow.bind('scroll', function(){
  32. // if(window.pageYOffset >= '10'){
  33. // var item = document.querySelector('.ready-menu-second .item:nth-child(1)');
  34. // var JQItem = angular.element(item);
  35. // JQItem.addClass('ready-menu-second-scroll-class');
  36. // } else{
  37. // var item = document.querySelector('.ready-menu-second .item:nth-child(1)');
  38. // var JQItem = angular.element(item);
  39. // JQItem.removeClass('ready-menu-second-scroll-class');
  40. // }
  41. if(window.pageYOffset >= '350'){
  42. var item = document.querySelector('.ready-menu-second .item:nth-child(2)');
  43. var JQItem = angular.element(item);
  44. JQItem.addClass('ready-menu-second-scroll-class');
  45. } else{
  46. var item = document.querySelector('.ready-menu-second .item:nth-child(2)');
  47. var JQItem = angular.element(item);
  48. JQItem.removeClass('ready-menu-second-scroll-class');
  49. }
  50. })
  51. $scope.onInit = function(){
  52. $timeout(function(){
  53. var item = document.querySelector('.ready-menu-second .item:nth-child(1)');
  54. var JQItem = angular.element(item);
  55. JQItem.addClass('ready-menu-second-scroll-class');
  56. },500)
  57. }
  58. // functions
  59. $scope.addToCart = function(diet, dietPrice, weekCount){
  60. if(firebase.auth().currentUser){
  61. var readyDiet = diet;
  62. readyDiet.overallPrice = dietPrice * weekCount;
  63. readyDiet.weekCount = weekCount;
  64. $scope.firebaseShoppingCart.push().set(readyDiet);
  65. var shoppingCartIconJQ = angular.element(document.querySelector('.shopping-cart-icon span'));
  66. shoppingCartIconJQ.addClass('animate');
  67. $timeout(function(){
  68. shoppingCartIconJQ.removeClass('animate');
  69. },500)
  70. } else{
  71. var loginPopupJQ = angular.element(document.querySelector('.login-popup'));
  72. loginPopupJQ.css('display','flex');
  73. $timeout(function(){
  74. loginPopupJQ.css('opacity','1');
  75. },50)
  76. }
  77. }
  78. }])