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();
66 $('#acl-wrapper').hide();
70 if (typeof window.AjaxUpload != "undefined") {
71 var uploader = new window.AjaxUpload(
72 window.imageUploadButton,
73 { action: 'wall_upload/'+window.nickname,
75 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
76 onComplete: function(file,response) {
77 addeditortext(window.jotId, response);
78 $('#profile-rotator').hide();
83 if ($('#wall-file-upload').length) {
84 var file_uploader = new window.AjaxUpload(
86 { action: 'wall_attach/'+window.nickname,
88 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
89 onComplete: function(file,response) {
90 addeditortext(window.jotId, response);
91 $('#profile-rotator').hide();
99 if (typeof window.aclInit !="undefined" && typeof acl=="undefined") {
102 [ window.allowCID,window.allowGID,window.denyCID,window.denyGID ]
107 if (window.aclType == "settings-head" || window.aclType == "photos_head" || window.aclType == "event_head") {
108 $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
110 $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
111 selstr = $(this).text();
112 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
113 $('#jot-public').hide();
115 if (selstr == null) {
116 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
117 $('#jot-public').show();
120 }).trigger('change');
123 if (window.aclType == "event_head") {
124 $('#events-calendar').fullCalendar({
125 events: baseurl + window.eventModuleUrl +'/json/',
127 left: 'prev,next today',
129 right: 'month,agendaWeek,agendaDay'
131 timeFormat: 'H(:mm)',
132 eventClick: function(calEvent, jsEvent, view) {
133 showEvent(calEvent.id);
135 loading: function(isLoading, view) {
137 $('td.fc-day').dblclick(function() { window.location.href='/events/new?start='+$(this).data('date'); });
141 eventRender: function(event, element, view) {
142 //console.log(view.name);
143 if (event.item['author-name']==null) return;
146 element.find(".fc-title").html(
147 "<img src='{0}' style='height:10px;width:10px'>{1} : {2}".format(
148 event.item['author-avatar'],
149 event.item['author-name'],
154 element.find(".fc-title").html(
155 "<img src='{0}' style='height:12px; width:12px'>{1}<p>{2}</p><p>{3}</p>".format(
156 event.item['author-avatar'],
157 event.item['author-name'],
163 element.find(".fc-title").html(
164 "<img src='{0}' style='height:24px;width:24px'>{1}<p>{2}</p><p>{3}</p>".format(
165 event.item['author-avatar'],
166 event.item['author-name'],
177 var args=location.href.replace(baseurl,"").split("/");
178 if (args.length>=5 && window.eventModeParams == 2) {
179 $("#events-calendar").fullCalendar('gotoDate',args[3] , args[4]-1);
180 } else if (args.length>=4 && window.eventModeParams == 1) {
181 $("#events-calendar").fullCalendar('gotoDate',args[2] , args[3]-1);
185 var hash = location.hash.split("-")
186 if (hash.length==2 && hash[0]=="#link") showEvent(hash[1]);
190 switch(window.autocompleteType) {
192 $("#recip").name_autocomplete(baseurl + '/acl', '', false, function(data) {
193 $("#recip-complete").val(data.id);
196 case 'contacts-head':
197 $("#contacts-search").contact_autocomplete(baseurl + '/acl', 'a', true);
200 $("#contacts-search").keyup(function(event) {
201 if (event.keyCode == 13) {
202 $("#contacts-search").click();
205 $(".autocomplete-w1 .selected").keyup(function(event) {
206 if (event.keyCode == 13) {
207 $("#contacts-search").click();
212 $(".comment-wwedit-wrapper textarea").editor_autocomplete(baseurl+"/acl");
218 // Add Colorbox for viewing Network page images
219 //var cBoxClasses = new Array();
220 $(".wall-item-body a img").each(function() {
221 var aElem = $(this).parent();
222 var imgHref = aElem.attr("href");
224 // We need to make sure we only put a Colorbox on links to Friendica images
225 // We'll try to do this by looking for links of the form
226 // .../photo/ab803d8eg08daf85023adfec08 (with nothing more following), in hopes
227 // that that will be unique enough
228 if (imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) {
230 // Add a unique class to all the images of a certain post, to allow scrolling through
231 var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox";
232 $(this).addClass(cBoxClass);
236 photo: true, // Colorbox doesn't recognize a URL that don't end in .jpg, etc. as a photo
237 rel: cBoxClass //$(this).attr("class").match(/wall-item-body-[\d]+-lightbox/)[0]
244 // update pending count //
247 $("nav").bind('nav-update', function(e,data) {
248 var elm = $('#pending-update');
249 var register = $(data).find('register').text();
250 if (register=="0") { register=""; elm.hide();} else { elm.show(); }
258 $("#cnftheme").click(function() {
262 href: baseurl + "/admin/themes/" + $("#id_theme :selected").val(),
263 onComplete: function() {
264 $("div#fancybox-content form").submit(function(e) {
265 var url = $(this).attr('action');
266 // can't get .serialize() to work...
268 $(this).find("input").each(function() {
269 data[$(this).attr('name')] = $(this).val();
271 $(this).find("select").each(function() {
272 data[$(this).attr('name')] = $(this).children(":selected").val();
274 console.log(":)", url, data);
276 $.post(url, data, function(data) {
294 function homeRedirect() {
295 $('html').fadeOut('slow', function() {
296 window.location = baseurl + "/login";
301 if (typeof window.photoEdit != 'undefined') {
303 $(document).keydown(function(event) {
305 if (window.prevLink != '') { if (event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = window.prevLink; }}
306 if (window.nextLink != '') { if (event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = window.nextLink; }}
311 function showEvent(eventid) {
313 baseurl + window.eventModuleUrl + '/?id=' + eventid,
315 $.colorbox({html:data});
321 function doEventPreview() {
322 $('#event-edit-preview').val(1);
323 $.post('events',$('#event-edit-form').serialize(), function(data) {
324 $.colorbox({ html: data });
326 $('#event-edit-preview').val(0);
329 function initCrop() {
330 function onEndCrop( coords, dimensions ) {
331 $PR( 'x1' ).value = coords.x1;
332 $PR( 'y1' ).value = coords.y1;
333 $PR( 'x2' ).value = coords.x2;
334 $PR( 'y2' ).value = coords.y2;
335 $PR( 'width' ).value = dimensions.width;
336 $PR( 'height' ).value = dimensions.height;
339 Event.observe( window, 'load', function() {
340 new Cropper.ImgWithPreview(
343 previewWrap: 'previewWrap',
348 ratioDim: { x: 100, y:100 },
355 function showNavMenu(menuID) {
357 if (window.navMenuTimeout[menuID + '-closing']) {
358 window.navMenuTimeout[menuID + '-closing'] = false;
359 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
362 window.navMenuTimeout[menuID + '-opening'] = true;
364 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
365 $(menuID).slideDown('fast').show();
366 window.navMenuTimeout[menuID + '-opening'] = false;
371 function hideNavMenu(menuID) {
373 if (window.navMenuTimeout[menuID + '-opening']) {
374 window.navMenuTimeout[menuID + '-opening'] = false;
375 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
378 window.navMenuTimeout[menuID + '-closing'] = true;
380 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
381 $(menuID).slideUp('fast');
382 window.navMenuTimeout[menuID + '-closing'] = false;
393 function InitMCEEditor(editorData) {
394 var tinyMCEInitConfig = {
397 //editor_selector: // SPECIFIC
398 //elements: // SPECIFIC
399 plugins : "bbcode,paste,autoresize,inlinepopups",
400 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
401 theme_advanced_buttons2 : "",
402 theme_advanced_buttons3 : "",
403 theme_advanced_toolbar_location : "top",
404 theme_advanced_toolbar_align : "center",
405 theme_advanced_blockformats : "blockquote,code",
406 gecko_spellcheck : true,
407 paste_text_sticky : true, // COUPLED WITH paste PLUGIN
408 entity_encoding : "raw",
409 add_unload_trigger : false,
410 remove_linebreaks : false,
411 //force_p_newlines : false,
412 //force_br_newlines : true,
413 forced_root_block : 'div',
414 //convert_urls: false, //SPECIFIC?
415 content_css: baseurl + "/view/custom_tinymce.css",
416 theme_advanced_path : false,
417 file_browser_callback : "fcFileBrowser",
418 //setup : // SPECIFIC
421 if (window.editSelect != 'none') {
422 $.extend(tinyMCEInitConfig, editorData);
423 tinyMCE.init(tinyMCEInitConfig);
425 else if (typeof editorData.plaintextFn == 'function') {
426 (editorData.plaintextFn)();
433 function initEditor(cb) {
436 $("#profile-jot-text-loading").show();
439 mode : "specific_textareas",
440 editor_selector : "profile-jot-text",
441 auto_focus : "profile-jot-text",
442 //plugins : "bbcode,paste,autoresize,inlinepopups",
443 //paste_text_sticky : true,
444 convert_urls : false,
445 setup : function(ed) {
447 ed.onKeyDown.add(function(ed,e) {
452 ed.onKeyUp.add(function(ed, e) {
453 var txt = tinyMCE.activeEditor.getContent();
454 match = txt.match(/@([^ \n]+)$/);
456 if (cPopup === null) {
457 cPopup = new ACPopup(this,baseurl+"/acl");
459 if (cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
460 if (! cPopup.ready) cPopup = null;
463 if (cPopup !== null) { cPopup.close(); cPopup = null; }
466 textlen = txt.length;
467 if (textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
468 $('#profile-jot-desc').html(window.isPublic);
471 $('#profile-jot-desc').html(' ');
476 if (textlen <= 140) {
477 $('#character-counter').removeClass('red');
478 $('#character-counter').removeClass('orange');
479 $('#character-counter').addClass('grey');
481 if ((textlen > 140) && (textlen <= 420)) {
482 $('#character-counter').removeClass('grey');
483 $('#character-counter').removeClass('red');
484 $('#character-counter').addClass('orange');
487 $('#character-counter').removeClass('grey');
488 $('#character-counter').removeClass('orange');
489 $('#character-counter').addClass('red');
491 $('#character-counter').text(textlen);
494 ed.onInit.add(function(ed) {
495 ed.pasteAsPlainText = true;
496 $("#profile-jot-text-loading").hide();
497 $(".jothidden").show();
498 if (typeof cb!="undefined") cb();
502 plaintextFn : function() {
503 $("#profile-jot-text-loading").hide();
504 $("#profile-jot-text").css({ 'height': 200, 'color': '#000' });
505 $("#profile-jot-text").editor_autocomplete(baseurl+"/acl");
506 $(".jothidden").show();
507 if (typeof cb!="undefined") cb();
510 InitMCEEditor(editorData);
513 $("a#jot-perms-icon").colorbox({
515 'transition' : 'elastic'
518 if (typeof cb!="undefined") cb();
522 function enableOnUser() {
529 function msgInitEditor() {
531 mode : "specific_textareas",
532 editor_selector : "prvmail-text",
533 //plugins : "bbcode,paste",
534 //paste_text_sticky : true,
535 convert_urls : false,
536 //theme_advanced_path : false,
537 setup : function(ed) {
539 ed.onKeyDown.add(function(ed,e) {
544 ed.onKeyUp.add(function(ed, e) {
545 var txt = tinyMCE.activeEditor.getContent();
546 match = txt.match(/@([^ \n]+)$/);
548 if (cPopup === null) {
549 cPopup = new ACPopup(this,baseurl+"/acl");
551 if (cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
552 if (! cPopup.ready) cPopup = null;
555 if (cPopup !== null) { cPopup.close(); cPopup = null; }
558 textlen = txt.length;
559 if (textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
560 $('#profile-jot-desc').html(window.isPublic);
563 $('#profile-jot-desc').html(' ');
567 ed.onInit.add(function(ed) {
568 ed.pasteAsPlainText = true;
569 var editorId = ed.editorId;
570 var textarea = $('#'+editorId);
571 if (typeof(textarea.attr('tabindex')) != "undefined") {
572 $('#'+editorId+'_ifr').attr('tabindex', textarea.attr('tabindex'));
573 textarea.attr('tabindex', null);
577 plaintextFn : function() {
578 $("#prvmail-text").editor_autocomplete(baseurl+"/acl");
581 InitMCEEditor(editorData);
585 function contactInitEditor() {
588 elements : "contact-edit-info",
591 InitMCEEditor(editorData);
595 function eventInitEditor() {
598 //plugins : "bbcode,paste",
599 //paste_text_sticky : true,
600 //theme_advanced_path : false,
601 setup : function(ed) {
602 ed.onInit.add(function(ed) {
603 ed.pasteAsPlainText = true;
607 InitMCEEditor(editorData);
611 function profInitEditor() {
614 //plugins : "bbcode,paste",
615 //paste_text_sticky : true,
616 //theme_advanced_path : false,
617 setup : function(ed) {
618 ed.onInit.add(function(ed) {
619 ed.pasteAsPlainText = true;
623 InitMCEEditor(editorData);
631 function addeditortext(textElem, data) {
632 if (window.editSelect == 'none') {
633 var currentText = $(textElem).val();
634 $(textElem).val(currentText + data);
637 tinyMCE.execCommand('mceInsertRawHTML',false,data);
640 function jotVideoURL() {
641 reply = prompt(window.vidURL);
642 if (reply && reply.length) {
643 addeditortext("#profile-jot-text", '[video]' + reply + '[/video]');
647 function jotAudioURL() {
648 reply = prompt(window.audURL);
649 if (reply && reply.length) {
650 addeditortext("#profile-jot-text", '[audio]' + reply + '[/audio]');
655 function jotGetLocation() {
656 reply = prompt(window.whereAreU, $('#jot-location').val());
657 if (reply && reply.length) {
658 $('#jot-location').val(reply);
662 function jotShare(id) {
663 if ($('#jot-popup').length != 0) $('#jot-popup').show();
665 $('#like-rotator-' + id).show();
666 $.get('share/' + id, function(data) {
667 if (!editor) $("#profile-jot-text").val("");
668 initEditor(function() {
669 addeditortext("#profile-jot-text", data);
670 $('#like-rotator-' + id).hide();
671 $(window).scrollTop(0);
677 function jotClearLocation() {
678 $('#jot-coord').val('');
679 $('#profile-nolocation-wrapper').hide();
683 function jotGetLink() {
684 reply = prompt(window.linkURL);
685 if (reply && reply.length) {
686 reply = bin2hex(reply);
687 $('#profile-rotator').show();
688 $.get('parse_url?binurl=' + reply, function(data) {
689 addeditortext(window.jotId, data);
690 $('#profile-rotator').hide();
696 function linkdropper(event) {
697 var linkFound = event.dataTransfer.types.contains("text/uri-list");
699 event.preventDefault();
703 function linkdrop(event) {
704 var reply = event.dataTransfer.getData("text/uri-list");
705 event.preventDefault();
706 if (reply && reply.length) {
707 reply = bin2hex(reply);
708 $('#profile-rotator').show();
709 $.get('parse_url?binurl=' + reply, function(data) {
710 addeditortext(window.jotId, data);
711 $('#profile-rotator').hide();
717 if (typeof window.geoTag === 'function') window.geoTag();
724 function confirmDelete() { return confirm(window.delItem); }
726 function deleteCheckedItems(delID) {
727 if (confirm(window.delItems)) {
731 $(delID + '-rotator').show();
732 $('.item-select').each( function() {
733 if ($(this).is(':checked')) {
734 if (checkedstr.length != 0) {
735 checkedstr = checkedstr + ',' + $(this).val();
738 checkedstr = $(this).val();
742 $.post('item', { dropitems: checkedstr }, function(data) {
743 window.location.reload();
748 function itemTag(id) {
749 reply = prompt(window.term);
750 if (reply && reply.length) {
751 reply = reply.replace('#','');
755 $('body').css('cursor', 'wait');
757 $.get('tagger/' + id + '?term=' + reply, NavUpdate);
763 function itemFiler(id) {
765 var bordercolor = $("input").css("border-color");
767 $.get('filer/', function(data) {
768 $.colorbox({html:data});
770 $("#id_term").keypress(function() {
771 $(this).css("border-color",bordercolor);
773 $("#select_term").change(function() {
774 $("#id_term").css("border-color",bordercolor);
777 $("#filer_save").click(function(e) {
779 reply = $("#id_term").val();
780 if (reply && reply.length) {
782 $('body').css('cursor', 'wait');
783 $.get('filer/' + id + '?term=' + reply, NavUpdate);
787 $("#id_term").css("border-color","#FF0000");
800 function insertFormatting(comment,BBcode,id) {
802 var tmpStr = $("#comment-edit-text-" + id).val();
803 if(tmpStr == comment) {
805 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
806 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
807 openMenu("comment-edit-submit-wrapper-" + id);
808 $("#comment-edit-text-" + id).val(tmpStr);
811 textarea = document.getElementById("comment-edit-text-" +id);
812 if (document.selection) {
814 selected = document.selection.createRange();
815 if (BBcode == "url"){
816 selected.text = "["+BBcode+"=http://]" + selected.text + "[/"+BBcode+"]";
818 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
819 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
820 var start = textarea.selectionStart;
821 var end = textarea.selectionEnd;
822 if (BBcode == "url"){
823 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"=http://]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
825 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
830 function cmtBbOpen(id) {
831 $("#comment-edit-bb-" + id).show();
833 function cmtBbClose(id) {
834 $("#comment-edit-bb-" + id).hide();
837 function commentOpen(obj,id) {
838 if(obj.value == window.commentEmptyText) {
840 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
841 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
842 $("#mod-cmnt-wrap-" + id).show();
843 openMenu("comment-edit-submit-wrapper-" + id);
846 function commentClose(obj,id) {
847 if(obj.value == "") {
848 obj.value = window.commentEmptyText;
849 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
850 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
851 $("#mod-cmnt-wrap-" + id).hide();
852 closeMenu("comment-edit-submit-wrapper-" + id);
857 function commentInsert(obj,id) {
858 var tmpStr = $("#comment-edit-text-" + id).val();
859 if(tmpStr == window.commentEmptyText) {
861 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
862 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
863 openMenu("comment-edit-submit-wrapper-" + id);
865 var ins = $(obj).html();
866 ins = ins.replace("<","<");
867 ins = ins.replace(">",">");
868 ins = ins.replace("&","&");
869 ins = ins.replace(""",'"');
870 $("#comment-edit-text-" + id).val(tmpStr + ins);
873 function qCommentInsert(obj,id) {
874 var tmpStr = $("#comment-edit-text-" + id).val();
875 if(tmpStr == window.commentEmptyText) {
877 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
878 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
879 openMenu("comment-edit-submit-wrapper-" + id);
881 var ins = $(obj).val();
882 ins = ins.replace("<","<");
883 ins = ins.replace(">",">");
884 ins = ins.replace("&","&");
885 ins = ins.replace(""",'"');
886 $("#comment-edit-text-" + id).val(tmpStr + ins);