Browse Source

- roster next arrow navigation

pull/16/head
Christine Ho 13 years ago
parent
commit
a4b6b677ab
  1. 7
      system/Widget/widgets/Roster/Roster.php
  2. 154
      system/Widget/widgets/Roster/roster.js

7
system/Widget/widgets/Roster/Roster.php

@ -237,15 +237,14 @@ class Roster extends WidgetBase
*
*/
function ajaxToggleCache($param){
//$bool = !currentValue
$bool = (Cache::c($param) == true) ? false : true;
//toggling value in cache
Cache::c($param, $bool);
//$offline = new value of wether offline are shown or not
$offline = Cache::c('offlineshown');
if($param == 'offlineshown') {
Cache::c('offlineshown', $bool);
RPC::call('showRoster', $bool);
} else
RPC::call('rosterToggleGroup', $param, $bool, $offline);

154
system/Widget/widgets/Roster/roster.js

@ -27,7 +27,6 @@ function sortRoster() {
for(i = 0; i < server_error.length; i++) {
server_error.item(i).parentNode.insertBefore(server_error.item(i), contacts.item(contacts.length))
}
/*cacher ce qu'il y a à cacher*/
}
function showRoster(boolOffline) {
@ -50,7 +49,7 @@ function focusContact(){
rosterlist = document.querySelector('#rosterlist');
if(rosterlist.querySelector('.focused') == null){
//offline are shown
if(rosterlist.querySelector(".offline").style.display!=""){
if(rosterlist.querySelectorAll(".offline").length !=0 && rosterlist.querySelectorAll(".offline").style!=""){
rosterlist.querySelector("li").className += " focused";
}
//offline are hidden
@ -66,50 +65,80 @@ function focusContact(){
function rosterNextGroup(cgp){
thisGp = gp[0];
while(cgp != thisGp && thisGp.nextSibling!= null){
while(cgp != thisGp){
thisGp = thisGp.nextSibling;
}
if(thisGp.nextSibling!= null){
console.log(thisGp.querySelectorAll("li")[0]);
thisGp = thisGp.nextSibling;
//offline are shown
while(thisGp.querySelectorAll("li:not([style='display: none;'])").length == 0){
thisGp = thisGp.nextSibling;
}
cgp = thisGp;
currContact = cgp.querySelectorAll("li")[0];
//here thisGp=cgp
if(thisGp.nextSibling.nextSibling != null){
thisGp = thisGp.nextSibling.nextSibling;
if(rosterInArray(thisGp.querySelector("li"), thisGp.querySelectorAll("li"))){//offline are shown
currContact = thisGp.querySelector("li");
console.log(currContact);
}
else{
rosterNext(thisGp.querySelector("li"));
}
}
}
function rosterInArray(thing, array){
for(i=0; i<array.length; i++){
if(array[i] == thing){
visibility = thing.currentStyle ? thing.currentStyle.display :
getComputedStyle(thing, null).display;
if(visibility != "none"){
return true;
}
}
}
return false;
}
function rosterNext(){
currFocus = rosterlist.querySelector(".focused");
function rosterNext(currFocus){
currGp = currFocus.parentNode;
end = false;
viable = false;
gp = rosterlist.querySelectorAll("div:not([class='chat on'])");
//querySelectorAll is used to be able to get nextsiblings
currContact = currGp.querySelectorAll("li")[0];
//Define contact end limit
if(rosterlist.querySelector(".offline").style.display != "")//offline are shown
last = rosterlist.querySelectorAll("li:not([style='display: none;'])")[rosterlist.querySelectorAll("li:not([style='display: none;'])").length -1];
else
last = rosterlist.querySelectorAll("li:not(.offline), li:not([style='display: none;'])")[rosterlist.querySelectorAll("li:not(.offline), li:not([style='display: none;'])").length -1];
visible = "";
currentGroupVisible = "";
if(rosterlist.class != ""){//offline are shown
visible = rosterlist.querySelectorAll("li");
currentGroupVisible = currGp.querySelectorAll("li");
}
else{
visible = rosterlist.querySelectorAll("li:not(.offline)");
currentGroupVisible = currGp.querySelectorAll("li:not(.offline)");
}
last = visible[visible.length - 1];
if(currFocus != last){
while(currContact.className.lastIndexOf("focused") < 0 && currContact != null){
while(currContact.className.lastIndexOf("focused") < 0){
currContact = currContact.nextSibling;
}
//here we have currContact = currFocus
currContact = currContact.nextSibling;
//Change groupe
if(currContact == null ){
if( currGp !== gp[gp.length-1]){
//here currContact can be null, visible, or invisible
if(currContact != null){
//search for the next viable contact or find the end of the group
while(!rosterInArray(currContact, currentGroupVisible) && currContact != null){
currContact = currContact.nextSibling;
}
viable = true;
}
if(currContact == null || (currContact.nextSibling == null && !viable)){//Change groupe
if(currGp != gp[gp.length-1] && currContact == null){
rosterNextGroup(currGp);
}
else{
end = true;
else{//end of roster
//if(currContact == null)
currContact = currContact.previousSibling;
}
}
if(currContact !== null && !end){
/*elseif(!end){
//offline are shown
if(rosterlist.querySelector(".offline").style.display != ""){
if(rosterlist.className != ""){
while(currContact.style.display.lastIndexOf("none") > (-1) && !end){
if(currContact.nextSibling != null){
currContact = currContact.nextSibling;
@ -125,9 +154,10 @@ function rosterNext(){
}
//offline are hidden
else{
while((currContact.className.lastIndexOf("offline") > -1 || currContact.className.lastIndexOf("server") > -1) && !end){
if(currContact.nextSibling != null){
currContact = currContact.nextSibling;
if((currContact.className.lastIndexOf("offline") > -1 || currContact.className.lastIndexOf("server") > -1) && !end){
console.log(currContact);
if(currContact != null){
contact = currContact;
}
else{
if(currGp != gp[gp.length-1])
@ -146,12 +176,16 @@ function rosterNext(){
else{
if(end)
contact = currFocus;
}
}*/
}
else{
currContact = currFocus;
}
else contact = currFocus;
giveFocusTo(currContact);
}
function rosterPreviousGroup(cgp){
/*function rosterPreviousGroup(cgp){
thisGp = gp[0];
if(cgp != thisGp){ //not first group
while(thisGp.nextSibling != cgp){
@ -166,24 +200,27 @@ function rosterPreviousGroup(cgp){
currContact = thisGp.querySelectorAll("li")[thisGp.querySelectorAll("li").length-1];
console.log(currContact);
}
}
}*/
function rosterPrevious(){
currFocus = rosterlist.querySelector(".focused");
/*function rosterPrevious(currFocus){
currGp = currFocus.parentNode;
gp = rosterlist.querySelectorAll("div:not([class='chat on'])");
firstGroup = gp[0];
end = false;
firstContact = currGp.querySelector("li");
//begin to read at the end of current group
currContact = currGp.querySelectorAll("li")[currGp.querySelectorAll("li").length -1];
if(rosterlist.querySelector(".offline").style.display != "")//offline are shown
//defining the upper limit
if(rosterlist.className != "")//offline are shown
first = rosterlist.querySelector("li:not([style='display: none;'])");
else
first = rosterlist.querySelector("li:not(.offline), li:not([style='display: none;'])");
if(currFocus != first){
while(currContact.className.lastIndexOf("focused") < 0 && currContact != firstContact){
//til the focused is found, read backward
while(currContact.className.lastIndexOf("focused") < 0){
currContact = currContact.previousSibling;
}
console.log(currContact);
currContact = currContact.previousSibling;
if(currGp.querySelector("li") == currFocus){ //first contact of the group
rosterPreviousGroup(currGp);
@ -224,6 +261,13 @@ function rosterPrevious(){
else{
contact = currFocus;
}
}*/
function giveFocusTo(newFocused){
focused = document.querySelector('#rosterlist').querySelector('.focused');
if(newFocused != focused){
focused.className = focused.className.split(' ')[0];
newFocused.className += " focused";
}
}
function rosterSearch(e){
@ -232,18 +276,20 @@ function rosterSearch(e){
names = rosterlist.getElementsByTagName('span');
request = document.querySelector('#request').value;
focused = rosterlist.querySelector('.focused');
if(e.keyCode==8 || (e.keyCode>47 && e.keyCode<91) || (e.keyCode>95 && e.keyCode<106) || e.keyCode==46){//key pressed is backspace, alphanumeric or delete
//if key pressed is backspace, alphanumeric or delete
if(e.keyCode==8 || (e.keyCode>47 && e.keyCode<91) || (e.keyCode>95 && e.keyCode<106) || e.keyCode==46){
focusflag = false;
for(i = 0; i < parents.length; i++){
/*hide all contacts that doesn't match*/
if(names[i].innerHTML.toLowerCase().lastIndexOf(request.toLowerCase()) == -1){
parents[i].style.display = "none";
}
else{
else{
parents[i].style.display = "list-item";
if(rosterlist.querySelectorAll('.focused').length == 1 && !focusflag){
rosterlist.querySelectorAll('.focused')[0].className = rosterlist.querySelectorAll('.focused')[0].className.split(' ')[0];
parents[i].className += " focused";
/*replace the old focused by the new one if there is an old one*/
if(!focusflag){
giveFocusTo(parents[i]);
focusflag = true;
}
}
@ -255,12 +301,8 @@ function rosterSearch(e){
eval(focused.getElementsByTagName("div")[0].getAttribute("onclick"));
}
if(e.keyCode>36 && e.keyCode<41){ //key pressed is an arrow
//contact is the first contact of the list which is shown (already sorted)
contact = rosterlist.querySelectorAll("li[style='display: list-item; ']")[0];
//otherwise it is the first contact of the list
if(typeof contact === 'undefined'){
contact = rosterlist.querySelectorAll("li:not(.offline)")[0];
}
//begin reading from focused
contact = rosterlist.querySelector('.focused');
found = false;
if(0 == (decallage = contact.offsetHeight))
decallage = contact.nextSibling.offsetHeight;
@ -268,23 +310,25 @@ function rosterSearch(e){
switch(e.keyCode){
//previous
case e.keyCode = 38:
rosterPrevious();
rosterPrevious(rosterlist.querySelector(".focused"));
if(contact.offsetTop-document.querySelector('#right').scrollTop < decallage){
document.querySelector('#right').scrollTop = currContact.offsetTop-document.querySelector('#nav').offsetHeight;
}
break;
//next
case e.keyCode = 40:
rosterNext();
rosterNext(rosterlist.querySelector(".focused"));
if(contact.offsetTop+decallage-document.querySelector('#right').scrollTop >= document.querySelector('#rostermenu').offsetTop){
document.querySelector('#right').scrollTop += contact.offsetTop+decallage-document.querySelector('#right').scrollTop - document.querySelector('#rostermenu').offsetTop;
}
break;
}
if(focused.className == (focused.className = focused.className.replace(" focused", "")))
/*if(focused.className == (focused.className = focused.className.replace(" focused", "")))
focused.className = focused.className.replace("focused", "");
if(contact.className.lastIndexOf("focused")<0)
if(contact.className.lastIndexOf("focused")<0){
contact.className += " focused";
console.log("303");
}*/
}
}
}

Loading…
Cancel
Save