This commit is contained in:
81
Announcement/Plugin.php
Normal file
81
Announcement/Plugin.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Typecho 公告栏插件
|
||||
*
|
||||
* @package Announcement
|
||||
* @author skylzl
|
||||
* @version 1.0.0
|
||||
* @link http://www.phoneshuo.com
|
||||
*/
|
||||
|
||||
class Announcement_Plugin implements Typecho_Plugin_Interface
|
||||
{
|
||||
/**
|
||||
* 激活插件方法,如果激活失败,直接抛出异常
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function activate()
|
||||
{
|
||||
Typecho_Plugin::factory('Widget_Archive')->footer = array('Announcement_Plugin', 'footer');
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用插件方法,如果禁用失败,直接抛出异常
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function deactivate(){}
|
||||
|
||||
/**
|
||||
* 获取插件配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form 配置面板
|
||||
* @return void
|
||||
*/
|
||||
public static function config(Typecho_Widget_Helper_Form $form){
|
||||
/** 公告栏的显示模式 */
|
||||
$annMode = new Typecho_Widget_Helper_Form_Element_Radio(
|
||||
'annMode', array('2' => '底部固定', '1' => '弹窗展示'), '2',
|
||||
'公告模式', '默认底部固定,可选择在底部固定展示或者弹窗展示');
|
||||
$form->addInput($annMode);
|
||||
/** 展示区域 */
|
||||
$showArea = new Typecho_Widget_Helper_Form_Element_Radio(
|
||||
'showArea', array('2' => '仅首页展示', '1' => '全站展示'), '2',
|
||||
'展示区域', '默认仅首页,可选择仅首页或全站展示');
|
||||
$form->addInput($showArea);
|
||||
/** 是否加载jquery */
|
||||
$jquery = new Typecho_Widget_Helper_Form_Element_Radio(
|
||||
'jquery', array('0'=> '手动加载', '1'=> '自动加载'), 0, '选择jQuery来源',
|
||||
'若选择"手动加载",则需要你手动加载jQuery到你的主题里,若选择"自动加载",本插件会自动加载jQuery到你的主题里。');
|
||||
$form->addInput($jquery);
|
||||
/** 公告内容 */
|
||||
$content = new Typecho_Widget_Helper_Form_Element_Textarea('content', NULL, "测试公告1\n测试公告2",
|
||||
_t('公告内容'), _t('多条公告请用换行符隔开'));
|
||||
$form->addInput($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人用户的配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form
|
||||
* @return void
|
||||
*/
|
||||
public static function personalConfig(Typecho_Widget_Helper_Form $form){
|
||||
}
|
||||
|
||||
/**
|
||||
* 公告相关js加载在尾部
|
||||
*/
|
||||
public static function footer() {
|
||||
include 'announce-js.php';
|
||||
}
|
||||
}
|
||||
10
Announcement/README.md
Normal file
10
Announcement/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
### Typecho悬浮式公告栏插件Announcement v1.0.0
|
||||
|
||||
给你的Typecho提供公告栏的功能,从Emlog的公告栏插件修改而成
|
||||
- 纯插件支持
|
||||
- 显示位置支持弹窗展示和底部固定
|
||||
- 显示区域支持全站或者仅首页
|
||||
- 弹出框公告支持最小化模式,且24小时只自动弹出一次。
|
||||
- 支持手动或者自动加载Jquery库
|
||||
|
||||
###### 更多详见论坛原帖:http://forum.typecho.org/viewtopic.php?f=6&t=5443
|
||||
20
Announcement/announce-js.php
Normal file
20
Announcement/announce-js.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
$settings = Helper::options()->plugin('Announcement');
|
||||
if($settings->showArea=='2'){
|
||||
$request = new Typecho_Request;
|
||||
$currentUrl = $request->getRequestUrl();
|
||||
$blogUrl = Helper::options()->stack[0]['siteUrl'];
|
||||
if($currentUrl!=$blogUrl || $currentUrl==$blogUrl.'index.php'){
|
||||
return;
|
||||
}
|
||||
}
|
||||
$jqUrl = Helper::options()->pluginUrl . '/Announcement/js/jquery.min.js';
|
||||
$styleSheetUrl = Helper::options()->pluginUrl . '/Announcement/css/style.css';
|
||||
$jqueryScriptUrl = Helper::options()->pluginUrl . '/Announcement/js/script.js';
|
||||
if($settings->jquery){
|
||||
echo '<script src="'.$jqUrl.'"></script>';
|
||||
}
|
||||
echo '<link href="'.$styleSheetUrl.'" type="text/css" rel="stylesheet" />';
|
||||
echo '<script src="'.$jqueryScriptUrl.'" type="text/javascript"></script>';
|
||||
echo '<span id="announcement_plug" data-type="'.$settings->annMode.'" data-content="'.$settings->content.'"></span>';
|
||||
?>
|
||||
201
Announcement/css/style.css
Normal file
201
Announcement/css/style.css
Normal file
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* @Description: 网站公告插件
|
||||
* @Author: Skylzl
|
||||
* @Author URL: http://www.phoneshuo.com
|
||||
*/
|
||||
|
||||
#div-ann-bm li{margin:0; padding:0; list-style-type:none}
|
||||
|
||||
.com-hd{
|
||||
margin: 20px 0 15px;
|
||||
}
|
||||
|
||||
.com-hd b{
|
||||
font-size:16px;
|
||||
color:#333;
|
||||
font-family:'Microsoft Yahei';
|
||||
}
|
||||
|
||||
.tb-set{
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.tb-set tr td{
|
||||
padding: 10px 5px;
|
||||
border: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.tb-set tr td input, .tb-set tr td img{
|
||||
margin:0 auto;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.tb-set tr td b{
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.tb-set tr td .sel{
|
||||
height:17px;
|
||||
border:1px solid #ccc;
|
||||
border-radius:5px;
|
||||
outline: none;
|
||||
color:#333;
|
||||
padding:3px 1px;
|
||||
}
|
||||
|
||||
.tb-set tr td .sel select{
|
||||
border:none;
|
||||
outline:none;
|
||||
width:120px;
|
||||
}
|
||||
|
||||
.tb-set tr td .txt{
|
||||
width:240px;
|
||||
height:18px;
|
||||
border:1px solid #ccc;
|
||||
line-height:23px;
|
||||
border-radius:5px;
|
||||
outline: none;
|
||||
color:#333;
|
||||
padding:3px 0 2px 5px;
|
||||
}
|
||||
|
||||
.tb-set tr td .txt-lar{
|
||||
width:450px;
|
||||
height:100px;
|
||||
border:1px solid #ccc;
|
||||
line-height:15px;
|
||||
}
|
||||
|
||||
.tb-set tr td .txt-sho{
|
||||
width:150px;
|
||||
}
|
||||
|
||||
.tb-set tr td .txt-min{
|
||||
width:60px;
|
||||
}
|
||||
|
||||
/*前台*/
|
||||
#div-mask{
|
||||
width:100%;
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
z-index:9999;
|
||||
background:#000;
|
||||
opacity:0.2;
|
||||
filter:alpha(opacity=20);
|
||||
}
|
||||
|
||||
#div-pop-box{
|
||||
width:0;
|
||||
height:0;
|
||||
position:absolute;
|
||||
z-index:99999;
|
||||
padding:20px 20px 10px;
|
||||
border:6px solid #767576;
|
||||
background:#fff;
|
||||
opacity:0;
|
||||
filter:alpha(opacity=0);
|
||||
}
|
||||
|
||||
#div-pop-box.min{
|
||||
position:fixed;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#div-pop-box h3{
|
||||
width:314px;
|
||||
margin:0;
|
||||
padding:5px;
|
||||
font-size:16px;
|
||||
position:absolute;
|
||||
top:5px;
|
||||
left:8px;
|
||||
border-bottom:1px solid #ccc;
|
||||
}
|
||||
|
||||
#div-pop-box b{
|
||||
float:left;
|
||||
}
|
||||
|
||||
#div-pop-box .a-close{
|
||||
float:right;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.div-announcement-main{
|
||||
width:300px;
|
||||
height:140px;
|
||||
overflow:hidden;
|
||||
font-weight:normal;
|
||||
line-height:180%;
|
||||
position:absolute;
|
||||
top:40px;
|
||||
left:20px;
|
||||
}
|
||||
|
||||
#aAnnMin{
|
||||
width: 35px;
|
||||
height: 64px;
|
||||
display:block;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: -35px;
|
||||
_position:absolute;
|
||||
z-index:9999;
|
||||
background: url(../img/annMin.gif) no-repeat 0 0;
|
||||
cursor: pointer;
|
||||
opacity:0;
|
||||
filter:alpha(opacity=0);
|
||||
}
|
||||
|
||||
#aAnnMin:hover{
|
||||
background-position:0 -70px;
|
||||
}
|
||||
|
||||
#div-ann-bm{
|
||||
width:100%;
|
||||
height:25px;
|
||||
overflow:hidden;
|
||||
position:fixed;
|
||||
left:0;
|
||||
bottom:0;
|
||||
background:#000;
|
||||
opacity:0.6;
|
||||
filter:alpha(opacity=60);
|
||||
_position:absolute;
|
||||
_left:0;
|
||||
_bottom:0;
|
||||
z-index:9999;
|
||||
}
|
||||
|
||||
#div-ann-bm .div-ann-main{
|
||||
width:100%;
|
||||
height:25px;
|
||||
overflow:hidden;
|
||||
position: absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
z-index:20;
|
||||
background:url("../img/bulletin.gif") no-repeat 20px center;
|
||||
}
|
||||
|
||||
#div-ann-bm .div-ann-main ul{
|
||||
margin-top:0px;
|
||||
margin-left:50px;
|
||||
}
|
||||
|
||||
#div-ann-bm .div-ann-main ul li{
|
||||
height:25px;
|
||||
line-height:25px;
|
||||
color:#fff;
|
||||
}
|
||||
|
||||
#div-ann-bm .div-ann-main .a-close{
|
||||
position:absolute;
|
||||
top:4px;
|
||||
right:8px;
|
||||
cursor: pointer;
|
||||
color:#fff;
|
||||
}
|
||||
BIN
Announcement/img/annMin.gif
Normal file
BIN
Announcement/img/annMin.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
Announcement/img/bulletin.gif
Normal file
BIN
Announcement/img/bulletin.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 736 B |
4
Announcement/js/jquery.min.js
vendored
Normal file
4
Announcement/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
128
Announcement/js/script.js
Normal file
128
Announcement/js/script.js
Normal file
@@ -0,0 +1,128 @@
|
||||
$(function(){
|
||||
var showAnn = $("#announcement_plug");
|
||||
var showCon = showAnn.attr("data-content");
|
||||
showCon = showCon.split("\n");
|
||||
var showConHtml = '';
|
||||
if(showCon.length>1){
|
||||
for(i=0; i<showCon.length; i++){
|
||||
showConHtml += '<li>'+(i+1)+'、'+showCon[i]+'</li>';
|
||||
}
|
||||
}else{
|
||||
showConHtml = '<li>'+showCon+'</li>';
|
||||
}
|
||||
if(showAnn.attr("data-type")==1){
|
||||
//显示弹出框
|
||||
function showPopBox(){
|
||||
if(getCookie("isShowAnn")!=0){
|
||||
$("body").append("<div id='div-mask'></div>");
|
||||
$("body").append("<div id='div-pop-box'></div>");
|
||||
$("#div-pop-box").css({"left":$(document).scrollLeft(), "top":$(document).scrollTop()});
|
||||
changeAnnPosi();
|
||||
}else{
|
||||
showAnnMin();
|
||||
}
|
||||
$("#div-pop-box").html('<h3><b>网站公告</b><a class="a-close" href="javascript:;">X</a></h3><div class="div-announcement-main"><ul>'+showConHtml+'</ul></div>');
|
||||
closeBtn();
|
||||
}
|
||||
//改变位置
|
||||
function changeAnnPosi(){
|
||||
$("#div-mask").css({"height":$(document).height(), "width":$(window).width()+$(document).scrollLeft()});
|
||||
var popBox = $("#div-pop-box");
|
||||
var leftVal = ($(window).width() - 300) / 2 + $(document).scrollLeft();
|
||||
var topVal = ($(window).height() - 160) / 2 + $(document).scrollTop();
|
||||
popBox.stop().animate({top: topVal, left: leftVal, width:300, height:160, opacity:1}, "slow", function(){
|
||||
var allHeight = $(".div-announcement-main").children("ul").height();
|
||||
if(allHeight>140){
|
||||
$(".div-announcement-main").css({"overflow-y":"scroll"});
|
||||
}
|
||||
});
|
||||
if (('undefined' == typeof(document.body.style.maxHeight)) && getCookie("isShowAnn")==0){
|
||||
$("#aAnnMin").css("top",$(document).scrollTop());
|
||||
}
|
||||
}
|
||||
//关闭按钮
|
||||
function closeBtn(){
|
||||
var popBox = $("#div-pop-box");
|
||||
popBox.find(".a-close").click(function(){
|
||||
popBox.delay(100).stop().animate({top: $(document).scrollTop(), left: $(document).scrollLeft(), width:0, height:0, opacity:0}, 300, function(){
|
||||
showAnnMin();
|
||||
});
|
||||
});
|
||||
}
|
||||
//显示最小化
|
||||
function showAnnMin(){
|
||||
$("#div-mask").remove();
|
||||
$("#div-pop-box").remove();
|
||||
$("#div-pop-box").html('');
|
||||
setCookie("isShowAnn", "0", 24);
|
||||
$("body").append("<a id='aAnnMin' href='javascript:;'></a>");
|
||||
var aAnnMin = $("#aAnnMin").animate({left:0, opacity:1}, 500);
|
||||
aAnnMin.click(function(){
|
||||
delCookie("isShowAnn");
|
||||
$(this).remove();
|
||||
showPopBox();
|
||||
});
|
||||
}
|
||||
showPopBox();
|
||||
// 根据窗口变动调整位置
|
||||
$(window).resize(function() {
|
||||
changeAnnPosi();
|
||||
}).scroll(function() {
|
||||
changeAnnPosi();
|
||||
});
|
||||
}else{
|
||||
//底部固定
|
||||
$("body").append("<div id='div-ann-bm'><div class='div-ann-main'><ul id='ulAnnBox'>"+showConHtml+"</ul><a class='a-close' href='javascript:;'>X</a></div></div>");
|
||||
var ul = $("#ulAnnBox");
|
||||
var timer = setInterval(function(){
|
||||
ul.animate({marginTop:"-25px"}, 600, function(){
|
||||
var liFirst = ul.children("li").eq(0);
|
||||
liFirst.remove();
|
||||
ul.append("<li>"+liFirst.html()+"</li>");
|
||||
ul.css("margin-top", "0");
|
||||
})
|
||||
}, 5000);
|
||||
var annBmBox = $("#div-ann-bm");
|
||||
annBmBox.find(".a-close").click(function(){
|
||||
clearInterval(timer);
|
||||
annBmBox.animate({height:0}, 500, function(){
|
||||
annBmBox.remove();
|
||||
});
|
||||
});
|
||||
|
||||
if (($.browser.msie) && ($.browser.version == "6.0")){
|
||||
$(window).resize(function() {
|
||||
annBmBox.css("top",$(window).height()+$(document).scrollTop()-25);
|
||||
}).scroll(function() {
|
||||
annBmBox.css("top",$(window).height()+$(document).scrollTop()-25);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
//添加cookie
|
||||
function setCookie(objName, objValue, objHours) {
|
||||
var str = objName + "=" + escape(objValue);
|
||||
if (objHours > 0) {// 为0时不设定过期时间,浏览器关闭时cookie自动消失
|
||||
var date = new Date();
|
||||
var ms = objHours * 3600 * 1000;
|
||||
date.setTime(date.getTime() + ms);
|
||||
str += "; path=/; expires=" + date.toGMTString();
|
||||
}
|
||||
document.cookie = str;
|
||||
}
|
||||
//获取指定名称的cookie的值
|
||||
function getCookie(objName) {
|
||||
var arrStr = document.cookie.split("; ");
|
||||
for ( var i = 0; i < arrStr.length; i++) {
|
||||
var temp = arrStr[i].split("=");
|
||||
if (temp[0] == objName)
|
||||
return unescape(temp[1]);
|
||||
}
|
||||
}
|
||||
//删除cookie
|
||||
function delCookie(name) {
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() - 1);
|
||||
var cval=getCookie(name);
|
||||
if(cval!=null) document.cookie= name + "="+cval+"; path=/; expires="+exp.toGMTString();
|
||||
}
|
||||
Reference in New Issue
Block a user