/**
 * Created by wangmh on 2017/6/28.
 */
var app = {
    loading : function(is, position) {
        app.isLoading = is;
        toastr.clear();
        $('#loading').css('display', is ? 'block' : 'none');
        is && position && ($('#loading').addClass(position));
    },
    init : function () {
        app.logout();
    },
    error : function(message, title, position) {
        toastr.clear();
        toastr.error(message, title, {
            positionClass : 'toast-' + (position || 'top-center')
        });
        window.location.href="http://www.ubtob.com";
    },
    logout : function(){
        app.logoutOther();
        setTimeout("app.returnHref()", 200);
        // window.location.href = data.content.returnUrl || 'http://www.ubtob.com';
    },
    returnHref: function () {
        var url = $('input[name="returnURL"]').val();
        window.location.href = url ? url + '?returnURL=' + url : 'http://www.ubtob.com';
    },
    // 跨域登出
    logoutOther: function () {
        var logoutUrls = $('input[name="logoutUrls"]').val().replace("[","").replace("]","").split(",");
        for (var i=0;i<logoutUrls.length;i++) {
            var logoutUrl = logoutUrls[i];
            $.ajax({
                url:logoutUrl,
                dataType:'jsonp',
                processData: false,
                type:'get',
                crossDomain: true,
                jsonp:'callback',
                jsonpCallback:"successCallback",
                success:function(data){
                    console.log(data);
                },
                error:function(data) {
                    console.log(data);
                }
            });
        }
    }
};
$(document).ready(function() {
    app.init();
});