/* jQuery News Viewer Plugin for WYSIWYG Web Builder 14 - Copyright Pablo Software solutions 2018 - http://www.wysiwygwebbuilder.com */
(function(d){function m(d){return 10>d?"0"+d:d}function h(e,a,b,c,n,g){a=d("").attr("href",a).attr("target",g.target).html(b);a=d("
").append(a);if(g.includeDate){b=new Date(c);if("twitter"==g.dateFormat)c=parseInt(((new Date).getTime()-b.getTime())/1E3),c=60>c?"less than a minute ago":120>c?"about a minute ago":3600>c?parseInt(c/60).toString()+" minutes ago":7200>c?"about an hour ago":86400>c?"about "+parseInt(c/3600).toString()+" hours ago":172800>c?"1 day ago":parseInt(c/86400).toString()+
" days ago";else{var p="January February March April May June July August September October November December".split(" "),t="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),f=b.getFullYear(),q=f.toString().substring(2),l=b.getMonth()+1,w=b.getDate(),h=b.getHours(),k=b.getMinutes(),r=b.getSeconds();c=g.dateFormat;c=c.replace("hh",m(h));c=c.replace("h",h);c=c.replace("nn",m(k));c=c.replace("n",k);c=c.replace("ss",m(r));c=c.replace("s",r);c=c.replace("yy",f);c=c.replace("y",q);c=
c.replace("mm",m(l));c=c.replace("m",l);c=c.replace("dd",m(w));c=c.replace("d",w);c=c.replace("DD","X1");c=c.replace("D","X2");c=c.replace("MM","X3");c=c.replace("M","X4");c=c.replace("X1",t[b.getDay()]);c=c.replace("X2",t[b.getDay()].substring(0,2));c=c.replace("X3",p[l-1]);c=c.replace("X4",p[l-1].substring(0,3))}c=d("").addClass("publication-date").text(c)}else c=d("");n=d("").addClass("summary").html(n);a=d('').addClass("headline").append(a,
c,n,"");0!=g.animation&&1!=g.animation&&6!=g.animation&&7!=g.animation||"rotate"!=g.mode||a.css({opacity:0});0==g.sortOrder?a.appendTo(e):a.prependTo(e)}function k(e,a){var b="#"+e.attr("id")+" .headline";if("default"==a.mode)e.css("overflow-y","auto"),d(b).css("position","relative"),d(b).css("height","auto"),d(b).css("top","0");else if("rotate"==a.mode){var c=0,n=0,g=0,p=e.css("padding-left");if(0==a.animation||1==a.animation||6==a.animation||7==a.animation)d(b).eq(c).css({opacity:1});else if(2==
a.animation||3==a.animation)g="100%",3==a.animation&&(g="-100%"),d(b).css("left",g),d(b).eq(c).css("left",p);else if(4==a.animation||5==a.animation)d(b).eq(c).css("top",p),g="100%",5==a.animation&&(g="-100%");var t=d(b).length,f,q=!1,l={},h={},k=function(){q||(q=!0,f=!1,c=(n+1)%t,0==a.animation||1==a.animation?(l={opacity:0},h={opacity:1}):2==a.animation||3==a.animation?(l={left:"100%"==g?"-100%":"100%"},h={left:p}):4==a.animation||5==a.animation?(l={top:"100%"==g?"-100%":"100%"},h={top:p}):6==a.animation?
(l={opacity:0,scale:5},h={opacity:1,scale:1},d(b).eq(n).animate({scale:0},0)):7==a.animation&&(l={opacity:0,rotate:0,scale:0},h={opacity:1,rotate:1440,scale:1},d(b).eq(n).animate({rotate:0},0)),d(b).eq(n).animate(l,a.animationDuration,function(){2==a.animation||3==a.animation?d(this).css("left",g):4==a.animation||5==a.animation?d(this).css("top",g):6==a.animation&&d(this).animate({scale:0},0)}),d(b).eq(c).animate(h,a.animationDuration,function(){q=!1;f||(f=setTimeout(k,a.pause))}),n=c)};f||(f=setTimeout(k,
a.pause));e.hover(function(){clearTimeout(f);f=!1},function(){f||(f=setTimeout(k,250))})}else if("scroller"==a.mode)d(b).css("position","relative"),d(b).css("height","auto"),d(b).css("top","0"),a.line_count=e.height(),a.rotate=!0,e.hover(function(){a.rotate=!1},function(){a.rotate=!0}),x(e,a);else if("paginate"==a.mode){e.css("overflow-y","auto");d(b).css("position","relative");d(b).css("height","auto");d(b).css("top","0");var m=0,r=function(){e.find(".headline").hide().slice(m*a.numPerPage,(m+1)*
a.numPerPage).show()},v=e.find(".headline").length;v=Math.ceil(v/a.numPerPage);for(var y=d(''),u=0;u').text(u+1).bind("click",{newPage:u},function(a){m=a.data.newPage;r();d(this).addClass("active").siblings().removeClass("active")}).appendTo(y).addClass("clickable");y.prependTo(e).find("span.page-number:first").addClass("active");r()}else"ticker"==a.mode&&(d(b).css("position","relative"),d(b).css("height","auto"),d(b).css("top","0"),
z(e,a))}function x(e,a){var b=a.container.height();a.line_count+=a.rotate?-2:0;d("p",e).css("top",a.line_count);a.line_count<-b-20&&(a.line_count=e.height());setTimeout(function(){x(e,a)},a.speed)}function z(d,a){d.find(".headline:last").clone().prependTo(d).css("display","none");d.find(".headline:first").fadeIn(1E3).slideDown(500);d.find(".headline:last").fadeOut().remove();setTimeout(function(){z(d,a)},a.pause)}d.fn.newsviewer=function(e){var a=d.extend({animation:0,animationDuration:500,dataSource:"local",
dateFormat:"yy/mm/dd",facebook_access_token:"",facebook_post_types:["status","photo","link"],includeDate:!0,maxItems:10,mode:"default",numPerPage:1,param:null,pause:5E3,sortOrder:0,speed:50,target:"_self",url:null},e);return this.each(function(){d.newsviewer(d(this),a)})};d.newsviewer=function(e,a){e.empty();"scroller"==a.mode&&d("").css("position","relative").appendTo(e);a.container=e;"scroller"==a.mode&&(a.container=d("p",e));if("local"==a.dataSource){if(null!=a.param)for(var b=0;b").attr({src:"wb.newsviewer.gif",alt:"Loading. Please wait."}).addClass("news-wait").appendTo(e);d.get(a.url,function(b){c.remove();1==d("feed",b).length?d("feed entry",b).each(function(c,b){if(c>=a.maxItems)return!1;h(a.container,d("link",this).text(),d("title",this).text(),d("updated",this).text(),d("content",this).text(),a)}):d("rss item",b).each(function(c,b){if(c>=a.maxItems)return!1;
h(a.container,d("link",this).text(),d("title",this).text(),d("pubDate",this).text(),d("description",this).text(),a)});k(e,a)})}else"twitter"==a.dataSource?(c=d("").attr({src:"wb.newsviewer.gif",alt:"Loading. Please wait."}).addClass("news-wait").appendTo(e),d.getJSON(a.url,function(b){c.remove();d.each(b,function(d,c){var b=c.created_at.split(" ");b=Date.parse(b[1]+" "+b[2]+", "+b[5]+" "+b[3]);var f=c.text.replace(/((http|https):\/\/\S+)/g,'$1');f=f.replace(/@(\w+)/g,
'@$1');h(a.container,"http://twitter.com/"+a.param,f,b,"",a)});k(e,a)})):"twittersearch"==a.dataSource?(c=d("").attr({src:"wb.newsviewer.gif",alt:"Loading. Please wait."}).addClass("news-wait").appendTo(e),d.getJSON(a.url,function(b){c.remove();d.each(b.statuses,function(d,c){var b=c.created_at.split(" ");b=Date.parse(b[1]+" "+b[2]+", "+b[5]+" "+b[3]);var f=c.text.replace(/(http:\/\/\S+)/g,'$1');f=f.replace(/@(\w+)/g,
'@$1');h(a.container,"http://www.twitter.com/"+c.user.screen_name,''+f,b,"",a)});k(e,a)})):"facebook"==a.dataSource?(c=d("").attr({src:"wb.newsviewer.gif",alt:"Loading. Please wait."}).addClass("news-wait").appendTo(e),b="https://graph.facebook.com/"+a.param,b=b+"/feed?access_token="+a.facebook_access_token,b=b+"&limit="+a.maxItems,d.getJSON(b+
"&callback=?",function(b){c.remove();d.each(b.data,function(c,b){if(0<=d.inArray(b.type,a.facebook_post_types)){var e=new Date((b.created_time||"").replace(/-/g,"/").replace(/TZ/g," "));(new Date).getTime();e.getTime();var f="",g=a.param;null!=b.from&&(g=b.from.name);void 0!=b.message?f=b.message:void 0!=b.story&&(f=b.story);"link"==b.type&&-1==f.indexOf(b.link)&&(""!=f&&(f+="
"),f+=b.link);f=f.replace(/\b((http|https):\/\/\S+)/g,'$1');"photo"==b.type&&(f+='");h(a.container,"http://www.facebook.com/profile.php?id="+a.param,g,e,f,a)}});k(e,a)})):"flickr"==a.dataSource&&(c=d("").attr({src:"wb.newsviewer.gif",alt:"Loading. Please wait."}).addClass("news-wait").appendTo(e),b="http://api.flickr.com/services/feeds/photos_public.gne?format=json&",null!=a.param&&(b+=a.param,b+="&"),d.getJSON(b+"jsoncallback=?",function(b){c.remove();
d.each(b.items,function(b,c){var e=d("").attr("href",c.link).attr("target",a.target).text(c.title);e=d("").append(e);var f=d("").addClass("publication-date").text(c.author.split("(")[1].replace(")","")),g=d("").attr("src",c.media.m);d("").addClass("headline").append(e,f,g,"").appendTo(a.container);if(b==a.maxItems)return!1});k(e,a)}))}})(jQuery);