OSDN Git Service

embrj
[embrj/master.git] / js / setting.js
1 $(function(){
2         checkbox('showpic',"#showpic",true);
3         checkbox('mediaPre',"#mediaPreSelect",true);
4         checkbox('p_avatar',"#proxifyAvatar",false,function(){
5                 var imgurl = $.cookie('imgurl');
6                 if(imgurl.indexOf('img.php') > -1) {
7                         imgurl = imgurl.substr(15);
8                 } else {
9                         imgurl = 'img.php?imgurl='+imgurl;
10                 }
11                 $.cookie('imgurl',imgurl,{expires:365});
12                 freshProfile();
13         });
14         checkbox('autoscroll',"#autoscroll",true);
15         checkbox('sidebarscroll',"#sidebarscroll",true,function(){
16                 $(window).unbind('scroll',scroller);
17         });
18         checkbox('shownick',"#shownick",false);
19         checkbox('twitterbg',"#twitterbg",false,function(){
20                 if($.cookie('twitterbg') === 'true'){
21                         $.ajax({
22                                 url:'ajax/updateProfile.php?extra=bg',
23                                 dataType:'json',
24                                 success: function (){
25                                         location.reload();
26                                 }
27                         });
28                 } else {
29                         $.cookie('Bgcolor', '');
30                         $.cookie('Bgimage','');
31                         $.cookie('Bgrepeat','no-repeat');
32                         location.reload();
33                 }
34         });
35         selectbox('homeInterval',"#homeInterval",function(){
36                 $.cookie('intervalChanged','true',{expires:365});
37         });
38         selectbox('updatesInterval',"#updatesInterval",function(){
39                 $.cookie('intervalChanged','true',{expires:365});
40         });
41         selectbox('fontsize',"#fontsize");
42         $('.bg_input').ColorPicker({ 
43                 onBeforeShow: function () {
44                         $(this).ColorPickerSetColor(this.value);
45                 },
46                 onSubmit: function(hsb, hex, rgb, el) {
47                         $(el).val("#" + hex);
48                         $(el).ColorPickerHide();
49                         $.cookie('bodyBg',"#" + hex,{expires:365});
50                         location.reload();
51                         updateSentTip('Setting saved successfully!',3000,'success');
52                 }
53         }).bind('keyup', function(){
54                 $(this).ColorPickerSetColor(this.value);
55         });
56         $('#reset_link').bind('click', function(e){
57                 e.preventDefault();
58                 if(confirm("You will lose all customized settings!")){
59                         $.cookie('myCSS', '/*default.css*/');
60                         $.cookie('theme','')
61                         $.cookie('fontsize', '');
62                         $.cookie('Bgcolor', '');
63                         $.cookie('Bgimage','');
64                         $.cookie('showpic','true');
65                         $.cookie('shownick','false');
66                         $.cookie('mediaPre','true');
67                         $.cookie('p_avatar','false');
68                         $.cookie('homeInterval',1);
69                         $.cookie('updatesInterval',3);
70                         location.reload();
71                         updateSentTip('Setting Reset successfully!',3000,'success');
72                 }
73         });
74         var style = {
75                 "Twitter Default":{theme:"/*default*/"}, 
76                 "Dark Rabr":{theme:"@import url(themes/1.css);"}, 
77                 "Monokai Python":{theme:"@import url(themes/2.css);"}, 
78                 "Old Times":{theme:"@import url(themes/3.css);"}, 
79                 "Pink":{theme:"@import url(themes/4.css);"},
80                 "Warm @lgsoltek":{theme:"@import url(themes/5.css);"},
81                 "Cold @lgsoltek":{theme:"@import url(themes/6.css);"},
82                 "Green":{theme:"@import url(themes/7.css);"},
83                 "Shine":{theme:"@import url(themes/8.css);"},
84                 "Flew":{theme:"@import url(themes/9.css);"},
85                 "Golden":{theme:"@import url(themes/10.css);"},
86                 "#red":{theme:"@import url(themes/11.css);"},
87                 "Storm":{theme:"@import url(themes/12.css);"},
88                 "City":{theme:"@import url(themes/13.css);"},
89                 "Cosmos":{theme:"@import url(themes/14.css);"},
90                 "Pride (Rainbow)":{theme:"@import url(themes/15.css); /* Have a gay day! */"},
91                 "Drop Bombs":{theme:"@import url(themes/16.css);"},
92                 "Minimal":{theme:"@import url(themes/minimal.css);"},
93         };
94         $.each(style, function (i,o) {
95                 $("#styleSelect").append('<option value="' + o.theme + '">' + i + '</option>');
96         });
97         var theme = $.cookie('theme') == undefined ? '/*default*/' : $.cookie('theme');
98         $("#styleSelect").change(function(){
99                 var o =$(this).val();
100                 $.cookie('theme',o,{expires:365});
101                 $.cookie('Bgimage','');
102                 location.reload();
103                 updateSentTip('Themes Saved Successfully!',3000,'success');
104         }).eq(0).val(theme);
105         
106         $("textarea#myCSS").change(function(){
107                 $.cookie('myCSS',$(this).val(),{expires:365});
108                 location.reload();
109                 updateSentTip('Themes saved successfully!',3000,'success');
110         });
111         $("#AvatarUpload").click(function (e) {
112                 e.preventDefault();
113                 ProfileImageUpload();
114         });
115         $("#BackgroundUpload").click(function (e) {
116                 e.preventDefault();
117                 ProfileBackgroundUpload();
118         });
119         $("#saveProfile").click(function(e){
120                 e.preventDefault();
121                 $.ajax({
122                         url: 'ajax/updateProfile.php',
123                         type: 'POST',
124                         data: {
125                                 'name': $('input[name="name"]').val(),
126                                 'url' : $('input[name="url"]').val(),
127                                 'location': $('input[name="location"]').val(),
128                                 'description': $('textarea[name="description"]').text()
129                         },
130                         dataType: 'json',
131                         success: function(msg) {
132                                 if (msg.result == 'success') {
133                                         freshProfile();
134                                         updateSentTip ('Profile updated successfully!',3000,'success');
135                                 } else {
136                                         updateSentTip ('Fail to update your profile, please try again',3000,'failure');
137                                 }
138                         },
139                         error: function() {
140                                 updateSentTip ('Fail to update your profile, please try again',3000,'failure');
141                         }
142                 });
143         });
144
145         $("#tile").click(function() {
146                 ProfileBackgroundTile($(this).prop('checked'));
147         });
148 });
149 function checkbox(c,id,d,extra){
150         var $id = $(id);
151         if ($.cookie (c) === null) {
152                 $.cookie (c, d, { expires: 30 });
153         } 
154         $id.prop('checked', $.cookie (c) === 'true').click(function (){
155                 $.cookie(c,$id.prop("checked"),{expires:365});
156                 if (extra != undefined) extra();
157                 updateSentTip('Setting saved successfully!',1000,'success');
158         });
159 }
160 function selectbox(c,id,extra){
161         var $id = $(id);
162         if($.cookie(c) != undefined){
163                 $id.eq(0).val($.cookie(c));
164         }
165         $id.change(function (){
166                 $.cookie(c,$id.find(':selected').val(),{expires:365});
167                 if (extra != undefined) extra();
168                 updateSentTip('Setting saved successfully!',1000,'success');
169         });
170 }
171
172 function ProfileImageUpload() {
173         updateSentTip("Uploading your profile image...", 10000, "ing");
174         $.ajaxFileUpload({
175                         url: 'ajax/uploadImage.php?do=profile',
176                         timeout: 60000,
177                         secureuri: false,
178                         fileElementId: 'profile_image',
179                         dataType: 'json',
180                         success: function (data, status) {
181                                 if (typeof(console) !== 'undefined' && console != null) {
182                                         console.info(data);
183                                 }
184                                 if (typeof(data.result) != 'undefined' && data.result == "success") {
185                                         $.ajax({
186                                                 url: '../ajax/updateProfile.php',
187                                                 type: "GET",
188                                                 dataType: "json",
189                                                 success: function(msg){
190                                                         freshProfile();
191                                                         $("#avatarimg").attr("src",$.cookie("imgurl"));
192                                                 }
193                                         });
194                                         updateSentTip("Your profile image has been uploaded!", 3000, "success");
195                                 } else {
196                                         updateSentTip("Failed to upload, please try again.", 3000, "failure");
197                                 }
198                         },
199                         error: function (data, status, e) {
200                                 updateSentTip("Failed to upload, please try again.", 3000, "failure");
201                         }
202                 })
203         return false;
204 }
205
206 function ProfileBackgroundUpload() {
207         updateSentTip("Uploading your profile background...", 10000, "ing");
208         $.ajaxFileUpload({
209                         url: 'ajax/uploadImage.php?do=background',
210                         timeout: 60000,
211                         secureuri: false,
212                         fileElementId: 'profile_background',
213                         dataType: 'json',
214                         success: function (data, status) {
215                                 if (typeof(console) !== 'undefined' && console != null) {
216                                         console.info(data);
217                                 }
218                                 if (typeof(data.result) != 'undefined' && data.result == "success") {
219                                         if ($.cookie('twitterbg') === 'true') {
220                                                 $.ajax({
221                                                         url:'ajax/updateProfile.php?extra=bg',
222                                                         dataType:'json',
223                                                         success: function() { location.reload(); }
224                                                 });
225                                         }
226                                         $("#backgroundimg").attr("src",data.url);
227                                         updateSentTip("Your profile background has been uploaded!", 3000, "success");
228                                 } else {
229                                         updateSentTip("Failed to upload, please try again.", 3000, "failure");
230                                 }
231                         },
232                         error: function (data, status, e) {
233                                 updateSentTip("Failed to upload, please try again.", 3000, "failure");
234                         }
235                 })
236         return false;
237 }
238
239 function ProfileBackgroundTile(tile) {
240         updateSentTip("Updating your profile background tile...", 3000, "ing");
241         $.ajax({
242                         url: 'ajax/uploadImage.php?do=background',
243                         type: 'POST',
244                         data: {'tile': tile},
245                         dataType: 'json',
246                         success: function (data, status) {
247                                 if (typeof(console) !== 'undefined' && console != null) {
248                                         console.info(data);
249                                 }
250                                 if (typeof(data.result) != 'undefined' && data.result == "success") {
251                                         if ($.cookie('twitterbg') === 'true') {
252                                                 $.ajax({
253                                                         url:'ajax/updateProfile.php?extra=bg',
254                                                         dataType:'json',
255                                                         success: function() { location.reload(); }
256                                                 });
257                                         }
258                                         var isok = data.tile === 'true';
259                                         if (isok != $("#tile").prop('checked')) {
260                                                 $("#tile").prop('checked', isok);
261                                                 updateSentTip("Failed to update, please try again.", 3000, "failure");
262                                         }
263                                         else {
264                                                 updateSentTip("Your profile background tile has been updated!", 3000, "success");
265                                         }
266                                 } else {
267                                         updateSentTip("Failed to update, please try again.", 3000, "failure");
268                                 }
269                         },
270                         error: function (data, status, e) {
271                                 updateSentTip("Failed to update, please try again.", 3000, "failure");
272                         }
273                 })
274         return false;
275 }