User:Mfaizsyahmi/ytlinkpopup3.js

function timeString(secs) { secs = Number(secs); var arr = new Array; if (secs >= 3600) arr.push( Math.floor(secs/3600) ); // hours arr.push( ('0'+ Math.floor(secs%3600/60) ).slice(-2) ); arr.push( ('0'+ secs%3600%60 ).slice(-2) ); return arr.join(":"); } function vidPopupAjax(vidID) { if ( $('.yt-vid-popup').length == 0) return false popupObj = $('.yt-vid-popup') // preliminary work - display loading text etc.	if ( $('a.watchlink',popupObj).length==0) $('.hlink', popupObj).wrap('') $('.info, .failed', popupObj).hide $('.loading', popupObj).show $('.thumbnail', popupObj).css('background',"url(http://images2.wikia.nocookie.net/dev/images/8/82/Facebook_throbber.gif) center no-repeat gray") $('.duration', popupObj).text('').hide // invoke the ajax function $.ajax({		type:"GET",		url:"http://gdata.youtube.com/feeds/api/videos/"+vidID+ "?v=2&fields=published,title,author,yt:hd,media:group(yt:duration),yt:statistics,yt:rating",		dataType:"xml",		success: function(ytdata) {			//popupObj = $('.yt-vid-popup')			var title = $('title', ytdata).text			var published = new Date( $('published',ytdata).text )			var author = $('author name', ytdata).text			var duration = Number( $('yt\\:duration', ytdata).attr('seconds') )			var hd = ( $('yt\\:hd', ytdata).length )?true:false			var views = $('yt\\:statistics', ytdata).attr('viewCount')			var rating = [ Number($('yt\\:rating', ytdata).attr('numLikes')), Number($('yt\\:rating', ytdata).attr('numDislikes')) ]			//var popupObj = $('.yt-vid-popup')			$('.thumbnail',popupObj).css('background','url(https://i1.ytimg.com/vi/'+vidID+'/default.jpg)')			$('.title', popupObj).text(title)			$('.author', popupObj).text(author) $('.published', popupObj).text( published.toDateString ) $('.viewcount', popupObj).text(views) $('.hd', popupObj).toggle(hd) $('.rating .likes', popupObj).text( rating[0] ) $('.rating .dislikes', popupObj).text( rating[1] ) $('.ratingBar .rating-like', popupObj).css('width', rating[0]/(rating[0]+rating[1])*100 +'%' ) $('.ratingBar .rating-dislike', popupObj).css('width', rating[1]/(rating[0]+rating[1])*100 +'%' ) $('.duration', popupObj).text( timeString(duration) ).show $('.watchlink', popupObj).attr({'href':'http://www.youtube.com/watch?v='+vidID,'title':title}) $('.info', popupObj).show //$('.loading', popupObj).hide },		error: function { //var popupObj = $('.yt-vid-popup') $('.failed', popupObj).show $('.loading, .info, .duration',popupObj).hide $('.thumbnail',popupObj).css('background','gray') $('.watchlink',popupObj).attr('href','#') },		complete: function { //cleans up UI			$('.loading', popupObj).hide }	}) } //test code hier $('.WikiaArticle').prepend(' ') $('.yt-popup-container').load('http://hitlerparody.wikia.com/wiki/Template:Ytlinkpopup?action=render .yt-vid-popup')//.hide $('a[href*="//www.youtube.com/watch?"]').wrap(' ')

$('.yt-link-container').unbind('mouseenter mouseleave').mouseenter( function(e) {	window.clearInterval(vidpopup_delay)

var pos = $(this).offset; var vidID = new RegExp("[\\?&]v=([^&#]*)").exec( $('a', this).attr('href') ) console.log(vidID[1], $(this).offset.left, $(this).offset.top) vidPopupAjax(vidID[1]) $('.yt-vid-popup').appendTo( $(this) )/*.css({		"position":"fixed", "left":(pos.left - $(window).scrollLeft ) +'px', "bottom":( $(window).scrollTop + $(window).height - pos.top ) +'px'		//"position":"fixed", "left":(pos.left - $(window).scrollLeft ) +'px', "top":(pos.top - $(window).scrollTop) +'px'	})*/.show vidPopupScroll }).mouseleave( function { vidpopup_delay = setInterval(function { $('.yt-vid-popup').hide },500); })

function vidPopupScroll { var pos = $('.yt-vid-popup').parent.offset $('.yt-vid-popup').css({		"position":"fixed", "left":(pos.left - $(window).scrollLeft ) +'px', "bottom":( $(window).scrollTop + $(window).height - pos.top ) +'px'		//"position":"fixed", "left":(pos.left - $(window).scrollLeft ) +'px', "top":(pos.top - $(window).scrollTop) +'px'	}) } $(window).scroll(vidPopupScroll).resize(vidPopupScroll);