OSDN Git Service

embrj
[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                                                 console.log(data);
118                                                 updateSentTip("Failed to upload, please try again.", 3e3, "failure");
119                                                 $("#photoArea").slideToggle(100);
120                                         }
121                                 },
122                                 error: function (data, status, e){
123                                         updateSentTip("Failed to upload, please try again.", 3e3, "failure");
124                                         $("#photoArea").slideToggle(100);
125                                         console.log(data);
126                                 }
127                         })
128                 return false;
129         }
130         
131 function enableFilter(){
132         if ($.cookie(FILTER_COOKIE) != null && $.cookie(FILTER_COOKIE) != ""){
133                 $('#iptFilter').val(recoverKeywords());
134                 $.cookie(FILTER_COUNTER, null);
135                 filterEle();
136         }
137 }
138 function filterEle(){
139         if ($.trim($('#iptFilter').val()).length == 0){
140                 return false;
141         }else{
142                 var objs;
143                 var targets = [];
144                 var keywords = keywordRegexp();
145                 if (keywords === $.cookie(FILTER_COOKIE)){
146                         objs = $('#statuses .timeline li:not(.filter:hidden)').find('.status_word');
147                 }else{
148                         objs = $('#statuses .timeline li').find('.status_word');
149                 }
150                 var reg = new RegExp(keywords, "i");
151                 for (i = 0; i < objs.length; i++){
152                         if (reg.test($(objs[i]).text())){
153                                 targets.push(objs[i]);
154                         }
155                 }
156                 if ($.cookie(FILTER_COUNTER) != null && $.cookie(FILTER_COUNTER) != ''){
157                         $.cookie(FILTER_COUNTER, targets.length + parseInt($.cookie(FILTER_COUNTER)));
158                 }else{
159                         $.cookie(FILTER_COUNTER, targets.length);
160                 }
161                 hideMatched(targets);
162                 $.cookie(FILTER_COOKIE, keywords);
163                 setCounter();
164         }
165 }
166 function hideMatched(obj){
167         $(obj).parent().parent().addClass("filter").hide();
168 }
169 function isMatch(txt, keywords){
170         var reg = RegExp(keywords, "i");
171         return reg.test(txt);
172 }
173 function keywordRegexp(){
174         if ($.cookie(FILTER_COOKIE) === null){
175                 return setFilterCookie();
176         }else{
177                 return $.cookie(FILTER_COOKIE);
178         }
179 }
180 function recoverKeywords(){
181         return $.cookie(FILTER_COOKIE).replace(/\|/g, ',');
182 }
183 function setFilterCookie(){
184         var strs = $('#iptFilter').val().split(",");
185         var keywords = '';
186         for (i = 0; i < strs.length; i++){
187                 if (strs[i] == "") continue;
188                 keywords += strs[i] + "|";
189         }
190         keywords = keywords.substr(0, keywords.length - 1);
191         return keywords;
192 }
193 var option ={ expire: 30 };
194 $(document).ready(function (){
195                 enableFilter();
196                 if($.cookie('transLang') === null){
197                         $.cookie('transLang', 'en', option);
198                 }
199                 if($.cookie('myLangs') === null){
200                         $.cookie('myLangs', 'en', option);
201                 }
202                 var select = $('#transArea select[name=langs]');
203                 select.change(function(){
204                                 var val = $(this).val();
205                                 $.cookie('transLang', val, option);
206                                 $.cookie('fullLang', $(this).find('option[value=' + val + ']').text(), option);
207                         })
208                         .find('option').each(function(){
209                                 var lang = $.cookie('transLang')
210                                 if(lang === null){
211                                         lang = 'en';
212                                 }
213                                 if($(this).val() === lang){
214                                         $(this).attr('selected', 'selected');
215                                 }
216                         });
217                 var mylang = $('#transArea select[name=myLangs]');
218                 mylang.change(function(){
219                                 var val = $(this).val();
220                                 $.cookie('myLangs', val, option);
221                         })
222                         .find('option').each(function(){
223                                 var lang = $.cookie('myLangs')
224                                 if(lang === null){
225                                         lang = 'en';
226                                 }
227                                 if($(this).val() === lang){
228                                         $(this).attr('selected', 'selected');
229                                 }
230                         });
231         });