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