Last active
November 29, 2017 22:39
-
-
Save kasimi/94e8bc6ff112833238193aeb71d88bde to your computer and use it in GitHub Desktop.
Making Magic OGP Parser compatible with mChat for phpBB 3.2
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"; | |
function parseOgp($container) { | |
$container.find('.postlink').each(function() { | |
var ogpdata = $(this).data('ogp'); | |
if (ogpdata.title !== undefined) { | |
var block = '<div class="ogpblock">'; | |
if (ogpdata.image !== undefined) { | |
block += '<img src="' + ogpdata.image + '"/>'; | |
} | |
block += '<div class="ogptext"><h4>' + ogpdata.title + '</h4>' + ogpdata.description + '</div></div>'; | |
$(this).html(block); | |
$(this).addClass('ogplink'); | |
$(this).removeAttr('data-ogp'); | |
} | |
}); | |
} | |
parseOgp($('.content')); | |
if (typeof mChat === 'object') { | |
$(mChat).on('mchat_add_message_before', function(e, data) { | |
parseOgp(data.message); | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment