// Code copyright (c) Willett Consulting Limited 2010-2018 Namespace.Register("WCL"); WCL.General = { onLoadHandlers: new Array(), popups: new Object, resizeTimeoutId: 0, SetTitle : function(title) { var newTitle = "Oxford Fieldpaths Society"; if(title) { newTitle += ' - ' + title; } document.title = newTitle; var t = document.getElementById('pageTitle'); if(t) { if(t.innerText != undefined) { t.innerText = title; } else { t.textContent = title; } } }, AddOnLoadHandler : function(newHandler) { WCL.Debug.Log('Adding OnLoad handler: ' + newHandler); WCL.General.onLoadHandlers.push(newHandler); }, OnLoadEvent : function() { for(var i = 0; i < WCL.General.onLoadHandlers.length; ++i) { WCL.Debug.Log("Executing onload handler " + WCL.General.onLoadHandlers[i]); eval(WCL.General.onLoadHandlers[i]); } }, SetupResizeEvent : function() { WCL.Debug.Log('Executing SetupResizeEvent'); WCL.General.OnResizeEvent(); window.onresize = WCL.General.OnResizeEvent; }, OnResizeEvent : function() { WCL.Debug.Log('OnResizeEvent fired'); var h = document.getElementById('header'); var c = document.getElementById('contents'); var f = document.getElementById('footer'); if(h && c && f) { c.style.height = (WCL.General.GetWindowHeight() - h.offsetHeight - f.offsetHeight) + "px"; } }, GetWindowHeight : function() { var ret = 100; // most browsers if(window.innerHeight) { ret = window.innerHeight; } // IE6 in strict mode else if(document.documentElement && document.documentElement.clientHeight) { ret = document.documentElement.clientHeight; } else if(document.body && document.body.clientHeight) { ret = document.body.clientHeight; } return ret; }, format : function() { var formated = arguments[0]; for(var i = 1; i < arguments.length; ++i) { formated = formated.replace("{" + (i - 1) + "}", arguments[i]); } return formated; }, findPopups : function() { WCL.Debug.Log('Executing findPopups'); var popups = document.getElementsByTagName("a"); for(i = 0;i < popups.length;++i) { popup = popups[i]; if(popup.rel.indexOf("popup:") != -1) { popup.onclick = WCL.General.doPopup; if(popup.rel.indexOf("noicon") == -1) { popup.style.backgroundImage = "url(/img/popup.png)"; popup.style.backgroundPosition = "0 center"; popup.style.backgroundRepeat = "no-repeat"; popup.style.paddingLeft = "12px"; } if(popup.title == undefined || popup.title.length == 0) { popup.title = "[Opens in another window]"; } else { popup.title = popup.title + " [Opens in another window]"; } } } }, doPopup : function(e) { var u = this.href; if(u.substr(0, 7) != "http://" && u.substr(0, 8) != "https://") { u = "http://www.ofs.org.uk" + u; } var s = this.rel.indexOf("popup:") + 6; var e = this.rel.indexOf(" ", s); if(e == -1) { e = this.rel.length + 1; } var name = this.rel.substring(s, e); var w; if(WCL.General.popups.hasOwnProperty(name)) { try { WCL.Debug.Log('Opening in existing window ' + u + ' in ' + name); w = WCL.General.popups[name]; w.location.href = u; } catch(ex) { WCL.Debug.Log('Exception (' + ex.message + '), reopening ' + u + ' in ' + name); w = window.open(u, name); WCL.General.popups[name] = w; } } else { WCL.Debug.Log('Opening in new window ' + u + ' in ' + name); w = window.open(u, name); WCL.General.popups[name] = w; } return false; }, addFavourite : function(url, title) { var s=document.createElement('div').style; var undefined; var isNewFF=((navigator.userAgent.toLowerCase().indexOf('firefox') !=-1 ) && (s.wordWrap !== undefined) && (s.MozTransform !== undefined)); if((window.opera && window.print) || isNewFF) { var elem = document.createElement('a'); elem.setAttribute('href',url); elem.setAttribute('title',title); elem.setAttribute('rel','sidebar'); elem.click(); } else if(document.all && window.external) { window.external.AddFavorite(url, title); } else if(window.sidebar) { window.sidebar.addPanel(title, url, ""); } else { alert("Adding to favourites is not supported in this browser. Please add " + url + " manually to your favourites."); } return false; } }