-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Video plugin #694
Open
abetis
wants to merge
10
commits into
samclarke:master
Choose a base branch
from
abetis:video-plugin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Video plugin #694
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b633d7
Fix plugins initialization problems
abetis 879cd17
Parameters for youtube tag
abetis a90076f
BBCode start time support
abetis a4c7586
XHTML implementation
abetis d39f1db
Adding video command
abetis eb79e6e
Merge branch 'youtube-enhancements' into video-plugin
abetis c113634
Merge branch 'fix-plugin-initialization' into video-plugin
abetis 73af14b
BBCode implementation
abetis 6c921ea
Make DeepScan happy
abetis 91d175a
Fix missing space
abetis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
/** | ||
* SCEditor Inline-Code Plugin for BBCode format | ||
* http://www.sceditor.com/ | ||
* | ||
* Copyright (C) 2011-2013, Sam Clarke (samclarke.com) | ||
* | ||
* SCEditor is licensed under the MIT license: | ||
* http://www.opensource.org/licenses/mit-license.php | ||
* | ||
* @fileoverview SCEditor Video plugin | ||
* This plugin replaces the youtube command with "add video" command, which | ||
* will recognize youtube and facebook URLs (hopefully other URLs as well | ||
* in the future) and generate the tags accordingly | ||
* @author Alex Betis | ||
*/ | ||
|
||
(function (sceditor) { | ||
'use strict'; | ||
|
||
sceditor.plugins.video = function () { | ||
var base = this; | ||
|
||
var utils = sceditor.utils; | ||
var dom = sceditor.dom; | ||
|
||
/** | ||
* Private functions | ||
* @private | ||
*/ | ||
var commandHandler; | ||
var processYoutube; | ||
var processFacebook; | ||
var youtubeHtml; | ||
var facebookHtml; | ||
|
||
base.init = function () { | ||
var opts = this.opts; | ||
|
||
// Enable for BBCode only | ||
if (opts.format && opts.format !== 'bbcode') { | ||
return; | ||
} | ||
|
||
if (opts.toolbar === sceditor.defaultOptions.toolbar) { | ||
opts.toolbar = opts.toolbar.replace(',image,', | ||
',image,video,'); | ||
|
||
opts.toolbar = opts.toolbar.replace(',youtube', ''); | ||
} | ||
|
||
// Remove youtube command | ||
sceditor.command.remove('youtube'); | ||
|
||
// Add new movie command | ||
sceditor.command.set('video', { | ||
exec: commandHandler, | ||
txtExec: commandHandler, | ||
tooltip: 'Insert a video (YouTube, Facebook)' | ||
}); | ||
|
||
sceditor.formats.bbcode.set('facebook', { | ||
allowsEmpty: true, | ||
tags: { | ||
iframe: { | ||
'data-facebook-id': null | ||
} | ||
}, | ||
format: function (element, content) { | ||
var id = dom.attr(element, 'data-facebook-id'); | ||
|
||
return id ? '[facebook]' + id + '[/facebook]' : content; | ||
}, | ||
html: function (token, attrs, content) { | ||
return facebookHtml(this.opts.facebookParameters, content); | ||
} | ||
}); | ||
}; | ||
|
||
youtubeHtml = function (pOpts, id, time) { | ||
return '<iframe ' + pOpts + ' ' + | ||
'src="https://www.youtube.com/embed/' + id + | ||
'?start=' + time + | ||
'&wmode=opaque" ' + | ||
'data-youtube-id="' + id + '" ' + | ||
'data-youtube-start="' + time + '"></iframe>'; | ||
}; | ||
|
||
facebookHtml = function (pOpts, id) { | ||
return '<iframe ' + pOpts + ' ' + | ||
'src="https://www.facebook.com/video/embed?video_id=' + | ||
id + '" ' + | ||
'data-facebook-id="' + id + '"></iframe>'; | ||
}; | ||
|
||
processYoutube = function (editor, val) { | ||
var pOpts = editor.opts.parserOptions; | ||
var idMatch = val.match(/(?:v=|v\/|embed\/|youtu.be\/)(.{11})/); | ||
var timeMatch = val.match(/[&|?](?:star)?t=((\d+[hms]?){1,3})/); | ||
var time = 0; | ||
|
||
if (timeMatch) { | ||
utils.each(timeMatch[1].split(/[hms]/), function (i, val) { | ||
if (val !== '') { | ||
time = (time * 60) + Number(val); | ||
} | ||
}); | ||
} | ||
|
||
if (idMatch && /^[a-zA-Z0-9_\-]{11}$/.test(idMatch[1])) { | ||
var id = idMatch[1]; | ||
|
||
if (editor.sourceMode()) { | ||
if (time === 0) { | ||
editor.insertText('[youtube]' + id + '[/youtube]'); | ||
} else { | ||
editor.insertText('[youtube=' + time + ']' + id + | ||
'[/youtube]'); | ||
} | ||
} else { | ||
editor.wysiwygEditorInsertHtml( | ||
youtubeHtml(pOpts.youtubeParameters, id, time)); | ||
} | ||
|
||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
processFacebook = function (editor, val) { | ||
var pOpts = editor.opts.parserOptions; | ||
var idMatch = val.match(/videos\/(\d+)+|v=(\d+)|vb.\d+\/(\d+)/); | ||
|
||
if (idMatch && /^[a-zA-Z0-9]/.test(idMatch[1])) { | ||
var id = idMatch[1]; | ||
|
||
if (editor.sourceMode()) { | ||
editor.insertText('[facebook]' + id + '[/facebook]'); | ||
} else { | ||
editor.wysiwygEditorInsertHtml( | ||
facebookHtml(pOpts.facebookParameters, id)); | ||
} | ||
|
||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
/** | ||
* Function for the txtExec and exec properties | ||
* | ||
* @param {node} caller | ||
* @private | ||
*/ | ||
commandHandler = function (caller) { | ||
var editor = this; | ||
var content = document.createElement('div'); | ||
|
||
var div; | ||
var label; | ||
var input; | ||
var button; | ||
|
||
div = document.createElement('div'); | ||
label = document.createElement('label'); | ||
label.setAttribute('for', 'link'); | ||
label.textContent = editor._('Video URL:'); | ||
input = document.createElement('input'); | ||
input.type = 'text'; | ||
input.id = 'link'; | ||
input.dir = 'ltr'; | ||
input.placeholder = 'https://'; | ||
div.appendChild(label); | ||
div.appendChild(input); | ||
|
||
content.appendChild(div); | ||
|
||
div = document.createElement('div'); | ||
button = document.createElement('input'); | ||
button.type = 'button'; | ||
button.className = 'button'; | ||
button.value = editor._('Insert'); | ||
div.appendChild(button); | ||
|
||
content.appendChild(div); | ||
|
||
button.addEventListener('click', function (e) { | ||
var val = input.value; | ||
var done; | ||
|
||
done = processYoutube(editor, val); | ||
if (!done) { | ||
processFacebook(editor, val); | ||
} | ||
|
||
editor.closeDropDown(true); | ||
e.preventDefault(); | ||
}); | ||
|
||
editor.createDropDown(caller, 'insertlink', content); | ||
}; | ||
}; | ||
})(sceditor); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice