Skip to content

Commit

Permalink
实现Ajax/Pjax加载
Browse files Browse the repository at this point in the history
  • Loading branch information
fghrsh committed Jun 3, 2016
1 parent 2142383 commit 495f848
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,25 @@
[dplayer url="http://xxx.com/xxx.mp4" pic="http://xxx.com/xxx.jpg" autoplay="true" danmu="false"/]
```

### V1.2 更新
已实现Ajax/Pjax模板支持,仅需在 加载完成时执行 里加入
```
dpajaxload();
```
即可无刷新加载 DPlayer 播放器(效果见我博客,全站pjax)

###参数说明
url - 视频地址(必须)
pic - 视频封面(可选)
danmu - 弹幕(可选,默认开)
autoplay - 自动播放(可选,默认关)
theme - 自定义颜色(可选,默认为全局设置)

###后台配置说明
本站地址 - 用于生成唯一视频ID
弹幕后端服务器 - 用于指定弹幕服务器地址
播放器色调 - 指定全局播放器颜色主题(颜色生效在哪?你看看进度条..)
Tips:想多个站显示同一弹幕,设置“本站地址”为同一地址即可(视频地址需相同)

## LICENSE
MIT © [FGHRSH](https://www.fghrsh.net)
5 changes: 4 additions & 1 deletion function.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ function parseCallback($post,$siteurl,$dmserver,$theme) {
$data['danmaku'] = ($atts['danmu'] != 'false') ? $danmaku : null;
if (empty($dmserver)) $data['danmaku'] = null;
$js = json_encode($data);
$src = "<div id=\"player".$id."\" class=\"dplayer\">如无显示请刷新本页,播放器暂不支持Pjax无刷新加载</div><script>dPlayerOptions.push(".$js.");</script>";
$src = "<div id=\"player".$id."\" class=\"dplayer\"></div>";
if (empty($out)) {
$out = str_replace($matches[0][$i], $src, $post);
$jssrc = "dPlayerOptions.push(".$js.");";
} else {
$out = str_replace($matches[0][$i], $src, $out);
$jssrc .= "dPlayerOptions.push(".$js.");";
}
}
$out .= "<i id=\"dpajax\" hidden=\"hidden\">".$jssrc."</i>";
return $out;
}

Expand Down
4 changes: 2 additions & 2 deletions include.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function DPlayer_Filter_Plugin_ViewList_Template(&$template) {

function DPlayer_Filter_Plugin_Zbp_MakeTemplatetags() {
global $zbp;
$zbp->header .= '<link rel="stylesheet" href="'.$zbp->host.'zb_users/plugin/DPlayer/dplayer/DPlayer.min.css">'."\r\n".'<script>var dPlayers = [];var dPlayerOptions = [];</script>'."\r\n";
$zbp->footer .= '<script type="text/javascript" src="'.$zbp->host.'zb_users/plugin/DPlayer/dplayer/DPlayer.min.js"></script>'."\r\n"."<script>var len = dPlayerOptions.length;for(var i=0;i<len;i++){dPlayers[i] = new DPlayer({element: document.getElementById('player' + dPlayerOptions[i]['id']),autoplay: dPlayerOptions[i]['autoplay'],video: dPlayerOptions[i]['video'],theme: dPlayerOptions[i]['theme'],danmaku: dPlayerOptions[i]['danmaku'],});dPlayers[i].init();}</script>";
$zbp->header .= '<link rel="stylesheet" href="'.$zbp->host.'zb_users/plugin/DPlayer/dplayer/DPlayer.min.css">'."\r\n";
$zbp->footer .= '<script type="text/javascript" src="'.$zbp->host.'zb_users/plugin/DPlayer/dplayer/DPlayer.min.js"></script>'."\r\n"."<script>function dpajaxload(){var dPlayers=[],dPlayerOptions=[];eval(document.getElementById(\"dpajax\").innerHTML);var len=dPlayerOptions.length;for(var i=0;i<len;i++){dPlayers[i]=new DPlayer({element:document.getElementById('player'+dPlayerOptions[i]['id']),autoplay:dPlayerOptions[i]['autoplay'],video:dPlayerOptions[i]['video'],theme:dPlayerOptions[i]['theme'],danmaku:dPlayerOptions[i]['danmaku'],});dPlayers[i].init()}}dpajaxload();</script>";
}

function InstallPlugin_DPlayer() {
Expand Down
6 changes: 3 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<id>DPlayer</id>
<name>DPlayer for Z-BlogPHP</name>
<url>https://github.com/fghrsh/DPlayer_for_Z-BlogPHP</url>
<note>DPlayer - 炒鸡好看的HTML5弹幕视频播放器</note>
<note>DPlayer - 超级好看的HTML5弹幕视频播放器</note>
<description>https://www.fghrsh.net/post/57.html</description>
<path>main.php</path>
<include>include.php</include>
Expand All @@ -19,9 +19,9 @@
<url></url>
</source>
<adapted>140614</adapted>
<version>1.1</version>
<version>1.2</version>
<pubdate>2016-05-30</pubdate>
<modified>2016-06-01</modified>
<modified>2016-06-03</modified>
<price>0</price>
<advanced>
<dependency></dependency>
Expand Down

0 comments on commit 495f848

Please sign in to comment.