Twenty Fourteen: JavaScript fixes after running jshint, see r25960:
* Enforce `===` instead of `==` * Fix confusing use of `!` * Remove unused variables like `calcNext`, defined but never used * Proper use of braces * Move functions out of if/else statements * Document unknown functions as Microsoft-specific Built from https://develop.svn.wordpress.org/trunk@25995 git-svn-id: http://core.svn.wordpress.org/trunk@25928 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6e15f77e5a
commit
9d0e238255
|
@ -5,12 +5,14 @@
|
|||
// Enable menu toggle for small screens.
|
||||
( function() {
|
||||
var nav = $( '#primary-navigation' ), button, menu;
|
||||
if ( ! nav )
|
||||
if ( ! nav ) {
|
||||
return;
|
||||
}
|
||||
|
||||
button = nav.find( '.menu-toggle' );
|
||||
if ( ! button )
|
||||
if ( ! button ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide button if menu is missing or empty.
|
||||
menu = nav.find( '.nav-menu' );
|
||||
|
@ -34,11 +36,12 @@
|
|||
var element = document.getElementById( location.hash.substring( 1 ) );
|
||||
|
||||
if ( element ) {
|
||||
if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) )
|
||||
if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
|
||||
element.tabIndex = -1;
|
||||
}
|
||||
|
||||
element.focus();
|
||||
};
|
||||
}
|
||||
} );
|
||||
|
||||
$( function() {
|
||||
|
@ -50,8 +53,9 @@
|
|||
that.toggleClass( 'active' );
|
||||
wrapper.toggleClass( 'hide' );
|
||||
|
||||
if ( that.is( '.active' ) )
|
||||
if ( that.is( '.active' ) ) {
|
||||
wrapper.find( '.search-field' ).focus();
|
||||
}
|
||||
} );
|
||||
|
||||
/*
|
||||
|
@ -65,10 +69,11 @@
|
|||
mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
|
||||
|
||||
_window.on( 'scroll.twentyfourteen', function() {
|
||||
if ( window.scrollY > mastheadOffset )
|
||||
if ( window.scrollY > mastheadOffset ) {
|
||||
body.addClass( 'masthead-fixed' );
|
||||
else
|
||||
} else {
|
||||
body.removeClass( 'masthead-fixed' );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
@ -89,7 +94,7 @@
|
|||
isResizable: true,
|
||||
isRTL: $( 'body' ).is( '.rtl' )
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
||||
// Initialize Featured Content slider.
|
||||
_window.load( function() {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
jQuery( document ).ready( function( $ ) {
|
||||
$( document ).keydown( function( e ) {
|
||||
var url = false;
|
||||
if ( e.which == 37 ) { // Left arrow key code
|
||||
if ( e.which === 37 ) { // Left arrow key code
|
||||
url = $( '.previous-image a' ).attr( 'href' );
|
||||
}
|
||||
else if ( e.which == 39 ) { // Right arrow key code
|
||||
else if ( e.which === 39 ) { // Right arrow key code
|
||||
url = $( '.entry-attachment a' ).attr( 'href' );
|
||||
}
|
||||
if ( url && ( !$( 'textarea, input' ).is( ':focus' ) ) ) {
|
||||
|
|
|
@ -15,12 +15,11 @@
|
|||
|
||||
var namespace = slider.vars.namespace,
|
||||
msGesture = window.navigator && window.navigator.msPointerEnabled && window.MSGesture,
|
||||
touch = ( ( 'ontouchstart' in window ) || msGesture || window.DocumentTouch && document instanceof DocumentTouch ),
|
||||
touch = ( ( 'ontouchstart' in window ) || msGesture || window.DocumentTouch && document instanceof DocumentTouch ), // MSFT specific.
|
||||
eventType = 'click touchend MSPointerUp',
|
||||
watchedEvent = '',
|
||||
watchedEventClearTimer,
|
||||
methods = {},
|
||||
focused = true;
|
||||
methods = {};
|
||||
|
||||
// Store a reference to the slider object.
|
||||
$.data( el, 'featuredslider', slider );
|
||||
|
@ -52,8 +51,9 @@
|
|||
return false;
|
||||
}() );
|
||||
// CONTROLSCONTAINER
|
||||
if ( slider.vars.controlsContainer !== '' )
|
||||
if ( slider.vars.controlsContainer !== '' ) {
|
||||
slider.controlsContainer = $( slider.vars.controlsContainer ).length > 0 && $( slider.vars.controlsContainer );
|
||||
}
|
||||
|
||||
slider.doMath();
|
||||
|
||||
|
@ -78,8 +78,9 @@
|
|||
}
|
||||
|
||||
// TOUCH
|
||||
if ( touch )
|
||||
if ( touch ) {
|
||||
methods.touch();
|
||||
}
|
||||
|
||||
$( window ).bind( 'resize orientationchange focus', methods.resize );
|
||||
|
||||
|
@ -127,8 +128,9 @@
|
|||
}
|
||||
|
||||
// Set up flags to prevent event duplication.
|
||||
if ( watchedEvent === '' )
|
||||
if ( watchedEvent === '' ) {
|
||||
watchedEvent = event.type;
|
||||
}
|
||||
|
||||
methods.setToClearWatchedEvent();
|
||||
} );
|
||||
|
@ -178,8 +180,9 @@
|
|||
}
|
||||
|
||||
// Set up flags to prevent event duplication.
|
||||
if ( watchedEvent === '' )
|
||||
if ( watchedEvent === '' ) {
|
||||
watchedEvent = event.type;
|
||||
}
|
||||
|
||||
methods.setToClearWatchedEvent();
|
||||
} );
|
||||
|
@ -208,6 +211,15 @@
|
|||
|
||||
if ( ! msGesture ) {
|
||||
el.addEventListener( 'touchstart', onTouchStart, false );
|
||||
} else {
|
||||
el.style.msTouchAction = 'none';
|
||||
el._gesture = new MSGesture(); // MSFT specific.
|
||||
el._gesture.target = el;
|
||||
el.addEventListener( 'MSPointerDown', onMSPointerDown, false );
|
||||
el._slider = slider;
|
||||
el.addEventListener( 'MSGestureChange', onMSGestureChange, false );
|
||||
el.addEventListener( 'MSGestureEnd', onMSGestureEnd, false );
|
||||
}
|
||||
|
||||
function onTouchStart( e ) {
|
||||
if ( slider.animating ) {
|
||||
|
@ -248,11 +260,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
function onTouchEnd( e ) {
|
||||
function onTouchEnd() {
|
||||
// Finish the touch by undoing the touch session.
|
||||
el.removeEventListener( 'touchmove', onTouchMove, false );
|
||||
|
||||
if ( slider.animatingTo === slider.currentSlide && ! scrolling && ! ( dx === null ) ) {
|
||||
if ( slider.animatingTo === slider.currentSlide && ! scrolling && dx !== null ) {
|
||||
var updateDx = dx,
|
||||
target = ( updateDx > 0 ) ? slider.getTarget( 'next' ) : slider.getTarget( 'prev' );
|
||||
|
||||
|
@ -265,14 +277,6 @@
|
|||
dx = null;
|
||||
offset = null;
|
||||
}
|
||||
} else {
|
||||
el.style.msTouchAction = 'none';
|
||||
el._gesture = new MSGesture();
|
||||
el._gesture.target = el;
|
||||
el.addEventListener( 'MSPointerDown', onMSPointerDown, false );
|
||||
el._slider = slider;
|
||||
el.addEventListener( 'MSGestureChange', onMSGestureChange, false );
|
||||
el.addEventListener( 'MSGestureEnd', onMSGestureEnd, false );
|
||||
|
||||
function onMSPointerDown( e ) {
|
||||
e.stopPropagation();
|
||||
|
@ -290,8 +294,9 @@
|
|||
function onMSGestureChange( e ) {
|
||||
e.stopPropagation();
|
||||
var slider = e.target._slider;
|
||||
if ( ! slider )
|
||||
if ( ! slider ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var transX = -e.translationX,
|
||||
transY = -e.translationY;
|
||||
|
@ -302,7 +307,7 @@
|
|||
scrolling = Math.abs( accDx ) < Math.abs( -transY );
|
||||
|
||||
if ( e.detail === e.MSGESTURE_FLAG_INERTIA ) {
|
||||
setImmediate( function () {
|
||||
setImmediate( function () { // MSFT specific.
|
||||
el._gesture.stop();
|
||||
} );
|
||||
|
||||
|
@ -320,10 +325,11 @@
|
|||
function onMSGestureEnd( e ) {
|
||||
e.stopPropagation();
|
||||
var slider = e.target._slider;
|
||||
if ( ! slider )
|
||||
if ( ! slider ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( slider.animatingTo === slider.currentSlide && ! scrolling && ! ( dx === null ) ) {
|
||||
if ( slider.animatingTo === slider.currentSlide && ! scrolling && dx !== null ) {
|
||||
var updateDx = dx,
|
||||
target = ( updateDx > 0 ) ? slider.getTarget( 'next' ) : slider.getTarget( 'prev' );
|
||||
|
||||
|
@ -336,7 +342,6 @@
|
|||
offset = null;
|
||||
accDx = 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
resize: function() {
|
||||
|
@ -365,8 +370,9 @@
|
|||
|
||||
// Public methods.
|
||||
slider.featureAnimate = function( target ) {
|
||||
if ( target !== slider.currentSlide )
|
||||
if ( target !== slider.currentSlide ) {
|
||||
slider.direction = ( target > slider.currentSlide ) ? 'next' : 'prev';
|
||||
}
|
||||
|
||||
if ( ! slider.animating && slider.is( ':visible' ) ) {
|
||||
slider.animating = true;
|
||||
|
@ -383,7 +389,7 @@
|
|||
methods.directionNav.update();
|
||||
|
||||
var dimension = slider.computedW,
|
||||
margin, slideString, calcNext;
|
||||
slideString;
|
||||
|
||||
if ( slider.currentSlide === 0 && target === slider.count - 1 && slider.direction !== 'next' ) {
|
||||
slideString = 0;
|
||||
|
@ -455,12 +461,13 @@
|
|||
}
|
||||
|
||||
slider.args[slider.prop] = target;
|
||||
if ( slider.transitions || dur === undefined )
|
||||
if ( slider.transitions || dur === undefined ) {
|
||||
slider.container.css( slider.args );
|
||||
}
|
||||
};
|
||||
|
||||
slider.setup = function( type ) {
|
||||
var sliderOffset, arr;
|
||||
var sliderOffset;
|
||||
|
||||
if ( type === 'init' ) {
|
||||
slider.viewport = $( '<div class="' + namespace + 'viewport"></div>' ).css( { 'overflow': 'hidden', 'position': 'relative' } ).appendTo( slider ).append( slider.container );
|
||||
|
@ -470,8 +477,9 @@
|
|||
slider.cloneCount = 2;
|
||||
slider.cloneOffset = 1;
|
||||
// Clear out old clones.
|
||||
if ( type !== 'init' )
|
||||
if ( type !== 'init' ) {
|
||||
slider.container.find( '.clone' ).remove();
|
||||
}
|
||||
|
||||
slider.container.append( slider.slides.first().clone().addClass( 'clone' ).attr( 'aria-hidden', 'true' ) ).prepend( slider.slides.last().clone().addClass( 'clone' ).attr( 'aria-hidden', 'true' ) );
|
||||
slider.newSlides = $( slider.vars.selector, slider );
|
||||
|
@ -531,13 +539,6 @@
|
|||
methods.init();
|
||||
};
|
||||
|
||||
// Ensure the slider isn't focused if the window loses focus.
|
||||
$( window ).blur( function ( e ) {
|
||||
focused = false;
|
||||
} ).focus( function ( e ) {
|
||||
focused = true;
|
||||
} );
|
||||
|
||||
// Default settings.
|
||||
$.featuredslider.defaults = {
|
||||
namespace: 'slider-', // String: prefix string attached to the class of every element generated by the plugin.
|
||||
|
@ -552,8 +553,9 @@
|
|||
|
||||
// FeaturedSlider: plugin function.
|
||||
$.fn.featuredslider = function( options ) {
|
||||
if ( options === undefined )
|
||||
if ( options === undefined ) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if ( typeof options === 'object' ) {
|
||||
return this.each( function() {
|
||||
|
|
Loading…
Reference in New Issue