Created
March 8, 2014 23:30
-
-
Save tenman/9440678 to your computer and use it in GitHub Desktop.
Go to Top and Menu Fixed functionality at Raindrops WordPress Theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Menu fixed | |
* | |
* | |
* | |
*/ | |
define('NOBITA_QUERY', 'nobita_fixed_menu' ); | |
define('NOBITA_VALUE_TYPE', 'js'); //or css | |
$nobita_external_link_value =<<<SCRIPT | |
jQuery(function() { | |
var topBtn = jQuery("#page-top"); | |
topBtn.hide(); | |
jQuery(window).scroll(function () { | |
if (jQuery(this).scrollTop() > 100) { | |
topBtn.fadeIn(); | |
jQuery('#access').css({'position':'fixed','top':'0','z-index':'999','margin':'0'}); | |
jQuery('.logged-in #access').css({'position':'fixed','top':'29px','z-index':'999','margin':'0'}); | |
} else { | |
topBtn.fadeOut(); | |
jQuery('#access').css({'position':'static'}); | |
jQuery('.logged-in #access').css({'position':'static'}); | |
} | |
}); | |
topBtn.click(function () { | |
jQuery("body,html").animate({ | |
scrollTop: 0}, 500); | |
return false; | |
}); | |
}); | |
SCRIPT; | |
add_action( 'after_setup_theme', 'nobita_setup_theme' ); | |
function nobita_setup_theme(){ | |
add_filter('query_vars','nobita_extend_query'); | |
add_action( 'wp_enqueue_scripts', 'nobita_add_style_link', 99 ); | |
add_action( 'template_redirect', 'nobita_external_link_value' ); | |
} | |
function nobita_extend_query( $vars ) { | |
$vars[] = NOBITA_QUERY; | |
return $vars; | |
} | |
function nobita_add_style_link() { | |
if( NOBITA_VALUE_TYPE == 'css' ){ | |
wp_register_style( 'nobita-extend-style', sprintf('/?%1$s=1', NOBITA_QUERY ) ); | |
wp_enqueue_style( 'nobita-extend-style' ); | |
} elseif ( NOBITA_VALUE_TYPE == 'js' ) { | |
wp_register_script( 'nobita-extend-script', sprintf('/?%1$s=1', NOBITA_QUERY ) ); | |
wp_enqueue_script( 'nobita-extend-script' ); | |
} | |
} | |
function nobita_external_link_value( ) { | |
global $nobita_external_link_value; | |
if( intval( get_query_var( NOBITA_QUERY ) ) == 1 ) { | |
$mime_type = wp_get_mime_types( NOBITA_VALUE_TYPE ); | |
if ( ! headers_sent( ) ) { | |
header( 'Content-type: '.$mime_type ); | |
} | |
// add value check | |
if( NOBITA_VALUE_TYPE == 'css' ){ | |
$nobita_external_link_value = strip_tags( $nobita_external_link_value ); | |
} elseif ( NOBITA_VALUE_TYPE == 'js' ) { | |
$nobita_external_link_value = strip_tags( $nobita_external_link_value ); | |
} | |
echo $nobita_external_link_value; | |
exit; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment