HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/topswtwmobile.komma.pro/wwwroot/js/app/pages/pages.ng.js
define([],
    function () {

        'use strict';

        var app = angular.module('pages', []);

        /**
         * This controller handles all the functions for the AskHelpPopup
         */
        app.controller('askHelpPopupController', ['$scope', '$timeout', '$window', function ($scope, $timeout, $window) {

            //By default the show is false, so the popup is hidden
            $scope.show = false;

            //By default the popup is in the closed form
            $scope.state = 'closed';

            //By default the bottom is 0px (style)
            $scope.bottomPx = 0;

            //By default the left is 0px (style)
            $scope.leftPx = 0;

            $scope.width = 230;

            //The amount of SECONDS the popup is hidden
            var secondsDelay = 30


            /**
             * This method is called after load,
             * and initializes al the methods
             *
             * @param $timeout
             * @param $scope
             */
            var initialize = function ($timeout, $scope) {
                //Create a timeout of secondsDelay
                $timeout(function () {
                    //When seconds are pased set the show variable to true
                    $scope.show = true
                }, secondsDelay * 1000)
            }

            //Initialize the AskHelpPopup
            initialize($timeout, $scope);

            /**
             * This method is called when the p.text is clicked (ng-click)
             */
            $scope.toggleState = function () {
                //If the state is closed
                if ($scope.state == 'closed') {
                    //Change state to open
                    $scope.state = 'open';
                    //Return
                    return;
                }
                //Set state to closed
                $scope.state = 'closed';
            }


            /**
             * Bind a load event to the window
             * So the bottom of the popup can be calculated
             */
            angular.element($window).load(function () {
                    calculatePopUpPosition(this)
                }
            );

            /**
             * Bind a resize event to the window
             * So the bottom of the popup can be calculated
             */
            angular.element($window).resize(function () {
                    calculatePopUpPosition(this)
                }
            );

            /**
             * Bind a scroll event to the window
             * So the bottom of the popup can be calculated
             */
            angular.element($window).bind('scroll', function () {
                calculatePopUpPosition(this)
            });

            /**
             * This method calculates the popup bottom value
             * @param element
             */
            function calculatePopUpPosition(element) {
                //First calculate the bottom offset
                //Get the footer element
                var footer = angular.element(document.querySelector('#footer'));
                //Content element
                var content = angular.element(document.querySelector('#content'));
                //Body element
                var body = angular.element(document.querySelector('body'));

                //Cookie bar
                var granola = angular.element(document.querySelector('#granola'));
                //default height  = 0
                var granolaHeight = 0
                //if the cookiebar is visible, set the height to granolaheihgt
                if (granola.length !== 0) granolaHeight = granola[0].clientHeight

                //By default the bottomPx is the body height - viewport - scrolled pixels + granolaHeight
                var bottomPx = body[0].clientHeight - element.innerHeight - element.pageYOffset + granolaHeight
                //When the block reaches teh footer (-granolaHeight)
                if ((element.pageYOffset + element.innerHeight - granolaHeight) >= footer.offset().top) {
                    //Set the bottompx to the height of the footer
                    bottomPx = footer[0].clientHeight
                }

                //Set the calculated bottomPx to the bottomnPx of the controller scope
                angular.element('[ng-controller=askHelpPopupController]').scope().bottomPx = bottomPx


                //Then calculate the left offset

                //Width if element
                var elementWith = angular.element('[ng-controller=askHelpPopupController]').scope().width

                //the conent offset.left - element with
                angular.element('[ng-controller=askHelpPopupController]').scope().leftPx = content.offset().left - elementWith

                //Apply to the scope
                angular.element('[ng-controller=askHelpPopupController]').scope().$apply();
            }


        }]);


    }
)