Tuesday, September 25, 2018

News Announcement Slider webpart

News announcement slider:
-------------------------------------


$(document).ready(function(){

  //$('#s4-bodyContainer').css({"padding-bottom":"0px !important",});

  GetAnnouncements();
 
  var url = _spPageContextInfo.webAbsoluteUrl +"/Lists/Announcements/AllItems.aspx";
  $('#NewsAnn').attr("href",url);
 
 

 


});



function GetAnnouncements() {

var listname = 'Announcements';

var url ="/_api/Web/Lists/GetByTitle('"+listname +"')/Items?$select=Title,Body,BodyText,IsActive&$filter=IsActive eq 1&$orderby=Created desc&$top=5";

    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
            //console.log(data.d.results);
            IterateAnnouncementItems(data.d.results);
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });
}
var resultNewsArr = [];
function IterateAnnouncementItems(result)
{

  if(result.length > 0)
  {
     resultNewsArr = result;
     var content="<div class='news_announcements'>";
     for(var i=0 ; i<result.length; i++)
{
     var body = result[i].BodyText;
     if(body.length > 580)
     {
        body = result[i].BodyText.substring(0, 580)+"</div>";
     }


         content +="<div><div class='ann_title'>"+result[i].Title+"</div>";
         content +="<div class='ann_desc'>"+body+"</div></br>";
         content +="<div class='more_list ann_more'><a href='#' onclick='ShowPopup("+i+")'>More <span>...</span></a></div>";

         content +="</div>";
       
     }
      content +="</div>";
     
      $('#announcements').append(content);
     
     
     
      $(function(){
$('.news_announcements').bxSlider({
    controls: false
});


});
  }

}


function ShowPopup(newsIndex)
{
 var bodyHTML = resultNewsArr[newsIndex].BodyText;
 var title = resultNewsArr[newsIndex].Title;
 var newsHtml = "<div><b>"+title+"</b></div><br>" + bodyHTML;

 $('#NewAnnouncement').empty();
 $('#NewAnnouncement').append(newsHtml);
 $('.hover_bkgr_fricc').show();
}


$(document).ready(function(){
$('.hover_bkgr_fricc').click(function(){
// $('.hover_bkgr_fricc').hide();
});
$('.popupCloseButton').click(function(){
$('.hover_bkgr_fricc').hide();
});

});

No comments:

Post a Comment