Update widget4.

This commit is contained in:
BoHung Chiu 2021-05-20 09:52:49 +08:00
parent 4dd8183a06
commit d788e94c47
2 changed files with 54 additions and 33 deletions

View File

@ -32,46 +32,54 @@
</li> </li>
</ul> </ul>
</div> </div>
<style type="text/css">
[data-subpart-id="{{subpart-id}}"] .bullseye{
overflow: hidden;
}
</style>
<script> <script>
var lilength = $('.widget-announcement-4 li.w-annc__item').length;
function combineul(){ function combineul(){
for(var i=1;i<$('.widget-announcement-4 ul.w-annc__list').length;i++) var parents = $('[data-subpart-id=\"{{subpart-id}}\"] ul.w-annc__list').parent();
$('.widget-announcement-4 ul.w-annc__list').eq(0).find('>li').eq(-1).after($('.widget-announcement-4 ul.w-annc__list').eq(i).html()); parents.each(function(i,v){
var ullength = $('.widget-announcement-4 ul.w-annc__list').length; for(var i=1;i<$(v).find('ul.w-annc__list').length;i++)
for(var i = 1;i < ullength;i++) $(v).find('ul.w-annc__list').eq(0).find('>li').eq(-1).after($(v).find('ul.w-annc__list').eq(i).html());
$('.widget-announcement-4 ul.w-annc__list').eq(-1).remove(); var ullength = $(v).find('ul.w-annc__list').length;
for(var i = 1;i < ullength;i++)
$(v).find('ul.w-annc__list').eq(-1).remove();
})
}; };
var num;
var lilength = $('[data-subpart-id=\"{{subpart-id}}\"] li.w-annc__item').length;
function reorganize(num){ function reorganize(num){
combineul(); combineul();
for(var i=1;i< Math.ceil(lilength/num);i++){ var parents = $('[data-subpart-id=\"{{subpart-id}}\"] ul.w-annc__list').parent();
$('.widget-announcement-4 ul.w-annc__list').eq(-1).after('<ul class="w-annc__list row" data-level="0" data-list="announcements"></ul>') parents.each(function(i,v){
var lihtml=""; var lilength = $(v).find('li.w-annc__item').length;
if(i != (Math.ceil(lilength/num)-1)){ var ul_length = Math.ceil(lilength/num);
for(var j=0;j<num;j++) for(var ii=1;ii< ul_length;ii++){
lihtml += "<li class='w-annc__item col-md-4'>"+$('.widget-announcement-4 li.w-annc__item').eq(i*num+j).html()+"</li>" var clone_ul = $(v).find('ul.w-annc__list').eq(-1).clone();
}else{ clone_ul.empty();
for(var j=0;j< lilength - num *(Math.ceil(lilength/num)-1) ;j++) clone_ul.removeClass("active");
lihtml += "<li class='w-annc__item col-md-4'>"+$('.widget-announcement-4 li.w-annc__item').eq(i*num+j).html()+"</li>" clone_ul.css("display","");
}; $(v).find('ul.w-annc__list').eq(-1).after(clone_ul.prop("outerHTML"));
$('.widget-announcement-4 ul.w-annc__list').eq(-1).html(lihtml); var lihtml="";
}; if(ii != (ul_length-1)){
if(Math.ceil(lilength/num) != 1 ) for(var j=0;j<num;j++){
for(var i=0;i< lilength -num ; i++ ) lihtml += $(v).find('li.w-annc__item').eq(ii*num+j).prop("outerHTML");
$('.widget-announcement-4 ul.w-annc__list').eq(0).find("li.w-annc__item").eq(num).remove(); };
}else{
for(var j=0;j< lilength - num *(ul_length-1) ;j++){
lihtml += $(v).find('li.w-annc__item').eq(ii*num+j).prop("outerHTML");
};
};
$(v).find('ul.w-annc__list').eq(-1).html(lihtml);
}
if(ul_length != 1 )
for(var i=0;i< lilength -num ; i++)
$(v).find('ul.w-annc__list').eq(0).find("li.w-annc__item").eq(num).remove();
})
$('.widget-announcement-4 ul.w-annc__list >li').css('width','calc('+100/num+'% - '+20/16+'em)'); //20px=>li的margin $('.widget-announcement-4 ul.w-annc__list >li').css('width','calc('+100/num+'% - '+20/16+'em)'); //20px=>li的margin
}; };
$(document).ready(function(){
if($(window).width()>1024){
reorganize(3);
num=3;
}else if($(window).width()>576){
reorganize(2);
num=2;
}else{
reorganize(1);
num=1;
}
});
$(window).resize(function(){ $(window).resize(function(){
if($(window).width()>1024){ if($(window).width()>1024){
reorganize(3); reorganize(3);
@ -84,4 +92,16 @@
num=1; num=1;
} }
}) })
$(document).ready(function(){
if($(window).width()>1024){
reorganize(3);
num=3;
}else if($(window).width()>576){
reorganize(2);
num=2;
}else{
reorganize(1);
num=1;
}
})
</script> </script>

View File

@ -164,6 +164,7 @@
}, },
{ {
"filename" : "annc_widget4", "filename" : "annc_widget4",
"force_cover": "true",
"name" : { "name" : {
"zh_tw" : "4. 三欄圖文 ( 模組標題, 圖片, 狀態, 日期, 類別, 標題, 副標題 )", "zh_tw" : "4. 三欄圖文 ( 模組標題, 圖片, 狀態, 日期, 類別, 標題, 副標題 )",
"en" : "4. 3-Column Standard Image + Text (widget-title, image, status, postdate, category, title, subtitle)" "en" : "4. 3-Column Standard Image + Text (widget-title, image, status, postdate, category, title, subtitle)"