'use strict'; P({ id: 'editor.js', key: 'MyPlayer', Init: function(me) { me.Load('api.js', function(){ var f = me.fn, o = me.option, api = me.GetPlugin('api.js'), apis = api.option.apis $(function() { var $wbr, textarea = f.id('text'), $textarea = $(textarea), md = $('input[name=markdown]').size() == 1 , $button = $('
  • MP
  • ').on('click', function(event) { show_dialog( ) }), $title = $(''), $url = $(''), $optional = { type:$(''), lyrics:$(''), width:$(''), height:$('') }, $ok = $(''), $cancel = $(''), $tip = $(''), $form = $('
    ').append($title, $url, $optional.type, $optional.lyrics, $optional.width, $optional.height, $ok, $cancel, $tip), $dialog = $('
    ').append('

    插入链接

    请在下方的输入框内输入要插入的媒体页面链接。

    ').append($form), $pop = $('
    ').add($dialog) var text = [] $.each(apis,function(index){ text.push(index) }) $('div',$dialog).append($('

    ').text('目前支持的有' + text.join('、') + '等。')) if (md){ insert_button() }else{ $('.notice button.yes').click(function(){ md = true insert_button() }) $('.notice button.no').click(function(){ md = false insert_button() }) } function insert_button(){ if (md) { $wbr = $('#wmd-button-row').append($('

  • ')) } else { $wbr = $('
      ').insertAfter('.url-slug') } $wbr.append($('
    • ').append($button)) } function show_dialog() { $('input', $pop).val('').attr('readonly',false).show() $tip.text('请输入有效的链接!') check($url.val()) $url.val('http://') $cancel.click(function(){ $pop.remove() }), $ok.click(function(){ write() $cancel.click() }) $url.keyup(onkeyup) $optional.type.keyup(onkeyup) $title.val($textarea.getSelection().text) $pop.appendTo(document.body) } var mode = {}, time function onkeyup(){ clearTimeout(time) time = setTimeout(function(){ mode.key = check($url.val(), $optional.type.val()) $tip.text(mode.key ? '将启用 ' + mode.key + ' 播放器!' : '这是不认识的链接!') f.each($optional, function(key, $input){ if( !mode.key || (apis[mode.key].optional && apis[mode.key].optional.indexOf(key)>-1) ) { $input.attr('readonly',false).show() mode[key] = true } else{ $input.attr('readonly',true).hide() mode[key] = false } }) }, 100); } function check(href, type) { var result = false f.each(apis, function(key, api) { if (api.check.call(null, href, type)) { result = key return false } }) return result } function write() { var sel = $textarea.getSelection(), end, html = '' end = (sel ? sel.start : 0) + html.length $textarea.replaceSelection(html) $textarea.setSelection(end, end) } }) }) } })