jQueryでXMLをパースするプラグイン「jParse」を使用して、当サイトのRSSフィードから最新5件を表示し、description部分を省略表示しています。「もっと見る」をクリックした後は[^]リンクで閉じられます。また5秒後に自動的に閉じます。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="ja" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="imagetoolbar" content="no" />
<title>設置サンプル</title>
<link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
<!-- JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="/content/lib/jquery/jparse-0.3.3.js"></script>
<script type="text/javascript" src="/content/lib/jquery/jquery.expander.js"></script>
<script type="text/javascript">
function start(){
$('#jparse-meta').html('<img src="/content/img/loading.gif" />');
}
function finish(){
$('#jparse-meta').remove();
$('dl#expander dd').expander({
collapseTimer:5000, /* 5秒後に自動で閉じる */
slicePoint:90, /* 表示する文字数 */
expandText:"もっと見る", /* 省略リンクテキスト */
userCollapseText: "[^]", /* 要素を閉じるリンクテキスト */
widow:0,
/* 展開される前 */
beforeExpand: function($thisElement) {
$thisElement.parent().parent().append('<div class="success">before expand.</div>');
},
/* 展開された時 */
afterExpand: function($thisElement) {
$thisElement.parent().parent().append('<div class="success">after expand.</div>');
},
/* 要素が閉じられた時 */
onCollapse: function($thisElement, byUser) {
if (byUser === true) {
/* ユーザー操作で要素が閉じられた時 */
$thisElement.parent().parent().append('<div class="success">on collapse (by user).</div>');
} else {
/* タイマーで要素が閉じられた時 */
$thisElement.parent().parent().append('<div class="success">on collapse (by timer).</div>');
}
}
});
}
$(function(){
// RSS取得
$('dl#expander').jParse({
ajaxOpts: {url: 'index.xml'},
elementTag: ['title', 'link', 'description'],
output: '<dt><a href="jpet01">jpet00</a></dt><dd>jpet02</dd>',
precallback: start,
callback: finish,
limit:5
});
});
</script>
<!-- CSS -->
<style media="screen,projection" type="text/css">
dl { margin:10px 0; padding:10px; border:1px solid #ccc; }
dt { margin:0; padding:0; font-size:11px; }
dd { font-size:11px; margin:10px 0 10px 0; padding:0; }
dt a { color:navy; }
</style>
<link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
<body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
<div id="wrap">
<h1>設置サンプル</h1>
<p>参照:<a href='http://plugins.learningjquery.com/expander/index.html#getting-started'>jQuery Expander Plugin</a></p>
<p>jQueryでXMLをパースするプラグイン「<a href='http://jparse.kylerush.net/'>jParse</a>」を使用して、当サイトのRSSフィードから最新5件を表示し、description部分を省略表示しています。「もっと見る」をクリックした後は[^]リンクで閉じられます。また5秒後に自動的に閉じます。</p>
<!-- CODE -->
<div id="jparse-meta" style="text-align: center; margin: 15px 0 0 0;"></div>
<dl id="expander"></dl>
<!-- / CODE -->
</div>
</body>
</html>