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