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($j(listID).is(":visible")) {
15 $j(listID+"-wrapper").show();
16 alert($j(listID+"-wrapper").attr("id"));
20 $j(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"
39 var totStopped = false;
43 var in_progress = false;
44 var langSelect = false;
45 var commentBusy = false;
46 var last_popup_menu = null;
47 var last_popup_button = null;
50 $j.ajaxSetup({cache: false});
52 msie = $j.browser.msie ;
56 /* setup tooltips *//*
57 $j("a,.tt").each(function(){
60 if (e.hasClass("tttop")) pos="top";
61 if (e.hasClass("ttbottom")) pos="bottom";
62 if (e.hasClass("ttleft")) pos="left";
63 if (e.hasClass("ttright")) pos="right";
64 e.tipTip({defaultPosition: pos, edgeOffset: 8});
69 /* setup onoff widgets */
70 $j(".onoff input").each(function(){
72 id = $j(this).attr("id");
73 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
76 $j(".onoff > a").click(function(event){
77 event.preventDefault();
78 var input = $j(this).siblings("input");
79 var val = 1-input.val();
80 var id = input.attr("id");
81 $j("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
82 $j("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
87 /* setup field_richtext */
88 /*setupFieldRichtext();*/
91 function close_last_popup_menu(e) {
93 if( last_popup_menu ) {
94 if( '#' + last_popup_menu.attr('id') !== $j(e.target).attr('rel')) {
95 last_popup_menu.hide();
96 if (last_popup_menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').show();
97 last_popup_button.removeClass("selected");
98 last_popup_menu = null;
99 last_popup_button = null;
103 $j('img[rel^=#]').click(function(e){
105 close_last_popup_menu(e);
106 menu = $j( $j(this).attr('rel') );
110 if (menu.attr('popup')=="false") return false;
112 // $j(this).parent().toggleClass("selected");
115 if (menu.css("display") == "none") {
116 $j(this).parent().addClass("selected");
118 if (menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').hide();
119 last_popup_menu = menu;
120 last_popup_button = $j(this).parent();
122 $j(this).parent().removeClass("selected");
124 if (menu.attr('id') == "nav-notifications-menu" ) $j('.main-container').show();
125 last_popup_menu = null;
126 last_popup_button = null;
130 $j('html').click(function(e) {
131 close_last_popup_menu(e);
135 /*$j("a.popupbox").colorbox({
137 'transition' : 'none'
141 /* notifications template */
142 var notifications_tpl= unescape($j("#nav-notifications-template[rel=template]").html());
143 var notifications_all = unescape($j('<div>').append( $j("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
144 var notifications_mark = unescape($j('<div>').append( $j("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
145 var notifications_empty = unescape($j("#nav-notifications-menu").html());
147 /* nav update event */
148 $j('nav').bind('nav-update', function(e,data){;
149 var invalid = $j(data).find('invalid').text();
150 if(invalid == 1) { window.location.href=window.location.href }
152 var net = $j(data).find('net').text();
153 if(net == 0) { net = ''; $j('#net-update').removeClass('show') } else { $j('#net-update').addClass('show') }
154 $j('#net-update').html(net);
156 var home = $j(data).find('home').text();
157 if(home == 0) { home = ''; $j('#home-update').removeClass('show') } else { $j('#home-update').addClass('show') }
158 $j('#home-update').html(home);
160 var intro = $j(data).find('intro').text();
161 if(intro == 0) { intro = ''; $j('#intro-update').removeClass('show') } else { $j('#intro-update').addClass('show') }
162 $j('#intro-update').html(intro);
164 var mail = $j(data).find('mail').text();
165 if(mail == 0) { mail = ''; $j('#mail-update').removeClass('show') } else { $j('#mail-update').addClass('show') }
166 $j('#mail-update').html(mail);
168 var intro = $j(data).find('intro').text();
169 if(intro == 0) { intro = ''; $j('#intro-update-li').removeClass('show') } else { $j('#intro-update-li').addClass('show') }
170 $j('#intro-update-li').html(intro);
172 var mail = $j(data).find('mail').text();
173 if(mail == 0) { mail = ''; $j('#mail-update-li').removeClass('show') } else { $j('#mail-update-li').addClass('show') }
174 $j('#mail-update-li').html(mail);
176 var eNotif = $j(data).find('notif')
178 if (eNotif.children("note").length==0){
179 $j("#nav-notifications-menu").html(notifications_empty);
181 nnm = $j("#nav-notifications-menu");
182 nnm.html(notifications_all + notifications_mark);
183 //nnm.attr('popup','true');
184 eNotif.children("note").each(function(){
186 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
187 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
191 $j("img[data-src]", nnm).each(function(i, el){
192 // Add src attribute for images with a data-src attribute
193 // However, don't bother if the data-src attribute is empty, because
194 // an empty "src" tag for an image will cause some browsers
195 // to prefetch the root page of the Friendica hub, which will
196 // unnecessarily load an entire profile/ or network/ page
197 if($j(el).data("src") != '') $j(el).attr('src', $j(el).data("src"));
200 notif = eNotif.attr('count');
202 $j("#nav-notifications-linkmenu").addClass("on");
204 $j("#nav-notifications-linkmenu").removeClass("on");
206 if(notif == 0) { notif = ''; $j('#notify-update').removeClass('show') } else { $j('#notify-update').addClass('show') }
207 $j('#notify-update').html(notif);
209 var eSysmsg = $j(data).find('sysmsgs');
210 eSysmsg.children("notice").each(function(){
211 text = $j(this).text();
212 $j.jGrowl(text, { sticky: false, theme: 'notice', life: 1000 });
214 eSysmsg.children("info").each(function(){
215 text = $j(this).text();
216 $j.jGrowl(text, { sticky: false, theme: 'info', life: 1000 });
223 // Allow folks to stop the ajax page updates with the pause/break key
224 /* $j(document).keydown(function(event) {
225 if(event.keyCode == '8') {
226 var target = event.target || event.srcElement;
227 if (!/input|textarea/i.test(target.nodeName)) {
231 if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
232 event.preventDefault();
233 if(stopped == false) {
238 $j('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
252 function NavUpdate() {
255 var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
256 $j.get(pingCmd,function(data) {
257 $j(data).find('result').each(function() {
258 // send nav-update event
259 $j('nav').trigger('nav-update', this);
266 if($j('#live-network').length) { src = 'network'; liveUpdate(); }
267 if($j('#live-profile').length) { src = 'profile'; liveUpdate(); }
268 if($j('#live-community').length) { src = 'community'; liveUpdate(); }
269 if($j('#live-notes').length) { src = 'notes'; liveUpdate(); }
270 if($j('#live-display').length) { src = 'display'; liveUpdate(); }
271 /*if($j('#live-display').length) {
274 window.location.href=window.location.href
277 if($j('#live-photos').length) {
280 window.location.href=window.location.href
290 timer = setTimeout(NavUpdate,updateInterval);
293 function liveUpdate() {
294 if((src == null) || (stopped) || (typeof profile_uid == 'undefined') || (! profile_uid)) { $j('.like-rotator').hide(); return; }
295 if(($j('.comment-edit-text-full').length) || (in_progress)) {
297 clearTimeout(livetime);
299 livetime = setTimeout(liveUpdate, 10000);
305 prev = 'live-' + src;
308 var udargs = ((netargs.length) ? '/' + netargs : '');
309 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
311 $j.get(update_url,function(data) {
313 // $j('.collapsed-comments',data).each(function() {
314 // var ident = $j(this).attr('id');
315 // var is_hidden = $j('#' + ident).is(':hidden');
316 // if($j('#' + ident).length) {
317 // $j('#' + ident).replaceWith($j(this));
319 // $j('#' + ident).hide();
325 $j('.toplevel_item',data).each(function() {
326 var ident = $j(this).attr('id');
328 if($j('#' + ident).length == 0 && profile_page == 1) {
329 $j('img',this).each(function() {
330 $j(this).attr('src',$j(this).attr('dst'));
332 $j('#' + prev).after($j(this));
335 // Find out if the hidden comments are open, so we can keep it that way
336 // if a new comment has been posted
337 var id = $j('.hide-comments-total', this).attr('id');
338 if(typeof id != 'undefined') {
339 id = id.split('-')[3];
340 var commentsOpen = $j("#collapsed-comments-" + id).is(":visible");
343 $j('img',this).each(function() {
344 $j(this).attr('src',$j(this).attr('dst'));
346 //vScroll = $j(document).scrollTop();
347 $j('html').height($j('html').height());
348 $j('#' + ident).replaceWith($j(this));
350 if(typeof id != 'undefined') {
351 if(commentsOpen) showHideComments(id);
353 $j('html').height('auto');
354 //$j(document).scrollTop(vScroll);
362 // reset vars for inserting individual items
364 /*prev = 'live-' + src;
366 $j('.wall-item-outside-wrapper',data).each(function() {
367 var ident = $j(this).attr('id');
369 if($j('#' + ident).length == 0 && prev != 'live-' + src) {
370 $j('img',this).each(function() {
371 $j(this).attr('src',$j(this).attr('dst'));
373 $j('#' + prev).after($j(this));
376 $j('#' + ident + ' ' + '.wall-item-ago').replaceWith($j(this).find('.wall-item-ago'));
377 if($j('#' + ident + ' ' + '.comment-edit-text-empty').length)
378 $j('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($j(this).find('.wall-item-comment-wrapper'));
379 $j('#' + ident + ' ' + '.hide-comments-total').replaceWith($j(this).find('.hide-comments-total'));
380 $j('#' + ident + ' ' + '.wall-item-like').replaceWith($j(this).find('.wall-item-like'));
381 $j('#' + ident + ' ' + '.wall-item-dislike').replaceWith($j(this).find('.wall-item-dislike'));
382 $j('#' + ident + ' ' + '.my-comment-photo').each(function() {
383 $j(this).attr('src',$j(this).attr('dst'));
389 $j('.like-rotator').hide();
392 $j('body').css('cursor', 'auto');
394 /* autocomplete @nicknames */
395 $j(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl");
397 // setup videos, since VideoJS won't take care of any loaded via AJAX
398 if(typeof videojs != 'undefined') videojs.autoSetup();
402 function collapseHeight(elems) {
403 var elemName = '.wall-item-body:not(.divmore)';
404 if(typeof elems != 'undefined') {
405 elemName = elems + ' ' + elemName;
407 $j(elemName).each(function() {
408 if($j(this).height() > 350) {
409 $j('html').height($j('html').height());
410 $j(this).divgrow({ initialHeight: 300, showBrackets: false, speed: 0 });
411 $j(this).addClass('divmore');
412 $j('html').height('auto');
417 /* function imgbright(node) {
418 $j(node).removeClass("drophide").addClass("drop");
421 function imgdull(node) {
422 $j(node).removeClass("drop").addClass("drophide");
425 // Since our ajax calls are asynchronous, we will give a few
426 // seconds for the first ajax call (setting like/dislike), then
427 // run the updater to pick up any changes and display on the page.
428 // The updater will turn any rotators off when it's done.
429 // This function will have returned long before any of these
430 // events have completed and therefore there won't be any
431 // visible feedback that anything changed without all this
432 // trickery. This still could cause confusion if the "like" ajax call
433 // is delayed and NavUpdate runs before it completes.
435 function dolike(ident,verb) {
437 $j('#like-rotator-' + ident.toString()).show();
438 $j.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
439 // if(timer) clearTimeout(timer);
440 // timer = setTimeout(NavUpdate,3000);
444 function dostar(ident) {
445 ident = ident.toString();
446 //$j('#like-rotator-' + ident).show();
447 $j.get('starred/' + ident, function(data) {
448 if(data.match(/1/)) {
449 $j('#starred-' + ident).addClass('starred');
450 $j('#starred-' + ident).removeClass('unstarred');
451 $j('#star-' + ident).addClass('hidden');
452 $j('#unstar-' + ident).removeClass('hidden');
455 $j('#starred-' + ident).addClass('unstarred');
456 $j('#starred-' + ident).removeClass('starred');
457 $j('#star-' + ident).removeClass('hidden');
458 $j('#unstar-' + ident).addClass('hidden');
460 //$j('#like-rotator-' + ident).hide();
464 function getPosition(e) {
465 var cursor = {x:0, y:0};
466 if ( e.pageX || e.pageY ) {
471 if( e.clientX || e.clientY ) {
472 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
473 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
485 var lockvisible = false;
487 function lockview(event,id) {
488 event = event || window.event;
489 cursor = getPosition(event);
495 $j.get('lockview/' + id, function(data) {
496 $j('#panel').html(data);
497 $j('#panel').css({ 'left': 10 , 'top': cursor.y + 20});
503 function lockviewhide() {
508 function post_comment(id) {
511 $j('body').css('cursor', 'wait');
512 $j("#comment-preview-inp-" + id).val("0");
515 $j("#comment-edit-form-" + id).serialize(),
518 $j("#comment-edit-wrapper-" + id).hide();
519 $j("#comment-edit-text-" + id).val('');
520 var tarea = document.getElementById("comment-edit-text-" + id);
522 commentClose(tarea,id);
523 if(timer) clearTimeout(timer);
524 timer = setTimeout(NavUpdate,10);
527 window.location.href=data.reload;
536 function preview_comment(id) {
537 $j("#comment-preview-inp-" + id).val("1");
538 $j("#comment-edit-preview-" + id).show();
541 $j("#comment-edit-form-" + id).serialize(),
545 $j("#comment-edit-preview-" + id).html(data.preview);
546 $j("#comment-edit-preview-" + id + " a").click(function() { return false; });
555 function showHideComments(id) {
556 if( $j("#collapsed-comments-" + id).is(":visible")) {
557 $j("#collapsed-comments-" + id).hide();
558 $j("#hide-comments-" + id).html(window.showMore);
561 $j("#collapsed-comments-" + id).show();
562 $j("#hide-comments-" + id).html(window.showFewer);
563 collapseHeight("#collapsed-comments-" + id);
568 function preview_post() {
569 $j("#jot-preview").val("1");
570 $j("#jot-preview-content").show();
571 tinyMCE.triggerSave();
574 $j("#profile-jot-form").serialize(),
577 $j("#jot-preview-content").html(data.preview);
578 $j("#jot-preview-content" + " a").click(function() { return false; });
583 $j("#jot-preview").val("0");
589 // unpause auto reloads if they are currently stopped
592 $j('#pause').html('');
597 // Converts the binary representation of data to hex
600 // discuss at: http://phpjs.org/functions/bin2hex
601 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
602 // + bugfixed by: Onno Marsman
603 // + bugfixed by: Linuxworld
604 // * example 1: bin2hex('Kev');
605 // * returns 1: '4b6576'
606 // * example 2: bin2hex(String.fromCharCode(0x00));
608 var v,i, f = 0, a = [];
612 for (i = 0; i<f; i++) {
613 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
619 function groupChangeMember(gid, cid, sec_token) {
620 $j('body .fakelink').css('cursor', 'wait');
621 $j.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
622 $j('#group-update-wrapper').html(data);
623 $j('body .fakelink').css('cursor', 'auto');
627 function profChangeMember(gid,cid) {
628 $j('body .fakelink').css('cursor', 'wait');
629 $j.get('profperm/' + gid + '/' + cid, function(data) {
630 $j('#prof-update-wrapper').html(data);
631 $j('body .fakelink').css('cursor', 'auto');
635 function contactgroupChangeMember(gid,cid) {
636 $j('body').css('cursor', 'wait');
637 $j.get('contactgroup/' + gid + '/' + cid, function(data) {
638 $j('body').css('cursor', 'auto');
643 function checkboxhighlight(box) {
644 if($j(box).is(':checked')) {
645 $j(box).addClass('checkeditem');
648 $j(box).removeClass('checkeditem');
652 function notifyMarkAll() {
653 $j.get('notify/mark/all', function(data) {
654 if(timer) clearTimeout(timer);
655 timer = setTimeout(NavUpdate,1000);
660 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
661 function fcFileBrowser (field_name, url, type, win) {
662 /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
663 the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
664 These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
667 var cmsURL = baseurl+"/fbrowser/"+type+"/";
669 tinyMCE.activeEditor.windowManager.open({
671 title : 'File Browser',
672 width : 420, // Your dimensions may differ - toy around with them!
675 inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
676 close_previous : "no"
684 function setupFieldRichtext(){
687 mode : "specific_textareas",
688 editor_selector: "fieldRichtext",
689 plugins : "bbcode,paste, inlinepopups",
690 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
691 theme_advanced_buttons2 : "",
692 theme_advanced_buttons3 : "",
693 theme_advanced_toolbar_location : "top",
694 theme_advanced_toolbar_align : "center",
695 theme_advanced_blockformats : "blockquote,code",
696 paste_text_sticky : true,
697 entity_encoding : "raw",
698 add_unload_trigger : false,
699 remove_linebreaks : false,
700 //force_p_newlines : false,
701 //force_br_newlines : true,
702 forced_root_block : 'div',
704 content_css: baseurl+"/view/custom_tinymce.css",
705 theme_advanced_path : false,
706 file_browser_callback : "fcFileBrowser",
712 * sprintf in javascript
713 * "{0} and {1}".format('zero','uno');
715 String.prototype.format = function() {
716 var formatted = this;
717 for (var i = 0; i < arguments.length; i++) {
718 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
719 formatted = formatted.replace(regexp, arguments[i]);
724 Array.prototype.remove = function(item) {
725 to=undefined; from=this.indexOf(item);
726 var rest = this.slice((to || from) + 1 || this.length);
727 this.length = from < 0 ? this.length + from : from;
728 return this.push.apply(this, rest);
731 function previewTheme(elm) {
732 theme = $j(elm).val();
733 $j.getJSON('pretheme?f=&theme=' + theme,function(data) {
734 $j('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div>');