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 editor 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;
393 function initEditor(callback) {
394 if(editor == false) {
395 $("#profile-jot-text-loading").show();
397 $("#profile-jot-text-loading").hide();
398 $("#profile-jot-text").css({ 'height': 200, 'color': '#000' });
399 $("#profile-jot-text").editor_autocomplete(baseurl+"/acl");
400 $(".jothidden").show();
402 $("a#jot-perms-icon").colorbox({
404 'transition' : 'elastic'
409 if (typeof callback != "undefined") {
414 function enableOnUser() {
422 function msgInitEditor() {
423 $("#prvmail-text").editor_autocomplete(baseurl+"/acl");
430 function addeditortext(textElem, data) {
431 var currentText = $(textElem).val();
432 $(textElem).val(currentText + data);
435 function jotVideoURL() {
436 reply = prompt(window.vidURL);
437 if (reply && reply.length) {
438 addeditortext("#profile-jot-text", '[video]' + reply + '[/video]');
442 function jotAudioURL() {
443 reply = prompt(window.audURL);
444 if (reply && reply.length) {
445 addeditortext("#profile-jot-text", '[audio]' + reply + '[/audio]');
450 function jotGetLocation() {
451 reply = prompt(window.whereAreU, $('#jot-location').val());
452 if (reply && reply.length) {
453 $('#jot-location').val(reply);
457 function jotShare(id) {
458 if ($('#jot-popup').length != 0) $('#jot-popup').show();
460 $('#like-rotator-' + id).show();
461 $.get('share/' + id, function(data) {
462 if (!editor) $("#profile-jot-text").val("");
463 initEditor(function() {
464 addeditortext("#profile-jot-text", data);
465 $('#like-rotator-' + id).hide();
466 $(window).scrollTop(0);
472 function jotClearLocation() {
473 $('#jot-coord').val('');
474 $('#profile-nolocation-wrapper').hide();
478 function jotGetLink() {
479 reply = prompt(window.linkURL);
480 if (reply && reply.length) {
481 reply = bin2hex(reply);
482 $('#profile-rotator').show();
483 $.get('parse_url?binurl=' + reply, function(data) {
484 addeditortext(window.jotId, data);
485 $('#profile-rotator').hide();
491 function linkdropper(event) {
492 var linkFound = event.dataTransfer.types.contains("text/uri-list");
494 event.preventDefault();
498 function linkdrop(event) {
499 var reply = event.dataTransfer.getData("text/uri-list");
500 event.preventDefault();
501 if (reply && reply.length) {
502 reply = bin2hex(reply);
503 $('#profile-rotator').show();
504 $.get('parse_url?binurl=' + reply, function(data) {
505 addeditortext(window.jotId, data);
506 $('#profile-rotator').hide();
512 if (typeof window.geoTag === 'function') window.geoTag();
519 function confirmDelete() { return confirm(window.delItem); }
521 function deleteCheckedItems(delID) {
522 if (confirm(window.delItems)) {
526 $(delID + '-rotator').show();
527 $('.item-select').each( function() {
528 if ($(this).is(':checked')) {
529 if (checkedstr.length != 0) {
530 checkedstr = checkedstr + ',' + $(this).val();
532 checkedstr = $(this).val();
536 $.post('item', { dropitems: checkedstr }, function(data) {
537 window.location.reload();
542 function itemTag(id) {
543 reply = prompt(window.term);
544 if (reply && reply.length) {
545 reply = reply.replace('#','');
549 $('body').css('cursor', 'wait');
551 $.get('tagger/' + id + '?term=' + reply, NavUpdate);
557 function itemFiler(id) {
559 var bordercolor = $("input").css("border-color");
561 $.get('filer/', function(data) {
562 $.colorbox({html:data});
564 $("#id_term").keypress(function() {
565 $(this).css("border-color",bordercolor);
567 $("#select_term").change(function() {
568 $("#id_term").css("border-color",bordercolor);
571 $("#filer_save").click(function(e) {
573 reply = $("#id_term").val();
574 if (reply && reply.length) {
576 $('body').css('cursor', 'wait');
577 $.get('filer/' + id + '?term=' + reply, NavUpdate);
581 $("#id_term").css("border-color","#FF0000");
594 function insertFormatting(BBcode, id) {
595 var tmpStr = $("#comment-edit-text-" + id).val();
597 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
598 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
599 openMenu("comment-edit-submit-wrapper-" + id);
602 textarea = document.getElementById("comment-edit-text-" +id);
603 if (document.selection) {
605 selected = document.selection.createRange();
606 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
607 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
608 var start = textarea.selectionStart;
609 var end = textarea.selectionEnd;
610 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
616 function cmtBbOpen(id) {
617 $("#comment-edit-bb-" + id).show();
619 function cmtBbClose(id) {
620 $("#comment-edit-bb-" + id).hide();
623 function commentOpen(obj,id) {
624 if (obj.value == "") {
625 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
626 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
627 $("#mod-cmnt-wrap-" + id).show();
628 openMenu("comment-edit-submit-wrapper-" + id);
631 function commentClose(obj,id) {
632 if (obj.value == "") {
633 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
634 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
635 $("#mod-cmnt-wrap-" + id).hide();
636 closeMenu("comment-edit-submit-wrapper-" + id);
641 function commentInsert(obj,id) {
642 var tmpStr = $("#comment-edit-text-" + id).val();
644 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
645 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
646 openMenu("comment-edit-submit-wrapper-" + id);
648 var ins = $(obj).html();
649 ins = ins.replace("<","<");
650 ins = ins.replace(">",">");
651 ins = ins.replace("&","&");
652 ins = ins.replace(""",'"');
653 $("#comment-edit-text-" + id).val(tmpStr + ins);
656 function qCommentInsert(obj,id) {
657 var tmpStr = $("#comment-edit-text-" + id).val();
659 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
660 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
661 openMenu("comment-edit-submit-wrapper-" + id);
663 var ins = $(obj).val();
664 ins = ins.replace("<","<");
665 ins = ins.replace(">",">");
666 ins = ins.replace("&","&");
667 ins = ins.replace(""",'"');
668 $("#comment-edit-text-" + id).val(tmpStr + ins);