Advertisement
Guest User

aws js code

a guest
Dec 7th, 2014
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Version 1.5.4
  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.             contentSelector = '#' + aws_data['container_id'],
  20.             $content = $(contentSelector),
  21.             contentNode = $content.get(0),
  22.             // Application Generic Variables
  23.             $body = $(document.body),
  24.             scrollOptions = {
  25.                 duration: 800,
  26.                 easing:'swing'
  27.             };
  28.  
  29.         // Ensure Content
  30.         if ( $content.length === 0 ) $content = $body;
  31.  
  32.         // Internal Helper
  33.         $.expr[':'].internal = function(obj, index, meta, stack){
  34.             // Prepare
  35.             var
  36.                 $this = $(obj),
  37.                 url = $this.attr('href')||'',
  38.                 isInternalLink;
  39.  
  40.             // Check link
  41.             isInternalLink = url.substring(0,rootUrl.length) === rootUrl || url.indexOf(':') === -1;
  42.  
  43.             // Ignore or Keep
  44.             return isInternalLink;
  45.         };
  46.  
  47.         // HTML Helper
  48.         var documentHtml = function(html){
  49.             // Prepare
  50.             var result = String(html).replace(/<\!DOCTYPE[^>]*>/i, '')
  51.                                      .replace(/<(html|head|body|title|script)([\s\>])/gi,'<div id="document-$1"$2')
  52.                                      .replace(/<\/(html|head|body|title|script)\>/gi,'</div>');
  53.             // Return
  54.             return result;
  55.         };
  56.  
  57.         // Ajaxify Helper
  58.         $.fn.ajaxify = function(){
  59.             // Prepare
  60.             var $this = $(this);
  61.  
  62.             // Ajaxify
  63.             $this.find('a:internal:not(.no-ajaxy,[href^="#"],[href*="wp-login"],[href*="wp-admin"])').on('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.             return $this;
  80.         };
  81.  
  82.         // Ajaxify our Internal Links
  83.         $body.ajaxify();
  84.  
  85.         // Hook into State Changes
  86.         $(window).bind('statechange',function(){
  87.             // Prepare Variables
  88.             var
  89.             State       = History.getState(),
  90.             url         = State.url,
  91.             relativeUrl = url.replace(rootUrl,'');
  92.  
  93.             // Set Loading
  94.             $body.addClass('loading');
  95.            
  96.             // Start Fade Out
  97.             // Animating to opacity to 0 still keeps the element's height intact
  98.             // Which prevents that annoying pop bang issue when loading in new content
  99.            
  100.             if ( '' != aws_data['transition'] ) {
  101.             $content.animate({opacity:0.6},900);
  102. //$content.addClass("slideLeft");
  103.             }
  104.             if( '' != aws_data['loader'] ) {
  105.                 $content
  106.                         .html('<img src="' + rootUrl + 'wp-content/plugins/ajaxify-wordpress-site/images/' + aws_data['loader'] + '" />')
  107.                         .css('text-align', 'center');
  108.             }
  109.  
  110.             // Ajax Request the Traditional Page
  111.             $.ajax({
  112.                 url: url,
  113.                 success: function(data, textStatus, jqXHR){
  114.                     // Prepare
  115.                     var
  116.                         $data           = $(documentHtml(data)),
  117.                         $dataBody       = $data.find('#document-body:first ' + contentSelector),
  118.                         bodyClasses     = $data.find('#document-body:first').attr('class'),
  119.                         contentHtml, $scripts;
  120.                    
  121.                     var $menu_list = $data.find('.' + aws_data['mcdc']);
  122.                    
  123.                     //Add classes to body
  124.                     jQuery('body').attr('class', bodyClasses);
  125.                    
  126.                     // Fetch the scripts
  127.                     $scripts = $dataBody.find('#document-script');
  128.                     if ( $scripts.length ) $scripts.detach();
  129.  
  130.                     // Fetch the content
  131.                     contentHtml = $dataBody.html()||$data.html();
  132.  
  133.                     if ( !contentHtml ) {
  134.                         document.location.href = url;
  135.                         return false;
  136.                     }
  137.  
  138.                     // Update the content
  139.                     $content.stop(true,true);
  140.                     $content.html(contentHtml)
  141.                             .ajaxify()
  142.                             .css('text-align', '')
  143.                             .animate({opacity: 1, visibility: "visible"});
  144.                    
  145.                     //Scroll to the top of ajax container
  146.                     if ( '' != aws_data['scrollTop'] ) {
  147.                         jQuery('html, body').animate({
  148.                                     scrollTop: jQuery(contentSelector).offset().top
  149.                                     }, 1000);
  150.                     }
  151.                    
  152.                     //Append new menu HTML to provided classs
  153.                     $('.' + aws_data['mcdc']).html($menu_list.html());
  154.                    
  155.                     //Adding no-ajaxy class to a tags present under ids provided
  156.                     $(aws_data['ids']).each(function(){
  157.                         jQuery(this).addClass('no-ajaxy');
  158.                     });
  159.                    
  160.                     // Update the title
  161.                     document.title = $data.find('#document-title:first').text();
  162.                     try {
  163.                         document.getElementsByTagName('title')[0].innerHTML = document.title.replace('<','&lt;')
  164.                                                                                             .replace('>','&gt;')
  165.                                                                                             .replace(' & ',' &amp; ');
  166.                     }
  167.                     catch ( Exception ) { }
  168.  
  169.                     // Add the scripts
  170.                     $scripts.each(function(){
  171.                         var scriptText = $(this).html();
  172.                            
  173.                         if ( '' != scriptText ) {
  174.                             scriptNode = document.createElement('script');
  175.                             scriptNode.appendChild(document.createTextNode(scriptText));
  176.                             contentNode.appendChild(scriptNode);
  177.                         } else {
  178.                             $.getScript( $(this).attr('src') );
  179.                         }
  180.                     });
  181.                    
  182.                     // BuddyPress Support
  183.                     if ( aws_data['bp_status'] ) {
  184.                         $.getScript(rootUrl + '/wp-content/plugins/buddypress/bp-templates/bp-legacy/js/buddypress.js');
  185.                     }
  186.                    
  187.                     $body.removeClass('loading');
  188.                     //$("#gbsright").addClass('slideLeft');
  189.  
  190.                     // Inform Google Analytics of the change
  191.                     if ( typeof window.pageTracker !== 'undefined' ) window.pageTracker._trackPageview(relativeUrl);
  192.  
  193.                     // Inform ReInvigorate of a state change
  194.                     if ( typeof window.reinvigorate !== 'undefined' && typeof window.reinvigorate.ajax_track !== 'undefined' )
  195.                         reinvigorate.ajax_track(url);// ^ we use the full url here as that is what reinvigorate supports
  196.                 },
  197.                 error: function(jqXHR, textStatus, errorThrown){
  198.                     document.location.href = url;
  199.                     return false;
  200.                 }
  201.  
  202.             }); // end ajax
  203.  
  204.         }); // end onStateChange
  205.  
  206.     }); // end onDomLoad
  207.  
  208. })(window); // end closure
  209.  
  210. jQuery(document).ready(function(){
  211.    
  212.     //Adding no-ajaxy class to a tags present under ids provided
  213.     jQuery(aws_data['ids']).each(function(){
  214.         jQuery(this).addClass('no-ajaxy');
  215.     });
  216.    
  217.     //append anchor tag to DOM to make the search in site ajaxify.
  218.     var searchButtonHtml = '<span id="ajax-search" style="display:none;"><a href=""></a></span>'
  219.     jQuery("body").prepend(searchButtonHtml);
  220.    
  221.     //Make the link ajaxify.
  222.     jQuery("#ajax-search").ajaxify();
  223.    
  224.     //After submitting the search form search the post without refreshing the browser.
  225.     jQuery(aws_data['searchID']).on('submit',
  226.         function(d){
  227.             d.preventDefault();
  228.             var host = aws_data['rootUrl'] + "?s=";
  229.             jQuery("#ajax-search a").attr("href", host + jQuery(this).find('input[type="search"]').val());
  230.             jQuery("#ajax-search a").trigger("click");
  231.         }
  232.     );
  233. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement