Advertisement
wpdreams

Untitled

Jun 19th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Version 1.5.2
  2. (function(window,undefined){
  3.  
  4.     // Prepare our Variables
  5.     var
  6.         History = window.History,
  7.         $ = window.jQuery,
  8.         document = window.document;
  9.  
  10.     // Check to see if History.js is enabled for our Browser
  11.   if ( !History.enabled ) return false;
  12.  
  13.     // Wait for Document
  14.   $(function(){
  15.         // Prepare Variables
  16.         var
  17.             // Application Specific Variables
  18.             rootUrl = aws_data['rootUrl'],
  19.             ThemeDir = aws_data['ThemeDir'],
  20.             contentSelector = '#ajaxwrap',
  21.             $content = $(contentSelector),
  22.             contentNode = $content.get(0),
  23.             // Application Generic Variables
  24.             $body = $(document.body),
  25.             scrollOptions = {
  26.                 duration: 800,
  27.                 easing:'swing'
  28.             };
  29.  
  30.     // Ensure Content
  31.         if ( $content.length === 0 ) $content = $body;
  32.  
  33.         // Internal Helper
  34.         $.expr[':'].internal = function(obj, index, meta, stack){
  35.             // Prepare
  36.             var
  37.                 $this = $(obj),
  38.                 url = $this.attr('href')||'',
  39.                 isInternalLink;
  40.  
  41.             // Check link
  42.             isInternalLink = url.substring(0,rootUrl.length) === rootUrl || url.indexOf(':') === -1;
  43.  
  44.             // Ignore or Keep
  45.             return isInternalLink;
  46.         };
  47.  
  48.  
  49.     // HTML Helper
  50.         var documentHtml = function(html){
  51.             // Prepare
  52.             var result = String(html).replace(/<\!DOCTYPE[^>]*>/i, '')
  53.                                      .replace(/<(html|head|body|title|script)([\s\>])/gi,'<div id="document-$1"$2')
  54.                                      .replace(/<\/(html|head|body|title|script)\>/gi,'</div>');
  55.             // Return
  56.             return result;
  57.         };
  58.  
  59.     $.fn.ajaxify1 = function(){
  60.             // Prepare
  61.             var $this = $(this);
  62.      
  63.             $this.find('a:internal:not(.no-ajaxy,[href^="#"],[href*="wp-login"],[href*="wp-admin"],[data-rel^="prettyPhoto"])').live('click', function(event){
  64.             // Prepare
  65.           var
  66.                     $this   = $(this),
  67.                     url     = $this.attr('href'),
  68.                     title   = $this.attr('title') || null;
  69.  
  70.                 // Continue as normal for cmd clicks etc
  71.                 if ( event.which == 2 || event.metaKey ) return true;
  72.  
  73.                 // Ajaxify this link
  74.                 History.pushState(null,title,url);
  75.                 event.preventDefault();
  76.                 return false;
  77.             });
  78.             // Chain
  79.  
  80.             // Ajaxify
  81.             jQuery('.resdrg').on('click', 'span.overlap',function(event){
  82.             // Prepare
  83.           var
  84.                     $this   = $(this).parent(),
  85.                     url     = $this.attr('href'),
  86.                     title   = $this.attr('title') || null;
  87.  
  88.                 // Continue as normal for cmd clicks etc
  89.                 if ( event.which == 2 || event.metaKey ) return true;
  90.  
  91.                 // Ajaxify this link
  92.                 History.pushState(null,title,url);
  93.        
  94.                 event.preventDefault();
  95.                 return false;
  96.             });
  97.             // Chain
  98.             return $this;
  99.         };
  100.  
  101.  
  102.     // Ajaxify our Internal Links
  103.         $body.ajaxify1();
  104.  
  105.         // Hook into State Changes
  106.         $(window).bind('statechange',function(){
  107.             // Prepare Variables
  108.             var
  109.             State       = History.getState(),
  110.             url         = State.url,
  111.             relativeUrl = url.replace(ThemeDir,'');
  112.  
  113.             // Set Loading
  114.             $body.addClass('loading');
  115.    
  116.  
  117.         // Start Fade Out
  118.             // Animating to opacity to 0 still keeps the element's height intact
  119.             // Which prevents that annoying pop bang issue when loading in new content
  120.             $content.animate({opacity:0},6000);
  121.  
  122.          $content
  123.             .html('<img src="'+ ThemeDir +'images/ajax-loader-blue-square.gif" />')  
  124.             .css('text-align', 'center');
  125.          
  126.          // Ajax Request the Traditional Page
  127.          $.ajax({
  128.            url: url,
  129.                 success: function(data, textStatus, jqXHR){
  130.                     // Prepare
  131.                     var
  132.                         $data           = $(documentHtml(data)),
  133.                         $dataBody       = $data.find('#document-body:first ' + contentSelector),
  134.                         bodyClasses     = $data.find('#document-body:first').attr('class'),
  135.                         contentHtml, $scripts;
  136.                    
  137.                     var $menu_list = $data.find('.menuwrap');
  138.                
  139.  
  140.             //Add classes to body
  141.                     jQuery('body').attr('class', bodyClasses);
  142.                    
  143.                     // Fetch the scripts
  144.                     $scripts = $dataBody.find('#document-script');
  145.                     if ( $scripts.length ) $scripts.detach();
  146.  
  147.                     // Fetch the content
  148.                     contentHtml = $dataBody.html()||$data.html();
  149.  
  150.                     if ( !contentHtml ) {
  151.                         document.location.href = url;
  152.                         return false;
  153.                     }
  154.  
  155.                     // Update the content
  156.                     $content.stop(true,true);
  157.                     $content.html(contentHtml)
  158.                             .ajaxify()
  159.                             .css('text-align', '')
  160.                             .animate({opacity: 1, visibility: "visible"});
  161.                
  162.                         // Load Custom Script
  163.                     atpcustom.atpinit();
  164.                     atpcustom.systoggle();
  165.                     atpcustom.buttondata();
  166.                     atpcustom.flexslider();
  167.                     atpcustom.accordion();
  168.                     atpcustom.progressbar();
  169.                     atpcustom.tabs();
  170.                     atpcustom.hoverimage();
  171.                     atpcustom.mobilemenu();
  172.                            
  173.                     $('.menuwrap').html($menu_list.html());
  174.                //Adding no-ajaxy class to a tags present under ids provided
  175.                     $(aws_data['ids']).each(function(){
  176.                         jQuery(this).addClass('no-ajaxy');
  177.                     });
  178.                    
  179.                     // Update the title
  180.                     document.title = $data.find('#document-title:first').text();
  181.                     try {
  182.                         document.getElementsByTagName('title')[0].innerHTML = document.title.replace('<','&lt;').replace('>','&gt;').replace(' & ',' &amp; ');
  183.                     }
  184.                     catch ( Exception ) { }
  185.  
  186.                     // Add the scripts
  187.                     $scripts.each(function(){
  188.                         var $script = $(this),
  189.                             scriptText = $script.html(),
  190.                             scriptNode = document.createElement('script');
  191.                         try {
  192.                             // doesn't work on ie...
  193.                             scriptNode.appendChild(document.createTextNode(scriptText));
  194.                             contentNode.appendChild(scriptNode);
  195.                         } catch(e) {
  196.                             // IE has funky script nodes
  197.                             scriptNode.text = scriptText;
  198.                             contentNode.appendChild(scriptNode);
  199.                         }
  200.                         if($(this).attr('src') != null) {
  201.                             scriptNode.setAttribute('src', ($(this).attr('src')));
  202.                         }
  203.                     });
  204.                                        
  205.                     $body.removeClass('loading');
  206.                     scriptNode = document.createElement('script');
  207.                     contentNode.appendChild(scriptNode);
  208.                     scriptNode.setAttribute('src', rootUrl + 'wp-content/plugins/contact-form-7/includes/js/scripts.js');
  209.                     // Inform Google Analytics of the change
  210.                     if ( typeof window.pageTracker !== 'undefined' ) window.pageTracker._trackPageview(relativeUrl);
  211.  
  212.                     // Inform ReInvigorate of a state change
  213.                     if ( typeof window.reinvigorate !== 'undefined' && typeof window.reinvigorate.ajax_track !== 'undefined' )
  214.                         reinvigorate.ajax_track(url);// ^ we use the full url here as that is what reinvigorate supports
  215.                 },
  216.                 error: function(jqXHR, textStatus, errorThrown){
  217.                     document.location.href = url;
  218.                     return false;
  219.                 }
  220.  
  221.             }); // end ajax
  222.  
  223.         }); // end onStateChange
  224.    
  225.     }); // end onDomLoad
  226.  
  227. })(window); // end closure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement