$(function () {
if ($('#wmd-button-row').length > 0) {
$('#wmd-button-row').append('
');
}
$(document).on('click', '#wmd-dplayer-button', function () {
$('body').append(
'' +
'
' +
'
' +
'
' +
'
插入视频
' +
'
在下方输入参数
' +
'
' +
'
' +
'
' +
'
开启弹幕
' +
'
自动播放
' +
'
' +
'
' +
'
' +
'
');
});
//cancel
$(document).on('click', '#cancel', function () {
$('#DPlayer-Panel').remove();
$('textarea').focus();
});
//ok
$(document).on('click', '#ok', function () {
var url = document.getElementById('DP-url').value,
pic = document.getElementById('DP-pic').value,
danmu = !!document.getElementById('DP-danmu').checked,
autoplay = !!document.getElementById('DP-autoplay').checked;
var tag = '[dplayer url="' + url + '" pic="' + pic + '" ';
if (!danmu) tag += 'danmu="' + danmu + '" ';
if (autoplay) tag += 'autoplay="' + autoplay + '" ';
tag += '/]\n';
var editor = document.getElementById('text');
if (document.selection) {
editor.focus();
sel = document.selection.createRange();
sel.text = tag;
editor.focus();
}
else if (editor.selectionStart || editor.selectionStart === '0') {
var startPos = editor.selectionStart;
var endPos = editor.selectionEnd;
var cursorPos = startPos;
editor.value = editor.value.substring(0, startPos)
+ tag
+ editor.value.substring(endPos, editor.textLength);
cursorPos += tag.length;
editor.focus();
editor.selectionStart = cursorPos;
editor.selectionEnd = cursorPos;
}
else {
editor.value += tag;
editor.focus();
}
$('#DPlayer-Panel').remove();
})
});