Skip to content

Commit

Permalink
Merge branch 'release/4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 15, 2020
2 parents e04df53 + 82b9580 commit bbcc301
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 0 deletions.
5 changes: 5 additions & 0 deletions classes/Twig/YoutubeTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function embedUrl($video_id, array $player_parameters = array(), $privacy
continue;
}

//YouTube loop fix for HTML5 player
if ($key == 'loop' && $value == 1) {
$filtered_player_parameters['playlist'] = $video_id;
}

$filtered_player_parameters[$key] = $value;
}

Expand Down
250 changes: 250 additions & 0 deletions nextgen-editor/shortcodes/youtube/youtube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
window.nextgenEditor.addShortcode('youtube', {
type: 'block',
plugin: 'shortcode-core',
title: 'YouTube',
button: {
label: 'YouTube',
icon: '<svg viewBox="-21 -117 682.66672 682" xmlns="http://www.w3.org/2000/svg"><path d="m626.8125 64.035156c-7.375-27.417968-28.992188-49.03125-56.40625-56.414062-50.082031-13.703125-250.414062-13.703125-250.414062-13.703125s-200.324219 0-250.40625 13.183593c-26.886719 7.375-49.03125 29.519532-56.40625 56.933594-13.179688 50.078125-13.179688 153.933594-13.179688 153.933594s0 104.378906 13.179688 153.933594c7.382812 27.414062 28.992187 49.027344 56.410156 56.410156 50.605468 13.707031 250.410156 13.707031 250.410156 13.707031s200.324219 0 250.40625-13.183593c27.417969-7.378907 49.03125-28.992188 56.414062-56.40625 13.175782-50.082032 13.175782-153.933594 13.175782-153.933594s.527344-104.382813-13.183594-154.460938zm-370.601562 249.878906v-191.890624l166.585937 95.945312zm0 0"/></svg>',
},
attributes: {
url: {
type: String,
innerHTML: true,
title: 'URL',
widget: 'input-text',
default: '',
},
width: {
type: String,
title: 'Width',
widget: 'input-text',
default: '',
},
height: {
type: String,
title: 'Width',
widget: 'input-text',
default: '',
},
autoplay: {
type: Number,
title: 'Autoplay',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 0,
},
cc_load_policy: {
type: Number,
title: 'Show Captions',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 0,
},
cc_lang_pref: {
type: String,
title: 'Captions Language',
widget: 'input-text',
default: '',
},
color: {
type: String,
title: 'Color',
widget: 'input-text',
default: 'red',
},
controls: {
type: Number,
title: 'Show Controls',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 1,
},
disablekb: {
type: Number,
title: 'Disable Keyboard',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 0,
},
enablejsapi: {
type: Number,
title: 'Enable API Control',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 0,
},
end: {
type: Number,
title: 'End Time (in sec)',
widget: 'input-number',
default: 0,
},
fs: {
type: Number,
title: 'Show Full Screen',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 1,
},
hl: {
type: String,
title: 'Interface Language',
widget: 'input-text',
default: '',
},
iv_load_policy: {
type: Number,
title: 'Show Annotations',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 1,
},
list: {
type: String,
title: 'List Name',
widget: 'input-text',
default: '',
},
listType: {
type: String,
title: 'List Type',
widget: {
type: 'select',
values: [
{ value: '', label: '' },
{ value: 'playlist', label: 'Playlist' },
{ value: 'user_uploads', label: 'User Uploads' },
],
},
default: '',
},
loop: {
type: Number,
title: 'Loop',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 0,
},
modestbranding: {
type: Number,
title: 'Hide YouTube Logo',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 0,
},
origin: {
type: String,
title: 'Origin',
widget: 'input-text',
default: '',
},
playlist: {
type: String,
title: 'Playlist',
widget: 'input-text',
default: '',
},
playsinline: {
type: Number,
title: 'Play Inline',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 0,
},
rel: {
type: Number,
title: 'Show Related',
widget: {
type: 'checkbox',
valueType: Number,
label: 'Yes',
},
default: 1,
},
start: {
type: Number,
title: 'Start Time (in sec)',
widget: 'input-number',
default: 0,
},
widget_referrer: {
type: String,
title: 'Widget Referrer',
widget: 'input-text',
default: '',
},
},
titlebar({ attributes }) {
let id = '';

try {
id = new URL(attributes.url).searchParams.get('v');
}
catch (err) {
}

return `id: <strong>${id}</strong>`;
},
content({ attributes }) {
let id = '';

try {
id = new URL(attributes.url).searchParams.get('v');
}
catch (err) {
}

return id
? `<div style="position:relative;padding-bottom:100%;height:0;padding-bottom:56.2493%;"><iframe src="https://www.youtube.com/embed/${id}" style="position:absolute;width:100%;height:100%;top:0;left:0;" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen=""></iframe></div>`
: '<div style="margin:36px;text-align:center;">Empty URL</div>';
},
preserve: {
block: [
'iframe',
],
},
});

window.nextgenEditor.addHook('hookMarkdowntoHTML', {
weight: -50,
async handler(options, input) {
let output = input;

output = output.replace(/\[plugin:youtube\]\((?<url>[^)]*)\)/g, (...matches) => {
const { url } = matches.pop();
return `[youtube]${url}[/youtube]`;
});

return output;
},
});
11 changes: 11 additions & 0 deletions youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
'registerNextGenEditorPlugin' => ['registerNextGenEditorPluginShortcodes', 0],
];
}

Expand Down Expand Up @@ -153,4 +154,14 @@ public function onShortcodeHandlers()
{
$this->grav['shortcode']->registerAllShortcodes(__DIR__.'/shortcodes');
}

public function registerNextGenEditorPluginShortcodes($event) {
$plugins = $event['plugins'];

// youtube
$plugins['js'][] = 'plugin://youtube/nextgen-editor/shortcodes/youtube/youtube.js';

$event['plugins'] = $plugins;
return $event;
}
}

0 comments on commit bbcc301

Please sign in to comment.