common.js.svn-base
资源名称:cindyblog.rar [点击查看]
上传用户:cdpainuo
上传日期:2022-07-12
资源大小:5257k
文件大小:6k
源码类别:
Jsp/Servlet
开发平台:
Java
- document.getElementsByClassName = function(eleClassName){
- var getEleClass = [];
- var myclass = new RegExp("\b"+eleClassName+"\b");
- var elem = this.getElementsByTagName("*");
- for(var h=0;h<elem.length;h++) {
- var classes = elem[h].className;
- if (myclass.test(classes)) getEleClass.push(elem[h]);
- }
- return getEleClass;
- };
- document.getViewportHeight = function(){
- if (window.innerHeight!=window.undefined) return window.innerHeight;
- if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
- if (document.body) return document.body.clientHeight;
- return window.undefined;
- };
- document.getViewportWidth = function(){
- if (window.innerWidth!=window.undefined) return window.innerWidth;
- if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
- if (document.body) return document.body.clientWidth;
- };
- function addEvent(obj, evType, fn){
- if (obj.addEventListener){
- obj.addEventListener(evType, fn, false);
- return true;
- } else if (obj.attachEvent){
- var r = obj.attachEvent("on"+evType, fn);
- return r;
- } else {
- return false;
- }
- }
- function removeEvent(obj, evType, fn, useCapture){
- if (obj.removeEventListener){
- obj.removeEventListener(evType, fn, useCapture);
- return true;
- } else if (obj.detachEvent){
- var r = obj.detachEvent("on"+evType, fn);
- return r;
- } else {
- alert("Handler could not be removed");
- }
- }
- /**************************************************
- * dom-drag.js
- * 09.25.2001
- * www.youngpup.net
- **************************************************
- * 10.28.2001 - fixed minor bug where events
- * sometimes fired off the handle, not the root.
- **************************************************/
- var Drag = {
- obj : null,
- init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
- {
- o.onmousedown = Drag.start;
- o.hmode = bSwapHorzRef ? false : true ;
- o.vmode = bSwapVertRef ? false : true ;
- o.root = oRoot && oRoot != null ? oRoot : o ;
- if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px";
- if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px";
- if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px";
- if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
- o.minX = typeof minX != 'undefined' ? minX : null;
- o.minY = typeof minY != 'undefined' ? minY : null;
- o.maxX = typeof maxX != 'undefined' ? maxX : null;
- o.maxY = typeof maxY != 'undefined' ? maxY : null;
- o.xMapper = fXMapper ? fXMapper : null;
- o.yMapper = fYMapper ? fYMapper : null;
- o.root.onDragStart = new Function();
- o.root.onDragEnd = new Function();
- o.root.onDrag = new Function();
- },
- start : function(e)
- {
- var o = Drag.obj = this;
- e = Drag.fixE(e);
- var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
- var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
- o.root.onDragStart(x, y);
- o.lastMouseX = e.clientX;
- o.lastMouseY = e.clientY;
- if (o.hmode) {
- if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
- if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
- } else {
- if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
- if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
- }
- if (o.vmode) {
- if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
- if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
- } else {
- if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
- if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
- }
- document.onmousemove = Drag.drag;
- document.onmouseup = Drag.end;
- return false;
- },
- drag : function(e)
- {
- e = Drag.fixE(e);
- var o = Drag.obj;
- var ey = e.clientY;
- var ex = e.clientX;
- var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
- var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
- var nx, ny;
- if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
- if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
- if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
- if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
- nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
- ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
- if (o.xMapper) nx = o.xMapper(y)
- else if (o.yMapper) ny = o.yMapper(x)
- Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
- Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
- Drag.obj.lastMouseX = ex;
- Drag.obj.lastMouseY = ey;
- Drag.obj.root.onDrag(nx, ny);
- return false;
- },
- end : function()
- {
- document.onmousemove = null;
- document.onmouseup = null;
- Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
- parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
- Drag.obj = null;
- },
- fixE : function(e)
- {
- if (typeof e == 'undefined') e = window.event;
- if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
- if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
- return e;
- }
- };
- //Ajax.request('get','http://localhost',function(msg){alert("success");});
- var Ajax = {
- createXHR:function(){
- var xhr = null;
- if (window.XMLHttpRequest){
- xhr = new XMLHttpRequest();
- }else{
- var MSXML=['Msxml2.XMLHTTP.7.0','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP'];
- for(var i=0;i<MSXML.length;i++){
- try{
- xhr=new ActiveXObject(MSXML[i]);
- break;
- }catch (ex){}
- }
- }
- return xhr;
- },
- request:function(method,url,callback){
- var xhr = this.createXHR();
- xhr.open(method, url, true);
- xhr.onreadystatechange = function(){
- if (xhr.readyState == 4){
- if (xhr.status == 200) {
- callback(xhr.responseText);
- } else {
- alert("Error:"+xhr.status);
- }
- }
- };
- if(method == "post" || method == "POST"){
- xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
- }
- xhr.send("");
- }
- };