Personal portfolio website for Regina Carvalho. Built with Famous.js library.

background.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @ngdoc function
  3. * @name domainManagerApp.controller:AboutCtrl
  4. * @description
  5. * # AboutCtrl
  6. * Controller of the domainManagerApp
  7. */
  8. angular.module('goApp.background', ['famous.angular', 'goApp.data'])
  9. .controller('BackgroundController',['$scope', '$rootScope', '$famous', '$timeline', 'Data', '$timeout', function ($scope, $rootScope, $famous, $timeline, Data, $timeout) {
  10. 'use strict';
  11. // Functions
  12. $scope.loadBackgroundData = function() {
  13. $scope.videos = Data.getBackgrounds();
  14. $rootScope.$on('data:loaded', function(data) {
  15. if(!$scope.$$phase) {
  16. $scope.$apply(function(){
  17. $scope.videos = Data.getBackgrounds();
  18. $scope.preload();
  19. });
  20. } else {
  21. $scope.videos = Data.getBackgrounds();
  22. $scope.preload();
  23. }
  24. });
  25. };
  26. $scope.preload = function() {
  27. $scope.current_video = $scope.videos[$scope.randomIntFromInterval(0,3)];
  28. console.log("> Preloading video: " + $scope.current_video);
  29. var preload = new createjs.LoadQueue();
  30. preload.addEventListener("complete", handleFileComplete);
  31. // for (var i = 0; i < $scope.videos.length; i++) {
  32. // preload.loadFile($scope.videos[i]);
  33. // }
  34. preload.loadFile($scope.current_video);
  35. function handleFileComplete(event) {
  36. console.log("> Preload Complete");
  37. $scope.startBackgroundVideo();
  38. $timeout(function(){
  39. $rootScope.$broadcast('background:loaded');
  40. },1000);
  41. }
  42. };
  43. $scope.randomIntFromInterval = function(min,max) {
  44. return Math.floor(Math.random()*(max-min+1)+min);
  45. };
  46. $scope.startBackgroundVideo = function() {
  47. console.log("> Playing background video");
  48. var video = new VideoSurface({
  49. size: [undefined, undefined],
  50. autoplay: true,
  51. src: $scope.current_video,
  52. classes: ['bg_video'],
  53. properties: {
  54. zIndex: 1,
  55. }
  56. });
  57. video.setAttributes({ loop: '' });
  58. var videoModifier = new Modifier();
  59. videoModifier.transformFrom(function(){
  60. //transform: Transform.translate(0, 0, 0);
  61. Transform.translate(0, 0, 0);
  62. });
  63. $scope.backgroundView.add(videoModifier).add(video);
  64. };
  65. // Start Background Controller
  66. var View = $famous['famous/core/View'];
  67. var Modifier = $famous['famous/core/Modifier'];
  68. var Surface = $famous['famous/core/Surface'];
  69. var Transform = $famous['famous/core/Transform'];
  70. var VideoSurface = $famous['famous/surfaces/VideoSurface'];
  71. $scope.backgroundView = new View();
  72. $scope.loadBackgroundData();
  73. }]);