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