%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/shaban/laviva/wp-content/themes/levelup/assets/js/app/tools/
Upload File :
Create Path :
Current File : //var/www/html/shaban/laviva/wp-content/themes/levelup/assets/js/app/tools/navigation.class.js

(function() {
    "use strict";

    APP.TOOLS.Navigation = APP.CORE.Event_Emitter.extend({
        options: {},

        staticInstantiate: function () {
            if (APP.TOOLS.Navigation.prototype.instance === null)
                return null;
            else
                return APP.TOOLS.Navigation.prototype.instance;
        },

        init: function (options) {
            this._super(options);

            this.history = history.pushState ? window.history : false;
            this.state_id = 0;

            if (this.history) {
                //this.update_state( { _prevent_default_tag : 1, title : document.title, id : this.state_id } );
            }

            this.init_events();

            APP.TOOLS.Navigation.prototype.instance = this;
        },

        init_events: function () {
            if (!this.history)
                return;

            var that = this;

            window.onpopstate = function (e) {
                var result = Object.create(e.state);

                if (!result._prevent_default_tag)
                    return;

                if (result.title)
                    document.title = result.title;

                result.direction = result.id < that.state_id ? 'backward' : 'frontward';
                that.state_id = result.id;

                that.trigger('pop', [result, window.location.href,]);
            };
        },

        update_state: function (data, replace_state) {
            if (!this.history)
                return;

            data._prevent_default_tag = 1;

            if (replace_state || !this.history.state) {
                this.history.replaceState(data, document.title, window.location.href);

                try {
                    this.history.state = data;
                }
                catch (error) {
                    console.log('catch');
                }
            }

            else {
                for (var key in data) {
                    try {
                        this.history.state[key] = data[key];
                    }
                    catch (error) {
                        console.log('catch');
                    }
                }

                this.history.replaceState(this.history.state, document.title, window.location.href);
            }
        },

        push: function (state, url) {
            if (!this.history)
                return;

            if (state.title)
                document.title = state.title;

            state.id = ++this.state_id;

            state.tag = 'test';

            this.history.pushState(state, state.title, url);

            this.trigger('push', [state, url]);
        }
    });
})();

Zerion Mini Shell 1.0