Skip to content

Commit

Permalink
增加了相册短代码功能
Browse files Browse the repository at this point in the history
同时修复了一些CSS错误
  • Loading branch information
youranreus committed Feb 21, 2021
1 parent edf889d commit e442b7b
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 17 deletions.
63 changes: 59 additions & 4 deletions CSS/G.css
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,54 @@ p.word{
color: RGBA(0,0,0,0.5);
}

div.photos{
width: 100%;
overflow: hidden;
display: flex;
flex-wrap: wrap;
margin: 0 auto;
}
div.photos figure{
position: relative;
margin: 5px;
}
div.photos figure div{
position: relative;
height: 0;
width: 100%;
}
div.photos figure div img{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 0px!important;
width: 100%!important;
max-width: 100%!important;
margin: 0px!important;
}

/* figcaption is not important */
figcaption{
position: absolute;
left: 0;
right: 0;
bottom: 0;
width: auto;
margin: 0;
padding: 5px 0 0px;
color: #fff;
text-align: center;
background-image: linear-gradient(180deg,hsla(0,0%,100%,0) 0,rgba(0,0,0,.03) 26%,rgba(0,0,0,.4) 71%,rgba(0,0,0,.5));
opacity: .6;
transition: opacity .3s ease;
}
figure:hover figcaption{
opacity: 1;
}

/**
* 侧边栏
*/
Expand Down Expand Up @@ -1158,8 +1206,9 @@ p.word{
}
#response{
color: RGB(48,71,88);
border-bottom: 1px solid #eaecef;
padding-bottom: .3em;
border-bottom: 1px solid #eaecef;
padding-bottom: .3em;
margin: 0;
text-align: left;
}
#comments a,#comments a:link,#comments a:visited {
Expand Down Expand Up @@ -1215,8 +1264,8 @@ p.word{
display: inline-block;
}

#comment-form {
padding-top: 15px;
#comment-form p{
margin-top:0;
}

button,html input[type=button],input[type=reset],input[type=submit] {
Expand Down Expand Up @@ -1972,6 +2021,9 @@ background : hsla(0,0%,100%,.6);
#zp-content p {
font-size: 1rem;
}
figcaption {
display: none;
}
.comment-list li {
padding: 24px;
}
Expand All @@ -1985,6 +2037,9 @@ background : hsla(0,0%,100%,.6);
#comment-form {
padding: 24px;
}
#response{
font-size: 120%;
}
#footer-content-left p {
font-size: 0.875rem;
margin: 0 0 3px 0px;
Expand Down
5 changes: 4 additions & 1 deletion CSS/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ html {
color: hsla(0,0%,100%,.6)!important;
}
#page-content-article,#post-content-article p,#post-content-article h1, #post-content-article h2, #post-content-article h3, #post-content-article h4 {
color:#f0f0f0;
color:#909090;
}
#post-content-article h1, #post-content-article h2, #post-content-article h3, #post-content-article h4 {
border:none;
Expand Down Expand Up @@ -148,6 +148,9 @@ html {
.post-content-notice{
background: RGBA(121,145,209,0.1);
}
.post-content-content {
color: #909090;
}
#post-content-excerpt {
background: #403E3E;
}
Expand Down
2 changes: 2 additions & 0 deletions CSS/shortcode.G.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
.post-content-content{
position: relative;
z-index:2;
line-height: 1.72222;
color: rgba(0,0,0,.86);
}
.post-content-notice:before{
content: " ";
Expand Down
31 changes: 24 additions & 7 deletions JS/X.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ function switchNightMode(){
}
})();

//相册排版by 熊猫小A
(function(){
var base = 50;
$.each($('.photos'), function(i, photoSet){
$.each($(photoSet).children(), function(j, item){
var img = new Image();
img.src = $(item).find('img').attr('src');
img.onload = function(){
var w = parseFloat(img.width);
var h = parseFloat(img.height);
$(item).css('width', w*base/h +'px');
$(item).css('flex-grow', w*base/h);
$(item).find('div').css('padding-top', h/w*100+'%');
};
});
});
})();



//pjax 刷新
Expand Down Expand Up @@ -113,14 +131,10 @@ function pjax_complete(){
function PreFancybox(){
$("#post img").each(function(){
$(this).wrap(function(){
if($(this).is(".bq"))
if($(this).is(".bq") || $(this).is("#feedme-content img"))
{
return '';
}
if($(this).is("#feedme-content img"))
{
return '';
}
return '<a data-fancybox="gallery" no-pjax data-type="image" href="' + $(this).attr("src") + '" class="light-link"></a>';
});
});
Expand All @@ -129,12 +143,15 @@ function PreFancybox(){
function imageinfo(){
$("#post img").each(function(){
$(this).wrap(function(){
if($(this).is(".bq"))
if($(this).is(".bq") || $(this).is("#feedme-content img"))
{
return '';
}
if($(this).is("#feedme-content img"))
if($(this).is("div.photos figure div img"))
{
$(this).addClass("lazyload");
$(this).attr('data-original',$(this).attr("src"));
$(this).attr('src','https://cdn.jsdelivr.net/gh/youranreus/[email protected]/G/IMG/loading2.gif');
return '';
}
$(this).addClass("lazyload");
Expand Down
6 changes: 6 additions & 0 deletions JS/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ $(function() {
<a id="g-warn-block">警告块</a>
<a id="g-dl">下载按钮</a>
<a id="g-tag">标签</a>
<a id="g-photos">相册</a>
</div>
`);

Expand Down Expand Up @@ -210,6 +211,11 @@ $(function() {
myField = document.getElementById("text"),
insertAtCursor(myField, '[tag]内容[/tag]')
});
$(document).on("click", "#g-photos",
function() {
myField = document.getElementById("text"),
insertAtCursor(myField, '[photos]\n\n图片1描述,图片1链接|\n\n图片2描述,图片2链接|\n\n以此类推,以 | 符号分割[/potos]')
});

$(document).on("click","#wmd-owo-button",function(){OwO_show();});
$(document).on("click","#wmd-sc-button",function(){sc_show();});
Expand Down
2 changes: 1 addition & 1 deletion footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<script src="https://cdn.jsdelivr.net/npm/[email protected]/jquery.pjax.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-lazyload/jquery.lazyload.min.js"></script>
<script src="<?php $this->options->themeUrl('JS/message.min.js'); ?>"></script>
<script src="<?php $this->options->themeUrl('JS/X.js'); ?>?v=2.3.1"></script>
<script src="<?php $this->options->themeUrl('JS/X.js'); ?>?v=2.3.2"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/prism.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/jquery.fancybox.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/tocbot.min.js"></script>
Expand Down
8 changes: 4 additions & 4 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<title><?php $this->archiveTitle(' &raquo; ', '', ' | '); ?><?php $this->options->title(); ?></title>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<link rel="stylesheet" href="<?php $this->options->themeUrl('CSS/G.css'); ?>?v=2.3.1" rel="stylesheet" />
<link rel="stylesheet" href="<?php $this->options->themeUrl('CSS/G.css'); ?>?v=2.3.5" rel="stylesheet" />
<link rel="stylesheet" href="<?php $this->options->themeUrl('CSS/message.css'); ?>" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/youranreus/G/CSS/shortcode.G.css" rel="stylesheet" />
<link rel="stylesheet" href="<?php $this->options->themeUrl('CSS/shortcode.G.css'); ?>" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/youranreus/G/CSS/OwO.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/prism.css" rel="stylesheet" />
<?php if ($this->options->enablenprogress == 1): ?>
Expand All @@ -23,7 +23,7 @@
window.QMSG_GLOBALS = {
DEFAULTS:{
showClose:false,
timeout:15000,
timeout:1000,
html: false
}
}
Expand Down Expand Up @@ -167,7 +167,7 @@
<script>
<?php echo $this->options->CustomJSh;?>
</script>
<link href="<?php $this->options->themeUrl('CSS/dark.css'); ?>" rel="<?php if($_COOKIE['night'] != '1'){echo 'alternate ';} ?>stylesheet" type="text/css" title="dark">
<link href="<?php $this->options->themeUrl('CSS/dark.css'); ?>?v=2.3.3" rel="<?php if($_COOKIE['night'] != '1'){echo 'alternate ';} ?>stylesheet" type="text/css" title="dark">
<link rel="icon" type="image/png" href="<?php $this->options->favicon(); ?>">
<link href="<?php $this->options->favicon(); ?>" rel="icon">
<link rel='dns-prefetch' href='//s.w.org'>
Expand Down
26 changes: 26 additions & 0 deletions lib/shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,29 @@ function shortcode_collapse( $atts, $content = '' ) {
return '<div class="collapse-box"><div class="collapse-title"><p>'.$args['title'].'</p></div><div class="collapse-content" style="display: none;">'.shortcodeContent($content).'</div></div>';
}
add_shortcode( 'collapse' , 'shortcode_collapse' );

function shortcode_photos( $atts, $content = '' ) {
$content = strip_tags($content);
$content = trim($content);
$content = str_replace(["\t", "\r\n", "\r", "\n", " "], '', $content);
$content = preg_replace('/\s+|\t+/u', '', $content);
$arr = explode('|',$content);
echo "<div class='photos'>";

foreach ($arr as $info) {
$info = explode(',',$info);
if($info[0]!=''){
echo "
<figure>
<div><img src='".$info[1]."' /></div>
<figcaption>".$info[0]."</figcaption>
</figure>
";
}

}
echo "</div>";

// return $string;
}
add_shortcode( 'photos' , 'shortcode_photos' );

0 comments on commit e442b7b

Please sign in to comment.