-
-
Save imath/43105d0241c330f6a12ba01044b672b7 to your computer and use it in GitHub Desktop.
suggestion...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git .jshintignore .jshintignore | |
index 7d7b4cc..2cf40f7 100644 | |
--- .jshintignore | |
+++ .jshintignore | |
@@ -7,3 +7,4 @@ src/bp-core/js/jquery.caret.js | |
src/bp-core/js/jquery-cookie.js | |
src/bp-core/js/jquery-scroll-to.js | |
src/bp-messages/js/autocomplete/* | |
+src/bp-activity/js/fluidvids.js | |
diff --git src/bp-activity/bp-activity-embeds.php src/bp-activity/bp-activity-embeds.php | |
index 220aa28..a902b1f 100644 | |
--- src/bp-activity/bp-activity-embeds.php | |
+++ src/bp-activity/bp-activity-embeds.php | |
@@ -61,7 +61,7 @@ p.wp-embed-heading { | |
margin-bottom: 0; | |
} | |
-.wp-embed-excerpt, p.wp-embed-timestamp { | |
+.wp-embed-excerpt, p.bp-embed-timestamp { | |
margin-bottom: .5em; | |
} | |
@@ -105,6 +105,52 @@ EOD; | |
add_action( 'bp_enqueue_embed_scripts', '_bp_activity_embed_add_inline_styles' ); | |
/** | |
+ * Register specific Activity Embed scripts | |
+ * | |
+ * @since 2.6.0 | |
+ * | |
+ * @param array $scripts The list of BP Core scripts | |
+ * @return arrat The list of scripts to register. | |
+ */ | |
+function bp_activity_embed_register_scripts() { | |
+ $min = bp_core_get_minified_asset_suffix(); | |
+ $url = buddypress()->plugin_url . 'bp-activity/js/'; | |
+ | |
+ $scripts = apply_filters( 'bp_activity_embed_register_scripts', array( | |
+ 'fluidvids' => array( 'file' => "{$url}fluidvids{$min}.js", 'dependencies' => array(), 'footer' => true ), | |
+ ) ); | |
+ | |
+ foreach ( $scripts as $id => $script ) { | |
+ /** | |
+ * Let plugins add their own version by using | |
+ * our version as fallback | |
+ */ | |
+ if ( empty( $script['version'] ) ) { | |
+ $version = bp_get_version(); | |
+ } | |
+ | |
+ wp_register_script( $id, $script['file'], $script['dependencies'], $version, $script['footer'] ); | |
+ } | |
+} | |
+add_action( 'bp_enqueue_embed_scripts', 'bp_activity_embed_register_scripts', 1, 1 ); | |
+ | |
+/** | |
+ * Prints an inline script for Activity Embeds. | |
+ * | |
+ * @since 2.6.0 | |
+ * | |
+ * @return string Inline Script | |
+ */ | |
+function bp_activity_embed_inline_script() { | |
+ return apply_filters( 'bp_activity_embed_inline_script', " | |
+ fluidvids.init( { | |
+ selector: ['iframe', 'object'], | |
+ players: ['.'] // remove default youtube / vimeo restriction. | |
+ } ); | |
+ " ); | |
+} | |
+ | |
+/** | |
* Outputs excerpt for an activity embed item. | |
* | |
* @since 2.6.0 | |
@@ -191,21 +237,21 @@ function bp_activity_embed_response_display_media() { | |
// Add fluidvids.js for responsive IFRAMEs / OBJECTs. | |
if ( false !== strpos( $content, '<iframe' ) || false !== strpos( $content, '<object' ) ) { | |
- ?> | |
- | |
-<script> | |
-/*! fluidvids.js v2.4.1 | (c) 2014 @toddmotto | License: MIT | https://github.com/toddmotto/fluidvids */ | |
-!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t:e.fluidvids=t()}(this,function(){"use strict";function e(e){return new RegExp("^(https?:)?//(?:"+d.players.join("|")+").*$","i").test(e)}function t(e,t){return parseInt(e,10)/parseInt(t,10)*100+"%"}function i(i){if((e(i.src)||e(i.data))&&!i.getAttribute("data-fluidvids")){var n=document.createElement("div");i.parentNode.insertBefore(n,i),i.className+=(i.className?" ":"")+"fluidvids-item",i.setAttribute("data-fluidvids","loaded"),n.className+="fluidvids",n.style.paddingTop=t(i.height,i.width),n.appendChild(i)}}function n(){var e=document.createElement("div");e.innerHTML="<p>x</p><style>"+o+"</style>",r.appendChild(e.childNodes[1])}var d={selector:["iframe","object"],players:["www.youtube.com","player.vimeo.com"]},o=[".fluidvids {","width: 100%; max-width: 100%; position: relative;","}",".fluidvids-item {","position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;","}"].join(""),r=document.head||document.getElementsByTagName("head")[0];return d.render=function(){for(var e=document.querySelectorAll(d.selector.join()),t=e.length;t--;)i(e[t])},d.init=function(e){for(var t in e)d[t]=e[t];d.render(),n()},d}); | |
- | |
-// init | |
-fluidvids.init({ | |
- selector: ['iframe', 'object'], | |
- players: ['.'] // remove default youtube / vimeo restriction. | |
-}); | |
-</script> | |
- | |
- <?php | |
+ wp_enqueue_script( 'fluidvids' ); | |
+ wp_add_inline_script( 'fluidvids', bp_activity_embed_inline_script() ); | |
} | |
} | |
} | |
-add_action( 'bp_activity_embed_after_content', 'bp_activity_embed_response_display_media' ); | |
+ | |
+/** | |
+ * Template tag to eventually render embed in embed | |
+ * | |
+ * @since 2.6.0 | |
+ * | |
+ * @return string HTML output | |
+ */ | |
+function bp_activity_embed_after_content() { | |
+ bp_activity_embed_response_display_media(); | |
+ | |
+ do_action( 'bp_activity_embed_after_content' ); | |
+} | |
diff --git src/bp-activity/js/fluidvids.js src/bp-activity/js/fluidvids.js | |
index e69de29..fba216a 100644 | |
--- src/bp-activity/js/fluidvids.js | |
+++ src/bp-activity/js/fluidvids.js | |
@@ -0,0 +1,73 @@ | |
+/*! fluidvids.js v2.4.1 | (c) 2014 @toddmotto | https://github.com/toddmotto/fluidvids */ | |
+(function (root, factory) { | |
+ if (typeof define === 'function' && define.amd) { | |
+ define(factory); | |
+ } else if (typeof exports === 'object') { | |
+ module.exports = factory; | |
+ } else { | |
+ root.fluidvids = factory(); | |
+ } | |
+})(this, function () { | |
+ | |
+ 'use strict'; | |
+ | |
+ var fluidvids = { | |
+ selector: ['iframe', 'object'], | |
+ players: ['www.youtube.com', 'player.vimeo.com'] | |
+ }; | |
+ | |
+ var css = [ | |
+ '.fluidvids {', | |
+ 'width: 100%; max-width: 100%; position: relative;', | |
+ '}', | |
+ '.fluidvids-item {', | |
+ 'position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;', | |
+ '}' | |
+ ].join(''); | |
+ | |
+ var head = document.head || document.getElementsByTagName('head')[0]; | |
+ | |
+ function matches (src) { | |
+ return new RegExp('^(https?:)?\/\/(?:' + fluidvids.players.join('|') + ').*$', 'i').test(src); | |
+ } | |
+ | |
+ function getRatio (height, width) { | |
+ return ((parseInt(height, 10) / parseInt(width, 10)) * 100) + '%'; | |
+ } | |
+ | |
+ function fluid (elem) { | |
+ if (!matches(elem.src) && !matches(elem.data) || !!elem.getAttribute('data-fluidvids')) return; | |
+ var wrap = document.createElement('div'); | |
+ elem.parentNode.insertBefore(wrap, elem); | |
+ elem.className += (elem.className ? ' ' : '') + 'fluidvids-item'; | |
+ elem.setAttribute('data-fluidvids', 'loaded'); | |
+ wrap.className += 'fluidvids'; | |
+ wrap.style.paddingTop = getRatio(elem.height, elem.width); | |
+ wrap.appendChild(elem); | |
+ } | |
+ | |
+ function addStyles () { | |
+ var div = document.createElement('div'); | |
+ div.innerHTML = '<p>x</p><style>' + css + '</style>'; | |
+ head.appendChild(div.childNodes[1]); | |
+ } | |
+ | |
+ fluidvids.render = function () { | |
+ var nodes = document.querySelectorAll(fluidvids.selector.join()); | |
+ var i = nodes.length; | |
+ while (i--) { | |
+ fluid(nodes[i]); | |
+ } | |
+ }; | |
+ | |
+ fluidvids.init = function (obj) { | |
+ for (var key in obj) { | |
+ fluidvids[key] = obj[key]; | |
+ } | |
+ fluidvids.render(); | |
+ addStyles(); | |
+ }; | |
+ | |
+ return fluidvids; | |
+ | |
+}); | |
diff --git src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php | |
index 6c88f53..af2c026 100644 | |
--- src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php | |
+++ src/bp-templates/bp-legacy/buddypress/assets/embeds/activity.php | |
@@ -4,9 +4,9 @@ | |
<?php while ( bp_activities() ) : bp_the_activity(); ?> | |
<div class="wp-embed-excerpt"><?php bp_activity_embed_excerpt(); ?></div> | |
- <p class="wp-embed-timestamp"><a href="<?php bp_activity_thread_permalink(); ?>"><?php echo date_i18n( get_option( 'time_format' ) . ' - ' . get_option( 'date_format' ), strtotime( bp_get_activity_date_recorded() ) ); ?></a></p> | |
+ <p class="bp-embed-timestamp"><a href="<?php bp_activity_thread_permalink(); ?>"><?php echo date_i18n( get_option( 'time_format' ) . ' - ' . get_option( 'date_format' ), strtotime( bp_get_activity_date_recorded() ) ); ?></a></p> | |
- <?php do_action( 'bp_activity_embed_after_content' ); ?> | |
+ <?php bp_activity_embed_after_content(); ?> | |
<?php endwhile; ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment