2 function openClose(listID) {
3 /* if(document.getElementById(theID).style.display == "block") {
4 document.getElementById(theID).style.display = "none"
7 document.getElementById(theID).style.display = "block"
9 listID = "#" + listID.replace(/:/g, "\\:");
10 listID = listID.replace(/\./g, "\\.");
11 listID = listID.replace(/@/g, "\\@");
13 if($(listID).is(":visible")) {
15 $(listID+"-wrapper").show();
16 alert($(listID+"-wrapper").attr("id"));
20 $(listID+"-wrapper").hide();
24 function openMenu(theID) {
25 document.getElementById(theID).style.display = "block"
28 function closeMenu(theID) {
29 document.getElementById(theID).style.display = "none"
38 var totStopped = false;
42 var in_progress = false;
43 var langSelect = false;
44 var commentBusy = false;
45 var last_popup_menu = null;
46 var last_popup_button = null;
49 $.ajaxSetup({cache: false});
53 /* setup tooltips *//*
54 $("a,.tt").each(function(){
57 if (e.hasClass("tttop")) pos="top";
58 if (e.hasClass("ttbottom")) pos="bottom";
59 if (e.hasClass("ttleft")) pos="left";
60 if (e.hasClass("ttright")) pos="right";
61 e.tipTip({defaultPosition: pos, edgeOffset: 8});
66 /* setup onoff widgets */
67 $(".onoff input").each(function(){
69 id = $(this).attr("id");
70 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
73 $(".onoff > a").click(function(event){
74 event.preventDefault();
75 var input = $(this).siblings("input");
76 var val = 1-input.val();
77 var id = input.attr("id");
78 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
79 $("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
84 /* setup field_richtext */
85 /*setupFieldRichtext();*/
88 function close_last_popup_menu(e) {
90 if( last_popup_menu ) {
91 if( '#' + last_popup_menu.attr('id') !== $(e.target).attr('rel')) {
92 last_popup_menu.hide();
93 if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $('.main-container').show();
94 last_popup_button.removeClass("selected");
95 last_popup_menu = null;
96 last_popup_button = null;
100 $('img[rel^=#]').click(function(e){
102 close_last_popup_menu(e);
103 menu = $( $(this).attr('rel') );
107 if (menu.attr('popup')=="false") return false;
109 // $(this).parent().toggleClass("selected");
112 if (menu.css("display") == "none") {
113 $(this).parent().addClass("selected");
115 if (menu.attr('id') == "nav-notifications-menu" ) $('.main-container').hide();
116 last_popup_menu = menu;
117 last_popup_button = $(this).parent();
119 $(this).parent().removeClass("selected");
121 if (menu.attr('id') == "nav-notifications-menu" ) $('.main-container').show();
122 last_popup_menu = null;
123 last_popup_button = null;
127 $('html').click(function(e) {
128 close_last_popup_menu(e);
132 /*$("a.popupbox").colorbox({
134 'transition' : 'none'
138 /* notifications template */
139 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
140 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
141 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
142 var notifications_empty = unescape($("#nav-notifications-menu").html());
144 /* nav update event */
145 $('nav').bind('nav-update', function(e,data){;
146 var invalid = $(data).find('invalid').text();
147 if(invalid == 1) { window.location.href=window.location.href }
149 var net = $(data).find('net').text();
150 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
151 $('#net-update').html(net);
153 var home = $(data).find('home').text();
154 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
155 $('#home-update').html(home);
157 var intro = $(data).find('intro').text();
158 if(intro == 0) { intro = ''; $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
159 $('#intro-update').html(intro);
161 var mail = $(data).find('mail').text();
162 if(mail == 0) { mail = ''; $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
163 $('#mail-update').html(mail);
165 var intro = $(data).find('intro').text();
166 if(intro == 0) { intro = ''; $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
167 $('#intro-update-li').html(intro);
169 var mail = $(data).find('mail').text();
170 if(mail == 0) { mail = ''; $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
171 $('#mail-update-li').html(mail);
173 var eNotif = $(data).find('notif')
175 if (eNotif.children("note").length==0){
176 $("#nav-notifications-menu").html(notifications_empty);
178 nnm = $("#nav-notifications-menu");
179 nnm.html(notifications_all + notifications_mark);
180 //nnm.attr('popup','true');
181 eNotif.children("note").each(function(){
183 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
184 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
188 $("img[data-src]", nnm).each(function(i, el){
189 // Add src attribute for images with a data-src attribute
190 // However, don't bother if the data-src attribute is empty, because
191 // an empty "src" tag for an image will cause some browsers
192 // to prefetch the root page of the Friendica hub, which will
193 // unnecessarily load an entire profile/ or network/ page
194 if($(el).data("src") != '') $(el).attr('src', $(el).data("src"));
197 notif = eNotif.attr('count');
199 $("#nav-notifications-linkmenu").addClass("on");
201 $("#nav-notifications-linkmenu").removeClass("on");
203 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
204 $('#notify-update').html(notif);
206 var eSysmsg = $(data).find('sysmsgs');
207 eSysmsg.children("notice").each(function(){
208 text = $(this).text();
209 $.jGrowl(text, { sticky: false, theme: 'notice', life: 1000 });
211 eSysmsg.children("info").each(function(){
212 text = $(this).text();
213 $.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
220 // Allow folks to stop the ajax page updates with the pause/break key
221 /* $(document).keydown(function(event) {
222 if(event.keyCode == '8') {
223 var target = event.target || event.srcElement;
224 if (!/input|textarea/i.test(target.nodeName)) {
228 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
229 event.preventDefault();
230 if(stopped == false) {
235 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
249 function NavUpdate() {
252 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
253 $.get(pingCmd,function(data) {
254 $(data).find('result').each(function() {
255 // send nav-update event
256 $('nav').trigger('nav-update', this);
263 if($('#live-network').length) { src = 'network'; liveUpdate(); }
264 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
265 if($('#live-community').length) { src = 'community'; liveUpdate(); }
266 if($('#live-notes').length) { src = 'notes'; liveUpdate(); }
267 if($('#live-display').length) { src = 'display'; liveUpdate(); }
268 /*if($('#live-display').length) {
271 window.location.href=window.location.href
274 if($('#live-photos').length) {
277 window.location.href=window.location.href
287 timer = setTimeout(NavUpdate,updateInterval);
290 function liveUpdate() {
291 if((src == null) || (stopped) || (typeof profile_uid == 'undefined') || (! profile_uid)) { $('.like-rotator').hide(); return; }
292 if(($('.comment-edit-text-full').length) || (in_progress)) {
294 clearTimeout(livetime);
296 livetime = setTimeout(liveUpdate, 10000);
302 prev = 'live-' + src;
305 var udargs = ((netargs.length) ? '/' + netargs : '');
306 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page;
308 $.get(update_url,function(data) {
310 // $('.collapsed-comments',data).each(function() {
311 // var ident = $(this).attr('id');
312 // var is_hidden = $('#' + ident).is(':hidden');
313 // if($('#' + ident).length) {
314 // $('#' + ident).replaceWith($(this));
316 // $('#' + ident).hide();
322 $('.toplevel_item',data).each(function() {
323 var ident = $(this).attr('id');
325 if($('#' + ident).length == 0 && profile_page == 1) {
326 $('img',this).each(function() {
327 $(this).attr('src',$(this).attr('dst'));
329 $('#' + prev).after($(this));
332 // Find out if the hidden comments are open, so we can keep it that way
333 // if a new comment has been posted
334 var id = $('.hide-comments-total', this).attr('id');
335 if(typeof id != 'undefined') {
336 id = id.split('-')[3];
337 var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
340 $('img',this).each(function() {
341 $(this).attr('src',$(this).attr('dst'));
343 //vScroll = $(document).scrollTop();
344 $('html').height($('html').height());
345 $('#' + ident).replaceWith($(this));
347 if(typeof id != 'undefined') {
348 if(commentsOpen) showHideComments(id);
350 $('html').height('auto');
351 //$(document).scrollTop(vScroll);
359 // reset vars for inserting individual items
361 /*prev = 'live-' + src;
363 $('.wall-item-outside-wrapper',data).each(function() {
364 var ident = $(this).attr('id');
366 if($('#' + ident).length == 0 && prev != 'live-' + src) {
367 $('img',this).each(function() {
368 $(this).attr('src',$(this).attr('dst'));
370 $('#' + prev).after($(this));
373 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
374 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
375 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
376 $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
377 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
378 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
379 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
380 $(this).attr('src',$(this).attr('dst'));
386 $('.like-rotator').hide();
389 $('body').css('cursor', 'auto');
391 /* autocomplete @nicknames */
392 $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
394 // setup videos, since VideoJS won't take care of any loaded via AJAX
395 if(typeof videojs != 'undefined') videojs.autoSetup();
399 function collapseHeight(elems) {
400 var elemName = '.wall-item-body:not(.divmore)';
401 if(typeof elems != 'undefined') {
402 elemName = elems + ' ' + elemName;
404 $(elemName).each(function() {
405 if($(this).height() > 350) {
406 $('html').height($('html').height());
407 $(this).divgrow({ initialHeight: 300, showBrackets: false, speed: 0 });
408 $(this).addClass('divmore');
409 $('html').height('auto');
414 /* function imgbright(node) {
415 $(node).removeClass("drophide").addClass("drop");
418 function imgdull(node) {
419 $(node).removeClass("drop").addClass("drophide");
422 // Since our ajax calls are asynchronous, we will give a few
423 // seconds for the first ajax call (setting like/dislike), then
424 // run the updater to pick up any changes and display on the page.
425 // The updater will turn any rotators off when it's done.
426 // This function will have returned long before any of these
427 // events have completed and therefore there won't be any
428 // visible feedback that anything changed without all this
429 // trickery. This still could cause confusion if the "like" ajax call
430 // is delayed and NavUpdate runs before it completes.
432 function dolike(ident,verb) {
434 $('#like-rotator-' + ident.toString()).show();
435 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
436 // if(timer) clearTimeout(timer);
437 // timer = setTimeout(NavUpdate,3000);
441 function dostar(ident) {
442 ident = ident.toString();
443 //$('#like-rotator-' + ident).show();
444 $.get('starred/' + ident, function(data) {
445 if(data.match(/1/)) {
446 $('#starred-' + ident).addClass('starred');
447 $('#starred-' + ident).removeClass('unstarred');
448 $('#star-' + ident).addClass('hidden');
449 $('#unstar-' + ident).removeClass('hidden');
452 $('#starred-' + ident).addClass('unstarred');
453 $('#starred-' + ident).removeClass('starred');
454 $('#star-' + ident).removeClass('hidden');
455 $('#unstar-' + ident).addClass('hidden');
457 //$('#like-rotator-' + ident).hide();
461 function getPosition(e) {
462 var cursor = {x:0, y:0};
463 if ( e.pageX || e.pageY ) {
468 if( e.clientX || e.clientY ) {
469 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
470 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
482 var lockvisible = false;
484 function lockview(event,id) {
485 event = event || window.event;
486 cursor = getPosition(event);
492 $.get('lockview/' + id, function(data) {
493 $('#panel').html(data);
494 $('#panel').css({ 'left': 10 , 'top': cursor.y + 20});
500 function lockviewhide() {
505 function post_comment(id) {
508 $('body').css('cursor', 'wait');
509 $("#comment-preview-inp-" + id).val("0");
512 $("#comment-edit-form-" + id).serialize(),
515 $("#comment-edit-wrapper-" + id).hide();
516 $("#comment-edit-text-" + id).val('');
517 var tarea = document.getElementById("comment-edit-text-" + id);
519 commentClose(tarea,id);
520 if(timer) clearTimeout(timer);
521 timer = setTimeout(NavUpdate,10);
524 window.location.href=data.reload;
533 function preview_comment(id) {
534 $("#comment-preview-inp-" + id).val("1");
535 $("#comment-edit-preview-" + id).show();
538 $("#comment-edit-form-" + id).serialize(),
542 $("#comment-edit-preview-" + id).html(data.preview);
543 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
552 function showHideComments(id) {
553 if( $("#collapsed-comments-" + id).is(":visible")) {
554 $("#collapsed-comments-" + id).hide();
555 $("#hide-comments-" + id).html(window.showMore);
558 $("#collapsed-comments-" + id).show();
559 $("#hide-comments-" + id).html(window.showFewer);
560 collapseHeight("#collapsed-comments-" + id);
565 function preview_post() {
566 $("#jot-preview").val("1");
567 $("#jot-preview-content").show();
568 tinyMCE.triggerSave();
571 $("#profile-jot-form").serialize(),
574 $("#jot-preview-content").html(data.preview);
575 $("#jot-preview-content" + " a").click(function() { return false; });
580 $("#jot-preview").val("0");
586 // unpause auto reloads if they are currently stopped
589 $('#pause').html('');
594 // Converts the binary representation of data to hex
597 // discuss at: http://phpjs.org/functions/bin2hex
598 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
599 // + bugfixed by: Onno Marsman
600 // + bugfixed by: Linuxworld
601 // * example 1: bin2hex('Kev');
602 // * returns 1: '4b6576'
603 // * example 2: bin2hex(String.fromCharCode(0x00));
605 var v,i, f = 0, a = [];
609 for (i = 0; i<f; i++) {
610 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
616 function groupChangeMember(gid, cid, sec_token) {
617 $('body .fakelink').css('cursor', 'wait');
618 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
619 $('#group-update-wrapper').html(data);
620 $('body .fakelink').css('cursor', 'auto');
624 function profChangeMember(gid,cid) {
625 $('body .fakelink').css('cursor', 'wait');
626 $.get('profperm/' + gid + '/' + cid, function(data) {
627 $('#prof-update-wrapper').html(data);
628 $('body .fakelink').css('cursor', 'auto');
632 function contactgroupChangeMember(gid,cid) {
633 $('body').css('cursor', 'wait');
634 $.get('contactgroup/' + gid + '/' + cid, function(data) {
635 $('body').css('cursor', 'auto');
640 function checkboxhighlight(box) {
641 if($(box).is(':checked')) {
642 $(box).addClass('checkeditem');
645 $(box).removeClass('checkeditem');
649 function notifyMarkAll() {
650 $.get('notify/mark/all', function(data) {
651 if(timer) clearTimeout(timer);
652 timer = setTimeout(NavUpdate,1000);
657 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
658 function fcFileBrowser (field_name, url, type, win) {
659 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
660 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
661 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
664 var cmsURL = baseurl+"/fbrowser/"+type+"/";
666 tinyMCE.activeEditor.windowManager.open({
668 title : 'File Browser',
669 width : 420, // Your dimensions may differ - toy around with them!
672 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
673 close_previous : "no"
681 function setupFieldRichtext(){
684 mode : "specific_textareas",
685 editor_selector: "fieldRichtext",
686 plugins : "bbcode,paste, inlinepopups",
687 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
688 theme_advanced_buttons2 : "",
689 theme_advanced_buttons3 : "",
690 theme_advanced_toolbar_location : "top",
691 theme_advanced_toolbar_align : "center",
692 theme_advanced_blockformats : "blockquote,code",
693 paste_text_sticky : true,
694 entity_encoding : "raw",
695 add_unload_trigger : false,
696 remove_linebreaks : false,
697 //force_p_newlines : false,
698 //force_br_newlines : true,
699 forced_root_block : 'div',
701 content_css: baseurl+"/view/custom_tinymce.css",
702 theme_advanced_path : false,
703 file_browser_callback : "fcFileBrowser",
709 * sprintf in javascript
710 * "{0} and {1}".format('zero','uno');
712 String.prototype.format = function() {
713 var formatted = this;
714 for (var i = 0; i < arguments.length; i++) {
715 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
716 formatted = formatted.replace(regexp, arguments[i]);
721 Array.prototype.remove = function(item) {
722 to=undefined; from=this.indexOf(item);
723 var rest = this.slice((to || from) + 1 || this.length);
724 this.length = from < 0 ? this.length + from : from;
725 return this.push.apply(this, rest);
728 function previewTheme(elm) {
729 theme = $(elm).val();
730 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
731 $('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div>');