/** * @description typecho后台编辑器插入的js * @author ihewro * @version 4.1.0 */ window.onload = function () { $(document).ready(function(){ if ($("#wmd-button-row").length >0){ $('#wmd-button-row').append('
  • ' + '
  • ' + '
  • '+ ''); $('#text').before('
    '); var owo = new OwO({ logo: '表情', container: document.getElementsByClassName('OwO')[0], target: document.getElementById('text'), api: themeUrl + 'usr/OwO.json', position: 'down', width: '100%', maxHeight: '220px' }); $(document).on('click', '#wmd-hplayer-button', function() { $('body').append( '
    '+ '
    '+ '
    '+ '
    '+ '

    插入音乐

    '+ '

    请在下方的输入框内输入要插入的音乐地址

    支持云解析歌曲地址和本地歌曲资源,不支持歌单地址

    使用文档'+ '

    输入音乐地址

    '+ '
    '+ '
    '+ ''+ ''+ '
    '+ '
    '+ '
    '); $('.wmd-prompt-dialog input').val('http://').select(); }); $(document).on('click', '#wmd-post-button', function() { $('body').append( '
    '+ '
    '+ '
    '+ '
    '+ '

    调用其他文章

    你可以在当前文章中调用另一篇文章,达到文章之间的交流体验。使用文档

    '+ '输入文章cid

    '+ '输入文章封面

    '+ '
    '+ '
    '+ ''+ ''+ '
    '+ '
    '+ '
    '); }); $(document).on('click', '#wmd-video-button', function() { $('body').append( '
    '+ '
    '+ '
    '+ '
    '+ '

    插入视频

    '+ '

    可以向文章中插入一个简约美观的视频播放器

    '+ '输入视频地址'+ '输入视频封面'+ '
    '+ '
    '+ ''+ ''+ '
    '+ '
    '+ '
    '); $('.wmd-prompt-dialog input').select(); }); $(document).on('click','#hplayer_cancel',function() { $('#MetingPanel').remove(); $('textarea').focus(); }); $(document).on('click','#video_cancel',function() { $('#videoPanel').remove(); $('textarea').focus(); }); $(document).on('click','#post_cancel',function() { $('#postPanel').remove(); $('textarea').focus(); }); $(document).on('click','#hplayer_ok',function() { //执行一个ajax请求获取解析歌单地址的音频信息 callback=$.ajax({ type:'POST', url: hplayerUrl, data:{data:$('.wmd-prompt-dialog input').val(),size:"large",autoplay:$("#autoplay").is(':checked')}, async:false }); myField = document.getElementById('text'); var textMetingContent = callback.responseText; inserContentToTextArea(myField,textMetingContent,'#MetingPanel'); }); $(document).on('click', '#video_ok',function () { var textContent = $('.wmd-prompt-dialog input[name="url"]').val(); var pic = $('.wmd-prompt-dialog input[name="pic"]').val(); var picHtml = ""; var reg = new RegExp("\/","g");//g,表示全部替换。 if (pic !== ""){ pic = pic.replace(reg,'\\/'); picHtml = 'pic="' + pic + '"'; } textContent=textContent.replace(reg,'\\/'); textContent = '[vplayer url="' + textContent + '" '+ picHtml +' /]'; myField = document.getElementById('text'); inserContentToTextArea(myField,textContent,'#videoPanel'); }) $(document).on('click', '#post_ok',function () { var cid = 'cid="' + $('.wmd-prompt-dialog input[name = "cid"]').val() + '"'; var coverValue =$('.wmd-prompt-dialog input[name = "cover"]').val(); if (coverValue){ var reg = new RegExp("\/","g");//g,表示全部替换。 coverValue=coverValue.replace(reg,'\\/'); var cover = 'cover="' + coverValue + '"'; }else{ var cover =""; } var textContent = '[post ' + cid + ' ' +cover +'/]'; myField = document.getElementById('text'); inserContentToTextArea(myField,textContent,'#postPanel'); }) } }); }; function inserContentToTextArea(myField,textContent,modelId) { $(modelId).remove(); if (document.selection) {//IE浏览器 myField.focus(); var sel = document.selection.createRange(); sel.text = textContent; myField.focus(); } else if (myField.selectionStart || myField.selectionStart == '0') { //FireFox、Chrome var startPos = myField.selectionStart; var endPos = myField.selectionEnd; var cursorPos = startPos; myField.value = myField.value.substring(0, startPos) + textContent + myField.value.substring(endPos, myField.value.length); cursorPos += textContent.length; myField.selectionStart = cursorPos; myField.selectionEnd = cursorPos; myField.focus(); } else{//其他环境 myField.value += textContent; myField.focus(); } }