Changeset 2339 for sandbox/jabberit_messenger/trophy/js/trophyim.js
- Timestamp:
- 03/24/10 16:02:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/jabberit_messenger/trophy/js/trophyim.js
r2325 r2339 29 29 make sure onload bootstrapping actually preserves existing onloads 30 30 */ 31 var TROPHYIM_BOSH_SERVICE = '/proxy/xmpp-httpbind'; //Change to suit 32 var TROPHYIM_LOG_LINES = 200; 33 var TROPHYIM_LOGLEVEL = 0; //0=debug, 1=info, 2=warn, 3=error, 4=fatal 34 var TROPHYIM_VERSION = "0.3"; 31 32 var TROPHYIM_BOSH_SERVICE = '/proxy/xmpp-httpbind'; //Change to suit 33 var TROPHYIM_LOG_LINES = 200; 34 35 //0=debug, 1=info, 2=warn, 3=error, 4=fatal 36 var TROPHYIM_LOGLEVEL = 0; 37 38 var TROPHYIM_VERSION = "0.3"; 39 40 var TROPHYIM_RESOURCE = "/JABBERITWEB"; 41 35 42 //Uncomment to make session reattachment work 36 43 //var TROPHYIM_JSON_STORE = "json_store.php"; … … 56 63 HTMLSnippets = { 57 64 58 chatArea : loadIM.HTMLSnippets.chatArea( ),65 //chatArea : loadIM.HTMLSnippets.chatArea( ), 59 66 60 67 chatBox : loadIM.HTMLSnippets.chatBox( ), … … 160 167 * object) 161 168 */ 162 getHTML : function(page) {163 //alert("Page : \n" + page); 169 getHTML : function(page) 170 { 164 171 return this.xmlParse(HTMLSnippets[page]); 165 172 }, 173 166 174 /** Function: getScript 167 175 * Returns script object with src to given script … … 253 261 return cObj; 254 262 }, 263 255 264 /** Function: load 256 265 * … … 258 267 * into it. 259 268 */ 260 load : function() 269 270 load : function() 261 271 { 262 272 TrophyIM.cookies = TrophyIM.getCookies(); … … 274 284 setTimeout("TrophyIM.showLogin()", 500); 275 285 276 /*TrophyIM.cookies = TrophyIM.getCookies(); 277 var client_div = document.getElementById('trophyimclient'); 278 if (client_div) 279 { 280 TrophyIM.client_div = client_div; 281 282 //load .css 283 //document.getElementsByTagName('head')[0].appendChild(DOMObjects.getHTML('cssLink')); 284 //DOMObjects.getHTML('cssLink'); 285 286 //Load other .js scripts needed 287 document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('strophejs/strophe.js')); 288 document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('strophejs/md5.js')); 289 document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('strophejs/sha1.js')); 290 document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('strophejs/b64.js')); 291 document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('js/json2.js')); //Keep this script last 292 293 //Wait a second to give scripts time to load 294 setTimeout("TrophyIM.showLogin()", 500); 295 } else { 296 alert("Cannot load TrophyIM client.\nClient div not found."); 297 }*/ 298 }, 286 }, 287 299 288 /** Function: storeData 300 289 * 301 290 * Store all our data in the JSONStore, if it is active 302 291 */ 303 storeData : function() { 304 if (TrophyIM.connection && TrophyIM.connection.connected) { 292 storeData : function() 293 { 294 if (TrophyIM.connection && TrophyIM.connection.connected) 295 { 305 296 TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" + 306 297 TrophyIM.connection.sid + "|" + TrophyIM.connection.rid); … … 392 383 * 393 384 */ 394 login : function() { 385 login : function() 386 { 395 387 if (document.getElementById('trophyimloglevel').checked) { 396 388 TrophyIM.setCookie('trophyimloglevel', 1); … … 416 408 Strophe.log = TrophyIM.log; 417 409 var barejid = document.getElementById('trophyimjid').value 418 var fulljid = barejid + '/TrophyIM';410 var fulljid = barejid + TROPHYIM_RESOURCE; 419 411 TrophyIM.setCookie('trophyimjid', barejid); 420 412 var password = document.getElementById('trophyimpass').value; … … 456 448 * Callback given to Strophe upon connection to BOSH proxy. 457 449 */ 458 onConnect : function(status) { 450 onConnect : function(status) 451 { 459 452 if (status == Strophe.Status.CONNECTING) { 460 453 Strophe.info('Strophe is connecting.'); … … 486 479 var logging_div = TrophyIM.clearClient(); 487 480 488 loadIM.HTMLSnippets.rosterDiv(); 489 loadIM.HTMLSnippets.chatArea(); 490 491 //TrophyIM.client_div.appendChild(DOMObjects.getHTML('rosterDiv')); 492 //TrophyIM.client_div.appendChild(DOMObjects.getHTML('chatArea')); 493 //TrophyIM.client_div.appendChild(DOMObjects.getHTML('statusDiv')); 494 495 if(logging_div) 481 if( logging_div ) 496 482 { 497 483 TrophyIM.client_div.appendChild(logging_div); 498 484 TrophyIM.logging_div = document.getElementById('trophyimlog'); 499 485 } 486 500 487 TrophyIM.rosterObj = new TrophyIMRoster(); 501 488 TrophyIM.connection.addHandler(TrophyIM.onVersion, Strophe.NS.VERSION, 'iq', null, null, null); … … 503 490 TrophyIM.connection.addHandler(TrophyIM.onPresence, null, 'presence', null, null, null); 504 491 TrophyIM.connection.addHandler(TrophyIM.onMessage, null, 'message', null, null, null); 505 //Get roster then announce presence. 492 493 //Get roster then announce presence. 506 494 TrophyIM.connection.send($iq({type: 'get', xmlns: Strophe.NS.CLIENT}).c('query', {xmlns: Strophe.NS.ROSTER}).tree()); 507 495 TrophyIM.connection.send($pres().tree()); 508 TrophyIM.renderChats(); 509 setTimeout("TrophyIM.renderRoster()", 1000); 496 setTimeout("TrophyIM.renderRoster()", 1000); 510 497 }, 511 498 … … 574 561 onPresence : function(msg) 575 562 { 576 //alert('Function onPresence');577 578 563 Strophe.debug("Presence handler"); 579 564 var type = msg.getAttribute('type') ? msg.getAttribute('type') : 'available'; … … 603 588 var contact = ""; 604 589 605 if( TrophyIM.rosterObj.roster[barejid.toLowerCase()] )590 if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] ) 606 591 { 607 592 contact = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; … … 621 606 TrophyIM.makeChat(from); //Make sure we have a chat window 622 607 TrophyIM.addMessage(message, jid_lower); 623 624 /*625 if ( contact )626 {627 628 //Do we know you?629 if ( contact['name'] != null )630 {631 message = contact['name'] + " (" + barejid + "): ";632 }633 else634 {635 message = contact['jid'] + ": ";636 }637 638 message += Strophe.getText(elems[0]);639 640 TrophyIM.makeChat(from); //Make sure we have a chat window641 TrophyIM.addMessage(message, jid_lower);642 643 644 //if (TrophyIM.activeChats['current'] != jid_lower) {645 // TrophyIM.activeChats['divs'][jid_lower][646 // 'tab'].className = "trophyimchattab trophyimchattab_a";647 // TrophyIM.setTabPresence(from,648 // TrophyIM.activeChats['divs'][jid_lower]['tab']);649 //}650 }*/651 608 } 652 609 return true; … … 698 655 } 699 656 ); 700 701 /* 702 * Codigo Original 703 * 704 var barejid = Strophe.getBareJidFromJid(fulljid); 705 if (!TrophyIM.activeChats['divs'][barejid]) { 706 var chat_tabs = document.getElementById('trophyimchattabs'); 707 var chat_tab = DOMObjects.getHTML('chatTab'); 708 var chat_box = DOMObjects.getHTML('chatBox'); 709 var contact = TrophyIM.rosterObj.getContact(barejid); 710 var tab_name = (contact['name'] != null) ? contact['name'] : barejid; 711 chat_tab.className = "trophyimchattab trophyimchattab_a"; 712 getElementsByClassName('trophyimchattabjid', 'div', chat_tab)[0].appendChild(document.createTextNode(barejid)); 713 getElementsByClassName('trophyimchattabname', 'div', chat_tab)[0].appendChild(document.createTextNode(tab_name)); 714 chat_tab = chat_tabs.appendChild(chat_tab); 715 TrophyIM.activeChats['divs'][barejid] = {jid:fulljid, tab:chat_tab, box:chat_box}; 716 717 if (!TrophyIM.activeChats['current']) { //We're the first 718 TrophyIM.activeChats['current'] = barejid; 719 document.getElementById('trophyimchat').appendChild(chat_box); 720 TrophyIM.activeChats['divs'][barejid]['box'] = chat_box; 721 TrophyIM.activeChats['divs'][barejid]['tab'].className = 722 "trophyimchattab trophyimchattab_f"; 723 } 724 if (!TrophyIM.chatHistory[barejid.toLowerCase()]) { 725 TrophyIM.chatHistory[barejid.toLowerCase()] = {resource: null, 726 history: new Array()}; 727 } 728 TrophyIM.setTabPresence(fulljid, chat_tab); 729 } 730 TrophyIM.activeChats['divs'][barejid.toLowerCase()]['resource'] = 731 Strophe.getResourceFromJid(fulljid); 732 TrophyIM.chatHistory[barejid.toLowerCase()]['resource'] = 733 Strophe.getResourceFromJid(fulljid);*/ 734 735 }, 736 /** Function showChat 737 * 738 * Make chat box to given barejid active 739 */ 740 showChat : function(barejid) { 741 if (TrophyIM.activeChats['current'] && 742 TrophyIM.activeChats['current'] != barejid) { 743 var chat_area = document.getElementById('trophyimchat'); 744 var active_divs = 745 TrophyIM.activeChats['divs'][TrophyIM.activeChats['current']]; 746 active_divs['box'] = 747 chat_area.removeChild(getElementsByClassName('trophyimchatbox', 748 'div', chat_area)[0].parentNode); 749 active_divs['tab'].className = "trophyimchattab trophyimchattab_b"; 750 TrophyIM.setTabPresence(TrophyIM.activeChats['current'], 751 active_divs['tab']); 752 TrophyIM.activeChats['divs'][barejid]['box'] = 753 chat_area.appendChild(TrophyIM.activeChats['divs'][barejid]['box']); 754 TrophyIM.activeChats['current'] = barejid; 755 TrophyIM.activeChats['divs'][barejid]['tab'].className = 756 "trophyimchattab trophyimchattab_f"; 757 TrophyIM.setTabPresence(barejid, 758 TrophyIM.activeChats['divs'][barejid]['tab']); 759 getElementsByClassName('trophyimchatinput', null, 760 TrophyIM.activeChats['divs'][barejid]['box'])[0].focus(); 761 } 762 }, 763 /** Function: setTabPresence 764 * 765 * Applies appropriate class to tab div based on presence 766 * 767 * Parameters: 768 * (String) jid - jid to check presence for 769 * (String) tab_div - tab div element to alter class on 770 */ 771 setTabPresence : function(jid, tab_div) 772 { 773 alert('function setTabPresence'); 774 775 var presence = TrophyIM.rosterObj.getPresence(jid); 776 tab_div.className = tab_div.className.replace(" trophyimchattab_av", ""); 777 tab_div.className = tab_div.className.replace(" trophyimchattab_aw", ""); 778 tab_div.className = tab_div.className.replace(" trophyimchattab_off", ""); 779 if (presence) { 780 if (presence['show'] == "chat" || presence['show'] == "available") { 781 tab_div.className += " trophyimchattab_av"; 782 } else { 783 tab_div.className += " trophyimchattab_aw"; 784 } 785 } else { 786 tab_div.className += " trophyimchattab_off"; 787 } 788 }, 657 }, 658 789 659 /** Function: addMessage 790 *791 * Adds message to chat box, and history792 660 * 793 661 * Parameters: … … 795 663 * (string) jid - the jid of chat box to add the message to. 796 664 */ 665 797 666 addMessage : function(msg, jid) 798 667 { 799 668 var chatBox = document.getElementById(jid + "__chatBox"); 800 669 var messageDiv = document.createElement("div"); 801 messageDiv.style.margin = "3px 0px 3px 3px"; 802 messageDiv.innerHTML = msg.contact + " : " + msg.msg ; 670 671 messageDiv.style.margin = "3px 0px 3px 3px"; 672 messageDiv.innerHTML = msg.contact + " : " + msg.msg ; 803 673 804 674 chatBox.appendChild(messageDiv); 805 675 chatBox.scrollTop = chatBox.scrollHeight; 806 807 /* 808 * Codigo Original Comentado 809 * 810 811 var chat_box = getElementsByClassName('trophyimchatbox', 'div', 812 TrophyIM.activeChats['divs'][jid]['box'])[0]; 813 var msg_div = document.createElement('div'); 814 msg_div.className = 'trophyimchatmessage'; 815 msg_div.appendChild(document.createTextNode(msg)); 816 chat_box.appendChild(msg_div); 817 chat_box.scrollTop = chat_box.scrollHeight; 818 if (TrophyIM.chatHistory[jid]['history'].length > 10) { 819 TrophyIM.chatHistory[jid]['history'].shift(); 820 } 821 TrophyIM.chatHistory[jid]['history'][ 822 TrophyIM.chatHistory[jid]['history'].length] = msg; 823 */ 824 }, 676 }, 677 825 678 /** Function: renderRoster 826 679 * … … 828 681 * changed. 829 682 */ 830 renderRoster : function() { 831 if (TrophyIM.rosterObj.changes.length > 0) { 832 var roster_div = document.getElementById('trophyimroster'); 833 if(roster_div) { 834 var groups = new Array(); 835 for (var group in TrophyIM.rosterObj.groups) { 836 groups[groups.length] = group; 683 684 renderRoster : function() 685 { 686 if( TrophyIM.rosterObj.changes.length > 0 ) 687 { 688 var roster_div = document.getElementById('trophyimroster'); 689 690 if( roster_div ) 691 { 692 var groups = new Array(); 693 694 for (var group in TrophyIM.rosterObj.groups) 695 { 696 groups[groups.length] = ( group ) ? group : "SEM GRUPO"; 837 697 } 838 groups.sort(); 839 var group_divs = getElementsByClassName('trophyimrostergroup', 840 null, roster_div); 841 for (var g = 0; g < group_divs.length; g++) { 842 var group_name = getElementsByClassName('trophyimrosterlabel', 843 null, group_divs[g])[0].firstChild.nodeValue; 844 while (group_name > groups[0]) { 845 var new_group = TrophyIM.renderGroup(groups[0], roster_div); 846 new_group = roster_div.insertBefore(new_group, 847 group_divs[g]); 848 if (TrophyIM.rosterObj.groupHasChanges(groups[0])) { 849 TrophyIM.renderGroupUsers(new_group, groups[0], 850 TrophyIM.rosterObj.changes.slice()); 851 } 852 groups.shift(); 853 } 854 if (group_name == groups[0]) { 855 groups.shift(); 856 } 857 if (TrophyIM.rosterObj.groupHasChanges(group_name)) { 858 TrophyIM.renderGroupUsers(group_divs[g], group_name, 859 TrophyIM.rosterObj.changes.slice()); 860 } 861 } 862 while (groups.length) { 863 var group_name = groups.shift(); 864 var new_group = TrophyIM.renderGroup(group_name, 865 roster_div); 866 new_group = roster_div.appendChild(new_group); 867 if (TrophyIM.rosterObj.groupHasChanges(group_name)) { 868 TrophyIM.renderGroupUsers(new_group, group_name, 869 TrophyIM.rosterObj.changes.slice()); 870 } 871 } 872 } 873 TrophyIM.rosterObj.changes = new Array(); 874 TrophyIM.constants.stale_roster = false; 875 } 876 setTimeout("TrophyIM.renderRoster()", 1000); 877 }, 878 /** Function: renderChats 879 * 880 * Renders chats found in TrophyIM.chatHistory. Called upon page reload. 881 * Waits for stale_roster flag to clear before trying to run, so that the 882 * roster exists 883 */ 884 renderChats : function() { 885 if (TrophyIM.constants.stale_roster == false) { 886 if(TrophyIM.JSONStore.store_working) { 887 var data = TrophyIM.JSONStore.getData(['chat_history', 888 'active_chat']); 889 if (data['active_chat']) { 890 for (var jid in data['chat_history']) { 891 fulljid = jid + "/" + data['chat_history'][jid]['resource']; 892 Strophe.info("Makechat " + fulljid); 893 TrophyIM.makeChat(fulljid); 894 for (var h = 0; h < 895 data['chat_history'][jid]['history'].length; h++) { 896 TrophyIM.addMessage(data['chat_history'][jid]['history'][h], 897 jid); 898 } 899 } 900 TrophyIM.chat_history = data['chat_history']; 901 TrophyIM.showChat(data['active_chat']); 902 } 903 } 904 } else { 905 setTimeout("TrophyIM.renderChats()", 1000); 906 } 907 }, 908 /** Function: renderGroup 909 * 910 * Renders actual group label in roster 911 * 912 * Parameters: 913 * (String) group - name of group to render 914 * (DOM) roster_div - roster div 915 * 916 * Returns: 917 * DOM group div to append into roster 918 */ 919 renderGroup : function(group, roster_div) { 920 var new_group = DOMObjects.getHTML('rosterGroup'); 921 var label_div = getElementsByClassName( 'trophyimrosterlabel', null, 922 new_group)[0]; 923 label_div.appendChild(document.createTextNode(group)); 924 new_group.appendChild(label_div); 925 return new_group; 926 }, 927 /** Function: renderGroupUsers 928 * 929 * Re-renders user entries in given group div based on status of roster 930 * 931 * Parameter: (Array) changes - jids with changes in the roster. Note: 932 * renderGroupUsers will clobber this. 933 */ 934 renderGroupUsers : function(group_div, group_name, changes) { 935 var group_members = TrophyIM.rosterObj.groups[group_name]; 936 var member_divs = getElementsByClassName('trophyimrosteritem', null, 937 group_div); 938 for (var m = 0; m < member_divs.length; m++) { 939 member_jid = getElementsByClassName('trophyimrosterjid', null, 940 member_divs[m])[0].firstChild.nodeValue; 941 if (member_jid > changes[0]) { 942 if (changes[0] in group_members) { 943 var new_presence = TrophyIM.rosterObj.getPresence( 944 changes[0]); 945 if(new_presence) { 946 var new_member = DOMObjects.getHTML('rosterItem'); 947 var new_contact = 948 TrophyIM.rosterObj.getContact(changes[0]); 949 getElementsByClassName('trophyimrosterjid', null, 950 new_member)[0].appendChild(document.createTextNode( 951 changes[0])); 952 var new_name = (new_contact['name'] != null) ? 953 new_contact['name'] : changes[0]; 954 getElementsByClassName('trophyimrostername', null, 955 new_member)[0].appendChild(document.createTextNode( 956 new_name)); 957 group_div.insertBefore(new_member, member_divs[m]); 958 if (new_presence['show'] == "available" || 959 new_presence['show'] == "chat") { 960 new_member.className = 961 "trophyimrosteritem trophyimrosteritem_av"; 962 } else { 963 new_member.className = 964 "trophyimrosteritem trophyimrosteritem_aw"; 965 } 966 } else { 967 //show offline contacts 968 } 969 } 970 changes.shift(); 971 } else if (member_jid == changes[0]) { 972 member_presence = TrophyIM.rosterObj.getPresence(member_jid); 973 if(member_presence) { 974 if (member_presence['show'] == "available" || 975 member_presence['show'] == "chat") { 976 member_divs[m].className = 977 "trophyimrosteritem trophyimrosteritem_av"; 978 } else { 979 member_divs[m].className = 980 "trophyimrosteritem trophyimrosteritem_aw"; 981 } 982 } else { 983 //show offline status 984 group_div.removeChild(member_divs[m]); 985 } 986 changes.shift(); 987 } 988 } 989 while (changes.length > 0) { 990 if (changes[0] in group_members) { 991 var new_presence = TrophyIM.rosterObj.getPresence(changes[0]); 992 if(new_presence) { 993 var new_member = DOMObjects.getHTML('rosterItem'); 994 var new_contact = 995 TrophyIM.rosterObj.getContact(changes[0]); 996 getElementsByClassName('trophyimrosterjid', null, 997 new_member)[0].appendChild(document.createTextNode( 998 changes[0])); 999 var new_name = (new_contact['name'] != null) ? 1000 new_contact['name'] : changes[0]; 1001 getElementsByClassName('trophyimrostername', null, 1002 new_member)[0].appendChild(document.createTextNode( 1003 new_name)); 1004 group_div.appendChild(new_member); 1005 if (new_presence['show'] == "available" || 1006 new_presence['show'] == "chat") { 1007 new_member.className = 1008 "trophyimrosteritem trophyimrosteritem_av"; 1009 } else { 1010 new_member.className = 1011 "trophyimrosteritem trophyimrosteritem_aw"; 1012 } 1013 } else { 1014 //show offline 1015 } 1016 } 1017 changes.shift(); 1018 } 1019 }, 698 699 groups.sort(); 700 701 for ( var i = 0; i < groups.length; i++ ) 702 { 703 704 TrophyIM.renderGroups( groups[i] , roster_div ); 705 } 706 707 TrophyIM.renderItensGroup( roster_div ); 708 } 709 } 710 711 setTimeout("TrophyIM.renderRoster()", 1000 ); 712 }, 713 714 /** Function: renderGroups 715 * 716 * 717 */ 718 719 renderGroups: function( nameGroup, elementParent ) 720 { 721 var _addGroup = function() 722 { 723 var paramsGroup = 724 { 725 'nameGroup' : arguments[0], 726 'id' : (( arguments[0] == "SEM GRUPO" ) ? "sem_grupo_jabber" : "" ) 727 } 728 729 elementParent.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup); 730 } 731 732 if( !elementParent.hasChildNodes() ) 733 { 734 _addGroup(nameGroup); 735 } 736 else 737 { 738 var elementChild = elementParent.firstChild; 739 var flag = false; 740 741 while ( elementChild ) 742 { 743 if ( elementChild.childNodes[0].childNodes[0].nodeValue === nameGroup ) 744 { 745 flag = true; 746 } 747 elementChild = elementChild.nextSibling; 748 } 749 750 if( !flag ) 751 _addGroup(nameGroup); 752 } 753 754 }, 755 756 /** Function: renderItensGroup 757 * 758 * 759 */ 760 761 renderItensGroup : function( elementParent ) 762 { 763 var _addItensGroup = function() 764 { 765 if( arguments.length > 0 ) 766 { 767 var objContact = arguments[0]; 768 var element = arguments[1]; 769 var itensGroup = document.getElementById('itenContact_' + objContact.contact.jid); 770 771 if ( itensGroup == null ) 772 { 773 // Name 774 var nameContact = ""; 775 776 if (objContact.contact.name) 777 nameContact = objContact.contact.name; 778 else 779 { 780 nameContact = objContact.contact.jid; 781 nameContact = nameContact.substring(0, nameContact.indexOf('@')); 782 } 783 784 // Presence 785 var presence = 'unavailable'; 786 787 if (objContact.presence) 788 { 789 for (var resource in objContact.presence) 790 { 791 presence = objContact.presence[resource].show; 792 } 793 } 794 795 var paramsContact = 796 { 797 'nameContact' : nameContact, 798 'jid' : objContact.contact.jid, 799 'id' : 'itenContact_' + objContact.contact.jid, 800 'presence' : presence 801 } 802 803 element.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact); 804 } 805 else 806 { 807 // Presence 808 var presence = 'unavailable'; 809 810 if (objContact.presence) 811 { 812 for (var resource in objContact.presence) 813 presence = objContact.presence[resource].show; 814 } 815 816 itensGroup.style.background = "url('images/" + presence + ".gif')no-repeat center left"; 817 } 818 } 819 } 820 821 for ( var userItem in TrophyIM.rosterObj.roster) 822 { 823 if ( TrophyIM.rosterObj.roster[userItem].contact.groups ) 824 { 825 var elementChild = elementParent.firstChild 826 827 while ( elementChild ) 828 { 829 if( elementChild.childNodes[0].childNodes[0].nodeValue == TrophyIM.rosterObj.roster[userItem].contact.groups ) 830 _addItensGroup( TrophyIM.rosterObj.roster[userItem], elementChild ); 831 832 elementChild = elementChild.nextSibling; 833 } 834 } 835 else 836 { 837 var elementChild = document.getElementById("sem_grupo_jabber"); 838 839 _addItensGroup( TrophyIM.rosterObj.roster[userItem], elementChild ); 840 } 841 } 842 }, 843 1020 844 /** Function: rosterClick 1021 845 * 1022 846 * Handles actions when a roster item is clicked 1023 847 */ 1024 rosterClick : function(roster_item) { 1025 var barejid = getElementsByClassName('trophyimrosterjid', null, 1026 roster_item)[0].firstChild.nodeValue; 1027 var presence = TrophyIM.rosterObj.getPresence(barejid); 1028 if (presence && presence['resource']) { 1029 var fulljid = barejid + "/" + presence['resource']; 1030 } else { 1031 var fulljid = barejid; 1032 } 848 849 rosterClick : function(fulljid) 850 { 1033 851 TrophyIM.makeChat(fulljid); 1034 TrophyIM.showChat(barejid); 1035 }, 1036 /** Function: tabClick 1037 * 1038 * Handles actions when a chat tab is clicked 1039 */ 1040 tabClick : function(tab_item) { 1041 var barejid = getElementsByClassName('trophyimchattabjid', null, 1042 tab_item)[0].firstChild.nodeValue; 1043 if (TrophyIM.activeChats['divs'][barejid]) { 1044 TrophyIM.showChat(barejid); 1045 } 1046 }, 1047 /** Function: tabClose 1048 * 1049 * Closes chat tab 1050 */ 1051 tabClose : function(tab_item) { 1052 var barejid = getElementsByClassName('trophyimchattabjid', null, 1053 tab_item.parentNode)[0].firstChild.nodeValue; 1054 if (TrophyIM.activeChats['current'] == barejid) { 1055 if (tab_item.parentNode.nextSibling) { 1056 TrophyIM.showChat(getElementsByClassName('trophyimchattabjid', 1057 null, tab_item.parentNode.nextSibling)[0].firstChild.nodeValue); 1058 } else if (tab_item.parentNode.previousSibling) { 1059 TrophyIM.showChat(getElementsByClassName('trophyimchattabjid', 1060 null, tab_item.parentNode.previousSibling)[0].firstChild.nodeValue); 1061 } else { //no other active chat 1062 document.getElementById('trophyimchat').removeChild( 1063 getElementsByClassName('trophyimchatbox')[0].parentNode); 1064 delete TrophyIM.activeChats['current']; 1065 } 1066 } 1067 delete TrophyIM.activeChats['divs'][barejid]; 1068 delete TrophyIM.chatHistory[barejid]; 1069 //delete tab 1070 tab_item.parentNode.parentNode.removeChild(tab_item.parentNode); 1071 }, 1072 852 }, 853 1073 854 setPresence : function() 1074 855 { … … 1109 890 } 1110 891 } 1111 1112 1113 /*1114 * Codigo original comentado1115 *1116 var message_input = getElementsByClassName('trophyimchatinput', null, chat_box.parentNode)[0];1117 var active_jid = TrophyIM.activeChats['current'];1118 1119 if(TrophyIM.activeChats['current'])1120 {1121 var active_chat =1122 TrophyIM.activeChats['divs'][TrophyIM.activeChats['current']];1123 var to = TrophyIM.activeChats['current'];1124 if (active_chat['resource'])1125 {1126 to += "/" + active_chat['resource'];1127 }1128 TrophyIM.connection.send($msg({to: to, from: TrophyIM.connection.jid, type: 'chat'}).c('body').t(message_input.value).tree());1129 1130 TrophyIM.addMessage("Me:\n" + message_input.value,1131 TrophyIM.activeChats['current']);1132 }1133 1134 message_input.value = '';1135 message_input.focus();1136 */1137 892 } 1138 893 }; … … 1146 901 * roster[jid_lower]['presence'][resource] 1147 902 */ 1148 function TrophyIMRoster() { 903 function TrophyIMRoster() 904 { 1149 905 /** Constants: internal arrays 1150 906 * (Object) roster - the actual roster/presence information … … 1152 908 * (Array) changes - array of jids with presence changes 1153 909 */ 1154 if (TrophyIM.JSONStore.store_working) { 910 if (TrophyIM.JSONStore.store_working) 911 { 1155 912 var data = TrophyIM.JSONStore.getData(['roster', 'groups']); 1156 913 this.roster = (data['roster'] != null) ? data['roster'] : {}; 1157 914 this.groups = (data['groups'] != null) ? data['groups'] : {}; 1158 } else { 915 } 916 else 917 { 1159 918 this.roster = {}; 1160 919 this.groups = {}; 1161 920 } 1162 921 this.changes = new Array(); 1163 if (TrophyIM.constants.stale_roster) { 1164 for (var jid in this.roster) { 1165 this.changes[this.changes.length] = jid; 1166 } 1167 } 922 923 if (TrophyIM.constants.stale_roster) 924 { 925 for (var jid in this.roster) 926 { 927 this.changes[this.changes.length] = jid; 928 } 929 } 930 1168 931 /** Function: addContact 1169 932 * … … 1176 939 * (Array) groups - array of groups contact is member of 1177 940 */ 1178 this.addContact = function(jid, subscription, name, groups) { 941 942 this.addContact = function(jid, subscription, name, groups) { 1179 943 var contact = {jid:jid, subscription:subscription, name:name, groups:groups} 1180 944 var jid_lower = jid.toLowerCase();
Note: See TracChangeset
for help on using the changeset viewer.