]> git.mxchange.org Git - friendica.git/blob - view/theme/frost/js/theme.js
34288420148434cce0f74e1fedc77660d82e2f44
[friendica.git] / view / theme / frost / js / theme.js
1 $j(document).ready(function() {
2
3         window.navMenuTimeout = {
4                 '#network-menu-list-timeout': null,
5                 '#contacts-menu-list-timeout': null,
6                 '#system-menu-list-timeout': null,
7                 '#network-menu-list-opening': false,
8                 '#contacts-menu-list-opening': false,
9                 '#system-menu-list-opening': false,
10                 '#network-menu-list-closing': false,
11                 '#contacts-menu-list-closing': false,
12                 '#system-menu-list-closing': false
13         };
14
15 /*    $j.ajaxSetup({ 
16         cache: false 
17     });*/
18
19
20         if(typeof window.aclInit !="undefined" && typeof acl=="undefined"){
21                 acl = new ACL(
22                         baseurl+"/acl",
23                         [ window.allowCID,window.allowGID,window.denyCID,window.denyGID ]
24                 );
25         }
26
27         /* enable tinymce on focus and click */
28         $j("#profile-jot-text").focus(enableOnUser);
29         $j("#profile-jot-text").click(enableOnUser);
30
31
32         $j('.nav-menu-list, .nav-menu-icon').hover(function() {
33                 showNavMenu($j(this).attr('point'));
34         }, function() {
35                 hideNavMenu($j(this).attr('point'));
36         });
37
38 /*      $j('html').click(function() { $j("#nav-notifications-menu" ).hide(); });*/
39
40         $j('.group-edit-icon').hover(
41                 function() {
42                         $j(this).addClass('icon'); $j(this).removeClass('iconspacer');},
43                 function() {
44                         $j(this).removeClass('icon'); $j(this).addClass('iconspacer');}
45                 );
46
47         $j('.sidebar-group-element').hover(
48                 function() {
49                         id = $j(this).attr('id');
50                         $j('#edit-' + id).addClass('icon'); $j('#edit-' + id).removeClass('iconspacer');},
51
52                 function() {
53                         id = $j(this).attr('id');
54                         $j('#edit-' + id).removeClass('icon');$j('#edit-' + id).addClass('iconspacer');}
55                 );
56
57
58         $j('.savedsearchdrop').hover(
59                 function() {
60                         $j(this).addClass('drop'); $j(this).addClass('icon'); $j(this).removeClass('iconspacer');},
61                 function() {
62                         $j(this).removeClass('drop'); $j(this).removeClass('icon'); $j(this).addClass('iconspacer');}
63         );
64
65         $j('.savedsearchterm').hover(
66                 function() {
67                         id = $j(this).attr('id');
68                         $j('#drop-' + id).addClass('icon');     $j('#drop-' + id).addClass('drophide'); $j('#drop-' + id).removeClass('iconspacer');},
69
70                 function() {
71                         id = $j(this).attr('id');
72                         $j('#drop-' + id).removeClass('icon');$j('#drop-' + id).removeClass('drophide'); $j('#drop-' + id).addClass('iconspacer');}
73         );
74
75 /*      $j('.nav-load-page-link').click(function() {
76                 getPageContent( $j(this).attr('href') );
77                 hideNavMenu( '#' + $j(this).closest('ul').attr('id') );
78                 return false;
79         });*/
80
81         if(window.autoCompleteType == "display-head") {
82                 //$j(".comment-edit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
83                 // make auto-complete work in more places
84                 //$j(".wall-item-comment-wrapper textarea").contact_autocomplete(baseurl+"/acl");
85                 $j(".comment-wwedit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
86         }
87
88         if(window.aclType == "event_head") {
89                 $j('#events-calendar').fullCalendar({
90                         events: baseurl + '/events/json/',
91                         header: {
92                                 left: 'prev,next today',
93                                 center: 'title',
94                                 right: 'month,agendaWeek,agendaDay'
95                         },                      
96                         timeFormat: 'H(:mm)',
97                         eventClick: function(calEvent, jsEvent, view) {
98                                 showEvent(calEvent.id);
99                         },
100                         
101                         eventRender: function(event, element, view) {
102                                 //console.log(view.name);
103                                 if (event.item['author-name']==null) return;
104                                 switch(view.name){
105                                         case "month":
106                                         element.find(".fc-event-title").html(
107                                                 "<img src='{0}' style='height:10px;width:10px'>{1} : {2}".format(
108                                                         event.item['author-avatar'],
109                                                         event.item['author-name'],
110                                                         event.title
111                                         ));
112                                         break;
113                                         case "agendaWeek":
114                                         element.find(".fc-event-title").html(
115                                                 "<img src='{0}' style='height:12px; width:12px'>{1}<p>{2}</p><p>{3}</p>".format(
116                                                         event.item['author-avatar'],
117                                                         event.item['author-name'],
118                                                         event.item.desc,
119                                                         event.item.location
120                                         ));
121                                         break;
122                                         case "agendaDay":
123                                         element.find(".fc-event-title").html(
124                                                 "<img src='{0}' style='height:24px;width:24px'>{1}<p>{2}</p><p>{3}</p>".format(
125                                                         event.item['author-avatar'],
126                                                         event.item['author-name'],
127                                                         event.item.desc,
128                                                         event.item.location
129                                         ));
130                                         break;
131                                 }
132                         }
133                         
134                 });
135                 
136                 // center on date
137                 var args=location.href.replace(baseurl,"").split("/");
138                 if (args.length>=4) {
139                         $j("#events-calendar").fullCalendar('gotoDate',args[2] , args[3]-1);
140                 } 
141                 
142                 // show event popup
143                 var hash = location.hash.split("-")
144                 if (hash.length==2 && hash[0]=="#link") showEvent(hash[1]);
145         }       
146
147         $j('#event-share-checkbox').change(function() {
148
149                 if ($j('#event-share-checkbox').is(':checked')) { 
150                         $j('#acl-wrapper').show();
151                 }
152                 else {
153                         $j('#acl-wrapper').hide();
154                 }
155         }).trigger('change');
156
157
158         if(window.aclType == "settings-head" || window.aclType == "photos_head" || window.aclType == "event_head") {
159                 $j('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
160                         var selstr;
161                         $j('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
162                                 selstr = $j(this).text();
163                                 $j('#jot-perms-icon').removeClass('unlock').addClass('lock');
164                                 $j('#jot-public').hide();
165                         });
166                         if(selstr == null) { 
167                                 $j('#jot-perms-icon').removeClass('lock').addClass('unlock');
168                                 $j('#jot-public').show();
169                         }
170
171                 }).trigger('change');
172         }
173 // For event_end.tpl
174 /*              $j('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
175                         var selstr;
176                         $j('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
177                                 selstr = $j(this).text();
178                                 $j('#jot-public').hide();
179                         });
180                         if(selstr == null) {
181                                 $j('#jot-public').show();
182                         }
183
184                 }).trigger('change');*/
185
186
187         switch(window.autocompleteType) {
188                 case 'msg-header':
189                         var a = $j("#recip").autocomplete({ 
190                                 serviceUrl: baseurl + '/acl',
191                                 minChars: 2,
192                                 width: 350,
193                                 onSelect: function(value,data) {
194                                         $j("#recip-complete").val(data);
195                                 }                       
196                         });
197                         break;
198                 case 'contacts-head':
199                         var a = $j("#contacts-search").autocomplete({ 
200                                 serviceUrl: baseurl + '/acl',
201                                 minChars: 2,
202                                 width: 350,
203                         });
204                         a.setOptions({ params: { type: 'a' }});
205                         break;
206                 default:
207                         break;
208         }
209
210
211         if(typeof window.AjaxUpload != "undefined") {
212                 switch(window.ajaxType) {
213                         case 'jot-header':
214                                 var uploader = new window.AjaxUpload(
215                                         'wall-image-upload',
216                                         { action: 'wall_upload/'+window.nickname,
217                                                 name: 'userfile',
218                                                 onSubmit: function(file,ext) { $j('#profile-rotator').show(); },
219                                                 onComplete: function(file,response) {
220                                                         addeditortext(response);
221                                                         $j('#profile-rotator').hide();
222                                                 }                                
223                                         }
224                                 );
225
226                                 var file_uploader = new window.AjaxUpload(
227                                         'wall-file-upload',
228                                         { action: 'wall_attach/'+window.nickname,
229                                                 name: 'userfile',
230                                                 onSubmit: function(file,ext) { $j('#profile-rotator').show(); },
231                                                 onComplete: function(file,response) {
232                                                         addeditortext(response);
233                                                         $j('#profile-rotator').hide();
234                                                 }                                
235                                         }
236                                 );
237                                 break;
238                         case 'msg-header':
239                                 var uploader = new window.AjaxUpload(
240                                         'prvmail-upload',
241                                         { action: 'wall_upload/' + window.nickname,
242                                                 name: 'userfile',
243                                                 onSubmit: function(file,ext) { $j('#profile-rotator').show(); },
244                                                 onComplete: function(file,response) {
245                                                         tinyMCE.execCommand('mceInsertRawHTML',false,response);
246                                                         $j('#profile-rotator').hide();
247                                                 }                                
248                                         }
249                                 );
250                                 break;
251                         default:
252                                 break;
253                 }
254         }
255
256 });
257
258
259 // update pending count //
260 $j(function(){
261
262         $j("nav").bind('nav-update',  function(e,data){
263                 var elm = $j('#pending-update');
264                 var register = $j(data).find('register').text();
265                 if (register=="0") { register=""; elm.hide();} else { elm.show(); }
266                 elm.html(register);
267         });
268 });
269
270
271 $j(function(){
272         
273         $j("#cnftheme").fancybox({
274                 width: 800,
275                 autoDimensions: false,
276                 onStart: function(){
277                         var theme = $j("#id_theme :selected").val();
278                         var theme_mobile = $j("#id_theme_mobile :selected").val();
279                         $j("#cnftheme").attr('href', baseurl + "/admin/themes/"+theme);
280                 }, 
281                 onComplete: function(){
282                         $j("div#fancybox-content form").submit(function(e){
283                                 var url = $j(this).attr('action');
284                                 // can't get .serialize() to work...
285                                 var data={};
286                                 $j(this).find("input").each(function(){
287                                         data[$j(this).attr('name')] = $j(this).val();
288                                 });
289                                 $j(this).find("select").each(function(){
290                                         data[$j(this).attr('name')] = $j(this).children(":selected").val();
291                                 });
292                                 console.log(":)", url, data);
293                                 
294                                 $j.post(url, data, function(data) {
295                                         if(timer) clearTimeout(timer);
296                                         NavUpdate();
297                                         $j.fancybox.close();
298                                 })
299                                 
300                                 return false;
301                         });
302                         
303                 }
304         });
305 });
306
307
308 function homeRedirect() {
309         $j('html').fadeOut('slow', function(){
310                 window.location = baseurl + "/login";
311         });
312 }
313
314
315 if(typeof window.photoEdit != 'undefined') {
316
317         $j(document).keydown(function(event) {
318
319                         if(window.prevLink != '') { if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = window.prevLink; }}
320                         if(window.nextLink != '') { if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = window.nextLink; }}
321
322         });
323 }
324
325 switch(window.ajaxType) {
326         case 'jot-header':
327                 function jotGetLink() {
328                         reply = prompt(window.linkURL);
329                         if(reply && reply.length) {
330                                 reply = bin2hex(reply);
331                                 $j('#profile-rotator').show();
332                                 $j.get('parse_url?binurl=' + reply, function(data) {
333                                         addeditortext(data);
334                                         $j('#profile-rotator').hide();
335                                 });
336                         }
337                 }
338
339                 function linkdrop(event) {
340                         var reply = event.dataTransfer.getData("text/uri-list");
341                         event.target.textContent = reply;
342                         event.preventDefault();
343                         if(reply && reply.length) {
344                                 reply = bin2hex(reply);
345                                 $j('#profile-rotator').show();
346                                 $j.get('parse_url?binurl=' + reply, function(data) {
347                                         if (!editor) $j("#profile-jot-text").val("");
348                                         initEditor(function(){
349                                                 addeditortext(data);
350                                                 $j('#profile-rotator').hide();
351                                         });
352                                 });
353                         }
354                 }
355                 break;
356         case 'msg-header':
357         case 'wallmsg-header':
358                 function jotGetLink() {
359                         reply = prompt(window.linkURL);
360                         if(reply && reply.length) {
361                                 $j('#profile-rotator').show();
362                                 $j.get('parse_url?url=' + reply, function(data) {
363                                         tinyMCE.execCommand('mceInsertRawHTML',false,data);
364                                         $j('#profile-rotator').hide();
365                                 });
366                         }
367                 }
368
369                 function linkdrop(event) {
370                         var reply = event.dataTransfer.getData("text/uri-list");
371                         event.target.textContent = reply;
372                         event.preventDefault();
373                         if(reply && reply.length) {
374                                 $j('#profile-rotator').show();
375                                 $j.get('parse_url?url=' + reply, function(data) {
376                                         tinyMCE.execCommand('mceInsertRawHTML',false,data);
377                                         $j('#profile-rotator').hide();
378                                 });
379                         }
380                 }
381
382                 break;
383         default:
384                 break;
385 }
386
387
388 function showEvent(eventid) {
389         $j.get(
390                 baseurl + '/events/?id='+eventid,
391                 function(data){
392                         $j.fancybox(data);
393                 }
394         );                      
395 }
396
397 function initCrop() {
398         function onEndCrop( coords, dimensions ) {
399                 $( 'x1' ).value = coords.x1;
400                 $( 'y1' ).value = coords.y1;
401                 $( 'x2' ).value = coords.x2;
402                 $( 'y2' ).value = coords.y2;
403                 $( 'width' ).value = dimensions.width;
404                 $( 'height' ).value = dimensions.height;
405         }
406
407         Event.observe( window, 'load', function() {
408                 new Cropper.ImgWithPreview(
409                 'croppa',
410                 {
411                         previewWrap: 'previewWrap',
412                         minWidth: 175,
413                         minHeight: 175,
414                         maxWidth: 640,
415                         maxHeight: 640,
416                         ratioDim: { x: 100, y:100 },
417                         displayOnInit: true,
418                         onEndCrop: onEndCrop
419                 });
420         });
421 }
422
423
424 /*
425 $j(document).mouseup(function (clickPos) {
426
427         var sysMenu = $j("#system-menu-list");
428         var sysMenuLink = $j(".system-menu-link");
429         var contactsMenu = $j("#contacts-menu-list");
430         var contactsMenuLink = $j(".contacts-menu-link");
431         var networkMenu = $j("#network-menu-list");
432         var networkMenuLink = $j(".network-menu-link");
433
434         if( !sysMenu.is(clickPos.target) && !sysMenuLink.is(clickPos.target) && sysMenu.has(clickPos.target).length === 0) {
435                 hideNavMenu("#system-menu-list");
436         }
437         if( !contactsMenu.is(clickPos.target) && !contactsMenuLink.is(clickPos.target) && contactsMenu.has(clickPos.target).length === 0) {
438                 hideNavMenu("#contacts-menu-list");
439         }
440         if( !networkMenu.is(clickPos.target) && !networkMenuLink.is(clickPos.target) && networkMenu.has(clickPos.target).length === 0) {
441                 hideNavMenu("#network-menu-list");
442         }
443 });
444
445
446 function getPageContent(url) {
447
448         var pos = $j('.main-container').position();
449
450         $j('.main-container').css('margin-left', pos.left);     
451         $j('.main-content-container').hide(0, function () {
452                 $j('.main-content-loading').show(0);
453         });
454
455         $j.get(url, function(html) {
456                 console.log($j('.main-content-container').html());
457                 $j('.main-content-container').html( $j('.main-content-container', html).html() );
458                 console.log($j('.main-content-container').html());
459                 $j('.main-content-loading').hide(function() {
460                         $j('.main-content-container').fadeIn(800,function() {
461                                 $j('.main-container').css('margin-left', 'auto'); // This sucks -- if the CSS specification changes, this will be wrong
462                         });
463                 });
464         });
465 }
466 */
467
468 function showNavMenu(menuID) {
469
470         if(window.navMenuTimeout[menuID + '-closing']) {
471                 window.navMenuTimeout[menuID + '-closing'] = false;
472                 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
473         }
474         else {
475                 window.navMenuTimeout[menuID + '-opening'] = true;
476                 
477                 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
478                         $j(menuID).slideDown('fast').show();
479                         window.navMenuTimeout[menuID + '-opening'] = false;
480                 }, 200);
481         }
482 }
483
484 function hideNavMenu(menuID) {
485
486         if(window.navMenuTimeout[menuID + '-opening']) {
487                 window.navMenuTimeout[menuID + '-opening'] = false;
488                 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
489         }
490         else {
491                 window.navMenuTimeout[menuID + '-closing'] = true;
492                 
493                 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
494                         $j(menuID).slideUp('fast');
495                         window.navMenuTimeout[menuID + '-closing'] = false;
496                 }, 500);
497         }
498 }
499
500
501
502 function insertFormatting(comment,BBcode,id) {
503         
504                 var tmpStr = $j("#comment-edit-text-" + id).val();
505                 if(tmpStr == comment) {
506                         tmpStr = "";
507                         $j("#comment-edit-text-" + id).addClass("comment-edit-text-full");
508                         $j("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
509                         openMenu("comment-edit-submit-wrapper-" + id);
510                         $j("#comment-edit-text-" + id).val(tmpStr);
511                 }
512
513         textarea = document.getElementById("comment-edit-text-" +id);
514         if (document.selection) {
515                 textarea.focus();
516                 selected = document.selection.createRange();
517                 if (BBcode == "url"){
518                         selected.text = "["+BBcode+"=http://]" +  selected.text + "[/"+BBcode+"]";
519                         } else                  
520                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
521         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
522                 var start = textarea.selectionStart;
523                 var end = textarea.selectionEnd;
524                 if (BBcode == "url"){
525                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"=http://]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
526                         } else
527                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
528         }
529         return true;
530 }
531
532 function cmtBbOpen(id) {
533         $j("#comment-edit-bb-" + id).show();
534 }
535 function cmtBbClose(id) {
536         $j("#comment-edit-bb-" + id).hide();
537 }
538
539 function confirmDelete() { return confirm(window.delItem); }
540
541 function commentOpen(obj,id) {
542         if(obj.value == window.commentEmptyText) {
543                 obj.value = "";
544                 $j("#comment-edit-text-" + id).addClass("comment-edit-text-full");
545                 $j("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
546                 $j("#mod-cmnt-wrap-" + id).show();
547                 openMenu("comment-edit-submit-wrapper-" + id);
548         }
549 }
550 function commentClose(obj,id) {
551         if(obj.value == "") {
552                 obj.value = window.commentEmptyText;
553                 $j("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
554                 $j("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
555                 $j("#mod-cmnt-wrap-" + id).hide();
556                 closeMenu("comment-edit-submit-wrapper-" + id);
557         }
558 }
559
560
561 function commentInsert(obj,id) {
562         var tmpStr = $j("#comment-edit-text-" + id).val();
563         if(tmpStr == window.commentEmptyText) {
564                 tmpStr = "";
565                 $j("#comment-edit-text-" + id).addClass("comment-edit-text-full");
566                 $j("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
567                 openMenu("comment-edit-submit-wrapper-" + id);
568         }
569         var ins = $j(obj).html();
570         ins = ins.replace("&lt;","<");
571         ins = ins.replace("&gt;",">");
572         ins = ins.replace("&amp;","&");
573         ins = ins.replace("&quot;",'"');
574         $j("#comment-edit-text-" + id).val(tmpStr + ins);
575 }
576
577 function qCommentInsert(obj,id) {
578         var tmpStr = $j("#comment-edit-text-" + id).val();
579         if(tmpStr == window.commentEmptyText) {
580                 tmpStr = "";
581                 $j("#comment-edit-text-" + id).addClass("comment-edit-text-full");
582                 $j("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
583                 openMenu("comment-edit-submit-wrapper-" + id);
584         }
585         var ins = $j(obj).val();
586         ins = ins.replace("&lt;","<");
587         ins = ins.replace("&gt;",">");
588         ins = ins.replace("&amp;","&");
589         ins = ins.replace("&quot;",'"');
590         $j("#comment-edit-text-" + id).val(tmpStr + ins);
591         $j(obj).val("");
592 }
593
594 /*function showHideCommentBox(id) {
595         if( $j('#comment-edit-form-' + id).is(':visible')) {
596                 $j('#comment-edit-form-' + id).hide();
597         }
598         else {
599                 $j('#comment-edit-form-' + id).show();
600         }
601 }*/
602
603
604
605 function enableOnUser(){
606         if (editor) return;
607         $j(this).val("");
608         initEditor();
609 }
610
611
612 var editor=false;
613 var textlen = 0;
614 var plaintext = window.editSelect;
615 var ispublic = window.isPublic;
616
617 function initEditor(cb){
618         if (editor==false){
619                 $j("#profile-jot-text-loading").show();
620                 if(plaintext == 'none') {
621                         $j("#profile-jot-text-loading").hide();
622                         $j("#profile-jot-text").css({ 'height': 200, 'color': '#000' });
623                         $j("#profile-jot-text").contact_autocomplete(baseurl+"/acl");
624                         editor = true;
625                         $j("a#jot-perms-icon").fancybox({
626                                 'transitionIn' : 'none', //'elastic',
627                                 'transitionOut' : 'none' //'elastic'
628                         });
629                         $j(".jothidden").show();
630                         if (typeof cb!="undefined") cb();
631                         return;
632                 }
633                 tinyMCE.init({
634                         theme : "advanced",
635                         mode : "specific_textareas",
636                         editor_selector: window.editSelect,
637                         auto_focus: "profile-jot-text",
638                         plugins : "bbcode,paste,autoresize, inlinepopups",
639                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
640                         theme_advanced_buttons2 : "",
641                         theme_advanced_buttons3 : "",
642                         theme_advanced_toolbar_location : "top",
643                         theme_advanced_toolbar_align : "center",
644                         theme_advanced_blockformats : "blockquote,code",
645                         gecko_spellcheck : true,
646                         paste_text_sticky : true,
647                         entity_encoding : "raw",
648                         add_unload_trigger : false,
649                         remove_linebreaks : false,
650                         force_p_newlines : false,
651                         force_br_newlines : true,
652                         forced_root_block : '',
653                         convert_urls: false,
654                         content_css: window.baseURL + "/view/custom_tinymce.css",
655                         theme_advanced_path : false,
656                         file_browser_callback : "fcFileBrowser",
657                         setup : function(ed) {
658                                 cPopup = null;
659                                 ed.onKeyDown.add(function(ed,e) {
660                                         if(cPopup !== null)
661                                                 cPopup.onkey(e);
662                                 });
663
664                                 ed.onKeyUp.add(function(ed, e) {
665                                         var txt = tinyMCE.activeEditor.getContent();
666                                         match = txt.match(/@([^ \n]+)$/);
667                                         if(match!==null) {
668                                                 if(cPopup === null) {
669                                                         cPopup = new ACPopup(this,baseurl+"/acl");
670                                                 }
671                                                 if(cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
672                                                 if(! cPopup.ready) cPopup = null;
673                                         }
674                                         else {
675                                                 if(cPopup !== null) { cPopup.close(); cPopup = null; }
676                                         }
677
678                                         textlen = txt.length;
679                                         if(textlen != 0 && $j('#jot-perms-icon').is('.unlock')) {
680                                                 $j('#profile-jot-desc').html(ispublic);
681                                         }
682                                         else {
683                                                 $j('#profile-jot-desc').html('&nbsp;');
684                                         }        
685
686                                  //Character count
687
688                                         if(textlen <= 140) {
689                                                 $j('#character-counter').removeClass('red');
690                                                 $j('#character-counter').removeClass('orange');
691                                                 $j('#character-counter').addClass('grey');
692                                         }
693                                         if((textlen > 140) && (textlen <= 420)) {
694                                                 $j('#character-counter').removeClass('grey');
695                                                 $j('#character-counter').removeClass('red');
696                                                 $j('#character-counter').addClass('orange');
697                                         }
698                                         if(textlen > 420) {
699                                                 $j('#character-counter').removeClass('grey');
700                                                 $j('#character-counter').removeClass('orange');
701                                                 $j('#character-counter').addClass('red');
702                                         }
703                                         $j('#character-counter').text(textlen);
704                                 });
705
706                                 ed.onInit.add(function(ed) {
707                                         ed.pasteAsPlainText = true;
708                                         $j("#profile-jot-text-loading").hide();
709                                         $j(".jothidden").show();
710                                         if (typeof cb!="undefined") cb();
711                                 });
712
713                         }
714                 });
715                 editor = true;
716                 // setup acl popup
717                 $j("a#jot-perms-icon").fancybox({
718                         'transitionIn' : 'none',
719                         'transitionOut' : 'none'
720                 }); 
721         } else {
722                 if (typeof cb!="undefined") cb();
723         }
724 }
725
726
727 function msgInitEditor() {
728         if(plaintext != 'none') {
729                 tinyMCE.init({
730                         theme : "advanced",
731                         mode : "specific_textareas",
732                         editor_selector: /(profile-jot-text|prvmail-text)/,
733                         plugins : "bbcode,paste",
734                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor",
735                         theme_advanced_buttons2 : "",
736                         theme_advanced_buttons3 : "",
737                         theme_advanced_toolbar_location : "top",
738                         theme_advanced_toolbar_align : "center",
739                         theme_advanced_blockformats : "blockquote,code",
740                         gecko_spellcheck : true,
741                         paste_text_sticky : true,
742                         entity_encoding : "raw",
743                         add_unload_trigger : false,
744                         remove_linebreaks : false,
745                         force_p_newlines : false,
746                         force_br_newlines : true,
747                         forced_root_block : '',
748                         convert_urls: false,
749                         content_css: baseurl + "/view/custom_tinymce.css",
750                              //Character count
751                         theme_advanced_path : false,
752                         setup : function(ed) {
753                                 ed.onInit.add(function(ed) {
754                                         ed.pasteAsPlainText = true;
755                                         var editorId = ed.editorId;
756                                         var textarea = $j('#'+editorId);
757                                         if (typeof(textarea.attr('tabindex')) != "undefined") {
758                                                 $j('#'+editorId+'_ifr').attr('tabindex', textarea.attr('tabindex'));
759                                                 textarea.attr('tabindex', null);
760                                         }
761                                 });
762                         }
763                 });
764         }
765         else
766                 $j("#prvmail-text").contact_autocomplete(baseurl+"/acl");
767 }
768
769
770 function profInitEditor() {
771         tinyMCE.init({
772                 theme : "advanced",
773                 mode : window.editSelect,
774                 plugins : "bbcode,paste",
775                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
776                 theme_advanced_buttons2 : "",
777                 theme_advanced_buttons3 : "",
778                 theme_advanced_toolbar_location : "top",
779                 theme_advanced_toolbar_align : "center",
780                 theme_advanced_blockformats : "blockquote,code",
781                 gecko_spellcheck : true,
782                 paste_text_sticky : true,
783                 entity_encoding : "raw",
784                 add_unload_trigger : false,
785                 remove_linebreaks : false,
786                 force_p_newlines : false,
787                 force_br_newlines : true,
788                 forced_root_block : '',
789                 content_css: baseurl + "/view/custom_tinymce.css",
790                 theme_advanced_path : false,
791                 setup : function(ed) {
792                         ed.onInit.add(function(ed) {
793                         ed.pasteAsPlainText = true;
794                     });
795                 }
796
797         });
798 }
799
800 function eventInitEditor() {
801         tinyMCE.init({
802                 theme : "advanced",
803                 mode : "textareas",
804                 plugins : "bbcode,paste",
805                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
806                 theme_advanced_buttons2 : "",
807                 theme_advanced_buttons3 : "",
808                 theme_advanced_toolbar_location : "top",
809                 theme_advanced_toolbar_align : "center",
810                 theme_advanced_blockformats : "blockquote,code",
811                 gecko_spellcheck : true,
812                 paste_text_sticky : true,
813                 entity_encoding : "raw",
814                 add_unload_trigger : false,
815                 remove_linebreaks : false,
816                 force_p_newlines : false,
817                 force_br_newlines : true,
818                 forced_root_block : '',
819                 content_css: baseurl + "/view/custom_tinymce.css",
820                 theme_advanced_path : false,
821                 setup : function(ed) {
822                         ed.onInit.add(function(ed) {
823                                 ed.pasteAsPlainText = true;
824                         });
825                 }
826
827         });
828 }
829
830 function contactInitEditor () {
831         tinyMCE.init({
832                 theme : "advanced",
833                 mode : window.editSelect,
834                 elements: "contact-edit-info",
835                 plugins : "bbcode",
836                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor",
837                 theme_advanced_buttons2 : "",
838                 theme_advanced_buttons3 : "",
839                 theme_advanced_toolbar_location : "top",
840                 theme_advanced_toolbar_align : "center",
841                 theme_advanced_styles : "blockquote,code",
842                 gecko_spellcheck : true,
843                 entity_encoding : "raw",
844                 add_unload_trigger : false,
845                 remove_linebreaks : false,
846                 force_p_newlines : false,
847                 force_br_newlines : true,
848                 forced_root_block : '',
849                 content_css: baseurl + "/view/custom_tinymce.css"
850
851
852         });
853 }
854
855 function wallInitEditor() {
856         var plaintext = window.editSelect;
857
858         if(plaintext != 'none') {
859                 tinyMCE.init({
860                         theme : "advanced",
861                         mode : "specific_textareas",
862                         editor_selector: /(profile-jot-text|prvmail-text)/,
863                         plugins : "bbcode,paste",
864                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor",
865                         theme_advanced_buttons2 : "",
866                         theme_advanced_buttons3 : "",
867                         theme_advanced_toolbar_location : "top",
868                         theme_advanced_toolbar_align : "center",
869                         theme_advanced_blockformats : "blockquote,code",
870                         gecko_spellcheck : true,
871                         paste_text_sticky : true,
872                         entity_encoding : "raw",
873                         add_unload_trigger : false,
874                         remove_linebreaks : false,
875                         force_p_newlines : false,
876                         force_br_newlines : true,
877                         forced_root_block : '',
878                         convert_urls: false,
879                         content_css: baseurl + "/view/custom_tinymce.css",
880                                  //Character count
881                         theme_advanced_path : false,
882                         setup : function(ed) {
883                                 ed.onInit.add(function(ed) {
884                                         ed.pasteAsPlainText = true;
885                                         var editorId = ed.editorId;
886                                         var textarea = $j('#'+editorId);
887                                         if (typeof(textarea.attr('tabindex')) != "undefined") {
888                                                 $j('#'+editorId+'_ifr').attr('tabindex', textarea.attr('tabindex'));
889                                                 textarea.attr('tabindex', null);
890                                         }
891                                 });
892                         }
893                 });
894         }
895         else
896                 $j("#prvmail-text").contact_autocomplete(baseurl+"/acl");
897 }
898
899 function deleteCheckedItems(delID) {
900         if(confirm(window.delItems)) {
901                 var checkedstr = '';
902
903                 $j(delID).hide();
904                 $j(delID + '-rotator').show();
905                 $j('.item-select').each( function() {
906                         if($j(this).is(':checked')) {
907                                 if(checkedstr.length != 0) {
908                                         checkedstr = checkedstr + ',' + $j(this).val();
909                                 }
910                                 else {
911                                         checkedstr = $j(this).val();
912                                 }
913                         }       
914                 });
915                 $j.post('item', { dropitems: checkedstr }, function(data) {
916                         window.location.reload();
917                 });
918         }
919 }
920
921
922 function jotVideoURL() {
923         reply = prompt(window.vidURL);
924         if(reply && reply.length) {
925                 addeditortext('[video]' + reply + '[/video]');
926         }
927 }
928
929 function jotAudioURL() {
930         reply = prompt(window.audURL);
931         if(reply && reply.length) {
932                 addeditortext('[audio]' + reply + '[/audio]');
933         }
934 }
935
936
937 function jotGetLocation() {
938
939 /*      if(navigator.geolocation) {
940
941                 navigator.geolocation.getCurrentPosition(function(position) {
942                         var lat = position.coords.latitude;
943                         var lng = position.coords.longitude;
944
945                         $j.ajax({
946                                 type: 'GET',
947                                 url: 'http://nominatim.openstreetmap.org/reverse?format=json&lat='+lat+'&lon='+lng,
948                                 jsonp: 'json_callback',
949                                 contentType: 'application/json',
950                                 dataType: 'jsonp',
951                                 success: function(json) {
952                                         console.log(json);
953                                         var locationDisplay = json.address.building+', '+json.address.city+', '+json.address.state;
954                                         $j('#jot-location').val(locationDisplay);
955                                         $j('#jot-display-location').html('Location: '+locationDisplay);
956                                         $j('#jot-display-location').show();
957                                 }
958                         });
959                 });
960
961         }
962         else {
963                 reply = prompt(window.whereAreU, $j('#jot-location').val());
964                 if(reply && reply.length) {
965                         $j('#jot-location').val(reply);
966                 }
967         }*/
968
969         reply = prompt(window.whereAreU, $j('#jot-location').val());
970         if(reply && reply.length) {
971                 $j('#jot-location').val(reply);
972         }
973 }
974
975 function jotShare(id) {
976         if ($j('#jot-popup').length != 0) $j('#jot-popup').show();
977
978         $j('#like-rotator-' + id).show();
979         $j.get('share/' + id, function(data) {
980                 if (!editor) $j("#profile-jot-text").val("");
981                 initEditor(function(){
982                         addeditortext(data);
983                         $j('#like-rotator-' + id).hide();
984                         $j(window).scrollTop(0);
985                 });
986
987         });
988 }
989
990 function linkdropper(event) {
991         var linkFound = event.dataTransfer.types.contains("text/uri-list");
992         if(linkFound)
993                 event.preventDefault();
994 }
995
996 function itemTag(id) {
997         reply = prompt(window.term);
998         if(reply && reply.length) {
999                 reply = reply.replace('#','');
1000                 if(reply.length) {
1001
1002                         commentBusy = true;
1003                         $j('body').css('cursor', 'wait');
1004
1005                         $j.get('tagger/' + id + '?term=' + reply, NavUpdate);
1006                         /*if(timer) clearTimeout(timer);
1007                         timer = setTimeout(NavUpdate,3000);*/
1008                         liking = 1;
1009                 }
1010         }
1011 }
1012
1013 function itemFiler(id) {
1014         
1015         var bordercolor = $j("input").css("border-color");
1016         
1017         $j.get('filer/', function(data){
1018                 $j.fancybox(data);
1019                 $j("#id_term").keypress(function(){
1020                         $j(this).css("border-color",bordercolor);
1021                 })
1022                 $j("#select_term").change(function(){
1023                         $j("#id_term").css("border-color",bordercolor);
1024                 })
1025                 
1026                 $j("#filer_save").click(function(e){
1027                         e.preventDefault();
1028                         reply = $j("#id_term").val();
1029                         if(reply && reply.length) {
1030                                 commentBusy = true;
1031                                 $j('body').css('cursor', 'wait');
1032                                 $j.get('filer/' + id + '?term=' + reply, NavUpdate);
1033 /*                                      if(timer) clearTimeout(timer);
1034                                 timer = setTimeout(NavUpdate,3000);*/
1035                                 liking = 1;
1036                                 $j.fancybox.close();
1037                         } else {
1038                                 $j("#id_term").css("border-color","#FF0000");
1039                         }
1040                         return false;
1041                 });
1042         });
1043         
1044 }
1045
1046 function jotClearLocation() {
1047         $j('#jot-coord').val('');
1048         $j('#profile-nolocation-wrapper').hide();
1049 }
1050
1051 function addeditortext(data) {
1052         if(plaintext == 'none') {
1053                 var currentText = $j("#profile-jot-text").val();
1054                 $j("#profile-jot-text").val(currentText + data);
1055         }
1056         else
1057                 tinyMCE.execCommand('mceInsertRawHTML',false,data);
1058 }
1059
1060 if(typeof window.geoTag === 'function') window.geoTag();
1061
1062