Changeset 1245652
- Timestamp:
- 09/15/2015 06:30:35 AM (9 years ago)
- Location:
- featured-video-plus
- Files:
-
- 16 deleted
- 9 edited
- 28 copied
Legend:
- Unmodified
- Added
- Removed
-
featured-video-plus/tags/2.2.2/CHANGELOG.md
r1240519 r1245652 1 1 # Changelog # 2 3 4 5 2 6 3 7 ## 2.2.1: 2015-09-08 ## -
featured-video-plus/tags/2.2.2/featured-video-plus.php
r1240519 r1245652 4 4 Plugin URI: http://yrnxt.com/wordpress/featured-video-plus/ 5 5 Description: Add Featured Videos to your posts and pages. 6 Version: 2.2. 16 Version: 2.2. 7 7 Author: Alexander Höreth 8 8 Author URI: http://yrnxt.com … … 33 33 // CONSTANTS 34 34 if ( ! defined( 'FVP_VERSION' ) ) { 35 define( 'FVP_VERSION', '2.2. 1' );35 define( 'FVP_VERSION', '2.2.' ); 36 36 } 37 37 -
featured-video-plus/tags/2.2.2/js/frontend.js
r1240519 r1245652 5 5 /* global fvpdata */ 6 6 7 8 var $loader = $('<div />').addClass('fvp-loader'); 9 var playBg = 'url(\'' + fvpdata.playicon + '\')'; 10 var loadBg = 'url(\'' + fvpdata.loadicon + '\')'; 11 var bgState; 12 var cache = {}; 13 var initTimeout; 7 var videoCache = {}; 8 var selectorCache; 9 var initTimeout = 0; 14 10 15 11 … … 65 61 66 62 /** 67 * Trigger the play / load icon (and preload them). 68 */ 69 function triggerPlayLoad() { 70 // preload images 71 if (bgState === undefined) { 72 [fvpdata.playicon, fvpdata.loadicon].forEach(function(val) { 73 $('body').append($('<img/>', { 74 src: val, 75 alt: 'preload image', 76 style: 'display: none;' 77 })); 78 }); 79 } 80 81 // trigger image 82 bgState = bgState === playBg ? loadBg : playBg; 83 $loader.css({ backgroundImage: bgState }); 63 * Get the actionicon element from the provided container. 64 */ 65 function getActioniconElem(elem) { 66 var $elem = $(elem); 67 var $icon = $elem.children('.fvp-actionicon'); 68 $icon.css({ 69 height: $elem.height(), 70 width : $elem.width(), 71 margin: $elem.css('margin') 72 }); 73 74 return $icon; 84 75 } 85 76 … … 88 79 * Handle mouseover and mouseout events. 89 80 */ 90 function hover (event) {81 function hover(event) { 91 82 var $img = $(event.currentTarget).children('img'); 92 93 // Is the overlay displayed currently? 94 if (0 === $img.siblings('.fvp-loader').length) { 95 96 // Copy classes and css styles onto the play icon overlay. 97 $loader.addClass($img.attr('class')).css({ 98 height: $img.height(), 99 width: $img.width(), 100 margin: $img.css('margin') 101 }); 102 103 // Set icon to play icon, fade out image and insert overlay. 104 $loader.css({ backgroundImage: (bgState = playBg) }); 105 $img.animate({ opacity: fvpdata.opacity }).before($loader); 106 } else if (bgState !== loadBg) { 83 var $icon = getActioniconElem(event.currentTarget); 84 85 $icon.toggleClass('play'); 86 if ($icon.hasClass('play')) { 87 $img.animate({ opacity: fvpdata.opacity }); 88 } else { 107 89 $img.animate({ opacity: 1 }); 108 $loader.remove();109 90 } 110 91 } … … 119 100 var id = parseInt($self.attr('data-id'), 10); 120 101 121 triggerPlayLoad(); 102 var $icon = getActioniconElem(event.currentTarget); 103 $icon.addClass('load ' + fvpdata.color); 122 104 123 105 $.post(fvpdata.ajaxurl, { … … 137 119 } 138 120 139 triggerPlayLoad();121 ); 140 122 }); 141 123 } … … 160 142 }); 161 143 162 $('#DOMWindow').css({ backgroundImage: loadBg });163 164 144 // Check if the result is already cached 165 if (! cache[id]) {145 if (! ache[id]) { 166 146 $.post(fvpdata.ajaxurl, { 167 147 'action' : 'fvp_get_embed', … … 171 151 if (response.success) { 172 152 // cache the result to not reload when opened again 173 cache[id] = response.data;153 ache[id] = response.data; 174 154 175 155 $('#DOMWindow').html(response.data); … … 180 160 } else { 181 161 // From cache 182 $('#DOMWindow').html( cache[id] );162 $('#DOMWindow').html( ache[id] ); 183 163 sizeLocal(); 184 164 $(window).trigger('scroll'); … … 191 171 */ 192 172 function init() { 173 174 175 176 193 177 // remove wrapping anchors 194 178 // doing this twice with a 1 second delay to fix wrapped local video posters … … 203 187 // add hover effect and preload icons 204 188 $('.fvp-overlay, .fvp-dynamic') 205 .off('mouseenter').on('mouseenter', hover) 206 .off('mouseleave').on('mouseleave', hover); 207 triggerPlayLoad(); 189 .off('mouseenter').on('mouseenter', hoverAction) 190 .off('mouseleave').on('mouseleave', hoverAction); 208 191 209 192 // on-demand video insertion click handler 210 $('.fvp-dynamic'). click(dynamicTrigger);193 $('.fvp-dynamic').dynamicTrigger); 211 194 212 195 // overlay click handler 213 $('.fvp-overlay'). click(overlayTrigger);196 $('.fvp-overlay').overlayTrigger); 214 197 } 215 198 … … 219 202 */ 220 203 initFeaturedVideoPlus = function() { 221 clearTimeout(initTimeout); 222 initTimeout = setTimeout(init, 50); 204 if (0 === initTimeout) { 205 init(); 206 initTimeout = setTimeout(function() {}, 100); 207 } else { 208 clearTimeout(initTimeout); 209 initTimeout = setTimeout(init, 100); 210 } 223 211 }; 224 212 … … 234 222 } 235 223 236 initFeaturedVideoPlus(); 224 // preload images 225 [fvpdata.playicon, fvpdata.loadicon].forEach(function(val) { 226 $('body').append($('<img/>', {src: val, alt: 'preload image'}).hide()); 227 }); 237 228 }); 238 229 })(jQuery); -
featured-video-plus/tags/2.2.2/js/frontend.min.js
r1240519 r1245652 1 var initFeaturedVideoPlus;!function( a){"use strict";function t(){a(".has-post-video a>.featured-video-plus,.has-post-video a>.fvp-dynamic,.has-post-video a>.fvp-overlay,.has-post-video a>.wp-video,.has-post-video a>.wp-video-shortcode").unwrap(),a(".has-post-video .post-thumbnail>.post-thumbnail").removeClass("post-thumbnail"),a("a.post-thumbnail:empty").not(".fvp-dynamic, .fvp-overlay").remove()}function e(){fvpdata.fitvids&&a(".featured-video-plus.fvp-responsive").fitVids({customSelector:["iframe","object","embed"]})}function i(){if(fvpdata.width&&!fvpdata.fitvids){a(".fvp-local .wp-video").css({width:fvpdata.width,height:"auto"});var t=a(".fvp-local .wp-video .wp-video-shortcode");t.attr({width:fvpdata.width,height:fvpdata.width/t.attr("width")*t.attr("heigth")})}}function o(){void 0===p&&[fvpdata.playicon,fvpdata.loadicon].forEach(function(t){a("body").append(a("<img/>",{src:t,alt:"preload image",style:"display: none;"}))}),p=p===f?l:f,v.css({backgroundImage:p})}function d(t){var e=a(t.currentTarget).children("img");0===e.siblings(".fvp-loader").length?(v.addClass(e.attr("class")).css({height:e.height(),width:e.width(),margin:e.css("margin")}),v.css({backgroundImage:p=f}),e.animate({opacity:fvpdata.opacity}).before(v)):p!==l&&(e.animate({opacity:1}),v.remove())}function n(i){i.preventDefault();var d=a(i.currentTarget),n=parseInt(d.attr("data-id"),10);o(),a.post(fvpdata.ajaxurl,{action:"fvp_get_embed",fvp_nonce:fvpdata.nonce,id:n},function(a){if(a.success){var i=d.parent();d.replaceWith(a.data),i.find(".wp-audio-shortcode, .wp-video-shortcode").mediaelementplayer(),e(),t()}o()})}function r(t){t.preventDefault();var e=a(t.currentTarget),o=parseInt(e.attr("data-id"),10);e.openDOMWindow({eventType:null,windowPadding:0,borderSize:0,windowBGColor:"transparent",overlayOpacity:100*fvpdata.opacity,width:"100%",height:"100%"}),a("#DOMWindow").css({backgroundImage:l}),u[o]?(a("#DOMWindow").html(u[o]),i(),a(window).trigger("scroll")):a.post(fvpdata.ajaxurl,{action:"fvp_get_embed",fvp_nonce:fvpdata.nonce,id:o},function(t){t.success&&(u[o]=t.data,a("#DOMWindow").html(t.data),i(),a(window).trigger("scroll"))})}function s(){t(),setTimeout(t,1e3),e(),i(),a(".fvp-overlay, .fvp-dynamic").off("mouseenter").on("mouseenter",d).off("mouseleave").on("mouseleave",d),o(),a(".fvp-dynamic").click(n),a(".fvp-overlay").click(r)}var p,c,v=a("<div />").addClass("fvp-loader"),f="url('"+fvpdata.playicon+"')",l="url('"+fvpdata.loadicon+"')",u={};initFeaturedVideoPlus=function(){clearTimeout(c),c=setTimeout(s,50)},a(document).ready(function(){window.chrome&&a(".featured-video-plus iframe").each(function(){this.src=this.src}),initFeaturedVideoPlus()})}(jQuery);1 var initFeaturedVideoPlus;!function()})}(jQuery); -
featured-video-plus/tags/2.2.2/php/class-backend.php
r1202444 r1245652 557 557 if ( has_post_video( $id ) ) { 558 558 // Return featured video html as requested. 559 $video = get_the_post_video( $id);559 $video = ); 560 560 wp_send_json_success( $video ); 561 561 } else { -
featured-video-plus/tags/2.2.2/php/class-frontend.php
r1240519 r1245652 7 7 * Class containing frontend functionality. 8 8 * 9 * Enqueue scripts/styles, replace featured images by featured videos or 10 * insert the ajax request handlers, add 'has-post-video' class and 11 * register the [featured-video-plus] shortcode. 9 * Enqueue scripts and styles specific to the frontend. 12 10 * 13 11 * @since 1.0.0 … … 24 22 25 23 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue' ) ); 26 27 add_filter( 'post_thumbnail_html', array( $this, 'filter_post_thumbnail' ), 99, 5 );28 add_filter( 'post_class', array( $this, 'has_post_video_class' ) );29 30 add_shortcode( 'featured-video-plus', array( $this, 'shortcode' ) );31 24 } 32 25 … … 101 94 'overlay' => 'overlay' === $mode, 102 95 'opacity' => 0.75, 103 'loadicon' => 'overlay' === $mode ? FVP_URL . 'img/loadicon_w.gif' : 104 FVP_URL . 'img/loadicon_b.gif', 105 'playicon' => FVP_URL . 'img/playicon.png', 96 'color' => 'overlay' === $mode ? 'w' : 'b', 106 97 'width' => ! empty( $options['sizing']['width'] ) ? 107 98 $options['sizing']['width'] : null … … 118 109 119 110 120 /**121 * Display featured videos in place of featured images if a featured video is available and only if so desired by user.122 *123 * @see http://wordpress.stackexchange.com/a/41858124 * @since 1.0.0125 *126 * @param string $html featured image html, ready to echo127 * @param int $post_id id of target post128 * @param int $post_thumbnail_id id of featured image129 * @param string|array $size desired size of featured image / video130 * @param array $attr131 */132 public function filter_post_thumbnail(133 $html,134 $post_id,135 $post_thumbnail_id,136 $size,137 $attr138 ) {139 $size = $this->get_size();140 141 $options = get_option( 'fvp-settings' );142 $mode = ! empty( $options['mode'] ) ? $options['mode'] : null;143 $conditions = ! empty( $options['conditions'] ) ?144 $options['conditions'] : null;145 $single_replace = is_single() &&146 ! empty( $options['single_replace'] ) && $options['single_replace'];147 148 // Don't show a video.149 if ( ( 'manual' === $mode ) ||150 ( ! self::check_conditions( $conditions ) ) ||151 ( ! has_post_video( $post_id ) )152 ) {153 return $html;154 }155 156 157 // Playicon with onload JavaScript for initalizing FVP JS functionality158 // which has to be done from here because of infinite scroll plugins.159 $onload = '<img class="playicon onload" ' .160 'src="'. FVP_URL . 'img/playicon.png" ' .161 'alt="Featured Video Play Icon" ' .162 'onload="(function() {' .163 "('initFeaturedVideoPlus' in this) && ".164 "('function' === typeof initFeaturedVideoPlus) && ".165 "initFeaturedVideoPlus();" .166 '})();" ' .167 '/>';168 169 // Show the video on-click - lazy load.170 if ( 'dynamic' === $mode && ! $single_replace ) {171 return sprintf(172 '<a href="#" data-id="%s" class="fvp-dynamic post-thumbnail">%s</a>%s',173 $post_id,174 $html,175 $onload176 );177 }178 179 // Show the video on-click in an overlay.180 if ( 'overlay' === $mode && ! $single_replace ) {181 return sprintf(182 '<a href="#" data-id="%s" class="fvp-overlay post-thumbnail">%s</a>%s',183 $post_id,184 $html,185 $onload186 );187 }188 189 // Replace the featured image with the video.190 return get_the_post_video( $post_id, $size ) . $onload;191 }192 193 194 /**195 * Add a 'has-post-video' class to posts if appropriate.196 *197 * @since 2.0.0198 *199 * @param {array} $classes Existing classes200 * @return {array} Updated classes201 */202 public function has_post_video_class( $classes ) {203 global $post;204 205 if ( has_post_video( $post->ID ) ) {206 $classes[] = 'has-post-video';207 }208 return $classes;209 }210 211 212 /**213 * Shortcode for usage in post or page entries. Echos the post's featured video.214 *215 * @since 1.0.0216 *217 * @param array $atts can contain the width and/or height how the featured video should be displayed in px, optional218 */219 public function shortcode($atts){220 $w = isset($atts['width']) ? $atts['width'] : '';221 $h = isset($atts['height']) ? $atts['height'] : '';222 223 if ( has_post_video() ) {224 return get_the_post_video( null, array( $w, $h ) );225 }226 }227 228 229 /**230 * Check a given set of display conditions if one or more of them hold. If231 * an empty set is given, return true.232 *233 * @param {assoc} $conditions234 * @return {bool}235 */236 private static function check_conditions( $conditions ) {237 if ( empty( $conditions ) ) {238 return true;239 }240 241 $conditions_hold = false;242 foreach ( $conditions AS $fun => $value ) {243 $negate = false;244 if ( '!' === $fun[0] ) {245 $negate = true;246 $fun = substr( $fun, 1 );247 }248 249 if ( $value && function_exists( 'is_' . $fun ) ) {250 $call = call_user_func( 'is_' . $fun );251 $conditions_hold = $conditions_hold || ( $negate ? ! $call : $call );252 }253 }254 255 return $conditions_hold;256 }257 111 } -
featured-video-plus/tags/2.2.2/php/class-main.php
r1202444 r1245652 5 5 6 6 /** 7 * Class containing all functions needed on front- AND backend. Functions only needed on one of those are found in distinct classes. 7 * Class containing all functions needed on front- AND backend. Functions only 8 * needed on one of those are found in the individual FVP_Frontend and 9 * FVP_Backend classes. 8 10 * 9 11 * @since 1.0.0 … … 17 19 18 20 add_action( 'plugins_loaded', array( $this, 'language' ) ); 21 22 23 24 25 26 27 19 28 } 20 29 … … 28 37 * @param string|array $size 29 38 */ 30 public function get_the_post_video( $post_id = null, $size = null ) { 39 public function get_the_post_video( 40 $post_id = null, 41 $size = null, 42 $ajax = null 43 ) { 31 44 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; 32 45 … … 44 57 45 58 // Autoplay option. Suppressed when viewing admin. 46 $general['autoplay'] = self::parse_autoplay_options( $options) ? true : null;59 $general['autoplay'] = self::parse_autoplay_options(; 47 60 48 61 // Responsive scaling option. Not used when viewing the admin screen. … … 64 77 case 'local': 65 78 $img_meta = wp_get_attachment_metadata( $meta['id'] ); 66 $size = $this->get_size( $size, array(79 $size = get_size( $size, array( 67 80 'width' => ! empty($img_meta['width'] ) ? $img_meta['width'] : null, 68 81 'height' => ! empty($img_meta['height']) ? $img_meta['height'] : null, … … 91 104 $atts = array_merge( 92 105 $general, 93 $this->get_size( $size ),106 get_size( $size ), 94 107 ! empty( $defaults[ $provider ] ) ? $defaults[ $provider ] : array(), 95 108 isset( $meta['parameters'] ) ? $meta['parameters'] : array() … … 126 139 127 140 /** 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 128 269 * Determine featured video size 129 270 * … … 137 278 * in the media settings into consideration. 138 279 */ 139 protected function get_size( $size = null, $original = null ) {280 protected function get_size( $size = null, $original = null ) { 140 281 $options = get_option( 'fvp-settings' ); 141 282 … … 145 286 $size['width'] : 146 287 ( isset( $size[0] ) && is_numeric( $size[0] ) ? $size[0] : null ); 147 $height = isset( $size['height'] ) && is_numeric( $size['height'] ) ?288 $height = isset( $size['height'] ) &&is_numeric( $size['height'] ) ? 148 289 $size['height'] : 149 290 ( isset( $size[1] ) && is_numeric( $size[1] ) ? $size[1] : null ); … … 190 331 191 332 /** 192 * Parse the autoplay options to determine if video should or should not193 * autoplay.194 *195 * @param {assoic} $options196 * @return {bool}197 */198 private static function parse_autoplay_options( $options ) {199 if ( empty( $options['autoplay'] ) ) {200 return false;201 }202 203 if (204 ! empty( $options['autoplay']['always'] ) &&205 $options['autoplay']['always']206 ) {207 return true;208 };209 210 $mode = ! empty( $options['mode'] ) ? $options['mode'] : null;211 //$islazy = 'overlay' === $mode || 'dynamic' === $mode;212 $isajax = defined( 'DOING_AJAX' ) && DOING_AJAX;213 214 if (215 ! empty( $options['autoplay']['lazy'] ) &&216 $options['autoplay']['lazy'] &&217 $isajax218 ) {219 return true;220 }221 222 if (223 ! empty( $options['autoplay']['single'] ) &&224 $options['autoplay']['single'] &&225 is_single()226 ) {227 return true;228 }229 230 return false;231 }232 233 /**234 333 * Gets a post by an meta_key meta_value pair. Returns it's post_id. 235 334 * … … 248 347 if ( $meta_value !== null ) { 249 348 $prepared = $wpdb->prepare( 250 "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key=%s AND meta_value=%s LIMIT 1", 349 "SELECT post_id FROM {$wpdb->postmeta} " . 350 "WHERE meta_key=%s AND meta_value=%s LIMIT 1", 251 351 $meta_key, 252 352 $meta_value … … 264 364 265 365 /** 266 * Initializes i18n 267 * 268 * @since 1.3.0 269 */ 270 public function language() { 271 load_plugin_textdomain( 272 'featured-video-plus', 273 FVP_DIR . 'lng/', 274 FVP_NAME . '/lng/' 275 ); 276 } 366 * Check a given set of display conditions if one or more of them hold. If 367 * an empty set is given, return true. 368 * 369 * @param {assoc} $conditions 370 * @return {bool} 371 */ 372 private static function check_conditions( $conditions ) { 373 if ( empty( $conditions ) ) { 374 return true; 375 } 376 377 $conditions_hold = false; 378 foreach ( $conditions AS $fun => $value ) { 379 $negate = false; 380 if ( '!' === $fun[0] ) { 381 $negate = true; 382 $fun = substr( $fun, 1 ); 383 } 384 385 if ( $value && function_exists( 'is_' . $fun ) ) { 386 $call = call_user_func( 'is_' . $fun ); 387 $conditions_hold = $conditions_hold || ( $negate ? ! $call : $call ); 388 } 389 } 390 391 return $conditions_hold; 392 } 393 394 395 /** 396 * Parse the autoplay options to determine if video should or should not 397 * autoplay. 398 * 399 * @param {assoic} $options 400 * @return {bool} 401 */ 402 private static function parse_autoplay_options( 403 $options = array(), 404 $ajax = null 405 ) { 406 if ( empty( $options['autoplay'] ) ) { 407 return false; 408 } 409 410 if ( 411 ! empty( $options['autoplay']['always'] ) && 412 $options['autoplay']['always'] 413 ) { 414 return true; 415 }; 416 417 $mode = ! empty( $options['mode'] ) ? $options['mode'] : null; 418 //$ajax = defined( 'DOING_AJAX' ) && DOING_AJAX && $ajax; 419 420 if ( 421 ! empty( $options['autoplay']['lazy'] ) && 422 $options['autoplay']['lazy'] && 423 $ajax 424 ) { 425 return true; 426 } 427 428 if ( 429 ! empty( $options['autoplay']['single'] ) && 430 $options['autoplay']['single'] && 431 is_single() 432 ) { 433 return true; 434 } 435 436 return false; 437 } 438 439 277 440 } -
featured-video-plus/tags/2.2.2/readme.txt
r1240519 r1245652 11 11 Requires at least: 3.7 12 12 Tested up to: 4.3 13 Stable tag: 2.2. 113 Stable tag: 2.2. 14 14 15 15 Add Featured Videos to your posts and pages. Works like magic with most themes which use Featured Images. Local Media, YouTube, Vimeo and many more. … … 107 107 108 108 == Changelog == 109 110 111 112 109 113 110 114 = 2.2.1: 2015-09-08 = -
featured-video-plus/tags/2.2.2/styles/frontend.css
r1240519 r1245652 54 54 width: auto; 55 55 } 56 .fvp-overlay .fvp- loader,57 .fvp-dynamic .fvp- loader{56 .fvp-overlay .fvp-, 57 .fvp-dynamic .fvp- { 58 58 background: transparent no-repeat scroll center center; 59 59 position: absolute; … … 62 62 z-index: 999; 63 63 pointer-events: none; 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 64 82 } 65 83 #DOMWindow { … … 69 87 margin: auto auto; 70 88 overflow: hidden; 89 90 91 92 93 94 95 71 96 } 72 97 .featured-video-plus .wp-video a:not(.post-thumbnail) { … … 79 104 padding-top: 100% !important; 80 105 } 81 .onload.playicon {82 display: none;83 } -
featured-video-plus/trunk/CHANGELOG.md
r1240519 r1245652 1 1 # Changelog # 2 3 4 5 2 6 3 7 ## 2.2.1: 2015-09-08 ## -
featured-video-plus/trunk/featured-video-plus.php
r1240519 r1245652 4 4 Plugin URI: http://yrnxt.com/wordpress/featured-video-plus/ 5 5 Description: Add Featured Videos to your posts and pages. 6 Version: 2.2. 16 Version: 2.2. 7 7 Author: Alexander Höreth 8 8 Author URI: http://yrnxt.com … … 33 33 // CONSTANTS 34 34 if ( ! defined( 'FVP_VERSION' ) ) { 35 define( 'FVP_VERSION', '2.2. 1' );35 define( 'FVP_VERSION', '2.2.' ); 36 36 } 37 37 -
featured-video-plus/trunk/js/frontend.js
r1240519 r1245652 5 5 /* global fvpdata */ 6 6 7 8 var $loader = $('<div />').addClass('fvp-loader'); 9 var playBg = 'url(\'' + fvpdata.playicon + '\')'; 10 var loadBg = 'url(\'' + fvpdata.loadicon + '\')'; 11 var bgState; 12 var cache = {}; 13 var initTimeout; 7 var videoCache = {}; 8 var selectorCache; 9 var initTimeout = 0; 14 10 15 11 … … 65 61 66 62 /** 67 * Trigger the play / load icon (and preload them). 68 */ 69 function triggerPlayLoad() { 70 // preload images 71 if (bgState === undefined) { 72 [fvpdata.playicon, fvpdata.loadicon].forEach(function(val) { 73 $('body').append($('<img/>', { 74 src: val, 75 alt: 'preload image', 76 style: 'display: none;' 77 })); 78 }); 79 } 80 81 // trigger image 82 bgState = bgState === playBg ? loadBg : playBg; 83 $loader.css({ backgroundImage: bgState }); 63 * Get the actionicon element from the provided container. 64 */ 65 function getActioniconElem(elem) { 66 var $elem = $(elem); 67 var $icon = $elem.children('.fvp-actionicon'); 68 $icon.css({ 69 height: $elem.height(), 70 width : $elem.width(), 71 margin: $elem.css('margin') 72 }); 73 74 return $icon; 84 75 } 85 76 … … 88 79 * Handle mouseover and mouseout events. 89 80 */ 90 function hover (event) {81 function hover(event) { 91 82 var $img = $(event.currentTarget).children('img'); 92 93 // Is the overlay displayed currently? 94 if (0 === $img.siblings('.fvp-loader').length) { 95 96 // Copy classes and css styles onto the play icon overlay. 97 $loader.addClass($img.attr('class')).css({ 98 height: $img.height(), 99 width: $img.width(), 100 margin: $img.css('margin') 101 }); 102 103 // Set icon to play icon, fade out image and insert overlay. 104 $loader.css({ backgroundImage: (bgState = playBg) }); 105 $img.animate({ opacity: fvpdata.opacity }).before($loader); 106 } else if (bgState !== loadBg) { 83 var $icon = getActioniconElem(event.currentTarget); 84 85 $icon.toggleClass('play'); 86 if ($icon.hasClass('play')) { 87 $img.animate({ opacity: fvpdata.opacity }); 88 } else { 107 89 $img.animate({ opacity: 1 }); 108 $loader.remove();109 90 } 110 91 } … … 119 100 var id = parseInt($self.attr('data-id'), 10); 120 101 121 triggerPlayLoad(); 102 var $icon = getActioniconElem(event.currentTarget); 103 $icon.addClass('load ' + fvpdata.color); 122 104 123 105 $.post(fvpdata.ajaxurl, { … … 137 119 } 138 120 139 triggerPlayLoad();121 ); 140 122 }); 141 123 } … … 160 142 }); 161 143 162 �� $('#DOMWindow').css({ backgroundImage: loadBg });163 164 144 // Check if the result is already cached 165 if (! cache[id]) {145 if (! ache[id]) { 166 146 $.post(fvpdata.ajaxurl, { 167 147 'action' : 'fvp_get_embed', … … 171 151 if (response.success) { 172 152 // cache the result to not reload when opened again 173 cache[id] = response.data;153 ache[id] = response.data; 174 154 175 155 $('#DOMWindow').html(response.data); … … 180 160 } else { 181 161 // From cache 182 $('#DOMWindow').html( cache[id] );162 $('#DOMWindow').html( ache[id] ); 183 163 sizeLocal(); 184 164 $(window).trigger('scroll'); … … 191 171 */ 192 172 function init() { 173 174 175 176 193 177 // remove wrapping anchors 194 178 // doing this twice with a 1 second delay to fix wrapped local video posters … … 203 187 // add hover effect and preload icons 204 188 $('.fvp-overlay, .fvp-dynamic') 205 .off('mouseenter').on('mouseenter', hover) 206 .off('mouseleave').on('mouseleave', hover); 207 triggerPlayLoad(); 189 .off('mouseenter').on('mouseenter', hoverAction) 190 .off('mouseleave').on('mouseleave', hoverAction); 208 191 209 192 // on-demand video insertion click handler 210 $('.fvp-dynamic'). click(dynamicTrigger);193 $('.fvp-dynamic').dynamicTrigger); 211 194 212 195 // overlay click handler 213 $('.fvp-overlay'). click(overlayTrigger);196 $('.fvp-overlay').overlayTrigger); 214 197 } 215 198 … … 219 202 */ 220 203 initFeaturedVideoPlus = function() { 221 clearTimeout(initTimeout); 222 initTimeout = setTimeout(init, 50); 204 if (0 === initTimeout) { 205 init(); 206 initTimeout = setTimeout(function() {}, 100); 207 } else { 208 clearTimeout(initTimeout); 209 initTimeout = setTimeout(init, 100); 210 } 223 211 }; 224 212 … … 234 222 } 235 223 236 initFeaturedVideoPlus(); 224 // preload images 225 [fvpdata.playicon, fvpdata.loadicon].forEach(function(val) { 226 $('body').append($('<img/>', {src: val, alt: 'preload image'}).hide()); 227 }); 237 228 }); 238 229 })(jQuery); -
featured-video-plus/trunk/js/frontend.min.js
r1240519 r1245652 1 var initFeaturedVideoPlus;!function( a){"use strict";function t(){a(".has-post-video a>.featured-video-plus,.has-post-video a>.fvp-dynamic,.has-post-video a>.fvp-overlay,.has-post-video a>.wp-video,.has-post-video a>.wp-video-shortcode").unwrap(),a(".has-post-video .post-thumbnail>.post-thumbnail").removeClass("post-thumbnail"),a("a.post-thumbnail:empty").not(".fvp-dynamic, .fvp-overlay").remove()}function e(){fvpdata.fitvids&&a(".featured-video-plus.fvp-responsive").fitVids({customSelector:["iframe","object","embed"]})}function i(){if(fvpdata.width&&!fvpdata.fitvids){a(".fvp-local .wp-video").css({width:fvpdata.width,height:"auto"});var t=a(".fvp-local .wp-video .wp-video-shortcode");t.attr({width:fvpdata.width,height:fvpdata.width/t.attr("width")*t.attr("heigth")})}}function o(){void 0===p&&[fvpdata.playicon,fvpdata.loadicon].forEach(function(t){a("body").append(a("<img/>",{src:t,alt:"preload image",style:"display: none;"}))}),p=p===f?l:f,v.css({backgroundImage:p})}function d(t){var e=a(t.currentTarget).children("img");0===e.siblings(".fvp-loader").length?(v.addClass(e.attr("class")).css({height:e.height(),width:e.width(),margin:e.css("margin")}),v.css({backgroundImage:p=f}),e.animate({opacity:fvpdata.opacity}).before(v)):p!==l&&(e.animate({opacity:1}),v.remove())}function n(i){i.preventDefault();var d=a(i.currentTarget),n=parseInt(d.attr("data-id"),10);o(),a.post(fvpdata.ajaxurl,{action:"fvp_get_embed",fvp_nonce:fvpdata.nonce,id:n},function(a){if(a.success){var i=d.parent();d.replaceWith(a.data),i.find(".wp-audio-shortcode, .wp-video-shortcode").mediaelementplayer(),e(),t()}o()})}function r(t){t.preventDefault();var e=a(t.currentTarget),o=parseInt(e.attr("data-id"),10);e.openDOMWindow({eventType:null,windowPadding:0,borderSize:0,windowBGColor:"transparent",overlayOpacity:100*fvpdata.opacity,width:"100%",height:"100%"}),a("#DOMWindow").css({backgroundImage:l}),u[o]?(a("#DOMWindow").html(u[o]),i(),a(window).trigger("scroll")):a.post(fvpdata.ajaxurl,{action:"fvp_get_embed",fvp_nonce:fvpdata.nonce,id:o},function(t){t.success&&(u[o]=t.data,a("#DOMWindow").html(t.data),i(),a(window).trigger("scroll"))})}function s(){t(),setTimeout(t,1e3),e(),i(),a(".fvp-overlay, .fvp-dynamic").off("mouseenter").on("mouseenter",d).off("mouseleave").on("mouseleave",d),o(),a(".fvp-dynamic").click(n),a(".fvp-overlay").click(r)}var p,c,v=a("<div />").addClass("fvp-loader"),f="url('"+fvpdata.playicon+"')",l="url('"+fvpdata.loadicon+"')",u={};initFeaturedVideoPlus=function(){clearTimeout(c),c=setTimeout(s,50)},a(document).ready(function(){window.chrome&&a(".featured-video-plus iframe").each(function(){this.src=this.src}),initFeaturedVideoPlus()})}(jQuery);1 var initFeaturedVideoPlus;!function()})}(jQuery); -
featured-video-plus/trunk/php/class-backend.php
r1202444 r1245652 557 557 if ( has_post_video( $id ) ) { 558 558 // Return featured video html as requested. 559 $video = get_the_post_video( $id);559 $video = ); 560 560 wp_send_json_success( $video ); 561 561 } else { -
featured-video-plus/trunk/php/class-frontend.php
r1240519 r1245652 7 7 * Class containing frontend functionality. 8 8 * 9 * Enqueue scripts/styles, replace featured images by featured videos or 10 * insert the ajax request handlers, add 'has-post-video' class and 11 * register the [featured-video-plus] shortcode. 9 * Enqueue scripts and styles specific to the frontend. 12 10 * 13 11 * @since 1.0.0 … … 24 22 25 23 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue' ) ); 26 27 add_filter( 'post_thumbnail_html', array( $this, 'filter_post_thumbnail' ), 99, 5 );28 add_filter( 'post_class', array( $this, 'has_post_video_class' ) );29 30 add_shortcode( 'featured-video-plus', array( $this, 'shortcode' ) );31 24 } 32 25 … … 101 94 'overlay' => 'overlay' === $mode, 102 95 'opacity' => 0.75, 103 'loadicon' => 'overlay' === $mode ? FVP_URL . 'img/loadicon_w.gif' : 104 FVP_URL . 'img/loadicon_b.gif', 105 'playicon' => FVP_URL . 'img/playicon.png', 96 'color' => 'overlay' === $mode ? 'w' : 'b', 106 97 'width' => ! empty( $options['sizing']['width'] ) ? 107 98 $options['sizing']['width'] : null … … 118 109 119 110 120 /**121 * Display featured videos in place of featured images if a featured video is available and only if so desired by user.122 *123 * @see http://wordpress.stackexchange.com/a/41858124 * @since 1.0.0125 *126 * @param string $html featured image html, ready to echo127 * @param int $post_id id of target post128 * @param int $post_thumbnail_id id of featured image129 * @param string|array $size desired size of featured image / video130 * @param array $attr131 */132 public function filter_post_thumbnail(133 $html,134 $post_id,135 $post_thumbnail_id,136 $size,137 $attr138 ) {139 $size = $this->get_size();140 141 $options = get_option( 'fvp-settings' );142 $mode = ! empty( $options['mode'] ) ? $options['mode'] : null;143 $conditions = ! empty( $options['conditions'] ) ?144 $options['conditions'] : null;145 $single_replace = is_single() &&146 ! empty( $options['single_replace'] ) && $options['single_replace'];147 148 // Don't show a video.149 if ( ( 'manual' === $mode ) ||150 ( ! self::check_conditions( $conditions ) ) ||151 ( ! has_post_video( $post_id ) )152 ) {153 return $html;154 }155 156 157 // Playicon with onload JavaScript for initalizing FVP JS functionality158 // which has to be done from here because of infinite scroll plugins.159 $onload = '<img class="playicon onload" ' .160 'src="'. FVP_URL . 'img/playicon.png" ' .161 'alt="Featured Video Play Icon" ' .162 'onload="(function() {' .163 "('initFeaturedVideoPlus' in this) && ".164 "('function' === typeof initFeaturedVideoPlus) && ".165 "initFeaturedVideoPlus();" .166 '})();" ' .167 '/>';168 169 // Show the video on-click - lazy load.170 if ( 'dynamic' === $mode && ! $single_replace ) {171 return sprintf(172 '<a href="#" data-id="%s" class="fvp-dynamic post-thumbnail">%s</a>%s',173 $post_id,174 $html,175 $onload176 );177 }178 179 // Show the video on-click in an overlay.180 if ( 'overlay' === $mode && ! $single_replace ) {181 return sprintf(182 '<a href="#" data-id="%s" class="fvp-overlay post-thumbnail">%s</a>%s',183 $post_id,184 $html,185 $onload186 );187 }188 189 // Replace the featured image with the video.190 return get_the_post_video( $post_id, $size ) . $onload;191 }192 193 194 /**195 * Add a 'has-post-video' class to posts if appropriate.196 *197 * @since 2.0.0198 *199 * @param {array} $classes Existing classes200 * @return {array} Updated classes201 */202 public function has_post_video_class( $classes ) {203 global $post;204 205 if ( has_post_video( $post->ID ) ) {206 $classes[] = 'has-post-video';207 }208 return $classes;209 }210 211 212 /**213 * Shortcode for usage in post or page entries. Echos the post's featured video.214 *215 * @since 1.0.0216 *217 * @param array $atts can contain the width and/or height how the featured video should be displayed in px, optional218 */219 public function shortcode($atts){220 $w = isset($atts['width']) ? $atts['width'] : '';221 $h = isset($atts['height']) ? $atts['height'] : '';222 223 if ( has_post_video() ) {224 return get_the_post_video( null, array( $w, $h ) );225 }226 }227 228 229 /**230 * Check a given set of display conditions if one or more of them hold. If231 * an empty set is given, return true.232 *233 * @param {assoc} $conditions234 * @return {bool}235 */236 private static function check_conditions( $conditions ) {237 if ( empty( $conditions ) ) {238 return true;239 }240 241 $conditions_hold = false;242 foreach ( $conditions AS $fun => $value ) {243 $negate = false;244 if ( '!' === $fun[0] ) {245 $negate = true;246 $fun = substr( $fun, 1 );247 }248 249 if ( $value && function_exists( 'is_' . $fun ) ) {250 $call = call_user_func( 'is_' . $fun );251 $conditions_hold = $conditions_hold || ( $negate ? ! $call : $call );252 }253 }254 255 return $conditions_hold;256 }257 111 } -
featured-video-plus/trunk/php/class-main.php
r1202444 r1245652 5 5 6 6 /** 7 * Class containing all functions needed on front- AND backend. Functions only needed on one of those are found in distinct classes. 7 * Class containing all functions needed on front- AND backend. Functions only 8 * needed on one of those are found in the individual FVP_Frontend and 9 * FVP_Backend classes. 8 10 * 9 11 * @since 1.0.0 … … 17 19 18 20 add_action( 'plugins_loaded', array( $this, 'language' ) ); 21 22 23 24 25 26 27 19 28 } 20 29 … … 28 37 * @param string|array $size 29 38 */ 30 public function get_the_post_video( $post_id = null, $size = null ) { 39 public function get_the_post_video( 40 $post_id = null, 41 $size = null, 42 $ajax = null 43 ) { 31 44 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; 32 45 … … 44 57 45 58 // Autoplay option. Suppressed when viewing admin. 46 $general['autoplay'] = self::parse_autoplay_options( $options) ? true : null;59 $general['autoplay'] = self::parse_autoplay_options(; 47 60 48 61 // Responsive scaling option. Not used when viewing the admin screen. … … 64 77 case 'local': 65 78 $img_meta = wp_get_attachment_metadata( $meta['id'] ); 66 $size = $this->get_size( $size, array(79 $size = get_size( $size, array( 67 80 'width' => ! empty($img_meta['width'] ) ? $img_meta['width'] : null, 68 81 'height' => ! empty($img_meta['height']) ? $img_meta['height'] : null, … … 91 104 $atts = array_merge( 92 105 $general, 93 $this->get_size( $size ),106 get_size( $size ), 94 107 ! empty( $defaults[ $provider ] ) ? $defaults[ $provider ] : array(), 95 108 isset( $meta['parameters'] ) ? $meta['parameters'] : array() … … 126 139 127 140 /** 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 128 269 * Determine featured video size 129 270 * … … 137 278 * in the media settings into consideration. 138 279 */ 139 protected function get_size( $size = null, $original = null ) {280 protected function get_size( $size = null, $original = null ) { 140 281 $options = get_option( 'fvp-settings' ); 141 282 … … 145 286 $size['width'] : 146 287 ( isset( $size[0] ) && is_numeric( $size[0] ) ? $size[0] : null ); 147 $height = isset( $size['height'] ) && is_numeric( $size['height'] ) ?288 $height = isset( $size['height'] ) &&is_numeric( $size['height'] ) ? 148 289 $size['height'] : 149 290 ( isset( $size[1] ) && is_numeric( $size[1] ) ? $size[1] : null ); … … 190 331 191 332 /** 192 * Parse the autoplay options to determine if video should or should not193 * autoplay.194 *195 * @param {assoic} $options196 * @return {bool}197 */198 private static function parse_autoplay_options( $options ) {199 if ( empty( $options['autoplay'] ) ) {200 return false;201 }202 203 if (204 ! empty( $options['autoplay']['always'] ) &&205 $options['autoplay']['always']206 ) {207 return true;208 };209 210 $mode = ! empty( $options['mode'] ) ? $options['mode'] : null;211 //$islazy = 'overlay' === $mode || 'dynamic' === $mode;212 $isajax = defined( 'DOING_AJAX' ) && DOING_AJAX;213 214 if (215 ! empty( $options['autoplay']['lazy'] ) &&216 $options['autoplay']['lazy'] &&217 $isajax218 ) {219 return true;220 }221 222 if (223 ! empty( $options['autoplay']['single'] ) &&224 $options['autoplay']['single'] &&225 is_single()226 ) {227 return true;228 }229 230 return false;231 }232 233 /**234 333 * Gets a post by an meta_key meta_value pair. Returns it's post_id. 235 334 * … … 248 347 if ( $meta_value !== null ) { 249 348 $prepared = $wpdb->prepare( 250 "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key=%s AND meta_value=%s LIMIT 1", 349 "SELECT post_id FROM {$wpdb->postmeta} " . 350 "WHERE meta_key=%s AND meta_value=%s LIMIT 1", 251 351 $meta_key, 252 352 $meta_value … … 264 364 265 365 /** 266 * Initializes i18n 267 * 268 * @since 1.3.0 269 */ 270 public function language() { 271 load_plugin_textdomain( 272 'featured-video-plus', 273 FVP_DIR . 'lng/', 274 FVP_NAME . '/lng/' 275 ); 276 } 366 * Check a given set of display conditions if one or more of them hold. If 367 * an empty set is given, return true. 368 * 369 * @param {assoc} $conditions 370 * @return {bool} 371 */ 372 private static function check_conditions( $conditions ) { 373 if ( empty( $conditions ) ) { 374 return true; 375 } 376 377 $conditions_hold = false; 378 foreach ( $conditions AS $fun => $value ) { 379 $negate = false; 380 if ( '!' === $fun[0] ) { 381 $negate = true; 382 $fun = substr( $fun, 1 ); 383 } 384 385 if ( $value && function_exists( 'is_' . $fun ) ) { 386 $call = call_user_func( 'is_' . $fun ); 387 $conditions_hold = $conditions_hold || ( $negate ? ! $call : $call ); 388 } 389 } 390 391 return $conditions_hold; 392 } 393 394 395 /** 396 * Parse the autoplay options to determine if video should or should not 397 * autoplay. 398 * 399 * @param {assoic} $options 400 * @return {bool} 401 */ 402 private static function parse_autoplay_options( 403 $options = array(), 404 $ajax = null 405 ) { 406 if ( empty( $options['autoplay'] ) ) { 407 return false; 408 } 409 410 if ( 411 ! empty( $options['autoplay']['always'] ) && 412 $options['autoplay']['always'] 413 ) { 414 return true; 415 }; 416 417 $mode = ! empty( $options['mode'] ) ? $options['mode'] : null; 418 //$ajax = defined( 'DOING_AJAX' ) && DOING_AJAX && $ajax; 419 420 if ( 421 ! empty( $options['autoplay']['lazy'] ) && 422 $options['autoplay']['lazy'] && 423 $ajax 424 ) { 425 return true; 426 } 427 428 if ( 429 ! empty( $options['autoplay']['single'] ) && 430 $options['autoplay']['single'] && 431 is_single() 432 ) { 433 return true; 434 } 435 436 return false; 437 } 438 439 277 440 } -
featured-video-plus/trunk/readme.txt
r1240519 r1245652 11 11 Requires at least: 3.7 12 12 Tested up to: 4.3 13 Stable tag: 2.2. 113 Stable tag: 2.2. 14 14 15 15 Add Featured Videos to your posts and pages. Works like magic with most themes which use Featured Images. Local Media, YouTube, Vimeo and many more. … … 107 107 108 108 == Changelog == 109 110 111 112 109 113 110 114 = 2.2.1: 2015-09-08 = -
featured-video-plus/trunk/styles/frontend.css
r1240519 r1245652 54 54 width: auto; 55 55 } 56 .fvp-overlay .fvp- loader,57 .fvp-dynamic .fvp- loader{56 .fvp-overlay .fvp-, 57 .fvp-dynamic .fvp- { 58 58 background: transparent no-repeat scroll center center; 59 59 position: absolute; … … 62 62 z-index: 999; 63 63 pointer-events: none; 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 64 82 } 65 83 #DOMWindow { … … 69 87 margin: auto auto; 70 88 overflow: hidden; 89 90 91 92 93 94 95 71 96 } 72 97 .featured-video-plus .wp-video a:not(.post-thumbnail) { … … 79 104 padding-top: 100% !important; 80 105 } 81 .onload.playicon {82 display: none;83 }
Note: See TracChangeset
for help on using the changeset viewer.