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