﻿                                      (function(floatDivId, options) { var floatDiv = document.getElementById(floatDivId); if (!floatDiv) { return; } if (document.body != floatDiv.parentNode) { floatDiv.parentNode.removeChild(floatDiv); document.body.appendChild(floatDiv); } function getClientSize() { var myWidth = 0, myHeight = 0; if (typeof (window.innerWidth) == 'number') { myWidth = window.innerWidth; myHeight = window.innerHeight; } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } return { width: myWidth, height: myHeight }; } function getImageSize() { var img = document.getElementById('comm100_ButtonImage'); return { width: img.width, height: img.height }; } function getDivLocation(div) { var left = parseInt(div.style.left.replace(/^(d+).*?$/, '$1')); var top = parseInt(div.style.top.replace(/^(d+).*?$/, '$1')); return { x: left, y: top }; } function addWindowEventListerner(event, func) { if (window.addEventListener) { window.addEventListener(event, func, false); } else if (window.attachEvent) { window.attachEvent('on' + event, func); } } function initLocation() { var clientSize = getClientSize(); var imageSize = getImageSize(); var x = 0, y = 0; if (options.left != undefined) { x = options.left; } else if (options.right != undefined) { x = clientSize.width - imageSize.width - options.right; } else if (options.pleft != undefined) { x = (clientSize.width - imageSize.width) * options.pleft * 0.01; } else if (options.pright != undefined) { x = (clientSize.width - imageSize.width) - (clientSize.width - imageSize.width) * options.pright * 0.01; } if (options.top != undefined) { y = options.top; } else if (options.bottom != undefined) { y = clientSize.height - imageSize.height - options.bottom; } else if (options.ptop != undefined) { y = (clientSize.height - imageSize.height) * options.ptop * 0.01; } else if (options.pbottom != undefined) { y = (clientSize.height - imageSize.height) - (clientSize.height - imageSize.height) * options.pbottom * 0.01; } if (x > 0) x = Math.ceil(x); else x = Math.floor(x); if (y > 0) dy = Math.ceil(y); else y = Math.floor(y); floatDiv.style.zIndex = 65535; floatDiv.style.position = 'absolute'; floatDiv.style.left = x + 'px'; floatDiv.style.top = y + 'px'; } var lastTimerID = 0; function initFloatChatButton() { initLocation(); var lastScrollY = 0; var lastScrollX = 0; function moveDiv() { try { scrollX = document.body.scrollLeft || document.documentElement.scrollLeft; scrollY = document.body.scrollTop || document.documentElement.scrollTop; dx = 0.5 * (scrollX - lastScrollX); dy = 0.5 * (scrollY - lastScrollY); if (dx > 0) dx = Math.ceil(dx); else dx = Math.floor(dx); if (dy > 0) dy = Math.ceil(dy); else dy = Math.floor(dy); var location = getDivLocation(floatDiv); floatDiv.style.left = (location.x + dx) + 'px'; floatDiv.style.top = (location.y + dy) + 'px'; lastScrollX = lastScrollX + dx; lastScrollY = lastScrollY + dy; } catch (err) { if (lastTimerID != 0) clearInterval(lastTimerID); alert(err); } } if (lastTimerID != 0) clearInterval(lastTimerID); lastTimerID = setInterval(moveDiv, 100); } addWindowEventListerner('resize', initFloatChatButton); addWindowEventListerner('load', initFloatChatButton); })('comm100_ChatButtonCode', { left: 10, top: 100 });
