mirror of
https://github.com/KevinMidboe/rohnenedre.git
synced 2026-01-09 19:05:48 +00:00
Initial commit. State 04.2021.
This commit is contained in:
38
wp-content/themes/twentyfourteen/js/customizer.js
Normal file
38
wp-content/themes/twentyfourteen/js/customizer.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Twenty Fourteen Customizer enhancements for a better user experience.
|
||||
*
|
||||
* Contains handlers to make Customizer preview reload changes asynchronously.
|
||||
*/
|
||||
( function( $ ) {
|
||||
// Site title and description.
|
||||
wp.customize( 'blogname', function( value ) {
|
||||
value.bind( function( to ) {
|
||||
$( '.site-title a' ).text( to );
|
||||
} );
|
||||
} );
|
||||
wp.customize( 'blogdescription', function( value ) {
|
||||
value.bind( function( to ) {
|
||||
$( '.site-description' ).text( to );
|
||||
} );
|
||||
} );
|
||||
// Header text color.
|
||||
wp.customize( 'header_textcolor', function( value ) {
|
||||
value.bind( function( to ) {
|
||||
if ( 'blank' === to ) {
|
||||
$( '.site-title, .site-description' ).css( {
|
||||
'clip': 'rect(1px, 1px, 1px, 1px)',
|
||||
'position': 'absolute'
|
||||
} );
|
||||
} else {
|
||||
$( '.site-title, .site-description' ).css( {
|
||||
'clip': 'auto',
|
||||
'position': 'static'
|
||||
} );
|
||||
|
||||
$( '.site-title a' ).css( {
|
||||
'color': to
|
||||
} );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} )( jQuery );
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Twenty Fourteen Featured Content admin behavior: add a tag suggestion
|
||||
* when changing the tag.
|
||||
*/
|
||||
/* global ajaxurl:true */
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
$( '#customize-control-featured-content-tag-name input' ).suggest( ajaxurl + '?action=ajax-tag-search&tax=post_tag', { delay: 500, minchars: 2 } );
|
||||
});
|
||||
170
wp-content/themes/twentyfourteen/js/functions.js
Normal file
170
wp-content/themes/twentyfourteen/js/functions.js
Normal file
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* Theme functions file
|
||||
*
|
||||
* Contains handlers for navigation, accessibility, header sizing
|
||||
* footer widgets and Featured Content slider
|
||||
*
|
||||
*/
|
||||
( function( $ ) {
|
||||
var body = $( 'body' ),
|
||||
_window = $( window ),
|
||||
nav, button, menu;
|
||||
|
||||
nav = $( '#primary-navigation' );
|
||||
button = nav.find( '.menu-toggle' );
|
||||
menu = nav.find( '.nav-menu' );
|
||||
|
||||
// Enable menu toggle for small screens.
|
||||
( function() {
|
||||
if ( ! nav || ! button ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide button if menu is missing or empty.
|
||||
if ( ! menu || ! menu.children().length ) {
|
||||
button.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
button.on( 'click.twentyfourteen', function() {
|
||||
nav.toggleClass( 'toggled-on' );
|
||||
if ( nav.hasClass( 'toggled-on' ) ) {
|
||||
$( this ).attr( 'aria-expanded', 'true' );
|
||||
menu.attr( 'aria-expanded', 'true' );
|
||||
} else {
|
||||
$( this ).attr( 'aria-expanded', 'false' );
|
||||
menu.attr( 'aria-expanded', 'false' );
|
||||
}
|
||||
} );
|
||||
} )();
|
||||
|
||||
/*
|
||||
* Makes "skip to content" link work correctly in IE9 and Chrome for better
|
||||
* accessibility.
|
||||
*
|
||||
* @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
|
||||
*/
|
||||
_window.on( 'hashchange.twentyfourteen', function() {
|
||||
var hash = location.hash.substring( 1 ), element;
|
||||
|
||||
if ( ! hash ) {
|
||||
return;
|
||||
}
|
||||
|
||||
element = document.getElementById( hash );
|
||||
|
||||
if ( element ) {
|
||||
if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
|
||||
element.tabIndex = -1;
|
||||
}
|
||||
|
||||
element.focus();
|
||||
|
||||
// Repositions the window on jump-to-anchor to account for header height.
|
||||
window.scrollBy( 0, -80 );
|
||||
}
|
||||
} );
|
||||
|
||||
$( function() {
|
||||
// Search toggle.
|
||||
$( '.search-toggle' ).on( 'click.twentyfourteen', function( event ) {
|
||||
var that = $( this ),
|
||||
wrapper = $( '#search-container' ),
|
||||
container = that.find( 'a' );
|
||||
|
||||
that.toggleClass( 'active' );
|
||||
wrapper.toggleClass( 'hide' );
|
||||
|
||||
if ( that.hasClass( 'active' ) ) {
|
||||
container.attr( 'aria-expanded', 'true' );
|
||||
} else {
|
||||
container.attr( 'aria-expanded', 'false' );
|
||||
}
|
||||
|
||||
if ( that.is( '.active' ) || $( '.search-toggle .screen-reader-text' )[0] === event.target ) {
|
||||
wrapper.find( '.search-field' ).focus();
|
||||
}
|
||||
} );
|
||||
|
||||
/*
|
||||
* Fixed header for large screen.
|
||||
* If the header becomes more than 48px tall, unfix the header.
|
||||
*
|
||||
* The callback on the scroll event is only added if there is a header
|
||||
* image and we are not on mobile.
|
||||
*/
|
||||
if ( _window.width() > 781 ) {
|
||||
var mastheadHeight = $( '#masthead' ).height(),
|
||||
toolbarOffset, mastheadOffset;
|
||||
|
||||
if ( mastheadHeight > 48 ) {
|
||||
body.removeClass( 'masthead-fixed' );
|
||||
}
|
||||
|
||||
if ( body.is( '.header-image' ) ) {
|
||||
toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
|
||||
mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
|
||||
|
||||
_window.on( 'scroll.twentyfourteen', function() {
|
||||
if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) {
|
||||
body.addClass( 'masthead-fixed' );
|
||||
} else {
|
||||
body.removeClass( 'masthead-fixed' );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
// Focus styles for menus.
|
||||
$( '.primary-navigation, .secondary-navigation' ).find( 'a' ).on( 'focus.twentyfourteen blur.twentyfourteen', function() {
|
||||
$( this ).parents().toggleClass( 'focus' );
|
||||
} );
|
||||
} );
|
||||
|
||||
/**
|
||||
* @summary Add or remove ARIA attributes.
|
||||
* Uses jQuery's width() function to determine the size of the window and add
|
||||
* the default ARIA attributes for the menu toggle if it's visible.
|
||||
* @since Twenty Fourteen 1.4
|
||||
*/
|
||||
function onResizeARIA() {
|
||||
if ( 781 > _window.width() ) {
|
||||
button.attr( 'aria-expanded', 'false' );
|
||||
menu.attr( 'aria-expanded', 'false' );
|
||||
button.attr( 'aria-controls', 'primary-menu' );
|
||||
} else {
|
||||
button.removeAttr( 'aria-expanded' );
|
||||
menu.removeAttr( 'aria-expanded' );
|
||||
button.removeAttr( 'aria-controls' );
|
||||
}
|
||||
}
|
||||
|
||||
_window
|
||||
.on( 'load.twentyfourteen', onResizeARIA )
|
||||
.on( 'resize.twentyfourteen', function() {
|
||||
onResizeARIA();
|
||||
} );
|
||||
|
||||
_window.load( function() {
|
||||
// Arrange footer widgets vertically.
|
||||
if ( $.isFunction( $.fn.masonry ) ) {
|
||||
$( '#footer-sidebar' ).masonry( {
|
||||
itemSelector: '.widget',
|
||||
columnWidth: function( containerWidth ) {
|
||||
return containerWidth / 4;
|
||||
},
|
||||
gutterWidth: 0,
|
||||
isResizable: true,
|
||||
isRTL: $( 'body' ).is( '.rtl' )
|
||||
} );
|
||||
}
|
||||
|
||||
// Initialize Featured Content slider.
|
||||
if ( body.is( '.slider' ) ) {
|
||||
$( '.featured-content' ).featuredslider( {
|
||||
selector: '.featured-content-inner > article',
|
||||
controlsContainer: '.featured-content'
|
||||
} );
|
||||
}
|
||||
} );
|
||||
} )( jQuery );
|
||||
8
wp-content/themes/twentyfourteen/js/html5.js
Normal file
8
wp-content/themes/twentyfourteen/js/html5.js
Normal file
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
HTML5 Shiv v3.7.0 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
|
||||
*/
|
||||
(function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag();
|
||||
a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/[\w\-]+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x<style>article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}</style>";
|
||||
c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="<xyz></xyz>";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode||
|
||||
"undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output progress section summary template time video",version:"3.7.0",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);
|
||||
if(g)return a.createDocumentFragment();for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d<h;d++)c.createElement(e[d]);return c}};l.html5=e;q(f)})(this,document);
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Twenty Fourteen keyboard support for image navigation.
|
||||
*/
|
||||
( function( $ ) {
|
||||
$( document ).on( 'keydown.twentyfourteen', function( e ) {
|
||||
var url = false;
|
||||
|
||||
// Left arrow key code.
|
||||
if ( e.which === 37 ) {
|
||||
url = $( '.previous-image a' ).attr( 'href' );
|
||||
|
||||
// Right arrow key code.
|
||||
} else if ( e.which === 39 ) {
|
||||
url = $( '.entry-attachment a' ).attr( 'href' );
|
||||
}
|
||||
|
||||
if ( url && ( ! $( 'textarea, input' ).is( ':focus' ) ) ) {
|
||||
window.location = url;
|
||||
}
|
||||
} );
|
||||
} )( jQuery );
|
||||
598
wp-content/themes/twentyfourteen/js/slider.js
Normal file
598
wp-content/themes/twentyfourteen/js/slider.js
Normal file
@@ -0,0 +1,598 @@
|
||||
/*
|
||||
* Twenty Fourteen Featured Content Slider
|
||||
*
|
||||
* Adapted from FlexSlider v2.2.0, copyright 2012 WooThemes
|
||||
* @link http://www.woothemes.com/flexslider/
|
||||
*/
|
||||
/* global DocumentTouch:true,setImmediate:true,featuredSliderDefaults:true,MSGesture:true */
|
||||
( function( $ ) {
|
||||
// FeaturedSlider: object instance.
|
||||
$.featuredslider = function( el, options ) {
|
||||
var slider = $( el ),
|
||||
msGesture = window.navigator && window.navigator.msPointerEnabled && window.MSGesture,
|
||||
touch = ( ( 'ontouchstart' in window ) || msGesture || window.DocumentTouch && document instanceof DocumentTouch ), // MSFT specific.
|
||||
eventType = 'click touchend MSPointerUp',
|
||||
watchedEvent = '',
|
||||
watchedEventClearTimer,
|
||||
methods = {},
|
||||
namespace;
|
||||
|
||||
// Make variables public.
|
||||
slider.vars = $.extend( {}, $.featuredslider.defaults, options );
|
||||
|
||||
namespace = slider.vars.namespace,
|
||||
|
||||
// Store a reference to the slider object.
|
||||
$.data( el, 'featuredslider', slider );
|
||||
|
||||
// Private slider methods.
|
||||
methods = {
|
||||
init: function() {
|
||||
slider.animating = false;
|
||||
slider.currentSlide = 0;
|
||||
slider.animatingTo = slider.currentSlide;
|
||||
slider.atEnd = ( slider.currentSlide === 0 || slider.currentSlide === slider.last );
|
||||
slider.containerSelector = slider.vars.selector.substr( 0, slider.vars.selector.search( ' ' ) );
|
||||
slider.slides = $( slider.vars.selector, slider );
|
||||
slider.container = $( slider.containerSelector, slider );
|
||||
slider.count = slider.slides.length;
|
||||
slider.prop = 'marginLeft';
|
||||
slider.isRtl = $( 'body' ).hasClass( 'rtl' );
|
||||
slider.args = {};
|
||||
// TOUCH
|
||||
slider.transitions = ( function() {
|
||||
var obj = document.createElement( 'div' ),
|
||||
props = ['perspectiveProperty', 'WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective'],
|
||||
i;
|
||||
|
||||
for ( i in props ) {
|
||||
if ( obj.style[ props[i] ] !== undefined ) {
|
||||
slider.pfx = props[i].replace( 'Perspective', '' ).toLowerCase();
|
||||
slider.prop = '-' + slider.pfx + '-transform';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}() );
|
||||
// CONTROLSCONTAINER
|
||||
if ( slider.vars.controlsContainer !== '' ) {
|
||||
slider.controlsContainer = $( slider.vars.controlsContainer ).length > 0 && $( slider.vars.controlsContainer );
|
||||
}
|
||||
|
||||
slider.doMath();
|
||||
|
||||
// INIT
|
||||
slider.setup( 'init' );
|
||||
|
||||
// CONTROLNAV
|
||||
methods.controlNav.setup();
|
||||
|
||||
// DIRECTIONNAV
|
||||
methods.directionNav.setup();
|
||||
|
||||
// KEYBOARD
|
||||
if ( $( slider.containerSelector ).length === 1 ) {
|
||||
$( document ).bind( 'keyup', function( event ) {
|
||||
var keycode = event.keyCode,
|
||||
target = false;
|
||||
if ( ! slider.animating && ( keycode === 39 || keycode === 37 ) ) {
|
||||
if ( keycode === 39 ) {
|
||||
target = slider.getTarget( 'next' );
|
||||
} else if ( keycode === 37 ) {
|
||||
target = slider.getTarget( 'prev' );
|
||||
}
|
||||
|
||||
slider.featureAnimate( target );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
// TOUCH
|
||||
if ( touch ) {
|
||||
methods.touch();
|
||||
}
|
||||
|
||||
$( window ).bind( 'resize orientationchange focus', methods.resize );
|
||||
|
||||
slider.find( 'img' ).attr( 'draggable', 'false' );
|
||||
},
|
||||
|
||||
controlNav: {
|
||||
setup: function() {
|
||||
methods.controlNav.setupPaging();
|
||||
},
|
||||
setupPaging: function() {
|
||||
var type = 'control-paging',
|
||||
j = 1,
|
||||
item,
|
||||
slide,
|
||||
i;
|
||||
|
||||
slider.controlNavScaffold = $( '<ol class="' + namespace + 'control-nav ' + namespace + type + '"></ol>' );
|
||||
|
||||
if ( slider.pagingCount > 1 ) {
|
||||
for ( i = 0; i < slider.pagingCount; i++ ) {
|
||||
slide = slider.slides.eq( i );
|
||||
item = '<a>' + j + '</a>';
|
||||
slider.controlNavScaffold.append( '<li>' + item + '</li>' );
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
// CONTROLSCONTAINER
|
||||
( slider.controlsContainer ) ? $( slider.controlsContainer ).append( slider.controlNavScaffold ) : slider.append( slider.controlNavScaffold );
|
||||
methods.controlNav.set();
|
||||
|
||||
methods.controlNav.active();
|
||||
|
||||
slider.controlNavScaffold.delegate( 'a, img', eventType, function( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
if ( watchedEvent === '' || watchedEvent === event.type ) {
|
||||
var $this = $( this ),
|
||||
target = slider.controlNav.index( $this );
|
||||
|
||||
if ( ! $this.hasClass( namespace + 'active' ) ) {
|
||||
slider.direction = ( target > slider.currentSlide ) ? 'next' : 'prev';
|
||||
slider.featureAnimate( target );
|
||||
}
|
||||
}
|
||||
|
||||
// Set up flags to prevent event duplication.
|
||||
if ( watchedEvent === '' ) {
|
||||
watchedEvent = event.type;
|
||||
}
|
||||
|
||||
methods.setToClearWatchedEvent();
|
||||
} );
|
||||
},
|
||||
set: function() {
|
||||
var selector = 'a';
|
||||
slider.controlNav = $( '.' + namespace + 'control-nav li ' + selector, ( slider.controlsContainer ) ? slider.controlsContainer : slider );
|
||||
},
|
||||
active: function() {
|
||||
slider.controlNav.removeClass( namespace + 'active' ).eq( slider.animatingTo ).addClass( namespace + 'active' );
|
||||
},
|
||||
update: function( action, pos ) {
|
||||
if ( slider.pagingCount > 1 && action === 'add' ) {
|
||||
slider.controlNavScaffold.append( $( '<li><a>' + slider.count + '</a></li>' ) );
|
||||
} else if ( slider.pagingCount === 1 ) {
|
||||
slider.controlNavScaffold.find( 'li' ).remove();
|
||||
} else {
|
||||
slider.controlNav.eq( pos ).closest( 'li' ).remove();
|
||||
}
|
||||
methods.controlNav.set();
|
||||
( slider.pagingCount > 1 && slider.pagingCount !== slider.controlNav.length ) ? slider.update( pos, action ) : methods.controlNav.active();
|
||||
}
|
||||
},
|
||||
|
||||
directionNav: {
|
||||
setup: function() {
|
||||
var directionNavScaffold = $( '<ul class="' + namespace + 'direction-nav"><li><a class="' + namespace + 'prev" href="#">' + slider.vars.prevText + '</a></li><li><a class="' + namespace + 'next" href="#">' + slider.vars.nextText + '</a></li></ul>' );
|
||||
|
||||
// CONTROLSCONTAINER
|
||||
if ( slider.controlsContainer ) {
|
||||
$( slider.controlsContainer ).append( directionNavScaffold );
|
||||
slider.directionNav = $( '.' + namespace + 'direction-nav li a', slider.controlsContainer );
|
||||
} else {
|
||||
slider.append( directionNavScaffold );
|
||||
slider.directionNav = $( '.' + namespace + 'direction-nav li a', slider );
|
||||
}
|
||||
|
||||
methods.directionNav.update();
|
||||
|
||||
slider.directionNav.bind( eventType, function( event ) {
|
||||
event.preventDefault();
|
||||
var target;
|
||||
|
||||
if ( watchedEvent === '' || watchedEvent === event.type ) {
|
||||
target = ( $( this ).hasClass( namespace + 'next' ) ) ? slider.getTarget( 'next' ) : slider.getTarget( 'prev' );
|
||||
slider.featureAnimate( target );
|
||||
}
|
||||
|
||||
// Set up flags to prevent event duplication.
|
||||
if ( watchedEvent === '' ) {
|
||||
watchedEvent = event.type;
|
||||
}
|
||||
|
||||
methods.setToClearWatchedEvent();
|
||||
} );
|
||||
},
|
||||
update: function() {
|
||||
var disabledClass = namespace + 'disabled';
|
||||
if ( slider.pagingCount === 1 ) {
|
||||
slider.directionNav.addClass( disabledClass ).attr( 'tabindex', '-1' );
|
||||
} else {
|
||||
slider.directionNav.removeClass( disabledClass ).removeAttr( 'tabindex' );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
touch: function() {
|
||||
var startX,
|
||||
startY,
|
||||
offset,
|
||||
cwidth,
|
||||
dx,
|
||||
startT,
|
||||
scrolling = false,
|
||||
localX = 0,
|
||||
localY = 0,
|
||||
accDx = 0;
|
||||
|
||||
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 ) {
|
||||
e.preventDefault();
|
||||
} else if ( ( window.navigator.msPointerEnabled ) || e.touches.length === 1 ) {
|
||||
cwidth = slider.w;
|
||||
startT = Number( new Date() );
|
||||
|
||||
// Local vars for X and Y points.
|
||||
localX = e.touches[0].pageX;
|
||||
localY = e.touches[0].pageY;
|
||||
|
||||
offset = ( slider.currentSlide + slider.cloneOffset ) * cwidth;
|
||||
if ( slider.animatingTo === slider.last && slider.direction !== 'next' ) {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
startX = localX;
|
||||
startY = localY;
|
||||
|
||||
el.addEventListener( 'touchmove', onTouchMove, false );
|
||||
el.addEventListener( 'touchend', onTouchEnd, false );
|
||||
}
|
||||
}
|
||||
|
||||
function onTouchMove( e ) {
|
||||
// Local vars for X and Y points.
|
||||
localX = e.touches[0].pageX;
|
||||
localY = e.touches[0].pageY;
|
||||
|
||||
dx = startX - localX;
|
||||
scrolling = Math.abs( dx ) < Math.abs( localY - startY );
|
||||
|
||||
if ( ! scrolling ) {
|
||||
e.preventDefault();
|
||||
if ( slider.transitions ) {
|
||||
slider.setProps( offset + dx, 'setTouch' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onTouchEnd() {
|
||||
// Finish the touch by undoing the touch session.
|
||||
el.removeEventListener( 'touchmove', onTouchMove, false );
|
||||
|
||||
if ( slider.animatingTo === slider.currentSlide && ! scrolling && dx !== null ) {
|
||||
var updateDx = dx,
|
||||
target = ( updateDx > 0 ) ? slider.getTarget( 'next' ) : slider.getTarget( 'prev' );
|
||||
|
||||
slider.featureAnimate( target );
|
||||
}
|
||||
el.removeEventListener( 'touchend', onTouchEnd, false );
|
||||
|
||||
startX = null;
|
||||
startY = null;
|
||||
dx = null;
|
||||
offset = null;
|
||||
}
|
||||
|
||||
function onMSPointerDown( e ) {
|
||||
e.stopPropagation();
|
||||
if ( slider.animating ) {
|
||||
e.preventDefault();
|
||||
} else {
|
||||
el._gesture.addPointer( e.pointerId );
|
||||
accDx = 0;
|
||||
cwidth = slider.w;
|
||||
startT = Number( new Date() );
|
||||
offset = ( slider.currentSlide + slider.cloneOffset ) * cwidth;
|
||||
if ( slider.animatingTo === slider.last && slider.direction !== 'next' ) {
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onMSGestureChange( e ) {
|
||||
e.stopPropagation();
|
||||
var slider = e.target._slider,
|
||||
transX,
|
||||
transY;
|
||||
if ( ! slider ) {
|
||||
return;
|
||||
}
|
||||
|
||||
transX = -e.translationX,
|
||||
transY = -e.translationY;
|
||||
|
||||
// Accumulate translations.
|
||||
accDx = accDx + transX;
|
||||
dx = accDx;
|
||||
scrolling = Math.abs( accDx ) < Math.abs( -transY );
|
||||
|
||||
if ( e.detail === e.MSGESTURE_FLAG_INERTIA ) {
|
||||
setImmediate( function () { // MSFT specific.
|
||||
el._gesture.stop();
|
||||
} );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! scrolling || Number( new Date() ) - startT > 500 ) {
|
||||
e.preventDefault();
|
||||
if ( slider.transitions ) {
|
||||
slider.setProps( offset + dx, 'setTouch' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onMSGestureEnd( e ) {
|
||||
e.stopPropagation();
|
||||
var slider = e.target._slider,
|
||||
updateDx,
|
||||
target;
|
||||
if ( ! slider ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( slider.animatingTo === slider.currentSlide && ! scrolling && dx !== null ) {
|
||||
updateDx = dx,
|
||||
target = ( updateDx > 0 ) ? slider.getTarget( 'next' ) : slider.getTarget( 'prev' );
|
||||
|
||||
slider.featureAnimate( target );
|
||||
}
|
||||
|
||||
startX = null;
|
||||
startY = null;
|
||||
dx = null;
|
||||
offset = null;
|
||||
accDx = 0;
|
||||
}
|
||||
},
|
||||
|
||||
resize: function() {
|
||||
if ( ! slider.animating && slider.is( ':visible' ) ) {
|
||||
slider.doMath();
|
||||
|
||||
// SMOOTH HEIGHT
|
||||
methods.smoothHeight();
|
||||
slider.newSlides.width( slider.computedW );
|
||||
slider.setProps( slider.computedW, 'setTotal' );
|
||||
}
|
||||
},
|
||||
|
||||
smoothHeight: function( dur ) {
|
||||
var $obj = slider.viewport;
|
||||
( dur ) ? $obj.animate( { 'height': slider.slides.eq( slider.animatingTo ).height() }, dur ) : $obj.height( slider.slides.eq( slider.animatingTo ).height() );
|
||||
},
|
||||
|
||||
setToClearWatchedEvent: function() {
|
||||
clearTimeout( watchedEventClearTimer );
|
||||
watchedEventClearTimer = setTimeout( function() {
|
||||
watchedEvent = '';
|
||||
}, 3000 );
|
||||
}
|
||||
};
|
||||
|
||||
// Public methods.
|
||||
slider.featureAnimate = function( target ) {
|
||||
if ( target !== slider.currentSlide ) {
|
||||
slider.direction = ( target > slider.currentSlide ) ? 'next' : 'prev';
|
||||
}
|
||||
|
||||
if ( ! slider.animating && slider.is( ':visible' ) ) {
|
||||
slider.animating = true;
|
||||
slider.animatingTo = target;
|
||||
|
||||
// CONTROLNAV
|
||||
methods.controlNav.active();
|
||||
|
||||
slider.slides.removeClass( namespace + 'active-slide' ).eq( target ).addClass( namespace + 'active-slide' );
|
||||
|
||||
slider.atEnd = target === 0 || target === slider.last;
|
||||
|
||||
// DIRECTIONNAV
|
||||
methods.directionNav.update();
|
||||
|
||||
var dimension = slider.computedW,
|
||||
slideString;
|
||||
|
||||
if ( slider.currentSlide === 0 && target === slider.count - 1 && slider.direction !== 'next' ) {
|
||||
slideString = 0;
|
||||
} else if ( slider.currentSlide === slider.last && target === 0 && slider.direction !== 'prev' ) {
|
||||
slideString = ( slider.count + 1 ) * dimension;
|
||||
} else {
|
||||
slideString = ( target + slider.cloneOffset ) * dimension;
|
||||
}
|
||||
slider.setProps( slideString, '', slider.vars.animationSpeed );
|
||||
if ( slider.transitions ) {
|
||||
if ( ! slider.atEnd ) {
|
||||
slider.animating = false;
|
||||
slider.currentSlide = slider.animatingTo;
|
||||
}
|
||||
slider.container.unbind( 'webkitTransitionEnd transitionend' );
|
||||
slider.container.bind( 'webkitTransitionEnd transitionend', function() {
|
||||
slider.wrapup( dimension );
|
||||
} );
|
||||
} else {
|
||||
slider.container.animate( slider.args, slider.vars.animationSpeed, 'swing', function() {
|
||||
slider.wrapup( dimension );
|
||||
} );
|
||||
}
|
||||
|
||||
// SMOOTH HEIGHT
|
||||
methods.smoothHeight( slider.vars.animationSpeed );
|
||||
}
|
||||
};
|
||||
|
||||
slider.wrapup = function( dimension ) {
|
||||
if ( slider.currentSlide === 0 && slider.animatingTo === slider.last ) {
|
||||
slider.setProps( dimension, 'jumpEnd' );
|
||||
} else if ( slider.currentSlide === slider.last && slider.animatingTo === 0 ) {
|
||||
slider.setProps( dimension, 'jumpStart' );
|
||||
}
|
||||
slider.animating = false;
|
||||
slider.currentSlide = slider.animatingTo;
|
||||
};
|
||||
|
||||
slider.getTarget = function( dir ) {
|
||||
slider.direction = dir;
|
||||
|
||||
// Swap for RTL.
|
||||
if ( slider.isRtl ) {
|
||||
dir = 'next' === dir ? 'prev' : 'next';
|
||||
}
|
||||
|
||||
if ( dir === 'next' ) {
|
||||
return ( slider.currentSlide === slider.last ) ? 0 : slider.currentSlide + 1;
|
||||
} else {
|
||||
return ( slider.currentSlide === 0 ) ? slider.last : slider.currentSlide - 1;
|
||||
}
|
||||
};
|
||||
|
||||
slider.setProps = function( pos, special, dur ) {
|
||||
var target = ( function() {
|
||||
var posCalc = ( function() {
|
||||
switch ( special ) {
|
||||
case 'setTotal': return ( slider.currentSlide + slider.cloneOffset ) * pos;
|
||||
case 'setTouch': return pos;
|
||||
case 'jumpEnd': return slider.count * pos;
|
||||
case 'jumpStart': return pos;
|
||||
default: return pos;
|
||||
}
|
||||
}() );
|
||||
|
||||
return ( posCalc * -1 ) + 'px';
|
||||
}() );
|
||||
|
||||
if ( slider.transitions ) {
|
||||
target = 'translate3d(' + target + ',0,0 )';
|
||||
dur = ( dur !== undefined ) ? ( dur / 1000 ) + 's' : '0s';
|
||||
slider.container.css( '-' + slider.pfx + '-transition-duration', dur );
|
||||
}
|
||||
|
||||
slider.args[slider.prop] = target;
|
||||
if ( slider.transitions || dur === undefined ) {
|
||||
slider.container.css( slider.args );
|
||||
}
|
||||
};
|
||||
|
||||
slider.setup = function( type ) {
|
||||
var sliderOffset;
|
||||
|
||||
if ( type === 'init' ) {
|
||||
slider.viewport = $( '<div class="' + namespace + 'viewport"></div>' ).css( { 'overflow': 'hidden', 'position': 'relative' } ).appendTo( slider ).append( slider.container );
|
||||
slider.cloneCount = 0;
|
||||
slider.cloneOffset = 0;
|
||||
}
|
||||
slider.cloneCount = 2;
|
||||
slider.cloneOffset = 1;
|
||||
// Clear out old clones.
|
||||
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 );
|
||||
|
||||
sliderOffset = slider.currentSlide + slider.cloneOffset;
|
||||
slider.container.width( ( slider.count + slider.cloneCount ) * 200 + '%' );
|
||||
slider.setProps( sliderOffset * slider.computedW, 'init' );
|
||||
setTimeout( function() {
|
||||
slider.doMath();
|
||||
slider.newSlides.css( { 'width': slider.computedW, 'float': 'left', 'display': 'block' } );
|
||||
// SMOOTH HEIGHT
|
||||
methods.smoothHeight();
|
||||
}, ( type === 'init' ) ? 100 : 0 );
|
||||
|
||||
slider.slides.removeClass( namespace + 'active-slide' ).eq( slider.currentSlide ).addClass( namespace + 'active-slide' );
|
||||
};
|
||||
|
||||
slider.doMath = function() {
|
||||
var slide = slider.slides.first();
|
||||
|
||||
slider.w = ( slider.viewport === undefined ) ? slider.width() : slider.viewport.width();
|
||||
slider.h = slide.height();
|
||||
slider.boxPadding = slide.outerWidth() - slide.width();
|
||||
|
||||
slider.itemW = slider.w;
|
||||
slider.pagingCount = slider.count;
|
||||
slider.last = slider.count - 1;
|
||||
slider.computedW = slider.itemW - slider.boxPadding;
|
||||
};
|
||||
|
||||
slider.update = function( pos, action ) {
|
||||
slider.doMath();
|
||||
|
||||
// Update currentSlide and slider.animatingTo if necessary.
|
||||
if ( pos < slider.currentSlide ) {
|
||||
slider.currentSlide += 1;
|
||||
} else if ( pos <= slider.currentSlide && pos !== 0 ) {
|
||||
slider.currentSlide -= 1;
|
||||
}
|
||||
slider.animatingTo = slider.currentSlide;
|
||||
|
||||
// Update controlNav.
|
||||
if ( action === 'add' || slider.pagingCount > slider.controlNav.length ) {
|
||||
methods.controlNav.update( 'add' );
|
||||
} else if ( action === 'remove' || slider.pagingCount < slider.controlNav.length ) {
|
||||
if ( slider.currentSlide > slider.last ) {
|
||||
slider.currentSlide -= 1;
|
||||
slider.animatingTo -= 1;
|
||||
}
|
||||
methods.controlNav.update( 'remove', slider.last );
|
||||
}
|
||||
// Update directionNav.
|
||||
methods.directionNav.update();
|
||||
};
|
||||
|
||||
// FeaturedSlider: initialize.
|
||||
methods.init();
|
||||
};
|
||||
|
||||
// Default settings.
|
||||
$.featuredslider.defaults = {
|
||||
namespace: 'slider-', // String: prefix string attached to the class of every element generated by the plugin.
|
||||
selector: '.slides > li', // String: selector, must match a simple pattern.
|
||||
animationSpeed: 600, // Integer: Set the speed of animations, in milliseconds.
|
||||
controlsContainer: '', // jQuery Object/Selector: container navigation to append elements.
|
||||
|
||||
// Text labels.
|
||||
prevText: featuredSliderDefaults.prevText, // String: Set the text for the "previous" directionNav item.
|
||||
nextText: featuredSliderDefaults.nextText // String: Set the text for the "next" directionNav item.
|
||||
};
|
||||
|
||||
// FeaturedSlider: plugin function.
|
||||
$.fn.featuredslider = function( options ) {
|
||||
if ( options === undefined ) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if ( typeof options === 'object' ) {
|
||||
return this.each( function() {
|
||||
var $this = $( this ),
|
||||
selector = ( options.selector ) ? options.selector : '.slides > li',
|
||||
$slides = $this.find( selector );
|
||||
|
||||
if ( $slides.length === 1 || $slides.length === 0 ) {
|
||||
$slides.fadeIn( 400 );
|
||||
} else if ( $this.data( 'featuredslider' ) === undefined ) {
|
||||
new $.featuredslider( this, options );
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
||||
} )( jQuery );
|
||||
Reference in New Issue
Block a user