(function()
{
var fullName = "";
var path = "";
var addUser = null;
var conn = null;
var selectEditable = null;
var showhidden = null;
var timeoutId = null
var userCurrent = null;
var Xtools = null;
var zIndex = 9001;
// Images
var add_user = new Image();
add_user.src = path_jabberit + 'templates/default/images/adduser_azul.png';
var arrow_down = new Image();
arrow_down.src = path_jabberit + 'templates/default/images/arrow_down.gif';
var arrow_right = new Image();
arrow_right.src = path_jabberit + 'templates/default/images/arrow_right.gif';
function actionButton()
{
if( arguments.length > 0 )
{
var e = arguments[0];
var _element = ( e.target ) ? e.target : e.srcElement;
var jid = arguments[1];
var index = arguments[2];
var coord = null;
if ( !e )
e = window.event;
var _X = e.clientX + document.body.scrollLeft - document.body.clientLeft;
var _Y = e.clientY + document.body.scrollTop - document.body.clientTop;
coord = { X : _X, Y : _Y };
var _onContextMenu = function()
{
return false;
};
window.document.oncontextmenu = _onContextMenu;
if( e.button )
{
if( e.button > 1 )
optionsItensContact( jid, index, coord );
else
TrophyIM.rosterClick(jid);
}
else if( e.which )
{
if( e.which > 1 )
optionsItensContact( jid, index, coord );
else
if( e.target.id )
TrophyIM.rosterClick(jid);
}
}
}
function addContact()
{
if( arguments.length > 0 )
addUser.add();
else
addUser.show();
}
function addIcon()
{
var StatusBar = getElement('divStatusBar');
/**
* @quando estiver habilitada a opção fora de escritório nos filtros.
*/
if( div_write_msg = getElement('em_div_write_msg') )
{
var StatusBarIM = getElement('JabberMessenger');
StatusBarIM.style.paddingLeft = '33px';
div_write_msg.parentNode.insertBefore( StatusBarIM, div_write_msg );
return;
}
if( StatusBar )
{
StatusBar.style.paddingLeft = '33px';
var _div = document.createElement('div');
_div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
StatusBar.parentNode.insertBefore( _div, StatusBar);
var divJabber = document.createElement('div');
divJabber.setAttribute('id', 'JabberMessenger');
var _fastMenu = top.document.createElement('div');
_fastMenu.setAttribute('id', 'fast_menu_jabber_expresso');
_fastMenu.style.background = 'no-repeat';
_fastMenu.style.backgroundImage = 'url(' + arrow_down.src + ')';
_fastMenu.style.float = 'left';
_fastMenu.style.height = '15px';
_fastMenu.style.left = '7px';
_fastMenu.style.margin = '8 0 0 10px';
_fastMenu.style.padding = '0px';
_fastMenu.style.position = 'absolute';
_fastMenu.style.width = '15px';
_fastMenu.style.cursor = 'pointer';
divJabber.insertBefore( _fastMenu, divJabber.firstChild );
// Add event onclick element _fastMenu
configEvents( _fastMenu, 'onclick', function(){ fastMenu(_fastMenu); });
var _statusJabber = top.document.createElement('div');
_statusJabber.setAttribute('id','status_jabber_expresso');
_statusJabber.style.background = 'no-repeat';
_statusJabber.style.backgroundImage = 'url(' + add_user.src +')';
_statusJabber.style.float = 'left';
_statusJabber.style.height = '18px';
_statusJabber.style.left = '19px';
_statusJabber.style.margin = '0 0 0 10px';
_statusJabber.style.padding = '0px';
_statusJabber.style.position = 'absolute';
_statusJabber.style.width = '18px';
_statusJabber.style.cursor = 'pointer';
_statusJabber.style.zindex = '999999';
divJabber.insertBefore( _statusJabber, divJabber.firstChild );
StatusBar.insertBefore( divJabber, StatusBar.firstChild );
// Add event onclick element _statusJabber
configEvents( _statusJabber, 'onclick', function(){ TrophyIM.load();});
}
}
function clrAllContacts()
{
getElement("JabberIMRoster").innerHTML = "";
}
function configEvents(pObj, pEvent, pHandler)
{
if ( typeof pObj == 'object' )
{
if ( pEvent.substring(0, 2) == 'on' )
pEvent = pEvent.substring(2, pEvent.length);
if ( pObj.addEventListener )
pObj.addEventListener(pEvent, pHandler, false);
else if ( pObj.attachEvent )
pObj.attachEvent('on' + pEvent, pHandler);
}
}
function fastMenu()
{
if( arguments.length > 0 )
{
var element = arguments[0];
if( showhidden == null )
showhidden = new ShowHidden(300);
var _options = [
['Adicionar Contato', 'loadIM.addContact();' ],
['Ajuda', 'alert("2")' ],
['Preferências', 'alert("3")'],
];
var _itens = "";
for( var i in _options )
{
if( typeof(_options) === "object" && _options[i][0] != "undefined" )
{
_itens += '';
_itens += '';
_itens += _options[i][0] + '
';
}
}
var _optionsItens = document.createElement("div");
_optionsItens.id = "fastMenu_Jabber";
_optionsItens.style.marginTop = "19px";
_optionsItens.style.marginLeft = "-8px";
_optionsItens.className = "x-menu";
_optionsItens.style.zIndex = '999999';
_optionsItens.innerHTML = _itens;
_optionsItens.onclick = function(){ showhidden.hiddenObject(false); };
_optionsItens.onmouseout = function(){ showhidden.hiddenObject(false); };
_optionsItens.onmouseover = function(){ showhidden.hiddenObject(true); };
showhidden.action('onmouseover', 'onmouseout', _optionsItens);
element.parentNode.appendChild( _optionsItens );
}
}
function getElement( elementId )
{
return document.getElementById( elementId );
}
function getPhotoUser( jid )
{
var _divPhoto = getElement( jid + '__photo' );
if( _divPhoto.style.backgroundImage.indexOf('photo.png') > 0 )
{
var _imgUser = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date );
_imgUser += '&photo_ldap=' + jid;
_divPhoto.style.backgroundImage = 'url(' + _imgUser + ')';
}
}
function getUserCurrent()
{
return userCurrent;
}
function getZindex()
{
return zIndex++;
}
function groupsHidden()
{
if( arguments.length > 0 )
{
var _element = arguments[0];
_element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif') no-repeat center left";
_element.onclick = function(){ groupsVisible(_element);};
// Hidden all
var _elementNext = _element.nextSibling;
while( _elementNext )
{
if( _elementNext.nodeType == 1 )
_elementNext.style.display = "none";
_elementNext = _elementNext.nextSibling;
}
}
}
function groupsVisible()
{
if( arguments.length > 0 )
{
var _element = arguments[0];
_element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif') no-repeat center left";
_element.onclick = function(){ groupsHidden(_element);};
// Display all
var _elementNext = _element.nextSibling;
while( _elementNext )
{
if( _elementNext.nodeType == 1 )
_elementNext.style.display = "block";
_elementNext = _elementNext.nextSibling;
}
}
}
function keyPressSearch()
{
if( arguments.length > 0 )
{
var ev = arguments[0];
var element = arguments[1];
if ( ev.keyCode == 13 )
if( element.value.length >= 3 )
searchUser( element.value );
else
alert('Your search argument must be longer than 3 characters.');
}
}
function loginPage()
{
var winLoginPage =
{
id_window : "window_login_page",
width : 260,
height : 150,
top : 100,
left : 400,
draggable : true,
visible : "display",
resizable : true,
zindex : zIndex++,
title : "Expresso Messenger - Login",
closeAction : "remove",
content : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl")
};
_winBuild( winLoginPage );
}
function loadScripts(pFiles)
{
// Load JavaScript
var loadJavaScript = function(pJs)
{
var newScript = document.createElement("script");
newScript.setAttribute("type", "text/javascript");
newScript.setAttribute("src", pJs );
return newScript;
};
// Load CSS
var loadStyleSheet = function(pCss)
{
var newStyle = document.createElement("link");
newStyle.setAttribute("rel", "stylesheet");
newStyle.setAttribute("type", "text/css");
newStyle.setAttribute("href", pCss);
return newStyle;
};
for(var i = 0; i < pFiles.length; i++)
{
if( pFiles[i].indexOf(".js") > -1 )
document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i]));
if( pFiles[i].indexOf(".css") > -1 )
document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i]));
}
}
function notificationNewMessage()
{
var oldTitle = document.title;
var newTitle = "## NOVA MENSAGEM ##";
var idWindow = arguments[1];
if( timeoutId == null )
{
timeoutId = setInterval(function()
{
document.title = ( document.title == newTitle ) ? oldTitle : newTitle;
}, 1000);
configEvents( window.document, 'onclick', function()
{
clearInterval(timeoutId);
document.title = oldTitle;
timeoutId = null;
});
configEvents( window.document, 'onkeypress', function()
{
clearInterval(timeoutId);
document.title = oldTitle;
timeoutId = null;
});
}
}
function optionsItensContact()
{
if( arguments.length > 0 )
{
var jid = arguments[0];
var index = arguments[1];
var coord = arguments[2];
var element = getElement('itenContact_' + jid + '_' + index );
var action = ( element.getAttribute("subscription") === "not-in-roster" ) ? "Adicionar" : "Autorizar";
if( showhidden == null )
showhidden = new ShowHidden(300);
var _options = [
[ action , 'loadIM.setAutorization(\''+jid+'\',\''+index+'\')'],
['Remover' , 'loadIM.removeContact(\''+jid+'\',\''+index+'\')'],
['Renomear' , 'loadIM.renameContact(\''+jid+'\',\''+index+'\')'],
['Trocar grupo' , 'loadIM.renameGroup(\''+jid+'\',\''+index+'\')']
];
var _itens = "";
for( var i in _options )
{
if( typeof(_options[i]) == "object")
{
_itens += '';
_itens += '';
_itens += _options[i][0] + '
';
}
}
var _optionsItens = document.createElement("div");
_optionsItens.className = "x-menu";
_optionsItens.style.top = coord.Y;
_optionsItens.style.left = ( coord.X - element.offsetLeft );
_optionsItens.style.zIndex = getZindex();
_optionsItens.innerHTML = _itens;
_optionsItens.onclick = function(){ showhidden.hiddenObject(false); };
_optionsItens.onmouseout = function(){ showhidden.hiddenObject(false); };
_optionsItens.onmouseover = function(){ showhidden.hiddenObject(true); };
showhidden.action('onmouseover', 'onmouseout', _optionsItens);
window.document.body.appendChild(_optionsItens);
setTimeout(function()
{
window.document.oncontextmenu = function()
{
return true;
};
},500);
}
}
function parse()
{
if( arguments.length == 2 )
return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] );
if( arguments.length === 3 )
return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] );
}
function removeContact(jid, index)
{
setTimeout(function()
{
TrophyIM.removeContact(jid, index);
},300);
}
function removeElement( )
{
if( arguments.length > 0 )
{
var _element = arguments[0]
var _parent = _element.parentNode;
_parent.removeChild( _element );
}
}
function removeGroup()
{
var _parent = arguments[0];
if( _parent.childNodes.length <= 2 )
_parent.parentNode.removeChild(_parent);
}
function renameContact()
{
if( arguments.length > 0 )
{
var _jid = arguments[0];
var _index = arguments[1];
TrophyIM.renameContact( _jid, _index );
}
}
function renameGroup()
{
if( arguments.length > 0 )
{
var _jid = arguments[0];
var _index = arguments[1];
TrophyIM.renameGroup( _jid , _index );
}
}
function rosterDiv()
{
var paramListContact =
{
'idUser' : Base64.decode(getUserCurrent().jid),
'full_name' : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")),
'path_jabberit' : path_jabberit,
'zIndex_' : zIndex++
};
var winRosterDiv =
{
id_window : "window_Roster_im",
width : 250,
height : 410,
top : 50,
left : 50,
draggable : true,
visible : "display",
resizable : true,
zindex : zIndex++,
title : "Expresso Messenger - Contatos",
closeAction : "hidden",
content : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact)
};
_winBuild( winRosterDiv );
// Photo User
getPhotoUser(Base64.decode(getUserCurrent().jid));
}
function searchUser()
{
var _input = getElement('search_user_jabber');
if( _input.value.length >= 3 )
addUser.search();
else
alert('Your search argument must be longer than 3 characters.');
}
function setAutorization(jidTo, indexTo)
{
var divItenContact = null;
if( ( divItenContact = getElement('itenContact_' + jidTo + '_' + indexTo )))
{
var subscription = divItenContact.getAttribute('subscription');
switch(subscription)
{
case 'from':
TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
break;
case 'none' :
TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
break;
case 'not-in-roster':
setTimeout(function()
{
var _add = "";
if( ( _add = confirm("Deseja adicionar o usuario!")) )
{
addUser.add( jidTo, indexTo );
}
},100);
break;
case 'to' :
TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed');
case 'subscribe' :
TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe');
break;
}
}
}
function setPresence()
{
if( arguments.length > 0 )
{
var element = arguments[0];
if( showhidden == null )
showhidden = new ShowHidden(300);
var _status = [
['Afastado', 'away', ''],
['Disponível', 'available', ''],
['Livre p/ Conversa', 'chat', ''],
['Não Disponível', 'xa', ''],
['Ocupado', 'dnd', ''],
['Desconectado', 'unavailable', ''],
['Mensagem de Status...', 'status', ''],
];
var _itens = "";
for( var i in _status )
{
if( typeof( _status[i]) == "object" )
{
_itens += '';
_itens += _status[i][2]+ "" + _status[i][0] + "
";
}
}
var _statusItens = document.createElement("div");
_statusItens.style.marginTop = "65px";
_statusItens.style.marginLeft = "67px";
_statusItens.className = "x-menu";
_statusItens.style.zIndex = '99999';
_statusItens.innerHTML = _itens;
_statusItens.onclick = function(){ showhidden.hiddenObject(false); };
showhidden.action('onmouseover', 'onmouseout', _statusItens);
element.parentNode.onmouseout = function(){ showhidden.hiddenObject(false); };
element.parentNode.onmouseover = function(){ showhidden.hiddenObject(true); };
element.parentNode.appendChild(_statusItens);
}
}
function setSelectEditable(element)
{
if( getElement('selectBox0') == null )
selectEditable.create(element);
}
function setStatusJabber()
{
if( arguments.length > 0 )
{
if( arguments[1] != 'status' )
{
var _text = arguments[0];
var _img = arguments[1];
getElement('statusJabberText').innerHTML = _text;
getElement('statusJabberImg').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')";
getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat";
}
}
}
function teste_meu(_jid, _password )
{
userCurrent =
{
'jid' : _jid.substring(11, _jid.length),
'password' : _password.substring(11, _password.length)
}
}
function setUserCurrent()
{
conn.go('p.ff.data_0',
function(_User)
{
var _user = _User;
conn.go('p.ff.data_1',
function(_pass)
{
teste_meu( _user, _pass );
});
});
}
function loadIM()
{
if( arguments.length > 0 )
{
var files = [
path_jabberit + 'js/connector.js',
path_jabberit + 'js/xtools.js',
path_jabberit + 'js/dragdrop.js',
path_jabberit + 'js/makeW.js',
path_jabberit + 'js/show_hidden.js',
path_jabberit + 'js/trophyim.js',
path_jabberit + 'js/AddUser.js',
path_jabberit + 'js/SelectEditable.js',
path_jabberit + 'templates/default/css/button.css',
path_jabberit + 'templates/default/css/common.css',
path_jabberit + 'templates/default/css/selectEditableStyle.css',
path_jabberit + 'templates/default/css/' + theme_jabberit
];
// FullName
fullName = arguments[0];
loadScripts(files);
setTimeout(function()
{
// Object Xtools
if( Xtools == null )
Xtools = new xtools(path_jabberit);
// Object Conector
if( conn == null )
conn = new AjaxConnector(path_jabberit);
// Object Add User
if( addUser == null )
addUser = new addUserIM(Xtools, conn);
// Object SelectEditable
if( selectEditable == null )
selectEditable = new SelectEditable();
// Add Jabber in StatusBar;
addIcon();
window.document.oncontextmenu = function()
{
return true;
};
}, 1000);
}
}
loadIM.prototype.addIcon = addIcon;
loadIM.prototype.actionButton = actionButton;
loadIM.prototype.addContact = addContact;
loadIM.prototype.clrAllContacts = clrAllContacts;
loadIM.prototype.configEvents = configEvents;
loadIM.prototype.getPhotoUser = getPhotoUser;
loadIM.prototype.getUserCurrent = getUserCurrent;
loadIM.prototype.getZIndex = getZindex;
loadIM.prototype.groupsHidden = groupsHidden;
loadIM.prototype.groupsVisible = groupsVisible;
loadIM.prototype.keyPressSearch = keyPressSearch;
loadIM.prototype.loginPage = loginPage;
loadIM.prototype.notification = notificationNewMessage;
loadIM.prototype.parse = parse;
loadIM.prototype.searchUser = searchUser
loadIM.prototype.setAutorization = setAutorization;
loadIM.prototype.setPresence = setPresence;
loadIM.prototype.setStatusJabber = setStatusJabber;
loadIM.prototype.setSelectEditable = setSelectEditable;
loadIM.prototype.setUserCurrent = setUserCurrent;
loadIM.prototype.removeContact = removeContact;
loadIM.prototype.removeElement = removeElement;
loadIM.prototype.removeGroup = removeGroup;
loadIM.prototype.renameContact = renameContact;
loadIM.prototype.renameGroup = renameGroup;
loadIM.prototype.rosterDiv = rosterDiv;
window.LoadIM = loadIM;
})();