Vergleich jscripts/bbcodes_sceditor.js - 1.8.19 - 1.8.23

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 1Zeile 1
// This was taken from the SCEditor plugin for MyBB

$(document).ready(function($) {

$(function ($) {



	'use strict';


	'use strict';


	var $document = $(document);


/***********************
* Add custom MyBB CSS *
***********************/
$('<style type="text/css">' +
'.sceditor-dropdown { text-align: ' + ($('body').css('direction') === 'rtl' ? 'right' :'left') + '; }' +
'</style>').appendTo('body');







































	var mybbCmd = {
align: ['left', 'center', 'right', 'justify'],
fsStr: ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'],
fSize: [9, 12, 15, 17, 23, 31],
video: {
'Dailymotion': {
'match': /(dailymotion\.com\/video\/|dai\.ly\/)([^\/]+)/,
'url': '//www.dailymotion.com/embed/video/',
'html': '<iframe frameborder="0" width="480" height="270" src="{url}" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
},
'Facebook': {
'match': /facebook\.com\/(?:photo.php\?v=|video\/video.php\?v=|video\/embed\?video_id=|v\/?)(\d+)/,
'url': 'https://www.facebook.com/video/embed?video_id=',
'html': '<iframe src="{url}" width="625" height="350" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
},
'Liveleak': {
'match': /liveleak\.com\/(?:view\?[a-z]=)([^\/]+)/,
'url': 'http://www.liveleak.com/ll_embed?i=',
'html': '<iframe width="500" height="300" src="{url}" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
},
'MetaCafe': {
'match': /metacafe\.com\/watch\/([^\/]+)/,
'url': 'http://www.metacafe.com/embed/',
'html': '<iframe src="{url}" width="440" height="248" frameborder=0 data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
},
'Mixer': {
'match': /mixer\.com\/([^\/]+)/,
'url': '//mixer.com/embed/player/',
'html': '<iframe allowfullscreen="true" src="{url}" width="620" height="349" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
},
'Vimeo': {
'match': /vimeo.com\/(\d+)($|\/)/,
'url': '//player.vimeo.com/video/',
'html': '<iframe src="{url}" width="500" height="281" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
},
'Youtube': {
'match': /(?:v=|v\/|embed\/|youtu\.be\/)(.{11})/,
'url': '//www.youtube.com/embed/',
'html': '<iframe width="560" height="315" src="{url}" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
},
'Twitch': {
'match': /twitch\.tv\/(?:[\w+_-]+)\/v\/(\d+)/,
'url': '//player.twitch.tv/?video=v',
'html': '<iframe src="{url}" frameborder="0" scrolling="no" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
}
}
};





 
	// Add custom MyBB CSS
$('<style type="text/css">' +
'.sceditor-dropdown { text-align: ' + ($('body').css('direction') === 'rtl' ? 'right' : 'left') + '; }' +
'</style>').appendTo('body');





	/********************************************
* Update editor to use align= as alignment *
********************************************/
$.sceditor.plugins.bbcode.bbcode

	// Update editor to use align= as alignment
$.sceditor.formats.bbcode



		.set('align', {

		.set('align', {

			html: function(element, attrs, content) {

			html: function (element, attrs, content) {

				return '<div align="' + (attrs.defaultattr || 'left') + '">' + content + '</div>';
},
isInline: false

				return '<div align="' + (attrs.defaultattr || 'left') + '">' + content + '</div>';
},
isInline: false

		})
.set('center', { format: '[align=center]{0}[/align]' })
.set('left', { format: '[align=left]{0}[/align]' })
.set('right', { format: '[align=right]{0}[/align]' })
.set('justify', { format: '[align=justify]{0}[/align]' });

$.sceditor.command
.set('center', { txtExec: ['[align=center]', '[/align]'] })
.set('left', { txtExec: ['[align=left]', '[/align]'] })
.set('right', { txtExec: ['[align=right]', '[/align]'] })
.set('justify', { txtExec: ['[align=justify]', '[/align]'] });


		});
$.each(mybbCmd.align, function (i, val) {
$.sceditor.formats.bbcode.set(val, {
format: '[align=' + val + ']{0}[/align]'
});
$.sceditor.command
.set(val, {
txtExec: ['[align=' + val + ']', '[/align]']
});
});








/************************************************
* Update font to support MyBB's BBCode dialect *
************************************************/
$.sceditor.plugins.bbcode.bbcode

	// Update font to support MyBB's BBCode dialect
$.sceditor.formats.bbcode




		.set('list', {

		.set('list', {

			html: function(element, attrs, content) {
var type = (attrs.defaultattr === '1' ? 'ol' : 'ul');

if(attrs.defaultattr === 'a')

			html: function (element, attrs, content) {
var type = (attrs.defaultattr === '1' ? 'ol' : 'ul');

if (attrs.defaultattr === 'a')

					type = 'ol type="a"';

return '<' + type + '>' + content + '</' + type + '>';
},

					type = 'ol type="a"';

return '<' + type + '>' + content + '</' + type + '>';
},





			breakAfter: false
})

			breakAfter: false
})

		.set('ul', { format: '[list]{0}[/list]' })



		.set('ul', {
format: '[list]{0}[/list]'
})

		.set('ol', {

		.set('ol', {

			format: function($elm, content) {
var type = ($elm.attr('type') === 'a' ? 'a' : '1');

			format: function ($elm, content) {
var type = ($($elm).attr('type') === 'a' ? 'a' : '1');


return '[list=' + type + ']' + content + '[/list]';


return '[list=' + type + ']' + content + '[/list]';

			}





			}
})
.set('li', {
format: '[*]{0}',
excludeClosing: true

		})

		})

		.set('li', { format: '[*]{0}', excludeClosing: true })
.set('*', { excludeClosing: true, isInline: true });



		.set('*', {
excludeClosing: true,
isInline: true
});


$.sceditor.command


$.sceditor.command

		.set('bulletlist', { txtExec: ['[list]\n[*]', '\n[/list]'] })
.set('orderedlist', { txtExec: ['[list=1]\n[*]', '\n[/list]'] });


		.set('bulletlist', {
txtExec: function (caller, selected) {
var content = '';





 
				$.each(selected.split(/\r?\n/), function () {
content += (content ? '\n' : '') +
'[*]' + this;
});





	/***********************************************************
* Update size tag to use xx-small-xx-large instead of 1-7 *
***********************************************************/
$.sceditor.plugins.bbcode.bbcode.set('size', {
format: function($elm, content) {
var fontSize,
sizes = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'],
size = $elm.attr('size');

if (!size) {
fontSize = $elm.css('fontSize');
// Most browsers return px value but IE returns 1-7
if(fontSize.indexOf('px') > -1) {
// convert size to an int
fontSize = fontSize.replace('px', '') - 0;
size = 1;

if(fontSize > 9)
size = 2;
if(fontSize > 12)
size = 3;
if(fontSize > 15)
size = 4;
if(fontSize > 17)
size = 5;
if(fontSize > 23)
size = 6;
if(fontSize > 31)
size = 7;
}
else {
size = (~~fontSize) + 1;
}

if(size > 7)
size = 7;
if(size < 1)
size = 1;

size = sizes[size-1];
}
else {
size = sizes[size-1];
}

				this.insertText('[list]\n' + content + '\n[/list]');
}
})
.set('orderedlist', {
txtExec: function (caller, selected) {
var content = '';











































 
				$.each(selected.split(/\r?\n/), function () {
content += (content ? '\n' : '') +
'[*]' + this;
});

this.insertText('[list=1]\n' + content + '\n[/list]');
}
});

// Update size tag to use xx-small-xx-large instead of 1-7
$.sceditor.formats.bbcode.set('size', {
format: function ($elm, content) {
var fontSize,
size = $($elm).attr('size');

if (!size) {
fontSize = $($elm).css('fontSize');
// Most browsers return px value but IE returns 1-7
if (fontSize.indexOf('px') > -1) {
// convert size to an int
fontSize = parseInt(fontSize);
size = 1;
$.each(mybbCmd.fSize, function (i, val) {
if (fontSize > val) size = i + 2;
});
} else {
size = (~~fontSize) + 1;
}
size = (size >= 7) ? mybbCmd.fsStr[6] : ((size <= 1) ? mybbCmd.fsStr[0] : mybbCmd.fsStr[size - 1]);
} else {
size = mybbCmd.fsStr[size - 1];
}

			return '[size=' + size + ']' + content + '[/size]';
},

			return '[size=' + size + ']' + content + '[/size]';
},

		html: function(token, attrs, content) {
var sizes = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'],
size = $.inArray(attrs.defaultattr, sizes)+1;

		html: function (token, attrs, content) {
var size = $.inArray(attrs.defaultattr, mybbCmd.fsStr) + 1;


			if (!isNaN(attrs.defaultattr)) {
size = attrs.defaultattr;

			if (!isNaN(attrs.defaultattr)) {
size = attrs.defaultattr;

				if(size > 7)

				if (size > 7)

					size = 7;

					size = 7;

				if(size < 1)

				if (size < 1)

					size = 1;
}
if (size < 0) {

					size = 1;
}
if (size < 0) {

Zeile 134Zeile 171
			return '<font data-scefontsize="' + attrs.defaultattr + '" size="' + size + '">' + content + '</font>';
}
});

			return '<font data-scefontsize="' + attrs.defaultattr + '" size="' + size + '">' + content + '</font>';
}
});





	$.sceditor.command.set('size', {

	$.sceditor.command.set('size', {

		_dropDown: function(editor, caller, callback) {
var content = $('<div />'),

		_dropDown: function (editor, caller, callback) {
var content = $('<div />'),

				clickFunc = function (e) {
callback($(this).data('size'));
editor.closeDropDown(true);
e.preventDefault();
};


				clickFunc = function (e) {
callback($(this).data('size'));
editor.closeDropDown(true);
e.preventDefault();
};


			for (var i=1; i <= 7; i++)
content.append($('<a class="sceditor-fontsize-option" data-size="' + i + '" href="#"><font size="' + i + '">' + i + '</font></a>').click(clickFunc));

			for (var i = 1; i <= 7; i++)
content.append($('<a class="sceditor-fontsize-option" data-size="' + i + '" href="#"><font size="' + i + '">' + i + '</font></a>').on('click', clickFunc));





			editor.createDropDown(caller, 'fontsize-picker', content);

			editor.createDropDown(caller, 'fontsize-picker', content.get(0));

		},
exec: function (caller) {

		},
exec: function (caller) {

			var	editor = this;

			var editor = this;


$.sceditor.command.get('size')._dropDown(
editor,
caller,


$.sceditor.command.get('size')._dropDown(
editor,
caller,

				function(fontSize) {

				function (fontSize) {

					editor.execCommand('fontsize', fontSize);
}
);
},

					editor.execCommand('fontsize', fontSize);
}
);
},

		txtExec: function(caller) {
var editor = this,
sizes = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'];

		txtExec: function (caller) {
var editor = this;



$.sceditor.command.get('size')._dropDown(
editor,
caller,


$.sceditor.command.get('size')._dropDown(
editor,
caller,

				function(size) {
size = (~~size);
size = (size > 7) ? 7 : ( (size < 1) ? 1 : size );

editor.insertText('[size=' + sizes[size-1] + ']', '[/size]');
}
);

				function (size) {
size = (~~size);
size = (size > 7) ? 7 : ((size < 1) ? 1 : size);
editor.insertText('[size=' + mybbCmd.fsStr[size - 1] + ']', '[/size]');
}
);


		}

		}

	});



	});







	/********************************************
* Update quote to support pid and dateline *
********************************************/
$.sceditor.plugins.bbcode.bbcode.set('quote', {
format: function(element, content) {
var author = '',
$elm = $(element),

	// Update quote to support pid and dateline
$.sceditor.formats.bbcode.set('quote', {
format: function (element, content) {
var author = '',
$elm = $(element),



				$cite = $elm.children('cite').first();

				$cite = $elm.children('cite').first();

				$cite.html($cite.text());

			$cite.html($cite.text());





			if($cite.length === 1 || $elm.data('author'))
{

			if ($cite.length === 1 || $elm.data('author')) {


				author = $cite.text() || $elm.data('author');

$elm.data('author', author);
$cite.remove();


				author = $cite.text() || $elm.data('author');

$elm.data('author', author);
$cite.remove();


				content	= this.elementToBbcode($(element));

				content = this.elementToBbcode(element);

				author = '=' + author.replace(/(^\s+|\s+$)/g, '');

$elm.prepend($cite);
}


				author = '=' + author.replace(/(^\s+|\s+$)/g, '');

$elm.prepend($cite);
}


			if($elm.data('pid'))

			if ($elm.data('pid'))

				author += " pid='" + $elm.data('pid') + "'";


				author += " pid='" + $elm.data('pid') + "'";


			if($elm.data('dateline'))

			if ($elm.data('dateline'))

				author += " dateline='" + $elm.data('dateline') + "'";

return '[quote' + author + ']' + content + '[/quote]';

				author += " dateline='" + $elm.data('dateline') + "'";

return '[quote' + author + ']' + content + '[/quote]';

		},
html: function(token, attrs, content) {

		},
html: function (token, attrs, content) {

			var data = '';


			var data = '';


			if(attrs.pid)

			if (attrs.pid)

				data += ' data-pid="' + attrs.pid + '"';


				data += ' data-pid="' + attrs.pid + '"';


			if(attrs.dateline)

			if (attrs.dateline)

				data += ' data-dateline="' + attrs.dateline + '"';


				data += ' data-dateline="' + attrs.dateline + '"';


			if(typeof attrs.defaultattr !== "undefined")

			if (typeof attrs.defaultattr !== "undefined")

				content = '<cite>' + attrs.defaultattr.replace(/ /g, '&nbsp;') + '</cite>' + content;

return '<blockquote' + data + '>' + content + '</blockquote>';

				content = '<cite>' + attrs.defaultattr.replace(/ /g, '&nbsp;') + '</cite>' + content;

return '<blockquote' + data + '>' + content + '</blockquote>';

		},
quoteType: function(val, name) {
return "'" + val.replace("'", "\\'") + "'";



		},
quoteType: function (val, name) {
var quoteChar = val.indexOf('"') !== -1 ? "'" : '"';

return quoteChar + val + quoteChar;

		},
breakStart: true,
breakEnd: true

		},
breakStart: true,
breakEnd: true

	});



/************************************************************
* Update font tag to allow limiting to only first in stack *
************************************************************/
$.sceditor.plugins.bbcode.bbcode.set('font', {
format: function(element, content) {
var font;

if(element[0].nodeName.toLowerCase() !== 'font' || !(font = element.attr('face')))
font = element.css('font-family');


	});

// Update font tag to allow limiting to only first in stack
$.sceditor.formats.bbcode.set('font', {
format: function (element, content) {
var font;
if (element.nodeName.toLowerCase() !== 'font' || !(font = $(element).attr('face')))
font = $(element).css('font-family');











			if(typeof font == 'string' && font != '' && font != 'defaultattr')
{

			if (typeof font == 'string' && font != '' && font != 'defaultattr') {


				return '[font=' + this.stripQuotes(font) + ']' + content + '[/font]';

				return '[font=' + this.stripQuotes(font) + ']' + content + '[/font]';

			}
else
{

			} else {



				return content;
}
},

				return content;
}
},

		html: function(token, attrs, content) {
if(typeof attrs.defaultattr == 'string' && attrs.defaultattr != '' && attrs.defaultattr != '{defaultattr}')
{

		html: function (token, attrs, content) {
if (typeof attrs.defaultattr == 'string' && attrs.defaultattr != '' && attrs.defaultattr != '{defaultattr}') {


				return '<font face="' +
attrs.defaultattr +
'">' + content + '</font>';

				return '<font face="' +
attrs.defaultattr +
'">' + content + '</font>';

			}
else
{

			} else {



				return content;
}
}
});


				return content;
}
}
});




/************************
* Add MyBB PHP command *
************************/
$.sceditor.plugins.bbcode.bbcode.set('php', {

	// Add MyBB PHP command
$.sceditor.formats.bbcode.set('php', {





		allowsEmpty: true,
isInline: false,
allowedChildren: ['#', '#newline'],

		allowsEmpty: true,
isInline: false,
allowedChildren: ['#', '#newline'],

Zeile 283Zeile 300
	$.sceditor.command.set("php", {
_dropDown: function (editor, caller) {
var $content;

	$.sceditor.command.set("php", {
_dropDown: function (editor, caller) {
var $content;





			$content = $(
'<div>' +

			$content = $(
'<div>' +

					'<label for="php">' + editor._('PHP') + ':</label> ' +
'<textarea type="text" id="php" />' +


				'<div>' +
'<label for="php">' + editor._('PHP') + ':</label> ' +
'<textarea type="text" id="php"></textarea>' +

				'</div>' +

				'</div>' +

				'<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>'


				'<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>' +
'</div>'

			);


			);


			setTimeout(function() {
$content.find('#php').focus();
},100);

			setTimeout(function () {
$content.find('#php').trigger('focus');
}, 100);





			$content.find('.button').click(function (e) {
var val = $content.find('#php').val(),

			$content.find('.button').on('click', function (e) {
var val = $content.find('#php').val(),

					before = '[php]',
end = '[/php]';

					before = '[php]',
end = '[/php]';


if (val) {
before = before + val + end;
end = null;
}

editor.insert(before, end);


if (val) {
before = before + val + end;
end = null;
}

editor.insert(before, end);

				editor.closeDropDown(true);
e.preventDefault();
});

				editor.closeDropDown(true);
e.preventDefault();
});


editor.createDropDown(caller, 'insertphp', $content);
},


editor.createDropDown(caller, 'insertphp', $content.get(0));
},

		exec: function (caller) {
if ($.trim(this.getRangeHelper().selectedRange())) {
this.insert('[php]', '[/php]');
return;

		exec: function (caller) {
if ($.trim(this.getRangeHelper().selectedRange())) {
this.insert('[php]', '[/php]');
return;

			}

			}

			$.sceditor.command.get('php')._dropDown(this, caller);
},
txtExec: ['[php]', '[/php]'],
tooltip: "PHP"
});


			$.sceditor.command.get('php')._dropDown(this, caller);
},
txtExec: ['[php]', '[/php]'],
tooltip: "PHP"
});




/******************************
* Update code to support PHP *
******************************/
$.sceditor.plugins.bbcode.bbcode.set('code', {

	// Update code to support PHP
$.sceditor.formats.bbcode.set('code', {





		allowsEmpty: true,
tags: {
code: null

		allowsEmpty: true,
tags: {
code: null

Zeile 337Zeile 352
		isInline: false,
allowedChildren: ['#', '#newline'],
format: function (element, content) {

		isInline: false,
allowedChildren: ['#', '#newline'],
format: function (element, content) {

			if ($(element[0]).hasClass('phpcodeblock')) {

			if ($(element).hasClass('phpcodeblock')) {

				return '[php]' + content + '[/php]';
}
return '[code]' + content + '[/code]';

				return '[php]' + content + '[/php]';
}
return '[code]' + content + '[/code]';

Zeile 351Zeile 366

$content = $(
'<div>' +


$content = $(
'<div>' +

					'<label for="code">' + editor._('Code') + ':</label> ' +
'<textarea type="text" id="code" />' +


				'<div>' +
'<label for="code">' + editor._('Code') + ':</label> ' +
'<textarea type="text" id="code"></textarea>' +

				'</div>' +

				'</div>' +

				'<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>'


				'<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>' +
'</div>'

			);


			);


			setTimeout(function() {
$content.find('#code').focus();
},100);

			setTimeout(function () {
$content.find('#code').trigger('focus');
}, 100);





			$content.find('.button').click(function (e) {
var val = $content.find('#code').val(),

			$content.find('.button').on('click', function (e) {
var val = $content.find('#code').val(),

					before = '[code]',
end = '[/code]';


					before = '[code]',
end = '[/code]';


Zeile 376Zeile 393
				e.preventDefault();
});


				e.preventDefault();
});


			editor.createDropDown(caller, 'insertcode', $content);

			editor.createDropDown(caller, 'insertcode', $content.get(0));

		},
exec: function (caller) {
if ($.trim(this.getRangeHelper().selectedRange())) {

		},
exec: function (caller) {
if ($.trim(this.getRangeHelper().selectedRange())) {

Zeile 388Zeile 405
		txtExec: ['[code]', '[/code]'],
});


		txtExec: ['[code]', '[/code]'],
});




/***************************************
* Update email to support description *
***************************************/

	// Update email to support description





	$.sceditor.command.set('email', {
_dropDown: function (editor, caller) {
var $content;

	$.sceditor.command.set('email', {
_dropDown: function (editor, caller) {
var $content;





			$content = $(
'<div>' +

			$content = $(
'<div>' +

					'<label for="email">' + editor._('E-mail:') + '</label> ' +
'<input type="text" id="email" />' +






				'<div>' +
'<label for="email">' + editor._('E-mail:') + '</label> ' +
'<input type="text" id="email" />' +
'</div>' +
'<div>' +
'<label for="des">' + editor._('Description (optional):') + '</label> ' +
'<input type="text" id="des" />' +

				'</div>' +

				'</div>' +

				'<div>' +
'<label for="des">' + editor._('Description (optional):') + '</label> ' +
'<input type="text" id="des" />' +
'</div>' +
'<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>'

				'<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>' +
'</div>'




			);


			);


			$content.find('.button').click(function (e) {
var val = $content.find('#email').val(),

			$content.find('.button').on('click', function (e) {
var val = $content.find('#email').val(),

					description = $content.find('#des').val();


					description = $content.find('#des').val();


				if(val) {

				if (val) {

					// needed for IE to reset the last range

					// needed for IE to reset the last range

					editor.focus();

					$(editor).trigger('focus');





					if(!editor.getRangeHelper().selectedHtml() || description) {
if(!description)

					if (!editor.getRangeHelper().selectedHtml() || description) {
if (!description)

							description = val;


							description = val;


						editor.wysiwygEditorInsertHtml('<a href="' + 'mailto:' + val + '">' + description + '</a>');
}
else

						editor.insert('[email=' + val + ']' + description + '[/email]');
} else


						editor.execCommand('createlink', 'mailto:' + val);

						editor.execCommand('createlink', 'mailto:' + val);

					}

editor.closeDropDown(true);
e.preventDefault();
});

editor.createDropDown(caller, 'insertemail', $content);
},

				}

editor.closeDropDown(true);
e.preventDefault();
});

editor.createDropDown(caller, 'insertemail', $content.get(0));
},

		exec: function (caller) {
$.sceditor.command.get('email')._dropDown(this, caller);

		exec: function (caller) {
$.sceditor.command.get('email')._dropDown(this, caller);

		}
});



		}
});







	/**************************
* Add MyBB video command *
**************************/
$.sceditor.plugins.bbcode.bbcode.set('video', {

	// Add MyBB video command
$.sceditor.formats.bbcode.set('video', {



		allowsEmpty: true,
allowedChildren: ['#', '#newline'],
tags: {

		allowsEmpty: true,
allowedChildren: ['#', '#newline'],
tags: {

Zeile 451Zeile 461
				'data-mybb-vt': null
}
},

				'data-mybb-vt': null
}
},

		format: function($element, content) {
return '[video=' + $element.data('mybb-vt') + ']' + $element.data('mybb-vsrc') + '[/video]';

		format: function ($element, content) {
return '[video=' + $($element).data('mybb-vt') + ']' + $($element).data('mybb-vsrc') + '[/video]';

		},

		},

		html: function(token, attrs, content) {
var matches, url,
html = {
dailymotion: '<iframe frameborder="0" width="480" height="270" src="{url}" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
facebook: '<iframe src="{url}" width="625" height="350" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
liveleak: '<iframe width="500" height="300" src="{url}" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
metacafe: '<iframe src="{url}" width="440" height="248" frameborder=0 data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
mixer: '<iframe allowfullscreen="true" src="{url}" width="620" height="349" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
vimeo: '<iframe src="{url}" width="500" height="281" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
youtube: '<iframe width="560" height="315" src="{url}" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
twitch: '<iframe src="{url}" frameborder="0" scrolling="no" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
};












































































		html: function (token, attrs, content) {
var params = mybbCmd.video[Object.keys(mybbCmd.video).find(key => key.toLowerCase() === attrs.defaultattr)];
var matches, url;
var n = (attrs.defaultattr == 'dailymotion') ? 2 : 1;
if (typeof params !== "undefined") {
matches = content.match(params['match']);
url = matches ? params['url'] + matches[n] : false;
}
if (url) {
return params['html'].replace('{url}', url).replace('{src}', content).replace('{type}', attrs.defaultattr);
}
return $.sceditor.escapeEntities(token.val + content + (token.closing ? token.closing.val : ''));
}
});

$.sceditor.command.set('video', {
_dropDown: function (editor, caller) {
var $content, videourl, videotype, videoOpts;

$.each(mybbCmd.video, function (provider, data) {
videoOpts += '<option value="' + provider.toLowerCase() + '">' + editor._(provider) + '</option>';
});
$content = $(
'<div>' +
'<div>' +
'<label for="videotype">' + editor._('Video Type:') + '</label> ' +
'<select id="videotype">' + videoOpts + '</select>' +
'</div>' +
'<div>' +
'<label for="link">' + editor._('Video URL:') + '</label> ' +
'<input type="text" id="videourl" value="http://" />' +
'</div>' +
'<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>' +
'</div>'
);

$content.find('.button').on('click', function (e) {
videourl = $content.find('#videourl').val();
videotype = $content.find('#videotype').val();

if (videourl !== '' && videourl !== 'http://')
editor.insert('[video=' + videotype + ']' + videourl + '[/video]');

editor.closeDropDown(true);
e.preventDefault();
});

editor.createDropDown(caller, 'insertvideo', $content.get(0));
},
exec: function (caller) {
$.sceditor.command.get('video')._dropDown(this, caller);
},
txtExec: function (caller) {
$.sceditor.command.get('video')._dropDown(this, caller);
},
tooltip: 'Insert a video'
});

// Update image command to support MyBB syntax
$.sceditor.formats.bbcode.set('img', {
format: function (element, content) {
if ($(element).data('sceditor-emoticon'))
return content;

var url = $(element).attr('src'),
width = $(element).attr('width'),
height = $(element).attr('height'),
align = $(element).data('scealign');

var attrs = width !== undefined && height !== undefined && width > 0 && height > 0
? '=' + width + 'x' + height
: ''
;

if (align === 'left' || align === 'right')
attrs += ' align='+align

return '[img' + attrs + ']' + url + '[/img]';
},
html: function (token, attrs, content) {
var width, height, match,
align = attrs.align,
attribs = '';

// handle [img=340x240]url[/img]
if (attrs.defaultattr) {
match = attrs.defaultattr.split(/x/i);





			if(html[attrs.defaultattr])
{
switch(attrs.defaultattr)
{
case 'dailymotion':
matches = content.match(/(dailymotion\.com\/video\/|dai\.ly\/)([^\/]+)/);
url = matches ? '//www.dailymotion.com/embed/video/' + matches[2] : false;
break;
case 'facebook':
matches = content.match(/facebook\.com\/(?:photo.php\?v=|video\/video.php\?v=|video\/embed\?video_id=|v\/?)(\d+)/);
url = matches ? 'https://www.facebook.com/video/embed?video_id=' + matches[1] : false;
break;
case 'liveleak':
matches = content.match(/liveleak\.com\/(?:view\?[a-z]=)([^\/]+)/);
url = matches ? 'http://www.liveleak.com/ll_embed?i=' + matches[1] : false;
break;
case 'metacafe':
matches = content.match(/metacafe\.com\/watch\/([^\/]+)/);
url = matches ? 'http://www.metacafe.com/embed/' + matches[1] + '/' : false;
break;
case 'mixer':
matches = content.match(/mixer\.com\/([^\/]+)/);
url = matches ? '//mixer.com/embed/player/' + matches[1] + "?disableLowLatency=1" : false;
break;
case 'vimeo':
matches = content.match(/vimeo.com\/(\d+)($|\/)/);
url = matches ? '//player.vimeo.com/video/' + matches[1] : false;
break;
case 'youtube':
matches = content.match(/(?:v=|v\/|embed\/|youtu\.be\/)(.{11})/);
url = matches ? '//www.youtube.com/embed/' + matches[1] : false;
break;
case 'twitch':
matches = content.match(/twitch\.tv\/(?:[\w+_-]+)\/v\/(\d+)/);
url = matches ? '//player.twitch.tv/?video=v' + matches[1] : false;
break;
}

				width  = match[0];
height = (match.length === 2 ? match[1] : match[0]);








































				if(url)
{
return html[attrs.defaultattr]
.replace('{url}', url)
.replace('{src}', content)
.replace('{type}', attrs.defaultattr);

				if (width !== undefined && height !== undefined && width > 0 && height > 0) {
attribs +=
' width="' + $.sceditor.escapeEntities(width, true) + '"' +
' height="' + $.sceditor.escapeEntities(height, true) + '"';



				}
}


				}
}


			return $.sceditor.escapeEntities(token.val + content + (token.closing ? token.closing.val : ''));





			if (align === 'left' || align === 'right')
attribs += ' style="float: ' + align + '" data-scealign="' + align + '"';

return '<img' + attribs +
' src="' + $.sceditor.escapeUriScheme(content) + '" />';

		}

		}

	});

$.sceditor.command.set('video', {

	})

$.sceditor.command.set('image', {

		_dropDown: function (editor, caller) {

		_dropDown: function (editor, caller) {

			var $content, videourl, videotype;

			var $content;





			// Excludes MySpace TV and Yahoo Video as I couldn't actually find them. Maybe they are gone now?

 
			$content = $(
'<div>' +

			$content = $(
'<div>' +

					'<label for="videotype">' + editor._('Video Type:') + '</label> ' +
'<select id="videotype">' +
'<option value="dailymotion">' + editor._('Dailymotion') + '</option>' +
'<option value="facebook">' + editor._('Facebook') + '</option>' +
'<option value="liveleak">' + editor._('LiveLeak') + '</option>' +
'<option value="metacafe">' + editor._('MetaCafe') + '</option>' +
'<option value="mixer">' + editor._('Mixer') + '</option>' +
'<option value="vimeo">' + editor._('Vimeo') + '</option>' +
'<option value="youtube">' + editor._('Youtube') + '</option>' +
'<option value="twitch">' + editor._('Twitch') + '</option>' +
'</select>'+




				'<div>' +
'<label for="image">' + editor._('URL') + ':</label> ' +
'<input type="text" id="image" placeholder="https://" />' +
'</div>' +
'<div>' +
'<label for="width">' + editor._('Width (optional)') + ':</label> ' +
'<input type="text" id="width" size="2" />' +
'</div>' +
'<div>' +
'<label for="height">' + editor._('Height (optional)') + ':</label> ' +
'<input type="text" id="height" size="2" />' +
'</div>' +
'<div>' +
'<input type="button" class="button" value="' + editor._('Insert') + '" />' +

				'</div>' +

				'</div>' +

				'<div>' +
'<label for="link">' + editor._('Video URL:') + '</label> ' +
'<input type="text" id="videourl" value="http://" />' +
'</div>' +
'<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>'

				'</div>'





			);


			);


			$content.find('.button').click(function (e) {
videourl = $content.find('#videourl').val();
videotype = $content.find('#videotype').val();

if (videourl !== '' && videourl !== 'http://')
editor.insert('[video=' + videotype + ']' + videourl + '[/video]');








			$content.find('.button').on('click', function (e) {
var url = $content.find('#image').val(),
width = $content.find('#width').val(),
height = $content.find('#height').val()
;

var attrs = width !== undefined && height !== undefined && width > 0 && height > 0
? '=' + width + 'x' + height
: ''
;

if (url)
editor.insert('[img' + attrs + ']' + url + '[/img]');


editor.closeDropDown(true);
e.preventDefault();


editor.closeDropDown(true);
e.preventDefault();

			});

editor.createDropDown(caller, 'insertvideo', $content);

			});

editor.createDropDown(caller, 'insertimage', $content.get(0));

		},
exec: function (caller) {

		},
exec: function (caller) {

			$.sceditor.command.get('video')._dropDown(this, caller);

			$.sceditor.command.get('image')._dropDown(this, caller);

		},
txtExec: function (caller) {

		},
txtExec: function (caller) {

			$.sceditor.command.get('video')._dropDown(this, caller);

			$.sceditor.command.get('image')._dropDown(this, caller);

		},

		},

		tooltip: 'Insert a video'

 
	});


	});




/*************************************
* Remove last bits of table, superscript/subscript, youtube and ltr/rtl support *
*************************************/
$.sceditor.command
.remove('table').remove('subscript').remove('superscript').remove('youtube').remove('ltr').remove('rtl');

$.sceditor.plugins.bbcode.bbcode
.remove('table').remove('tr').remove('th').remove('td').remove('sub').remove('sup').remove('youtube').remove('ltr').remove('rtl');



/********************************************
* Remove code and quote if in partial mode *
********************************************/
if(partialmode) {
$.sceditor.plugins.bbcode.bbcode.remove('code').remove('php').remove('quote').remove('video').remove('img');

	// Remove last bits of table, superscript/subscript, youtube and ltr/rtl support
$.sceditor.command
.remove('table').remove('subscript').remove('superscript').remove('youtube').remove('ltr').remove('rtl');

$.sceditor.formats.bbcode
.remove('table').remove('tr').remove('th').remove('td').remove('sub').remove('sup').remove('youtube').remove('ltr').remove('rtl');

// Remove code and quote if in partial mode
if (partialmode) {
$.sceditor.formats.bbcode.remove('code').remove('php').remove('quote').remove('video').remove('img');









		$.sceditor.command

		$.sceditor.command

			.set('image', {
exec: function (caller) {
var editor = this,
content = $(this._('<form><div><label for="link">{0}</label> <input type="text" id="image" value="http://" /></div>' +
'<div><label for="width">{1}</label> <input type="text" id="width" size="2" /></div>' +
'<div><label for="height">{2}</label> <input type="text" id="height" size="2" /></div></form>',
this._("URL:"),
this._("Width (optional):"),
this._("Height (optional):")
))
.submit(function () {return false;});

content.append($(this._('<div><input type="button" class="button" value="Insert" /></div>',
this._("Insert")
)).click(function (e) {
var $form = $(this).parent('form'),
val = $form.find('#image').val(),
width = $form.find('#width').val(),
height = $form.find('#height').val(),
attrs = '';

if(width && height) {
attrs = '=' + width + 'x' + height;
}

if(val && val !== 'http://') {
editor.wysiwygEditorInsertHtml('[img' + attrs + ']' + val + '[/img]');
}

editor.closeDropDown(true);
e.preventDefault();
}));

editor.createDropDown(caller, 'insertimage', content);
}
})

 
			.set('quote', {

			.set('quote', {

				exec: function() {

				exec: function () {

					this.insert('[quote]', '[/quote]');
}
});
}


					this.insert('[quote]', '[/quote]');
}
});
}


 
	// Fix url code
$.sceditor.formats.bbcode.set('url', {
html: function (token, attrs, content) {

if (!attrs.defaultattr)
attrs.defaultattr = content;






/****************
* Fix url code *
****************/
$.sceditor.plugins.bbcode.bbcode.set('url', {
html: function(token, attrs, content) {

if(!attrs.defaultattr)
attrs.defaultattr = content;

return '<a href="' + $.sceditor.escapeUriScheme($.sceditor.escapeEntities(attrs.defaultattr)) + '">' + content + '</a>';
}

			return '<a href="' + $.sceditor.escapeUriScheme($.sceditor.escapeEntities(attrs.defaultattr)) + '">' + content + '</a>';
}











	});
});

	});
});