日期:2014-05-16  浏览次数:20284 次

Facebook Like的JS实现

    /**
     *like
     */
    flashShowLike : function() {
        var _this = this;
        var dialog = FB.Dialog.create({
            content   : '<fb:like-box href="http://www.facebook.com/apps/application.php?id='+ this.initData.appId +'" width="360" height="400" show_faces="true" stream="false" header="true"></fb:like-box>',
            closeIcon : true,
            visible   : true,
            onClose   : function() {
                callBackFun(0);
                _this.log('player close likewin');
            }
        });
        var callBackFun = function(like) {
            FB.Dialog.remove(dialog);
            var flash = swfobject.getObjectById("flashApp");
            if (like) {
                flash["gameLikeComplete"]();
            } else {
                flash["gameLikeCancel"]();
            }
            flash = null;
        };
        FB.XFBML.parse(dialog);
        FB.Dialog.show(dialog);
        $(".fb_dialog_close_icon").attr("style", "background-position:center bottom;z-index:99;")
        //事件监听
        if (this.initData.likeEvent) {
            return;
        }
        this.initData.likeEvent = true;
        //点击like
        FB.Event.subscribe("edge.create", function(resp) {
            _this.post('ajax_get.php',{
                'action' : 'like',
                'uid'    : _this.initData.playerId
            },function(data){
                callBackFun(data);
                _this.log('player press like');
            });
        });
        //取消like
        FB.Event.subscribe("edge.remove", function(resp) {
            callBackFun(0);
            _this.log('player cancel like');
        });
    },
?