Created
December 27, 2013 11:22
-
-
Save lizheming/8145744 to your computer and use it in GitHub Desktop.
XiaMiPlayer插件部分代码
This file contains hidden or 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
<?php | |
/** | |
* 虾米音乐播放器:虾米音乐搜索+引用 | |
* | |
* @package XiaMiPlayer | |
* @author 公子 | |
* @version 3.0.6 | |
* @link http://zh.eming.li/#typecho | |
*/ | |
class XiaMiPlayer_Plugin implements Typecho_Plugin_Interface | |
{ | |
/** | |
* 插件版本号 | |
* @var string | |
*/ | |
const _VERSION = '3.0.6'; | |
/** | |
* 激活插件方法,如果激活失败,直接抛出异常 | |
* | |
* @access public | |
* @return void | |
* @throws Typecho_Plugin_Exception | |
*/ | |
public static function activate() | |
{ | |
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('XiaMiPlayer_Plugin', 'In'); | |
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('XiaMiPlayer_Plugin', 'In'); | |
Typecho_Plugin::factory('admin/editor-js.php')->markdownEditor = array('XiaMiPlayer_Plugin', 'AddButton'); | |
} | |
public static function AddButton() | |
{ | |
?> | |
editor.hooks.chain('makeButton', function (buttons, makeButton, bindCommand, ui) { | |
buttons.music = makeButton('wmd-music-button', '插入音乐 Ctrl+Shift+M', '0', function (chunk, postProcessing) { | |
background = ui.createBackground(); | |
ui.dialog(function(parent) { | |
console.log(parent); | |
var Panel = window.document.createElement('div'); | |
Panel.setAttribute('id', 'searchPanel'); | |
/* 增加选项 */ | |
var tab = window.document.createElement('ul'); | |
tab.setAttribute('id', 'tab'); | |
tab.classname = "wmd-button-row"; | |
tab.innerHTML = '<li onclick="xm_search();" title="Ctrl + ←"><b>虾米搜索</b></li>'; | |
tab.innerHTML += '<li onclick="xm_link();" title="Ctrl + →"><b>输入链接</b></li>'; | |
Panel.appendChild(tab); | |
/* 增加搜索框 */ | |
var form = window.document.createElement('form'); | |
form.setAttribute('id', 'xm'); | |
Panel.appendChild(form); | |
parent.appendChild(Panel); | |
xm_search(); | |
}, function(isCancle){ | |
background.parentNode.removeChild(background); | |
}, '搜索', '取消'); | |
}); | |
buttons.music.getElementsByTagName('span')[0].style.background = 'transparent url(<?php echo Helper::options()->pluginUrl; ?>/XiaMiPlayer/music-image.png) no-repeat'; | |
}); | |
function search() { | |
var k = $('#xiami_search').val(), p = Number($('#xiami_navi').attr('page')); | |
$('.pre').html('上一页'); | |
$('.next').html('下一页'); | |
if(k) { | |
$('#xiami_result').html('正在载入请稍后...'); | |
$.getJSON('http://www.xiami.com/app/nineteen/search/key/'+k+'/page/'+p+'?callback=?',function(data) { | |
$('#xiami_result').html(''); | |
$.each(data.results, | |
function(i, item) { | |
$('<a href=\"#\" onclick=\"show(\'' + item.song_id + '\');\" title=\"Ctrl + '+(i+1)+'\">' + (i+1) + '. ' + decodeURIComponent(item.song_name).split('+').join(' ') + ' - ' + decodeURIComponent(item.artist_name).split('+').join(' ') + '</a>').appendTo('#xiami_result'); | |
}); | |
}); | |
} else { | |
alert('请输入歌曲名称!') | |
} | |
} | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment