Created
January 19, 2014 06:30
-
-
Save barisusakli/8501190 to your computer and use it in GitHub Desktop.
render url to canvas, not working good enough for general use, uses html2canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
"use strict"; | |
$(document).ready(function() { | |
$('<iframe frameborder="0" scrolling="no" id="myFrame" width=1024 height=768 class="hidden"></iframe>') | |
.appendTo('body'); | |
$('<div id="canvas-container" class="linkcheck-preview hidden"></div>').appendTo('body'); | |
}); | |
$(document).bind('DOMNodeInserted', function(event) { | |
if(!$('.topic').length || $(event.target).hasClass('linkcheck-plugin')) { | |
return; | |
} | |
verifyLinks(); | |
$('.post-content a').off('mouseenter').on('mouseenter', function(e) { | |
var link = $(this); | |
socket.emit('topics.renderLinkPreview', $(this).attr('href'), function(err, html) { | |
var jqFrame = $('#myFrame'); | |
link.off('mouseleave').on('mouseleave', function() { | |
$('#canvas-container').addClass('hidden'); | |
}); | |
var iframe = jqFrame[0]; | |
jqFrame.removeClass('hidden'); | |
var iframedoc = iframe.contentDocument || iframe.contentWindow.document; | |
iframedoc.body.innerHTML = html; | |
//setTimeout(function() { | |
html2canvas(iframedoc.body, { | |
onrendered: function(canvas) { | |
jqFrame.addClass('hidden'); | |
$(canvas).addClass('linkcheck-canvas'); | |
$('#canvas-container').html('').append(canvas).removeClass('hidden'); | |
$('#canvas-container').css({top: link.offset().top + 20, left:link.offset().left + link.outerWidth()}); | |
}, | |
width: 1024, | |
height: 768 | |
}); | |
//}, 10); | |
}); | |
}); | |
}); | |
function verifyLinks() { | |
$('.post-content a').each(function(index, element) { | |
var link = $(element); | |
if(link.attr('class') || link.attr('done')) { | |
return; | |
} | |
link.attr('done', 1); | |
socket.emit('topics.checkLink', link.attr('href'), function(err, result) { | |
if(!result) { | |
$('<i class="fa fa-chain-broken linkcheck-plugin"></i>').insertBefore(link); | |
} | |
}); | |
}); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment