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