2013-07-19 23:06:27 +00:00
|
|
|
/*
|
|
|
|
* youtube
|
|
|
|
* https://github.com/savetheinternet/Tinyboard/blob/master/js/youtube.js
|
|
|
|
*
|
|
|
|
* Don't load the YouTube player unless the video image is clicked.
|
|
|
|
* This increases performance issues when many videos are embedded on the same page.
|
|
|
|
* Currently only compatiable with YouTube.
|
|
|
|
*
|
|
|
|
* Proof of concept.
|
|
|
|
*
|
|
|
|
* Released under the MIT license
|
|
|
|
* Copyright (c) 2013 Michael Save <savetheinternet@tinyboard.org>
|
2014-01-19 13:27:24 +00:00
|
|
|
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
2013-07-19 23:06:27 +00:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* $config['embedding'] = array();
|
2013-07-20 22:11:25 +00:00
|
|
|
* $config['embedding'][0] = array(
|
|
|
|
* '/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i',
|
2014-01-09 17:24:53 +00:00
|
|
|
* $config['youtube_js_html']);
|
2013-07-19 23:06:27 +00:00
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
|
|
|
* $config['additional_javascript'][] = 'js/youtube.js';
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-06-27 01:40:57 +00:00
|
|
|
$(document).ready(function(){
|
2021-01-30 03:30:55 +00:00
|
|
|
const ON = "[Remove]";
|
|
|
|
const OFF = "[Embed]";
|
2013-07-20 21:50:52 +00:00
|
|
|
|
2021-01-30 03:30:55 +00:00
|
|
|
function addEmbedButton(index, videoNode) {
|
2021-01-30 03:39:00 +00:00
|
|
|
videoNode = $(videoNode);
|
2021-04-03 00:15:26 +00:00
|
|
|
var contents = videoNode.contents();
|
2021-01-30 02:55:23 +00:00
|
|
|
var videoId = videoNode.data('video');
|
|
|
|
var span = $("<span>[Embed]</span>");
|
|
|
|
var embedNode = $('<iframe style="float:left;margin: 10px 20px" type="text/html" '+
|
|
|
|
'width="360" height="270" src="//www.youtube.com/embed/' + videoId +
|
2021-01-30 03:30:55 +00:00
|
|
|
'?autoplay=1&html5=1" allowfullscreen frameborder="0"/>');
|
2021-04-03 23:02:53 +00:00
|
|
|
videoNode.click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2021-01-30 02:55:23 +00:00
|
|
|
if (span.text() == ON){
|
2021-04-03 00:15:26 +00:00
|
|
|
videoNode.append(contents);
|
2021-01-30 02:55:23 +00:00
|
|
|
embedNode.remove();
|
|
|
|
span.text(OFF);
|
|
|
|
} else{
|
2021-04-03 00:15:26 +00:00
|
|
|
contents.detach();
|
2021-01-30 02:55:23 +00:00
|
|
|
videoNode.append(embedNode);
|
|
|
|
span.text(ON);
|
|
|
|
}
|
2013-07-20 22:25:58 +00:00
|
|
|
});
|
2021-01-30 02:55:23 +00:00
|
|
|
|
|
|
|
videoNode.append(span);
|
2021-01-30 03:30:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$('div.video-container', document).each(addEmbedButton);
|
|
|
|
|
2013-07-20 22:25:58 +00:00
|
|
|
|
2021-01-30 02:55:23 +00:00
|
|
|
// allow to work with auto-reload.js, etc.
|
|
|
|
$(document).on('new_post', function(e, post) {
|
2021-01-30 03:30:55 +00:00
|
|
|
$('div.video-container', post).each(addEmbedButton);
|
2021-01-30 02:55:23 +00:00
|
|
|
});
|
2013-07-19 23:06:27 +00:00
|
|
|
});
|
|
|
|
|