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