2 function openClose(theID) {
3 if(document.getElementById(theID).style.display == "block") {
4 document.getElementById(theID).style.display = "none"
7 document.getElementById(theID).style.display = "block"
11 function openMenu(theID) {
12 document.getElementById(theID).style.display = "block"
15 function closeMenu(theID) {
16 document.getElementById(theID).style.display = "none"
28 var in_progress = false;
29 var langSelect = false;
30 var commentBusy = false;
33 $.ajaxSetup({cache: false});
35 msie = $.browser.msie ;
37 /* setup navbar menus */
41 /* setup onoff widgets */
42 $(".onoff input").each(function(){
44 id = $(this).attr("id");
45 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
48 $(".onoff > a").click(function(event){
49 event.preventDefault();
50 var input = $(this).siblings("input");
51 var val = 1-input.val();
52 var id = input.attr("id");
53 $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
54 $("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
59 /* setup field_richtext */
63 $('a[rel^=#]').click(function(e){
64 menu = $( $(this).attr('rel') );
66 if (menu.attr('popup')=="false") return false;
67 $(this).parent().toggleClass("selected");
74 /* notifications template */
75 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
76 var notifications_empty = unescape($("#nav-notifications-menu").html());
78 /* nav update event */
79 $('nav').bind('nav-update', function(e,data){;
80 var net = $(data).find('net').text();
81 if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
82 $('#net-update').html(net);
84 var home = $(data).find('home').text();
85 if(home == 0) { home = ''; $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
86 $('#home-update').html(home);
88 var eNotif = $(data).find('notif')
89 notif = eNotif.attr('count');
91 nnm = $("#nav-notifications-menu");
93 nnm.attr('popup','true');
94 eNotif.children("note").each(function(){
96 text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
97 html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'));
101 $("#nav-notifications-menu").html(notifications_empty);
103 if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
104 $('#notify-update').html(notif);
110 // Allow folks to stop the ajax page updates with the pause/break key
111 $(document).keypress(function(event) {
112 if(event.keyCode == '19') {
113 event.preventDefault();
114 if(stopped == false) {
116 $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
120 $('#pause').html('');
125 if(stopped == true) {
127 $('#pause').html('');
134 function NavUpdate() {
136 if($('#live-network').length) { src = 'network'; liveUpdate(); }
137 if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
138 if($('#live-community').length) { src = 'community'; liveUpdate(); }
139 if($('#live-display').length) {
142 window.location.href=window.location.href
145 if($('#live-photos').length) {
148 window.location.href=window.location.href
153 $.get("ping",function(data) {
154 $(data).find('result').each(function() {
155 // send nav-update event
156 $('nav').trigger('nav-update', this);
160 timer = setTimeout(NavUpdate,30000);
163 function liveUpdate() {
164 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
165 if(($('.comment-edit-text-full').length) || (in_progress)) {
166 livetime = setTimeout(liveUpdate, 10000);
169 prev = 'live-' + src;
172 var udargs = ((netargs.length) ? '/' + netargs : '');
173 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
175 $.get(update_url,function(data) {
177 $('.ccollapse-wrapper',data).each(function() {
178 var ident = $(this).attr('id');
179 var is_hidden = $('#' + ident).is(':hidden');
180 if($('#' + ident).length) {
181 $('#' + ident).replaceWith($(this));
183 $('#' + ident).hide();
186 $('.wall-item-outside-wrapper',data).each(function() {
187 var ident = $(this).attr('id');
188 if($('#' + ident).length == 0) {
189 $('img',this).each(function() {
190 $(this).attr('src',$(this).attr('dst'));
192 $('#' + prev).after($(this));
196 $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago'));
197 if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
198 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
199 $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
200 $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
201 $('#' + ident + ' ' + '.my-comment-photo').each(function() {
202 $(this).attr('src',$(this).attr('dst'));
207 $('.like-rotator').hide();
210 $('body').css('cursor', 'auto');
215 function imgbright(node) {
216 $(node).removeClass("drophide").addClass("drop");
219 function imgdull(node) {
220 $(node).removeClass("drop").addClass("drophide");
223 // Since our ajax calls are asynchronous, we will give a few
224 // seconds for the first ajax call (setting like/dislike), then
225 // run the updater to pick up any changes and display on the page.
226 // The updater will turn any rotators off when it's done.
227 // This function will have returned long before any of these
228 // events have completed and therefore there won't be any
229 // visible feedback that anything changed without all this
230 // trickery. This still could cause confusion if the "like" ajax call
231 // is delayed and NavUpdate runs before it completes.
233 function dolike(ident,verb) {
234 $('#like-rotator-' + ident.toString()).show();
235 $.get('like/' + ident.toString() + '?verb=' + verb );
236 if(timer) clearTimeout(timer);
237 timer = setTimeout(NavUpdate,3000);
241 function dostar(ident) {
242 $('#like-rotator-' + ident.toString()).show();
243 $.get('starred/' + ident.toString(), function(data) {
244 if(data.match(/1/)) {
245 $('#starred-' + ident.toString()).addClass('starred');
246 $('#starred-' + ident.toString()).removeClass('unstarred');
249 $('#starred-' + ident.toString()).addClass('unstarred');
250 $('#starred-' + ident.toString()).removeClass('starred');
252 $('#like-rotator-' + ident.toString()).hide();
256 function getPosition(e) {
257 var cursor = {x:0, y:0};
258 if ( e.pageX || e.pageY ) {
263 if( e.clientX || e.clientY ) {
264 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
265 cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
277 var lockvisible = false;
279 function lockview(event,id) {
280 event = event || window.event;
281 cursor = getPosition(event);
287 $.get('lockview/' + id, function(data) {
288 $('#panel').html(data);
289 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
295 function lockviewhide() {
300 function post_comment(id) {
302 $('body').css('cursor', 'wait');
305 $("#comment-edit-form-" + id).serialize(),
308 $("#comment-edit-wrapper-" + id).hide();
309 $("#comment-edit-text-" + id).val('');
310 var tarea = document.getElementById("comment-edit-text-" + id);
312 commentClose(tarea,id);
313 if(timer) clearTimeout(timer);
314 timer = setTimeout(NavUpdate,10);
317 window.location.href=data.reload;
327 // Converts the binary representation of data to hex
330 // discuss at: http://phpjs.org/functions/bin2hex
331 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
332 // + bugfixed by: Onno Marsman
333 // + bugfixed by: Linuxworld
334 // * example 1: bin2hex('Kev');
335 // * returns 1: '4b6576'
336 // * example 2: bin2hex(String.fromCharCode(0x00));
338 var v,i, f = 0, a = [];
342 for (i = 0; i<f; i++) {
343 a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
349 function groupChangeMember(gid,cid) {
350 $('body .fakelink').css('cursor', 'wait');
351 $.get('group/' + gid + '/' + cid, function(data) {
352 $('#group-update-wrapper').html(data);
353 $('body .fakelink').css('cursor', 'auto');
357 function profChangeMember(gid,cid) {
358 $('body .fakelink').css('cursor', 'wait');
359 $.get('profperm/' + gid + '/' + cid, function(data) {
360 $('#prof-update-wrapper').html(data);
361 $('body .fakelink').css('cursor', 'auto');
365 function contactgroupChangeMember(gid,cid) {
366 $('body').css('cursor', 'wait');
367 $.get('contactgroup/' + gid + '/' + cid, function(data) {
368 $('body').css('cursor', 'auto');
373 function checkboxhighlight(box) {
374 if($(box).is(':checked')) {
375 $(box).addClass('checkeditem');
378 $(box).removeClass('checkeditem');
382 function setupFieldRichtext(){
385 mode : "specific_textareas",
386 editor_selector: "fieldRichtext",
387 plugins : "bbcode,paste",
388 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
389 theme_advanced_buttons2 : "",
390 theme_advanced_buttons3 : "",
391 theme_advanced_toolbar_location : "top",
392 theme_advanced_toolbar_align : "center",
393 theme_advanced_blockformats : "blockquote,code",
394 paste_text_sticky : true,
395 entity_encoding : "raw",
396 add_unload_trigger : false,
397 remove_linebreaks : false,
398 force_p_newlines : false,
399 force_br_newlines : true,
400 forced_root_block : '',
402 content_css: baseurl+"/view/custom_tinymce.css",
403 theme_advanced_path : false,
408 * sprintf in javascript
409 * "{0} and {1}".format('zero','uno');
411 String.prototype.format = function() {
412 var formatted = this;
413 for (var i = 0; i < arguments.length; i++) {
414 var regexp = new RegExp('\\{'+i+'\\}', 'gi');
415 formatted = formatted.replace(regexp, arguments[i]);
420 Array.prototype.remove = function(item) {
421 to=undefined; from=this.indexOf(item);
422 var rest = this.slice((to || from) + 1 || this.length);
423 this.length = from < 0 ? this.length + from : from;
424 return this.push.apply(this, rest);