{"action":"opened","number":230,"pull_request":{"url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/pulls/230","id":29989591,"html_url":"https://github.com/cuny-academic-commons/cbox-theme/pull/230","diff_url":"https://github.com/cuny-academic-commons/cbox-theme/pull/230.diff","patch_url":"https://github.com/cuny-academic-commons/cbox-theme/pull/230.patch","issue_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/issues/230","number":230,"state":"open","locked":false,"title":"Enable bxSlider API","user":{"login":"christianwach","id":726936,"avatar_url":"https://avatars.githubusercontent.com/u/726936?v=3","gravatar_id":"","url":"https://api.github.com/users/christianwach","html_url":"https://github.com/christianwach","followers_url":"https://api.github.com/users/christianwach/followers","following_url":"https://api.github.com/users/christianwach/following{/other_user}","gists_url":"https://api.github.com/users/christianwach/gists{/gist_id}","starred_url":"https://api.github.com/users/christianwach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christianwach/subscriptions","organizations_url":"https://api.github.com/users/christianwach/orgs","repos_url":"https://api.github.com/users/christianwach/repos","events_url":"https://api.github.com/users/christianwach/events{/privacy}","received_events_url":"https://api.github.com/users/christianwach/received_events","type":"User","site_admin":false},"body":"I've been making progress with #207 for a client project but can't get the bxSlider API to function without the changes to the way it's being initialised. When inited with `auto = true`, subsequent calls to `startAuto()` and `stopAuto()` fail silently, so this PR issues `startAuto()` directly after the slider init. This does not change how the slider behaves, but does enable starting and stopping the slideshow via code.\r\n\r\nThe PR also introduces a global scope variable `cbox_slider` which is the slider instance because there are no methods of retrieving the bxSlider instance in its API. This variable means that the slider can be addressed and controlled externally, which is necessary for making it play better with videos.\r\n\r\nAt present, I have only got the slider to work better with YouTube videos, but it looks like it's possible to do this with Vimeo too. Here's how to get things working...\r\n\r\nIn 'functions.php' or in a plugin, add the following filter which enables the YouTube API on the videos that are embedded in the slider:\r\n\r\n```php\r\n/**\r\n * Filter YouTube URL to enable API\r\n */\r\nfunction my_wp_embed_handler_youtube( $html, $url, $attr, $post_ID ) {\r\n\t// do we have an oembed?\r\n\tif ( false !== strpos( $html, 'feature=oembed' ) ) {\r\n\t\t// enable YouTube API on video\r\n\t\t$html = str_replace( 'feature=oembed', 'feature=oembed&enablejsapi=1', $html );\r\n\t}\r\n\treturn $html;\r\n}\r\nadd_filter( 'embed_oembed_html', 'my_wp_embed_handler_youtube', 10, 4 );\r\n```\r\n\r\nNext, enqueue the following Javascript on the homepage:\r\n\r\n```js\r\n// load YouTube Frame API\r\n(function() { // closure, so as not to leak scope\r\n  var s = document.createElement(\"script\");\r\n  s.src = (location.protocol == 'https:' ? 'https' : 'http') + \"://www.youtube.com/player_api\";\r\n  var before = document.getElementsByTagName(\"script\")[0];\r\n  before.parentNode.insertBefore(s, before);\r\n})();\r\n\r\n/**\r\n * Define what happens when the page is ready\r\n */\r\njQuery(document).ready( function($) {\r\n\r\n\t/**\r\n\t * Trap clicks on the pager\r\n\t */\r\n\t$('.bx-pager.bx-default-pager').click( function( event ) {\r\n\r\n\t\t// stop auto slider\r\n\t\tcbox_slider.stopAuto();\r\n\r\n\t\t// pause all videos\r\n\t\t$('.slide-video-embed iframe').each( function() {\r\n\t\t\t$(this).data('player').pauseVideo();\r\n\t\t});\r\n\r\n\t});\r\n\r\n    /**\r\n     * Callback for the YouTube API that fires when the API is ready\r\n     */\r\n\twindow.onYouTubeIframeAPIReady = function(){\r\n\r\n\t\t// iterate through videos\r\n\t\t$('.slide-video-embed iframe').each( function(){\r\n\r\n\t\t\t// create a new player pointer\r\n\t\t\tvar player = new YT.Player( document.getElementById( $(this).attr('id') ) );\r\n\r\n\t\t\t// watch for changes on the player\r\n\t\t\tplayer.addEventListener( 'onStateChange', function(state) {\r\n\r\n\t\t\t\tswitch( state.data ) {\r\n\r\n\t\t\t\t\t// if a video is playing, stop the slider\r\n\t\t\t\t\tcase YT.PlayerState.PLAYING:\r\n\t\t\t\t\t\tcbox_slider.stopAuto();\r\n\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t// if the video is paused, start the slider\r\n\t\t\t\t\tcase YT.PlayerState.PAUSED:\r\n\t\t\t\t\t\tcbox_slider.startAuto();\r\n\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t\t// if the video has finished, go straight to next slide\r\n\t\t\t\t\tcase YT.PlayerState.ENDED:\r\n\t\t\t\t\t\tcbox_slider.goToNextSlide();\r\n\t\t\t\t\t\tbreak;\r\n\r\n\t\t\t\t}\r\n\r\n\t\t\t});\r\n\r\n\t\t\t// store\r\n\t\t\t$(this).data('player', player);\r\n\r\n\t\t});\r\n\r\n\t}\r\n\r\n});\r\n```\r\n\r\nWhat you should see is that playing a YouTube video now pauses the slideshow, whilst pausing it restarts the slideshow. And when a video finishes, the next slide is immediately loaded.\r\n\r\nI'd like to add a number of filters (or one monolithic filter) that allows the bxSlider init in ['engine/includes/feature-slider/setup.php'](https://github.com/cuny-academic-commons/cbox-theme/blob/master/engine/includes/feature-slider/setup.php#L201) to be more adaptable. Thoughts?","created_at":"2015-02-25T14:12:11Z","updated_at":"2015-02-25T14:12:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/pulls/230/commits","review_comments_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/pulls/230/comments","review_comment_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/issues/230/comments","statuses_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/statuses/435e9e751905de3456d10127cdfbe51688fa2cc7","head":{"label":"christianwach:slider-control","ref":"slider-control","sha":"435e9e751905de3456d10127cdfbe51688fa2cc7","user":{"login":"christianwach","id":726936,"avatar_url":"https://avatars.githubusercontent.com/u/726936?v=3","gravatar_id":"","url":"https://api.github.com/users/christianwach","html_url":"https://github.com/christianwach","followers_url":"https://api.github.com/users/christianwach/followers","following_url":"https://api.github.com/users/christianwach/following{/other_user}","gists_url":"https://api.github.com/users/christianwach/gists{/gist_id}","starred_url":"https://api.github.com/users/christianwach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christianwach/subscriptions","organizations_url":"https://api.github.com/users/christianwach/orgs","repos_url":"https://api.github.com/users/christianwach/repos","events_url":"https://api.github.com/users/christianwach/events{/privacy}","received_events_url":"https://api.github.com/users/christianwach/received_events","type":"User","site_admin":false},"repo":{"id":10910439,"name":"cbox-theme","full_name":"christianwach/cbox-theme","owner":{"login":"christianwach","id":726936,"avatar_url":"https://avatars.githubusercontent.com/u/726936?v=3","gravatar_id":"","url":"https://api.github.com/users/christianwach","html_url":"https://github.com/christianwach","followers_url":"https://api.github.com/users/christianwach/followers","following_url":"https://api.github.com/users/christianwach/following{/other_user}","gists_url":"https://api.github.com/users/christianwach/gists{/gist_id}","starred_url":"https://api.github.com/users/christianwach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christianwach/subscriptions","organizations_url":"https://api.github.com/users/christianwach/orgs","repos_url":"https://api.github.com/users/christianwach/repos","events_url":"https://api.github.com/users/christianwach/events{/privacy}","received_events_url":"https://api.github.com/users/christianwach/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/christianwach/cbox-theme","description":"Default theme for Commons In A Box","fork":true,"url":"https://api.github.com/repos/christianwach/cbox-theme","forks_url":"https://api.github.com/repos/christianwach/cbox-theme/forks","keys_url":"https://api.github.com/repos/christianwach/cbox-theme/keys{/key_id}","collaborators_url":"https://api.github.com/repos/christianwach/cbox-theme/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/christianwach/cbox-theme/teams","hooks_url":"https://api.github.com/repos/christianwach/cbox-theme/hooks","issue_events_url":"https://api.github.com/repos/christianwach/cbox-theme/issues/events{/number}","events_url":"https://api.github.com/repos/christianwach/cbox-theme/events","assignees_url":"https://api.github.com/repos/christianwach/cbox-theme/assignees{/user}","branches_url":"https://api.github.com/repos/christianwach/cbox-theme/branches{/branch}","tags_url":"https://api.github.com/repos/christianwach/cbox-theme/tags","blobs_url":"https://api.github.com/repos/christianwach/cbox-theme/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/christianwach/cbox-theme/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/christianwach/cbox-theme/git/refs{/sha}","trees_url":"https://api.github.com/repos/christianwach/cbox-theme/git/trees{/sha}","statuses_url":"https://api.github.com/repos/christianwach/cbox-theme/statuses/{sha}","languages_url":"https://api.github.com/repos/christianwach/cbox-theme/languages","stargazers_url":"https://api.github.com/repos/christianwach/cbox-theme/stargazers","contributors_url":"https://api.github.com/repos/christianwach/cbox-theme/contributors","subscribers_url":"https://api.github.com/repos/christianwach/cbox-theme/subscribers","subscription_url":"https://api.github.com/repos/christianwach/cbox-theme/subscription","commits_url":"https://api.github.com/repos/christianwach/cbox-theme/commits{/sha}","git_commits_url":"https://api.github.com/repos/christianwach/cbox-theme/git/commits{/sha}","comments_url":"https://api.github.com/repos/christianwach/cbox-theme/comments{/number}","issue_comment_url":"https://api.github.com/repos/christianwach/cbox-theme/issues/comments{/number}","contents_url":"https://api.github.com/repos/christianwach/cbox-theme/contents/{+path}","compare_url":"https://api.github.com/repos/christianwach/cbox-theme/compare/{base}...{head}","merges_url":"https://api.github.com/repos/christianwach/cbox-theme/merges","archive_url":"https://api.github.com/repos/christianwach/cbox-theme/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/christianwach/cbox-theme/downloads","issues_url":"https://api.github.com/repos/christianwach/cbox-theme/issues{/number}","pulls_url":"https://api.github.com/repos/christianwach/cbox-theme/pulls{/number}","milestones_url":"https://api.github.com/repos/christianwach/cbox-theme/milestones{/number}","notifications_url":"https://api.github.com/repos/christianwach/cbox-theme/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/christianwach/cbox-theme/labels{/name}","releases_url":"https://api.github.com/repos/christianwach/cbox-theme/releases{/id}","created_at":"2013-06-24T14:26:33Z","updated_at":"2015-02-23T11:14:36Z","pushed_at":"2015-02-25T13:40:16Z","git_url":"git://github.com/christianwach/cbox-theme.git","ssh_url":"git@github.com:christianwach/cbox-theme.git","clone_url":"https://github.com/christianwach/cbox-theme.git","svn_url":"https://github.com/christianwach/cbox-theme","homepage":null,"size":8075,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cuny-academic-commons:master","ref":"master","sha":"0bec3e94c7afc28300665b4d2a5ea1f68e1e8f9a","user":{"login":"cuny-academic-commons","id":1213847,"avatar_url":"https://avatars.githubusercontent.com/u/1213847?v=3","gravatar_id":"","url":"https://api.github.com/users/cuny-academic-commons","html_url":"https://github.com/cuny-academic-commons","followers_url":"https://api.github.com/users/cuny-academic-commons/followers","following_url":"https://api.github.com/users/cuny-academic-commons/following{/other_user}","gists_url":"https://api.github.com/users/cuny-academic-commons/gists{/gist_id}","starred_url":"https://api.github.com/users/cuny-academic-commons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cuny-academic-commons/subscriptions","organizations_url":"https://api.github.com/users/cuny-academic-commons/orgs","repos_url":"https://api.github.com/users/cuny-academic-commons/repos","events_url":"https://api.github.com/users/cuny-academic-commons/events{/privacy}","received_events_url":"https://api.github.com/users/cuny-academic-commons/received_events","type":"Organization","site_admin":false},"repo":{"id":4546992,"name":"cbox-theme","full_name":"cuny-academic-commons/cbox-theme","owner":{"login":"cuny-academic-commons","id":1213847,"avatar_url":"https://avatars.githubusercontent.com/u/1213847?v=3","gravatar_id":"","url":"https://api.github.com/users/cuny-academic-commons","html_url":"https://github.com/cuny-academic-commons","followers_url":"https://api.github.com/users/cuny-academic-commons/followers","following_url":"https://api.github.com/users/cuny-academic-commons/following{/other_user}","gists_url":"https://api.github.com/users/cuny-academic-commons/gists{/gist_id}","starred_url":"https://api.github.com/users/cuny-academic-commons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cuny-academic-commons/subscriptions","organizations_url":"https://api.github.com/users/cuny-academic-commons/orgs","repos_url":"https://api.github.com/users/cuny-academic-commons/repos","events_url":"https://api.github.com/users/cuny-academic-commons/events{/privacy}","received_events_url":"https://api.github.com/users/cuny-academic-commons/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cuny-academic-commons/cbox-theme","description":"Default theme for Commons In A Box","fork":false,"url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme","forks_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/forks","keys_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/teams","hooks_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/hooks","issue_events_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/issues/events{/number}","events_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/events","assignees_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/assignees{/user}","branches_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/branches{/branch}","tags_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/tags","blobs_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/git/refs{/sha}","trees_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/statuses/{sha}","languages_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/languages","stargazers_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/stargazers","contributors_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/contributors","subscribers_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/subscribers","subscription_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/subscription","commits_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/commits{/sha}","git_commits_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/git/commits{/sha}","comments_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/comments{/number}","issue_comment_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/issues/comments{/number}","contents_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/contents/{+path}","compare_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/merges","archive_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/downloads","issues_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/issues{/number}","pulls_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/pulls{/number}","milestones_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/milestones{/number}","notifications_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/labels{/name}","releases_url":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/releases{/id}","created_at":"2012-06-04T12:46:34Z","updated_at":"2015-02-20T06:24:59Z","pushed_at":"2015-02-20T06:24:58Z","git_url":"git://github.com/cuny-academic-commons/cbox-theme.git","ssh_url":"git@github.com:cuny-academic-commons/cbox-theme.git","clone_url":"https://github.com/cuny-academic-commons/cbox-theme.git","svn_url":"https://github.com/cuny-academic-commons/cbox-theme","homepage":null,"size":8441,"stargazers_count":21,"watchers_count":21,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":28,"forks":13,"open_issues":28,"watchers":21,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/pulls/230"},"html":{"href":"https://github.com/cuny-academic-commons/cbox-theme/pull/230"},"issue":{"href":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/issues/230"},"comments":{"href":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/issues/230/comments"},"review_comments":{"href":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/pulls/230/comments"},"review_comment":{"href":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/pulls/230/commits"},"statuses":{"href":"https://api.github.com/repos/cuny-academic-commons/cbox-theme/statuses/435e9e751905de3456d10127cdfbe51688fa2cc7"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":5,"deletions":2,"changed_files":1}}