(function($) { $.textMetrics = function(el) { var h = 0, w = 0; var div = document.createElement('div'); document.body.appendChild(div); $(div).css({ position: 'absolute', left: -1000, top: -1000, display: 'none' }); $(div).html($(el).html()); var styles = ['font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing']; $(styles).each(function() { var s = this.toString(); $(div).css({ s: $(el).css(s) }); }); h = $(div).outerHeight(); w = $(div).outerWidth(); $(div).remove(); var ret = { height: h, width: w }; return ret; } })(jQuery); function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt){ // The index() method calculates the index from a // given index who is out of the actual item range. var idx = carousel.index(i, mycarousel_itemList.length); carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1])); } function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt){ carousel.remove(i); } function startCarousel(){ // Since we get all URLs in one file, we simply add all items // at once and set the size accordingly. jQuery.ajax({ dataType: 'jsonp', url: LATEST_DATA_WIDGET_SERVLET_URL+"?list=urls&callback=?", // this is taken from frontend success:function(json){ if(json.status=="ok"){ mycarousel_itemList=[]; for(var i=0;i0){ initCarousel(mycarousel_itemList.length-4); jQuery(".pubsub").show(); }else{ jQuery(".pubsub").hide(); setTimeout(startCarousel,tryToStartTime); } }else{ jQuery(".pubsub").hide(); setTimeout(startCarousel,tryToStartTime); } }, error:function(){ } }); }; function callForFreshData(){ if(iDetector && !iDetector.isIdle){ jQuery.ajax({ dataType: 'jsonp', url: LATEST_DATA_WIDGET_SERVLET_URL+"?list=urls&callback=?", // this is taken from frontend success:function(json){ if(json.status=="ok"){ var n = mycarousel_itemList.length; // push new values at the end of the list for(var i=0;ilineLength){ var allowedLengthOfUrl = lineLength - labelStrNoUrl.length; if(domainNoHttp.length>allowedLengthOfUrl){ domainNoHttp = domainNoHttp.substring(0,allowedLengthOfUrl-4); } escapedUrlNoHttp = domainNoHttp +"..."+ escapedUrlNoHttp.substring( escapedUrlNoHttp.length -( allowedLengthOfUrl - domainNoHttp.length - 3) , escapedUrlNoHttp.length ); } if(escapedUrlNoHttp.indexOf("http://")==-1){ escapedUrlNoHttp = escapedUrlNoHttp.replace(domainNoHttp,''+domainNoHttp+''); }else{ escapedUrlNoHttp = escapedUrlNoHttp.replace(domainNoHttp.replace(/http:\/\//,""),''+domainNoHttp.replace(/http:\/\//,"")+''); } var ret = '
'+ created+' '+ ''+triplesNo+' triples '+ escapedUrlNoHttp+ '
'; /* jQuery('body').append('
'+ret+'
'); console.log( jQuery.textMetrics(jQuery("#test")).width ); jQuery('#test').remove(); for future change the way the width of the string is calculated by using jQuery.textMetrics which calculates the width in pixels We can not use monotype font (look ugly) */ return ret; }else{ return '

Sorry we are currently experiencing server communication error

' } } function initCarousel(){ jQuery('#jcarousel').jcarousel({ wrap: 'circular', vertical: true, scroll: scrollBy, start:97, // put this here to scroll down by first visible elements (prevent to show the latest first) // here should be 97 but it does not work in chrome animation:"fast", itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback}, itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}, initCallback:function(){ jQuery(".jcarousel-prev").hide(); jQuery(".jcarousel-next").hide(); setTimeout(makeColumnsEqual,200); setTimeout(scrollCarousel,2000); } }); } function makeColumnsEqual(){ //var tallestColumn = equalHeight(jQuery("div.equalColumn")); //var entriesBoxH = tallestColumn-70; //jQuery(".blogEntriesBox").css("height",entriesBoxH+"px"); } function scrollCarousel(){ if(scroll==true){ jQuery(".jcarousel-prev").click(); } var time = randomXToY(scrollTimeMin,scrollTimeMax); scrollTimeout = setTimeout(scrollCarousel,time); } function randomXToY(minVal,maxVal,floatVal){ var randVal = minVal+(Math.random()*(maxVal-minVal)); var ret = typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal); return ret; } function refreshDoscNumber(){ if(iDetector && !iDetector.isIdle){ jQuery.ajax({ url:"search/stats", dataType:"json", success:function(json){ if(json.status=="ok"){ jQuery(".last24").text(json.last24words); jQuery(".totalNo").text(json.totalwords); jQuery(".documentNumberTotal").slideDown(); if(json.last24 > json.threshold){ jQuery("a.latestData").slideDown(); } } setTimeout(refreshDoscNumber,freshDoscNoCallTime); },error:function(a,b,c){ setTimeout(refreshDoscNumber,freshDoscNoCallTime); } }); }else{ setTimeout(refreshDoscNumber,freshDoscNoCallTime); } } //globals used by xmpp widget var freshDataCallTime = 20*1000; // 20 sec ~ 15 entries - refresh xmpp data var freshDoscNoCallTime= 60*1000; // 60 sec every minute refresh documents number var tryToStartTime = 10*1000; var scrollTimeMin = 1000; var scrollTimeMax = 3000; var mycarousel_itemList = []; var scroll = true; var scrollBy=1; var scrollTimeout=null; var triples = 0; var documents = 0; var iDetector = null; // end of globals used by xmpp widget jQuery(document).ready(function() { jQuery.fx.interval = 40; // set up a global idle detector iDetector = new IdleDetector({ inactivityTimeInSec:60, // detect when browser is idle for more then 60 sec idleCallback:function(){ //console.log("idle"); // here put code which should be executed when user become inactive scroll=false; clearTimeout(scrollTimeout); }, backToActivityCallback:function(){ //console.log("activity starts calling fresh data"); // here put code which should be executed when user become active again refreshDoscNumber(); callForFreshData(); scroll=true; scrollCarousel(); } }); // end of set up idle detector //set up a xmpp widget startCarousel(); refreshDoscNumber(); callForFreshData(); jQuery("#jcarousel").hover( function(){ scroll=false; jQuery(".jcarousel-prev").show(); jQuery(".jcarousel-next").show(); }, function(){ scroll=true; jQuery(".jcarousel-prev").hide(); jQuery(".jcarousel-next").hide(); } ); // end of set up xmpp widget });