OSDN Git Service

501e549bb2ae2af87089f0c4bb28a393bb822ea6
[embrj/master.git] / js / formfunc.js
1 FILTER_COOKIE = 'filKey';
2 FILTER_COUNTER = 'filCnt';
3 FILTER_KEY_OPT ={
4         expires: 30
5 }
6 $(function (){
7                 $("#photoBtn").click(function (){
8                                 $("#photoArea").slideToggle(100);
9                         });
10                 $("#imageUploadSubmit").click(function (e){
11                                 e.preventDefault();
12                                 ImageUpload();
13                         });
14                 $("#filterBtn").click(function (){
15                                 $("#filterArea").slideToggle(100);
16                         });
17                 $("#symbolBtn").click(function (){
18                                 $("#symArea").toggle();
19                         });
20                 $("#symbols span").click(function (){
21               var obj = document.getElementById('textbox'); 
22               var str = $(this).html();
23               if(document.selection){  
24                  obj.focus();  
25                  var sel=document.selection.createRange();  
26                  document.selection.empty();  
27                  sel.text = str;  
28               }else{  
29                  var prefix, main, suffix;  
30                  prefix = obj.value.substring(0, obj.selectionStart);  
31                  main = obj.value.substring(obj.selectionStart, obj.selectionEnd);  
32                  suffix = obj.value.substring(obj.selectionEnd);  
33                  obj.value = prefix + str + suffix;  
34               }
35                         $("#symArea").hide();
36                         leaveWord();
37                 });
38                 $("#restoreBtn").click(function (){
39                                 $('#textbox').val($.cookie('recover'));
40                                 updateSentTip("Your previous tweet has been restored!", 3e3, "success");
41                         });
42                 $("#autoBtn").click(function(){
43                                 if ($("#autoBtn").hasClass("pause")){
44                                         clearInterval(UPDATE_INTERVAL);
45                                         $("#autoBtn").removeClass("pause").addClass("start");
46                                         updateSentTip("Auto refresh deactivated!", 3e3, "success");
47                                 }else{
48                                         setUpdateInterval();
49                                         $("#autoBtn").removeClass("start").addClass("pause");
50                                         updateSentTip("Auto refresh activated!", 3e3, "success");
51                                         update();
52                                 }
53                         });
54                 $("#refreshBtn").click(function (){
55                                 update();
56                                 updateSentTip("Retrieving new tweets...", 3e3, "ing");
57                         });
58                 $("#transBtn").click(function (){
59                                 $("#transArea").slideToggle(100);
60                         });
61                 $("#filterSubmit").click(function (e){
62                                 e.preventDefault();
63                                 if ($.trim($('#iptFilter').val()).length == 0){
64                                         updateSentTip("Please enter at least one keyword!", 3e3, "failure");
65                                         return false;
66                                 }else{
67                                         $.cookie(FILTER_COOKIE, null);
68                                         $.cookie(FILTER_COUNTER, null);
69                                         updateSentTip("New keyword: " + $.trim($('#iptFilter').val()) + " added!", 3e3, "success");
70                                         filterEle();
71                                 }
72                         });
73                 $("#filterReset").click(function (e){
74                                 e.preventDefault();
75                                 $.cookie(FILTER_COOKIE, null);
76                                 $.cookie(FILTER_COUNTER, null);
77                                 $('#iptFilter').val("");
78                                 updateSentTip("Filtered tweets have been restored!", 5e3, "success");
79                                 $('#statuses .filter').slideDown("fast");
80                         });
81                 $("#filterHide").toggle(
82
83                         function (){
84                                 $('#statuses .reply').slideUp("fast");
85                                 $('#filterHide').val("Show @");
86                         }, function (){
87                                 $('#statuses .reply').slideDown("fast");
88                                 $('#filterHide').val("Hide @");
89                         });
90                 $("#clearBtn").click(function(e){
91                                 e.preventDefault();
92                                 if (confirm("This will sweep your timeline and remove excess tweets, are you sure?")){
93                                         $("#statuses .timeline").each(function(){
94                                                         $(this).find("li:gt(19)").remove();
95                                                 });
96                                 }
97                         });
98         });
99         
100         function ImageUpload(){
101                 updateSentTip("Uploading your image...", 10000, "ing");
102                 $.ajaxFileUpload({
103                                 url: 'ajax/uploadImage.php?do=image',
104                                 timeout: 60000,
105                                 secureuri: false,
106                                 fileElementId: 'imageFile',
107                                 dataType: 'json',
108                                 success: function (data, status){
109                                         if (typeof(console) !== 'undefined' && console != null){
110                                                 console.info(data);
111                                         }
112                                         if (data.result != undefined && data.result == "success"){
113                                                 $("#textbox").val($("#textbox").val() + data.url);
114                                                 updateSentTip("Your image has been uploaded!", 3e3, "success");
115                                                 $("#photoArea").slideToggle(100);
116                                         }else{
117                                                 updateSentTip("Failed to upload, please try again.", 3e3, "failure");
118                                                 $("#photoArea").slideToggle(100);
119                                         }
120                                 },
121                                 error: function (data, status, e){
122                                         updateSentTip("Failed to upload, please try again.", 3e3, "failure");
123                                         $("#photoArea").slideToggle(100);
124                                 }
125                         })
126                 return false;
127         }
128         
129 function enableFilter(){
130         if ($.cookie(FILTER_COOKIE) != null && $.cookie(FILTER_COOKIE) != ""){
131                 $('#iptFilter').val(recoverKeywords());
132                 $.cookie(FILTER_COUNTER, null);
133                 filterEle();
134         }
135 }
136 function filterEle(){
137         if ($.trim($('#iptFilter').val()).length == 0){
138                 return false;
139         }else{
140                 var objs;
141                 var targets = [];
142                 var keywords = keywordRegexp();
143                 if (keywords === $.cookie(FILTER_COOKIE)){
144                         objs = $('#statuses .timeline li:not(.filter:hidden)').find('.status_word');
145                 }else{
146                         objs = $('#statuses .timeline li').find('.status_word');
147                 }
148                 var reg = new RegExp(keywords, "i");
149                 for (i = 0; i < objs.length; i++){
150                         if (reg.test($(objs[i]).text())){
151                                 targets.push(objs[i]);
152                         }
153                 }
154                 if ($.cookie(FILTER_COUNTER) != null && $.cookie(FILTER_COUNTER) != ''){
155                         $.cookie(FILTER_COUNTER, targets.length + parseInt($.cookie(FILTER_COUNTER)));
156                 }else{
157                         $.cookie(FILTER_COUNTER, targets.length);
158                 }
159                 hideMatched(targets);
160                 $.cookie(FILTER_COOKIE, keywords);
161                 setCounter();
162         }
163 }
164 function hideMatched(obj){
165         $(obj).parent().parent().addClass("filter").hide();
166 }
167 function isMatch(txt, keywords){
168         var reg = RegExp(keywords, "i");
169         return reg.test(txt);
170 }
171 function keywordRegexp(){
172         if ($.cookie(FILTER_COOKIE) === null){
173                 return setFilterCookie();
174         }else{
175                 return $.cookie(FILTER_COOKIE);
176         }
177 }
178 function recoverKeywords(){
179         return $.cookie(FILTER_COOKIE).replace(/\|/g, ',');
180 }
181 function setFilterCookie(){
182         var strs = $('#iptFilter').val().split(",");
183         var keywords = '';
184         for (i = 0; i < strs.length; i++){
185                 if (strs[i] == "") continue;
186                 keywords += strs[i] + "|";
187         }
188         keywords = keywords.substr(0, keywords.length - 1);
189         return keywords;
190 }
191 var option ={ expire: 30 };
192 $(document).ready(function (){
193                 enableFilter();
194                 if($.cookie('transLang') === null){
195                         $.cookie('transLang', 'en', option);
196                 }
197                 if($.cookie('myLangs') === null){
198                         $.cookie('myLangs', 'en', option);
199                 }
200                 var select = $('#transArea select[name=langs]');
201                 select.change(function(){
202                                 var val = $(this).val();
203                                 $.cookie('transLang', val, option);
204                                 $.cookie('fullLang', $(this).find('option[value=' + val + ']').text(), option);
205                         })
206                         .find('option').each(function(){
207                                 var lang = $.cookie('transLang')
208                                 if(lang === null){
209                                         lang = 'en';
210                                 }
211                                 if($(this).val() === lang){
212                                         $(this).attr('selected', 'selected');
213                                 }
214                         });
215                 var mylang = $('#transArea select[name=myLangs]');
216                 mylang.change(function(){
217                                 var val = $(this).val();
218                                 $.cookie('myLangs', val, option);
219                         })
220                         .find('option').each(function(){
221                                 var lang = $.cookie('myLangs')
222                                 if(lang === null){
223                                         lang = 'en';
224                                 }
225                                 if($(this).val() === lang){
226                                         $(this).attr('selected', 'selected');
227                                 }
228                         });
229         });