/* $Id: sentel.js 14 2007-07-13 22:18:40Z zapotek $ */ /* __________________________________________________________________ */ /** * Here we keep general data that we want available globaly */ var gbl = { 'method' : 'POST', 'handler' : 'ajax_handler.php', 'showLoader' : true, 'uploadFile' : false, 'parent_id' : 0 } var default_gbl = { } /** * Here we will save the variables we want to send to the server */ var params = { // this language is the language currenlty viewing in // the browser 'lang' : 'en', // this language is the one we tell the server we want the // sent data to be in ( defaults to the current viewing language ) 'language' : 'en' } /** * Xtra params will be send to the server along with params * but will be emptied after every request */ var xparams = { } // common utility functions function $() { var elements = new Array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getElementById(element); if (arguments.length == 1) return element; elements.push(element); } return elements; } // ----------------------------------- // SENTELs namespace utilities if (typeof SENTEL == "undefined") { var SENTEL = {}; } SENTEL.util = { toggle : function( el ) { if( typeof el != 'object' ) el = document.getElementById(el); if ( el.style.display != 'none' ) { el.style.display = 'none'; } else { el.style.display = 'block'; } }, showLoader : function( state ) { var el = $('loadingDialog'); if( !el ) return; if( !state ) el.style.display = 'none'; else el.style.display = 'block'; }, response : function( o, key, index ) { index = ( typeof index == 'undefined' ) ? 0 : index; // SENTEL.log( o.responseXML ); node = o.responseXML.getElementsByTagName(key)[index]; return SENTEL.dom.nodeContent( node ); }, responseError : function( o ) { error = SENTEL.util.response( o, 'error' ); return parseInt( error ); }, getCenter : function( obj ) { var cX = Math.round((Dom.getViewportWidth() - parseInt(obj[0])) / 2); var cY = Math.round((Dom.getViewportHeight() - parseInt(obj[1])) / 2); return [cX, cY]; } }; SENTEL.log = function( mixed, type ) { // echo info to the console if( typeof console == 'object' ) { switch( type ) { case 'error': console.error( mixed ); break; case 'info': console.info( mixed ); break; default: console.log( mixed ); break; } } } SENTEL.dom = { nodeContent : function( node ) { // -- Crossbrowser solution // -- textContent for Firefox // -- text for IE var ret = (node.text) ? node.text : node.textContent; return ret; } // end getNodeContent() }; // end SENTEL namespace utilities // ----------------------------------- // ----------------------------------- // SENTELs YUI wrappers SENTEL.util.sendRequest = function( action, myCallback ) { if( gbl.showLoader ) { // before we send the request show our kewl loading bar image SENTEL.util.showLoader(true); } var tempData = ''; var i = 0; for( key in params ) { if( params[ key ] != 'undefined' ){ if( i ) tempData += '&'; tempData += key +'='+ params[ key ]; i++; } } gbl.last_action = action; gbl.last_callback = myCallback; xparams.action = action; for( key in xparams ) { if( tempData != '' ) tempData += '&'; tempData += key +'='+ xparams[ key ]; } xparams = {}; var data = { get : '', post : '' } if( gbl.method == 'POST' ) { data.post = tempData; } else { data.get = '?'+ tempData; } var handleSuccess = function(o) { // hide our loader SENTEL.util.showLoader(false); if( o.responseText != undefined || o.responseXML != undefined ) { if( typeof myCallback == 'function' ) { myCallback(o); } } } var handleFailure = function(o) { // hide our loader SENTEL.util.showLoader(false); SENTEL.log( 'ajax request failed!', 'error' ); SENTEL.log( o, 'info' ); } if( !gbl.uploadFile ) { var callback = { success : handleSuccess, failure : handleFailure }; } else { var callback = { upload: handleSuccess }; } Connect.asyncRequest( gbl.method, gbl.handler + data.get, callback, data.post ); } // end SENTEL.util.sendRequest() /** * */ function animateDialog( obj, fn ) { if( !obj.startFromEvent ) { Dom.setXY( obj.dlgName, obj.xy ); var attrs = { width : { to: obj.wh[0] }, height : { to: obj.wh[1] } }; } else { Dom.setXY( obj.dlgName, obj.startXY ); var attrs = { points : { to : obj.xy }, width : { to: obj.wh[0] }, height : { to: obj.wh[1] } }; } var anim = new Motion( obj.dlgName, attrs, obj.duration, Easing.easeBothStrong ); if( typeof fn == 'function' ) { anim.onComplete.subscribe( fn ); } anim.animate(); } // end animateDialog() // end SENTELs YUI wrappers // ----------------------------------- function closeDialog( dlgName ) { el = $(dlgName); el.innerHTML = ''; Dom.setXY( el, [-500, -500] ); } function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } // global initializes go here function init() { toggleTocByCookie(); sidebars = Array( 'popProjects', 'popCodes', 'popPapers', 'tagList', 'others', 'stupidPeople' ); for( i = 0; i < sidebars.length; i++ ) { toggleSidebarByCookie(sidebars[i]); } } YAHOO.util.Event.addListener( window, 'load', init ); // shorhands var Event = YAHOO.util.Event; var Dom = YAHOO.util.Dom; var Connect = YAHOO.util.Connect; var Animation = YAHOO.util.Animation; var Motion = YAHOO.util.Motion; var Easing = YAHOO.util.Easing; function toggleSidebarByCookie( id ) { if( !$(id) ) return; // alert( id ); var sidebar = $(id); if ( readCookie( "hide_" + id ) == '1' ) { sidebar.style.display = 'none'; } else { sidebar.style.display = 'block'; } } function toggleTocByCookie() { if( !$('toc') ) return; var toc = $('toc').getElementsByTagName('ul')[0]; var toggleLink = $('togglelink'); if ( readCookie( 'hidetoc' ) == '1' ) { toggleLink.innerHTML = "Show"; toc.style.display = 'none'; } else { toggleLink.innerHTML = "Hide"; toc.style.display = 'block'; } } function toggleToc() { var toc = $('toc').getElementsByTagName('ul')[0]; var toggleLink = $('togglelink'); if (toc && toggleLink && toc.style.display == 'none') { toggleLink.innerHTML = "Hide"; toc.style.display = 'block'; createCookie( 'hidetoc', '0' ); } else { toggleLink.innerHTML = "Show"; toc.style.display = 'none'; createCookie( 'hidetoc', '1' ); } } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }