Skip to content

Instantly share code, notes, and snippets.

@xboston
Created April 16, 2014 13:28
Show Gist options
  • Save xboston/10875065 to your computer and use it in GitHub Desktop.
Save xboston/10875065 to your computer and use it in GitHub Desktop.
Очеловечивание ссылок на медиа-файлы
// PRIVATE очеловечиваем ссылки на медиа-файлы
this._parseMedia = function(){
var _img_class = '';
// подсвечиваем все ссылки
$message = $('#chat_body div:last .message');
$message.html( ' '+$message.html()+' ' );
$message.html($message.html().replace(/(\s|^)(https?:\/\/\S+)/gi,"$1<a href=\"$2\" target=\"_blank\">$2</a>"));
// определяем расширение куда ведут ссылки в сообщении
$('#chat_body div:last span.message a').each(function(){
try{
$(this).data('extension', $(this)[0].href.match(/\.(.{1,4})$/)[1]);
}catch(e){};
});
// для ссылок ведущих на изображение выводим превью
$('#chat_body div:last span.message a:regex(data:extension, png|jpg|jpeg|gif)').each(function() {
_img_class = this.href.indexOf('images/smiles')>0 ? '':'images_from_message';
$(this).html($('<img/>').attr('src',this.href).attr('class', _img_class));
_img_class = '';
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment