//------------------------------------------------------------------------------ (function(window, undefined){ var document = window.document; function link_creater(){ var self = this; var ui = {}; var show = true; var base = 'https://www.kingwebtools.com/gwsfoods/login/'; self.init = function(){ map_ui(); if(show === true){ self.add_link('Login', 'login.html', 'kwm_user_status'); } else{ self.add_link('Logout', 'javascript:void(0);', 'kwm_user_status'); add_event('click', $('kwm_user_status'), (function(l){ return function(){ l(); }; })(logout)); } }; self.add_logout_link = function(){ self.add_link('Logout', 'javascript:void(0);', 'kwm_user_status'); add_event('click', $('kwm_user_status'), (function(l){ return function(){ l(); }; })(logout)); }; var logout = function(){ get_script(base + 'logout.php', (function(ui){ return function(){ window.location.reload(); }; })(ui)); }; var add_event = function(evt, obj, func){ if(obj === false){ return; } if(window.addEventListener){ obj.addEventListener(evt, func, false); } else if(document.attachEvent){ obj.attachEvent('on' + evt, func); } }; var get_script = function(url, callback, remove){ var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; var func = (function(h, s, c, r){ return function(){ if(c !== undefined){ c(); } if(r === undefined || r === true){ h.removeChild(s); } }; })(head, script, callback, remove); script.onload = func; script.onreadystatechange = (function(f){ return function(){ if(this.readyState === 'complete' || this.readyState === 'loaded'){ f(); } }; })(func); head.appendChild(script); }; var $ = function(div){ var d = document.getElementById(div); if(d){ return d; } else{ return false; } }; var map_ui = function(){ var elems = document.getElementsByTagName('td'); ui.side_nav = elems[0]; var d = document.createElement('div'); d.id = 'kwm_link_injector'; d.style.cssText = 'text-align: center; font-weight: normal; font-family: sans-serif; margin-top: 10px;'; ui.side_nav.appendChild(d); ui.main = d; }; self.add_link = function(name, src, id){ var a = document.createElement('a'); a.href = src; a.innerHTML = name; a.id = (id === undefined) ? '' : id; ui.main.appendChild(a); }; }; window.$kwm_links = new link_creater(); $kwm_links.init(); })(window); //------------------------------------------------------------------------------