<script type="text/javascript">
(function () {
var doc = document;
var body = doc.body;
var xhr_done_auth = true;
doc.addEventListener ? window.addEventListener( 'load', init, false ) : window.attachEvent( 'onload', init );
function init () {
doc = document;
body = doc.body;
var el_auth = doc.getElementById( 'xt_auth_container' );
doc.addEventListener ? el_auth.addEventListener( 'click', hook_xhr_action, false ) : el_auth.attachEvent( 'onclick', hook_xhr_action );
if ( 'backgroundSize' in doc.body.style ) {
if ( window.devicePixelRatio && window.devicePixelRatio > 1 ) {
el_auth.className += ' xt_auth_icon_enchanted';
}
}
}
// bind xhr links
function hook_xhr_action ( e ) {
var e = e || window.event;
var target = e.target || e.srcElement;
target = target.className == 'xt_auth_icon' ? target.parentNode : target;
if ( target.getAttribute( 'data-xhr' ) ) {
var url = target.href;
url = url + (url.indexOf( '?' ) == -1 ? '?via_ajax=1' : '&via_ajax=1');
load_data({ url: url, xhr_done: xhr_done_auth, callback: handle_xhr_response });
(e.preventDefault) ? e.preventDefault() : e.returnValue = false; return false;
}
}
function handle_xhr_response ( xhr ) {
function handle_error ( xhr ) {
window.location.href = window.location.href;
}
function handle_success ( xhr ) {
var wrapper = document.getElementById( 'xt_auth_container' );
var tmp_class = wrapper.className;
var current_action = xhr.response.split( ';' )[1];
var actions = {
bookmark: 'xt_auth_action_star_active',
vote: 'xt_auth_action_rate_active',
subscribe: 'xt_auth_action_subscribe_active'
};
for ( key in actions ) {
if ( !actions.hasOwnProperty( key ) ) continue;
if ( current_action.indexOf( key ) == -1 ) continue;
wrapper.className = current_action.indexOf( 'un' ) == -1 ? tmp_class + ' ' + actions[key] : tmp_class.replace( (' ' + actions[key]), '' );
}
}
xhr.response = xhr.response ? xhr.response : xhr.responseText;
(xhr.status != 200 || xhr.response.indexOf( 'ERR;') != -1 ) ? handle_error(xhr) : handle_success(xhr);
}