From 49426a94d97aaf6bdfabaa4fdf5cd558974bb343 Mon Sep 17 00:00:00 2001 From: msdfgrant Date: Thu, 3 Jul 2014 14:39:00 -0500 Subject: [PATCH] Added feature to copy body CSS classes from the new page into the existing body element. --- ajaxify-html5.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/ajaxify-html5.js b/ajaxify-html5.js index c232db7..b70c321 100755 --- a/ajaxify-html5.js +++ b/ajaxify-html5.js @@ -68,8 +68,21 @@ // Return return $.trim(result); }; - - // Ajaxify Helper + + // Get body CSS classes + var getBodyClasses = function(html){ + // Prepare + var matches = html.match(//i); + + // Return + if ($.isArray(matches) && matches.length > 1) { + return $.trim(matches[1]); + } else { + return ''; + } + }; + + // Ajaxify Helper $.fn.ajaxify = function(){ // Prepare var $this = $(this); @@ -123,8 +136,9 @@ $data = $(documentHtml(data)), $dataBody = $data.find('.document-body:first'), $dataContent = $dataBody.find(contentSelector).filter(':first'), - $menuChildren, contentHtml, $scripts; - + $menuChildren, contentHtml, $scripts, + bodyClasses = getBodyClasses(data); + // Fetch the scripts $scripts = $dataContent.find('.document-script'); if ( $scripts.length ) { @@ -154,8 +168,14 @@ document.getElementsByTagName('title')[0].innerHTML = document.title.replace('<','<').replace('>','>').replace(' & ',' & '); } catch ( Exception ) { } - - // Add the scripts + + // Update the body CSS classes + try { + document.getElementsByTagName('body')[0].className = bodyClasses; + } + catch ( Exception ) { } + + // Add the scripts $scripts.each(function(){ var $script = $(this), scriptText = $script.text(), scriptNode = document.createElement('script'); if ( $script.attr('src') ) {