Refactor pleer.com embedding

This commit is contained in:
isqua 2015-01-29 14:46:46 +03:00
parent 068c461070
commit 21cab163d5

View file

@ -972,82 +972,23 @@ function set_posts_count_label() {
} }
function parse_pleercom_links(current_options) { function parse_pleercom_links(current_options) {
if (current_options.is('option_embedding_pleercom_nokita_server')) { $('.post-content a').each(function(num, link) {
parse_pleercom_links_nokita(); var $link = $(link);
} else { var href = link.href;
parse_pleercom_links_ajax(current_options); var matches = href.match(new RegExp('^https?:\\/\\/pleer\\.com\\/tracks\\/([0-9a-z]+)', 'i'));
}
}
/**
* @deprecated since 1.19
*/
function parse_pleercom_links_nokita() {
$('.post-content a').each(function(num, obj) {
var href = obj.href;
var n = null;
if (n = href.match(new RegExp('^https?:\\/\\/pleer\\.com\\/tracks\\/([0-9a-z]+)', 'i'))) { if (matches) {
var player = document.createElement('audio'); trackHref = 'http://embed.pleer.com/normal/track?id=' + matches[1] + '&t=grey';
$(player).attr({
'src': 'https://api.kanaria.ru/point/get_pleer_file.php?id=' + n[1],
'controls': 'controls',
'preload': 'none'
});
var player_div = document.createElement('div'); $link.before('<object width="578" height="60"><param name="movie" value="' + trackHref + '"></param>' +
$(player_div).addClass('embeded_audio').addClass('embeded_audio_' + n[1]); '<embed src="' + trackHref + '" type="application/x-shockwave-flash" width="578" height="60">' +
player_div.appendChild(player); '</embed></object>');
obj.parentElement.insertBefore(player_div, obj); if ( ! current_options.is('option_embedding_pleercom_orig_link')) {
} $link.remove();
});
}
function parse_pleercom_links_ajax(current_options) {
$('.post-content a').each(function(num, obj) {
var href = obj.href;
var n = null;
if (n = href.match(new RegExp('^https?:\\/\\/pleer\\.com\\/tracks\\/([0-9a-z]+)', 'i'))) {
var player_div = document.createElement('div');
$(player_div).addClass('embeded_audio').addClass('embeded_audio_' + n[1]);
$(obj).addClass('pleercom_original_link_'+n[1]);
obj.parentElement.insertBefore(player_div, obj);
create_pleercom_ajax(n[1], current_options);
}
});
}
function create_pleercom_ajax(id, current_options) {
$ajax({
'url': 'https://pleer.com/site_api/files/get_url',
'type': 'post',
'postdata': 'action=download&id=' + id,
'dont_set_content_type': true,
'pleer_id': id,
'headers': [['Accept', '*'], ['Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8']],
'success': function(a) {
var answer = JSON.parse(a);
var player = document.createElement('audio');
// @todo Проверять существование track_link
$(player).attr({
'src': answer.track_link,
'controls': 'controls',
'preload': 'auto'
});
$('.embeded_audio_' + this.settings.pleer_id)[0].appendChild(player);
if (current_options.is('option_embedding_pleercom_orig_link', false)){
$('.pleercom_original_link_'+this.settings.pleer_id).hide();
} }
},
'error': function() {
console.log('Can not get pleer.com url');
setTimeout(new Function('create_pleercom_ajax("' + this.settings.pleer_id + '");'), 1000);
} }
}); });
} }
// Проставляем теги у постов // Проставляем теги у постов