discourse-legacysite-perl/site/common/static/js/utils.min.js

12 lines
4.4 KiB
JavaScript
Raw Normal View History

2024-06-17 12:27:49 +00:00
function registerEvent(a,b,c){if(a&&b&&c)if(a.addEventListener)a.addEventListener(b,c,false);else a.attachEvent&&a.attachEvent("on"+b,c)}function unregisterEvent(a,b,c){if(a&&b&&c)if(a.removeEventListener)try{a.removeEventListener(b,c,false)}catch(d){}else if(a.detachEvent)try{a.detachEvent("on"+b,c)}catch(f){}}function stopPropagation(a){if(a)if(a.stopPropagation)a.stopPropagation();else a.cancelBubble=true}
function cancelEvent(a){if(a)if(a.preventDefault&&a.cancelable)a.preventDefault();else a.returnValue=false}function findPosX(a){var b=0;if(a.offsetParent)for(;a.offsetParent;){b+=a.offsetLeft;a=a.offsetParent}else if(a.x)b+=a.x;return b}function findPosY(a){var b=0;if(a.offsetParent)for(;a.offsetParent;){b+=a.offsetTop;a=a.offsetParent}else if(a.y)b+=a.y;return b}
function getStyle(a,b){if(document.defaultView&&document.defaultView.getComputedStyle){if(a=document.defaultView.getComputedStyle(a,null))return a.getPropertyValue(b)}else if(a.currentStyle){b=b.replace(/-(.)/g,function(c,d){return d.toUpperCase()});return a.currentStyle[b]}}function getStyleLength(a,b){a=getStyle(a,b);if(a.match(/^\d+(?:\.\d+)?px$/))return parseFloat(a);return 0}
function calcCSSWidth(a,b){if(isIE&&ieVersion<=5.5)return b+"px";return b-getStyleLength(a,"padding-left")-getStyleLength(a,"padding-right")-getStyleLength(a,"border-left-width")-getStyleLength(a,"border-right-width")+"px"}function calcCSSHeight(a,b){if(isIE&&ieVersion<=5.5)return b+"px";return b-getStyleLength(a,"padding-top")-getStyleLength(a,"padding-bottom")-getStyleLength(a,"border-bottom-width")-getStyleLength(a,"border-bottom-width")+"px"}
function htmlEscape(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function htmlUnEscape(a){return a.replace(/&quot;/gi,'"').replace(/&gt;/gi,">").replace(/&lt;/gi,"<").replace(/&amp;/gi,"&")}var isOpera=false,operaVersion,isIE=false,ieVersion,isMozilla=false,mozillaVersion,isWebkit=false,webkitVersion,isChrome=false,chromeVersion,isSafari=false,safariVersion,ua=navigator.userAgent;
if(ua.match(/Opera(?:\s+|\/)([0-9.]+)/i)){isOpera=true;operaVersion=RegExp.$1}else if(ua.match(/MSIE\s+([0-9.]+)/i)){isIE=true;ieVersion=RegExp.$1}else if(ua.match(/Mozilla\/([0-9.]+)\s+\(.*\s+rv:([0-9.]+)/i)){isMozilla=true;mozillaVersion=RegExp.$2}else if(ua.match(/AppleWebKit\/([0-9.]+)/i)){isWebkit=true;webkitVersion=RegExp.$1;if(ua.match(/Chrome\/([0-9.]+)/i)){isChrome=true;chromeVersion=RegExp.$1}else if(ua.match(/Version\/([0-9.]+)/i)){isSafari=true;safariVersion=RegExp.$1}}var _submitForm_Div;
function submitForm(a,b){_submitForm_Div&&_submitForm_Div.parentNode.removeChild(_submitForm_Div);_submitForm_Div=document.createElement("div");_submitForm_Div.id="_submitForm_Div";_submitForm_Div.style.display="none";a.appendChild(_submitForm_Div);var c;for(a=0;a<b.length;a+=2){c=document.createElement("input");c.type="hidden";c.name=b[a];c.value=b[a+1];_submitForm_Div.appendChild(c)}b=document.createElement("input");b.type="submit";_submitForm_Div.appendChild(b);b.click();return false}
function xmlReqSend(a,b,c,d,f){var e;b=b?b.toUpperCase():"GET";if(b!="GET"&&b!="POST"&&b!="HEAD")b="GET";if(window.XMLHttpRequest)e=new XMLHttpRequest;else if(window.ActiveXObject)try{e=new ActiveXObject("Msxml2.XMLHTTP")}catch(g){try{e=new ActiveXObject("Microsoft.XMLHTTP")}catch(h){e=false}}if(e){e.onreadystatechange=function(){_xmlReqChange(e,d,f)};a=a.replace(/^https?:\/\/[^\/]+\//,"/");e.open(b,a,true);e.send(c)}}
function _xmlReqChange(a,b,c){if(a.readyState==4)if(a.status==200)b&&b(a);else c&&c(a)}function insertText(a,b){if(a.setSelectionRange){var c=a.selectionStart,d=a.selectionEnd;a.value=a.value.substr(0,c)+b+a.value.substr(d,a.value.length);c+=b.length;setSelectionRange(a,c,c)}else if(document.selection){a.focus();c=document.selection.createRange();if(c.parentElement()==a)c.text=b}else a.value+=b}
function wrapText(a,b,c){if(a.setSelectionRange){var d=a.selectionStart,f=a.selectionEnd;a.value=a.value.substr(0,d)+b+a.value.substr(d,f-d)+c+a.value.substr(f,a.value.length);setSelectionRange(a,d+b.length,f+b.length)}else if(document.selection){a.focus();d=document.selection.createRange();if(d.parentElement()==a){a=d.text.length;d.text=b+d.text+c;d.moveEnd("character",-c.length);d.moveStart("character",-a);d.select()}}else a.value+=b+c}
function setSelectionRange(a,b,c){if(a.setSelectionRange){a.focus();a.setSelectionRange(b,c)}else if(a.createTextRange){a=a.createTextRange();a.collapse(true);a.moveEnd("character",c);a.moveStart("character",b);a.select()}};