]> git.mxchange.org Git - friendica.git/blob - view/theme/frost/js/theme.js
various bug fixes
[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-link').hover(function() {
33                 showNavMenu($j(this).attr('rel'));
34         }, function() {
35                 hideNavMenu($j(this).attr('rel'));
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 if(typeof window.photoEdit != 'undefined') {
309
310         $j(document).keydown(function(event) {
311
312                         if(window.prevLink != '') { if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = window.prevLink; }}
313                         if(window.nextLink != '') { if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = window.nextLink; }}
314
315         });
316 }
317
318 switch(window.ajaxType) {
319         case 'jot-header':
320                 function jotGetLink() {
321                         reply = prompt(window.linkURL);
322                         if(reply && reply.length) {
323                                 reply = bin2hex(reply);
324                                 $j('#profile-rotator').show();
325                                 $j.get('parse_url?binurl=' + reply, function(data) {
326                                         addeditortext(data);
327                                         $j('#profile-rotator').hide();
328                                 });
329                         }
330                 }
331
332                 function linkdrop(event) {
333                         var reply = event.dataTransfer.getData("text/uri-list");
334                         event.target.textContent = reply;
335                         event.preventDefault();
336                         if(reply && reply.length) {
337                                 reply = bin2hex(reply);
338                                 $j('#profile-rotator').show();
339                                 $j.get('parse_url?binurl=' + reply, function(data) {
340                                         if (!editor) $j("#profile-jot-text").val("");
341                                         initEditor(function(){
342                                                 addeditortext(data);
343                                                 $j('#profile-rotator').hide();
344                                         });
345                                 });
346                         }
347                 }
348                 break;
349         case 'msg-header':
350         case 'wallmsg-header':
351                 function jotGetLink() {
352                         reply = prompt(window.linkURL);
353                         if(reply && reply.length) {
354                                 $j('#profile-rotator').show();
355                                 $j.get('parse_url?url=' + reply, function(data) {
356                                         tinyMCE.execCommand('mceInsertRawHTML',false,data);
357                                         $j('#profile-rotator').hide();
358                                 });
359                         }
360                 }
361
362                 function linkdrop(event) {
363                         var reply = event.dataTransfer.getData("text/uri-list");
364                         event.target.textContent = reply;
365                         event.preventDefault();
366                         if(reply && reply.length) {
367                                 $j('#profile-rotator').show();
368                                 $j.get('parse_url?url=' + reply, function(data) {
369                                         tinyMCE.execCommand('mceInsertRawHTML',false,data);
370                                         $j('#profile-rotator').hide();
371                                 });
372                         }
373                 }
374
375                 break;
376         default:
377                 break;
378 }
379
380
381 function showEvent(eventid) {
382         $j.get(
383                 baseurl + '/events/?id='+eventid,
384                 function(data){
385                         $j.fancybox(data);
386                 }
387         );                      
388 }
389
390 function initCrop() {
391         function onEndCrop( coords, dimensions ) {
392                 $( 'x1' ).value = coords.x1;
393                 $( 'y1' ).value = coords.y1;
394                 $( 'x2' ).value = coords.x2;
395                 $( 'y2' ).value = coords.y2;
396                 $( 'width' ).value = dimensions.width;
397                 $( 'height' ).value = dimensions.height;
398         }
399
400         Event.observe( window, 'load', function() {
401                 new Cropper.ImgWithPreview(
402                 'croppa',
403                 {
404                         previewWrap: 'previewWrap',
405                         minWidth: 175,
406                         minHeight: 175,
407                         maxWidth: 640,
408                         maxHeight: 640,
409                         ratioDim: { x: 100, y:100 },
410                         displayOnInit: true,
411                         onEndCrop: onEndCrop
412                 });
413         });
414 }
415
416
417 /*
418 $j(document).mouseup(function (clickPos) {
419
420         var sysMenu = $j("#system-menu-list");
421         var sysMenuLink = $j(".system-menu-link");
422         var contactsMenu = $j("#contacts-menu-list");
423         var contactsMenuLink = $j(".contacts-menu-link");
424         var networkMenu = $j("#network-menu-list");
425         var networkMenuLink = $j(".network-menu-link");
426
427         if( !sysMenu.is(clickPos.target) && !sysMenuLink.is(clickPos.target) && sysMenu.has(clickPos.target).length === 0) {
428                 hideNavMenu("#system-menu-list");
429         }
430         if( !contactsMenu.is(clickPos.target) && !contactsMenuLink.is(clickPos.target) && contactsMenu.has(clickPos.target).length === 0) {
431                 hideNavMenu("#contacts-menu-list");
432         }
433         if( !networkMenu.is(clickPos.target) && !networkMenuLink.is(clickPos.target) && networkMenu.has(clickPos.target).length === 0) {
434                 hideNavMenu("#network-menu-list");
435         }
436 });
437
438
439 function getPageContent(url) {
440
441         var pos = $j('.main-container').position();
442
443         $j('.main-container').css('margin-left', pos.left);     
444         $j('.main-content-container').hide(0, function () {
445                 $j('.main-content-loading').show(0);
446         });
447
448         $j.get(url, function(html) {
449                 console.log($j('.main-content-container').html());
450                 $j('.main-content-container').html( $j('.main-content-container', html).html() );
451                 console.log($j('.main-content-container').html());
452                 $j('.main-content-loading').hide(function() {
453                         $j('.main-content-container').fadeIn(800,function() {
454                                 $j('.main-container').css('margin-left', 'auto'); // This sucks -- if the CSS specification changes, this will be wrong
455                         });
456                 });
457         });
458 }
459 */
460
461 function showNavMenu(menuID) {
462
463         if(window.navMenuTimeout[menuID + '-closing']) {
464                 window.navMenuTimeout[menuID + '-closing'] = false;
465                 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
466         }
467         else {
468                 window.navMenuTimeout[menuID + '-opening'] = true;
469                 
470                 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
471                         $j(menuID).slideDown('fast').show();
472                         window.navMenuTimeout[menuID + '-opening'] = false;
473                 }, 200);
474         }
475 }
476
477 function hideNavMenu(menuID) {
478
479         if(window.navMenuTimeout[menuID + '-opening']) {
480                 window.navMenuTimeout[menuID + '-opening'] = false;
481                 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
482         }
483         else {
484                 window.navMenuTimeout[menuID + '-closing'] = true;
485                 
486                 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
487                         $j(menuID).slideUp('fast');
488                         window.navMenuTimeout[menuID + '-closing'] = false;
489                 }, 500);
490         }
491 }
492
493
494
495 function insertFormatting(comment,BBcode,id) {
496         
497                 var tmpStr = $j("#comment-edit-text-" + id).val();
498                 if(tmpStr == comment) {
499                         tmpStr = "";
500                         $j("#comment-edit-text-" + id).addClass("comment-edit-text-full");
501                         $j("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
502                         openMenu("comment-edit-submit-wrapper-" + id);
503                         $j("#comment-edit-text-" + id).val(tmpStr);
504                 }
505
506         textarea = document.getElementById("comment-edit-text-" +id);
507         if (document.selection) {
508                 textarea.focus();
509                 selected = document.selection.createRange();
510                 if (BBcode == "url"){
511                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
512                         } else                  
513                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
514         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
515                 var start = textarea.selectionStart;
516                 var end = textarea.selectionEnd;
517                 if (BBcode == "url"){
518                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
519                         } else
520                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
521         }
522         return true;
523 }
524
525 function cmtBbOpen(id) {
526         $j("#comment-edit-bb-" + id).show();
527 }
528 function cmtBbClose(id) {
529         $j("#comment-edit-bb-" + id).hide();
530 }
531
532 function confirmDelete() { return confirm(window.delItem); }
533
534 function commentOpen(obj,id) {
535         if(obj.value == window.commentEmptyText) {
536                 obj.value = "";
537                 $j("#comment-edit-text-" + id).addClass("comment-edit-text-full");
538                 $j("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
539                 $j("#mod-cmnt-wrap-" + id).show();
540                 openMenu("comment-edit-submit-wrapper-" + id);
541         }
542 }
543 function commentClose(obj,id) {
544         if(obj.value == "") {
545                 obj.value = window.commentEmptyText;
546                 $j("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
547                 $j("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
548                 $j("#mod-cmnt-wrap-" + id).hide();
549                 closeMenu("comment-edit-submit-wrapper-" + id);
550         }
551 }
552
553
554 function commentInsert(obj,id) {
555         var tmpStr = $j("#comment-edit-text-" + id).val();
556         if(tmpStr == window.commentEmptyText) {
557                 tmpStr = "";
558                 $j("#comment-edit-text-" + id).addClass("comment-edit-text-full");
559                 $j("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
560                 openMenu("comment-edit-submit-wrapper-" + id);
561         }
562         var ins = $j(obj).html();
563         ins = ins.replace("&lt;","<");
564         ins = ins.replace("&gt;",">");
565         ins = ins.replace("&amp;","&");
566         ins = ins.replace("&quot;",'"');
567         $j("#comment-edit-text-" + id).val(tmpStr + ins);
568 }
569
570 function qCommentInsert(obj,id) {
571         var tmpStr = $j("#comment-edit-text-" + id).val();
572         if(tmpStr == window.commentEmptyText) {
573                 tmpStr = "";
574                 $j("#comment-edit-text-" + id).addClass("comment-edit-text-full");
575                 $j("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
576                 openMenu("comment-edit-submit-wrapper-" + id);
577         }
578         var ins = $j(obj).val();
579         ins = ins.replace("&lt;","<");
580         ins = ins.replace("&gt;",">");
581         ins = ins.replace("&amp;","&");
582         ins = ins.replace("&quot;",'"');
583         $j("#comment-edit-text-" + id).val(tmpStr + ins);
584         $j(obj).val("");
585 }
586
587 function showHideComments(id) {
588         if( $j("#collapsed-comments-" + id).is(":visible")) {
589                 $j("#collapsed-comments-" + id).hide();
590                 $j("#hide-comments-" + id).html(window.showMore);
591         }
592         else {
593                 $j("#collapsed-comments-" + id).show();
594                 $j("#hide-comments-" + id).html(window.showFewer);
595         }
596 }
597
598 /*function showHideCommentBox(id) {
599         if( $j('#comment-edit-form-' + id).is(':visible')) {
600                 $j('#comment-edit-form-' + id).hide();
601         }
602         else {
603                 $j('#comment-edit-form-' + id).show();
604         }
605 }*/
606
607
608
609 function enableOnUser(){
610         if (editor) return;
611         $j(this).val("");
612         initEditor();
613 }
614
615
616 var editor=false;
617 var textlen = 0;
618 var plaintext = window.editSelect;
619 var ispublic = window.isPublic;
620
621 function initEditor(cb){
622         if (editor==false){
623                 $j("#profile-jot-text-loading").show();
624                 if(plaintext == 'none') {
625                         $j("#profile-jot-text-loading").hide();
626                         $j("#profile-jot-text").css({ 'height': 200, 'color': '#000' });
627                         $j("#profile-jot-text").contact_autocomplete(baseurl+"/acl");
628                         editor = true;
629                         $j("a#jot-perms-icon").fancybox({
630                                 'transitionIn' : 'elastic',
631                                 'transitionOut' : 'elastic'
632                         });
633                         $j(".jothidden").show();
634                         if (typeof cb!="undefined") cb();
635                         return;
636                 }
637                 tinyMCE.init({
638                         theme : "advanced",
639                         mode : "specific_textareas",
640                         editor_selector: window.editSelect,
641                         auto_focus: "profile-jot-text",
642                         plugins : "bbcode,paste,autoresize, inlinepopups",
643                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
644                         theme_advanced_buttons2 : "",
645                         theme_advanced_buttons3 : "",
646                         theme_advanced_toolbar_location : "top",
647                         theme_advanced_toolbar_align : "center",
648                         theme_advanced_blockformats : "blockquote,code",
649                         gecko_spellcheck : true,
650                         paste_text_sticky : true,
651                         entity_encoding : "raw",
652                         add_unload_trigger : false,
653                         remove_linebreaks : false,
654                         force_p_newlines : false,
655                         force_br_newlines : true,
656                         forced_root_block : '',
657                         convert_urls: false,
658                         content_css: window.baseURL + "/view/custom_tinymce.css",
659                         theme_advanced_path : false,
660                         file_browser_callback : "fcFileBrowser",
661                         setup : function(ed) {
662                                 cPopup = null;
663                                 ed.onKeyDown.add(function(ed,e) {
664                                         if(cPopup !== null)
665                                                 cPopup.onkey(e);
666                                 });
667
668                                 ed.onKeyUp.add(function(ed, e) {
669                                         var txt = tinyMCE.activeEditor.getContent();
670                                         match = txt.match(/@([^ \n]+)$/);
671                                         if(match!==null) {
672                                                 if(cPopup === null) {
673                                                         cPopup = new ACPopup(this,baseurl+"/acl");
674                                                 }
675                                                 if(cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
676                                                 if(! cPopup.ready) cPopup = null;
677                                         }
678                                         else {
679                                                 if(cPopup !== null) { cPopup.close(); cPopup = null; }
680                                         }
681
682                                         textlen = txt.length;
683                                         if(textlen != 0 && $j('#jot-perms-icon').is('.unlock')) {
684                                                 $j('#profile-jot-desc').html(ispublic);
685                                         }
686                                         else {
687                                                 $j('#profile-jot-desc').html('&nbsp;');
688                                         }        
689
690                                  //Character count
691
692                                         if(textlen <= 140) {
693                                                 $j('#character-counter').removeClass('red');
694                                                 $j('#character-counter').removeClass('orange');
695                                                 $j('#character-counter').addClass('grey');
696                                         }
697                                         if((textlen > 140) && (textlen <= 420)) {
698                                                 $j('#character-counter').removeClass('grey');
699                                                 $j('#character-counter').removeClass('red');
700                                                 $j('#character-counter').addClass('orange');
701                                         }
702                                         if(textlen > 420) {
703                                                 $j('#character-counter').removeClass('grey');
704                                                 $j('#character-counter').removeClass('orange');
705                                                 $j('#character-counter').addClass('red');
706                                         }
707                                         $j('#character-counter').text(textlen);
708                                 });
709
710                                 ed.onInit.add(function(ed) {
711                                         ed.pasteAsPlainText = true;
712                                         $j("#profile-jot-text-loading").hide();
713                                         $j(".jothidden").show();
714                                         if (typeof cb!="undefined") cb();
715                                 });
716
717                         }
718                 });
719                 editor = true;
720                 // setup acl popup
721                 $j("a#jot-perms-icon").fancybox({
722                         'transitionIn' : 'none',
723                         'transitionOut' : 'none'
724                 }); 
725         } else {
726                 if (typeof cb!="undefined") cb();
727         }
728 }
729
730
731 function msgInitEditor() {
732         if(plaintext != 'none') {
733                 tinyMCE.init({
734                         theme : "advanced",
735                         mode : "specific_textareas",
736                         editor_selector: /(profile-jot-text|prvmail-text)/,
737                         plugins : "bbcode,paste",
738                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor",
739                         theme_advanced_buttons2 : "",
740                         theme_advanced_buttons3 : "",
741                         theme_advanced_toolbar_location : "top",
742                         theme_advanced_toolbar_align : "center",
743                         theme_advanced_blockformats : "blockquote,code",
744                         gecko_spellcheck : true,
745                         paste_text_sticky : true,
746                         entity_encoding : "raw",
747                         add_unload_trigger : false,
748                         remove_linebreaks : false,
749                         force_p_newlines : false,
750                         force_br_newlines : true,
751                         forced_root_block : '',
752                         convert_urls: false,
753                         content_css: baseurl + "/view/custom_tinymce.css",
754                              //Character count
755                         theme_advanced_path : false,
756                         setup : function(ed) {
757                                 ed.onInit.add(function(ed) {
758                                         ed.pasteAsPlainText = true;
759                                         var editorId = ed.editorId;
760                                         var textarea = $j('#'+editorId);
761                                         if (typeof(textarea.attr('tabindex')) != "undefined") {
762                                                 $j('#'+editorId+'_ifr').attr('tabindex', textarea.attr('tabindex'));
763                                                 textarea.attr('tabindex', null);
764                                         }
765                                 });
766                         }
767                 });
768         }
769         else
770                 $j("#prvmail-text").contact_autocomplete(baseurl+"/acl");
771 }
772
773
774 function profInitEditor() {
775         tinyMCE.init({
776                 theme : "advanced",
777                 mode : window.editSelect,
778                 plugins : "bbcode,paste",
779                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
780                 theme_advanced_buttons2 : "",
781                 theme_advanced_buttons3 : "",
782                 theme_advanced_toolbar_location : "top",
783                 theme_advanced_toolbar_align : "center",
784                 theme_advanced_blockformats : "blockquote,code",
785                 gecko_spellcheck : true,
786                 paste_text_sticky : true,
787                 entity_encoding : "raw",
788                 add_unload_trigger : false,
789                 remove_linebreaks : false,
790                 force_p_newlines : false,
791                 force_br_newlines : true,
792                 forced_root_block : '',
793                 content_css: baseurl + "/view/custom_tinymce.css",
794                 theme_advanced_path : false,
795                 setup : function(ed) {
796                         ed.onInit.add(function(ed) {
797                         ed.pasteAsPlainText = true;
798                     });
799                 }
800
801         });
802 }
803
804 function eventInitEditor() {
805         tinyMCE.init({
806                 theme : "advanced",
807                 mode : "textareas",
808                 plugins : "bbcode,paste",
809                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
810                 theme_advanced_buttons2 : "",
811                 theme_advanced_buttons3 : "",
812                 theme_advanced_toolbar_location : "top",
813                 theme_advanced_toolbar_align : "center",
814                 theme_advanced_blockformats : "blockquote,code",
815                 gecko_spellcheck : true,
816                 paste_text_sticky : true,
817                 entity_encoding : "raw",
818                 add_unload_trigger : false,
819                 remove_linebreaks : false,
820                 force_p_newlines : false,
821                 force_br_newlines : true,
822                 forced_root_block : '',
823                 content_css: baseurl + "/view/custom_tinymce.css",
824                 theme_advanced_path : false,
825                 setup : function(ed) {
826                         ed.onInit.add(function(ed) {
827                                 ed.pasteAsPlainText = true;
828                         });
829                 }
830
831         });
832 }
833
834 function contactInitEditor () {
835         tinyMCE.init({
836                 theme : "advanced",
837                 mode : window.editSelect,
838                 elements: "contact-edit-info",
839                 plugins : "bbcode",
840                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor",
841                 theme_advanced_buttons2 : "",
842                 theme_advanced_buttons3 : "",
843                 theme_advanced_toolbar_location : "top",
844                 theme_advanced_toolbar_align : "center",
845                 theme_advanced_styles : "blockquote,code",
846                 gecko_spellcheck : true,
847                 entity_encoding : "raw",
848                 add_unload_trigger : false,
849                 remove_linebreaks : false,
850                 force_p_newlines : false,
851                 force_br_newlines : true,
852                 forced_root_block : '',
853                 content_css: baseurl + "/view/custom_tinymce.css"
854
855
856         });
857 }
858
859 function wallInitEditor() {
860         var plaintext = window.editSelect;
861
862         if(plaintext != 'none') {
863                 tinyMCE.init({
864                         theme : "advanced",
865                         mode : "specific_textareas",
866                         editor_selector: /(profile-jot-text|prvmail-text)/,
867                         plugins : "bbcode,paste",
868                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor",
869                         theme_advanced_buttons2 : "",
870                         theme_advanced_buttons3 : "",
871                         theme_advanced_toolbar_location : "top",
872                         theme_advanced_toolbar_align : "center",
873                         theme_advanced_blockformats : "blockquote,code",
874                         gecko_spellcheck : true,
875                         paste_text_sticky : true,
876                         entity_encoding : "raw",
877                         add_unload_trigger : false,
878                         remove_linebreaks : false,
879                         force_p_newlines : false,
880                         force_br_newlines : true,
881                         forced_root_block : '',
882                         convert_urls: false,
883                         content_css: baseurl + "/view/custom_tinymce.css",
884                                  //Character count
885                         theme_advanced_path : false,
886                         setup : function(ed) {
887                                 ed.onInit.add(function(ed) {
888                                         ed.pasteAsPlainText = true;
889                                         var editorId = ed.editorId;
890                                         var textarea = $j('#'+editorId);
891                                         if (typeof(textarea.attr('tabindex')) != "undefined") {
892                                                 $j('#'+editorId+'_ifr').attr('tabindex', textarea.attr('tabindex'));
893                                                 textarea.attr('tabindex', null);
894                                         }
895                                 });
896                         }
897                 });
898         }
899         else
900                 $j("#prvmail-text").contact_autocomplete(baseurl+"/acl");
901 }
902
903 function deleteCheckedItems() {
904         var checkedstr = '';
905
906         $j('.item-select').each( function() {
907                 if($j(this).is(':checked')) {
908                         if(checkedstr.length != 0) {
909                                 checkedstr = checkedstr + ',' + $j(this).val();
910                         }
911                         else {
912                                 checkedstr = $j(this).val();
913                         }
914                 }       
915         });
916         $j.post('item', { dropitems: checkedstr }, function(data) {
917                 window.location.reload();
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