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
20 /* enable editor on focus and click */
21 $("#profile-jot-text").focus(enableOnUser);
22 $("#profile-jot-text").click(enableOnUser);
24 $('.nav-menu-list, .nav-menu-icon').hover(function() {
25 showNavMenu($(this).attr('point'));
27 hideNavMenu($(this).attr('point'));
30 /* $('html').click(function() { $("#nav-notifications-menu" ).hide(); });*/
32 $('.group-edit-icon').hover(
34 $(this).addClass('icon'); $(this).removeClass('iconspacer');},
36 $(this).removeClass('icon'); $(this).addClass('iconspacer');}
39 $('.sidebar-group-element').hover(
41 id = $(this).attr('id');
42 $('#edit-' + id).addClass('icon'); $('#edit-' + id).removeClass('iconspacer');},
45 id = $(this).attr('id');
46 $('#edit-' + id).removeClass('icon');$('#edit-' + id).addClass('iconspacer');}
50 $('.savedsearchdrop').hover(
52 $(this).addClass('drop'); $(this).addClass('icon'); $(this).removeClass('iconspacer');},
54 $(this).removeClass('drop'); $(this).removeClass('icon'); $(this).addClass('iconspacer');}
57 $('.savedsearchterm').hover(
59 id = $(this).attr('id');
60 $('#drop-' + id).addClass('icon'); $('#drop-' + id).addClass('drophide'); $('#drop-' + id).removeClass('iconspacer');},
63 id = $(this).attr('id');
64 $('#drop-' + id).removeClass('icon');$('#drop-' + id).removeClass('drophide'); $('#drop-' + id).addClass('iconspacer');}
67 /* $('.nav-load-page-link').click(function() {
68 getPageContent( $(this).attr('href') );
69 hideNavMenu( '#' + $(this).closest('ul').attr('id') );
73 $('#id_share').change(function() {
75 if ($('#id_share').is(':checked')) {
76 $('#acl-wrapper').show();
79 $('#acl-wrapper').hide();
84 /* $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
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();
91 $('#jot-public').show();
94 }).trigger('change');*/
97 if(typeof window.AjaxUpload != "undefined") {
98 var uploader = new window.AjaxUpload(
99 window.imageUploadButton,
100 { action: 'wall_upload/'+window.nickname,
102 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
103 onComplete: function(file,response) {
104 addeditortext(window.jotId, response);
105 $('#profile-rotator').hide();
110 if($('#wall-file-upload').length) {
111 var file_uploader = new window.AjaxUpload(
113 { action: 'wall_attach/'+window.nickname,
115 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
116 onComplete: function(file,response) {
117 addeditortext(window.jotId, response);
118 $('#profile-rotator').hide();
126 if(typeof window.aclInit !="undefined" && typeof acl=="undefined"){
129 [ window.allowCID,window.allowGID,window.denyCID,window.denyGID ]
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() {
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();
143 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
144 $('#jot-public').show();
147 }).trigger('change');
150 if(window.aclType == "event_head") {
151 $('#events-calendar').fullCalendar({
152 events: baseurl + window.eventModuleUrl +'/json/',
154 left: 'prev,next today',
156 right: 'month,agendaWeek,agendaDay'
158 timeFormat: 'H(:mm)',
159 eventClick: function(calEvent, jsEvent, view) {
160 showEvent(calEvent.id);
162 loading: function(isLoading, view) {
164 $('td.fc-day').dblclick(function() { window.location.href='/events/new?start='+$(this).data('date'); });
168 eventRender: function(event, element, view) {
169 //console.log(view.name);
170 if (event.item['author-name']==null) return;
173 element.find(".fc-title").html(
174 "<img src='{0}' style='height:10px;width:10px'>{1} : {2}".format(
175 event.item['author-avatar'],
176 event.item['author-name'],
181 element.find(".fc-title").html(
182 "<img src='{0}' style='height:12px; width:12px'>{1}<p>{2}</p><p>{3}</p>".format(
183 event.item['author-avatar'],
184 event.item['author-name'],
190 element.find(".fc-title").html(
191 "<img src='{0}' style='height:24px;width:24px'>{1}<p>{2}</p><p>{3}</p>".format(
192 event.item['author-avatar'],
193 event.item['author-name'],
204 var args=location.href.replace(baseurl,"").split("/");
205 if (args.length>=5 && window.eventModeParams == 2) {
206 $("#events-calendar").fullCalendar('gotoDate',args[3] , args[4]-1);
207 } else if (args.length>=4 && window.eventModeParams == 1) {
208 $("#events-calendar").fullCalendar('gotoDate',args[2] , args[3]-1);
212 var hash = location.hash.split("-")
213 if (hash.length==2 && hash[0]=="#link") showEvent(hash[1]);
217 switch(window.autocompleteType) {
219 $("#recip").name_autocomplete(baseurl + '/acl', '', false, function(data) {
220 $("#recip-complete").val(data.id);
223 case 'contacts-head':
224 $("#contacts-search").contact_autocomplete(baseurl + '/acl', 'a', true);
227 $("#contacts-search").keyup(function(event){
228 if(event.keyCode == 13){
229 $("#contacts-search").click();
232 $(".autocomplete-w1 .selected").keyup(function(event){
233 if(event.keyCode == 13){
234 $("#contacts-search").click();
239 $(".comment-wwedit-wrapper textarea").editor_autocomplete(baseurl+"/acl");
245 /* if(window.autoCompleteType == "display-head") {
246 //$(".comment-edit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
247 // make auto-complete work in more places
248 //$(".wall-item-comment-wrapper textarea").contact_autocomplete(baseurl+"/acl");
249 $(".comment-wwedit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
252 // Add Colorbox for viewing Network page images
253 //var cBoxClasses = new Array();
254 $(".wall-item-body a img").each(function(){
255 var aElem = $(this).parent();
256 var imgHref = aElem.attr("href");
258 // We need to make sure we only put a Colorbox on links to Friendica images
259 // We'll try to do this by looking for links of the form
260 // .../photo/ab803d8eg08daf85023adfec08 (with nothing more following), in hopes
261 // that that will be unique enough
262 if(imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) {
264 // Add a unique class to all the images of a certain post, to allow scrolling through
265 var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox";
266 $(this).addClass(cBoxClass);
268 // if( $.inArray(cBoxClass, cBoxClasses) < 0 ) {
269 // cBoxClasses.push(cBoxClass);
274 photo: true, // Colorbox doesn't recognize a URL that don't end in .jpg, etc. as a photo
275 rel: cBoxClass //$(this).attr("class").match(/wall-item-body-[\d]+-lightbox/)[0]
279 /*$.each(cBoxClasses, function(){
280 $('.'+this).colorbox({
290 // update pending count //
293 $("nav").bind('nav-update', function(e,data){
294 var elm = $('#pending-update');
295 var register = $(data).find('register').text();
296 if (register=="0") { register=""; elm.hide();} else { elm.show(); }
304 $("#cnftheme").click(function(){
308 href: baseurl + "/admin/themes/" + $("#id_theme :selected").val(),
309 onComplete: function(){
310 $("div#fancybox-content form").submit(function(e){
311 var url = $(this).attr('action');
312 // can't get .serialize() to work...
314 $(this).find("input").each(function(){
315 data[$(this).attr('name')] = $(this).val();
317 $(this).find("select").each(function(){
318 data[$(this).attr('name')] = $(this).children(":selected").val();
320 console.log(":)", url, data);
322 $.post(url, data, function(data) {
323 if(timer) clearTimeout(timer);
338 function homeRedirect() {
339 $('html').fadeOut('slow', function(){
340 window.location = baseurl + "/login";
345 if(typeof window.photoEdit != 'undefined') {
347 $(document).keydown(function(event) {
349 if(window.prevLink != '') { if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = window.prevLink; }}
350 if(window.nextLink != '') { if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = window.nextLink; }}
355 function showEvent(eventid) {
357 baseurl + window.eventModuleUrl + '/?id=' + eventid,
359 $.colorbox({html:data});
365 function doEventPreview() {
366 $('#event-edit-preview').val(1);
367 $.post('events',$('#event-edit-form').serialize(), function(data) {
368 $.colorbox({ html: data });
370 $('#event-edit-preview').val(0);
373 function initCrop() {
374 function onEndCrop( coords, dimensions ) {
375 $PR( 'x1' ).value = coords.x1;
376 $PR( 'y1' ).value = coords.y1;
377 $PR( 'x2' ).value = coords.x2;
378 $PR( 'y2' ).value = coords.y2;
379 $PR( 'width' ).value = dimensions.width;
380 $PR( 'height' ).value = dimensions.height;
383 Event.observe( window, 'load', function() {
384 new Cropper.ImgWithPreview(
387 previewWrap: 'previewWrap',
392 ratioDim: { x: 100, y:100 },
401 $(document).mouseup(function (clickPos) {
403 var sysMenu = $("#system-menu-list");
404 var sysMenuLink = $(".system-menu-link");
405 var contactsMenu = $("#contacts-menu-list");
406 var contactsMenuLink = $(".contacts-menu-link");
407 var networkMenu = $("#network-menu-list");
408 var networkMenuLink = $(".network-menu-link");
410 if( !sysMenu.is(clickPos.target) && !sysMenuLink.is(clickPos.target) && sysMenu.has(clickPos.target).length === 0) {
411 hideNavMenu("#system-menu-list");
413 if( !contactsMenu.is(clickPos.target) && !contactsMenuLink.is(clickPos.target) && contactsMenu.has(clickPos.target).length === 0) {
414 hideNavMenu("#contacts-menu-list");
416 if( !networkMenu.is(clickPos.target) && !networkMenuLink.is(clickPos.target) && networkMenu.has(clickPos.target).length === 0) {
417 hideNavMenu("#network-menu-list");
422 function getPageContent(url) {
424 var pos = $('.main-container').position();
426 $('.main-container').css('margin-left', pos.left);
427 $('.main-content-container').hide(0, function () {
428 $('.main-content-loading').show(0);
431 $.get(url, function(html) {
432 console.log($('.main-content-container').html());
433 $('.main-content-container').html( $('.main-content-container', html).html() );
434 console.log($('.main-content-container').html());
435 $('.main-content-loading').hide(function() {
436 $('.main-content-container').fadeIn(800,function() {
437 $('.main-container').css('margin-left', 'auto'); // This sucks -- if the CSS specification changes, this will be wrong
444 function showNavMenu(menuID) {
446 if(window.navMenuTimeout[menuID + '-closing']) {
447 window.navMenuTimeout[menuID + '-closing'] = false;
448 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
451 window.navMenuTimeout[menuID + '-opening'] = true;
453 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
454 $(menuID).slideDown('fast').show();
455 window.navMenuTimeout[menuID + '-opening'] = false;
460 function hideNavMenu(menuID) {
462 if(window.navMenuTimeout[menuID + '-opening']) {
463 window.navMenuTimeout[menuID + '-opening'] = false;
464 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
467 window.navMenuTimeout[menuID + '-closing'] = true;
469 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
470 $(menuID).slideUp('fast');
471 window.navMenuTimeout[menuID + '-closing'] = false;
485 function initEditor(callback) {
486 if(editor == false) {
487 $("#profile-jot-text-loading").show();
489 $("#profile-jot-text-loading").hide();
490 $("#profile-jot-text").css({ 'height': 200, 'color': '#000' });
491 $("#profile-jot-text").editor_autocomplete(baseurl+"/acl");
492 $(".jothidden").show();
494 $("a#jot-perms-icon").colorbox({
496 'transition' : 'elastic'
501 if (typeof callback != "undefined") {
506 function enableOnUser() {
514 function msgInitEditor() {
515 $("#prvmail-text").editor_autocomplete(baseurl+"/acl");
522 function addeditortext(textElem, data) {
523 var currentText = $(textElem).val();
524 $(textElem).val(currentText + data);
527 function jotVideoURL() {
528 reply = prompt(window.vidURL);
529 if(reply && reply.length) {
530 addeditortext("#profile-jot-text", '[video]' + reply + '[/video]');
534 function jotAudioURL() {
535 reply = prompt(window.audURL);
536 if(reply && reply.length) {
537 addeditortext("#profile-jot-text", '[audio]' + reply + '[/audio]');
542 function jotGetLocation() {
544 /* if(navigator.geolocation) {
546 navigator.geolocation.getCurrentPosition(function(position) {
547 var lat = position.coords.latitude;
548 var lng = position.coords.longitude;
552 url: 'http://nominatim.openstreetmap.org/reverse?format=json&lat='+lat+'&lon='+lng,
553 jsonp: 'json_callback',
554 contentType: 'application/json',
556 success: function(json) {
558 var locationDisplay = json.address.building+', '+json.address.city+', '+json.address.state;
559 $('#jot-location').val(locationDisplay);
560 $('#jot-display-location').html('Location: '+locationDisplay);
561 $('#jot-display-location').show();
568 reply = prompt(window.whereAreU, $('#jot-location').val());
569 if(reply && reply.length) {
570 $('#jot-location').val(reply);
574 reply = prompt(window.whereAreU, $('#jot-location').val());
575 if(reply && reply.length) {
576 $('#jot-location').val(reply);
580 function jotShare(id) {
581 if ($('#jot-popup').length != 0) $('#jot-popup').show();
583 $('#like-rotator-' + id).show();
584 $.get('share/' + id, function(data) {
585 if (!editor) $("#profile-jot-text").val("");
586 initEditor(function(){
587 addeditortext("#profile-jot-text", data);
588 $('#like-rotator-' + id).hide();
589 $(window).scrollTop(0);
595 function jotClearLocation() {
596 $('#jot-coord').val('');
597 $('#profile-nolocation-wrapper').hide();
601 function jotGetLink() {
602 reply = prompt(window.linkURL);
603 if(reply && reply.length) {
604 reply = bin2hex(reply);
605 $('#profile-rotator').show();
606 $.get('parse_url?binurl=' + reply, function(data) {
607 addeditortext(window.jotId, data);
608 $('#profile-rotator').hide();
614 function linkdropper(event) {
615 var linkFound = event.dataTransfer.types.contains("text/uri-list");
617 event.preventDefault();
621 function linkdrop(event) {
622 var reply = event.dataTransfer.getData("text/uri-list");
623 //event.target.textContent = reply;
624 event.preventDefault();
625 if(reply && reply.length) {
626 reply = bin2hex(reply);
627 $('#profile-rotator').show();
628 $.get('parse_url?binurl=' + reply, function(data) {
629 /* if(window.jotId == "#profile-jot-text") {
630 if (!editor) $("#profile-jot-text").val("");
631 initEditor(function(){
632 addeditortext(window.jotId, data);
633 $('#profile-rotator').hide();
637 addeditortext(window.jotId, data);
638 $('#profile-rotator').hide();
645 if(typeof window.geoTag === 'function') window.geoTag();
652 function confirmDelete() { return confirm(window.delItem); }
654 function deleteCheckedItems(delID) {
655 if(confirm(window.delItems)) {
659 $(delID + '-rotator').show();
660 $('.item-select').each( function() {
661 if($(this).is(':checked')) {
662 if(checkedstr.length != 0) {
663 checkedstr = checkedstr + ',' + $(this).val();
666 checkedstr = $(this).val();
670 $.post('item', { dropitems: checkedstr }, function(data) {
671 window.location.reload();
676 function itemTag(id) {
677 reply = prompt(window.term);
678 if(reply && reply.length) {
679 reply = reply.replace('#','');
683 $('body').css('cursor', 'wait');
685 $.get('tagger/' + id + '?term=' + reply, NavUpdate);
686 /*if(timer) clearTimeout(timer);
687 timer = setTimeout(NavUpdate,3000);*/
693 function itemFiler(id) {
695 var bordercolor = $("input").css("border-color");
697 $.get('filer/', function(data){
698 $.colorbox({html:data});
700 $("#id_term").keypress(function(){
701 $(this).css("border-color",bordercolor);
703 $("#select_term").change(function(){
704 $("#id_term").css("border-color",bordercolor);
707 $("#filer_save").click(function(e){
709 reply = $("#id_term").val();
710 if(reply && reply.length) {
712 $('body').css('cursor', 'wait');
713 $.get('filer/' + id + '?term=' + reply, NavUpdate);
714 /* if(timer) clearTimeout(timer);
715 timer = setTimeout(NavUpdate,3000);*/
719 $("#id_term").css("border-color","#FF0000");
732 function insertFormatting(comment,BBcode,id) {
734 var tmpStr = $("#comment-edit-text-" + id).val();
735 if(tmpStr == comment) {
737 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
738 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
739 openMenu("comment-edit-submit-wrapper-" + id);
740 $("#comment-edit-text-" + id).val(tmpStr);
743 textarea = document.getElementById("comment-edit-text-" +id);
744 if (document.selection) {
746 selected = document.selection.createRange();
747 if (BBcode == "url"){
748 selected.text = "["+BBcode+"=http://]" + selected.text + "[/"+BBcode+"]";
750 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
751 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
752 var start = textarea.selectionStart;
753 var end = textarea.selectionEnd;
754 if (BBcode == "url"){
755 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"=http://]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
757 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
762 function cmtBbOpen(id) {
763 $("#comment-edit-bb-" + id).show();
765 function cmtBbClose(id) {
766 $("#comment-edit-bb-" + id).hide();
769 function commentOpen(obj,id) {
770 if(obj.value == window.commentEmptyText) {
772 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
773 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
774 $("#mod-cmnt-wrap-" + id).show();
775 openMenu("comment-edit-submit-wrapper-" + id);
778 function commentClose(obj,id) {
779 if(obj.value == "") {
780 obj.value = window.commentEmptyText;
781 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
782 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
783 $("#mod-cmnt-wrap-" + id).hide();
784 closeMenu("comment-edit-submit-wrapper-" + id);
789 function commentInsert(obj,id) {
790 var tmpStr = $("#comment-edit-text-" + id).val();
791 if(tmpStr == window.commentEmptyText) {
793 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
794 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
795 openMenu("comment-edit-submit-wrapper-" + id);
797 var ins = $(obj).html();
798 ins = ins.replace("<","<");
799 ins = ins.replace(">",">");
800 ins = ins.replace("&","&");
801 ins = ins.replace(""",'"');
802 $("#comment-edit-text-" + id).val(tmpStr + ins);
805 function qCommentInsert(obj,id) {
806 var tmpStr = $("#comment-edit-text-" + id).val();
807 if(tmpStr == window.commentEmptyText) {
809 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
810 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
811 openMenu("comment-edit-submit-wrapper-" + id);
813 var ins = $(obj).val();
814 ins = ins.replace("<","<");
815 ins = ins.replace(">",">");
816 ins = ins.replace("&","&");
817 ins = ins.replace(""",'"');
818 $("#comment-edit-text-" + id).val(tmpStr + ins);
822 /*function showHideCommentBox(id) {
823 if( $('#comment-edit-form-' + id).is(':visible')) {
824 $('#comment-edit-form-' + id).hide();
827 $('#comment-edit-form-' + id).show();