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