1 $(document).ready(function() {
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
15 /* enable tinymce on focus and click */
16 $("#profile-jot-text").focus(enableOnUser);
17 $("#profile-jot-text").click(enableOnUser);
19 $('.nav-menu-list, .nav-menu-icon').hover(function() {
20 showNavMenu($(this).attr('point'));
22 hideNavMenu($(this).attr('point'));
25 $('.group-edit-icon').hover(
27 $(this).addClass('icon'); $(this).removeClass('iconspacer');},
29 $(this).removeClass('icon'); $(this).addClass('iconspacer');}
32 $('.sidebar-group-element').hover(
34 id = $(this).attr('id');
35 $('#edit-' + id).addClass('icon'); $('#edit-' + id).removeClass('iconspacer');},
38 id = $(this).attr('id');
39 $('#edit-' + id).removeClass('icon');$('#edit-' + id).addClass('iconspacer');}
43 $('.savedsearchdrop').hover(
45 $(this).addClass('drop'); $(this).addClass('icon'); $(this).removeClass('iconspacer');},
47 $(this).removeClass('drop'); $(this).removeClass('icon'); $(this).addClass('iconspacer');}
50 $('.savedsearchterm').hover(
52 id = $(this).attr('id');
53 $('#drop-' + id).addClass('icon'); $('#drop-' + id).addClass('drophide'); $('#drop-' + id).removeClass('iconspacer');},
56 id = $(this).attr('id');
57 $('#drop-' + id).removeClass('icon');$('#drop-' + id).removeClass('drophide'); $('#drop-' + id).addClass('iconspacer');}
60 $('#id_share').change(function() {
62 if ($('#id_share').is(':checked')) {
63 $('#acl-wrapper').show();
65 $('#acl-wrapper').hide();
69 if (typeof window.AjaxUpload != "undefined") {
70 var uploader = new window.AjaxUpload(
71 window.imageUploadButton,
72 { action: 'wall_upload/'+window.nickname,
74 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
75 onComplete: function(file,response) {
76 addeditortext(window.jotId, response);
77 $('#profile-rotator').hide();
82 if ($('#wall-file-upload').length) {
83 var file_uploader = new window.AjaxUpload(
85 { action: 'wall_attach/'+window.nickname,
87 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
88 onComplete: function(file,response) {
89 addeditortext(window.jotId, response);
90 $('#profile-rotator').hide();
98 if (typeof window.aclInit !="undefined" && typeof acl=="undefined") {
101 [ window.allowCID,window.allowGID,window.denyCID,window.denyGID ]
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() {
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();
114 if (selstr == null) {
115 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
116 $('#jot-public').show();
119 }).trigger('change');
122 if (window.aclType == "event_head") {
123 $('#events-calendar').fullCalendar({
124 events: baseurl + window.eventModuleUrl +'/json/',
126 left: 'prev,next today',
128 right: 'month,agendaWeek,agendaDay'
130 timeFormat: 'H(:mm)',
131 eventClick: function(calEvent, jsEvent, view) {
132 showEvent(calEvent.id);
134 loading: function(isLoading, view) {
136 $('td.fc-day').dblclick(function() { window.location.href='/events/new?start='+$(this).data('date'); });
140 eventRender: function(event, element, view) {
141 //console.log(view.name);
142 if (event.item['author-name']==null) return;
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'],
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'],
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'],
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);
184 var hash = location.hash.split("-")
185 if (hash.length==2 && hash[0]=="#link") showEvent(hash[1]);
189 switch(window.autocompleteType) {
191 $("#recip").name_autocomplete(baseurl + '/acl', '', false, function(data) {
192 $("#recip-complete").val(data.id);
195 case 'contacts-head':
196 $("#contacts-search").contact_autocomplete(baseurl + '/acl', 'a', true);
199 $("#contacts-search").keyup(function(event) {
200 if (event.keyCode == 13) {
201 $("#contacts-search").click();
204 $(".autocomplete-w1 .selected").keyup(function(event) {
205 if (event.keyCode == 13) {
206 $("#contacts-search").click();
211 $(".comment-wwedit-wrapper textarea").editor_autocomplete(baseurl+"/acl");
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");
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]+?)?$/)) {
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);
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]
243 // update pending count //
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(); }
257 $("#cnftheme").click(function() {
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...
267 $(this).find("input").each(function() {
268 data[$(this).attr('name')] = $(this).val();
270 $(this).find("select").each(function() {
271 data[$(this).attr('name')] = $(this).children(":selected").val();
273 console.log(":)", url, data);
275 $.post(url, data, function(data) {
293 function homeRedirect() {
294 $('html').fadeOut('slow', function() {
295 window.location = baseurl + "/login";
300 if (typeof window.photoEdit != 'undefined') {
302 $(document).keydown(function(event) {
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; }}
310 function showEvent(eventid) {
312 baseurl + window.eventModuleUrl + '/?id=' + eventid,
314 $.colorbox({html:data});
320 function doEventPreview() {
321 $('#event-edit-preview').val(1);
322 $.post('events',$('#event-edit-form').serialize(), function(data) {
323 $.colorbox({ html: data });
325 $('#event-edit-preview').val(0);
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;
338 Event.observe( window, 'load', function() {
339 new Cropper.ImgWithPreview(
342 previewWrap: 'previewWrap',
347 ratioDim: { x: 100, y:100 },
354 function showNavMenu(menuID) {
356 if (window.navMenuTimeout[menuID + '-closing']) {
357 window.navMenuTimeout[menuID + '-closing'] = false;
358 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
360 window.navMenuTimeout[menuID + '-opening'] = true;
362 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
363 $(menuID).slideDown('fast').show();
364 window.navMenuTimeout[menuID + '-opening'] = false;
369 function hideNavMenu(menuID) {
371 if (window.navMenuTimeout[menuID + '-opening']) {
372 window.navMenuTimeout[menuID + '-opening'] = false;
373 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
375 window.navMenuTimeout[menuID + '-closing'] = true;
377 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
378 $(menuID).slideUp('fast');
379 window.navMenuTimeout[menuID + '-closing'] = false;
390 function InitMCEEditor(editorData) {
391 var tinyMCEInitConfig = {
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
418 if (window.editSelect != 'none') {
419 $.extend(tinyMCEInitConfig, editorData);
420 tinyMCE.init(tinyMCEInitConfig);
421 } else if (typeof editorData.plaintextFn == 'function') {
422 (editorData.plaintextFn)();
429 function initEditor(cb) {
432 $("#profile-jot-text-loading").show();
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) {
443 ed.onKeyDown.add(function(ed,e) {
448 ed.onKeyUp.add(function(ed, e) {
449 var txt = tinyMCE.activeEditor.getContent();
450 match = txt.match(/@([^ \n]+)$/);
452 if (cPopup === null) {
453 cPopup = new ACPopup(this,baseurl+"/acl");
455 if (cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
456 if (! cPopup.ready) cPopup = null;
458 if (cPopup !== null) { cPopup.close(); cPopup = null; }
461 textlen = txt.length;
462 if (textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
463 $('#profile-jot-desc').html(window.isPublic);
465 $('#profile-jot-desc').html(' ');
470 if (textlen <= 140) {
471 $('#character-counter').removeClass('red');
472 $('#character-counter').removeClass('orange');
473 $('#character-counter').addClass('grey');
475 if ((textlen > 140) && (textlen <= 420)) {
476 $('#character-counter').removeClass('grey');
477 $('#character-counter').removeClass('red');
478 $('#character-counter').addClass('orange');
481 $('#character-counter').removeClass('grey');
482 $('#character-counter').removeClass('orange');
483 $('#character-counter').addClass('red');
485 $('#character-counter').text(textlen);
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();
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();
504 InitMCEEditor(editorData);
507 $("a#jot-perms-icon").colorbox({
509 'transition' : 'elastic'
512 if (typeof cb!="undefined") cb();
516 function enableOnUser() {
523 function msgInitEditor() {
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) {
533 ed.onKeyDown.add(function(ed,e) {
538 ed.onKeyUp.add(function(ed, e) {
539 var txt = tinyMCE.activeEditor.getContent();
540 match = txt.match(/@([^ \n]+)$/);
542 if (cPopup === null) {
543 cPopup = new ACPopup(this,baseurl+"/acl");
545 if (cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
546 if (! cPopup.ready) cPopup = null;
548 if (cPopup !== null) { cPopup.close(); cPopup = null; }
551 textlen = txt.length;
552 if (textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
553 $('#profile-jot-desc').html(window.isPublic);
555 $('#profile-jot-desc').html(' ');
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);
569 plaintextFn : function() {
570 $("#prvmail-text").editor_autocomplete(baseurl+"/acl");
573 InitMCEEditor(editorData);
577 function contactInitEditor() {
580 elements : "contact-edit-info",
583 InitMCEEditor(editorData);
587 function eventInitEditor() {
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;
599 InitMCEEditor(editorData);
603 function profInitEditor() {
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;
615 InitMCEEditor(editorData);
623 function addeditortext(textElem, data) {
624 if (window.editSelect == 'none') {
625 var currentText = $(textElem).val();
626 $(textElem).val(currentText + data);
628 tinyMCE.execCommand('mceInsertRawHTML',false,data);
632 function jotVideoURL() {
633 reply = prompt(window.vidURL);
634 if (reply && reply.length) {
635 addeditortext("#profile-jot-text", '[video]' + reply + '[/video]');
639 function jotAudioURL() {
640 reply = prompt(window.audURL);
641 if (reply && reply.length) {
642 addeditortext("#profile-jot-text", '[audio]' + reply + '[/audio]');
647 function jotGetLocation() {
648 reply = prompt(window.whereAreU, $('#jot-location').val());
649 if (reply && reply.length) {
650 $('#jot-location').val(reply);
654 function jotShare(id) {
655 if ($('#jot-popup').length != 0) $('#jot-popup').show();
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);
669 function jotClearLocation() {
670 $('#jot-coord').val('');
671 $('#profile-nolocation-wrapper').hide();
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();
688 function linkdropper(event) {
689 var linkFound = event.dataTransfer.types.contains("text/uri-list");
691 event.preventDefault();
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();
709 if (typeof window.geoTag === 'function') window.geoTag();
716 function confirmDelete() { return confirm(window.delItem); }
718 function deleteCheckedItems(delID) {
719 if (confirm(window.delItems)) {
723 $(delID + '-rotator').show();
724 $('.item-select').each( function() {
725 if ($(this).is(':checked')) {
726 if (checkedstr.length != 0) {
727 checkedstr = checkedstr + ',' + $(this).val();
729 checkedstr = $(this).val();
733 $.post('item', { dropitems: checkedstr }, function(data) {
734 window.location.reload();
739 function itemTag(id) {
740 reply = prompt(window.term);
741 if (reply && reply.length) {
742 reply = reply.replace('#','');
746 $('body').css('cursor', 'wait');
748 $.get('tagger/' + id + '?term=' + reply, NavUpdate);
754 function itemFiler(id) {
756 var bordercolor = $("input").css("border-color");
758 $.get('filer/', function(data) {
759 $.colorbox({html:data});
761 $("#id_term").keypress(function() {
762 $(this).css("border-color",bordercolor);
764 $("#select_term").change(function() {
765 $("#id_term").css("border-color",bordercolor);
768 $("#filer_save").click(function(e) {
770 reply = $("#id_term").val();
771 if (reply && reply.length) {
773 $('body').css('cursor', 'wait');
774 $.get('filer/' + id + '?term=' + reply, NavUpdate);
778 $("#id_term").css("border-color","#FF0000");
791 function insertFormatting(BBcode, id) {
792 var tmpStr = $("#comment-edit-text-" + id).val();
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);
800 textarea = document.getElementById("comment-edit-text-" +id);
801 if (document.selection) {
803 selected = document.selection.createRange();
804 if (BBcode == "url") {
805 selected.text = "["+BBcode+"=http://]" + selected.text + "[/"+BBcode+"]";
807 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
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);
815 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
822 function cmtBbOpen(id) {
823 $("#comment-edit-bb-" + id).show();
825 function cmtBbClose(id) {
826 $("#comment-edit-bb-" + id).hide();
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);
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);
847 function commentInsert(obj,id) {
848 var tmpStr = $("#comment-edit-text-" + id).val();
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);
854 var ins = $(obj).html();
855 ins = ins.replace("<","<");
856 ins = ins.replace(">",">");
857 ins = ins.replace("&","&");
858 ins = ins.replace(""",'"');
859 $("#comment-edit-text-" + id).val(tmpStr + ins);
862 function qCommentInsert(obj,id) {
863 var tmpStr = $("#comment-edit-text-" + id).val();
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);
869 var ins = $(obj).val();
870 ins = ins.replace("<","<");
871 ins = ins.replace(">",">");
872 ins = ins.replace("&","&");
873 ins = ins.replace(""",'"');
874 $("#comment-edit-text-" + id).val(tmpStr + ins);