織夢(mèng)DEDECMS頂踩功能修改(非插件)
最近在做一個(gè)站時(shí)。要用到頂踩功能,網(wǎng)上找了好久,沒(méi)有找到合適的。只好拿默認(rèn)模板里里修改了。修改后的效果如下,有需要的朋友 ,可拿去修改使用。
用頂踩功能,就必須在內(nèi)容頁(yè)模板<HEAD>頭部引入dedeajax2.js文件,引入代碼如下:
<script language="javascript" type="text/javascript" src="{dede:global.cfg_cmsurl/}/include/dedeajax2.js"></script>
<script language="javascript" type="text/javascript">
<!--
function postBadGood(ftype,fid)
{
var taget_obj = document.getElementById(ftype+fid);
var saveid = GetCookie('badgoodid');
if(saveid != null)
{
var saveids = saveid.split(',');
var hasid = false;
saveid = '';
j = 1;
for(i=saveids.length-1;i>=0;i--)
{
if(saveids[i]==fid && hasid) continue;
else {
if(saveids[i]==fid && !hasid) hasid = true;
saveid += (saveid=='' ? saveids[i] : ','+saveids[i]);
j++;
if(j==10 && hasid) break;
if(j==9 && !hasid) break;
}
}
if(hasid) { alert('您剛才已表決過(guò)了喔!'); return false;}
else saveid += ','+fid;
SetCookie('badgoodid',saveid,1);
}
else
{
SetCookie('badgoodid',fid,1);
}
myajax = new DedeAjax(taget_obj,false,false,'','','');
myajax.SendGet2("{dede:field name='phpurl'/}/feedback.php?aid="+fid+"&action="+ftype+"&fid="+fid);
}
function postDigg(ftype,aid)
{
var taget_obj = document.getElementById('newdigg');
var saveid = GetCookie('diggid');
if(saveid != null)
{
var saveids = saveid.split(',');
var hasid = false;
saveid = '';
j = 1;
for(i=saveids.length-1;i>=0;i--)
{
if(saveids[i]==aid && hasid) continue;
else {
if(saveids[i]==aid && !hasid) hasid = true;
saveid += (saveid=='' ? saveids[i] : ','+saveids[i]);
j++;
if(j==20 && hasid) break;
if(j==19 && !hasid) break;
}
}
if(hasid) { alert("您已經(jīng)表決過(guò),請(qǐng)不要重復(fù)點(diǎn)擊哦 !"); return; }
else saveid += ','+aid;
SetCookie('diggid',saveid,1);
}
else
{
SetCookie('diggid',aid,1);
}
myajax = new DedeAjax(taget_obj,false,false,'','','');
var url = "{dede:global.cfg_phpurl/}/digg_ajax.php?action="+ftype+"&id="+aid;
myajax.SendGet2(url);
}
function getDigg(aid)
{
var taget_obj = document.getElementById('newdigg');
myajax = new DedeAjax(taget_obj,false,false,'','','');
myajax.SendGet2("{dede:global.cfg_phpurl/}/digg_ajax.php?id="+aid);
DedeXHTTP = null;
}
-->
</script>
樣式:
/*頂踩*/
.newdigg {
height: 51px;
margin: 0 auto;
clear: both;
overflow: hidden;
padding: 10px 0 30px 150px;
}
.newdigg .digg_good {
background: #ff6666;
}
.diggbox {
width: 195px;
height: 51px;
float: left;
margin-right: 8px;
overflow: hidden;
cursor: pointer;
}
.newdigg .digg_good .digg_act {
color: #fff;
}
.diggbox .digg_act {
font-size: 14px;
float: left;
line-height: 31px;
text-indent: 32px;
height: 29px;
overflow: hidden;
font-weight: bold;
}
.newdigg .digg_good .digg_num {
color: #fff;
}
.diggbox .digg_num {
float: left;
line-height: 29px;
text-indent: 5px;
}
.diggbox .digg_percent {
width: 180px;
clear: both;
padding-left: 10px;
overflow: hidden;
}
.diggbox .digg_percent .digg_percent_bar {
width: 100px;
height: 7px;
background: #E8E8E8;
border-right: 1px solid #CCC;
float: left;
overflow: hidden;
margin-top: 3px;
}
.newdigg .digg_good .digg_percent .digg_percent_bar span {
border: 1px solid #999999;
background: #999999;
}
.diggbox .digg_percent .digg_percent_bar span {
display: block;
height: 5px;
overflow: hidden;
background: #000;
}
.diggbox .digg_percent .digg_percent_num {
font-size: 10px;
float: left;
padding-left: 10px;
}
.newdigg .digg_bad {
background:#ff9966;
}
.diggbox {
height: 51px;
float: left;
margin-right: 8px;
overflow: hidden;
cursor: pointer;
}
.newdigg .digg_bad .digg_act {
color: #FFFFFF;
}
.diggbox .digg_act {
font-size: 14px;
float: left;
line-height: 31px;
text-indent: 32px;
height: 29px;
overflow: hidden;
font-weight: bold;
}
.newdigg .digg_bad .digg_num {
color: #fff;
}
.diggbox .digg_num {
float: left;
line-height: 29px;
text-indent: 5px;
}
.diggbox .digg_percent {
width: 180px;
clear: both;
padding-left: 10px;
overflow: hidden;
}
.diggbox .digg_percent .digg_percent_bar {
width: 100px;
height: 7px;
background: #E8E8E8;
border-right: 1px solid #CCC;
float: left;
overflow: hidden;
margin-top: 3px;
}
.newdigg .digg_bad .digg_percent .digg_percent_bar span {
border: 1px solid #999999;
background: #999999;
}
.diggbox .digg_percent .digg_percent_bar span {
display: block;
height: 5px;
overflow: hidden;
background: #000;
}
.diggbox .digg_percent .digg_percent_num {
font-size: 10px;
float: left;
padding-left: 10px;
}
模板頁(yè)面html調(diào)用代碼:
<!-- //頂踩 -->
<div class="newdigg" id="newdigg">
<div class="diggbox digg_good" onmousemove="this.style.backgroundPosition='left bottom';" onmouseout="this.style.backgroundPosition='left top';" onclick="javascript:postDigg('good',{dede:field.id/})">
<div class="digg_act">頂一下</div>
<div class="digg_num">({dede:field.goodpost/})</div>
<div class="digg_percent">
<div class="digg_percent_bar"><span style="width:{dede:field.goodper/}%"></span></div>
<div class="digg_percent_num">{dede:field.goodper/}%</div>
</div>
</div>
<div class="diggbox digg_bad" onmousemove="this.style.backgroundPosition='right bottom';" onmouseout="this.style.backgroundPosition='right top';" onclick="javascript:postDigg('bad',{dede:field.id/})">
<div class="digg_act">踩一下</div>
<div class="digg_num">({dede:field.badpost/})</div>
<div class="digg_percent">
<div class="digg_percent_bar"><span style="width:{dede:field.badper/}%"></span></div>
<div class="digg_percent_num">{dede:field.badper/}%</div>
</div>
</div>
</div>
<script language="javascript" type="text/javascript">getDigg({dede:field.id/});</script>
<!-- //頂踩部份的源碼結(jié)束 -->
聲明:
1.本站主要是為了記錄工作、學(xué)習(xí)中遇到的問(wèn)題,可能由于本人技術(shù)有限,內(nèi)容難免有紕漏,一切內(nèi)容僅供參考。
2.本站部分內(nèi)容來(lái)源互聯(lián)網(wǎng),如果有圖片或者內(nèi)容侵犯您的權(quán)益請(qǐng)聯(lián)系我們刪除!
3.本站所有原創(chuàng)作品,包括文字、資料、圖片、網(wǎng)頁(yè)格式,轉(zhuǎn)載時(shí)請(qǐng)標(biāo)注作者與來(lái)源。
1.本站主要是為了記錄工作、學(xué)習(xí)中遇到的問(wèn)題,可能由于本人技術(shù)有限,內(nèi)容難免有紕漏,一切內(nèi)容僅供參考。
2.本站部分內(nèi)容來(lái)源互聯(lián)網(wǎng),如果有圖片或者內(nèi)容侵犯您的權(quán)益請(qǐng)聯(lián)系我們刪除!
3.本站所有原創(chuàng)作品,包括文字、資料、圖片、網(wǎng)頁(yè)格式,轉(zhuǎn)載時(shí)請(qǐng)標(biāo)注作者與來(lái)源。
THE END