]> git.mxchange.org Git - friendica.git/blob - view/theme/frost-mobile/js/theme.js
52258f0be5fbf2c00180bbd31b14b961c91019e6
[friendica.git] / view / theme / frost-mobile / js / theme.js
1 $(document).ready(function() {
2
3         /* enable editor on focus and click */
4         $("#profile-jot-text").focus(enableOnUser);
5         $("#profile-jot-text").click(enableOnUser);
6
7         $('#event-share-checkbox').change(function() {
8
9                 if ($('#event-share-checkbox').is(':checked')) {
10                         $('#acl-wrapper').show();
11                 }
12                 else {
13                         $('#acl-wrapper').hide();
14                 }
15         }).trigger('change');
16
17
18         $(".popupbox").click(function () {
19                 var parent = $( $(this).attr('href') ).parent();
20                 if (parent.css('display') == 'none') {
21                         parent.show();
22                 } else {
23                         parent.hide();
24                 }
25                 return false;
26         });
27
28
29
30         if(typeof window.AjaxUpload != "undefined") {
31                 var uploader = new window.AjaxUpload(
32                         window.imageUploadButton,
33                         { action: 'wall_upload/'+window.nickname+'?nomce=1',
34                                 name: 'userfile',
35                                 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
36                                 onComplete: function(file,response) {
37                                         addeditortext(window.jotId, response);
38                                         $('#profile-rotator').hide();
39                                 }
40                         }
41                 );
42
43                 if($('#wall-file-upload').length) {
44                         var file_uploader = new window.AjaxUpload(
45                                 'wall-file-upload',
46                                 { action: 'wall_attach/'+window.nickname+'?nomce=1',
47                                         name: 'userfile',
48                                         onSubmit: function(file,ext) { $('#profile-rotator').show(); },
49                                         onComplete: function(file,response) {
50                                                 addeditortext(window.jotId, response);
51                                                 $('#profile-rotator').hide();
52                                         }
53                                 }
54                         );
55                 }
56         }
57
58
59         if(typeof window.aclInit !="undefined" && typeof acl=="undefined"){
60                 acl = new ACL(
61                         baseurl+"/acl",
62                         [ window.allowCID,window.allowGID,window.denyCID,window.denyGID ]
63                 );
64         }
65
66         switch(window.autocompleteType) {
67                 case 'msg-header':
68                         $("#recip").name_autocomplete(baseurl + '/acl', '', false, function(data) {
69                                         $("#recip-complete").val(data.id);
70                         });
71                         break;
72                 case 'contacts-head':
73                         $("#contacts-search").contact_autocomplete(baseurl + '/acl', 'a', true);
74
75
76                         $("#contacts-search").keyup(function(event){
77                                 if(event.keyCode == 13){
78                                         $("#contacts-search").click();
79                                 }
80                         });
81                         $(".autocomplete-w1 .selected").keyup(function(event){
82                                 if(event.keyCode == 13){
83                                         $("#contacts-search").click();
84                                 }
85                         });
86                         break;
87                 case 'display-head':
88                         $(".comment-wwedit-wrapper textarea").editor_autocomplete(baseurl+"/acl");
89                         break;
90                 default:
91                         break;
92         }
93
94
95 /*      if(window.autoCompleteType == "display-head") {
96                 //$(".comment-edit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
97                 // make auto-complete work in more places
98                 //$(".wall-item-comment-wrapper textarea").contact_autocomplete(baseurl+"/acl");
99                 $(".comment-wwedit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
100         }*/
101
102
103         if(window.aclType == "settings-head" || window.aclType == "photos_head" || window.aclType == "event_head") {
104                 $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
105                         var selstr;
106                         $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
107                                 selstr = $(this).text();
108                                 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
109                                 $('#jot-public').hide();
110                         });
111                         if(selstr == null) {
112                                 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
113                                 $('#jot-public').show();
114                         }
115
116                 }).trigger('change');
117         }
118
119         if(window.aclType == "event_head") {
120                 $('#events-calendar').fullCalendar({
121                         events: baseurl + window.eventModuleUrl +'/json/',
122                         header: {
123                                 left: 'prev,next today',
124                                 center: 'title',
125                                 right: 'month,agendaWeek,agendaDay'
126                         },
127                         timeFormat: 'H(:mm)',
128                         eventClick: function(calEvent, jsEvent, view) {
129                                 showEvent(calEvent.id);
130                         },
131
132                         eventRender: function(event, element, view) {
133                                 //console.log(view.name);
134                                 if (event.item['author-name']==null) return;
135                                 switch(view.name){
136                                         case "month":
137                                         element.find(".fc-title").html(
138                                                 "<img src='{0}' style='height:10px;width:10px'>{1} : {2}".format(
139                                                         event.item['author-avatar'],
140                                                         event.item['author-name'],
141                                                         event.title
142                                         ));
143                                         break;
144                                         case "agendaWeek":
145                                         element.find(".fc-title").html(
146                                                 "<img src='{0}' style='height:12px; width:12px'>{1}<p>{2}</p><p>{3}</p>".format(
147                                                         event.item['author-avatar'],
148                                                         event.item['author-name'],
149                                                         event.item.desc,
150                                                         event.item.location
151                                         ));
152                                         break;
153                                         case "agendaDay":
154                                         element.find(".fc-title").html(
155                                                 "<img src='{0}' style='height:24px;width:24px'>{1}<p>{2}</p><p>{3}</p>".format(
156                                                         event.item['author-avatar'],
157                                                         event.item['author-name'],
158                                                         event.item.desc,
159                                                         event.item.location
160                                         ));
161                                         break;
162                                 }
163                         }
164
165                 });
166
167                 // center on date
168                 var args=location.href.replace(baseurl,"").split("/");
169                 if (args.length>=5 && window.eventModeParams == 2) {
170                         $("#events-calendar").fullCalendar('gotoDate',args[3] , args[4]-1);
171                 } else if (args.length>=4 && window.eventModeParams == 1) {
172                         $("#events-calendar").fullCalendar('gotoDate',args[2] , args[3]-1);
173                 }
174
175                 // show event popup
176                 var hash = location.hash.split("-")
177                 if (hash.length==2 && hash[0]=="#link") showEvent(hash[1]);
178         }
179
180 });
181
182 // update pending count //
183 $(function(){
184
185         $("nav").bind('nav-update',  function(e,data){
186                 var elm = $('#pending-update');
187                 var register = $(data).find('register').text();
188                 if (register=="0") { register=""; elm.hide();} else { elm.show(); }
189                 elm.html(register);
190         });
191 });
192
193
194
195 function homeRedirect() {
196         $('html').fadeOut('slow', function(){
197                 window.location = baseurl + "/login";
198         });
199 }
200
201
202 function initCrop() {
203         function onEndCrop( coords, dimensions ) {
204                 $PR( 'x1' ).value = coords.x1;
205                 $PR( 'y1' ).value = coords.y1;
206                 $PR( 'x2' ).value = coords.x2;
207                 $PR( 'y2' ).value = coords.y2;
208                 $PR( 'width' ).value = dimensions.width;
209                 $PR( 'height' ).value = dimensions.height;
210         }
211
212         Event.observe( window, 'load', function() {
213                 new Cropper.ImgWithPreview(
214                 'croppa',
215                 {
216                         previewWrap: 'previewWrap',
217                         minWidth: 175,
218                         minHeight: 175,
219                         maxWidth: 640,
220                         maxHeight: 640,
221                         ratioDim: { x: 100, y:100 },
222                         displayOnInit: true,
223                         onEndCrop: onEndCrop
224                 });
225         });
226 }
227
228
229 function showEvent(eventid) {
230 /*      $.get(
231                 baseurl + window.eventModuleUrl + '/?id=' + eventid,
232                 function(data){
233                         $.colorbox({html:data});
234                 }
235         );*/
236 }
237
238 /*
239  * Editor
240  */
241 var editor = false;
242 var textlen = 0;
243
244 function initEditor(callback){
245         if (editor == false) {
246                 $("#profile-jot-text").css({ 'height': 200, 'color': '#000' });
247                 $("#profile-jot-text").editor_autocomplete(baseurl+"/acl");
248                 $("a#jot-perms-icon, a#settings-default-perms-menu").click(function () {
249                         var parent = $("#profile-jot-acl-wrapper").parent();
250                         if (parent.css('display') == 'none') {
251                                 parent.show();
252                         } else {
253                                 parent.hide();
254                         }
255                         return false;
256                 });
257                 $(".jothidden").show();
258
259                 editor = true;
260         }
261         if (typeof callback != "undefined") {
262                 callback();
263         }
264 }
265
266 function enableOnUser(){
267         if (editor) {
268                 return;
269         }
270         $(this).val("");
271         initEditor();
272 }
273
274 /*
275  * Jot
276  */
277
278 function addeditortext(textElem, data) {
279         var currentText = $(textElem).val();
280         $(textElem).val(currentText + data);
281 }
282
283 function jotVideoURL() {
284         reply = prompt(window.vidURL);
285         if(reply && reply.length) {
286                 addeditortext("#profile-jot-text", '[video]' + reply + '[/video]');
287         }
288 }
289
290 function jotAudioURL() {
291         reply = prompt(window.audURL);
292         if(reply && reply.length) {
293                 addeditortext("#profile-jot-text", '[audio]' + reply + '[/audio]');
294         }
295 }
296
297
298 function jotGetLocation() {
299         reply = prompt(window.whereAreU, $('#jot-location').val());
300         if(reply && reply.length) {
301                 $('#jot-location').val(reply);
302         }
303 }
304
305 function jotShare(id) {
306         if ($('#jot-popup').length != 0) $('#jot-popup').show();
307
308         $('#like-rotator-' + id).show();
309         $.get('share/' + id, function(data) {
310                 if (!editor) $("#profile-jot-text").val("");
311                 initEditor(function(){
312                         addeditortext("#profile-jot-text", data);
313                         $('#like-rotator-' + id).hide();
314                         $(window).scrollTop(0);
315                 });
316
317         });
318 }
319
320 function jotGetLink() {
321         reply = prompt(window.linkURL);
322         if(reply && reply.length) {
323                 reply = bin2hex(reply);
324                 $('#profile-rotator').show();
325                 $.get('parse_url?binurl=' + reply, function(data) {
326                         addeditortext(window.jotId, data);
327                         $('#profile-rotator').hide();
328                 });
329         }
330 }
331
332 /*function linkdropper(event) {
333         var linkFound = event.dataTransfer.types.contains("text/uri-list");
334         if(linkFound)
335                 event.preventDefault();
336 }
337
338 function linkdrop(event) {
339         var reply = event.dataTransfer.getData("text/uri-list");
340         event.target.textContent = reply;
341         event.preventDefault();
342         if(reply && reply.length) {
343                 reply = bin2hex(reply);
344                 $('#profile-rotator').show();
345                 $.get('parse_url?binurl=' + reply, function(data) {
346                         //if (!editor) $("#profile-jot-text").val("");
347                         //initEditor(function(){
348                         addeditortext(window.jotId, data);
349                         $('#profile-rotator').hide();
350                         //});
351                 });
352         }
353 }*/
354
355 function jotClearLocation() {
356         $('#jot-coord').val('');
357         $('#profile-nolocation-wrapper').hide();
358 }
359
360 if(typeof window.geoTag === 'function') window.geoTag();
361
362
363
364 /*
365  * Items
366  */
367
368 function confirmDelete() { return confirm(window.delItem); }
369
370 /*function deleteCheckedItems() {
371         var checkedstr = '';
372
373         $('.item-select').each( function() {
374                 if($(this).is(':checked')) {
375                         if(checkedstr.length != 0) {
376                                 checkedstr = checkedstr + ',' + $(this).val();
377                         }
378                         else {
379                                 checkedstr = $(this).val();
380                         }
381                 }
382         });
383         $.post('item', { dropitems: checkedstr }, function(data) {
384                 window.location.reload();
385         });
386 }*/
387
388 function itemTag(id) {
389         reply = prompt(window.term);
390         if(reply && reply.length) {
391                 reply = reply.replace('#','');
392                 if(reply.length) {
393
394                         commentBusy = true;
395                         $('body').css('cursor', 'wait');
396
397                         $.get('tagger/' + id + '?term=' + reply, NavUpdate);
398                         /*if(timer) clearTimeout(timer);
399                         timer = setTimeout(NavUpdate,3000);*/
400                         liking = 1;
401                 }
402         }
403 }
404
405 function itemFiler(id) {
406
407         $.get('filer/', function(data){
408
409                 var promptText = $('#id_term_label', data).text();
410
411                 reply = prompt(promptText);
412                 if(reply && reply.length) {
413                         commentBusy = true;
414                         $('body').css('cursor', 'wait');
415                         $.get('filer/' + id + '?term=' + reply, NavUpdate);
416 /*                              if(timer) clearTimeout(timer);
417                         timer = setTimeout(NavUpdate,3000);*/
418                         liking = 1;
419 /*                              $.colorbox.close();*/
420                 }
421         });
422
423 /*              var bordercolor = $("input").css("border-color");
424
425         $.get('filer/', function(data){
426                 $.colorbox({html:data});
427                 $("#id_term").keypress(function(){
428                         $(this).css("border-color",bordercolor);
429                 })
430                 $("#select_term").change(function(){
431                         $("#id_term").css("border-color",bordercolor);
432                 })
433
434                 $("#filer_save").click(function(e){
435                         e.preventDefault();
436                         reply = $("#id_term").val();
437                         if(reply && reply.length) {
438                                 commentBusy = true;
439                                 $('body').css('cursor', 'wait');
440                                 $.get('filer/' + id + '?term=' + reply);
441                                 if(timer) clearTimeout(timer);
442                                 timer = setTimeout(NavUpdate,3000);
443                                 liking = 1;
444                                 $.colorbox.close();
445                         } else {
446                                 $("#id_term").css("border-color","#FF0000");
447                         }
448                         return false;
449                 });
450         });
451 */
452 }
453
454
455
456 /*
457  * Comments
458  */
459
460
461 function commentOpen(obj,id) {
462         if(obj.value == window.commentEmptyText) {
463                 obj.value = "";
464                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
465                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
466                 $("#mod-cmnt-wrap-" + id).show();
467                 openMenu("comment-edit-submit-wrapper-" + id);
468         }
469 }
470 function commentClose(obj,id) {
471         if(obj.value == "") {
472                 obj.value = window.commentEmptyText;
473                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
474                 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
475                 $("#mod-cmnt-wrap-" + id).hide();
476                 closeMenu("comment-edit-submit-wrapper-" + id);
477         }
478 }
479
480
481 function commentInsert(obj,id) {
482         var tmpStr = $("#comment-edit-text-" + id).val();
483         if(tmpStr == window.commentEmptyText) {
484                 tmpStr = "";
485                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
486                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
487                 openMenu("comment-edit-submit-wrapper-" + id);
488         }
489         var ins = $(obj).html();
490         ins = ins.replace("&lt;","<");
491         ins = ins.replace("&gt;",">");
492         ins = ins.replace("&amp;","&");
493         ins = ins.replace("&quot;",'"');
494         $("#comment-edit-text-" + id).val(tmpStr + ins);
495 }
496
497 function qCommentInsert(obj,id) {
498         var tmpStr = $("#comment-edit-text-" + id).val();
499         if(tmpStr == window.commentEmptyText) {
500                 tmpStr = "";
501                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
502                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
503                 openMenu("comment-edit-submit-wrapper-" + id);
504         }
505         var ins = $(obj).val();
506         ins = ins.replace("&lt;","<");
507         ins = ins.replace("&gt;",">");
508         ins = ins.replace("&amp;","&");
509         ins = ins.replace("&quot;",'"');
510         $("#comment-edit-text-" + id).val(tmpStr + ins);
511         $(obj).val("");
512 }
513
514 /*function showHideCommentBox(id) {
515         if( $('#comment-edit-form-' + id).is(':visible')) {
516                 $('#comment-edit-form-' + id).hide();
517         }
518         else {
519                 $('#comment-edit-form-' + id).show();
520         }
521 }*/
522
523
524 function insertFormatting(comment,BBcode,id) {
525
526         var tmpStr = $("#comment-edit-text-" + id).val();
527         if(tmpStr == comment) {
528                 tmpStr = "";
529                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
530                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
531                 openMenu("comment-edit-submit-wrapper-" + id);
532                 $("#comment-edit-text-" + id).val(tmpStr);
533         }
534
535         textarea = document.getElementById("comment-edit-text-" +id);
536         if (document.selection) {
537                 textarea.focus();
538                 selected = document.selection.createRange();
539                 if (BBcode == "url"){
540                         selected.text = "["+BBcode+"=http://]" +  selected.text + "[/"+BBcode+"]";
541                         } else
542                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
543         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
544                 var start = textarea.selectionStart;
545                 var end = textarea.selectionEnd;
546                 if (BBcode == "url"){
547                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"=http://]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
548                         } else
549                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
550         }
551         return true;
552 }
553
554 function cmtBbOpen(id) {
555         $(".comment-edit-bb-" + id).show();
556 }
557 function cmtBbClose(id) {
558         $(".comment-edit-bb-" + id).hide();
559 }
560
561