diff options
author | Theo Chatzimichos <tampakrap@gentoo.org> | 2013-10-03 21:53:38 +0200 |
---|---|---|
committer | Theo Chatzimichos <tampakrap@gentoo.org> | 2013-10-03 21:53:38 +0200 |
commit | 61f7269ffabd11b7de56507c69191be42d7cfa60 (patch) | |
tree | 2ad81bec8d0c124019b23c841d80882c303801bc /plugins/jetpack/modules/shortcodes | |
parent | forgot to include new files of jetpack (diff) | |
download | blogs-gentoo-61f7269ffabd11b7de56507c69191be42d7cfa60.tar.gz blogs-gentoo-61f7269ffabd11b7de56507c69191be42d7cfa60.tar.bz2 blogs-gentoo-61f7269ffabd11b7de56507c69191be42d7cfa60.zip |
update jetpack
Diffstat (limited to 'plugins/jetpack/modules/shortcodes')
15 files changed, 3793 insertions, 1333 deletions
diff --git a/plugins/jetpack/modules/shortcodes/css/rtl/slideshow-shortcode-rtl.css b/plugins/jetpack/modules/shortcodes/css/rtl/slideshow-shortcode-rtl.css index eea868af..fdfa6aea 100644 --- a/plugins/jetpack/modules/shortcodes/css/rtl/slideshow-shortcode-rtl.css +++ b/plugins/jetpack/modules/shortcodes/css/rtl/slideshow-shortcode-rtl.css @@ -1,4 +1,4 @@ -/* This file was automatically generated on Mar 25 2013 08:14:36 */ +/* This file was automatically generated on Aug 22 2013 17:45:44 */ .slideshow-window { background-color: #222; @@ -8,6 +8,7 @@ -webkit-border-radius: 11px; -khtml-border-radius: 11px; margin-bottom: 20px; + height: 410px; } .slideshow-window, .slideshow-window * { diff --git a/plugins/jetpack/modules/shortcodes/css/slideshow-shortcode.css b/plugins/jetpack/modules/shortcodes/css/slideshow-shortcode.css index 13cef497..fb3ec530 100644 --- a/plugins/jetpack/modules/shortcodes/css/slideshow-shortcode.css +++ b/plugins/jetpack/modules/shortcodes/css/slideshow-shortcode.css @@ -6,6 +6,7 @@ -webkit-border-radius: 11px; -khtml-border-radius: 11px; margin-bottom: 20px; + height: 410px; } .slideshow-window, .slideshow-window * { diff --git a/plugins/jetpack/modules/shortcodes/css/style.css b/plugins/jetpack/modules/shortcodes/css/style.css new file mode 100644 index 00000000..137663a3 --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/css/style.css @@ -0,0 +1,187 @@ +/** +* 1. Fullscreen styles +*/ +html.presentation-wrapper-fullscreen-parent, +body.presentation-wrapper-fullscreen-parent { + overflow: hidden !important; +} + +.presentation-wrapper-fullscreen-parent #wpadminbar { + display: none; +} + +.presentation-wrapper-fullscreen, +.presentation-wrapper-fullscreen-parent { + min-width: 100% !important; + min-height: 100% !important; + position: absolute !important; + top: 0 !important; + right: 0 !important; + bottom: 0 !important; + left: 0 !important; + margin: 0 !important; + padding: 0 !important; + z-index: 10000 !important; +} + +.presentation-wrapper-fullscreen { + background-color: #808080; + border: none !important; +} + +.presentation-wrapper-fullscreen .nav-arrow-left, +.presentation-wrapper-fullscreen .nav-arrow-right { + z-index: 20001; +} + +.presentation-wrapper-fullscreen .nav-fullscreen-button { + z-index: 20002; +} + + +/** + * 2. General presentation styles + */ +.presentation-wrapper { + margin: 20px auto; + border: 1px solid #e5e5e5; + overflow: hidden; +} + +.presentation { + position: relative; + margin: 0; + overflow: hidden; + outline: none; +} + +/** + * jmpress requires that step sizes are explicitly defined + * as it inserts sizeless divs before the steps. These + * dimensions are set by the js code on initialization + */ +.presentation, +.presentation .step { + background-repeat: no-repeat; + background-position: center; + background-size: 100% 100%; +} + +/** + * Opacity transition durations are set by the js code + * so they match the presentation animation durations + */ +.presentation .step.fade:not(.active) { + opacity: 0; +} + +.presentation .slide-content { + padding: 30px; +} + + +/** + * 3. Styles for the navigation arrows + */ +.presentation .nav-arrow-left, +.presentation .nav-arrow-right, +.presentation .nav-fullscreen-button { + position: absolute; + width: 34px; + background-repeat: no-repeat; + z-index: 2; + opacity: 0; + + -webkit-transition : opacity .25s; + -moz-transition : opacity .25s; + -ms-transition : opacity .25s; + -o-transition : opacity .25s; + transition : opacity .25s; +} + +.presentation .nav-arrow-left, +.presentation .nav-arrow-right { + height: 100%; + background-image: url(../images/slide-nav.png); + background-size: 450% 61px; +} + +.presentation .nav-arrow-left { + left: 0; + background-position: 4px 50%; +} + +.presentation .nav-arrow-right { + right: 0; + background-position: -120px 50%; +} + +.presentation .nav-fullscreen-button { + width: 32px; + height: 32px; + margin: 4px; + bottom: 0; + right: 0; + z-index: 3; + background-image: url(../images/expand.png); + background-size: 100% 100%; +} + +.presentation:hover .nav-arrow-left, +.presentation:hover .nav-arrow-right { + opacity: 1; +} + +.presentation:hover .nav-fullscreen-button { + opacity: 0.8; +} + +.presentation-wrapper-fullscreen .nav-fullscreen-button { + background-image: url(../images/collapse.png); +} + +/** + * 4. Styles for the autoplay overlay + */ +.presentation .autoplay-overlay { + height: 15%; + width: 80%; + margin: 30% 10%; + position: relative; + z-index: 100; + display: table; + border-radius: 50px; + background-color: #e5e5e5; + background-color: rgba(0, 0, 0, 0.75); + + -webkit-transition : opacity .5s; + -moz-transition : opacity .5s; + -ms-transition : opacity .5s; + -o-transition : opacity .5s; + transition : opacity .5s; +} + +.presentation .autoplay-overlay .overlay-msg { + position: relative; + display: table-cell; + text-align: center; + vertical-align: middle; + color: #fff; +} + +/** + * 5. Styles for fading steps + */ +.presentation .will-fade { + opacity: 0; +} + +.presentation .do-fade { + opacity: 1; + + -webkit-transition : opacity .5s; + -moz-transition : opacity .5s; + -ms-transition : opacity .5s; + -o-transition : opacity .5s; + transition : opacity .5s; +}
\ No newline at end of file diff --git a/plugins/jetpack/modules/shortcodes/facebook.php b/plugins/jetpack/modules/shortcodes/facebook.php new file mode 100644 index 00000000..39152a2c --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/facebook.php @@ -0,0 +1,44 @@ +<?php + +/** + * Facebook embeds + */ + +define( 'JETPACK_FACEBOOK_EMBED_REGEX', '#^https?://(www.)?facebook\.com/([^/]+)/posts/([^/]+)?#' ); +define( 'JETPACK_FACEBOOK_PHOTO_EMBED_REGEX', '#^https?://(www.)?facebook\.com/photo.php\?([^\s]+)#' ); + +// Example URL: https://www.facebook.com/VenusWilliams/posts/10151647007373076 +wp_embed_register_handler( 'facebook', JETPACK_FACEBOOK_EMBED_REGEX, 'jetpack_facebook_embed_handler' ); +// Photos are handled on a different endpoint; e.g. https://www.facebook.com/photo.php?fbid=10151609960150073&set=a.398410140072.163165.106666030072&type=1 +wp_embed_register_handler( 'facebook-photo', JETPACK_FACEBOOK_PHOTO_EMBED_REGEX, 'jetpack_facebook_embed_handler' ); + +function jetpack_facebook_embed_handler( $matches, $attr, $url ) { + static $did_script; + + if ( ! $did_script ) { + $did_script = true; + add_action( 'wp_footer', 'jetpack_facebook_add_script' ); + } + + return sprintf( '<fb:post href="%s"></fb:post>', esc_url( $url ) ); +} + +function jetpack_facebook_add_script() { + ?> + <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, "script", "facebook-jssdk"));</script> + <?php +} + +add_shortcode( 'facebook', 'jetpack_facebook_shortcode_handler' ); + +function jetpack_facebook_shortcode_handler( $atts ) { + global $wp_embed; + + if ( empty( $atts['url'] ) ) + return; + + if ( ! preg_match( JETPACK_FACEBOOK_EMBED_REGEX, $atts['url'] ) && ! preg_match( JETPACK_FACEBOOK_PHOTO_EMBED_REGEX, $atts['url'] ) ) + return; + + return $wp_embed->shortcode( $atts, $atts['url'] ); +} diff --git a/plugins/jetpack/modules/shortcodes/googleplus.php b/plugins/jetpack/modules/shortcodes/googleplus.php new file mode 100644 index 00000000..95d8b813 --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/googleplus.php @@ -0,0 +1,41 @@ +<?php + +/** + * Google+ embeds + */ + +define( 'JETPACK_GOOGLEPLUS_EMBED_REGEX', '#^https?://plus\.(sandbox\.)?google\.com/([^/]+)/posts/([^/]+)$#' ); + +// Example URL: https://plus.google.com/114986219448604314131/posts/LgHkesWCmJo +wp_embed_register_handler( 'googleplus', JETPACK_GOOGLEPLUS_EMBED_REGEX, 'jetpack_googleplus_embed_handler' ); + +function jetpack_googleplus_embed_handler( $matches, $attr, $url ) { + static $did_script; + + if ( ! $did_script ) { + $did_script = true; + add_action( 'wp_footer', 'jetpack_googleplus_add_script' ); + } + + return sprintf( '<div class="g-post" data-href="%s"></div>', esc_url( $url ) ); +} + +function jetpack_googleplus_add_script() { + ?> + <script src="https://apis.google.com/js/plusone.js"></script> + <?php +} + +add_shortcode( 'googleplus', 'jetpack_googleplus_shortcode_handler' ); + +function jetpack_googleplus_shortcode_handler( $atts ) { + global $wp_embed; + + if ( empty( $atts['url'] ) ) + return; + + if ( ! preg_match( JETPACK_GOOGLEPLUS_EMBED_REGEX, $atts['url'] ) ) + return; + + return $wp_embed->shortcode( $atts, $atts['url'] ); +} diff --git a/plugins/jetpack/modules/shortcodes/images/collapse.png b/plugins/jetpack/modules/shortcodes/images/collapse.png Binary files differnew file mode 100644 index 00000000..6cdf84fd --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/images/collapse.png diff --git a/plugins/jetpack/modules/shortcodes/images/expand.png b/plugins/jetpack/modules/shortcodes/images/expand.png Binary files differnew file mode 100644 index 00000000..ddf11ea2 --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/images/expand.png diff --git a/plugins/jetpack/modules/shortcodes/images/slide-nav.png b/plugins/jetpack/modules/shortcodes/images/slide-nav.png Binary files differnew file mode 100644 index 00000000..da6b74aa --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/images/slide-nav.png diff --git a/plugins/jetpack/modules/shortcodes/js/jmpress.js b/plugins/jetpack/modules/shortcodes/js/jmpress.js new file mode 100644 index 00000000..294e1fd6 --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/js/jmpress.js @@ -0,0 +1,2721 @@ +/*! + * jmpress.js v0.4.5 + * http://jmpressjs.github.com/jmpress.js + * + * A jQuery plugin to build a website on the infinite canvas. + * + * Copyright 2013 Kyle Robinson Young @shama & Tobias Koppers @sokra + * Licensed MIT + * http://www.opensource.org/licenses/mit-license.php + * + * Based on the foundation laid by Bartek Szopka @bartaz + *//*! + * jmpress.js v0.4.5 + * http://jmpressjs.github.com/jmpress.js + * + * A jQuery plugin to build a website on the infinite canvas. + * + * Copyright 2013 Kyle Robinson Young @shama & Tobias Koppers @sokra + * Licensed MIT + * http://www.opensource.org/licenses/mit-license.php + * + * Based on the foundation laid by Bartek Szopka @bartaz + *//* + * core.js + * The core of jmpress.js + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + /** + * Set supported prefixes + * + * @access protected + * @return Function to get prefixed property + */ + var pfx = (function () { + var style = document.createElement('dummy').style, + prefixes = 'Webkit Moz O ms Khtml'.split(' '), + memory = {}; + return function ( prop ) { + if ( typeof memory[ prop ] === "undefined" ) { + var ucProp = prop.charAt(0).toUpperCase() + prop.substr(1), + props = (prop + ' ' + prefixes.join(ucProp + ' ') + ucProp).split(' '); + memory[ prop ] = null; + for ( var i in props ) { + if ( style[ props[i] ] !== undefined ) { + memory[ prop ] = props[i]; + break; + } + } + } + return memory[ prop ]; + }; + }()); + + /** + * map ex. "WebkitTransform" to "-webkit-transform" + */ + function mapProperty( name ) { + if(!name) { + return; + } + var index = 1 + name.substr(1).search(/[A-Z]/); + var prefix = name.substr(0, index).toLowerCase(); + var postfix = name.substr(index).toLowerCase(); + return "-" + prefix + "-" + postfix; + } + function addComma( attribute ) { + if(!attribute) { + return ""; + } + return attribute + ","; + } + /** + * Return an jquery object only if it's not empty + */ + function ifNotEmpty(el) { + if(el.length > 0) { + return el; + } + return null; + } + + /** + * Default Settings + */ + var defaults = { + /* CLASSES */ + stepSelector: '.step' + ,containerClass: '' + ,canvasClass: '' + ,areaClass: '' + ,notSupportedClass: 'not-supported' + + /* CONFIG */ + ,fullscreen: true + + /* ANIMATION */ + ,animation: { + transformOrigin: 'top left' + ,transitionProperty: addComma(mapProperty(pfx('transform'))) + addComma(mapProperty(pfx('perspective'))) + 'opacity' + ,transitionDuration: '1s' + ,transitionDelay: '500ms' + ,transitionTimingFunction: 'ease-in-out' + ,transformStyle: "preserve-3d" + } + ,transitionDuration: 1500 + }; + var callbacks = { + 'beforeChange': 1 + ,'beforeInitStep': 1 + ,'initStep': 1 + ,'beforeInit': 1 + ,'afterInit': 1 + ,'beforeDeinit': 1 + ,'afterDeinit': 1 + ,'applyStep': 1 + ,'unapplyStep': 1 + ,'setInactive': 1 + ,'beforeActive': 1 + ,'setActive': 1 + ,'selectInitialStep': 1 + ,'selectPrev': 1 + ,'selectNext': 1 + ,'selectHome': 1 + ,'selectEnd': 1 + ,'idle': 1 + ,'applyTarget': 1 + }; + for(var callbackName in callbacks) { + defaults[callbackName] = []; + } + + + /** + * Initialize jmpress + */ + function init( args ) { + args = $.extend(true, {}, args || {}); + + // accept functions and arrays of functions as callbacks + var callbackArgs = {}; + var callbackName = null; + for (callbackName in callbacks) { + callbackArgs[callbackName] = $.isFunction( args[callbackName] ) ? + [ args[callbackName] ] : + args[callbackName]; + args[callbackName] = []; + } + + // MERGE SETTINGS + var settings = $.extend(true, {}, defaults, args); + + for (callbackName in callbacks) { + if (callbackArgs[callbackName]) { + Array.prototype.push.apply(settings[callbackName], callbackArgs[callbackName]); + } + } + + /*** MEMBER VARS ***/ + + var jmpress = $( this ) + ,container = null + ,area = null + ,oldStyle = { + container: "" + ,area: "" + } + ,canvas = null + ,current = null + ,active = false + ,activeSubstep = null + ,activeDelegated = false; + + + /*** MEMBER FUNCTIONS ***/ + // functions have to be called with this + + /** + * Init a single step + * + * @param element the element of the step + * @param idx number of step + */ + function doStepInit( element, idx ) { + var data = dataset( element ); + var step = { + oldStyle: $(element).attr("style") || "" + }; + + var callbackData = { + data: data + ,stepData: step + }; + callCallback.call(this, 'beforeInitStep', $(element), callbackData); + step.delegate = data.delegate; + callCallback.call(this, 'initStep', $(element), callbackData); + + $(element).data('stepData', step); + + if ( !$(element).attr('id') ) { + $(element).attr('id', 'step-' + (idx + 1)); + } + + callCallback.call(this, 'applyStep', $(element), callbackData); + } + /** + * Deinit a single step + * + * @param element the element of the step + */ + function doStepDeinit( element ) { + var stepData = $(element).data('stepData'); + + $(element).attr("style", stepData.oldStyle); + + callCallback.call(this, 'unapplyStep', $(element), { + stepData: stepData + }); + } + /** + * Reapplies stepData to the element + * + * @param element + */ + function doStepReapply( element ) { + callCallback.call(this, 'unapplyStep', $(element), { + stepData: element.data("stepData") + }); + + callCallback.call(this, 'applyStep', $(element), { + stepData: element.data("stepData") + }); + } + /** + * Completly deinit jmpress + * + */ + function deinit() { + if ( active ) { + callCallback.call(this, 'setInactive', active, { + stepData: $(active).data('stepData') + ,reason: "deinit" + } ); + } + if (current.jmpressClass) { + $(jmpress).removeClass(current.jmpressClass); + } + + callCallback.call(this, 'beforeDeinit', $(this), {}); + + $(settings.stepSelector, jmpress).each(function( idx ) { + doStepDeinit.call(jmpress, this ); + }); + + container.attr("style", oldStyle.container); + if(settings.fullscreen) { + $("html").attr("style", ""); + } + area.attr("style", oldStyle.area); + $(canvas).children().each(function() { + jmpress.append( $( this ) ); + }); + if( settings.fullscreen ) { + canvas.remove(); + } else { + canvas.remove(); + area.remove(); + } + + callCallback.call(this, 'afterDeinit', $(this), {}); + + $(jmpress).data("jmpressmethods", false); + } + /** + * Call a callback + * + * @param callbackName String callback which should be called + * @param element some arguments to the callback + * @param eventData + */ + function callCallback( callbackName, element, eventData ) { + eventData.settings = settings; + eventData.current = current; + eventData.container = container; + eventData.parents = element ? getStepParents(element) : null; + eventData.current = current; + eventData.jmpress = this; + var result = {}; + $.each( settings[callbackName], function(idx, callback) { + result.value = callback.call( jmpress, element, eventData ) || result.value; + }); + return result.value; + } + /** + * + */ + function getStepParents( el ) { + return $(el).parentsUntil(jmpress).not(jmpress).filter(settings.stepSelector); + } + /** + * Reselect the active step + * + * @param String type reason of reselecting step + */ + function reselect( type ) { + return select( { step: active, substep: activeSubstep }, type); + } + /** + * Select a given step + * + * @param el element to select + * @param type reason of changing step + * @return Object element selected + */ + function select( el, type ) { + var substep; + if ( $.isPlainObject( el ) ) { + substep = el.substep; + el = el.step; + } + if ( typeof el === 'string') { + el = jmpress.find( el ).first(); + } + if ( !el || !$(el).data('stepData') ) { + return false; + } + + scrollFix.call(this); + + var step = $(el).data('stepData'); + + var cancelSelect = false; + callCallback.call(this, "beforeChange", el, { + stepData: step + ,reason: type + ,cancel: function() { + cancelSelect = true; + } + }); + if (cancelSelect) { + return undefined; + } + + var target = {}; + + var delegated = el; + if($(el).data("stepData").delegate) { + delegated = ifNotEmpty($(el).parentsUntil(jmpress).filter(settings.stepSelector).filter(step.delegate)) || + ifNotEmpty($(el).near(step.delegate)) || + ifNotEmpty($(el).near(step.delegate, true)) || + ifNotEmpty($(step.delegate, jmpress)); + if(delegated) { + step = delegated.data("stepData"); + } else { + // Do not delegate if expression not found + delegated = el; + } + } + if ( activeDelegated ) { + callCallback.call(this, 'setInactive', activeDelegated, { + stepData: $(activeDelegated).data('stepData') + ,delegatedFrom: active + ,reason: type + ,target: target + ,nextStep: delegated + ,nextSubstep: substep + ,nextStepData: step + } ); + } + var callbackData = { + stepData: step + ,delegatedFrom: el + ,reason: type + ,target: target + ,substep: substep + ,prevStep: activeDelegated + ,prevSubstep: activeSubstep + ,prevStepData: activeDelegated && $(activeDelegated).data('stepData') + }; + callCallback.call(this, 'beforeActive', delegated, callbackData); + callCallback.call(this, 'setActive', delegated, callbackData); + + // Set on step class on root element + if (current.jmpressClass) { + $(jmpress).removeClass(current.jmpressClass); + } + $(jmpress).addClass(current.jmpressClass = 'step-' + $(delegated).attr('id') ); + if (current.jmpressDelegatedClass) { + $(jmpress).removeClass(current.jmpressDelegatedClass); + } + $(jmpress).addClass(current.jmpressDelegatedClass = 'delegating-step-' + $(el).attr('id') ); + + callCallback.call(this, "applyTarget", delegated, $.extend({ + canvas: canvas + ,area: area + ,beforeActive: activeDelegated + }, callbackData)); + + active = el; + activeSubstep = callbackData.substep; + activeDelegated = delegated; + + if(current.idleTimeout) { + clearTimeout(current.idleTimeout); + } + current.idleTimeout = setTimeout(function() { + callCallback.call(this, 'idle', delegated, callbackData); + }, Math.max(1, settings.transitionDuration - 100)); + + return delegated; + } + /** + * This should fix ANY kind of buggy scrolling + */ + function scrollFix() { + (function fix() { + if ($(container)[0].tagName === "BODY") { + try { + window.scrollTo(0, 0); + } catch(e) {} + } + $(container).scrollTop(0); + $(container).scrollLeft(0); + function check() { + if ($(container).scrollTop() !== 0 || + $(container).scrollLeft() !== 0) { + fix(); + } + } + setTimeout(check, 1); + setTimeout(check, 10); + setTimeout(check, 100); + setTimeout(check, 200); + setTimeout(check, 400); + }()); + } + /** + * Alias for select + */ + function goTo( el ) { + return select.call(this, el, "jump" ); + } + /** + * Goto Next Slide + * + * @return Object newly active slide + */ + function next() { + return select.call(this, callCallback.call(this, 'selectNext', active, { + stepData: $(active).data('stepData') + ,substep: activeSubstep + }), "next" ); + } + /** + * Goto Previous Slide + * + * @return Object newly active slide + */ + function prev() { + return select.call(this, callCallback.call(this, 'selectPrev', active, { + stepData: $(active).data('stepData') + ,substep: activeSubstep + }), "prev" ); + } + /** + * Goto First Slide + * + * @return Object newly active slide + */ + function home() { + return select.call(this, callCallback.call(this, 'selectHome', active, { + stepData: $(active).data('stepData') + }), "home" ); + } + /** + * Goto Last Slide + * + * @return Object newly active slide + */ + function end() { + return select.call(this, callCallback.call(this, 'selectEnd', active, { + stepData: $(active).data('stepData') + }), "end" ); + } + /** + * Manipulate the canvas + * + * @param props + * @return Object + */ + function canvasMod( props ) { + css(canvas, props || {}); + return $(canvas); + } + /** + * Return current step + * + * @return Object + */ + function getActive() { + return activeDelegated && $(activeDelegated); + } + /** + * fire a callback + * + * @param callbackName + * @param element + * @param eventData + * @return void + */ + function fire( callbackName, element, eventData ) { + if( !callbacks[callbackName] ) { + $.error( "callback " + callbackName + " is not registered." ); + } else { + return callCallback.call(this, callbackName, element, eventData); + } + } + + /** + * PUBLIC METHODS LIST + */ + jmpress.data("jmpressmethods", { + select: select + ,reselect: reselect + ,scrollFix: scrollFix + ,goTo: goTo + ,next: next + ,prev: prev + ,home: home + ,end: end + ,canvas: canvasMod + ,container: function() { return container; } + ,settings: function() { return settings; } + ,active: getActive + ,current: function() { return current; } + ,fire: fire + ,init: function(step) { + doStepInit.call(this, $(step), current.nextIdNumber++); + } + ,deinit: function(step) { + if(step) { + doStepDeinit.call(this, $(step)); + } else { + deinit.call(this); + } + } + ,reapply: doStepReapply + }); + + /** + * Check for support + * This will be removed in near future, when support is coming + * + * @access protected + * @return void + */ + function checkSupport() { + var ua = navigator.userAgent.toLowerCase(); + return (ua.search(/(iphone)|(ipod)|(android)/) === -1) || (ua.search(/(chrome)/) !== -1); + } + + // BEGIN INIT + + // CHECK FOR SUPPORT + if (checkSupport() === false) { + if (settings.notSupportedClass) { + jmpress.addClass(settings.notSupportedClass); + } + return; + } else { + if (settings.notSupportedClass) { + jmpress.removeClass(settings.notSupportedClass); + } + } + + // grabbing all steps + var steps = $(settings.stepSelector, jmpress); + + // GERNERAL INIT OF FRAME + container = jmpress; + area = $('<div />'); + canvas = $('<div />'); + $(jmpress).children().filter(steps).each(function() { + canvas.append( $( this ) ); + }); + if(settings.fullscreen) { + container = $('body'); + $("html").css({ + overflow: 'hidden' + }); + area = jmpress; + } + oldStyle.area = area.attr("style") || ""; + oldStyle.container = container.attr("style") || ""; + if(settings.fullscreen) { + container.css({ + height: '100%' + }); + jmpress.append( canvas ); + } else { + container.css({ + position: "relative" + }); + area.append( canvas ); + jmpress.append( area ); + } + + $(container).addClass(settings.containerClass); + $(area).addClass(settings.areaClass); + $(canvas).addClass(settings.canvasClass); + + document.documentElement.style.height = "100%"; + container.css({ + overflow: 'hidden' + }); + + var props = { + position: "absolute" + ,transitionDuration: '0s' + }; + props = $.extend({}, settings.animation, props); + css(area, props); + css(area, { + top: '50%' + ,left: '50%' + ,perspective: '1000px' + }); + css(canvas, props); + + current = {}; + + callCallback.call(this, 'beforeInit', null, {}); + + // INITIALIZE EACH STEP + steps.each(function( idx ) { + doStepInit.call(jmpress, this, idx ); + }); + current.nextIdNumber = steps.length; + + callCallback.call(this, 'afterInit', null, {}); + + // START + select.call(this, callCallback.call(this, 'selectInitialStep', "init", {}) ); + + if (settings.initClass) { + $(steps).removeClass(settings.initClass); + } + } + /** + * Return default settings + * + * @return Object + */ + function getDefaults() { + return defaults; + } + /** + * Register a callback or a jmpress function + * + * @access public + * @param name String the name of the callback or function + * @param func Function? the function to be added + */ + function register(name, func) { + if( $.isFunction(func) ) { + if( methods[name] ) { + $.error( "function " + name + " is already registered." ); + } else { + methods[name] = func; + } + } else { + if( callbacks[name] ) { + $.error( "callback " + name + " is already registered." ); + } else { + callbacks[name] = 1; + defaults[name] = []; + } + } + } + /** + * Set CSS on element w/ prefixes + * + * @return Object element which properties were set + * + * TODO: Consider bypassing pfx and blindly set as jQuery + * already checks for support + */ + function css( el, props ) { + var key, pkey, cssObj = {}; + for ( key in props ) { + if ( props.hasOwnProperty(key) ) { + pkey = pfx(key); + if ( pkey !== null ) { + cssObj[pkey] = props[key]; + } + } + } + $(el).css(cssObj); + return el; + } + /** + * Return dataset for element + * + * @param el element + * @return Object + */ + function dataset( el ) { + if ( $(el)[0].dataset ) { + return $.extend({}, $(el)[0].dataset); + } + function toCamelcase( str ) { + str = str.split( '-' ); + for( var i = 1; i < str.length; i++ ) { + str[i] = str[i].substr(0, 1).toUpperCase() + str[i].substr(1); + } + return str.join( '' ); + } + var returnDataset = {}; + var attrs = $(el)[0].attributes; + $.each(attrs, function ( idx, attr ) { + if ( attr.nodeName.substr(0, 5) === "data-" ) { + returnDataset[ toCamelcase(attr.nodeName.substr(5)) ] = attr.nodeValue; + } + }); + return returnDataset; + } + /** + * Returns true, if jmpress is initialized + * + * @return bool + */ + function initialized() { + return !!$(this).data("jmpressmethods"); + } + + + /** + * PUBLIC STATIC METHODS LIST + */ + var methods = { + init: init + ,initialized: initialized + ,deinit: function() {} + ,css: css + ,pfx: pfx + ,defaults: getDefaults + ,register: register + ,dataset: dataset + }; + + /** + * $.jmpress() + */ + $.fn.jmpress = function( method ) { + function f() { + var jmpressmethods = $(this).data("jmpressmethods"); + if ( jmpressmethods && jmpressmethods[method] ) { + return jmpressmethods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( methods[method] ) { + return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( callbacks[method] && jmpressmethods ) { + var settings = jmpressmethods.settings(); + var func = Array.prototype.slice.call( arguments, 1 )[0]; + if ($.isFunction( func )) { + settings[method] = settings[method] || []; + settings[method].push(func); + } + } else if ( typeof method === 'object' || ! method ) { + return init.apply( this, arguments ); + } else { + $.error( 'Method ' + method + ' does not exist on jQuery.jmpress' ); + } + // to allow chaining + return this; + } + var args = arguments; + var result; + $(this).each(function(idx, element) { + result = f.apply(element, args); + }); + return result; + }; + $.extend({ + jmpress: function( method ) { + if ( methods[method] ) { + return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( callbacks[method] ) { + // plugin interface + var func = Array.prototype.slice.call( arguments, 1 )[0]; + if ($.isFunction( func )) { + defaults[method].push(func); + } else { + $.error( 'Second parameter should be a function: $.jmpress( callbackName, callbackFunction )' ); + } + } else { + $.error( 'Method ' + method + ' does not exist on jQuery.jmpress' ); + } + } + }); + +}(jQuery, document, window)); + +/* + * near.js + * Find steps near each other + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + // add near( selector, backwards = false) to jquery + + + function checkAndGo( elements, func, selector, backwards ) { + var next; + elements.each(function(idx, element) { + if(backwards) { + next = func(element, selector, backwards); + if (next) { + return false; + } + } + if( $(element).is(selector) ) { + next = element; + return false; + } + if(!backwards) { + next = func(element, selector, backwards); + if (next) { + return false; + } + } + }); + return next; + } + function findNextInChildren(item, selector, backwards) { + var children = $(item).children(); + if(backwards) { + children = $(children.get().reverse()); + } + return checkAndGo( children, findNextInChildren, selector, backwards ); + } + function findNextInSiblings(item, selector, backwards) { + return checkAndGo( + $(item)[backwards ? "prevAll" : "nextAll"](), + findNextInChildren, selector, backwards ); + } + function findNextInParents(item, selector, backwards) { + var next; + var parents = $(item).parents(); + parents = $(parents.get()); + $.each(parents.get(), function(idx, element) { + if( backwards && $(element).is(selector) ) { + next = element; + return false; + } + next = findNextInSiblings(element, selector, backwards); + if(next) { + return false; + } + }); + return next; + } + + $.fn.near = function( selector, backwards ) { + var array = []; + $(this).each(function(idx, element) { + var near = (backwards ? + false : + findNextInChildren( element, selector, backwards )) || + findNextInSiblings( element, selector, backwards ) || + findNextInParents( element, selector, backwards ); + if( near ) { + array.push(near); + } + }); + return $(array); + }; +}(jQuery, document, window)); +/* + * transform.js + * The engine that powers the transforms or falls back to other methods + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + /* FUNCTIONS */ + function toCssNumber(number) { + return (Math.round(10000*number)/10000)+""; + } + + /** + * 3D and 2D engines + */ + var engines = { + 3: { + transform: function( el, data ) { + var transform = 'translate(-50%,-50%)'; + $.each(data, function(idx, item) { + var coord = ["X", "Y", "Z"]; + var i; + if(item[0] === "translate") { // ["translate", x, y, z] + transform += " translate3d(" + toCssNumber(item[1] || 0) + "px," + toCssNumber(item[2] || 0) + "px," + toCssNumber(item[3] || 0) + "px)"; + } else if(item[0] === "rotate") { + var order = item[4] ? [1, 2, 3] : [3, 2, 1]; + for(i = 0; i < 3; i++) { + transform += " rotate" + coord[order[i]-1] + "(" + toCssNumber(item[order[i]] || 0) + "deg)"; + } + } else if(item[0] === "scale") { + for(i = 0; i < 3; i++) { + transform += " scale" + coord[i] + "(" + toCssNumber(item[i+1] || 1) + ")"; + } + } + }); + $.jmpress("css", el, $.extend({}, { transform: transform })); + } + } + ,2: { + transform: function( el, data ) { + var transform = 'translate(-50%,-50%)'; + $.each(data, function(idx, item) { + var coord = ["X", "Y"]; + if(item[0] === "translate") { // ["translate", x, y, z] + transform += " translate(" + toCssNumber(item[1] || 0) + "px," + toCssNumber(item[2] || 0) + "px)"; + } else if(item[0] === "rotate") { + transform += " rotate(" + toCssNumber(item[3] || 0) + "deg)"; + } else if(item[0] === "scale") { + for(var i = 0; i < 2; i++) { + transform += " scale" + coord[i] + "(" + toCssNumber(item[i+1] || 1) + ")"; + } + } + }); + $.jmpress("css", el, $.extend({}, { transform: transform })); + } + } + ,1: { + // CHECK IF SUPPORT IS REALLY NEEDED? + // this not even work without scaling... + // it may better to display the normal view + transform: function( el, data ) { + var anitarget = { top: 0, left: 0 }; + $.each(data, function(idx, item) { + var coord = ["X", "Y"]; + if(item[0] === "translate") { // ["translate", x, y, z] + anitarget.left = Math.round(item[1] || 0) + "px"; + anitarget.top = Math.round(item[2] || 0) + "px"; + } + }); + el.animate(anitarget, 1000); // TODO: Use animation duration + } + } + }; + + /** + * Engine to power cross-browser translate, scale and rotate. + */ + var engine = (function() { + if ($.jmpress("pfx", "perspective")) { + return engines[3]; + } else if ($.jmpress("pfx", "transform")) { + return engines[2]; + } else { + // CHECK IF SUPPORT IS REALLY NEEDED? + return engines[1]; + } + }()); + + $.jmpress("defaults").reasonableAnimation = {}; + $.jmpress("initStep", function( step, eventData ) { + var data = eventData.data; + var stepData = eventData.stepData; + var pf = parseFloat; + $.extend(stepData, { + x: pf(data.x) || 0 + ,y: pf(data.y) || 0 + ,z: pf(data.z) || 0 + ,r: pf(data.r) || 0 + ,phi: pf(data.phi) || 0 + ,rotate: pf(data.rotate) || 0 + ,rotateX: pf(data.rotateX) || 0 + ,rotateY: pf(data.rotateY) || 0 + ,rotateZ: pf(data.rotateZ) || 0 + ,revertRotate: false + ,scale: pf(data.scale) || 1 + ,scaleX: pf(data.scaleX) || false + ,scaleY: pf(data.scaleY) || false + ,scaleZ: pf(data.scaleZ) || 1 + }); + }); + $.jmpress("afterInit", function( nil, eventData ) { + var stepSelector = eventData.settings.stepSelector, + current = eventData.current; + current.perspectiveScale = 1; + current.maxNestedDepth = 0; + var nestedSteps = $(eventData.jmpress).find(stepSelector).children(stepSelector); + while(nestedSteps.length) { + current.maxNestedDepth++; + nestedSteps = nestedSteps.children(stepSelector); + } + }); + $.jmpress("applyStep", function( step, eventData ) { + $.jmpress("css", $(step), { + position: "absolute" + ,transformStyle: "preserve-3d" + }); + if ( eventData.parents.length > 0 ) { + $.jmpress("css", $(step), { + top: "50%" + ,left: "50%" + }); + } + var sd = eventData.stepData; + var transform = [ + ["translate", + sd.x || (sd.r * Math.sin(sd.phi*Math.PI/180)), + sd.y || (-sd.r * Math.cos(sd.phi*Math.PI/180)), + sd.z], + ["rotate", + sd.rotateX, + sd.rotateY, + sd.rotateZ || sd.rotate, + true], + ["scale", + sd.scaleX || sd.scale, + sd.scaleY || sd.scale, + sd.scaleZ || sd.scale] + ]; + engine.transform( step, transform ); + }); + $.jmpress("setActive", function( element, eventData ) { + var target = eventData.target; + var step = eventData.stepData; + var tf = target.transform = []; + target.perspectiveScale = 1; + + for(var i = eventData.current.maxNestedDepth; i > (eventData.parents.length || 0); i--) { + tf.push(["scale"], ["rotate"], ["translate"]); + } + + tf.push(["scale", + 1 / (step.scaleX || step.scale), + 1 / (step.scaleY || step.scale), + 1 / (step.scaleZ)]); + tf.push(["rotate", + -step.rotateX, + -step.rotateY, + -(step.rotateZ || step.rotate)]); + tf.push(["translate", + -(step.x || (step.r * Math.sin(step.phi*Math.PI/180))), + -(step.y || (-step.r * Math.cos(step.phi*Math.PI/180))), + -step.z]); + target.perspectiveScale *= (step.scaleX || step.scale); + + $.each(eventData.parents, function(idx, element) { + var step = $(element).data("stepData"); + tf.push(["scale", + 1 / (step.scaleX || step.scale), + 1 / (step.scaleY || step.scale), + 1 / (step.scaleZ)]); + tf.push(["rotate", + -step.rotateX, + -step.rotateY, + -(step.rotateZ || step.rotate)]); + tf.push(["translate", + -(step.x || (step.r * Math.sin(step.phi*Math.PI/180))), + -(step.y || (-step.r * Math.cos(step.phi*Math.PI/180))), + -step.z]); + target.perspectiveScale *= (step.scaleX || step.scale); + }); + + $.each(tf, function(idx, item) { + if(item[0] !== "rotate") { + return; + } + function lowRotate(name) { + if(eventData.current["rotate"+name+"-"+idx] === undefined) { + eventData.current["rotate"+name+"-"+idx] = item[name] || 0; + } + var cur = eventData.current["rotate"+name+"-"+idx], tar = item[name] || 0, + curmod = cur % 360, tarmod = tar % 360; + if(curmod < 0) { + curmod += 360; + } + if(tarmod < 0) { + tarmod += 360; + } + var diff = tarmod - curmod; + if(diff < -180) { + diff += 360; + } else if(diff > 180) { + diff -= 360; + } + eventData.current["rotate"+name+"-"+idx] = item[name] = cur + diff; + } + lowRotate(1); + lowRotate(2); + lowRotate(3); + }); + }); + $.jmpress("applyTarget", function( active, eventData ) { + + var target = eventData.target, + props, step = eventData.stepData, + settings = eventData.settings, + zoomin = target.perspectiveScale * 1.3 < eventData.current.perspectiveScale, + zoomout = target.perspectiveScale > eventData.current.perspectiveScale * 1.3; + + // extract first scale from transform + var lastScale = -1; + $.each(target.transform, function(idx, item) { + if(item.length <= 1) { + return; + } + if(item[0] === "rotate" && + item[1] % 360 === 0 && + item[2] % 360 === 0 && + item[3] % 360 === 0) { + return; + } + if(item[0] === "scale") { + lastScale = idx; + } else { + return false; + } + }); + + if(lastScale !== eventData.current.oldLastScale) { + zoomin = zoomout = false; + eventData.current.oldLastScale = lastScale; + } + + var extracted = []; + if(lastScale !== -1) { + while(lastScale >= 0) { + if(target.transform[lastScale][0] === "scale") { + extracted.push(target.transform[lastScale]); + target.transform[lastScale] = ["scale"]; + } + lastScale--; + } + } + + var animation = settings.animation; + if(settings.reasonableAnimation[eventData.reason]) { + animation = $.extend({}, + animation, + settings.reasonableAnimation[eventData.reason]); + } + + props = { + // to keep the perspective look similar for different scales + // we need to 'scale' the perspective, too + perspective: Math.round(target.perspectiveScale * 1000) + "px" + }; + props = $.extend({}, animation, props); + if (!zoomin) { + props.transitionDelay = '0s'; + } + if (!eventData.beforeActive) { + props.transitionDuration = '0s'; + props.transitionDelay = '0s'; + } + $.jmpress("css", eventData.area, props); + engine.transform(eventData.area, extracted); + + props = $.extend({}, animation); + if (!zoomout) { + props.transitionDelay = '0s'; + } + if (!eventData.beforeActive) { + props.transitionDuration = '0s'; + props.transitionDelay = '0s'; + } + + eventData.current.perspectiveScale = target.perspectiveScale; + + $.jmpress("css", eventData.canvas, props); + engine.transform(eventData.canvas, target.transform); + }); + +}(jQuery, document, window)); +/* + * active.js + * Set the active classes on steps + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* DEFINES */ + var activeClass = 'activeClass', + nestedActiveClass = 'nestedActiveClass'; + + /* DEFAULTS */ + var defaults = $jmpress( 'defaults' ); + defaults[nestedActiveClass] = "nested-active"; + defaults[activeClass] = "active"; + + /* HOOKS */ + $jmpress( 'setInactive', function( step, eventData ) { + var settings = eventData.settings, + activeClassSetting = settings[activeClass], + nestedActiveClassSettings = settings[nestedActiveClass]; + if(activeClassSetting) { + $(step).removeClass( activeClassSetting ); + } + if(nestedActiveClassSettings) { + $.each(eventData.parents, function(idx, element) { + $(element).removeClass(nestedActiveClassSettings); + }); + } + }); + $jmpress( 'setActive', function( step, eventData ) { + var settings = eventData.settings, + activeClassSetting = settings[activeClass], + nestedActiveClassSettings = settings[nestedActiveClass]; + if(activeClassSetting) { + $(step).addClass( activeClassSetting ); + } + if(nestedActiveClassSettings) { + $.each(eventData.parents, function(idx, element) { + $(element).addClass(nestedActiveClassSettings); + }); + } + }); + +}(jQuery, document, window)); +/* + * circular.js + * Repeat from start after end + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* FUNCTIONS */ + function firstSlide( step, eventData ) { + return $(this).find(eventData.settings.stepSelector).first(); + } + function prevOrNext( jmpress, step, eventData, prev) { + if (!step) { + return false; + } + var stepSelector = eventData.settings.stepSelector; + step = $(step); + do { + var item = step.near( stepSelector, prev ); + if (item.length === 0 || item.closest(jmpress).length === 0) { + item = $(jmpress).find(stepSelector)[prev?"last":"first"](); + } + if (!item.length) { + return false; + } + step = item; + } while( step.data("stepData").exclude ); + return step; + } + + /* HOOKS */ + $jmpress( 'initStep', function( step, eventData ) { + eventData.stepData.exclude = eventData.data.exclude && ["false", "no"].indexOf(eventData.data.exclude) === -1; + }); + $jmpress( 'selectInitialStep', firstSlide); + $jmpress( 'selectHome', firstSlide); + $jmpress( 'selectEnd', function( step, eventData ) { + return $(this).find(eventData.settings.stepSelector).last(); + }); + $jmpress( 'selectPrev', function( step, eventData ) { + return prevOrNext(this, step, eventData, true); + }); + $jmpress( 'selectNext', function( step, eventData ) { + return prevOrNext(this, step, eventData); + }); +}(jQuery, document, window)); +/* + * start.js + * Set the first step to start on + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + /* HOOKS */ + $.jmpress( 'selectInitialStep', function( nil, eventData ) { + return eventData.settings.start; + }); + +}(jQuery, document, window)); +/* + * ways.js + * Control the flow of the steps + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* FUNCTIONS */ + function routeFunc( jmpress, route, type ) { + for(var i = 0; i < route.length - 1; i++) { + var from = route[i]; + var to = route[i+1]; + if($(jmpress).jmpress("initialized")) { + $(from, jmpress).data("stepData")[type] = to; + } else { + $(from, jmpress).attr('data-' + type, to); + } + } + } + function selectPrevOrNext( step, eventData, attr, prev ) { + var stepData = eventData.stepData; + if(stepData[attr]) { + var near = $(step).near(stepData[attr], prev); + if(near && near.length) { + return near; + } + near = $(stepData[attr], this)[prev?"last":"first"](); + if(near && near.length) { + return near; + } + } + } + + /* EXPORTED FUNCTIONS */ + $jmpress( 'register', 'route', function( route, unidirectional, reversedRoute ) { + if( typeof route === "string" ) { + route = [route, route]; + } + routeFunc(this, route, reversedRoute ? "prev" : "next"); + if (!unidirectional) { + routeFunc(this, route.reverse(), reversedRoute ? "next" : "prev"); + } + }); + + /* HOOKS */ + $jmpress( 'initStep', function( step, eventData ) { + for(var attr in {next:1,prev:1}) { + eventData.stepData[attr] = eventData.data[attr]; + } + }); + $jmpress( 'selectNext', function( step, eventData ) { + return selectPrevOrNext.call(this, step, eventData, "next"); + }); + $jmpress( 'selectPrev', function( step, eventData ) { + return selectPrevOrNext.call(this, step, eventData, "prev", true); + }); + +}(jQuery, document, window)); +/* + * ajax.js + * Load steps via ajax + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* DEFINES */ + var afterStepLoaded = 'ajax:afterStepLoaded', + loadStep = 'ajax:loadStep'; + + /* REGISTER EVENTS */ + $jmpress('register', loadStep); + $jmpress('register', afterStepLoaded); + + /* DEFAULTS */ + $jmpress('defaults').ajaxLoadedClass = "loaded"; + + /* HOOKS */ + $jmpress('initStep', function( step, eventData ) { + eventData.stepData.src = $(step).attr('href') || eventData.data.src || false; + eventData.stepData.srcLoaded = false; + }); + $jmpress(loadStep, function( step, eventData ) { + var stepData = eventData.stepData, + href = stepData && stepData.src, + settings = eventData.settings; + if ( href ) { + $(step).addClass( settings.ajaxLoadedClass ); + stepData.srcLoaded = true; + $(step).load(href, function(response, status, xhr) { + $(eventData.jmpress).jmpress('fire', afterStepLoaded, step, $.extend({}, eventData, { + response: response + ,status: status + ,xhr: xhr + })); + }); + } + }); + $jmpress('idle', function( step, eventData ) { + if (!step) { + return; + } + var settings = eventData.settings, + jmpress = $(this), + stepData = eventData.stepData; + var siblings = $(step) + .add( $(step).near( settings.stepSelector ) ) + .add( $(step).near( settings.stepSelector, true) ) + .add( jmpress.jmpress('fire', 'selectPrev', step, { + stepData: $(step).data('stepData') + })) + .add( jmpress.jmpress('fire', 'selectNext', step, { + stepData: $(step).data('stepData') + })); + siblings.each(function() { + var step = this, + stepData = $(step).data("stepData"); + if(!stepData.src || stepData.srcLoaded) { + return; + } + jmpress.jmpress('fire', loadStep, step, { + stepData: $(step).data('stepData') + }); + }); + }); + $jmpress("setActive", function(step, eventData) { + var stepData = $(step).data("stepData"); + if(!stepData.src || stepData.srcLoaded) { + return; + } + $(this).jmpress('fire', loadStep, step, { + stepData: $(step).data('stepData') + }); + }); + +}(jQuery, document, window)); +/* + * hash.js + * Detect and set the URL hash + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress, + hashLink = "a[href^=#]"; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + /** + * getElementFromUrl + * + * @return String or undefined + */ + function getElementFromUrl(settings) { + // get id from url # by removing `#` or `#/` from the beginning, + // so both "fallback" `#slide-id` and "enhanced" `#/slide-id` will work + // TODO SECURITY check user input to be valid! + try { + var el = $( '#' + window.location.hash.replace(/^#\/?/,"") ); + return el.length > 0 && el.is(settings.stepSelector) ? el : undefined; + } catch(e) {} + } + function setHash(stepid) { + var shouldBeHash = "#/" + stepid; + if(window.history && window.history.pushState) { + // shouldBeHash = "#" + stepid; + // consider this for future versions + // it has currently issues, when startup with a link with hash (webkit) + if(window.location.hash !== shouldBeHash) { + window.history.pushState({}, '', shouldBeHash); + } + } else { + if(window.location.hash !== shouldBeHash) { + window.location.hash = shouldBeHash; + } + } + } + + /* DEFAULTS */ + $jmpress('defaults').hash = { + use: true + ,update: true + ,bindChange: true + // NOTICE: {use: true, update: false, bindChange: true} + // will cause a error after clicking on a link to the current step + }; + + /* HOOKS */ + $jmpress('selectInitialStep', function( step, eventData ) { + var settings = eventData.settings, + hashSettings = settings.hash, + current = eventData.current, + jmpress = $(this); + eventData.current.hashNamespace = ".jmpress-"+randomString(); + // HASH CHANGE EVENT + if ( hashSettings.use ) { + if ( hashSettings.bindChange ) { + $(window).bind('hashchange'+current.hashNamespace, function(event) { + var urlItem = getElementFromUrl(settings); + if ( jmpress.jmpress('initialized') ) { + jmpress.jmpress("scrollFix"); + } + if(urlItem && urlItem.length) { + if(urlItem.attr("id") !== jmpress.jmpress("active").attr("id")) { + jmpress.jmpress('select', urlItem); + } + setHash(urlItem.attr("id")); + } + event.preventDefault(); + }); + $(hashLink).on("click"+current.hashNamespace, function(event) { + var href = $(this).attr("href"); + try { + if($(href).is(settings.stepSelector)) { + jmpress.jmpress("select", href); + event.preventDefault(); + event.stopPropagation(); + } + } catch(e) {} + }); + } + return getElementFromUrl(settings); + } + }); + $jmpress('afterDeinit', function( nil, eventData ) { + $(hashLink).off(eventData.current.hashNamespace); + $(window).unbind(eventData.current.hashNamespace); + }); + $jmpress('setActive', function( step, eventData ) { + var settings = eventData.settings, + current = eventData.current; + // `#/step-id` is used instead of `#step-id` to prevent default browser + // scrolling to element in hash + if ( settings.hash.use && settings.hash.update ) { + clearTimeout(current.hashtimeout); + current.hashtimeout = setTimeout(function() { + setHash($(eventData.delegatedFrom).attr('id')); + }, settings.transitionDuration + 200); + } + }); + +}(jQuery, document, window)); +/* + * keyboard.js + * Keyboard event mapping and default keyboard actions + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress, + jmpressNext = "next", + jmpressPrev = "prev"; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + function stopEvent(event) { + event.preventDefault(); + event.stopPropagation(); + } + + /* DEFAULTS */ + $jmpress('defaults').keyboard = { + use: true + ,keys: { + 33: jmpressPrev // pg up + ,37: jmpressPrev // left + ,38: jmpressPrev // up + + ,9: jmpressNext+":"+jmpressPrev // tab + ,32: jmpressNext // space + ,34: jmpressNext // pg down + ,39: jmpressNext // right + ,40: jmpressNext // down + + ,36: "home" // home + + ,35: "end" // end + } + ,ignore: { + "INPUT": [ + 32 // space + ,37 // left + ,38 // up + ,39 // right + ,40 // down + ] + ,"TEXTAREA": [ + 32 // space + ,37 // left + ,38 // up + ,39 // right + ,40 // down + ] + ,"SELECT": [ + 38 // up + ,40 // down + ] + } + ,tabSelector: "a[href]:visible, :input:visible" + }; + + /* HOOKS */ + $jmpress('afterInit', function( nil, eventData ) { + var settings = eventData.settings, + keyboardSettings = settings.keyboard, + ignoreKeyboardSettings = keyboardSettings.ignore, + current = eventData.current, + jmpress = $(this); + + // tabindex make it focusable so that it can recieve key events + if(!settings.fullscreen) { + jmpress.attr("tabindex", 0); + } + + current.keyboardNamespace = ".jmpress-"+randomString(); + + // KEYPRESS EVENT: this fixes a Opera bug + $(settings.fullscreen ? document : jmpress) + .bind("keypress"+current.keyboardNamespace, function( event ) { + + for( var nodeName in ignoreKeyboardSettings ) { + if ( event.target.nodeName === nodeName && ignoreKeyboardSettings[nodeName].indexOf(event.which) !== -1 ) { + return; + } + } + if(event.which >= 37 && event.which <= 40 || event.which === 32) { + stopEvent(event); + } + }); + // KEYDOWN EVENT + $(settings.fullscreen ? document : jmpress) + .bind("keydown"+current.keyboardNamespace, function( event ) { + var eventTarget = $(event.target); + + if ( !settings.fullscreen && !eventTarget.closest(jmpress).length || !keyboardSettings.use ) { + return; + } + + for( var nodeName in ignoreKeyboardSettings ) { + if ( eventTarget[0].nodeName === nodeName && ignoreKeyboardSettings[nodeName].indexOf(event.which) !== -1 ) { + return; + } + } + + var reverseSelect = false; + var nextFocus; + if (event.which === 9) { + // tab + if ( !eventTarget.closest( jmpress.jmpress('active') ).length ) { + if ( !event.shiftKey ) { + nextFocus = jmpress.jmpress('active').find("a[href], :input").filter(":visible").first(); + } else { + reverseSelect = true; + } + } else { + nextFocus = eventTarget.near( keyboardSettings.tabSelector, event.shiftKey ); + if( !$(nextFocus) + .closest( settings.stepSelector ) + .is(jmpress.jmpress('active') ) ) { + nextFocus = undefined; + } + } + if( nextFocus && nextFocus.length > 0 ) { + nextFocus.focus(); + jmpress.jmpress("scrollFix"); + stopEvent(event); + return; + } else { + if(event.shiftKey) { + reverseSelect = true; + } + } + } + + var action = keyboardSettings.keys[ event.which ]; + if ( typeof action === "string" ) { + if (action.indexOf(":") !== -1) { + action = action.split(":"); + action = event.shiftKey ? action[1] : action[0]; + } + jmpress.jmpress( action ); + stopEvent(event); + } else if ( $.isFunction(action) ) { + action.call(jmpress, event); + } else if ( action ) { + jmpress.jmpress.apply( jmpress, action ); + stopEvent(event); + } + + if (reverseSelect) { + // tab + nextFocus = jmpress.jmpress('active').find("a[href], :input").filter(":visible").last(); + nextFocus.focus(); + jmpress.jmpress("scrollFix"); + } + }); + }); + $jmpress('afterDeinit', function( nil, eventData ) { + $(document).unbind(eventData.current.keyboardNamespace); + }); + + +}(jQuery, document, window)); +/* + * viewport.js + * Scale to fit a given viewport + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + + var browser = (function() { + var ua = navigator.userAgent.toLowerCase(); + var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || + /(webkit)[ \/]([\w.]+)/.exec(ua) || + /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || + /(msie) ([\w.]+)/.exec(ua) || + ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || + []; + return match[1] || ""; + }()); + + var defaults = $.jmpress("defaults"); + defaults.viewPort = { + width: false + ,height: false + ,maxScale: 0 + ,minScale: 0 + ,zoomable: 0 + ,zoomBindMove: true + ,zoomBindWheel: true + }; + var keys = defaults.keyboard.keys; + keys[browser === 'mozilla' ? 107 : 187] = "zoomIn"; // + + keys[browser === 'mozilla' ? 109 : 189] = "zoomOut"; // - + defaults.reasonableAnimation.resize = { + transitionDuration: '0s' + ,transitionDelay: '0ms' + }; + defaults.reasonableAnimation.zoom = { + transitionDuration: '0s' + ,transitionDelay: '0ms' + }; + $.jmpress("initStep", function( step, eventData ) { + for(var variable in {"viewPortHeight":1, "viewPortWidth":1, "viewPortMinScale":1, "viewPortMaxScale":1, "viewPortZoomable":1}) { + eventData.stepData[variable] = eventData.data[variable] && parseFloat(eventData.data[variable]); + } + }); + $.jmpress("afterInit", function( nil, eventData ) { + var jmpress = this; + eventData.current.viewPortNamespace = ".jmpress-"+randomString(); + $(window).bind("resize"+eventData.current.viewPortNamespace, function (event) { + $(jmpress).jmpress("reselect", "resize"); + }); + eventData.current.userZoom = 0; + eventData.current.userTranslateX = 0; + eventData.current.userTranslateY = 0; + if(eventData.settings.viewPort.zoomBindWheel) { + $(eventData.settings.fullscreen ? document : this) + .bind("mousewheel"+eventData.current.viewPortNamespace+" DOMMouseScroll"+eventData.current.viewPortNamespace, function( event, delta ) { + delta = delta || event.originalEvent.wheelDelta || -event.originalEvent.detail /* mozilla */; + var direction = (delta / Math.abs(delta)); + if(direction < 0) { + $(eventData.jmpress).jmpress("zoomOut", event.originalEvent.x, event.originalEvent.y); + } else if(direction > 0) { + $(eventData.jmpress).jmpress("zoomIn", event.originalEvent.x, event.originalEvent.y); + } + return false; + }); + } + if(eventData.settings.viewPort.zoomBindMove) { + $(eventData.settings.fullscreen ? document : this).bind("mousedown"+eventData.current.viewPortNamespace, function (event) { + if(eventData.current.userZoom) { + eventData.current.userTranslating = { x: event.clientX, y: event.clientY }; + event.preventDefault(); + event.stopImmediatePropagation(); + } + }).bind("mousemove"+eventData.current.viewPortNamespace, function (event) { + var userTranslating = eventData.current.userTranslating; + if(userTranslating) { + $(jmpress).jmpress("zoomTranslate", event.clientX - userTranslating.x, event.clientY - userTranslating.y); + userTranslating.x = event.clientX; + userTranslating.y = event.clientY; + event.preventDefault(); + event.stopImmediatePropagation(); + } + }).bind("mouseup"+eventData.current.viewPortNamespace, function (event) { + if(eventData.current.userTranslating) { + eventData.current.userTranslating = undefined; + event.preventDefault(); + event.stopImmediatePropagation(); + } + }); + } + }); + function maxAbs(value, range) { + return Math.max(Math.min(value, range), -range); + } + function zoom(x, y, direction) { + var current = $(this).jmpress("current"), + settings = $(this).jmpress("settings"), + stepData = $(this).jmpress("active").data("stepData"), + container = $(this).jmpress("container"); + if(current.userZoom === 0 && direction < 0) { + return; + } + var zoomableSteps = stepData.viewPortZoomable || settings.viewPort.zoomable; + if(current.userZoom === zoomableSteps && direction > 0) { + return; + } + current.userZoom += direction; + + var halfWidth = $(container).innerWidth()/2, + halfHeight = $(container).innerHeight()/2; + + x = x ? x - halfWidth : x; + y = y ? y - halfHeight : y; + + // TODO this is not perfect... too much math... :( + current.userTranslateX = + maxAbs(current.userTranslateX - direction * x / current.zoomOriginWindowScale / zoomableSteps, + halfWidth * current.userZoom * current.userZoom / zoomableSteps); + current.userTranslateY = + maxAbs(current.userTranslateY - direction * y / current.zoomOriginWindowScale / zoomableSteps, + halfHeight * current.userZoom * current.userZoom / zoomableSteps); + + $(this).jmpress("reselect", "zoom"); + } + $.jmpress("register", "zoomIn", function(x, y) { + zoom.call(this, x||0, y||0, 1); + }); + $.jmpress("register", "zoomOut", function(x, y) { + zoom.call(this, x||0, y||0, -1); + }); + $.jmpress("register", "zoomTranslate", function(x, y) { + var current = $(this).jmpress("current"), + settings = $(this).jmpress("settings"), + stepData = $(this).jmpress("active").data("stepData"), + container = $(this).jmpress("container"); + var zoomableSteps = stepData.viewPortZoomable || settings.viewPort.zoomable; + var halfWidth = $(container).innerWidth(), + halfHeight = $(container).innerHeight(); + current.userTranslateX = + maxAbs(current.userTranslateX + x / current.zoomOriginWindowScale, + halfWidth * current.userZoom * current.userZoom / zoomableSteps); + current.userTranslateY = + maxAbs(current.userTranslateY + y / current.zoomOriginWindowScale, + halfHeight * current.userZoom * current.userZoom / zoomableSteps); + $(this).jmpress("reselect", "zoom"); + }); + $.jmpress('afterDeinit', function( nil, eventData ) { + $(eventData.settings.fullscreen ? document : this).unbind(eventData.current.viewPortNamespace); + $(window).unbind(eventData.current.viewPortNamespace); + }); + $.jmpress("setActive", function( step, eventData ) { + var viewPort = eventData.settings.viewPort; + var viewPortHeight = eventData.stepData.viewPortHeight || viewPort.height; + var viewPortWidth = eventData.stepData.viewPortWidth || viewPort.width; + var viewPortMaxScale = eventData.stepData.viewPortMaxScale || viewPort.maxScale; + var viewPortMinScale = eventData.stepData.viewPortMinScale || viewPort.minScale; + // Correct the scale based on the window's size + var windowScaleY = viewPortHeight && $(eventData.container).innerHeight()/viewPortHeight; + var windowScaleX = viewPortWidth && $(eventData.container).innerWidth()/viewPortWidth; + var windowScale = (windowScaleX || windowScaleY) && Math.min( windowScaleX || windowScaleY, windowScaleY || windowScaleX ); + + if(windowScale) { + windowScale = windowScale || 1; + if(viewPortMaxScale) { + windowScale = Math.min(windowScale, viewPortMaxScale); + } + if(viewPortMinScale) { + windowScale = Math.max(windowScale, viewPortMinScale); + } + + var zoomableSteps = eventData.stepData.viewPortZoomable || eventData.settings.viewPort.zoomable; + if(zoomableSteps) { + var diff = (1/windowScale) - (1/viewPortMaxScale); + diff /= zoomableSteps; + windowScale = 1/((1/windowScale) - diff * eventData.current.userZoom); + } + + eventData.target.transform.reverse(); + if(eventData.current.userTranslateX && eventData.current.userTranslateY) { + eventData.target.transform.push(["translate", eventData.current.userTranslateX, eventData.current.userTranslateY, 0]); + } else { + eventData.target.transform.push(["translate"]); + } + eventData.target.transform.push(["scale", + windowScale, + windowScale, + 1]); + eventData.target.transform.reverse(); + eventData.target.perspectiveScale /= windowScale; + } + eventData.current.zoomOriginWindowScale = windowScale; + }); + $.jmpress("setInactive", function( step, eventData ) { + if(!eventData.nextStep || !step || $(eventData.nextStep).attr("id") !== $(step).attr("id")) { + eventData.current.userZoom = 0; + eventData.current.userTranslateX = 0; + eventData.current.userTranslateY = 0; + } + }); + +}(jQuery, document, window)); + +/* + * mouse.js + * Clicking to select a step + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + + /* DEFAULTS */ + $jmpress("defaults").mouse = { + clickSelects: true + }; + + /* HOOKS */ + $jmpress("afterInit", function( nil, eventData ) { + var settings = eventData.settings, + stepSelector = settings.stepSelector, + current = eventData.current, + jmpress = $(this); + current.clickableStepsNamespace = ".jmpress-"+randomString(); + jmpress.bind("click"+current.clickableStepsNamespace, function(event) { + if (!settings.mouse.clickSelects || current.userZoom) { + return; + } + + // get clicked step + var clickedStep = $(event.target).closest(stepSelector); + + // clicks on the active step do default + if ( clickedStep.is( jmpress.jmpress("active") ) ) { + return; + } + + if (clickedStep.length) { + // select the clicked step + jmpress.jmpress("select", clickedStep[0], "click"); + event.preventDefault(); + event.stopPropagation(); + } + }); + }); + $jmpress('afterDeinit', function( nil, eventData ) { + $(this).unbind(eventData.current.clickableStepsNamespace); + }); + +}(jQuery, document, window)); +/* + * mobile.js + * Adds support for swipe on touch supported browsers + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + + /* HOOKS */ + $jmpress( 'afterInit', function( step, eventData ) { + var settings = eventData.settings, + current = eventData.current, + jmpress = eventData.jmpress; + current.mobileNamespace = ".jmpress-"+randomString(); + var data, start = [0,0]; + $(settings.fullscreen ? document : jmpress) + .bind("touchstart"+current.mobileNamespace, function( event ) { + + data = event.originalEvent.touches[0]; + start = [ data.pageX, data.pageY ]; + + }).bind("touchmove"+current.mobileNamespace, function( event ) { + data = event.originalEvent.touches[0]; + event.preventDefault(); + return false; + }).bind("touchend"+current.mobileNamespace, function( event ) { + var end = [ data.pageX, data.pageY ], + diff = [ end[0]-start[0], end[1]-start[1] ]; + + if(Math.max(Math.abs(diff[0]), Math.abs(diff[1])) > 50) { + diff = Math.abs(diff[0]) > Math.abs(diff[1]) ? diff[0] : diff[1]; + $(jmpress).jmpress(diff > 0 ? "prev" : "next"); + event.preventDefault(); + return false; + } + }); + }); + $jmpress('afterDeinit', function( nil, eventData ) { + var settings = eventData.settings, + current = eventData.current, + jmpress = eventData.jmpress; + $(settings.fullscreen ? document : jmpress).unbind(current.mobileNamespace); + }); + +}(jQuery, document, window)); +/* + * templates.js + * The amazing template engine + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress, + templateFromParentIdent = "_template_", + templateFromApplyIdent = "_applied_template_"; + + /* STATIC VARS */ + var templates = {}; + + /* FUNCTIONS */ + function addUndefined( target, values, prefix ) { + for( var name in values ) { + var targetName = name; + if ( prefix ) { + targetName = prefix + targetName.substr(0, 1).toUpperCase() + targetName.substr(1); + } + if ( $.isPlainObject(values[name]) ) { + addUndefined( target, values[name], targetName ); + } else if( target[targetName] === undefined ) { + target[targetName] = values[name]; + } + } + } + function applyChildrenTemplates( children, templateChildren ) { + if ($.isArray(templateChildren)) { + if (templateChildren.length < children.length) { + $.error("more nested steps than children in template"); + } else { + children.each(function(idx, child) { + child = $(child); + var tmpl = child.data(templateFromParentIdent) || {}; + addUndefined(tmpl, templateChildren[idx]); + child.data(templateFromParentIdent, tmpl); + }); + } + } else if($.isFunction(templateChildren)) { + children.each(function(idx, child) { + child = $(child); + var tmpl = child.data(templateFromParentIdent) || {}; + addUndefined(tmpl, templateChildren(idx, child, children)); + child.data(templateFromParentIdent, tmpl); + }); + } // TODO: else if(object) + } + function applyTemplate( data, element, template, eventData ) { + if (template.children) { + var children = element.children( eventData.settings.stepSelector ); + applyChildrenTemplates( children, template.children ); + } + applyTemplateData( data, template ); + } + function applyTemplateData( data, template ) { + addUndefined(data, template); + } + + /* HOOKS */ + $jmpress("beforeInitStep", function( step, eventData ) { + step = $(step); + var data = eventData.data, + templateFromAttr = data.template, + templateFromApply = step.data(templateFromApplyIdent), + templateFromParent = step.data(templateFromParentIdent); + if(templateFromAttr) { + $.each(templateFromAttr.split(" "), function(idx, tmpl) { + var template = templates[tmpl]; + applyTemplate( data, step, template, eventData ); + }); + } + if (templateFromApply) { + applyTemplate( data, step, templateFromApply, eventData ); + } + if (templateFromParent) { + applyTemplate( data, step, templateFromParent, eventData ); + step.data(templateFromParentIdent, null); + if(templateFromParent.template) { + $.each(templateFromParent.template.split(" "), function(idx, tmpl) { + var template = templates[tmpl]; + applyTemplate( data, step, template, eventData ); + }); + } + } + }); + $jmpress("beforeInit", function( nil, eventData ) { + var data = $jmpress("dataset", this), + dataTemplate = data.template, + stepSelector = eventData.settings.stepSelector; + if (dataTemplate) { + var template = templates[dataTemplate]; + applyChildrenTemplates( $(this).find(stepSelector).filter(function() { + return !$(this).parent().is(stepSelector); + }), template.children ); + } + }); + + /* EXPORTED FUNCTIONS */ + $jmpress("register", "template", function( name, tmpl ) { + if (templates[name]) { + templates[name] = $.extend(true, {}, templates[name], tmpl); + } else { + templates[name] = $.extend(true, {}, tmpl); + } + }); + $jmpress("register", "apply", function( selector, tmpl ) { + if( !tmpl ) { + // TODO ERROR because settings not found + var stepSelector = $(this).jmpress("settings").stepSelector; + applyChildrenTemplates( $(this).find(stepSelector).filter(function() { + return !$(this).parent().is(stepSelector); + }), selector ); + } else if($.isArray(tmpl)) { + applyChildrenTemplates( $(selector), tmpl ); + } else { + var template; + if(typeof tmpl === "string") { + template = templates[tmpl]; + } else { + template = $.extend(true, {}, tmpl); + } + $(selector).each(function(idx, element) { + element = $(element); + var tmpl = element.data(templateFromApplyIdent) || {}; + addUndefined(tmpl, template); + element.data(templateFromApplyIdent, tmpl); + }); + } + }); + +}(jQuery, document, window)); +/* + * jqevents.js + * Fires jQuery events + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + /* HOOKS */ + // the events should not bubble up the tree + // elsewise nested jmpress would cause buggy behavior + $.jmpress("setActive", function( step, eventData ) { + if(eventData.prevStep !== step) { + $(step).triggerHandler("enterStep"); + } + }); + $.jmpress("setInactive", function( step, eventData ) { + if(eventData.nextStep !== step) { + $(step).triggerHandler("leaveStep"); + } + }); + +}(jQuery, document, window)); +/* + * animation.js + * Apply custom animations to steps + */ +(function( $, document, window, undefined ) { + + 'use strict'; + + function parseSubstepInfo(str) { + var arr = str.split(" "); + var className = arr[0]; + var config = { willClass: "will-"+className, doClass: "do-"+className, hasClass: "has-"+className }; + var state = ""; + for(var i = 1; i < arr.length; i++) { + var s = arr[i]; + switch(state) { + case "": + if(s === "after") { + state = "after"; + } else { + $.warn("unknown keyword in '"+str+"'. '"+s+"' unknown."); + } + break; + case "after": + if(s.match(/^[1-9][0-9]*m?s?/)) { + var value = parseFloat(s); + if(s.indexOf("ms") !== -1) { + value *= 1; + } else if(s.indexOf("s") !== -1) { + value *= 1000; + } else if(s.indexOf("m") !== -1) { + value *= 60000; + } + config.delay = value; + } else { + config.after = Array.prototype.slice.call(arr, i).join(" "); + i = arr.length; + } + } + } + return config; + } + function find(array, selector, start, end) { + end = end || (array.length - 1); + start = start || 0; + for(var i = start; i < end + 1; i++) { + if($(array[i].element).is(selector)) { + return i; + } + } + } + function addOn(list, substep, delay) { + $.each(substep._on, function(idx, child) { + list.push({substep: child.substep, delay: child.delay + delay}); + addOn(list, child.substep, child.delay + delay); + }); + } + $.jmpress("defaults").customAnimationDataAttribute = "jmpress"; + $.jmpress("afterInit", function( nil, eventData ) { + eventData.current.animationTimeouts = []; + eventData.current.animationCleanupWaiting = []; + }); + $.jmpress("applyStep", function( step, eventData ) { + // read custom animation from elements + var substepsData = {}; + var listOfSubsteps = []; + $(step).find("[data-"+eventData.settings.customAnimationDataAttribute+"]") + .each(function(idx, element) { + if($(element).closest(eventData.settings.stepSelector).is(step)) { + listOfSubsteps.push({element: element}); + } + }); + if(listOfSubsteps.length === 0) { + return; + } + $.each(listOfSubsteps, function(idx, substep) { + substep.info = parseSubstepInfo( + $(substep.element).data(eventData.settings.customAnimationDataAttribute)); + $(substep.element).addClass(substep.info.willClass); + substep._on = []; + substep._after = null; + }); + var current = {_after: undefined, _on: [], info: {}}; // virtual zero step + $.each(listOfSubsteps, function(idx, substep) { + var other = substep.info.after; + if(other) { + if(other === "step") { + other = current; + } else if(other === "prev") { + other = listOfSubsteps[idx-1]; + } else { + var index = find(listOfSubsteps, other, 0, idx - 1); + if(index === undefined) { + index = find(listOfSubsteps, other); + } + other = (index === undefined || index === idx) ? listOfSubsteps[idx-1] : listOfSubsteps[index]; + } + } else { + other = listOfSubsteps[idx-1]; + } + if(other) { + if(!substep.info.delay) { + if(!other._after) { + other._after = substep; + return; + } + other = other._after; + } + other._on.push({substep: substep, delay: substep.info.delay || 0}); + } + }); + if(current._after === undefined && current._on.length === 0) { + var startStep = find(listOfSubsteps, eventData.stepData.startSubstep) || 0; + current._after = listOfSubsteps[startStep]; + } + var substepsInOrder = []; + function findNextFunc(idx, item) { + if(item.substep._after) { + current = item.substep._after; + return false; + } + } + do { + var substepList = [{substep: current, delay: 0}]; + addOn(substepList, current, 0); + substepsInOrder.push(substepList); + current = null; + $.each(substepList, findNextFunc); + } while(current); + substepsData.list = substepsInOrder; + $(step).data("substepsData", substepsData); + }); + $.jmpress("unapplyStep", function( step, eventData ) { + var substepsData = $(step).data("substepsData"); + if(substepsData) { + $.each(substepsData.list, function(idx, activeSubsteps) { + $.each(activeSubsteps, function(idx, substep) { + if(substep.substep.info.willClass) { + $(substep.substep.element).removeClass(substep.substep.info.willClass); + } + if(substep.substep.info.hasClass) { + $(substep.substep.element).removeClass(substep.substep.info.hasClass); + } + if(substep.substep.info.doClass) { + $(substep.substep.element).removeClass(substep.substep.info.doClass); + } + }); + }); + } + }); + $.jmpress("setActive", function(step, eventData) { + var substepsData = $(step).data("substepsData"); + if(!substepsData) { + return; + } + if(eventData.substep === undefined) { + eventData.substep = + (eventData.reason === "prev" ? + substepsData.list.length-1 : + 0 + ); + } + var substep = eventData.substep; + $.each(eventData.current.animationTimeouts, function(idx, timeout) { + clearTimeout(timeout); + }); + eventData.current.animationTimeouts = []; + $.each(substepsData.list, function(idx, activeSubsteps) { + var applyHas = idx < substep; + var applyDo = idx <= substep; + $.each(activeSubsteps, function(idx, substep) { + if(substep.substep.info.hasClass) { + $(substep.substep.element)[(applyHas?"add":"remove")+"Class"](substep.substep.info.hasClass); + } + function applyIt() { + $(substep.substep.element).addClass(substep.substep.info.doClass); + } + if(applyDo && !applyHas && substep.delay && eventData.reason !== "prev") { + if(substep.substep.info.doClass) { + $(substep.substep.element).removeClass(substep.substep.info.doClass); + eventData.current.animationTimeouts.push(setTimeout(applyIt, substep.delay)); + } + } else { + if(substep.substep.info.doClass) { + $(substep.substep.element)[(applyDo?"add":"remove")+"Class"](substep.substep.info.doClass); + } + } + }); + }); + }); + $.jmpress("setInactive", function(step, eventData) { + if(eventData.nextStep === step) { + return; + } + function cleanupAnimation( substepsData ) { + $.each(substepsData.list, function(idx, activeSubsteps) { + $.each(activeSubsteps, function(idx, substep) { + if(substep.substep.info.hasClass) { + $(substep.substep.element).removeClass(substep.substep.info.hasClass); + } + if(substep.substep.info.doClass) { + $(substep.substep.element).removeClass(substep.substep.info.doClass); + } + }); + }); + } + $.each(eventData.current.animationCleanupWaiting, function(idx, item) { + cleanupAnimation(item); + }); + eventData.current.animationCleanupWaiting = []; + var substepsData = $(step).data("substepsData"); + if(substepsData) { + eventData.current.animationCleanupWaiting.push( substepsData ); + } + }); + $.jmpress("selectNext", function( step, eventData ) { + if(eventData.substep === undefined) { + return; + } + var substepsData = $(step).data("substepsData"); + if(!substepsData) { + return; + } + if(eventData.substep < substepsData.list.length-1) { + return {step: step, substep: eventData.substep+1}; + } + }); + $.jmpress("selectPrev", function( step, eventData ) { + if(eventData.substep === undefined) { + return; + } + var substepsData = $(step).data("substepsData"); + if(!substepsData) { + return; + } + if(eventData.substep > 0) { + return {step: step, substep: eventData.substep-1}; + } + }); + +}(jQuery, document, window)); +/*! + * plugin for jmpress.js v0.4.5 + * + * Copyright 2013 Kyle Robinson Young @shama & Tobias Koppers @sokra + * Licensed MIT + * http://www.opensource.org/licenses/mit-license.php + *//* + * jmpress.toggle plugin + * For binding a key to toggle de/initialization of jmpress.js. + */ +(function( $, document, window, undefined ) { + 'use strict'; + $.jmpress("register", "toggle", function( key, config, initial ) { + var jmpress = this; + $(document).bind("keydown", function( event ) { + if ( event.keyCode === key ) { + if ($(jmpress).jmpress("initialized")) { + $(jmpress).jmpress("deinit"); + } else { + $(jmpress).jmpress(config); + } + } + }); + if ( initial ) { + $(jmpress).jmpress(config); + } + }); +}(jQuery, document, window)); + +/* + * jmpress.secondary plugin + * Apply a secondary animation when step is selected. + */ +(function( $, document, window, undefined ) { + 'use strict'; + $.jmpress("initStep", function( step, eventData ) { + for(var name in eventData.data) { + if(name.indexOf("secondary") === 0) { + eventData.stepData[name] = eventData.data[name]; + } + } + }); + function exchangeIf(childStepData, condition, step) { + if(childStepData.secondary && + childStepData.secondary.split(" ").indexOf(condition) !== -1) { + for(var name in childStepData) { + if(name.length > 9 && name.indexOf("secondary") === 0) { + var tmp = childStepData[name]; + var normal = name.substr(9); + normal = normal.substr(0, 1).toLowerCase() + normal.substr(1); + childStepData[name] = childStepData[normal]; + childStepData[normal] = tmp; + } + } + $(this).jmpress("reapply", $(step)); + } + } + $.jmpress("beforeActive", function( step, eventData ) { + exchangeIf.call(eventData.jmpress, $(step).data("stepData"), "self", step); + var parent = $(step).parent(); + $(parent) + .children(eventData.settings.stepSelector) + .each(function(idx, child) { + var childStepData = $(child).data("stepData"); + exchangeIf.call(eventData.jmpress, childStepData, "siblings", child); + }); + function grandchildrenFunc(idx, child) { + var childStepData = $(child).data("stepData"); + exchangeIf.call(eventData.jmpress, childStepData, "grandchildren", child); + } + for(var i = 1; i < eventData.parents.length; i++) { + $(eventData.parents[i]) + .children(eventData.settings.stepSelector) + .each(); + } + }); + $.jmpress("setInactive", function( step, eventData ) { + exchangeIf.call(eventData.jmpress, $(step).data("stepData"), "self", step); + var parent = $(step).parent(); + $(parent) + .children(eventData.settings.stepSelector) + .each(function(idx, child) { + var childStepData = $(child).data("stepData"); + exchangeIf.call(eventData.jmpress, childStepData, "siblings", child); + }); + function grandchildrenFunc(idx, child) { + var childStepData = $(child).data("stepData"); + exchangeIf.call(eventData.jmpress, childStepData, "grandchildren", child); + } + for(var i = 1; i < eventData.parents.length; i++) { + $(eventData.parents[i]) + .children(eventData.settings.stepSelector) + .each(grandchildrenFunc); + } + }); +}(jQuery, document, window)); + +/* + * jmpress.duration plugin + * For auto advancing steps after a given duration and optionally displaying a + * progress bar. + */ +(function( $, document, window, undefined ) { + 'use strict'; + + $.jmpress("defaults").duration = { + defaultValue: -1 + ,defaultAction: "next" + ,barSelector: undefined + ,barProperty: "width" + ,barPropertyStart: "0" + ,barPropertyEnd: "100%" + }; + $.jmpress("initStep", function( step, eventData ) { + eventData.stepData.duration = eventData.data.duration && parseInt(eventData.data.duration, 10); + eventData.stepData.durationAction = eventData.data.durationAction; + }); + $.jmpress("setInactive", function( step, eventData ) { + var settings = eventData.settings, + durationSettings = settings.duration, + current = eventData.current; + var dur = eventData.stepData.duration || durationSettings.defaultValue; + if( current.durationTimeout ) { + if( durationSettings.barSelector ) { + var css = { + transitionProperty: durationSettings.barProperty + ,transitionDuration: '0' + ,transitionDelay: '0' + ,transitionTimingFunction: 'linear' + }; + css[durationSettings.barProperty] = durationSettings.barPropertyStart; + var bars = $(durationSettings.barSelector); + $.jmpress("css", bars, css); + bars.each(function(idx, element) { + var next = $(element).next(); + var parent = $(element).parent(); + $(element).detach(); + if(next.length) { + next.insertBefore(element); + } else { + parent.append(element); + } + }); + } + clearTimeout(current.durationTimeout); + delete current.durationTimeout; + } + }); + $.jmpress("setActive", function( step, eventData ) { + var settings = eventData.settings, + durationSettings = settings.duration, + current = eventData.current; + var dur = eventData.stepData.duration || durationSettings.defaultValue; + if( dur && dur > 0 ) { + if( durationSettings.barSelector ) { + var css = { + transitionProperty: durationSettings.barProperty + ,transitionDuration: (dur-settings.transitionDuration*2/3-100)+"ms" + ,transitionDelay: (settings.transitionDuration*2/3)+'ms' + ,transitionTimingFunction: 'linear' + }; + css[durationSettings.barProperty] = durationSettings.barPropertyEnd; + $.jmpress("css", $(durationSettings.barSelector), css); + } + var jmpress = this; + if(current.durationTimeout) { + clearTimeout(current.durationTimeout); + current.durationTimeout = undefined; + } + current.durationTimeout = setTimeout(function() { + var action = eventData.stepData.durationAction || durationSettings.defaultAction; + $(jmpress).jmpress(action); + }, dur); + } + }); +}(jQuery, document, window)); + +/* + * jmpress.presentation-mode plugin + * Display a window for the presenter with notes and a control and view of the + * presentation + */ +(function( $, document, window, undefined ) { + + 'use strict'; + var $jmpress = $.jmpress; + + var PREFIX = "jmpress-presentation-"; + + /* FUNCTIONS */ + function randomString() { + return "" + Math.round(Math.random() * 100000, 0); + } + + /* DEFAULTS */ + $jmpress("defaults").presentationMode = { + use: true, + url: "presentation-screen.html", + notesUrl: false, + transferredValues: ["userZoom", "userTranslateX", "userTranslateY"] + }; + $jmpress("defaults").keyboard.keys[80] = "presentationPopup"; // p key + + /* HOOKS */ + $jmpress("afterInit", function( nil, eventData) { + var current = eventData.current; + + current.selectMessageListeners = []; + + if(eventData.settings.presentationMode.use) { + + window.addEventListener("message", function(event) { + // We do not test orgin, because we want to accept messages + // from all orgins + try { + if(typeof event.data !== "string" || event.data.indexOf(PREFIX) !== 0) { + return; + } + var json = JSON.parse(event.data.slice(PREFIX.length)); + switch(json.type) { + case "select": + $.each(eventData.settings.presentationMode.transferredValues, function(idx, name) { + eventData.current[name] = json[name]; + }); + if(/[a-z0-9\-]+/i.test(json.targetId) && typeof json.substep in {number:1,undefined:1}) { + $(eventData.jmpress).jmpress("select", {step: "#"+json.targetId, substep: json.substep}, json.reason); + } else { + $.error("For security reasons the targetId must match /[a-z0-9\\-]+/i and substep must be a number."); + } + break; + case "listen": + current.selectMessageListeners.push(event.source); + break; + case "ok": + clearTimeout(current.presentationPopupTimeout); + break; + case "read": + try { + event.source.postMessage(PREFIX + JSON.stringify({type: "url", url: window.location.href, notesUrl: eventData.settings.presentationMode.notesUrl}), "*"); + } catch(e) { + $.error("Cannot post message to source: " + e); + } + break; + default: + throw "Unknown message type: " + json.type; + } + } catch(e) { + $.error("Received message is malformed: " + e); + } + }); + try { + if(window.parent && window.parent !== window) { + window.parent.postMessage(PREFIX + JSON.stringify({ + "type": "afterInit" + }), "*"); + } + } catch(e) { + $.error("Cannot post message to parent: " + e); + } + } + }); + $jmpress("afterDeinit", function( nil, eventData) { + if(eventData.settings.presentationMode.use) { + try { + if(window.parent && window.parent !== window) { + window.parent.postMessage(PREFIX + JSON.stringify({ + "type": "afterDeinit" + }), "*"); + } + } catch(e) { + $.error("Cannot post message to parent: " + e); + } + } + }); + $jmpress("setActive", function( step, eventData) { + var stepId = $(eventData.delegatedFrom).attr("id"), + substep = eventData.substep, + reason = eventData.reason; + $.each(eventData.current.selectMessageListeners, function(idx, listener) { + try { + var msg = { + "type": "select", + "targetId": stepId, + "substep": substep, + "reason": reason + }; + $.each(eventData.settings.presentationMode.transferredValues, function(idx, name) { + msg[name] = eventData.current[name]; + }); + listener.postMessage(PREFIX + JSON.stringify(msg), "*"); + } catch(e) { + $.error("Cannot post message to listener: " + e); + } + }); + }); + $jmpress("register", "presentationPopup", function() { + function trySend() { + jmpress.jmpress("current").presentationPopupTimeout = setTimeout(trySend, 100); + try { + popup.postMessage(PREFIX + JSON.stringify({type: "url", url: window.location.href, notesUrl: jmpress.jmpress("settings").presentationMode.notesUrl}), "*"); + } catch(e) { + } + } + var jmpress = $(this), + popup; + if(jmpress.jmpress("settings").presentationMode.use) { + popup = window.open($(this).jmpress("settings").presentationMode.url); + jmpress.jmpress("current").presentationPopupTimeout = setTimeout(trySend, 100); + } + }); +}(jQuery, document, window)); diff --git a/plugins/jetpack/modules/shortcodes/js/jmpress.min.js b/plugins/jetpack/modules/shortcodes/js/jmpress.min.js new file mode 100644 index 00000000..c650c830 --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/js/jmpress.min.js @@ -0,0 +1,13 @@ +/*! + * jmpress.js v0.4.5 + * http://jmpressjs.github.com/jmpress.js + * + * A jQuery plugin to build a website on the infinite canvas. + * + * Copyright 2013 Kyle Robinson Young @shama & Tobias Koppers @sokra + * Licensed MIT + * http://www.opensource.org/licenses/mit-license.php + * + * Based on the foundation laid by Bartek Szopka @bartaz + */(function(e,t,s,a){"use strict";function r(e){if(e){var t=1+e.substr(1).search(/[A-Z]/),s=e.substr(0,t).toLowerCase(),a=e.substr(t).toLowerCase();return"-"+s+"-"+a}}function n(e){return e?e+",":""}function i(e){return e.length>0?e:null}function o(r){function n(t,s){var a=p(t),r={oldStyle:e(t).attr("style")||""},n={data:a,stepData:r};f.call(this,"beforeInitStep",e(t),n),r.delegate=a.delegate,f.call(this,"initStep",e(t),n),e(t).data("stepData",r),e(t).attr("id")||e(t).attr("id","step-"+(s+1)),f.call(this,"applyStep",e(t),n)}function o(t){var s=e(t).data("stepData");e(t).attr("style",s.oldStyle),f.call(this,"unapplyStep",e(t),{stepData:s})}function c(t){f.call(this,"unapplyStep",e(t),{stepData:t.data("stepData")}),f.call(this,"applyStep",e(t),{stepData:t.data("stepData")})}function l(){O&&f.call(this,"setInactive",O,{stepData:e(O).data("stepData"),reason:"deinit"}),Y.jmpressClass&&e(I).removeClass(Y.jmpressClass),f.call(this,"beforeDeinit",e(this),{}),e(A.stepSelector,I).each(function(){o.call(I,this)}),k.attr("style",Z.container),A.fullscreen&&e("html").attr("style",""),z.attr("style",Z.area),e(X).children().each(function(){I.append(e(this))}),A.fullscreen?X.remove():(X.remove(),z.remove()),f.call(this,"afterDeinit",e(this),{}),e(I).data("jmpressmethods",!1)}function f(t,s,a){a.settings=A,a.current=Y,a.container=k,a.parents=s?d(s):null,a.current=Y,a.jmpress=this;var r={};return e.each(A[t],function(e,t){r.value=t.call(I,s,a)||r.value}),r.value}function d(t){return e(t).parentsUntil(I).not(I).filter(A.stepSelector)}function v(e){return g({step:O,substep:F},e)}function g(t,s){var r;if(e.isPlainObject(t)&&(r=t.substep,t=t.step),"string"==typeof t&&(t=I.find(t).first()),!t||!e(t).data("stepData"))return!1;b.call(this);var n=e(t).data("stepData"),o=!1;if(f.call(this,"beforeChange",t,{stepData:n,reason:s,cancel:function(){o=!0}}),o)return a;var c={},l=t;e(t).data("stepData").delegate&&(l=i(e(t).parentsUntil(I).filter(A.stepSelector).filter(n.delegate))||i(e(t).near(n.delegate))||i(e(t).near(n.delegate,!0))||i(e(n.delegate,I)),l?n=l.data("stepData"):l=t),Q&&f.call(this,"setInactive",Q,{stepData:e(Q).data("stepData"),delegatedFrom:O,reason:s,target:c,nextStep:l,nextSubstep:r,nextStepData:n});var u={stepData:n,delegatedFrom:t,reason:s,target:c,substep:r,prevStep:Q,prevSubstep:F,prevStepData:Q&&e(Q).data("stepData")};return f.call(this,"beforeActive",l,u),f.call(this,"setActive",l,u),Y.jmpressClass&&e(I).removeClass(Y.jmpressClass),e(I).addClass(Y.jmpressClass="step-"+e(l).attr("id")),Y.jmpressDelegatedClass&&e(I).removeClass(Y.jmpressDelegatedClass),e(I).addClass(Y.jmpressDelegatedClass="delegating-step-"+e(t).attr("id")),f.call(this,"applyTarget",l,e.extend({canvas:X,area:z,beforeActive:Q},u)),O=t,F=u.substep,Q=l,Y.idleTimeout&&clearTimeout(Y.idleTimeout),Y.idleTimeout=setTimeout(function(){f.call(this,"idle",l,u)},Math.max(1,A.transitionDuration-100)),l}function b(){(function t(){function a(){(0!==e(k).scrollTop()||0!==e(k).scrollLeft())&&t()}if("BODY"===e(k)[0].tagName)try{s.scrollTo(0,0)}catch(r){}e(k).scrollTop(0),e(k).scrollLeft(0),setTimeout(a,1),setTimeout(a,10),setTimeout(a,100),setTimeout(a,200),setTimeout(a,400)})()}function y(e){return g.call(this,e,"jump")}function j(){return g.call(this,f.call(this,"selectNext",O,{stepData:e(O).data("stepData"),substep:F}),"next")}function D(){return g.call(this,f.call(this,"selectPrev",O,{stepData:e(O).data("stepData"),substep:F}),"prev")}function S(){return g.call(this,f.call(this,"selectHome",O,{stepData:e(O).data("stepData")}),"home")}function x(){return g.call(this,f.call(this,"selectEnd",O,{stepData:e(O).data("stepData")}),"end")}function w(t){return u(X,t||{}),e(X)}function C(){return Q&&e(Q)}function T(t,s,r){return h[t]?f.call(this,t,s,r):(e.error("callback "+t+" is not registered."),a)}function M(){var e=navigator.userAgent.toLowerCase();return-1===e.search(/(iphone)|(ipod)|(android)/)||-1!==e.search(/(chrome)/)}r=e.extend(!0,{},r||{});var P={},N=null;for(N in h)P[N]=e.isFunction(r[N])?[r[N]]:r[N],r[N]=[];var A=e.extend(!0,{},m,r);for(N in h)P[N]&&Array.prototype.push.apply(A[N],P[N]);var I=e(this),k=null,z=null,Z={container:"",area:""},X=null,Y=null,O=!1,F=null,Q=!1;if(I.data("jmpressmethods",{select:g,reselect:v,scrollFix:b,goTo:y,next:j,prev:D,home:S,end:x,canvas:w,container:function(){return k},settings:function(){return A},active:C,current:function(){return Y},fire:T,init:function(t){n.call(this,e(t),Y.nextIdNumber++)},deinit:function(t){t?o.call(this,e(t)):l.call(this)},reapply:c}),M()===!1)return A.notSupportedClass&&I.addClass(A.notSupportedClass),a;A.notSupportedClass&&I.removeClass(A.notSupportedClass);var E=e(A.stepSelector,I);k=I,z=e("<div />"),X=e("<div />"),e(I).children().filter(E).each(function(){X.append(e(this))}),A.fullscreen&&(k=e("body"),e("html").css({overflow:"hidden"}),z=I),Z.area=z.attr("style")||"",Z.container=k.attr("style")||"",A.fullscreen?(k.css({height:"100%"}),I.append(X)):(k.css({position:"relative"}),z.append(X),I.append(z)),e(k).addClass(A.containerClass),e(z).addClass(A.areaClass),e(X).addClass(A.canvasClass),t.documentElement.style.height="100%",k.css({overflow:"hidden"});var L={position:"absolute",transitionDuration:"0s"};L=e.extend({},A.animation,L),u(z,L),u(z,{top:"50%",left:"50%",perspective:"1000px"}),u(X,L),Y={},f.call(this,"beforeInit",null,{}),E.each(function(e){n.call(I,this,e)}),Y.nextIdNumber=E.length,f.call(this,"afterInit",null,{}),g.call(this,f.call(this,"selectInitialStep","init",{})),A.initClass&&e(E).removeClass(A.initClass)}function c(){return m}function l(t,s){e.isFunction(s)?g[t]?e.error("function "+t+" is already registered."):g[t]=s:h[t]?e.error("callback "+t+" is already registered."):(h[t]=1,m[t]=[])}function u(t,s){var a,r,n={};for(a in s)s.hasOwnProperty(a)&&(r=d(a),null!==r&&(n[r]=s[a]));return e(t).css(n),t}function p(t){function s(e){e=e.split("-");for(var t=1;e.length>t;t++)e[t]=e[t].substr(0,1).toUpperCase()+e[t].substr(1);return e.join("")}if(e(t)[0].dataset)return e.extend({},e(t)[0].dataset);var a={},r=e(t)[0].attributes;return e.each(r,function(e,t){"data-"===t.nodeName.substr(0,5)&&(a[s(t.nodeName.substr(5))]=t.nodeValue)}),a}function f(){return!!e(this).data("jmpressmethods")}var d=function(){var e=t.createElement("dummy").style,s="Webkit Moz O ms Khtml".split(" "),r={};return function(t){if(r[t]===a){var n=t.charAt(0).toUpperCase()+t.substr(1),i=(t+" "+s.join(n+" ")+n).split(" ");r[t]=null;for(var o in i)if(e[i[o]]!==a){r[t]=i[o];break}}return r[t]}}(),m={stepSelector:".step",containerClass:"",canvasClass:"",areaClass:"",notSupportedClass:"not-supported",fullscreen:!0,animation:{transformOrigin:"top left",transitionProperty:n(r(d("transform")))+n(r(d("perspective")))+"opacity",transitionDuration:"1s",transitionDelay:"500ms",transitionTimingFunction:"ease-in-out",transformStyle:"preserve-3d"},transitionDuration:1500},h={beforeChange:1,beforeInitStep:1,initStep:1,beforeInit:1,afterInit:1,beforeDeinit:1,afterDeinit:1,applyStep:1,unapplyStep:1,setInactive:1,beforeActive:1,setActive:1,selectInitialStep:1,selectPrev:1,selectNext:1,selectHome:1,selectEnd:1,idle:1,applyTarget:1};for(var v in h)m[v]=[];var g={init:o,initialized:f,deinit:function(){},css:u,pfx:d,defaults:c,register:l,dataset:p};e.fn.jmpress=function(t){function s(){var s=e(this).data("jmpressmethods");if(s&&s[t])return s[t].apply(this,Array.prototype.slice.call(arguments,1));if(g[t])return g[t].apply(this,Array.prototype.slice.call(arguments,1));if(h[t]&&s){var a=s.settings(),r=Array.prototype.slice.call(arguments,1)[0];e.isFunction(r)&&(a[t]=a[t]||[],a[t].push(r))}else{if("object"==typeof t||!t)return o.apply(this,arguments);e.error("Method "+t+" does not exist on jQuery.jmpress")}return this}var a,r=arguments;return e(this).each(function(e,t){a=s.apply(t,r)}),a},e.extend({jmpress:function(t){if(g[t])return g[t].apply(this,Array.prototype.slice.call(arguments,1));if(h[t]){var s=Array.prototype.slice.call(arguments,1)[0];e.isFunction(s)?m[t].push(s):e.error("Second parameter should be a function: $.jmpress( callbackName, callbackFunction )")}else e.error("Method "+t+" does not exist on jQuery.jmpress")}})})(jQuery,document,window),function(e){"use strict";function t(t,s,a,r){var n;return t.each(function(t,i){return r&&(n=s(i,a,r))?!1:e(i).is(a)?(n=i,!1):!r&&(n=s(i,a,r))?!1:undefined}),n}function s(a,r,n){var i=e(a).children();return n&&(i=e(i.get().reverse())),t(i,s,r,n)}function a(a,r,n){return t(e(a)[n?"prevAll":"nextAll"](),s,r,n)}function r(t,s,r){var n,i=e(t).parents();return i=e(i.get()),e.each(i.get(),function(t,i){return r&&e(i).is(s)?(n=i,!1):(n=a(i,s,r),n?!1:undefined)}),n}e.fn.near=function(t,n){var i=[];return e(this).each(function(e,o){var c=(n?!1:s(o,t,n))||a(o,t,n)||r(o,t,n);c&&i.push(c)}),e(i)}}(jQuery,document,window),function(e,t,s,a){"use strict";function r(e){return Math.round(1e4*e)/1e4+""}var n={3:{transform:function(t,s){var a="translate(-50%,-50%)";e.each(s,function(e,t){var s,n=["X","Y","Z"];if("translate"===t[0])a+=" translate3d("+r(t[1]||0)+"px,"+r(t[2]||0)+"px,"+r(t[3]||0)+"px)";else if("rotate"===t[0]){var i=t[4]?[1,2,3]:[3,2,1];for(s=0;3>s;s++)a+=" rotate"+n[i[s]-1]+"("+r(t[i[s]]||0)+"deg)"}else if("scale"===t[0])for(s=0;3>s;s++)a+=" scale"+n[s]+"("+r(t[s+1]||1)+")"}),e.jmpress("css",t,e.extend({},{transform:a}))}},2:{transform:function(t,s){var a="translate(-50%,-50%)";e.each(s,function(e,t){var s=["X","Y"];if("translate"===t[0])a+=" translate("+r(t[1]||0)+"px,"+r(t[2]||0)+"px)";else if("rotate"===t[0])a+=" rotate("+r(t[3]||0)+"deg)";else if("scale"===t[0])for(var n=0;2>n;n++)a+=" scale"+s[n]+"("+r(t[n+1]||1)+")"}),e.jmpress("css",t,e.extend({},{transform:a}))}},1:{transform:function(t,s){var a={top:0,left:0};e.each(s,function(e,t){"translate"===t[0]&&(a.left=Math.round(t[1]||0)+"px",a.top=Math.round(t[2]||0)+"px")}),t.animate(a,1e3)}}},i=function(){return e.jmpress("pfx","perspective")?n[3]:e.jmpress("pfx","transform")?n[2]:n[1]}();e.jmpress("defaults").reasonableAnimation={},e.jmpress("initStep",function(t,s){var a=s.data,r=s.stepData,n=parseFloat;e.extend(r,{x:n(a.x)||0,y:n(a.y)||0,z:n(a.z)||0,r:n(a.r)||0,phi:n(a.phi)||0,rotate:n(a.rotate)||0,rotateX:n(a.rotateX)||0,rotateY:n(a.rotateY)||0,rotateZ:n(a.rotateZ)||0,revertRotate:!1,scale:n(a.scale)||1,scaleX:n(a.scaleX)||!1,scaleY:n(a.scaleY)||!1,scaleZ:n(a.scaleZ)||1})}),e.jmpress("afterInit",function(t,s){var a=s.settings.stepSelector,r=s.current;r.perspectiveScale=1,r.maxNestedDepth=0;for(var n=e(s.jmpress).find(a).children(a);n.length;)r.maxNestedDepth++,n=n.children(a)}),e.jmpress("applyStep",function(t,s){e.jmpress("css",e(t),{position:"absolute",transformStyle:"preserve-3d"}),s.parents.length>0&&e.jmpress("css",e(t),{top:"50%",left:"50%"});var a=s.stepData,r=[["translate",a.x||a.r*Math.sin(a.phi*Math.PI/180),a.y||-a.r*Math.cos(a.phi*Math.PI/180),a.z],["rotate",a.rotateX,a.rotateY,a.rotateZ||a.rotate,!0],["scale",a.scaleX||a.scale,a.scaleY||a.scale,a.scaleZ||a.scale]];i.transform(t,r)}),e.jmpress("setActive",function(t,s){var r=s.target,n=s.stepData,i=r.transform=[];r.perspectiveScale=1;for(var o=s.current.maxNestedDepth;o>(s.parents.length||0);o--)i.push(["scale"],["rotate"],["translate"]);i.push(["scale",1/(n.scaleX||n.scale),1/(n.scaleY||n.scale),1/n.scaleZ]),i.push(["rotate",-n.rotateX,-n.rotateY,-(n.rotateZ||n.rotate)]),i.push(["translate",-(n.x||n.r*Math.sin(n.phi*Math.PI/180)),-(n.y||-n.r*Math.cos(n.phi*Math.PI/180)),-n.z]),r.perspectiveScale*=n.scaleX||n.scale,e.each(s.parents,function(t,s){var a=e(s).data("stepData");i.push(["scale",1/(a.scaleX||a.scale),1/(a.scaleY||a.scale),1/a.scaleZ]),i.push(["rotate",-a.rotateX,-a.rotateY,-(a.rotateZ||a.rotate)]),i.push(["translate",-(a.x||a.r*Math.sin(a.phi*Math.PI/180)),-(a.y||-a.r*Math.cos(a.phi*Math.PI/180)),-a.z]),r.perspectiveScale*=a.scaleX||a.scale}),e.each(i,function(e,t){function r(r){s.current["rotate"+r+"-"+e]===a&&(s.current["rotate"+r+"-"+e]=t[r]||0);var n=s.current["rotate"+r+"-"+e],i=t[r]||0,o=n%360,c=i%360;0>o&&(o+=360),0>c&&(c+=360);var l=c-o;-180>l?l+=360:l>180&&(l-=360),s.current["rotate"+r+"-"+e]=t[r]=n+l}"rotate"===t[0]&&(r(1),r(2),r(3))})}),e.jmpress("applyTarget",function(t,s){var r,n=s.target,o=(s.stepData,s.settings),c=1.3*n.perspectiveScale<s.current.perspectiveScale,l=n.perspectiveScale>1.3*s.current.perspectiveScale,u=-1;e.each(n.transform,function(e,t){return 1>=t.length||"rotate"===t[0]&&0===t[1]%360&&0===t[2]%360&&0===t[3]%360?a:"scale"!==t[0]?!1:(u=e,a)}),u!==s.current.oldLastScale&&(c=l=!1,s.current.oldLastScale=u);var p=[];if(-1!==u)for(;u>=0;)"scale"===n.transform[u][0]&&(p.push(n.transform[u]),n.transform[u]=["scale"]),u--;var f=o.animation;o.reasonableAnimation[s.reason]&&(f=e.extend({},f,o.reasonableAnimation[s.reason])),r={perspective:Math.round(1e3*n.perspectiveScale)+"px"},r=e.extend({},f,r),c||(r.transitionDelay="0s"),s.beforeActive||(r.transitionDuration="0s",r.transitionDelay="0s"),e.jmpress("css",s.area,r),i.transform(s.area,p),r=e.extend({},f),l||(r.transitionDelay="0s"),s.beforeActive||(r.transitionDuration="0s",r.transitionDelay="0s"),s.current.perspectiveScale=n.perspectiveScale,e.jmpress("css",s.canvas,r),i.transform(s.canvas,n.transform)})}(jQuery,document,window),function(e){"use strict";var t=e.jmpress,s="activeClass",a="nestedActiveClass",r=t("defaults");r[a]="nested-active",r[s]="active",t("setInactive",function(t,r){var n=r.settings,i=n[s],o=n[a];i&&e(t).removeClass(i),o&&e.each(r.parents,function(t,s){e(s).removeClass(o)})}),t("setActive",function(t,r){var n=r.settings,i=n[s],o=n[a];i&&e(t).addClass(i),o&&e.each(r.parents,function(t,s){e(s).addClass(o)})})}(jQuery,document,window),function(e){"use strict";function t(t,s){return e(this).find(s.settings.stepSelector).first()}function s(t,s,a,r){if(!s)return!1;var n=a.settings.stepSelector;s=e(s);do{var i=s.near(n,r);if((0===i.length||0===i.closest(t).length)&&(i=e(t).find(n)[r?"last":"first"]()),!i.length)return!1;s=i}while(s.data("stepData").exclude);return s}var a=e.jmpress;a("initStep",function(e,t){t.stepData.exclude=t.data.exclude&&-1===["false","no"].indexOf(t.data.exclude)}),a("selectInitialStep",t),a("selectHome",t),a("selectEnd",function(t,s){return e(this).find(s.settings.stepSelector).last()}),a("selectPrev",function(e,t){return s(this,e,t,!0)}),a("selectNext",function(e,t){return s(this,e,t)})}(jQuery,document,window),function(e){"use strict";e.jmpress("selectInitialStep",function(e,t){return t.settings.start})}(jQuery,document,window),function(e){"use strict";function t(t,s,a){for(var r=0;s.length-1>r;r++){var n=s[r],i=s[r+1];e(t).jmpress("initialized")?e(n,t).data("stepData")[a]=i:e(n,t).attr("data-"+a,i)}}function s(t,s,a,r){var n=s.stepData;if(n[a]){var i=e(t).near(n[a],r);if(i&&i.length)return i;if(i=e(n[a],this)[r?"last":"first"](),i&&i.length)return i}}var a=e.jmpress;a("register","route",function(e,s,a){"string"==typeof e&&(e=[e,e]),t(this,e,a?"prev":"next"),s||t(this,e.reverse(),a?"next":"prev")}),a("initStep",function(e,t){for(var s in{next:1,prev:1})t.stepData[s]=t.data[s]}),a("selectNext",function(e,t){return s.call(this,e,t,"next")}),a("selectPrev",function(e,t){return s.call(this,e,t,"prev",!0)})}(jQuery,document,window),function(e){"use strict";var t=e.jmpress,s="ajax:afterStepLoaded",a="ajax:loadStep";t("register",a),t("register",s),t("defaults").ajaxLoadedClass="loaded",t("initStep",function(t,s){s.stepData.src=e(t).attr("href")||s.data.src||!1,s.stepData.srcLoaded=!1}),t(a,function(t,a){var r=a.stepData,n=r&&r.src,i=a.settings;n&&(e(t).addClass(i.ajaxLoadedClass),r.srcLoaded=!0,e(t).load(n,function(r,n,i){e(a.jmpress).jmpress("fire",s,t,e.extend({},a,{response:r,status:n,xhr:i}))}))}),t("idle",function(t,s){if(t){var r=s.settings,n=e(this);s.stepData;var i=e(t).add(e(t).near(r.stepSelector)).add(e(t).near(r.stepSelector,!0)).add(n.jmpress("fire","selectPrev",t,{stepData:e(t).data("stepData")})).add(n.jmpress("fire","selectNext",t,{stepData:e(t).data("stepData")}));i.each(function(){var t=this,s=e(t).data("stepData");s.src&&!s.srcLoaded&&n.jmpress("fire",a,t,{stepData:e(t).data("stepData")})})}}),t("setActive",function(t){var s=e(t).data("stepData");s.src&&!s.srcLoaded&&e(this).jmpress("fire",a,t,{stepData:e(t).data("stepData")})})}(jQuery,document,window),function(e,t,s,a){"use strict";function r(){return""+Math.round(1e5*Math.random(),0)}function n(t){try{var r=e("#"+s.location.hash.replace(/^#\/?/,""));return r.length>0&&r.is(t.stepSelector)?r:a}catch(n){}}function i(e){var t="#/"+e;s.history&&s.history.pushState?s.location.hash!==t&&s.history.pushState({},"",t):s.location.hash!==t&&(s.location.hash=t)}var o=e.jmpress,c="a[href^=#]";o("defaults").hash={use:!0,update:!0,bindChange:!0},o("selectInitialStep",function(t,o){var l=o.settings,u=l.hash,p=o.current,f=e(this);return o.current.hashNamespace=".jmpress-"+r(),u.use?(u.bindChange&&(e(s).bind("hashchange"+p.hashNamespace,function(e){var t=n(l);f.jmpress("initialized")&&f.jmpress("scrollFix"),t&&t.length&&(t.attr("id")!==f.jmpress("active").attr("id")&&f.jmpress("select",t),i(t.attr("id"))),e.preventDefault()}),e(c).on("click"+p.hashNamespace,function(t){var s=e(this).attr("href");try{e(s).is(l.stepSelector)&&(f.jmpress("select",s),t.preventDefault(),t.stopPropagation())}catch(a){}})),n(l)):a}),o("afterDeinit",function(t,a){e(c).off(a.current.hashNamespace),e(s).unbind(a.current.hashNamespace)}),o("setActive",function(t,s){var a=s.settings,r=s.current;a.hash.use&&a.hash.update&&(clearTimeout(r.hashtimeout),r.hashtimeout=setTimeout(function(){i(e(s.delegatedFrom).attr("id"))},a.transitionDuration+200))})}(jQuery,document,window),function(e,t,s,a){"use strict";function r(){return""+Math.round(1e5*Math.random(),0)}function n(e){e.preventDefault(),e.stopPropagation()}var i=e.jmpress,o="next",c="prev";i("defaults").keyboard={use:!0,keys:{33:c,37:c,38:c,9:o+":"+c,32:o,34:o,39:o,40:o,36:"home",35:"end"},ignore:{INPUT:[32,37,38,39,40],TEXTAREA:[32,37,38,39,40],SELECT:[38,40]},tabSelector:"a[href]:visible, :input:visible"},i("afterInit",function(s,i){var o=i.settings,c=o.keyboard,l=c.ignore,u=i.current,p=e(this);o.fullscreen||p.attr("tabindex",0),u.keyboardNamespace=".jmpress-"+r(),e(o.fullscreen?t:p).bind("keypress"+u.keyboardNamespace,function(e){for(var t in l)if(e.target.nodeName===t&&-1!==l[t].indexOf(e.which))return;(e.which>=37&&40>=e.which||32===e.which)&&n(e)}),e(o.fullscreen?t:p).bind("keydown"+u.keyboardNamespace,function(t){var s=e(t.target);if((o.fullscreen||s.closest(p).length)&&c.use){for(var r in l)if(s[0].nodeName===r&&-1!==l[r].indexOf(t.which))return;var i,u=!1;if(9===t.which){if(s.closest(p.jmpress("active")).length?(i=s.near(c.tabSelector,t.shiftKey),e(i).closest(o.stepSelector).is(p.jmpress("active"))||(i=a)):t.shiftKey?u=!0:i=p.jmpress("active").find("a[href], :input").filter(":visible").first(),i&&i.length>0)return i.focus(),p.jmpress("scrollFix"),n(t),a;t.shiftKey&&(u=!0)}var f=c.keys[t.which];"string"==typeof f?(-1!==f.indexOf(":")&&(f=f.split(":"),f=t.shiftKey?f[1]:f[0]),p.jmpress(f),n(t)):e.isFunction(f)?f.call(p,t):f&&(p.jmpress.apply(p,f),n(t)),u&&(i=p.jmpress("active").find("a[href], :input").filter(":visible").last(),i.focus(),p.jmpress("scrollFix"))}})}),i("afterDeinit",function(s,a){e(t).unbind(a.current.keyboardNamespace)})}(jQuery,document,window),function(e,t,s,a){"use strict";function r(){return""+Math.round(1e5*Math.random(),0)}function n(e,t){return Math.max(Math.min(e,t),-t)}function i(t,s,a){var r=e(this).jmpress("current"),i=e(this).jmpress("settings"),o=e(this).jmpress("active").data("stepData"),c=e(this).jmpress("container");if(!(0===r.userZoom&&0>a)){var l=o.viewPortZoomable||i.viewPort.zoomable;if(!(r.userZoom===l&&a>0)){r.userZoom+=a;var u=e(c).innerWidth()/2,p=e(c).innerHeight()/2;t=t?t-u:t,s=s?s-p:s,r.userTranslateX=n(r.userTranslateX-a*t/r.zoomOriginWindowScale/l,u*r.userZoom*r.userZoom/l),r.userTranslateY=n(r.userTranslateY-a*s/r.zoomOriginWindowScale/l,p*r.userZoom*r.userZoom/l),e(this).jmpress("reselect","zoom")}}}var o=function(){var e=navigator.userAgent.toLowerCase(),t=/(chrome)[ \/]([\w.]+)/.exec(e)||/(webkit)[ \/]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||0>e.indexOf("compatible")&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[];return t[1]||""}(),c=e.jmpress("defaults");c.viewPort={width:!1,height:!1,maxScale:0,minScale:0,zoomable:0,zoomBindMove:!0,zoomBindWheel:!0};var l=c.keyboard.keys;l["mozilla"===o?107:187]="zoomIn",l["mozilla"===o?109:189]="zoomOut",c.reasonableAnimation.resize={transitionDuration:"0s",transitionDelay:"0ms"},c.reasonableAnimation.zoom={transitionDuration:"0s",transitionDelay:"0ms"},e.jmpress("initStep",function(e,t){for(var s in{viewPortHeight:1,viewPortWidth:1,viewPortMinScale:1,viewPortMaxScale:1,viewPortZoomable:1})t.stepData[s]=t.data[s]&&parseFloat(t.data[s])}),e.jmpress("afterInit",function(n,i){var o=this;i.current.viewPortNamespace=".jmpress-"+r(),e(s).bind("resize"+i.current.viewPortNamespace,function(){e(o).jmpress("reselect","resize")}),i.current.userZoom=0,i.current.userTranslateX=0,i.current.userTranslateY=0,i.settings.viewPort.zoomBindWheel&&e(i.settings.fullscreen?t:this).bind("mousewheel"+i.current.viewPortNamespace+" DOMMouseScroll"+i.current.viewPortNamespace,function(t,s){s=s||t.originalEvent.wheelDelta||-t.originalEvent.detail;var a=s/Math.abs(s);return 0>a?e(i.jmpress).jmpress("zoomOut",t.originalEvent.x,t.originalEvent.y):a>0&&e(i.jmpress).jmpress("zoomIn",t.originalEvent.x,t.originalEvent.y),!1}),i.settings.viewPort.zoomBindMove&&e(i.settings.fullscreen?t:this).bind("mousedown"+i.current.viewPortNamespace,function(e){i.current.userZoom&&(i.current.userTranslating={x:e.clientX,y:e.clientY},e.preventDefault(),e.stopImmediatePropagation())}).bind("mousemove"+i.current.viewPortNamespace,function(t){var s=i.current.userTranslating;s&&(e(o).jmpress("zoomTranslate",t.clientX-s.x,t.clientY-s.y),s.x=t.clientX,s.y=t.clientY,t.preventDefault(),t.stopImmediatePropagation())}).bind("mouseup"+i.current.viewPortNamespace,function(e){i.current.userTranslating&&(i.current.userTranslating=a,e.preventDefault(),e.stopImmediatePropagation())})}),e.jmpress("register","zoomIn",function(e,t){i.call(this,e||0,t||0,1)}),e.jmpress("register","zoomOut",function(e,t){i.call(this,e||0,t||0,-1)}),e.jmpress("register","zoomTranslate",function(t,s){var a=e(this).jmpress("current"),r=e(this).jmpress("settings"),i=e(this).jmpress("active").data("stepData"),o=e(this).jmpress("container"),c=i.viewPortZoomable||r.viewPort.zoomable,l=e(o).innerWidth(),u=e(o).innerHeight();a.userTranslateX=n(a.userTranslateX+t/a.zoomOriginWindowScale,l*a.userZoom*a.userZoom/c),a.userTranslateY=n(a.userTranslateY+s/a.zoomOriginWindowScale,u*a.userZoom*a.userZoom/c),e(this).jmpress("reselect","zoom")}),e.jmpress("afterDeinit",function(a,r){e(r.settings.fullscreen?t:this).unbind(r.current.viewPortNamespace),e(s).unbind(r.current.viewPortNamespace)}),e.jmpress("setActive",function(t,s){var a=s.settings.viewPort,r=s.stepData.viewPortHeight||a.height,n=s.stepData.viewPortWidth||a.width,i=s.stepData.viewPortMaxScale||a.maxScale,o=s.stepData.viewPortMinScale||a.minScale,c=r&&e(s.container).innerHeight()/r,l=n&&e(s.container).innerWidth()/n,u=(l||c)&&Math.min(l||c,c||l);if(u){u=u||1,i&&(u=Math.min(u,i)),o&&(u=Math.max(u,o));var p=s.stepData.viewPortZoomable||s.settings.viewPort.zoomable;if(p){var f=1/u-1/i;f/=p,u=1/(1/u-f*s.current.userZoom)}s.target.transform.reverse(),s.current.userTranslateX&&s.current.userTranslateY?s.target.transform.push(["translate",s.current.userTranslateX,s.current.userTranslateY,0]):s.target.transform.push(["translate"]),s.target.transform.push(["scale",u,u,1]),s.target.transform.reverse(),s.target.perspectiveScale/=u}s.current.zoomOriginWindowScale=u}),e.jmpress("setInactive",function(t,s){s.nextStep&&t&&e(s.nextStep).attr("id")===e(t).attr("id")||(s.current.userZoom=0,s.current.userTranslateX=0,s.current.userTranslateY=0)})}(jQuery,document,window),function(e){"use strict";function t(){return""+Math.round(1e5*Math.random(),0)}var s=e.jmpress;s("defaults").mouse={clickSelects:!0},s("afterInit",function(s,a){var r=a.settings,n=r.stepSelector,i=a.current,o=e(this);i.clickableStepsNamespace=".jmpress-"+t(),o.bind("click"+i.clickableStepsNamespace,function(t){if(r.mouse.clickSelects&&!i.userZoom){var s=e(t.target).closest(n);s.is(o.jmpress("active"))||s.length&&(o.jmpress("select",s[0],"click"),t.preventDefault(),t.stopPropagation())}})}),s("afterDeinit",function(t,s){e(this).unbind(s.current.clickableStepsNamespace)})}(jQuery,document,window),function(e,t){"use strict";function s(){return""+Math.round(1e5*Math.random(),0)}var a=e.jmpress;a("afterInit",function(a,r){var n=r.settings,i=r.current,o=r.jmpress;i.mobileNamespace=".jmpress-"+s();var c,l=[0,0];e(n.fullscreen?t:o).bind("touchstart"+i.mobileNamespace,function(e){c=e.originalEvent.touches[0],l=[c.pageX,c.pageY]}).bind("touchmove"+i.mobileNamespace,function(e){return c=e.originalEvent.touches[0],e.preventDefault(),!1}).bind("touchend"+i.mobileNamespace,function(t){var s=[c.pageX,c.pageY],a=[s[0]-l[0],s[1]-l[1]];return Math.max(Math.abs(a[0]),Math.abs(a[1]))>50?(a=Math.abs(a[0])>Math.abs(a[1])?a[0]:a[1],e(o).jmpress(a>0?"prev":"next"),t.preventDefault(),!1):undefined})}),a("afterDeinit",function(s,a){var r=a.settings,n=a.current,i=a.jmpress;e(r.fullscreen?t:i).unbind(n.mobileNamespace)})}(jQuery,document,window),function(e,t,s,a){"use strict";function r(t,s,n){for(var i in s){var o=i;n&&(o=n+o.substr(0,1).toUpperCase()+o.substr(1)),e.isPlainObject(s[i])?r(t,s[i],o):t[o]===a&&(t[o]=s[i])}}function n(t,s){e.isArray(s)?s.length<t.length?e.error("more nested steps than children in template"):t.each(function(t,a){a=e(a);var n=a.data(l)||{};r(n,s[t]),a.data(l,n)}):e.isFunction(s)&&t.each(function(a,n){n=e(n);var i=n.data(l)||{};r(i,s(a,n,t)),n.data(l,i)})}function i(e,t,s,a){if(s.children){var r=t.children(a.settings.stepSelector);n(r,s.children)}o(e,s)}function o(e,t){r(e,t)}var c=e.jmpress,l="_template_",u="_applied_template_",p={};c("beforeInitStep",function(t,s){t=e(t);var a=s.data,r=a.template,n=t.data(u),o=t.data(l);r&&e.each(r.split(" "),function(e,r){var n=p[r];i(a,t,n,s)}),n&&i(a,t,n,s),o&&(i(a,t,o,s),t.data(l,null),o.template&&e.each(o.template.split(" "),function(e,r){var n=p[r];i(a,t,n,s)}))}),c("beforeInit",function(t,s){var a=c("dataset",this),r=a.template,i=s.settings.stepSelector;if(r){var o=p[r];n(e(this).find(i).filter(function(){return!e(this).parent().is(i)}),o.children)}}),c("register","template",function(t,s){p[t]=p[t]?e.extend(!0,{},p[t],s):e.extend(!0,{},s)}),c("register","apply",function(t,s){if(s)if(e.isArray(s))n(e(t),s);else{var a;a="string"==typeof s?p[s]:e.extend(!0,{},s),e(t).each(function(t,s){s=e(s);var n=s.data(u)||{};r(n,a),s.data(u,n)})}else{var i=e(this).jmpress("settings").stepSelector;n(e(this).find(i).filter(function(){return!e(this).parent().is(i)}),t)}})}(jQuery,document,window),function(e){"use strict";e.jmpress("setActive",function(t,s){s.prevStep!==t&&e(t).triggerHandler("enterStep")}),e.jmpress("setInactive",function(t,s){s.nextStep!==t&&e(t).triggerHandler("leaveStep")})}(jQuery,document,window),function(e,t,s,a){"use strict";function r(t){for(var s=t.split(" "),a=s[0],r={willClass:"will-"+a,doClass:"do-"+a,hasClass:"has-"+a},n="",i=1;s.length>i;i++){var o=s[i];switch(n){case"":"after"===o?n="after":e.warn("unknown keyword in '"+t+"'. '"+o+"' unknown.");break;case"after":if(o.match(/^[1-9][0-9]*m?s?/)){var c=parseFloat(o);-1!==o.indexOf("ms")?c*=1:-1!==o.indexOf("s")?c*=1e3:-1!==o.indexOf("m")&&(c*=6e4),r.delay=c}else r.after=Array.prototype.slice.call(s,i).join(" "),i=s.length}}return r}function n(t,s,a,r){r=r||t.length-1,a=a||0;for(var n=a;r+1>n;n++)if(e(t[n].element).is(s))return n}function i(t,s,a){e.each(s._on,function(e,s){t.push({substep:s.substep,delay:s.delay+a}),i(t,s.substep,s.delay+a)})}e.jmpress("defaults").customAnimationDataAttribute="jmpress",e.jmpress("afterInit",function(e,t){t.current.animationTimeouts=[],t.current.animationCleanupWaiting=[]}),e.jmpress("applyStep",function(t,s){function o(e,t){return t.substep._after?(u=t.substep._after,!1):a}var c={},l=[];if(e(t).find("[data-"+s.settings.customAnimationDataAttribute+"]").each(function(a,r){e(r).closest(s.settings.stepSelector).is(t)&&l.push({element:r})}),0!==l.length){e.each(l,function(t,a){a.info=r(e(a.element).data(s.settings.customAnimationDataAttribute)),e(a.element).addClass(a.info.willClass),a._on=[],a._after=null});var u={_after:a,_on:[],info:{}};if(e.each(l,function(e,t){var s=t.info.after;if(s)if("step"===s)s=u;else if("prev"===s)s=l[e-1];else{var r=n(l,s,0,e-1);r===a&&(r=n(l,s)),s=r===a||r===e?l[e-1]:l[r]}else s=l[e-1];if(s){if(!t.info.delay){if(!s._after)return s._after=t,a;s=s._after}s._on.push({substep:t,delay:t.info.delay||0})}}),u._after===a&&0===u._on.length){var p=n(l,s.stepData.startSubstep)||0;u._after=l[p]}var f=[];do{var d=[{substep:u,delay:0}];i(d,u,0),f.push(d),u=null,e.each(d,o)}while(u);c.list=f,e(t).data("substepsData",c)}}),e.jmpress("unapplyStep",function(t){var s=e(t).data("substepsData");s&&e.each(s.list,function(t,s){e.each(s,function(t,s){s.substep.info.willClass&&e(s.substep.element).removeClass(s.substep.info.willClass),s.substep.info.hasClass&&e(s.substep.element).removeClass(s.substep.info.hasClass),s.substep.info.doClass&&e(s.substep.element).removeClass(s.substep.info.doClass)})})}),e.jmpress("setActive",function(t,s){var r=e(t).data("substepsData");if(r){s.substep===a&&(s.substep="prev"===s.reason?r.list.length-1:0);var n=s.substep;e.each(s.current.animationTimeouts,function(e,t){clearTimeout(t)}),s.current.animationTimeouts=[],e.each(r.list,function(t,a){var r=n>t,i=n>=t;e.each(a,function(t,a){function n(){e(a.substep.element).addClass(a.substep.info.doClass)}a.substep.info.hasClass&&e(a.substep.element)[(r?"add":"remove")+"Class"](a.substep.info.hasClass),i&&!r&&a.delay&&"prev"!==s.reason?a.substep.info.doClass&&(e(a.substep.element).removeClass(a.substep.info.doClass),s.current.animationTimeouts.push(setTimeout(n,a.delay))):a.substep.info.doClass&&e(a.substep.element)[(i?"add":"remove")+"Class"](a.substep.info.doClass)})})}}),e.jmpress("setInactive",function(t,s){function a(t){e.each(t.list,function(t,s){e.each(s,function(t,s){s.substep.info.hasClass&&e(s.substep.element).removeClass(s.substep.info.hasClass),s.substep.info.doClass&&e(s.substep.element).removeClass(s.substep.info.doClass)})})}if(s.nextStep!==t){e.each(s.current.animationCleanupWaiting,function(e,t){a(t)}),s.current.animationCleanupWaiting=[];var r=e(t).data("substepsData");r&&s.current.animationCleanupWaiting.push(r)}}),e.jmpress("selectNext",function(t,s){if(s.substep!==a){var r=e(t).data("substepsData");if(r)return s.substep<r.list.length-1?{step:t,substep:s.substep+1}:a}}),e.jmpress("selectPrev",function(t,s){if(s.substep!==a){var r=e(t).data("substepsData");if(r)return s.substep>0?{step:t,substep:s.substep-1}:a}})}(jQuery,document,window),function(e,t){"use strict";e.jmpress("register","toggle",function(s,a,r){var n=this;e(t).bind("keydown",function(t){t.keyCode===s&&(e(n).jmpress("initialized")?e(n).jmpress("deinit"):e(n).jmpress(a))}),r&&e(n).jmpress(a)})}(jQuery,document,window),function(e){"use strict";function t(t,s,a){if(t.secondary&&-1!==t.secondary.split(" ").indexOf(s)){for(var r in t)if(r.length>9&&0===r.indexOf("secondary")){var n=t[r],i=r.substr(9);i=i.substr(0,1).toLowerCase()+i.substr(1),t[r]=t[i],t[i]=n}e(this).jmpress("reapply",e(a))}}e.jmpress("initStep",function(e,t){for(var s in t.data)0===s.indexOf("secondary")&&(t.stepData[s]=t.data[s])}),e.jmpress("beforeActive",function(s,a){t.call(a.jmpress,e(s).data("stepData"),"self",s);var r=e(s).parent();e(r).children(a.settings.stepSelector).each(function(s,r){var n=e(r).data("stepData");t.call(a.jmpress,n,"siblings",r)});for(var n=1;a.parents.length>n;n++)e(a.parents[n]).children(a.settings.stepSelector).each()}),e.jmpress("setInactive",function(s,a){function r(s,r){var n=e(r).data("stepData");t.call(a.jmpress,n,"grandchildren",r)}t.call(a.jmpress,e(s).data("stepData"),"self",s); +var n=e(s).parent();e(n).children(a.settings.stepSelector).each(function(s,r){var n=e(r).data("stepData");t.call(a.jmpress,n,"siblings",r)});for(var i=1;a.parents.length>i;i++)e(a.parents[i]).children(a.settings.stepSelector).each(r)})}(jQuery,document,window),function(e,t,s,a){"use strict";e.jmpress("defaults").duration={defaultValue:-1,defaultAction:"next",barSelector:a,barProperty:"width",barPropertyStart:"0",barPropertyEnd:"100%"},e.jmpress("initStep",function(e,t){t.stepData.duration=t.data.duration&&parseInt(t.data.duration,10),t.stepData.durationAction=t.data.durationAction}),e.jmpress("setInactive",function(t,s){var a=s.settings,r=a.duration,n=s.current;if(s.stepData.duration||r.defaultValue,n.durationTimeout){if(r.barSelector){var i={transitionProperty:r.barProperty,transitionDuration:"0",transitionDelay:"0",transitionTimingFunction:"linear"};i[r.barProperty]=r.barPropertyStart;var o=e(r.barSelector);e.jmpress("css",o,i),o.each(function(t,s){var a=e(s).next(),r=e(s).parent();e(s).detach(),a.length?a.insertBefore(s):r.append(s)})}clearTimeout(n.durationTimeout),delete n.durationTimeout}}),e.jmpress("setActive",function(t,s){var r=s.settings,n=r.duration,i=s.current,o=s.stepData.duration||n.defaultValue;if(o&&o>0){if(n.barSelector){var c={transitionProperty:n.barProperty,transitionDuration:o-2*r.transitionDuration/3-100+"ms",transitionDelay:2*r.transitionDuration/3+"ms",transitionTimingFunction:"linear"};c[n.barProperty]=n.barPropertyEnd,e.jmpress("css",e(n.barSelector),c)}var l=this;i.durationTimeout&&(clearTimeout(i.durationTimeout),i.durationTimeout=a),i.durationTimeout=setTimeout(function(){var t=s.stepData.durationAction||n.defaultAction;e(l).jmpress(t)},o)}})}(jQuery,document,window),function(e,t,s){"use strict";var a=e.jmpress,r="jmpress-presentation-";a("defaults").presentationMode={use:!0,url:"presentation-screen.html",notesUrl:!1,transferredValues:["userZoom","userTranslateX","userTranslateY"]},a("defaults").keyboard.keys[80]="presentationPopup",a("afterInit",function(t,a){var n=a.current;if(n.selectMessageListeners=[],a.settings.presentationMode.use){s.addEventListener("message",function(t){try{if("string"!=typeof t.data||0!==t.data.indexOf(r))return;var i=JSON.parse(t.data.slice(r.length));switch(i.type){case"select":e.each(a.settings.presentationMode.transferredValues,function(e,t){a.current[t]=i[t]}),/[a-z0-9\-]+/i.test(i.targetId)&&typeof i.substep in{number:1,undefined:1}?e(a.jmpress).jmpress("select",{step:"#"+i.targetId,substep:i.substep},i.reason):e.error("For security reasons the targetId must match /[a-z0-9\\-]+/i and substep must be a number.");break;case"listen":n.selectMessageListeners.push(t.source);break;case"ok":clearTimeout(n.presentationPopupTimeout);break;case"read":try{t.source.postMessage(r+JSON.stringify({type:"url",url:s.location.href,notesUrl:a.settings.presentationMode.notesUrl}),"*")}catch(o){e.error("Cannot post message to source: "+o)}break;default:throw"Unknown message type: "+i.type}}catch(o){e.error("Received message is malformed: "+o)}});try{s.parent&&s.parent!==s&&s.parent.postMessage(r+JSON.stringify({type:"afterInit"}),"*")}catch(i){e.error("Cannot post message to parent: "+i)}}}),a("afterDeinit",function(t,a){if(a.settings.presentationMode.use)try{s.parent&&s.parent!==s&&s.parent.postMessage(r+JSON.stringify({type:"afterDeinit"}),"*")}catch(n){e.error("Cannot post message to parent: "+n)}}),a("setActive",function(t,s){var a=e(s.delegatedFrom).attr("id"),n=s.substep,i=s.reason;e.each(s.current.selectMessageListeners,function(t,o){try{var c={type:"select",targetId:a,substep:n,reason:i};e.each(s.settings.presentationMode.transferredValues,function(e,t){c[t]=s.current[t]}),o.postMessage(r+JSON.stringify(c),"*")}catch(l){e.error("Cannot post message to listener: "+l)}})}),a("register","presentationPopup",function(){function t(){n.jmpress("current").presentationPopupTimeout=setTimeout(t,100);try{a.postMessage(r+JSON.stringify({type:"url",url:s.location.href,notesUrl:n.jmpress("settings").presentationMode.notesUrl}),"*")}catch(e){}}var a,n=e(this);n.jmpress("settings").presentationMode.use&&(a=s.open(e(this).jmpress("settings").presentationMode.url),n.jmpress("current").presentationPopupTimeout=setTimeout(t,100))})}(jQuery,document,window);
\ No newline at end of file diff --git a/plugins/jetpack/modules/shortcodes/js/main.js b/plugins/jetpack/modules/shortcodes/js/main.js new file mode 100644 index 00000000..a6913f78 --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/js/main.js @@ -0,0 +1,255 @@ +(function($){ + var jmpressOpts = { + fullscreen : false, + hash : { use : false }, + mouse : { clickSelects : false }, + keyboard : { use : true }, + animation : { transitionDuration : '1s' }, + presentationMode : false, + stepSelector : '.step', + duration : { + defaultValue: 0 + } + }; + + /** + * Presentation constructor + */ + function Presentation (wrapper) { + var _self, size, duration, new_css, ie_regex, matches; + + _self = this; + + _self.wrapper = $(wrapper); // The wrapper for toggling fullscreen + _self.slideshow = $('.presentation', wrapper); // Holds the slides for jmpress + _self.navLeft = $('.nav-arrow-left', wrapper); + _self.navRight = $('.nav-arrow-right', wrapper); + _self.expandButton = $('.nav-fullscreen-button', wrapper); + _self.overlay = $('.autoplay-overlay', wrapper); + _self.fullscreen = false; + _self.autoPlaying = false; + _self.autoplayTime = parseFloat(_self.slideshow.attr('data-autoplay'), 10) || 0; + + // The wrapper is scaled to the contents' size so that its border wraps tightly + _self.wrapper.css({ + width: _self.slideshow.width(), + height: _self.slideshow.height() + }); + + duration = _self.slideshow.attr('duration') || '1s'; + jmpressOpts.animation.transitionDuration = duration; + + // Compensate for transition times + if( _self.autoplayTime ) { + _self.autoplayTime += parseFloat(duration, 10) * 1000; + } + + // Set the opacity transition duration + // as it is delegated by css and not jmpress + duration = 'opacity ' + duration; + new_css = { + 'width' : _self.slideshow.width(), + 'height' : _self.slideshow.height(), + '-webkit-transition': duration, + '-moz-transition' : duration, + '-ms-transition' : duration, + '-o-transition' : duration, + 'transition' : duration + }; + + $('.step', _self.slideshow).each(function(i, step) { + $(step).css(new_css); + }); + + // Apply attribute to allow fading individual bullets here, + // otherwise wp_kses will strip the attribute out + $('.step.fadebullets li', _self.slideshow).each(function(i, step) { + $(step).attr('data-jmpress', 'fade'); + }); + + // Register resizing to window when fullscreen + $(window).resize(function() { + if ( _self.fullscreen ) + _self.resizePresentation(); + }); + + // Register the nav bars to move the slides + _self.navLeft.on('click', function(){ + _self.slideshow.jmpress('prev'); + _self.overlay.css('opacity', 0); + return false; + }); + + _self.navRight.on('click', function(){ + _self.slideshow.jmpress('next'); + _self.overlay.css('opacity', 0); + return false; + }); + + _self.slideshow.on('click', function() { + _self.setAutoplay(true); + return false; + }); + + _self.slideshow.on('focusout', function() { + _self.setAutoplay(false); + }); + + // Register toggling fullscreen except for IE 9 or lower + ie_regex = /MSIE\s(\d+)\.\d+/; + matches = ie_regex.exec(navigator.userAgent); + + if ( matches && parseInt(matches[1], 10) < 10 ) { + _self.expandButton.remove(); + _self.expandButton = null; + } else { + _self.expandButton.on('click', function() { + _self.setFullscreen( !_self.fullscreen ); + return false; + }); + } + + // Register ESC key to exit fullscreen + $(window).on('keydown', function( event ) { + if ( event.which == 27 ) + _self.setFullscreen( false ); + }); + + // Start the presentation + _self.slideshow.jmpress(jmpressOpts); + + // Make content visible and remove error message on jmpress success + if ( _self.slideshow.jmpress('initialized') ) { + _self.slideshow.css('display', ''); + _self.overlay.css('display', ''); + $('.not-supported-msg', _self.wrapper).remove(); + } + + // A bug in Firefox causes issues with the nav arrows appearing + // on hover in presentation mode. Explicitly disabling fullscreen + // on init seems to fix the issue + _self.setFullscreen( false ); + } + + $.extend( Presentation.prototype, { + resizePresentation: function () { + var scale, duration, settings, new_css, widthScale, heightScale; + + // Set the animation duration to 0 during resizing + // so that there isn't an animation delay when scaling + // up the slide contents + settings = this.slideshow.jmpress('settings'); + duration = settings.animation.transitionDuration; + + settings.animation.transitionDuration = '0s'; + this.slideshow.jmpress('reselect'); + + scale = 1; + new_css = { + top : 0, + left : 0, + zoom : 1 + }; + + // Expand the presentation to fill the lesser of the max width or height + // This avoids content moving past the window for certain window sizes + if ( this.fullscreen ) { + widthScale = $(window).width() / this.slideshow.width(); + heightScale = $(window).height() / this.slideshow.height(); + + scale = Math.min(widthScale, heightScale); + + new_css.top = ( $(window).height() - (scale * this.slideshow.height()) ) / 2; + new_css.left = ( $(window).width() - (scale * this.slideshow.width() ) ) / 2; + } + + // Firefox does not support the zoom property; IE does, but it does not work + // well like in webkit, so we manually transform and position the slideshow + if ( this.slideshow.css('-moz-transform') || this.slideshow.css('-ms-transform') ) { + // Firefox keeps the center of the element in place and expands outward + // so we must shift everything to compensate + new_css.top += (scale - 1) * this.slideshow.height() / 2; + new_css.left += (scale - 1) * this.slideshow.width() / 2; + + scale = 'scale(' + scale + ')'; + + $.extend(new_css, { + '-moz-transform' : scale, + '-ms-transform' : scale, + 'transform' : scale, + }); + } else { + // webkit scales everything with zoom so we need to offset the right amount + // so that the content is vertically centered after scaling effects + new_css.top /= scale; + new_css.left /= scale; + new_css.zoom = scale; + } + + this.slideshow.css(new_css); + + settings.animation.transitionDuration = duration; + this.slideshow.jmpress('reselect'); + }, + + setFullscreen: function ( on ) { + this.fullscreen = on; + this.setAutoplay(false); + + // Save the scroll positions before going into fullscreen mode + if ( on ) { + this.scrollVert = $(window).scrollTop(); + this.scrollHoriz = $(window).scrollLeft(); + + // Chrome Bug: Force scroll to be at top + // otherwise the presentation can end up offscreen + $(window).scrollTop(0); + $(window).scrollLeft(0); + } + + $('html').toggleClass('presentation-global-fullscreen', on); + $('body').toggleClass('presentation-global-fullscreen', on); + + this.wrapper.toggleClass('presentation-wrapper-fullscreen', on); + + this.wrapper.parents().each(function(i, e){ + $(e).toggleClass('presentation-wrapper-fullscreen-parent', on); + }); + + this.resizePresentation(); + + // Reset the scroll positions after exiting fullscreen mode + if ( !on ) { + $(window).scrollTop(this.scrollVert); + $(window).scrollLeft(this.scrollHoriz); + } + }, + + setAutoplay: function ( on ) { + var _self = this, newAutoplayTime; + + if ( _self.autoPlaying == on ) + return; + + newAutoplayTime = (on && _self.autoplayTime > 0) ? _self.autoplayTime : 0; + _self.slideshow.jmpress('settings').duration.defaultValue = newAutoplayTime; + + // Move to the next slide when activating autoplay + if( newAutoplayTime ) { + _self.slideshow.jmpress('next'); + _self.overlay.css('opacity', 0); + } else { + _self.slideshow.jmpress('reselect'); + } + + _self.autoPlaying = on; + } + }); + + $( document ).ready( function(){ + $('.presentation-wrapper').map(function() { + new Presentation(this); + }); + }); + +})(jQuery); diff --git a/plugins/jetpack/modules/shortcodes/presentations.php b/plugins/jetpack/modules/shortcodes/presentations.php new file mode 100644 index 00000000..6fb2b674 --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/presentations.php @@ -0,0 +1,431 @@ +<?php +/* +Plugin Name: Presentations +Plugin URI: http://automattic.com/wordpress-plugins/ +Description: Presentations plugin based on the work done by <a href="http://darylkoop.com/">Daryl Koopersmith</a>. Powered by jmpress.js +Version: 0.2 +Author: Automattic +Author URI: http://automattic.com/wordpress-plugins/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +/** + * Known issues: + * + * - IE 7/8 are not supported by jmpress and presentations will not work + * - IE 9 will not animate transitions at all, though it's possible to at least + * switch between slides. + * - Infinite Scroll themes will not load presentations properly unless the post + * happens to be on the first loaded page. The permalink page will function + * properly, however. + * - Exiting fullscreen mode will not properly reset the scroll locations in Safari + */ + + +/* +HOW TO: How the plugin settings are organized and which features are supported. + +The entire presentation should be wrapped with a [presentation] shortcode, and every +individual slide should be wrapped with a [slide] shortcode. Any settings supported +by [slide] can be set into [presentation], which will apply that setting for the entire +presentation unless overridden by individual slides. + +- [presentation] only settings: + - duration: transition durations, default is one second. + - height: content height, default is 400px + - width: content width, default is 550px + - autoplay: delay between transitions in seconds, default 3s + when set the presentation will automatically transition between slides + as long as the presentation remains in focus + +- [slide] settings: + - transition: specifies where the next slide will be placed relative + to the last one before it. Supported values are "up", "down" + "left", "right", or "none". Default value is "down". + + - scale: scales the content relative to other slides, default value is one + + - rotate: rotates the content by the specified degrees, default is zero + + - fade: slides will fade in and out during transition. Values of "on" or + "true" will enable fading, while values of "no" or "false" will + disable it. Default value is "on" + + - bgcolor: specifies a background color for the slides. Any CSS valid value + is permitted. Default color is transparent. + + - bgimg: specifies an image url which will fill the background. Image is + set to fill the background 100% width and height + + - fadebullets: any html <li> tags will start out with an opacity of 0 and any + subsequent slide transitions will show the bullets one by one +*/ + +if ( ! class_exists( 'Presentations' ) ) : + +class Presentations { + + private $presentation_settings; + private $presentation_initialized; + private $scripts_and_style_included; + + /** + * Constructor + */ + function __construct() { + // Bail without 3.0. + if ( ! function_exists( '__return_false' ) ) + return; + + $this->presentation_initialized = false; + $this->scripts_and_style_included = false; + + // Registers shortcodes + add_action( 'wp_head', array( &$this, 'add_scripts' ), 1 ); + + add_shortcode( 'presentation', array( &$this, 'presentation_shortcode' ) ); + add_shortcode( 'slide', array( &$this, 'slide_shortcode' ) ); + } + + function add_scripts() { + $this->scripts_and_style_included = false; + + if ( empty( $GLOBALS['posts'] ) || !is_array( $GLOBALS['posts'] ) ) { + return; + } + + foreach ( $GLOBALS['posts'] as $p ) { + if ( false !== strpos( $p->post_content, '[presentation' ) ) { + $this->scripts_and_style_included = true; + break; + } + } + + if ( ! $this->scripts_and_style_included ) + return; + + $plugin = plugin_dir_url( __FILE__ ); + // Add CSS + wp_enqueue_style('presentations', $plugin . 'css/style.css'); + // Add JavaScript + wp_enqueue_script('jquery'); + wp_enqueue_script('jmpress', + $plugin . 'js/jmpress.min.js', + array('jquery'), + '0.4.5', + true); + wp_enqueue_script('presentations', + $plugin . 'js/main.js', + array('jquery', 'jmpress'), + false, + true); + } + + function presentation_shortcode( $atts, $content='' ) { + // Mark that we've found a valid [presentation] shortcode + $this->presentation_initialized = true; + + $atts = shortcode_atts( array( + 'duration' => '', + 'height' => '', + 'width' => '', + 'bgcolor' => '', + 'bgimg' => '', + 'autoplay' => '', + + // Settings + 'transition' => '', + 'scale' => '', + 'rotate' => '', + 'fade' => '', + 'fadebullets'=> '', + ), $atts ); + + $this->presentation_settings = array( + 'transition' => 'down', + 'scale' => 1, + 'rotate' => 0, + 'fade' => 'on', + 'last' => array( + 'x' => 0, + 'y' => 0, + 'scale' => 1, + 'rotate' => 0, + ), + ); + + // Set the presentation-wide settings + if ( '' != trim( $atts['transition'] ) ) + $this->presentation_settings['transition'] = $atts['transition']; + + if ( '' != trim( $atts['scale'] ) ) + $this->presentation_settings['scale'] = floatval( $atts['scale'] ); + + if ( '' != trim( $atts['rotate'] ) ) + $this->presentation_settings['rotate'] = floatval( $atts['rotate'] ); + + if ( '' != trim( $atts['fade'] ) ) + $this->presentation_settings['fade'] = $atts['fade']; + + if ( '' != trim( $atts['fadebullets'] ) ) + $this->presentation_settings['fadebullets'] = $atts['fadebullets']; + + // Set any settings the slides don't care about + if ( '' != trim( $atts['duration'] ) ) + $duration = floatval( $atts['duration'] ) . 's'; + else + $duration = '1s'; + + // Autoplay durations are set in milliseconds + if ( '' != trim( $atts['autoplay'] ) ) + $autoplay = floatval( $atts['autoplay'] ) * 1000; + else + $autoplay = 0; // No autoplay + + // Set the presentation size as specified or with some nicely sized dimensions + if ( '' != trim( $atts['width'] ) ) + $this->presentation_settings['width'] = intval( $atts['width'] ); + else + $this->presentation_settings['width'] = 480; + + if ( '' != trim( $atts['height'] ) ) + $this->presentation_settings['height'] = intval( $atts['height'] ); + else + $this->presentation_settings['height'] = 370; + + // Hide the content by default in case the scripts fail + $style = 'display: none; width: ' . $this->presentation_settings['width'] . 'px; height: ' . $this->presentation_settings['height'] . 'px;'; + + // Check for background color XOR background image + // Use a white background if nothing specified + if ( preg_match( '/https?\:\/\/[^\'"\s]*/', $atts['bgimg'], $matches ) ) { + $style .= ' background-image: url("' . esc_url( $matches[0] ) . '");'; + } else if ( '' != trim( $atts['bgcolor'] ) ) { + $style .= ' background-color: ' . esc_attr( $atts['bgcolor'] ) . ';'; + } else { + $style .= ' background-color: #fff;'; + } + + // Not supported message style is inlined incase the style sheet doesn't get included + $out = "<section class='presentation-wrapper'>"; + $out.= "<p class='not-supported-msg' style='display: inherit; padding: 25%; text-align: center;'>"; + $out.= __( 'This slideshow could not be started. Try refreshing the page or viewing it in another browser.' , 'jetpack' ) . '</p>'; + + // Bail out unless the scripts were added + if ( $this->scripts_and_style_included ) { + $out.= sprintf( + '<div class="presentation" duration="%s" data-autoplay="%s" style="%s">', + esc_attr( $duration ), + esc_attr( $autoplay ), + esc_attr( $style ) + ); + $out.= "<div class='nav-arrow-left'></div>"; + $out.= "<div class='nav-arrow-right'></div>"; + $out.= "<div class='nav-fullscreen-button'></div>"; + + if ( $autoplay ) { + $out.= "<div class='autoplay-overlay' style='display: none'><p class='overlay-msg'>"; + $out.= __( 'Click to autoplay the presentation!' , 'jetpack' ); + $out.= "</p></div>"; + } + + $out.= do_shortcode( $content ); + $out.= "</section>"; + } + + $out.= "</section>"; + + $this->presentation_initialized = false; + return $out; + } + + function slide_shortcode( $atts, $content = '' ) { + // Bail out unless wrapped by a [presentation] shortcode + if ( ! $this->presentation_initialized ) + return $content; + + $atts = shortcode_atts( array( + 'transition' => '', + 'scale' => '', + 'rotate' => '', + 'fade' => '', + 'fadebullets'=> '', + 'bgcolor' => '', + 'bgimg' => '', + ), $atts ); + + // Determine positioning based on transition + if ( '' == trim( $atts['transition'] ) ) + $atts['transition'] = $this->presentation_settings['transition']; + + // Setting the content scale + if ( '' == trim( $atts['scale'] ) ) + $atts['scale'] = $this->presentation_settings['scale']; + + if( '' == trim( $atts['scale'] ) ) + $scale = 1; + else + $scale = floatval( $atts['scale'] ); + + if ( $scale < 0 ) + $scale *= -1; + + // Setting the content rotation + if ( '' == trim( $atts['rotate'] ) ) + $atts['rotate'] = $this->presentation_settings['rotate']; + + if( '' == trim( $atts['rotate'] ) ) + $rotate = 0; + else + $rotate = floatval( $atts['rotate'] ); + + // Setting if the content should fade + if ( '' == trim( $atts['fade'] ) ) + $atts['fade'] = $this->presentation_settings['fade']; + + if ( 'on' == $atts['fade'] || 'true' == $atts['fade'] ) + $fade = 'fade'; + else + $fade = ''; + + // Setting if bullets should fade on step changes + if ( '' == trim( $atts['fadebullets'] ) ) + $atts['fadebullets'] = $this->presentation_settings['fadebullets']; + + if ( 'on' == $atts['fadebullets'] || 'true' == $atts['fadebullets'] ) + $fadebullets = 'fadebullets'; + else + $fadebullets = ''; + + $coords = $this->get_coords( array( + 'transition' => $atts['transition'], + 'scale' => $scale, + 'rotate' => $rotate, + )); + + $x = $coords['x']; + $y = $coords['y']; + + // Check for background color XOR background image + // Use a white background if nothing specified + if ( preg_match( '/https?\:\/\/[^\'"\s]*/', $atts['bgimg'], $matches ) ) { + $style = 'background-image: url("' . esc_url( $matches[0] ) . '");'; + } else if ( '' != trim( $atts['bgcolor'] ) ) { + $style = 'background-color: ' . esc_attr( $atts['bgcolor'] ) . ';'; + } else { + $style = ''; + } + + // Put everything together and let jmpress do the magic! + $out = sprintf( + '<div class="step %s %s" data-x="%s" data-y="%s" data-scale="%s" data-rotate="%s" style="%s">', + esc_attr( $fade ), + esc_attr( $fadebullets ), + esc_attr( $x ), + esc_attr( $y ), + esc_attr( $scale ), + esc_attr( $rotate ), + esc_attr( $style ) + ); + + $out.= "<div class='slide-content'>"; + $out.= do_shortcode( $content ); + $out.= "</div></div>"; + return $out; + } + + /** + * Determines the position of the next slide based on the position and scaling of the previous slide. + * + * @param array $args: an array with the following key-value pairs + * string $transition: the transition name, "up", "down", "left", or "right" + * float $scale: the scale of the next slide (used to determine the position of the slide after that) + * + * @return array with the 'x' and 'y' coordinates of the slide + */ + function get_coords( $args ) { + if ( 0 == $args['scale'] ) + $args['scale'] = 1; + + $width = $this->presentation_settings['width']; + $height = $this->presentation_settings['height']; + $last = $this->presentation_settings['last']; + $scale = $last['scale']; + + $next = array( + 'x' => $last['x'], + 'y' => $last['y'], + 'scale' => $args['scale'], + 'rotate' => $args['rotate'], + ); + + // All angles are measured from the vertical axis, so everything is backwards! + $diagAngle = atan2( $width, $height ); + $diagonal = sqrt( pow( $width, 2 ) + pow( $height, 2 ) ); + + // We offset the angles by the angle formed by the diagonal so that + // we can multiply the sines directly against the diagonal length + $theta = deg2rad( $last['rotate'] ) - $diagAngle; + $phi = deg2rad( $next['rotate'] ) - $diagAngle; + + // We start by displacing by the slide dimensions + $totalHorizDisp = $width * $scale; + $totalVertDisp = $height * $scale; + + // If the previous slide was rotated, we add the incremental offset from the rotation + // Namely the difference between the regular dimension (no rotation) and the component + // of the diagonal for that angle + $totalHorizDisp += ( ( ( abs( sin( $theta ) ) * $diagonal) - $width ) / 2) * $scale; + $totalVertDisp += ( ( ( abs( cos( $theta ) ) * $diagonal) - $height) / 2) * $scale; + + // Similarly, we check if the current slide has been rotated and add whatever additional + // offset has been added. This is so that two rotated corners don't clash with each other. + // Note: we are checking the raw angle relative to the vertical axis, NOT the diagonal angle. + if ( $next['rotate'] % 180 != 0 ){ + $totalHorizDisp += ( abs( ( sin( $phi ) * $diagonal ) - $width ) / 2) * $next['scale']; + $totalVertDisp += ( abs( ( cos( $phi ) * $diagonal ) - $height ) / 2) * $next['scale']; + } + + switch ( trim( $args['transition'] ) ) { + case 'none': + break; + + case 'left': + $next['x'] -= $totalHorizDisp; + break; + + case 'right': + $next['x'] += $totalHorizDisp; + break; + + case 'up': + $next['y'] -= $totalVertDisp; + break; + + case 'down': + default: + $next['y'] += $totalVertDisp; + break; + } + + $this->presentation_settings['last'] = $next; + return $next; + } +} + +$GLOBALS['presentations'] = new Presentations(); +endif; diff --git a/plugins/jetpack/modules/shortcodes/twitter-timeline.php b/plugins/jetpack/modules/shortcodes/twitter-timeline.php new file mode 100644 index 00000000..8931592b --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/twitter-timeline.php @@ -0,0 +1,31 @@ +<?php +add_shortcode( 'twitter-timeline', 'twitter_timeline_shortcode' ); + +function twitter_timeline_shortcode( $attr ) { + + $default_atts = array( + 'username' => '', + 'id' => '', + 'height' => 282, + 'width' => 450, + + ); + + $attr = shortcode_atts( $default_atts, $attr ); + + if ( $attr['username'] != preg_replace( '/[^A-Za-z0-9_]+/', '', $attr['username'] ) ) + return '<!--' . __( 'Invalid username', 'jetpack' ) . '-->'; + + if ( ! is_numeric( $attr['id'] ) ) + return '<!--' . __( 'Invalid id', 'jetpack' ) . '-->'; + + $tweets_by = sprintf( __( 'Tweets by @%s', 'jetpack' ), $attr['username'] ); + $output = '<a class="twitter-timeline" width="' . (int)$attr['width'] . '" height="' . (int)$attr['width'] . '" href="' . esc_url( 'https://twitter.com/'. $attr['username'] ) . '" data-widget-id="' . (int)$attr['id'] . '">' . esc_html( $tweets_by ) . '</a>'; + add_action( 'wp_footer', 'twitter_timeline_js' ); + + return $output; +} + +function twitter_timeline_js() { + echo '<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>'; +} diff --git a/plugins/jetpack/modules/shortcodes/videopress.php b/plugins/jetpack/modules/shortcodes/videopress.php index 6a3a75b0..08f33c6f 100644 --- a/plugins/jetpack/modules/shortcodes/videopress.php +++ b/plugins/jetpack/modules/shortcodes/videopress.php @@ -1,1333 +1,3 @@ <?php -/** - * @package video - * @category video - * @author Automattic Inc - * @link http://automattic.com/wordpress-plugins/#videopress VideoPress - * @version 1.5.4 - * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - */ - -/* -Plugin Name: VideoPress -Plugin URI: http://wordpress.org/extend/plugins/video/ -Description: Upload new videos to <a href="http://videopress.com/">VideoPress</a>, edit metadata, and easily insert VideoPress videos into posts and pages using shortcodes. Requires a <a href="http://wordpress.com/">WordPress.com</a> account and a WordPress.com blog with the <a href="http://en.wordpress.com/products/#videopress">VideoPress upgrade</a> to store and serve uploaded videos. -Author: Automattic, Niall Kennedy, Joseph Scott, Gary Pendergast -Contributor: Hailin Wu -Author URI: http://automattic.com/wordpress-plugins/#videopress -Version: 1.5.4 -Stable tag: 1.5.4 -License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - */ - -if ( ! class_exists( 'VideoPress' ) ): - -/** - * VideoPress main handler. - * Attach actions and filters. Handle shortcodes. Add video button to rich text editor. - * @since 1.3 - */ -class VideoPress { - /** - * Plugin version in PHP-addressable form - * @var string - * @since 1.3 - */ - const version = '1.5.4'; - - /** - * Minimum allowed width. We don't expect videos viewed below this width to be useful; we drop small values to help save publishers from themselves. - * @var int - * @since 1.3 - */ - const min_width = 60; - - /** - * Remember if videopress.js and dependencies have already been loaded - * @var bool - * @since 1.5 - */ - var $js_loaded; - - /** - * Remember all of the videos loaded on this page - * @var array - * @since 1.5 - */ - var $shown; - - /** - * Attach actions, filters, and shortcode handlers - * @since 1.3 - */ - public function __construct() { - /** - * json_decode should be initialized by compat.php. It's a PHP extension that might not be turned on, or could not be compatible with older version of PHP. We won't be able to unpack the server response without it, so let's fail early. - */ - if ( ! function_exists( 'json_decode' ) ) - return; - - add_action( 'wp_head', array( $this, 'html_head' ), -1 ); // load before enqueue_scripts action - - //allow either [videopress xyz] or [wpvideo xyz] for backward compatibility - add_shortcode( 'videopress', array( $this, 'shortcode' ) ); - add_shortcode( 'wpvideo', array( $this, 'shortcode' ) ); - - // set default values - $this->js_loaded = false; - $this->shown = array(); - } - - /** - * PHP 4 constructor compatibility - * - * @since 1.5 - * @todo remove when targeting PHP 5 (WordPress 3.2 requirement) or above. - */ - public function VideoPress() { - $this->__construct(); - } - - /** - * Validate user-supplied guid values against expected inputs - * - * @since 1.1 - * @param string $guid video identifier - * @return bool true if passes validation test - */ - public static function is_valid_guid( $guid ) { - if ( ! empty( $guid ) && strlen( $guid ) === 8 && ctype_alnum( $guid ) ) - return true; - else - return false; - } - - /** - * Search a given content string for VideoPress shortcodes. Return an array of shortcodes with guid and attribute values. - * - * @since 1.2 - * @see do_shortcode() - * @param string $content post content string - * @return array Array of shortcode data. GUID as the key and other customization parameters as value. empty array if no matches found. - */ - public static function find_all_shortcodes( $content ) { - $r = preg_match_all( '/(.?)\[(wpvideo|videopress)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)/s', $content, $matches, PREG_SET_ORDER ); - - if ( $r === false || $r === 0 ) - return array(); - - $guids = array(); - foreach ( $matches as $m ) { - // allow [[foo]] syntax for escaping a tag - if ( $m[1] === '[' && $m[6] === ']' ) - continue; - $attr = shortcode_parse_atts( $m[3] ); - if ( self::is_valid_guid( $attr[0] ) ) { - $guid = $attr[0]; - unset( $attr[0] ); - $guids[$guid] = $attr; - } - } - - return $guids; - } - - - /** - * Insert video handlers into HTML <head> if posts with video shortcodes exist. - * If video posts are present then queue VideoPress JavaScript files. - * If a video is present and is single post or page then add Open Graph protocol markup for first video found - * - * @since 1.3 - */ - public function html_head() { - if ( is_feed() || ! have_posts() ) - return; - - $guid = ''; - while ( have_posts() ) { - the_post(); - $guids = self::find_all_shortcodes( get_the_content() ); - if ( ! empty( $guids ) ) { - $guid = trim( key( $guids ) ); - break; - } - unset( $guids ); - } - rewind_posts(); - - if ( ! empty( $guid ) ) - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 20 ); - } - - /** - * Add VideoPress JavaScript files to the script queue. - * A blog with the video_player_freedom option set to true may still require the VideoPress JS for stats purposes and therefore is not a reason for exclusion. - * - * @uses wp_enqueue_script() - * @since 1.3 - * @return bool true if queued; else false - */ - public function enqueue_scripts() { - if ( $this->js_loaded === true ) - return false; - - $jquery = '://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'; - $swfobject = '://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js'; - if ( is_ssl() ) { - $vpjs = 'https://v0.wordpress.com/js/videopress.js'; - $swfobject = 'https' . $swfobject; - $jquery = 'https' . $jquery; - } else { - $vpjs = 'http://s0.videopress.com/js/videopress.js'; - $swfobject = 'http' . $swfobject; - $jquery = 'http' . $jquery; - } - - wp_enqueue_script( 'swfobject', $swfobject, false. '2.2' ); - wp_enqueue_script( 'jquery', $jquery, false, '1.4.4' ); - wp_enqueue_script( 'videopress', $vpjs, array( 'jquery','swfobject' ), '1.09' ); - - $this->js_loaded = true; - return true; - } - - /** - * Print the VideoPress JS files now. - * Used to load the JS in the footer, if it hasn't already been loaded in the header. - * - * @uses wp_enqueue_script() - * @uses wp_print_scripts() - * @since 1.5 - */ - public function print_scripts() { - if ( $this->enqueue_scripts() === true ) - wp_print_scripts( array( 'swfobject', 'videopress' ) ); - } - - /** - * Translate a 'videopress' or 'wpvideo' shortcode and arguments into a video player display. - * - * @link http://codex.wordpress.org/Shortcode_API Shortcode API - * @param array $attr shortcode attributes - * @return string HTML markup or blank string on fail - */ - public function shortcode( $attr ) { - global $content_width; - - $guid = $attr[0]; - if ( ! self::is_valid_guid( $guid ) ) - return ''; - - if ( array_key_exists( $guid, $this->shown ) ) - $this->shown[$guid]++; - else - $this->shown[$guid] = 1; - - extract( shortcode_atts( array( - 'w' => 0, - 'freedom' => false, - 'flashonly' => false, - 'autoplay' => false, - 'hd' => false - ), $attr ) ); - - $freedom = (bool) $freedom; - /** - * Test if embedded blog prefers videos only displayed in Freedom-loving formats - */ - if ( $freedom === false && (bool) get_option( 'video_player_freedom', false ) ) - $freedom = true; - - $forcestatic = get_option( 'video_player_static', false ); - - /** - * Set the video to HD if the blog option has it enabled - */ - if ( (bool) get_option( 'video_player_high_quality', false ) ) - $hd = true; - - $width = absint($w); - unset($w); - - if ( $width < self::min_width ) - $width = 0; - elseif ( isset($content_width) && $content_width > self::min_width && $width > $content_width ) - $width = 0; - - if ( $width === 0 && isset( $content_width ) && $content_width > self::min_width ) - $width = $content_width; - - if ( ($width % 2) === 1 ) - $width--; - - $options = array( - 'freedom' => $freedom, - 'force_flash' => (bool) $flashonly, - 'autoplay' => (bool) $autoplay, - 'forcestatic' => $forcestatic, - 'hd' => (bool) $hd - ); - unset( $freedom ); - unset( $flashonly ); - - add_action( 'wp_footer', array( $this, 'print_scripts' ), -1 ); - - $player = new VideoPress_Player( $guid, $width, $options ); - if ( $player instanceOf VideoPress_Player ) { - if ( is_feed() ) - return $player->asXML(); - else - return $player->asHTML(); - } else { - return 'error'; - } - } - - /** - * Add a video button above the post composition screen linking to a thickbox view of WordPress.com videos - * - * @since 0.1.0 - */ - public function media_button() { - echo '<a href="https://public-api.wordpress.com/videopress-plugin.php?page=video-plugin&video_plugin=1&iframe&TB_iframe=true" id="add_video" class="thickbox" title="VideoPress"><img src="' . esc_url( plugins_url( ) . '/' . dirname( plugin_basename( __FILE__ ) ) . '/camera-video.png' ) . '" alt="VideoPress" width="16" height="16" /></a>'; - } -} - -/** - * VideoPress video object retrieved from VideoPress servers and parsed. - * @since 1.3 - */ -class VideoPress_Video { - /** - * Manifest version returned by remote service. - * - * @var string - * @since 1.3 - */ - const manifest_version = '1.5'; - - /** - * Expiration of the video expressed in Unix time - * - * @var int - * @since 1.3 - */ - public $expires; - - /** - * VideoPress unique identifier - * - * @var string - * @since 1.3 - */ - public $guid; - - /** - * WordPress.com blog identifier - * - * @var int - * @since 1.5 - */ - public $blog_id; - - /** - * Remote blog attachment identifier - * - * @var int - * @since 1.5 - */ - public $post_id; - - /** - * Maximum desired width. - * - * @var int - * @since 1.3 - */ - public $maxwidth; - - /** - * Video width calculated based on original video dimensions and the requested maxwidth - * - * @var int - * @since 1.3 - */ - public $calculated_width; - - /** - * Video height calculated based on original video dimensions and the requested maxwidth - * - * @var int - * @since 1.3 - */ - public $calculated_height; - - /** - * Video title - * - * @var string - * @since 1.3 - */ - public $title; - - /** - * Directionality of title text. ltr or rtl - * - * @var string - * @since 1.3 - */ - public $text_direction; - - /** - * Text and audio language as ISO 639-2 language code - * - * @var string - * @since 1.3 - */ - public $language; - - /** - * Video duration in whole seconds - * - * @var int - * @since 1.3 - */ - public $duration; - - /** - * Recommended minimum age of the viewer. - * - * @var int - * @since 1.3 - */ - public $age_rating; - - /** - * Video author has restricted video embedding or sharing - * - * @var bool - * @since 1.3 - */ - public $restricted_embed; - - /** - * Poster frame image URI for the given video guid and calculated dimensions. - * - * @var string - * @since 1.3 - */ - public $poster_frame_uri; - - /** - * Video files associated with the given guid for the calculated dimensions. - * - * @var stdClass - * @since 1.3 - */ - public $videos; - - /** - * Video player information - * - * @var stdClass - * @since 1.3 - */ - public $players; - - /** - * Video player skinning preferences including background color and watermark - * - * @var array - * @since 1.5 - */ - public $skin; - - /** - * Closed captions if available for the given video. Associative array of ISO 639-2 language code and a WebVTT URI - * - * @var array - * @since 1.5 - */ - public $captions; - - /** - * Setup the object. - * Request video information from VideoPress servers and process the response. - * - * @since 1.3 - * @var string $guid VideoPress unique identifier - * @var int $maxwidth maximum requested video width. final width and height are calculated on VideoPress servers based on the aspect ratio of the original video upload. - */ - public function __construct( $guid, $maxwidth=0 ) { - if ( VideoPress::is_valid_guid( $guid ) ) - $this->guid = $guid; - - $maxwidth = absint( $maxwidth ); - if ( $maxwidth > 0 ) - $this->maxwidth = $maxwidth; - - $data = $this->get_data(); - if ( is_wp_error( $data ) || empty( $data ) ) { - $this->error = $data; - return; - } - - if ( isset( $data->blog_id ) ) - $this->blog_id = absint( $data->blog_id ); - - if ( isset( $data->post_id ) ) - $this->post_id = absint( $data->post_id ); - - if ( isset( $data->title ) && $data->title !== '' ) - $this->title = trim( str_replace( ' ', ' ', $data->title ) ); - - if ( isset( $data->text_direction ) && $data->text_direction === 'rtl' ) - $this->text_direction = 'rtl'; - else - $this->text_direction = 'ltr'; - - if ( isset( $data->language ) ) - $this->language = $data->language; - - if ( isset( $data->duration ) && $data->duration > 0 ) - $this->duration = absint( $data->duration ); - - if ( isset( $data->width ) && $data->width > 0 ) - $this->calculated_width = absint( $data->width ); - - if ( isset( $data->height ) && $data->height > 0 ) - $this->calculated_height = absint( $data->height ); - - if ( isset( $data->age_rating ) ) - $this->age_rating = absint( $this->age_rating ); - - if ( isset( $data->restricted_embed ) && $data->restricted_embed === true ) - $this->restricted_embed = true; - else - $this->restricted_embed = false; - - if ( isset( $data->posterframe ) && $data->posterframe !== '' ) - $this->poster_frame_uri = esc_url_raw( $data->posterframe, array( 'http', 'https' ) ); - - if ( isset( $data->mp4 ) || isset( $data->ogv ) ) { - $this->videos = new stdClass(); - if ( isset( $data->mp4 ) ) - $this->videos->mp4 = $data->mp4; - if ( isset( $data->ogv ) ) - $this->videos->ogv = $data->ogv; - } - - if ( isset( $data->swf ) ) { - if ( ! isset( $this->players ) ) - $this->players = new stdClass(); - $this->players->swf = $data->swf; - } - - if ( isset( $data->skin ) ) - $this->skin = $data->skin; - - if ( isset( $data->captions ) ) - $this->captions = (array) $data->captions; - } - - /** - * PHP 4 constructor compatibility - * - * @since 1.5 - * @todo remove when targeting PHP 5 (WordPress 3.2 requirement) or above. - */ - public function VideoPress_Video( $guid, $maxwidth=0 ) { - $this->__construct( $guid, $maxwidth ); - } - - /** - * Convert an Expires HTTP header value into Unix time for use in WP Cache - * - * @since 1.3 - * @var string $expires_header - * @return int|bool Unix time or false - */ - public static function calculate_expiration( $expires_header ) { - if ( empty( $expires_header ) || ! is_string( $expires_header ) ) - return false; - - if ( class_exists( 'DateTime' ) && class_exists( 'DateTimeZone' ) ) { - $expires_date = DateTime::createFromFormat( 'D, d M Y H:i:s T', $expires_header, new DateTimeZone( 'UTC' ) ); - if ( $expires_date instanceOf DateTime ) - return date_format( $expires_date, 'U' ); - } else { - $expires_array = strptime( $expires_header, '%a, %d %b %Y %H:%M:%S %Z' ); - if ( is_array( $expires_array ) && isset( $expires_array['tm_hour'] ) && isset( $expires_array['tm_min'] ) && isset( $expires_array['tm_sec'] ) && isset( $expires_array['tm_mon'] ) && isset( $expires_array['tm_mday'] ) && isset( $expires_array['tm_year'] ) ) - return gmmktime( $expires_array['tm_hour'], $expires_array['tm_min'], $expires_array['tm_sec'], 1 + $expires_array['tm_mon'], $expires_array['tm_mday'], 1900 + $expires_array['tm_year'] ); - } - return false; - } - - /** - * Extract the site's host domain for statistics and comparison against an allowed site list in the case of restricted embeds. - * - * @since 1.2 - * @param string $url absolute URL - * @return bool|string host component of the URL, or false if none found - */ - public static function hostname( $url ) { - if ( empty($url) || ! function_exists('parse_url') ) - return false; - - // PHP 5.3.3 or newer can throw a warning on a bad input URI. catch that occurance just in case - try { - return parse_url( $url, PHP_URL_HOST ); - } catch (Exception $e){} - return false; - } - - - /** - * Request data from WordPress.com for the given guid, maxwidth, and calculated blog hostname. - * - * @since 1.3 - * @return stdClass|WP_Error parsed JSON response or WP_Error if request unsuccessful - */ - private function get_data() { - global $wp_version; - - $domain = self::hostname( home_url() ); - $request_params = array( 'guid' => $this->guid, 'domain' => $domain ); - if ( isset( $this->maxwidth ) && $this->maxwidth > 0 ) - $request_params['maxwidth'] = $this->maxwidth; - - $url = 'http://videopress.com/data/wordpress.json'; - if ( is_ssl() ) - $url = 'https://v.wordpress.com/data/wordpress.json'; - - $response = wp_remote_get( $url . '?' . http_build_query( $request_params, null, '&' ), array( - 'redirection' => 1, - 'user-agent' => 'VideoPress plugin ' . VideoPress::version . '; WordPress ' . $wp_version . ' (' . home_url('/') . ')' - ) ); - unset( $request_params ); - unset( $url ); - $response_body = wp_remote_retrieve_body( $response ); - $response_code = absint( wp_remote_retrieve_response_code( $response ) ); - - if ( is_wp_error( $response ) ) { - return $response; - } elseif ( $response_code === 400 ) { - return new WP_Error( 'bad_config', __( 'The VideoPress plugin could not communicate with the VideoPress servers. This error is most likely caused by a misconfigured plugin. Please reinstall or upgrade.', 'jetpack' ) ); - } elseif ( $response_code === 403 ) { - return new WP_Error( 'http_forbidden', '<p>' . sprintf( __( '<strong>%s</strong> is not an allowed embed site.' , 'jetpack' ), esc_html( $domain ) ) . '</p><p>' . __( 'Publisher limits playback of video embeds.', 'jetpack' ) . '</p>' ); - } elseif ( $response_code === 404 ) { - return new WP_Error( 'http_not_found', '<p>' . sprintf( __( 'No data found for VideoPress identifier: <strong>%s</strong>.', 'jetpack' ), $this->guid ) . '</p>' ); - } elseif ( $response_code !== 200 || empty( $response_body ) ) { - return; - } else { - $expires_header = wp_remote_retrieve_header( $response, 'Expires' ); - if ( ! empty( $expires_header ) ) { - $expires = self::calculate_expiration( $expires_header ); - if ( ! empty( $expires ) ) - $this->expires = $expires; - } - return json_decode( $response_body ); - } - } -} - -/** - * VideoPress playback module markup generator. - * - * @since 1.3 - */ -class VideoPress_Player { - /** - * Video data for the requested guid and maximum width - * - * @since 1.3 - * @var VideoPress_Video - */ - protected $video; - - /** - * DOM identifier of the video container - * - * @var string - * @since 1.3 - */ - protected $video_container_id; - - /** - * DOM identifier of the video element (video, object, embed) - * - * @var string - * @since 1.3 - */ - protected $video_id; - - /** - * Array of playback options: force_flash or freedom - * - * @var array - * @since 1.3 - */ - protected $options; - - /** - * Initiate a player object based on shortcode values and possible blog-level option overrides - * - * @since 1.3 - * @var string $guid VideoPress unique identifier - * @var int $maxwidth maximum desired width of the video player if specified - * @var array $options player customizations - */ - public function __construct( $guid, $maxwidth = 0, $options = array() ) { - global $videopress; - $this->video_container_id = 'v-' . $guid . '-' . $videopress->shown[$guid]; - $this->video_id = $this->video_container_id . '-video'; - - if ( is_array( $options ) ) - $this->options = $options; - else - $this->options = array(); - - // set up the video - $cache_key = null; - - // disable cache in debug mode - if ( defined('WP_DEBUG') && WP_DEBUG === true ) { - $cached_video = null; - } else { - $cache_key_pieces = array( 'video' ); - if ( is_multisite() && is_subdomain_install() ) { - /** - * Compatibility wrapper for less than WordPress 3.1 - * - * @todo remove when targeting WordPress 3.2 or above. - */ - if ( function_exists( 'get_current_blog_id' ) ) - $cache_key_pieces[] = get_current_blog_id(); - elseif ( isset( $GLOBALS ) && isset( $GLOBALS['blog_id'] ) ) - $cache_key_pieces[] = absint( $GLOBALS['blog_id'] ); - else - $cache_key_pieces[] = 1; - } - $cache_key_pieces[] = $guid; - if ( $width > 0 ) - $cache_key_pieces[] = $maxwidth; - if ( is_ssl() ) - $cache_key_pieces[] = 'ssl'; - $cache_key = implode( '-', $cache_key_pieces ); - unset( $cache_key_pieces ); - $cached_video = wp_cache_get( $cache_key, 'video' ); - } - if ( empty( $cached_video ) ) { - $video = new VideoPress_Video( $guid, $maxwidth ); - if ( empty( $video ) ) { - return; - } elseif ( isset( $video->error ) ) { - $this->video = $video->error; - return; - } elseif ( is_wp_error( $video ) ) { - $this->video = $video; - return; - } - - $this->video = $video; - unset( $video ); - - if ( ! defined( 'WP_DEBUG' ) || WP_DEBUG !== true ) { - $expire = 3600; - if ( isset( $video->expires ) && is_int( $video->expires ) ) { - $expires_diff = time() - $video->expires; - if ( $expires_diff > 0 && $expires_diff < 86400 ) // allowed range: 1 second to 1 day - $expire = $expires_diff; - unset( $expires_diff ); - } - - wp_cache_set( $cache_key, serialize($this->video), 'video', $expire ); - unset( $expire ); - } - } else { - $this->video = unserialize( $cached_video ); - } - unset( $cache_key ); - unset( $cached_video ); - } - - /** - * PHP 4 constructor compatibility - * - * @since 1.5 - * @todo remove when targeting PHP 5 (WordPress 3.2 min requirement) or above. - */ - public function VideoPress_Player( $guid, $maxwidth = 0, $options = array() ) { - $this->__construct( $guid, $maxwidth, $options ); - } - - /** - * Wrap output in a VideoPress player container - * - * @since 1.3 - * @var string $content HTML string - * @return string HTML string or blank string if nothing to wrap - */ - private function html_wrapper( $content ) { - if ( empty( $content ) ) - return ''; - else - return '<div id="' . esc_attr( $this->video_container_id ) . '" class="video-player">' . $content . '</div>'; - } - - /** - * Output content suitable for a feed reader displaying RSS or Atom feeds - * We do not display error messages in the feed view due to caching concerns. - * Flash content presented using <embed> markup for feed reader compatibility. - * - * @since 1.3 - * @return string HTML string or empty string if error - */ - public function asXML() { - if ( empty( $this->video ) || is_wp_error( $this->video ) ) - return ''; - - if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) - $content = $this->html5_static(); - else - $content = $this->flash_embed(); - - return $this->html_wrapper( $content ); - } - - /** - * Video player markup for best matching the current request and publisher options - * @since 1.3 - * @return string HTML markup string or empty string if no video property found - */ - public function asHTML() { - if ( empty( $this->video ) ) { - $content = ''; - } elseif ( is_wp_error( $this->video ) ) { - $content = $this->error_message( $this->video ); - } elseif ( isset( $this->options['force_flash'] ) && $this->options['force_flash'] === true ) { - $content = $this->flash_object(); - } elseif ( isset( $this->video->restricted_embed ) && $this->video->restricted_embed === true ) { - if( $this->options['forcestatic'] ) - $content = $this->flash_object(); - else - $content = $this->html5_dynamic(); - } elseif ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) { - $content = $this->html5_static(); - } else { - $content = $this->html5_dynamic(); - } - return $this->html_wrapper( $content ); - } - - /** - * Display an error message to users capable of doing something about the error - * - * @since 1.3 - * @uses current_user_can() to test if current user has edit_posts capability - * @var WP_Error $error WordPress error - * @return string HTML string - */ - private function error_message( $error ) { - if ( ! current_user_can( 'edit_posts' ) || empty( $error ) ) - return ''; - - $html = '<div class="videopress-error" style="background-color:rgb(255,0,0);color:rgb(255,255,255);font-family:font-family:\'Helvetica Neue\',Arial,Helvetica,\'Nimbus Sans L\',sans-serif;font-size:140%;min-height:10em;padding-top:1.5em;padding-bottom:1.5em">'; - $html .= '<h1 style="font-size:180%;font-style:bold;line-height:130%;text-decoration:underline">' . esc_html( sprintf( __( '%s Error', 'jetpack' ), 'VideoPress' ) ) . '</h1>'; - foreach( $error->get_error_messages() as $message ) { - $html .= $message; - } - $html .= '</div>'; - return $html; - } - - /** - * Rating agencies and industry associations require a potential viewer verify his or her age before a video or its poster frame are displayed. - * Content rated for audiences 17 years of age or older requires such verification across multiple rating agencies and industry associations - * - * @since 1.3 - * @return bool true if video requires the viewer verify he or she is 17 years of age or older - */ - private function age_gate_required() { - if ( isset( $this->video->age_rating ) && $this->video->age_rating >= 17 ) - return true; - else - return false; - } - - /** - * Select a date of birth using HTML form elements. - * - * @since 1.5 - * @return string HTML markup - */ - private function html_age_gate() { - $text_align = 'left'; - if ( $this->video->text_direction === 'rtl' ) - $text_align = 'right'; - - $html = '<div class="videopress-age-gate" style="margin:0 60px">'; - $html .= '<p class="instructions" style="color:rgb(255, 255, 255);font-size:21px;padding-top:60px;padding-bottom:20px;text-align:' . $text_align . '">' . esc_html( __( 'This video is intended for mature audiences.', 'jetpack' ) ) . '<br />' . esc_html( __( 'Please verify your birthday.', 'jetpack' ) ) . '</p>'; - $html .= '<fieldset id="birthday" style="border:0 none;text-align:' . $text_align . ';padding:0;">'; - $inputs_style = 'border:1px solid #444;margin-'; - if ( $this->video->text_direction === 'rtl' ) - $inputs_style .= 'left'; - else - $inputs_style .= 'right'; - $inputs_style .= ':10px;background-color:rgb(0, 0, 0);font-size:14px;color:rgb(255,255,255);padding:4px 6px;line-height: 2em;vertical-align: middle'; - - /** - * Display a list of months in the Gregorian calendar. - * Set values to 0-based to match JavaScript Date. - * @link https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date Mozilla JavaScript Reference: Date - */ - $html .= '<select name="month" style="' . $inputs_style . '">'; - - $months = array( __('January', 'jetpack'), __('February', 'jetpack'), __('March', 'jetpack'), __('April', 'jetpack'), __('May', 'jetpack'), __('June', 'jetpack'), __('July', 'jetpack'), __('August', 'jetpack'), __('September', 'jetpack'), __('October', 'jetpack'), __('November', 'jetpack'), __('December', 'jetpack') ); - for( $i=0; $i<12; $i++ ) { - $html .= '<option value="' . esc_attr( $i ) . '">' . esc_html( $months[$i] ) . '</option>'; - } - $html .= '</select>'; - unset( $months ); - - /** - * todo: numdays variance by month - */ - $html .= '<select name="day" style="' . $inputs_style . '">'; - for ( $i=1; $i<32; $i++ ) { - $html .= '<option>' . $i . '</option>'; - } - $html .= '</select>'; - - /** - * Current record for human life is 122. Go back 130 years and no one is left out. - * Don't ask infants younger than 2 for their birthday - * Default to 13 - */ - $html .= '<select name="year" style="' . $inputs_style . '">'; - $start_year = date('Y') - 2; - $default_year = $start_year - 11; - $end_year = $start_year - 128; - for ( $year=$start_year; $year>$end_year; $year-- ) { - $html .= '<option'; - if ( $year === $default_year ) - $html .= ' selected="selected"'; - $html .= '>' . $year . '</option>'; - } - unset( $start_year ); - unset( $default_year ); - unset( $end_year ); - $html .= '</select>'; - - $html .= '<input type="submit" value="' . __( 'Submit', 'jetpack' ) . '" style="cursor:pointer;border-radius: 1em;border:1px solid #333;background-color:#333;background:-webkit-gradient( linear, left top, left bottom, color-stop(0.0, #444), color-stop(1, #111) );background:-moz-linear-gradient(center top, #444 0%, #111 100%);font-size:13px;padding:4px 10px 5px;line-height:1em;vertical-align:top;color:white;text-decoration:none;margin:0" />'; - - $html .= '</fieldset>'; - $html .= '<p style="padding-top:20px;padding-bottom:60px;text-align:' . $text_align . ';"><a rel="nofollow" href="http://videopress.com/" style="color:rgb(128,128,128);text-decoration:underline;font-size:15px">' . __( 'More information', 'jetpack' ) . '</a></p>'; - - $html .= '</div>'; - return $html; - } - - /** - * Return HTML5 video static markup for the given video parameters. - * Use default browser player controls. - * No Flash fallback. - * - * @since 1.2 - * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html HTML5 video - * @return string HTML5 video element and children - */ - private function html5_static() { - $thumbnail = esc_url( $this->video->poster_frame_uri ); - $html = "<video id=\"{$this->video_id}\" width=\"{$this->video->calculated_width}\" height=\"{$this->video->calculated_height}\" poster=\"$thumbnail\" controls=\"true\""; - if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) - $html .= ' autoplay="true"'; - else - $html .= ' preload="metadata"'; - if ( isset( $this->video->text_direction ) ) - $html .= ' dir="' . esc_attr( $this->video->text_direction ) . '"'; - if ( isset( $this->video->language ) ) - $html .= ' lang="' . esc_attr( $this->video->language ) . '"'; - $html .= '>'; - if ( ! isset( $this->options['freedom'] ) || $this->options['freedom'] === false ) { - $mp4 = $this->video->videos->mp4->url; - if ( ! empty( $mp4 ) ) - $html .= '<source src="' . esc_url( $mp4 ) . '" type="video/mp4; codecs="' . esc_attr( $this->video->videos->mp4->codecs ) . '"" />'; - unset( $mp4 ); - } - $ogg = $this->video->videos->ogv->url; - if ( ! empty( $ogg ) ) - $html .= '<source src="' . esc_url( $ogg ) . '" type="video/ogg; codecs="' . esc_attr( $this->video->videos->ogv->codecs ) . '"" />'; - unset( $ogg ); - - $html .= '<div><img alt="'; - if ( isset( $this->video->title ) ) - $html .= esc_attr( $this->video->title ); - $html .= '" src="' . $thumbnail . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" /></div>'; - if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) - $html .= '<p class="robots-nocontent">' . sprintf( __( 'You do not have sufficient <a rel="nofollow" href="%s">freedom levels</a> to view this video. Support free software and upgrade.', 'jetpack' ), 'http://www.gnu.org/philosophy/free-sw.html' ) . '</p>'; - elseif ( isset( $this->video->title ) ) - $html .= '<p>' . esc_html( $this->video->title ) . '</p>'; - $html .= '</video>'; - return $html; - } - - /** - * Click to play dynamic HTML5-capable player. - * The player displays a video preview section including poster frame, video title, play button and watermark on the original page load and calculates the playback capabilities of the browser. The video player is loaded when the visitor clicks on the video preview area. - * If Flash Player 10 or above is available the browser will display the Flash version of the video. If HTML5 video appears to be supported and the browser may be capable of MP4 (H.264, AAC) or OGV (Theora, Vorbis) playback the browser will display its native HTML5 player. - * - * @since 1.5 - * @return string HTML markup - */ - private function html5_dynamic() { - global $videopress; - - $video_placeholder_id = $this->video_container_id . '-placeholder'; - $age_gate_required = $this->age_gate_required(); - $width = absint( $this->video->calculated_width ); - $height = absint( $this->video->calculated_height ); - - $html = '<div id="' . $video_placeholder_id . '" class="videopress-placeholder" style="'; - if ( $age_gate_required ) - $html .= "min-width:{$width}px;min-height:{$height}px"; - else - $html .= "width:{$width}px;height:{$height}px"; - $html .= ';display:none;cursor:pointer !important;position:relative;'; - if ( isset( $this->video->skin ) && isset( $this->video->skin->background_color ) ) - $html .= 'background-color:' . esc_attr( $this->video->skin->background_color ) . ';'; - $html .= 'font-family: \'Helvetica Neue\',Arial,Helvetica,\'Nimbus Sans L\',sans-serif;font-weight:bold;font-size:18px">' . PHP_EOL; - - /** - * Do not display a poster frame, title, or any other content hints for mature content. - */ - if ( ! $age_gate_required ) { - if ( ! empty( $this->video->title ) ) { - $html .= '<div class="videopress-title" style="display:inline;position:absolute;margin:20px 20px 0 20px;padding:4px 8px;vertical-align:top;text-align:'; - if ( $this->video->text_direction === 'rtl' ) - $html .= 'right" dir="rtl"'; - else - $html .= 'left" dir="ltr"'; - if ( isset( $this->video->language ) ) - $html .= ' lang="' . esc_attr( $this->video->language ) . '"'; - $html .= '><span style="padding:3px 0;line-height:1.5em;'; - if ( isset( $this->video->skin ) && isset( $this->video->skin->background_color ) ) { - $html .= 'background-color:'; - if ( $this->video->skin->background_color === 'rgb(0,0,0)' ) - $html .= 'rgba(0,0,0,0.8)'; - else - $html .= esc_attr( $this->video->skin->background_color ); - $html .= ';'; - } - $html .= 'color:rgb(255,255,255)">' . esc_html( $this->video->title ) . '</span></div>'; - } - $html .= '<img class="videopress-poster" alt="'; - if ( ! empty( $this->video->title ) ) - $html .= esc_attr( $this->video->title ) . '" title="' . esc_attr( sprintf( _x( 'Watch: %s', 'watch a video title', 'jetpack' ), $this->video->title ) ); - $html .= '" src="' . esc_url( $this->video->poster_frame_uri, array( 'http', 'https' ) ) . '" width=' . $width . '" height="' . $height . '" />' . PHP_EOL; - - //style a play button hovered over the poster frame - $html .= '<div class="play-button"><span style="z-index:2;display:block;position:absolute;top:50%;left:50%;text-align:center;vertical-align:middle;color:rgb(255,255,255);opacity:0.9;margin:0 0 0 -0.45em;padding:0;line-height:0;font-size:500%;text-shadow:0 0 40px rgba(0,0,0,0.5)">▶</span></div>' . PHP_EOL; - - // watermark - if ( isset( $this->video->skin ) && isset( $this->video->skin->watermark ) ) { - $html .= '<div style="position:relative;margin-top:-40px;height:25px;margin-bottom:35px;'; - if ( $this->video->text_direction === 'rtl' ) - $html .= 'margin-left:20px;text-align:left;'; - else - $html .= 'margin-right:20px;text-align:right;'; - $html .= 'vertical-align:bottom;z-index:3">'; - $html .= '<img alt="" src="' . esc_url( $this->video->skin->watermark, array( 'http', 'https' ) ) . '" width="90" height="13" style="background-color:transparent;background-image:none;background-repeat:no-repeat;border:none;margin:0;padding:0"/>'; - $html .= '</div>' . PHP_EOL; - } - } - - $data = array( - 'blog' => absint( $this->video->blog_id ), - 'post' => absint( $this->video->post_id ), - 'duration'=> absint( $this->video->duration ), - 'poster' => esc_url_raw( $this->video->poster_frame_uri, array( 'http', 'https' ) ), - 'hd' => (bool) $this->options['hd'] - ); - if ( isset( $this->video->videos ) ) { - if ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) - $data['mp4'] = array( 'size' => $this->video->videos->mp4->format, 'uri' => esc_url_raw( $this->video->videos->mp4->url, array( 'http', 'https' ) ) ); - if ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) - $data['ogv'] = array( 'size' => 'std', 'uri' => esc_url_raw( $this->video->videos->ogv->url, array( 'http', 'https' ) ) ); - } - $locale = array( 'dir' => $this->video->text_direction ); - if ( isset( $this->video->language ) ) - $locale['lang'] = $this->video->language; - $data['locale'] = $locale; - unset( $locale ); - - $guid = $this->video->guid; - $guid_js = json_encode( $guid ); - $html .= '<script type="text/javascript">' . PHP_EOL; - $html .= 'jQuery(document).ready(function() {'; - - $html .= 'if ( !jQuery.VideoPress.data[' . json_encode($guid) . '] ) { jQuery.VideoPress.data[' . json_encode($guid) . '] = new Array(); }' . PHP_EOL; - $html .= 'jQuery.VideoPress.data[' . json_encode( $guid ) . '][' . $videopress->shown[$guid] . ']=' . json_encode($data) . ';' . PHP_EOL; - unset( $data ); - - $jq_container = json_encode( '#' . $this->video_container_id ); - $jq_placeholder = json_encode( '#' . $video_placeholder_id ); - $player_config = "{width:{$width},height:{$height},"; - if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) - $player_config .= 'freedom:"true",'; - $player_config .= 'container:jQuery(' . $jq_container . ')}'; - - $html .= "jQuery({$jq_placeholder}).show(0,function(){jQuery.VideoPress.analytics.impression({$guid_js})});" . PHP_EOL; - - if ( $age_gate_required ) { - $html .= 'if ( jQuery.VideoPress.support.flash() ) {' . PHP_EOL; - /** - * @link http://code.google.com/p/swfobject/wiki/api#swfobject.embedSWF(swfUrlStr,_replaceElemIdStr,_widthStr,_height - */ - $html .= 'swfobject.embedSWF(' . implode( ',', array( - 'jQuery.VideoPress.video.flash.player_uri', - json_encode( $this->video_container_id ), - json_encode( $width ), - json_encode( $height ), - 'jQuery.VideoPress.video.flash.min_version', - 'jQuery.VideoPress.video.flash.expressinstall', // attempt to upgrade the Flash player if less than min_version. requires a 310x137 container or larger but we will always try to include - '{guid:' . $guid_js . '}', // FlashVars - 'jQuery.VideoPress.video.flash.params', - 'null', // no attributes - 'jQuery.VideoPress.video.flash.embedCallback' // error fallback - ) ) . ');'; - $html .= '} else {' . PHP_EOL; - $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js},{$player_config}," . $videopress->shown[$guid] . ') ) {' . PHP_EOL; - $html .= 'if ( jQuery(' . $jq_container . ').data( "player" ) === "flash" ){jQuery.VideoPress.video.play(jQuery(' . json_encode('#' . $this->video_container_id) . '));}else{'; - $html .= 'jQuery(' . $jq_placeholder . ').html(' . json_encode( $this->html_age_date() ) . ');' . PHP_EOL; - $html .= 'jQuery(' . json_encode( '#' . $video_placeholder_id . ' input[type=submit]' ) . ').one("click", function(event){jQuery.VideoPress.requirements.isSufficientAge(jQuery(' . $jq_container . '),' . absint( $this->video->age_rating ) . ')});' . PHP_EOL; - $html .= '}}}' . PHP_EOL; - } else { - $html .= "if ( jQuery.VideoPress.video.prepare({$guid_js}, {$player_config}," . $videopress->shown[$guid] . ') ) {' . PHP_EOL; - if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) - $html .= "jQuery.VideoPress.video.play(jQuery({$jq_container}));"; - else - $html .= 'jQuery(' . $jq_placeholder . ').one("click",function(){jQuery.VideoPress.video.play(jQuery(' . $jq_container . '))});'; - $html .= '}'; - - // close the jQuery(document).ready() function - $html .= '});'; - } - $html .= '</script>' . PHP_EOL; - $html .= '</div>' . PHP_EOL; - - /* - * JavaScript required - */ - $noun = __( 'this video', 'jetpack' ); - if ( ! $age_gate_required ) { - $vid_type = ''; - if ( ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) && ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) ) - $vid_type = 'ogv'; - elseif ( isset( $this->video->videos->mp4 ) && isset( $this->video->videos->mp4->url ) ) - $vid_type = 'mp4'; - elseif ( isset( $this->video->videos->ogv ) && isset( $this->video->videos->ogv->url ) ) - $vid_type = 'ogv'; - - if ( $vid_type !== '' ) { - $noun = '<a '; - if ( isset( $this->video->language ) ) - $noun .= 'hreflang="' . esc_attr( $this->video->language ) . '" '; - if ( $vid_type === 'mp4' ) - $noun .= 'type="video/mp4" href="' . esc_url( $this->video->videos->mp4->url, array( 'http', 'https' ) ); - elseif ( $vid_type === 'ogv' ) - $noun .= 'type="video/ogv" href="' . esc_url( $this->video->videos->ogv->url, array( 'http', 'https' ) ); - $noun .= '">'; - if ( isset( $this->video->title ) ) - $noun .= esc_html( $this->video->title ); - else - $noun .= __( 'this video', 'jetpack' ); - $noun .= '</a>'; - } elseif ( ! empty( $this->title ) ) { - $noun = esc_html( $this->title ); - } - unset( $vid_type ); - } - $html .= '<noscript><p>' . sprintf( _x( 'JavaScript required to play %s.', 'Play as in playback or view a movie', 'jetpack' ), $noun ) . '</p></noscript>'; - - return $html; - } - - /** - * Only allow legitimate Flash parameters and their values - * - * @since 1.2 - * @link http://kb2.adobe.com/cps/127/tn_12701.html Flash object and embed attributes - * @link http://kb2.adobe.com/cps/133/tn_13331.html devicefont - * @link http://kb2.adobe.com/cps/164/tn_16494.html allowscriptaccess - * @link http://www.adobe.com/devnet/flashplayer/articles/full_screen_mode.html full screen mode - * @link http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001079.html allownetworking - * @param array $flash_params Flash parameters expressed in key-value form - * @return array validated Flash parameters - */ - public static function esc_flash_params( $flash_params ) { - $allowed_params = array( - 'swliveconnect' => array('true', 'false'), - 'play' => array('true', 'false'), - 'loop' => array('true', 'false'), - 'menu' => array('true', 'false'), - 'quality' => array('low', 'autolow', 'autohigh', 'medium', 'high', 'best'), - 'scale' => array('default', 'noborder', 'exactfit', 'noscale'), - 'align' => array('l', 'r', 't'), - 'salign' => array('l', 'r', 't', 'tl', 'tr', 'bl', 'br'), - 'wmode' => array('window', 'opaque', 'transparent','direct','gpu'), - 'devicefont' => array('_sans', '_serif', '_typewriter'), - 'allowscriptaccess' => array('always', 'samedomain', 'never'), - 'allownetworking' => array('all','internal', 'none'), - 'seamlesstabbing' => array('true', 'false'), - 'allowfullscreen' => array('true', 'false'), - 'fullScreenAspectRatio' => array('portrait', 'landscape'), - 'base', - 'bgcolor', - 'flashvars' - ); - - $allowed_params_keys = array_keys( $allowed_params ); - - $filtered_params = array(); - foreach( $flash_params as $param=>$value ) { - if ( empty($param) || empty($value) ) - continue; - $param = strtolower($param); - if ( in_array($param, $allowed_params_keys) ) { - if ( isset( $allowed_params[$param] ) && is_array( $allowed_params[$param] ) ) { - $value = strtolower($value); - if ( in_array( $value, $allowed_params[$param] ) ) - $filtered_params[$param] = $value; - } else { - $filtered_params[$param] = $value; - } - } - } - unset( $allowed_params_keys ); - - /** - * Flash specifies sameDomain, not samedomain. change from lowercase value for preciseness - */ - if ( isset( $filtered_params['allowscriptaccess'] ) && $filtered_params['allowscriptaccess'] === 'samedomain' ) - $filtered_params['allowscriptaccess'] = 'sameDomain'; - - return $filtered_params; - } - - /** - * Filter Flash variables from the response, taking into consideration player options. - * - * @since 1.3 - * @return array Flash variable key value pairs - */ - private function get_flash_variables() { - if ( ! isset( $this->video->players->swf->vars ) ) - return array(); - - $flashvars = (array) $this->video->players->swf->vars; - if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) - $flashvars['autoPlay'] = 'true'; - return $flashvars; - } - - /** - * Validate and filter Flash parameters - * - * @since 1.3 - * @return array Flash parameters passed through key and value validation - */ - private function get_flash_parameters() { - if ( ! isset( $this->video->players->swf->params ) ) - return array(); - else - return self::esc_flash_params( apply_filters( 'video_flash_params', (array) $this->video->players->swf->params, 10, 1 ) ); - } - - /** - * Flash player markup in a HTML embed element. - * - * @since 1.1 - * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#the-embed-element embed element - * @link http://www.google.com/support/reader/bin/answer.py?answer=70664 Google Reader markup support - * @return string HTML markup. Embed element with no children - */ - private function flash_embed() { - if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) - return ''; - - $embed = array( - 'id' => $this->video_id, - 'src' => esc_url_raw( $this->video->players->swf->url . '&' . http_build_query( $this->get_flash_variables(), null, '&' ) , array( 'http', 'https' ) ), - 'type' => 'application/x-shockwave-flash', - 'width' => $this->video->calculated_width, - 'height' => $this->video->calculated_height - ); - if ( isset( $this->video->title ) ) - $embed['title'] = $this->video->title; - $embed = array_merge( $embed, $this->get_flash_parameters() ); - - $html = '<embed'; - foreach ( $embed as $attribute => $value ) { - $html .= ' ' . esc_html( $attribute ) . '="' . esc_attr( $value ) . '"'; - } - unset( $embed ); - $html .= '></embed>'; - return $html; - } - - /** - * Double-baked Flash object markup for Internet Explorer and more standards-friendly consuming agents. - * - * @since 1.1 - * @return HTML markup. Object and children. - */ - private function flash_object() { - if ( ! isset( $this->video->players->swf ) || ! isset( $this->video->players->swf->url ) ) - return ''; - - $thumbnail_html = '<img alt="'; - if ( isset( $this->video->title ) ) - $thumbnail_html .= esc_attr( $this->video->title ); - $thumbnail_html .= '" src="' . esc_url( $this->video->poster_frame_uri, array( 'http', 'https' ) ) . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" />'; - $flash_vars = esc_attr( http_build_query( $this->get_flash_variables(), null, '&' ) ); - $flash_params = ''; - foreach ( $this->get_flash_parameters() as $attribute => $value ) { - $flash_params .= '<param name="' . esc_attr( $attribute ) . '" value="' . esc_attr( $value ) . '" />'; - } - $flash_help = sprintf( __( 'This video requires <a rel="nofollow" href="%s">Adobe Flash</a> for playback.', 'jetpack' ), 'http://www.adobe.com/go/getflashplayer'); - $flash_player_url = esc_url( $this->video->players->swf->url, array( 'http', 'https' ) ); - $description = ''; - if ( isset( $this->video->title ) ) { - $standby = $this->video->title; - $description = '<p><strong>' . esc_html( $this->video->title ) . '</strong></p>'; - } else { - $standby = __( 'Loading video...', 'jetpack' ); - } - $standby = ' standby="' . esc_attr( $standby ) . '"'; - return <<<OBJECT -<script type="text/javascript">if(typeof swfobject!=="undefined"){swfobject.registerObject("{$this->video_id}", "{$this->video->players->swf->version}");}</script> -<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{$this->video->calculated_width}" height="{$this->video->calculated_height}" id="{$this->video_id}"{$standby}> - <param name="movie" value="{$flash_player_url}" /> - {$flash_params} - <param name="flashvars" value="{$flash_vars}" /> - <!--[if !IE]>--> - <object type="application/x-shockwave-flash" data="{$flash_player_url}" width="{$this->video->calculated_width}" height="{$this->video->calculated_height}"{$standby}> - {$flash_params} - <param name="flashvars" value="{$flash_vars}" /> - <!--<![endif]--> - {$thumbnail_html}{$description}<p class="robots-nocontent">{$flash_help}</p> - <!--[if !IE]>--> - </object> - <!--<![endif]--> -</object> -OBJECT; - } -} - -global $videopress; -$videopress = new VideoPress(); - -endif; -?> +// Boom! +require_once( JETPACK__PLUGIN_DIR . 'modules/videopress/shortcode.php' );
\ No newline at end of file diff --git a/plugins/jetpack/modules/shortcodes/vine.php b/plugins/jetpack/modules/shortcodes/vine.php new file mode 100644 index 00000000..184d005e --- /dev/null +++ b/plugins/jetpack/modules/shortcodes/vine.php @@ -0,0 +1,65 @@ +<?php +/** + * Vine shortcode + */ + +/** + * Vine embed code: + * <iframe class="vine-embed" src="https://vine.co/v/bjHh0zHdgZT" width="600" height="600" frameborder="0"></iframe> + * <script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script> + * + * URL example: + * https://vine.co/v/bjHh0zHdgZT/ + * + * Embed shortcode examples: + * [embed]https://vine.co/v/bjHh0zHdgZT[/embed] + * [embed width="300"]https://vine.co/v/bjHh0zHdgZT[/embed] + * [embed type="postcard" width="300"]https://vine.co/v/bjHh0zHdgZT[/embed] + **/ + +function vine_embed_video( $matches, $attr, $url, $rawattr ) { + static $vine_flag_embedded_script; + + $max_height = 300; + $type = 'simple'; + + // Only allow 'postcard' or 'simple' types + if ( isset( $rawattr['type'] ) && $rawattr['type'] === 'postcard' ) + $type = 'postcard'; + + $vine_size = Jetpack::get_content_width(); + + // If the user enters a value for width or height, we ignore the Jetpack::get_content_width() + if ( isset( $rawattr['width'] ) || isset( $rawattr['height'] ) ) { + // 300 is the minimum size that Vine provides for embeds. Lower than that, the postcard embeds looks weird. + $vine_size = max( $max_height, min( $attr['width'], $attr['height'] ) ); + } + + if ( empty( $vine_size ) ) { + $vine_size = $max_height; + } + + $url = 'https://vine.co/v/' . $matches[1] . '/embed/' . $type; + $vine_html = sprintf( '<iframe class="vine-embed" src="%s" width="%s" height="%s" frameborder="0"></iframe>', esc_url( $url ), (int) $vine_size, (int) $vine_size ); + + if ( $vine_flag_embedded_script !== true ) { + $vine_html .= '<script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script>'; + $vine_flag_embedded_script = true; + } + + return $vine_html; +} +wp_embed_register_handler( 'jetpack_vine', '#https?://vine.co/v/([a-z0-9]+).*#i', 'vine_embed_video' ); + +function vine_shortcode( $atts ) { + global $wp_embed; + + if ( empty( $atts['url'] ) ) + return ''; + + if ( ! preg_match( '#https?://vine.co/v/([a-z0-9]+).*#i', $atts['url'] ) ) + return ''; + + return $wp_embed->shortcode( $atts, $atts['url'] ); +} +add_shortcode( 'vine', 'vine_shortcode' ); |