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 $('html').height($('html').height());
406 $(this).readmore({maxheight:350 , moreLink:'<a href="#" class="showmore">+ Show more</a>', lessLink:'<a href="#" class="showmore">+ Show less</a>'});
407 $(this).addClass('divmore');
408 $('html').height('auto');
412 /* function imgbright(node) {
413 $(node).removeClass("drophide").addClass("drop");
416 function imgdull(node) {
417 $(node).removeClass("drop").addClass("drophide");
420 // Since our ajax calls are asynchronous, we will give a few
421 // seconds for the first ajax call (setting like/dislike), then
422 // run the updater to pick up any changes and display on the page.
423 // The updater will turn any rotators off when it's done.
424 // This function will have returned long before any of these
425 // events have completed and therefore there won't be any
426 // visible feedback that anything changed without all this
427 // trickery. This still could cause confusion if the "like" ajax call
428 // is delayed and NavUpdate runs before it completes.
430 function dolike(ident,verb) {
432 $('#like-rotator-' + ident.toString()).show();
433 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
434 // if(timer) clearTimeout(timer);
435 // timer = setTimeout(NavUpdate,3000);
439 function dostar(ident) {
440 ident = ident.toString();
441 //$('#like-rotator-' + ident).show();
442 $.get('starred/' + ident, function(data) {
443 if(data.match(/1/)) {
444 $('#starred-' + ident).addClass('starred');
445 $('#starred-' + ident).removeClass('unstarred');
446 $('#star-' + ident).addClass('hidden');
447 $('#unstar-' + ident).removeClass('hidden');
450 $('#starred-' + ident).addClass('unstarred');
451 $('#starred-' + ident).removeClass('starred');
452 $('#star-' + ident).removeClass('hidden');
453 $('#unstar-' + ident).addClass('hidden');
455 //$('#like-rotator-' + ident).hide();
459 function getPosition(e) {
460 var cursor = {x:0, y:0};
461 if ( e.pageX || e.pageY ) {
466 if( e.clientX || e.clientY ) {
467 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
468 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
480 var lockvisible = false;
482 function lockview(event,id) {
483 event = event || window.event;
484 cursor = getPosition(event);
490 $.get('lockview/' + id, function(data) {
491 $('#panel').html(data);
492 $('#panel').css({ 'left': 10 , 'top': cursor.y + 20});
498 function lockviewhide() {
503 function post_comment(id) {
506 $('body').css('cursor', 'wait');
507 $("#comment-preview-inp-" + id).val("0");
510 $("#comment-edit-form-" + id).serialize(),
513 $("#comment-edit-wrapper-" + id).hide();
514 $("#comment-edit-text-" + id).val('');
515 var tarea = document.getElementById("comment-edit-text-" + id);
517 commentClose(tarea,id);
518 if(timer) clearTimeout(timer);
519 timer = setTimeout(NavUpdate,10);
522 window.location.href=data.reload;
531 function preview_comment(id) {
532 $("#comment-preview-inp-" + id).val("1");
533 $("#comment-edit-preview-" + id).show();
536 $("#comment-edit-form-" + id).serialize(),
540 $("#comment-edit-preview-" + id).html(data.preview);
541 $("#comment-edit-preview-" + id + " a").click(function() { return false; });
550 function showHideComments(id) {
551 if( $("#collapsed-comments-" + id).is(":visible")) {
552 $("#collapsed-comments-" + id).hide();
553 $("#hide-comments-" + id).html(window.showMore);
556 $("#collapsed-comments-" + id).show();
557 $("#hide-comments-" + id).html(window.showFewer);
558 collapseHeight("#collapsed-comments-" + id);
563 function preview_post() {
564 $("#jot-preview").val("1");
565 $("#jot-preview-content").show();
566 tinyMCE.triggerSave();
569 $("#profile-jot-form").serialize(),
572 $("#jot-preview-content").html(data.preview);
573 $("#jot-preview-content" + " a").click(function() { return false; });
578 $("#jot-preview").val("0");
584 // unpause auto reloads if they are currently stopped
587 $('#pause').html('');
592 // Converts the binary representation of data to hex
595 // discuss at: http://phpjs.org/functions/bin2hex
596 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
597 // + bugfixed by: Onno Marsman
598 // + bugfixed by: Linuxworld
599 // * example 1: bin2hex('Kev');
600 // * returns 1: '4b6576'
601 // * example 2: bin2hex(String.fromCharCode(0x00));
603 var v,i, f = 0, a = [];
607 for (i = 0; i<f; i++) {
608 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
614 function groupChangeMember(gid, cid, sec_token) {
615 $('body .fakelink').css('cursor', 'wait');
616 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
617 $('#group-update-wrapper').html(data);
618 $('body .fakelink').css('cursor', 'auto');
622 function profChangeMember(gid,cid) {
623 $('body .fakelink').css('cursor', 'wait');
624 $.get('profperm/' + gid + '/' + cid, function(data) {
625 $('#prof-update-wrapper').html(data);
626 $('body .fakelink').css('cursor', 'auto');
630 function contactgroupChangeMember(gid,cid) {
631 $('body').css('cursor', 'wait');
632 $.get('contactgroup/' + gid + '/' + cid, function(data) {
633 $('body').css('cursor', 'auto');
638 function checkboxhighlight(box) {
639 if($(box).is(':checked')) {
640 $(box).addClass('checkeditem');
643 $(box).removeClass('checkeditem');
647 function notifyMarkAll() {
648 $.get('notify/mark/all', function(data) {
649 if(timer) clearTimeout(timer);
650 timer = setTimeout(NavUpdate,1000);
655 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
656 function fcFileBrowser (field_name, url, type, win) {
657 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
658 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
659 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
662 var cmsURL = baseurl+"/fbrowser/"+type+"/";
664 tinyMCE.activeEditor.windowManager.open({
666 title : 'File Browser',
667 width : 420, // Your dimensions may differ - toy around with them!
670 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
671 close_previous : "no"
679 function setupFieldRichtext(){
682 mode : "specific_textareas",
683 editor_selector: "fieldRichtext",
684 plugins : "bbcode,paste, inlinepopups",
685 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
686 theme_advanced_buttons2 : "",
687 theme_advanced_buttons3 : "",
688 theme_advanced_toolbar_location : "top",
689 theme_advanced_toolbar_align : "center",
690 theme_advanced_blockformats : "blockquote,code",
691 paste_text_sticky : true,
692 entity_encoding : "raw",
693 add_unload_trigger : false,
694 remove_linebreaks : false,
695 //force_p_newlines : false,
696 //force_br_newlines : true,
697 forced_root_block : 'div',
699 content_css: baseurl+"/view/custom_tinymce.css",
700 theme_advanced_path : false,
701 file_browser_callback : "fcFileBrowser",
707 * sprintf in javascript
708 * "{0} and {1}".format('zero','uno');
710 String.prototype.format = function() {
711 var formatted = this;
712 for (var i = 0; i < arguments.length; i++) {
713 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
714 formatted = formatted.replace(regexp, arguments[i]);
719 Array.prototype.remove = function(item) {
720 to=undefined; from=this.indexOf(item);
721 var rest = this.slice((to || from) + 1 || this.length);
722 this.length = from < 0 ? this.length + from : from;
723 return this.push.apply(this, rest);
726 function previewTheme(elm) {
727 theme = $(elm).val();
728 $.getJSON('pretheme?f=&theme=' + theme,function(data) {
729 $('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div>');