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