活动页面添加参赛作品瀑布流
[PumpkinHouse.git] / PumpkinHouseWeb / Scripts / user.js
blobe3e5d42af44ce1db4d4452c25dfe7f664673d2bf
1 /// <reference path="lib/jquery-1.7.js" />\r
2 /// <reference path="lib/jquery.validate.js" />\r
3 /// <reference path="util.js" />\r
4 /// <reference path="data.js" />\r
5 /// <reference path="ajaxCall.js" />\r
6 \r
7 (function ($) {\r
8     $.fn.fanButton = function (loggedIn, numberHolder) {\r
9         this.each(function (index, item) {\r
10             var i = $(item);\r
11             var status = parseInt(i.attr('data-status'));\r
12             renderUserButton(status, i);\r
14             i.on('click', function (event) {\r
15                 if (!loggedIn) {\r
16                     showLogonDialog();\r
17                 }\r
18                 else {\r
19                     var status = parseInt(i.attr('data-status'));\r
20                     var targetUser = i.attr('data-target-user');\r
21                     if (status & 2) { // I am watching him\r
22                         ajaxUnfanUser(true, targetUser, function () {\r
23                             if (typeof renderUser != 'undefined') {\r
24                                 globalUser.hasMyAttention = false;\r
25                                 globalUser.numberOfFans--;\r
26                                 globalUser.relation = globalUser.relation - 2;\r
27                                 renderUser();\r
28                             }\r
29                             else {\r
30                                 renderUserButton(status - 2, i);\r
31                                 if (numberHolder) {\r
32                                     numberHolder.text(numberHolder.text().charCodeAt() - 1);\r
33                                 }\r
34                             }\r
35                         }, handleFault);\r
36                     }\r
37                     else {\r
38                         ajaxFanUser(true, targetUser, function () {\r
39                             if (typeof renderUser != 'undefined') {\r
40                                 globalUser.hasMyAttention = true;\r
41                                 globalUser.numberOfFans++;\r
42                                 globalUser.relation = globalUser.relation + 2;\r
43                                 renderUser();\r
44                             }\r
45                             else {\r
46                                 renderUserButton(status + 2, i);\r
47                                 if (numberHolder) {\r
48                                     numberHolder.text(numberHolder.text().charCodeAt() + 1);\r
49                                 }\r
50                             }\r
51                         }, handleFault);\r
52                     }\r
53                 }\r
54             });\r
55         });\r
56     }\r
58     function renderUserButton(status, btn) {\r
59         btn.removeClass('HxGz');\r
60         btn.removeClass('yjGz');\r
61         btn.removeClass('GzW');\r
62         btn.removeClass('MsR');\r
63         var watching = status & 2;\r
64         var watchingMe = status & 1;\r
65         if (watching) {\r
66             if (watchingMe) {\r
67                 btn.addClass('HxGz'); // 互相关注\r
68                 btn.val(' ');\r
69             }\r
70             else {\r
71                 btn.addClass('yjGz'); // 已关注     \r
72                 btn.val(' ');\r
73             }\r
74         }\r
75         else {\r
76             if (watchingMe) {\r
77                 btn.addClass('GzW'); // 关注我\r
78                 btn.val(' ');\r
79             }\r
80             else {\r
81                 btn.addClass('MsR'); // 陌生人\r
82                 btn.val(' ');\r
83             }\r
84         }\r
85         btn.attr('data-status', status);\r
86     }\r
88 } (jQuery));\r