$(function(){
BB.build_share_buttons();
// Setup ajax-loading box
$("#ajax-loading").ajaxStart(function(){
$("#ajax-error").hide();
$(this).show();
ajax.setStatusBoxPosition($(this));
});
$("#ajax-loading").ajaxStop(function(){ $(this).hide(); });
// Setup ajax-error box
$("#ajax-error").ajaxError(function(req, xml){
var status = xml.status;
var text = xml.statusText;
if (status == 200) {
status = '';
text = 'invalid data format';
}
$(this).html(
"Ajax error in: <i>"+ ajax.url +"</i><br /><b>"+ status +" "+ text +"</b>"
).show();
ajax.setStatusBoxPosition($(this));
});
// Bind ajax events
$('var.ajax-params').each(function(){
var params = $.evalJSON( $(this).html() );
params.event = params.event || 'dblclick';
ajax.params[params.id] = params;
$("#"+params.id).bind(params.event, ajax.callInitFn);
if (params.event == 'click' || params.event == 'dblclick') {
$("#"+params.id).addClass('editable-container');
}
});
});
BB.build_share_buttons = function ()
{
if ( !$('#soc-container').length ) {
return;
}
var socials = {};
socials['Facebook'] = [ 0, 'http://www.facebook.com/sharer.php?u={URL}&t={TITLE}'];
socials['Twitter'] = [-18, 'http://twitter.com/share?url={URL}&text={TITLE}'];
socials['Вконтакте'] = [-36, 'http://vkontakte.ru/share.php?url={URL}'];
socials['LiveJournal'] = [-54, 'http://www.livejournal.com/update.bml?event={URL}&subject={TITLE}'];
socials['Google +1'] = [-72, 'https://plus.google.com/share?url={URL}'];
var $container = $('#soc-container');
var $buttons = $('<div class="soc-buttons"></div>');
var share_url = encodeURIComponent( $container.data('share_url') );
var share_title = encodeURIComponent( $container.data('share_title') );
$.each(socials, function(soc_name,params){
var btn_title = 'Опубликовать ссылку в '+ soc_name;
var bg_position = params[0] +'px';
var soc_url = params[1].replace('{URL}', share_url).replace('{TITLE}', share_title);
$('<span></span>')
.attr('title', btn_title)
.css('background-position', bg_position)
.click(function(){
window.open(soc_url, '_blank', 'width=800,height=550,top=50,left=100,location=yes,scrollbars=yes');
})
.appendTo($buttons);
});
$buttons.appendTo($container);
}