|
From: Lo?c C. <lo...@us...> - 2001-04-03 20:17:44
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/index_libs In directory usw-pr-cvs1:/tmp/cvs-serv6312/chat/lib/index_libs Added Files: start_page.lib.js users.lib.js Log Message: The first dev. version that works! Still many things to do, of course... --- NEW FILE --- // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | Set of JavaScript functions used by the starting form of the chat. | // | | // | This library is called by the 'chat/lib/index_libs/main_index.lib.php3' | // | script. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: start_page.lib.js,v 1.1 2001/04/03 20:17:40 loic1 Exp $ // // Set of JavaScript functions used by the starting form of the chat. // /** * Updates the "jsVersion" field in the form below according to the JavaScript * abilities of the browser * * @access public */ function pmcDefineVerField() { // js1.1 but not 1.2 enabled browser if (typeof(document.images) != 'undefined' && jsWhichVersion == 'low') { document.forms['startingForm'].elements['jsVersion'].value = 'medium'; } // other cases else { document.forms['startingForm'].elements['jsVersion'].value = jsWhichVersion; } } // end of the 'pmcDefineVerField()' function /** * Launches the tutorial * * @access public */ function pmcTutorialPopup() { var tutorialUrl = jsChatPath + 'tutorial_popup.' + jsPhpExt + '?' + 'lang=' + jsLang + jsUrlArgSeparator + 'jsVersion=' + jsWhichVersion; // Launches the tutorial window only if it doesn't already exists if (!jsTutorialWin) { if (jsIsJs11) window.focus(); jsTutorialWin = window.open(tutorialUrl, 'tutorial_popup', 'resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,status=yes'); } if (jsIsJs11) jsTutorialWin.focus(); } // end of the 'pmcTutorialPopup()' function /** * Launches the users popup according to the DHTML capacities of the browser * * @param dummy used to ensure the popup name is unique * * @access public */ function pmcUsersPopup(dummy) { var whichFile = (jsWhichVersion == 'low') ? '_low' : ''; var usersUrl = jsChatPath + 'users_popup' + whichFile + '.' + jsPhpExt + '?' + jsDbSessionSID; // Launches the users popup only if it doesn't already exists if (!jsUsersPopupWin) { if (jsIsJs11) window.focus(); jsUsersPopupWin = window.open(usersUrl, 'users_popup_' + dummy, 'width=180,height=300,resizable=yes,scrollbars=yes'); } if (jsIsJs11) jsUsersPopupWin.focus(); } // end of the 'pmcUsersPopup()' function /** * Launches the popups for the registration stuffes * * @param name the name of the script to launch * * @access public */ function pmcRegPopups(name) { var regUrl = jsChatPath + name + '.' + jsPhpExt + '?' + jsDbSessionSID; var popWidth = (name != 'admin') ? 350 : 510; var popHeight = (name != 'profile_del') ? 470 : 190; var popParams = 'width=' + popWidth + ',height=' + popHeight + ',resizable=yes,scrollbars=yes'; if (jsIsJs11) window.focus(); jsRegPopupWin = window.open(regUrl, name + '_popup', popParams); if (jsIsJs11) jsRegPopupWin.focus(); } // end of the 'pmcRegPopups()' function /** * Allows to ensure an unique choice among rooms * * @param choiceType type of the room that has been selected * * @access public */ function pmcResetRoomBox(choiceType) { var resetR0 = document.forms['startingForm'].elements['enterDefaultRoomName'].options[0]; var resetR1 = document.forms['startingForm'].elements['enterOtherRoomName'].options[0]; var resetT = document.forms['startingForm'].elements['roomType'].options[0]; var resetR2 = document.forms['startingForm'].elements['createRoomName']; // A default public chat room has been selected if (choiceType == 'default') { resetR1.selected = true; resetT.selected = true; resetR2.value = ''; } // An 'other' public chat room has been selected else if (choiceType == 'otherPub') { resetR0.selected = true; resetT.selected = true; resetR2.value = ''; } else { resetR0.selected = true; resetR1.selected = true; } } // end of the 'pmcResetRoomBox()' function /** * Validates briefly the starting form * * @param doCheckPaswd whether to ensure there is a password or not * * @access public */ function pmcIndexValidate(doCheckPswd) { // The replace function (js1.2) isn't supported -> no js tests are done if (typeof(document.forms['startingForm'].elements['nick'].value.replace) == 'undefined') return true; var nickField = document.forms['startingForm'].elements['nick']; var pswdField = document.forms['startingForm'].elements['password']; var roomToCreate = document.forms['startingForm'].elements['createRoomName']; var reNick = /\\|,| /; var reRoom = /\\|,/; // Brief nick validation if (nickField.value.replace(/ /g, '') == '') // nick is empty { nickField.value = ''; nickField.focus(); alert(jsErrorNick1); return false; } else if (reNick.test(nickField.value)) // invalid characters in { // the nick nickField.focus(); alert(jsErrorNick2); return false; } // Brief password validation if (doCheckPswd && pswdField.value.replace(/ /g, '') == '') // registration is required { // but password is empty pswdField.value = ''; pswdField.focus(); alert(jsErrorPswd1); return false; } // Ensure there is a password if the user wants to create room if (roomToCreate.value != '' && pswdField.value.replace(/ /g, '') == '') { pswdField.focus(); alert(jsErrorPswd2); return false; } // Brief room name validation if (roomToCreate != '') { if (roomToCreate.value.replace(/ /g, '') == '') // only space chars { roomToCreate.value = ''; } else if (reRoom.test(roomToCreate.value)) // invalid characters in { // the name of the room to roomToCreate.focus(); // create alert(jsErrorRoom); return false; } } // All the tests have been succesfully passed -> submit the from return true; } // end of the function 'pmcIndexValidate()' --- NEW FILE --- // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | Set of JavaScript functions used to handle the the collapsible list of | // | rooms at the users frame with IE & NS 4+ browsers (DHTML stuff). | // | | // | This library is called by the 'chat/lib/index_libs/main_index.lib.php3' | // | script. | // | | // | It is is based on the 'Expandable Outlines' script from WebReference | // | (http://webreference.com/). | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: users.lib.js,v 1.1 2001/04/03 20:17:40 loic1 Exp $ // // Handle the expandable/collapsible list of rooms at the users frame. // var jsUsersFrame = null; var jsExitFrame = null; var jsUsersY = false; var jsIsExpanded = false; var jsOpenedRooms = new Array; var jsRoomsCnt = 0; var jsOpenedRoomsCnt = 0; var jsChildCnt = new Array; var jsImgBigOpened = new Image(13,13); jsImgBigOpened.src = jsChatPath + 'images/open_big.gif'; var jsImgBigClosed = new Image(13,13); jsImgBigClosed.src = jsChatPath + 'images/closed_big.gif'; var jsImgOpened = new Image(9,9); jsImgOpened.src = jsChatPath + 'images/open.gif'; var jsImgClosed = new Image(9,9); jsImgClosed.src = jsChatPath + 'images/closed.gif'; /** * Resets the table containing the state (opened/closed) of each room */ function pmcResetRoomTable() { for (test in jsOpenedRooms) { jsOpenedRooms[test] = (jsOpenedRooms[test] == 1) ? '+' : '-'; } } // end of the 'pmcResetRoomTable()' function /** * Checks the state (opened/closed) of a room * * @param room the room name to be checked */ function pmcCheckRoomState(room) { if (jsOpenedRooms[room]) { jsOpenedRooms[room] = (jsOpenedRooms[room] == '+') ? 1 : -1; return jsOpenedRooms[room]; } else return 0; } // end of the 'pmcCheckRoomState()' function /** * Cleans the table containing all rooms names from those that are no longer * in use */ function pmcCleanRoom() { var temp = new Array(); for (test in jsOpenedRooms) { if (jsOpenedRooms[test] == 1 || jsOpenedRooms[test] == -1) temp[test] = jsOpenedRooms[test]; } jsOpenedRooms = temp; temp = null; } // end of the 'pmcCleanRoom()' function /** * Sets the new state of a room in the rooms array * * @param room the name of the room which state has changed * @param action wether to set this new status to opened or closed */ function pmcModifyRoomState(room, action) { jsOpenedRooms[room] = (action == 'add') ? 1 : -1; } // end of the 'pmcModifyRoomState()' function /** * Gets the id of the first collapsible room * * @param el name of the first collapsible room */ function pmcGetIndex(el) { var ind = null; for (var i = 0; i < jsUsersFrame.document.layers.length; i++) { var whichEl = jsUsersFrame.document.layers[i]; if (whichEl.id == el) { ind = i; break; } } return ind; } // end of the 'pmcGetIndex()' function /** * Positions layers under NS4+ */ function pmcNsArrangeList() { if (jsUsersFrame.jsFirstInd != null) { var nextY = jsUsersFrame.document.layers[jsUsersFrame.jsFirstInd].pageY + jsUsersFrame.document.layers[jsUsersFrame.jsFirstInd].document.height; for (var i = jsUsersFrame.jsFirstInd + 1; i < jsUsersFrame.document.layers.length; i++) { var whichEl = jsUsersFrame.document.layers[i]; if (whichEl.visibility != 'hide') { whichEl.pageY = nextY; nextY += whichEl.document.height; } } } } // end of the 'pmcNsArrangeList()' function /** * Defines the state of the big +/- icon */ function pmcSetBigIcon() { if (jsRoomsCnt == 0) return; var bigImg = (jsIsNS4) ? jsExitFrame.document.images['imgExpandAll'] : jsExitFrame.document.images.item('imgExpandAll'); if (jsOpenedRoomsCnt == jsRoomsCnt) { jsIsExpanded = true; bigImg.src = jsImgBigOpened.src; } else if (jsIsExpanded) { jsIsExpanded = false; bigImg.src = jsImgBigClosed.src; } } // end of the 'pmcSetBigIcon()' function /** * Collapses/expands rooms (depends on the state of the room before the page * reloads) each time the web page is loaded */ function pmcInitList() { if (!jsIsVersion4) return; pmcResetRoomTable(); var parentElts = new Array(); jsOpenedRoomsCnt = 0; if (jsIsNS4) { for (var i = 0; i < jsUsersFrame.document.layers.length; i++) { var whichEl = jsUsersFrame.document.layers[i]; if (whichEl.id.indexOf('Parent') != -1) var parentEl = whichEl; if (whichEl.id.indexOf('Child') != -1) { var currentId = whichEl.id.substring(5); var roomState = pmcCheckRoomState(whichEl.id); if (roomState == 1 || (roomState == 0 && jsChildCnt[currentId] < 10)) { jsOpenedRoomsCnt++; whichEl.visibility = 'show'; if (!parentElts[parentEl.id]) { parentElts[parentEl.id] = 1; parentEl.document.images['imEx'].src = jsImgOpened.src; } } else { whichEl.visibility = 'hide'; } } } pmcNsArrangeList(); } // end of the NS4 case else { divColl = jsUsersFrame.document.all.tags('div'); for (var i = 0; i < divColl.length; i++) { var whichEl = divColl(i); if (whichEl.className == 'parent') var parentEl = whichEl; if (whichEl.className == 'child') { var currentId = whichEl.id.substring(5); var roomState = pmcCheckRoomState(whichEl.id); if (roomState == 1 || (roomState == 0 && jsChildCnt[currentId] < 10)) { jsOpenedRoomsCnt++; whichEl.style.display = 'block'; if (!parentElts[parentEl.id]) { parentElts[parentEl.id] = 1; parentEl.all.tags('IMG').item('imEx').src = jsImgOpened.src; } } else { whichEl.style.display = 'none'; } } } } // end of the IE4 case parentElts = null; jsChildCnt = null; pmcCleanRoom(); pmcSetBigIcon(); } // end of the 'pmcInitList()' function /** * Collapses/expands a room when the user require this to be done and store * the new state of the room * * @param el name of the room to act on */ function pmcExpandRoom(el) { if (!jsIsVersion4) return; if (jsIsIE4) { var whichEl = jsUsersFrame.document.all('Child' + el); var whichIm = jsUsersFrame.event.srcElement; if (whichEl.style.display == 'none') { jsOpenedRoomsCnt++; whichEl.style.display = 'block'; whichIm.src = jsImgOpened.src; pmcModifyRoomState(whichEl.id, 'add'); } else { jsOpenedRoomsCnt--; whichEl.style.display = 'none'; whichIm.src = jsImgClosed.src; pmcModifyRoomState(whichEl.id, 'del'); } } // end of the IE4 case else { var whichEl = jsUsersFrame.document.layers['Child' + el]; var whichIm = jsUsersFrame.document.layers['Parent' + el].document.images['imEx']; if (whichEl.visibility == 'hide') { jsOpenedRoomsCnt++; whichEl.visibility = 'show'; whichIm.src = jsImgOpened.src; pmcModifyRoomState(whichEl.id, 'add'); } else { jsOpenedRoomsCnt--; whichEl.visibility = 'hide'; whichIm.src = jsImgClosed.src; pmcModifyRoomState(whichEl.id, 'del'); } pmcNsArrangeList(); } // end of the NS4 case pmcSetBigIcon(); var msgBox = pmcGetInputForm('msgText') // the 'pmcGetInputForm()' function if (msgBox) // is defined inside the script msgBox.focus(); // 'chat/lib/index_libs/misc.lib.js' } // end of the 'pmcExpandRoom()' function /** * Collapses/expands all rooms when the user require this to be done and store * the new state of these rooms */ function pmcExpandAll() { if (!jsIsVersion4) return; var newBigSrc = (jsIsExpanded) ? jsImgBigClosed.src : jsImgBigOpened.src; var newSrc = (jsIsExpanded) ? jsImgClosed.src : jsImgOpened.src; var what = (jsIsExpanded) ? 'del' : 'add'; jsOpenedRoomsCnt = (jsIsExpanded) ? 0 : jsRoomsCnt; if (jsIsNS4) { jsExitFrame.document.images['imgExpandAll'].src = newBigSrc; if (jsUsersFrame.jsFirstInd != null) { if (jsUsersFrame.document.layers.length) { for (var i = jsUsersFrame.jsFirstInd; i < jsUsersFrame.document.layers.length; i++) { var whichEl = jsUsersFrame.document.layers[i]; if (whichEl.id.indexOf('Parent') != -1) whichEl.document.images['imEx'].src = newSrc; if (whichEl.id.indexOf('Child') != -1) { whichEl.visibility = (jsIsExpanded) ? 'hide' : 'show'; pmcModifyRoomState(whichEl.id, what); } } } pmcNsArrangeList(); if (jsIsExpanded) jsUsersFrame.scrollTo(0, jsUsersFrame.document.layers[jsUsersFrame.jsFirstInd].pageY); } } // end of the NS4 case else { var divColl = jsUsersFrame.document.all.tags('div'); for (var i = 0; i < divColl.length; i++) { if (divColl(i).className == 'child') { divColl(i).style.display = (jsIsExpanded) ? 'none' : 'block'; pmcModifyRoomState(divColl(i).id, what); } } jsExitFrame.document.images.item('imgExpandAll').src = newBigSrc; var imColl = jsUsersFrame.document.images.item('imEx'); if (imColl) { for (var i = 0; i < imColl.length; i++) { imColl(i).src = newSrc; } if (!imColl.length) jsUsersFrame.document.imEx.src = newSrc; } } // end of the IE4 case jsIsExpanded = (!jsIsExpanded); var msgBox = pmcGetInputForm('msgText') // the 'pmcGetInputForm()' function if (msgBox) // is defined inside the script msgBox.focus(); // 'chat/lib/index_libs/misc.lib.js' } // end of the 'pmcExpandAll()' function |