OSDN Git Service

c2390cc5c624468a159ef1b511bde51466ab2447
[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('twitterbg',"#twitterbg",false,function(){
19                 if($.cookie('twitterbg') === 'true'){
20                         $.ajax({
21                                 url:'ajax/updateProfile.php?extra=bg',
22                                 dataType:'json',
23                                 success: function (){
24                                         location.reload();
25                                 }
26                         });
27                 } else {
28                         $.cookie('Bgcolor', '');
29                         $.cookie('Bgimage','');
30                         $.cookie('Bgrepeat','no-repeat');
31                         location.reload();
32                 }
33         });
34         selectbox('homeInterval',"#homeInterval",function(){
35                 $.cookie('intervalChanged','true',{expires:365});
36         });
37         selectbox('updatesInterval',"#updatesInterval",function(){
38                 $.cookie('intervalChanged','true',{expires:365});
39         });
40         selectbox('fontsize',"#fontsize");
41         $('.bg_input').ColorPicker({ 
42                 onBeforeShow: function () {
43                         $(this).ColorPickerSetColor(this.value);
44                 },
45                 onSubmit: function(hsb, hex, rgb, el) {
46                         $(el).val("#" + hex);
47                         $(el).ColorPickerHide();
48                         $.cookie('bodyBg',"#" + hex,{expires:365});
49                         location.reload();
50                         updateSentTip('Setting saved successfully!',3000,'success');
51                 }
52         }).bind('keyup', function(){
53                 $(this).ColorPickerSetColor(this.value);
54         });
55         $('#reset_link').bind('click', function(e){
56                 e.preventDefault();
57                 if(confirm("You will lose all customized settings!")){
58                         $.cookie('myCSS', '/*default.css*/');
59                         $.cookie('theme','')
60                         $.cookie('fontsize', '');
61                         $.cookie('Bgcolor', '');
62                         $.cookie('Bgimage','');
63                         $.cookie('showpic','true');
64                         $.cookie('mediaPre','true');
65                         $.cookie('p_avatar','false');
66                         $.cookie('homeInterval',1);
67                         $.cookie('updatesInterval',3);
68                         location.reload();
69                         updateSentTip('Setting Reset successfully!',3000,'success');
70                 }
71         });
72         var style = {
73                 "Twitter Default":{theme:"/*default*/"}, 
74                 "Dark Rabr":{theme:"@import url(themes/1.css);"}, 
75                 "Monokai Python":{theme:"@import url(themes/2.css);"}, 
76                 "Old Times":{theme:"@import url(themes/3.css);"}, 
77                 "Pink":{theme:"@import url(themes/4.css);"},
78                 "Warm @lgsoltek":{theme:"@import url(themes/5.css);"},
79                 "Cold @lgsoltek":{theme:"@import url(themes/6.css);"},
80                 "Green":{theme:"@import url(themes/7.css);"},
81                 "Shine":{theme:"@import url(themes/8.css);"},
82                 "Flew":{theme:"@import url(themes/9.css);"},
83                 "Golden":{theme:"@import url(themes/10.css);"},
84                 "#red":{theme:"@import url(themes/11.css);"},
85                 "Storm":{theme:"@import url(themes/12.css);"},
86                 "City":{theme:"@import url(themes/13.css);"},
87                 "Cosmos":{theme:"@import url(themes/14.css);"},
88                 "Pride (Rainbow)":{theme:"@import url(themes/15.css); /* Have a gay day! */"},
89                 "Drop Bombs":{theme:"@import url(themes/16.css);"},
90                 "Minimal":{theme:"@import url(themes/minimal.css);"},
91         };
92         $.each(style, function (i,o) {
93                 $("#styleSelect").append('<option value="' + o.theme + '">' + i + '</option>');
94         });
95         var theme = $.cookie('theme') == undefined ? '/*default*/' : $.cookie('theme');
96         $("#styleSelect").change(function(){
97                 var o =$(this).val();
98                 $.cookie('theme',o,{expires:365});
99                 $.cookie('Bgimage','');
100                 location.reload();
101                 updateSentTip('Themes Saved Successfully!',3000,'success');
102         }).eq(0).val(theme);
103         
104         $("textarea#myCSS").change(function(){
105                 $.cookie('myCSS',$(this).val(),{expires:365});
106                 location.reload();
107                 updateSentTip('Themes saved successfully!',3000,'success');
108         });
109         $("#AvatarUpload").click(function (e) {
110                 e.preventDefault();
111                 ProfileImageUpload();
112         });
113         $("#saveProfile").click(function(e){
114                 e.preventDefault();
115                 $.ajax({
116                         url: 'ajax/updateProfile.php',
117                         type: 'POST',
118                         data: {
119                                 'name': $('input[name="name"]').val(),
120                                 'url' : $('input[name="url"]').val(),
121                                 'location': $('input[name="location"]').val(),
122                                 'description': $('textarea[name="description"]').text()
123                         },
124                         dataType: 'json',
125                         success: function(msg) {
126                                 if (msg.result == 'success') {
127                                         freshProfile();
128                                         updateSentTip ('Profile updated successfully!',3000,'success');
129                                 } else {
130                                         updateSentTip ('Fail to update your profile, please try again',3000,'failure');
131                                 }
132                         },
133                         error: function() {
134                                 updateSentTip ('Fail to update your profile, please try again',3000,'failure');
135                         }
136                 });
137         });
138 });
139 function checkbox(c,id,d,extra){
140         var $id = $(id);
141         if ($.cookie (c) === null) {
142                 $.cookie (c, d, { expires: 30 });
143         } 
144         $id.prop('checked', $.cookie (c) === 'true').click(function (){
145                 $.cookie(c,$id.prop("checked"),{expires:365});
146                 if (extra != undefined) extra();
147                 updateSentTip('Setting saved successfully!',1000,'success');
148         });
149 }
150 function selectbox(c,id,extra){
151         var $id = $(id);
152         if($.cookie(c) != undefined){
153                 $id.eq(0).val($.cookie(c));
154         }
155         $id.change(function (){
156                 $.cookie(c,$id.find(':selected').val(),{expires:365});
157                 if (extra != undefined) extra();
158                 updateSentTip('Setting saved successfully!',1000,'success');
159         });
160 }
161
162 function ProfileImageUpload() {
163         updateSentTip("Uploading your profile image...", 10000, "ing");
164         $.ajaxFileUpload({
165                         url: 'ajax/uploadImage.php?do=profile',
166                         timeout: 60000,
167                         secureuri: false,
168                         fileElementId: 'profile_image',
169                         dataType: 'json',
170                         success: function (data, status) {
171                                 if (typeof(console) !== 'undefined' && console != null) {
172                                         console.info(data);
173                                 }
174                                 if (typeof(data.result) != 'undefined' && data.result == "success") {
175                                         $.ajax({
176                                                 url: '../ajax/updateProfile.php',
177                                                 type: "GET",
178                                                 dataType: "json",
179                                                 success: function(msg){
180                                                         freshProfile();
181                                                         $(".settings > img").attr("src",$.cookie("imgurl"));
182                                                 }
183                                         });
184                                         updateSentTip("Your profile image has been uploaded!", 3000, "success");
185                                 } else {
186                                         updateSentTip("Failed to upload, please try again.", 3000, "failure");
187                                 }
188                         },
189                         error: function (data, status, e) {
190                                 updateSentTip("Failed to upload, please try again.", 3000, "failure");
191                         }
192                 })
193         return false;
194 }