`

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');
        });
    },
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics