Update theme-jquery.js

This commit is contained in:
Braad
2015-03-19 15:20:37 -07:00
parent 26278516b6
commit 2d87079e05
+93 -93
View File
@@ -9,132 +9,132 @@
// Executes when the document is ready // Executes when the document is ready
jQuery( document ).ready( function( $ ) { jQuery( document ).ready( function( $ ) {
// Remove .no-jquery body class // Remove .no-jquery body class
$( 'body' ).removeClass( 'no-jquery' ); $( 'body' ).removeClass( 'no-jquery' );
// External Links // External Links
var h = window.location.host.toLowerCase(); var h = window.location.host.toLowerCase();
$( '[href^="http"]' ).not( '[href*="' + h + '"]' ).addClass( 'external-link' ).attr( "target", "_blank" ); $( '[href^="http"]' ).not( '[href*="' + h + '"]' ).addClass( 'external-link' ).attr( "target", "_blank" );
// Add classes to different types of links // Add classes to different types of links
$( 'a[href^="mailto:"]' ).addClass( 'email-link' ); $( 'a[href^="mailto:"]' ).addClass( 'email-link' );
$( 'a[href$=".pdf"]' ).attr({ "target":"_blank" }).addClass( 'pdf-link' ); $( 'a[href$=".pdf"]' ).attr({ "target":"_blank" }).addClass( 'pdf-link' );
$( 'a[href$=".doc"]' ).attr({ "target":"_blank" }).addClass( 'doc-link' ); $( 'a[href$=".doc"]' ).attr({ "target":"_blank" }).addClass( 'doc-link' );
$( 'a' ).has( 'img' ).addClass( 'image-link' ); $( 'a' ).has( 'img' ).addClass( 'image-link' );
// Add classes to parts of lists // Add classes to parts of lists
$( 'li:last-child' ).addClass( 'last' ); $( 'li:last-child' ).addClass( 'last' );
$( 'li:first-child' ).addClass( 'first' ); $( 'li:first-child' ).addClass( 'first' );
$( 'ul, ol' ).parent( 'li' ).addClass( 'parent' ); $( 'ul, ol' ).parent( 'li' ).addClass( 'parent' );
// Mobile header toggle buttons // Mobile header toggle buttons
$( '.site-header .title-area' ).after( '<div class="toggle-buttons" />' ); $( '.site-header .title-area' ).after( '<div class="toggle-buttons" />' );
$( '.site-header .widget-area, .nav-primary' ).each( function( i ) { $( '.site-header .widget-area, .nav-primary' ).each( function( i ) {
// Store target // Store target
$target = $( this ); $target = $( this );
// Scope variables // Scope variables
var $target, buttonClass, targetClass; var $target, buttonClass, targetClass;
// Setup classes // Setup classes
buttonClass = 'toggle-button'; buttonClass = 'toggle-button';
targetClass = $target.attr( 'class' ).split( /\s+/ ); targetClass = $target.attr( 'class' ).split( /\s+/ );
// Add targets-[] class to buttonClass // Add targets-[] class to buttonClass
$.each( targetClass, function( index, value ) { $.each( targetClass, function( index, value ) {
buttonClass += ' targets-' + value; buttonClass += ' targets-' + value;
}); });
// Add nav-toggle class to buttonClass if the button is for the nav // Add nav-toggle class to buttonClass if the button is for the nav
if ( $target.is( 'nav' ) ) { if ( $target.is( 'nav' ) ) {
buttonClass += ' nav-toggle'; buttonClass += ' nav-toggle';
} }
// Add toggle buttons to header // Add toggle buttons to header
$( '.toggle-buttons' ).prepend( '<a id="toggle-button-' + i + '" class="' + buttonClass + '" href="#">Toggle</a>' ); $( '.toggle-buttons' ).prepend( '<a id="toggle-button-' + i + '" class="' + buttonClass + '" href="#">Toggle</a>' );
// Add target class to nav and widget areas // Add target class to nav and widget areas
$target.addClass( 'toggle-target-' + i ); $target.addClass( 'toggle-target-' + i );
}); });
// Toggle widget areas and primary nav // Toggle widget areas and primary nav
$( '.site-header .toggle-button' ).click( function( event ) { $( '.site-header .toggle-button' ).click( function( event ) {
// Prevent default behavior // Prevent default behavior
event.preventDefault(); event.preventDefault();
// Scope our variables // Scope our variables
var $button, $target; var $button, $target;
// Get toggle button that was clicked // Get toggle button that was clicked
$button = $( this ); $button = $( this );
//Remove focus //Remove focus
$button.blur(); $button.blur();
// Match the button to the right target // Match the button to the right target
$target = $( '.toggle-target-' + $button.attr( 'id' ).match( /\d+/ ) ); $target = $( '.toggle-target-' + $button.attr( 'id' ).match( /\d+/ ) );
// Toggle buttons // Toggle buttons
$button.toggleClass( 'open' ); $button.toggleClass( 'open' );
$( '.site-header .toggle-button' ).not( $button ).removeClass( 'open' ); $( '.site-header .toggle-button' ).not( $button ).removeClass( 'open' );
// Toggle targets // Toggle targets
$target.toggleClass( 'open' ); $target.toggleClass( 'open' );
$( '[class^="toggle-target"]' ).not( $target ).removeClass( 'open' ); $( '[class^="toggle-target"]' ).not( $target ).removeClass( 'open' );
}); });
// Mobile navigation icons // Mobile navigation icons
var closedIcon = '+'; var closedIcon = '+';
var openIcon = '-'; var openIcon = '-';
// Insert the icons into the nav where appropriate // Insert the icons into the nav where appropriate
$( '.nav-primary' ).find( '.genesis-nav-menu .parent:not( .current-menu-item, .current_page_item, .current_page_parent, .current_page_ancestor) > a' ).after( '<a class="sub-icon" href="#">' + closedIcon + '</a>' ); $( '.nav-primary' ).find( '.genesis-nav-menu .parent:not( .current-menu-item, .current_page_item, .current_page_parent, .current_page_ancestor) > a' ).after( '<a class="sub-icon" href="#">' + closedIcon + '</a>' );
$( '.nav-primary' ).find( '.genesis-nav-menu .parent.current-menu-item > a, .genesis-nav-menu .parent.current_page_item > a, .genesis-nav-menu .parent.current_page_parent > a, .genesis-nav-menu .parent.current_page_ancestor > a' ).after( '<a class="sub-icon" href="#">' + openIcon + '</a>' ); $( '.nav-primary' ).find( '.genesis-nav-menu .parent.current-menu-item > a, .genesis-nav-menu .parent.current_page_item > a, .genesis-nav-menu .parent.current_page_parent > a, .genesis-nav-menu .parent.current_page_ancestor > a' ).after( '<a class="sub-icon" href="#">' + openIcon + '</a>' );
// Mobile navigation expand/contract functionality // Mobile navigation expand/contract functionality
$( '.sub-icon' ).click( function( event ) { $( '.sub-icon' ).click( function( event ) {
// Prevent default behavior // Prevent default behavior
event.preventDefault(); event.preventDefault();
// Get icon click // Get icon click
var $icon = $( this ); var $icon = $( this );
// Remove focus // Remove focus
$icon.blur(); $icon.blur();
// Expand/contract // Expand/contract
$icon.next( 'ul' ).slideToggle().toggleClass( 'open' ); $icon.next( 'ul' ).slideToggle().toggleClass( 'open' );
// Change the icon to indicate open/closed // Change the icon to indicate open/closed
if ( $icon.text().indexOf( closedIcon ) !== -1 ) { if ( $icon.text().indexOf( closedIcon ) !== -1 ) {
$icon.text( openIcon ); $icon.text( openIcon );
} else if ( $icon.text().indexOf( openIcon ) !== -1 ) { } else if ( $icon.text().indexOf( openIcon ) !== -1 ) {
$icon.text( closedIcon ); $icon.text( closedIcon );
} }
}); });
// Header widget area expand/contract functionality // Header widget area expand/contract functionality
$( '.widget-area-toggle' ).click( function( event ) { $( '.widget-area-toggle' ).click( function( event ) {
// Prevent default behavior // Prevent default behavior
event.preventDefault(); event.preventDefault();
// Get button clicked // Get button clicked
var $button = $( this ); var $button = $( this );
// Remove focus // Remove focus
$button.blur(); $button.blur();
// Expand/contract // Expand/contract
$button.toggleClass( 'open' ).next( '.widget-area' ).slideToggle(); $button.toggleClass( 'open' ).next( '.widget-area' ).slideToggle();
}); });
// Executes when complete page is fully loaded, including all frames, objects, and images // Executes when complete page is fully loaded, including all frames, objects, and images
$( window ).on( 'load', function() { $( window ).on( 'load', function() {
}); });
}); /* end of page load scripts */ }); /* end of page load scripts */