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/tandartsmaas.komma.pro/wwwroot/js/app/core/pageAnimator.js
define([],function()
{
    var $content = $('#content');
    var tl = new TimelineLite();

    var services = ['services',
                    'inspection',
                    'oralHygiene',
                    'hygienist',
                    'preventionAssistant',
                    'crownBridge',
                    'clickTeeth',
                    'childrenDentistry',
                    'gnarlPlate',
                    'partners',
                    'fear'];

    var practice = ['practice',
                    'pregnancy',
                    'signUp',
                    'invoicing',
                    'houseRules',
                    'reschedule',
                    'privacy',
                    'complaint'];

    var allowed = true;

    return{

        /*
         | Switch what kind of animation
         */

        animateOut : function(currentPage, target, callback)
        {
            // Child with equal parent
            if(this.hasEqualParent(currentPage,target))
            {
                this.animateOutWithFixedSubmenu(callback)
            }

            // Services to practice or vice versa
            else if( this.isSubPage(target) && this.isSubPage(currentPage) )
            {
                var dir = 'right';
                if(target == 'services') dir = 'left';

                this.switchSubmenuPageOut(dir, callback)
            }

            // Normal page
            else
            {
                this.fadeOut(callback)
            }
        },

        animateIn : function(currentPage, targetData, callback)
        {
            // Child with equal parent
            if(this.hasEqualParent(currentPage,targetData.name))
            {
                this.animateInWithFixedSubmenu(targetData.view, callback)
            }

            // Services to practice or vice versa
            else if( this.isSubPage(targetData.name) && this.isSubPage(currentPage) )
            {
                var dir = 'right';
                if(targetData.name == 'services') dir = 'left';

                this.switchSubmenuPageIn(dir, targetData.view, callback)
            }

            // Normal page
            else
            {
                this.fadeIn(targetData.view, callback)
            }
        },

        /*
         | Simple animation for standard pages
         | Fade content in, fade content out
         */

        fadeOut : function(callback)
        {
            tl.to($content, .5, {
                opacity: 0,
                onComplete: callback
            });
        },

        fadeIn : function(view, callback)
        {
            $content.html(view);
            tl.to($content, .5,
                {
                    opacity: 1,
                    onComplete: callback
                });
        },


        /*
         | Switch page with submenu to page with submenu
         | F.E. services to pages
         */

        switchSubmenuPageOut : function(dir, callback)
        {
            allowed = false;

            // Properties
            var $subContent = $('#subContent');
            var $table = $content.children('.table');

            // Direction
            var animateTo = '50%';
            if(dir == 'left') animateTo = '-50%';

            // Time line
            var tl = new TimelineLite();
            tl.set($table,{ left: 'auto' })
                .set($content,{ right: 'auto' })

                .to($subContent, .4,{ opacity: 0 })

                .to($table, .4,{ right: animateTo }, 'closeSubmenu')
                .to($content, .4,{ left: animateTo }, 'closeSubmenu')

                .call(callback);
        },

        switchSubmenuPageIn : function(dir, view, callback)
        {
            // Set html
            $content.html(view);

            // Properties
            var $subContent = $('#subContent');
            var $table = $content.children('.table');

            // Direction
            var animateTo = '50%';
            if(dir == 'left') animateTo = '-50%';

            // Time line
            var tl = new TimelineLite();
            tl.set($subContent,{  opacity: 0 })
                .set($table,{ right: 'auto', left: animateTo })
                .set($content,{ left: 'auto', right: animateTo })

                .to($content, .4,{ opacity: 1 })

                .to($table, .4,{ left: 0  }, 'openSubmenu')
                .to($content, .4,{ right: 0  }, 'openSubmenu')

                .to($subContent, .4,{ opacity: 1 })

                .call(function()
                {
                    allowed = true;
                    callback()
                });
        },


        /*
         | Practice and Service page
         | Only animate the text part, leave the submenu
         */

        animateOutWithFixedSubmenu : function(callback)
        {
            var $subContent = $('#subContent');
            tl.to($subContent, .5, {
                opacity: 0,
                onComplete: callback
            });
        },

        animateInWithFixedSubmenu : function(view, callback)
        {
            var $subContent = $('#subContent');
            $subContent.html(view);
            tl.to($subContent,.5,
                {
                    opacity: 1,
                    onComplete: callback
                });
        },

        /*
         | Helper functions
         */

        hasEqualParent : function(currentPageName, targetPageName)
        {
            return (
                $.inArray(currentPageName, services)!==-1 && $.inArray(targetPageName, services)!==-1 ||
                $.inArray(currentPageName, practice)!==-1 && $.inArray(targetPageName, practice)!==-1
            );
        },

        isSubPage : function(pageName)
        {
           return $.inArray(pageName, services)!==-1 || $.inArray(pageName, practice)!==-1
        },

        allowed : function()
        {
            return allowed;
        }
    }
});