/* broadcast object is to help maintain a hash for link clicks and ajax calls * so we can have back button and refresh button working. * * Other file that currently depending on this are: * calendar.js * period_select.tpl * sites_selections.tpl * menu.js, ...etc */ // Load this once and only once. broadcast = {}; broadcast.init = function() { if(typeof broadcast.isInit != 'undefined') { return; } broadcast.isInit = true; // Initialize history plugin. // The callback is called at once by present location.hash $.historyInit(broadcast.pageload); } /************************************************ * * Broadcast Main Methods: * ************************************************/ /**========== PageLoad function ================= * This function is called when: * 1. after calling $.historyInit(); * 2. after calling $.historyLoad(); //look at broadcast.changeParameter(); * 3. after pushing "Go Back" button of a browser */ broadcast.pageload = function( hash ) { broadcast.init(); // hash doesn't contain the first # character. if( hash ) { // restore ajax loaded state broadcast.loadAjaxContent(hash); } else { // start page $('#content').empty(); } }; /* ============================================ * propagateAjax -- update hash values then make ajax calls. * example : * 1) View keywords report * 2) Main menu li also goes through this function. check out onClickLi(); * * Will propagate your new value into the current hash string and make ajax calls. * * NOTE: this method will only make ajax call and replacing main content. */ broadcast.propagateAjax = function (ajaxUrl) { broadcast.init(); // available in global scope var currentHashStr = window.location.hash; // Because $.history plugin doens't care about # or ? sign infront of the query string // We take it out if exist; currentHashStr = currentHashStr.replace(/^\?|^#/,''); ajaxUrl = ajaxUrl.replace(/^\?|&#/,''); var params_vals = ajaxUrl.split("&"); for( var i=0; i= 0 ) { var endStr = url.indexOf("&", startStr); if( endStr == -1 ) { endStr = url.length; } return url.substring(startStr + param.length +1,endStr); } else { return ''; } };