2014/05/15

Jquery Ajax loader


$(function () {
                if (window.location.hash){ contentload(window.location.hash);}

                $("body").on("click", "a", function(event){
                    fragment = this.hash; 
                    if(this.hostname == window.location.hostname )
                    {
                        if($(this).attr('data-toggle') != "dropdown" && $(this).attr('target') != "_blank")
                        {
                            var load_url = this.href.split('<?php echo $_SERVER['SERVER_NAME']?>');
                            contentload(load_url[1], true);
                        }
                        return false;
                    }
                });
                
                window.onpopstate = function(event) {
                        load_url = location.href;
                        contentload( load_url, false);
                        console.log("path: " + load_url);
                       
                };
                
        });
        function contentload(load_url, is_link) {
                $("#body-loader").show();
                
                $.ajax({
                    url      : load_url,  
                    success  : function(data) {
                        $('#container-wrapper').html(data);
                        $("#body-loader").hide();
                        if(is_link)
                        {
                            var full_url = '//<?php echo $_SERVER['SERVER_NAME']?>'+load_url;
                            history.pushState({}, 'New URL: ' + full_url, full_url);
                        }
                        load_start();
                    }                     
                });    
        }

No comments:

Post a Comment

Миний бичсэн бичлэг танд өчүүхэн ч болтугай хэрэг болсон бол сэтгэгдлээ бичиж үлдээхийг хүсье. Баярлалаа :)