⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ig_webtab.js

📁 研究怎样通过手写代码来完成自动生成代码
💻 JS
📖 第 1 页 / 共 3 页
字号:
			tab.elemLeft = elem;
			this.addLsnr(elem, false);
		}
		if((round & 2) != 0) if((elem = igtab_getElementById(id + "td" + i + "R")) != null)
		{
			elem.setAttribute("tabID", id + "," + i);
			tab.elemRight = elem;
			this.addLsnr(elem, false);
		}
	}
	this.findControl = function(id)
	{
		var c, i = -1;
		while(this.Tabs[++i] != null) if((c = this.Tabs[i].findControl(id)) != null) return c;
	}
	//
	this.update = function(i, pr, v, post)
	{
		var e = this.elemState;
		if(e == null) if((e = this.elemState = igtab_getElementById(this.ID)) == null) return;
		if(this.viewState == null) this.viewState = new ig_xmlNode();
		var n = this.viewState.addNode("x", true);
		if(i >= 0) n = n.addNode("Tabs", true).addNode("i" + i, true);
		//10000 - flag for server about postBack!!
		n.setPropertyValue(pr, "" + ((post == 1) ? (v + 10000) : v));
		e.value = this.viewState.getText();
		if(post != 1) return;
		if((e = this.getSelectedTab()) != null) if((e = e.getTargetUrlDocument()) != null) try
		{
			if((e = e.forms) != null) for(i = 0; i < e.length; i++)
				if(ig_csom.IsIE) e[i].fireEvent("onsubmit"); else e[i].submit();
		}catch(ex){}
		try{if((e = document.activeElement) != null) e.fireEvent("onblur");}catch(ex){}
		try{__doPostBack(this.uniqueId, v);}catch(ex){}
	}
	//
	this.fireEvt = function(o, evtName, e)
	{
		var owner = o.owner;
		if(owner == null) owner = o;
		if(ig_csom.isEmpty(evtName)) return false;
		var evt = owner.Event;
		if(evt == null) evt = owner.Event = new ig_EventObject();
		evt.reset();
		if((evt.event = e) == null) ig_fireEvent(owner, evtName);
		else ig_fireEvent(owner, evtName, o, evt);
		owner.doPost = (evt.needPostBack == true) || (owner.autoPost && evt.cancelPostBack == false);
		return evt.cancel;
	}
	// swap 0 and i rows
	this.moveRow = function(i)
	{
		var e1 = this.rows[i], e0 = this.rows[0];
		var t1 = e1.firstChild, t0 = e0.firstChild;
		if(t1 == null || t0 == null) return;
		e0.removeChild(t0);
		e1.removeChild(t1);
		this.fixTD(t1, "", true);
		this.fixTD(t0, "0px", i + 1 < this.rows.length);
		e1.appendChild(t0);
		e0.appendChild(t1);
	}
	this.fixTD = function(e, v, c)
	{
		if(ig_csom.notEmpty(e.nodeName) && e.nodeName.toUpperCase() == "TD")
		{
			var s = e.style;
			if(e.id != null && s != null)
			{
				if(this.top) s.borderBottomWidth = v; else s.borderTopWidth = v;
				if(e.id != "edge") s.backgroundColor = c ? this.back : "";
			}
		}
		if((e = e.childNodes) != null) for(var i = 0; i < e.length; i++) this.fixTD(e[i], v, c);
	}
	this.butState = function(b, s)
	{
		var e, i = -1, bb = this.buttons;
		if(bb != null) bb = bb[b];
		if(s < 0) if(bb.state < 3) return; else s = 0;
		if(bb == null || bb.state == s) return;
		var timer = (s == 2) ? 2 : ((bb.state == 2) ? 1 : 0);
		bb.state = s;
		if(ig_csom.notEmpty(e = this.val(this.css, s))) if(bb.elem.className != e) bb.elem.className = e;
		if(ig_csom.isEmpty(s = bb.img[s])) s = bb.img[0];
		if(ig_csom.notEmpty(s)) for(i = 0; i < bb.elem.childNodes.length; i++)
		{
			e = bb.elem.childNodes[i];
			b = e.nodeName.toUpperCase();
			if(b == "IMG") if(e.src != s) e.src = s;
		}
		if(timer > 0) this.timer(this, timer == 1);
	}
	//0-out,1-move,2-down,4-up
	this.doBut = function(type, e, b)
	{
		ig_cancelEvent(e);
		if(this.hover != null && this.hover.state == 1) this.hover.setState(0, e);
		var but = 4;
		while(but-- > 0) if(this.buttons[but] == b) break;
		if(but < 0) return;
		//more button
		if(but > 1){this.scroll(but == 2); return;}
		if(type == 4) this.butP = -1;
		else if(type != 2 && e.button != 0 && this.butP < 0) return;
		if(!this.getEnabled() || b.state == 3) return;
		if(type == 0 && this.butL == 0) this.butP = -1;
		b = this.butP;
		if(type == 2)
		{
			if(b >= 0) this.butState(b, 0);
			this.butP = -2;
			if(e.button < 2)
			{
				this.butP = but;
				this.butL = e.button;
				this.butState(but, 2);
			}
			return;
		}
		if(e.button == 0 && b < -1) b = this.butP = -1;
		if(b >= 0 && e.button != this.butL && type == 1)
		{
			b = this.butP = -1;
			this.butState(but, 1);
			return;
		}
		if(b < -1 || (b >= 0 && b != but)) return;
		this.butState(but, (type == 0) ? 0 : ((b >= 0) ? 2 : 1));
	}
	this.scrolInit = function(e)
	{
		var w = -1, j = -1, i = this.Tabs.length;
		if(i < 2 || this.butP == null || (e != null && this.butP >= 0)) return false;
		var t = this.Tabs[0];
		if(e == "") if(this.scrolW_Vis == t.rect(this.scrolDiv)) return false;
		e = t.element;
		// find scroll elems
		var div, tbl, tds = null;
		while(j++ < 15 && w <= 0)
		{
			if(w < 0)
			{
				// table inside div
				if(e.tagName == "TABLE") tbl = e;
				if(e.tagName == "TR") tds = e.childNodes;
				if(e.tagName == "DIV")
				{
					//NS6
					if(t.rect(e, 1) != (w = t.rect(tbl, 1))) e.style.height = w;
					w = t.rect(this.scrolDiv = div = e);
				}
			}
			//IE-Mac
			else if((w = t.rect(e)) > 0)
			{
				div.style.width = w;
				if(t.rect(div, 1) != (j = t.rect(tbl, 1))) div.style.height = j;
			}
			if((e = e.parentNode) == null) return false;
		}
		if(tds == null || (this.scrolW_Vis == w && this.scrolW_All != null)) return false;
		var my, tail, last = true, iTD = tds.length, i0 = 3;
		while(--iTD > 2)
		{
			e = tds[iTD];
			if(e.tagName == "TD"){this.scrolEnd = e; break;}
		}
		j = 0;
		while(j-- > -2) if(tds[iTD + j] == this.buttons[3])
		{
			this.vis(this.buttons[3]);
			iTD += j;
		}
		if(iTD > 2) while(--i0 > 0) if(tds[i0 - 1] == this.buttons[2])
		{
			this.vis(this.buttons[2]);
			break;
		}
		if(iTD - i0 < 3) return false;
		this.vis(e);
		var old0 = this.scrol0;
		// show hidden tabs
		for(j = i; j > 0;) this.show(this.Tabs[--j], true);
		if(this.scrolW_All == null) old0 = -1;
		this.scrolW_Vis = w;
		this.scrolW_All = t.rect(tbl);
		w = 0;
		t = null;
		while(iTD-- > i0)
		{
			if(t == null && i > 0)
			{
				while(i-- > 0)
				{
					if(old0 < 0) this.scrol0 = i;
					t = this.Tabs[i];
					t.scrolW = 0;
					t.scrolX = -1;
					if(t.visible) break;
				}
				if(i < 0) break;
				j = 0;
				tail = true;
				t.scrolTDs = new Array();
			}
			e = tds[iTD];
			if(e.tagName != "TD") continue;
			if(my = t.isMy(e)) tail = false;
			// go to next tab
			else if(!tail && i > 0){last = false; t = null; iTD++; continue;}
			if(my || tail || i == 0)
			{
				if(t.scrolX < 0) t.scrolX = e.offsetLeft;
				j = e.offsetWidth;
				// elem to scroll (hide/show)
				t.scrolTDs[t.scrolTDs.length] = e;
				t.scrolW += j;
				w += j;
				// width from left of t to the last tab
				t.scrolW_Right = last ? 0 : (this.scrolToLast ? 9999 : w);
			}
		}
		for(i = j = 0; j < this.Tabs.length; j++)
		{
			t = this.Tabs[j];
			if(t.scrolW > 0)
			{
				if(old0 > 0 && j < old0) this.show(t, false);
				// index within visible tabs
				t.scrolI = i++;
			}
		}
		this.vis(this.scrolEnd, "");
		this.scrolFix();
		return true;
	}
	this.timer = function(tab, end)
	{
		if(tab != null && tab.Tabs != null)
		{
			if(ig_csom.tab_f != null) window.clearInterval(ig_csom.tab_f);
			ig_csom.tab_f = end ? (tab = null) : window.setInterval(tab.timer, this.delay);
			ig_csom.tab_o = tab;
		}
		else tab = ig_csom.tab_o;
		if(tab != null) tab.scroll();
	}
	// public: show selected tab
	this.ensureVisible = function()
	{
		var i0 = this.selected, i = this.Tabs.length;
		if(this.scrol0 == null || i0 < 0) return;
		while(this.scrol0 > i0 && i-- > 0) this.scroll(true);
		if(this.scrol0 >= i0) return;
		var t = this.Tabs[i0];
		var iR = t.scrolX + t.scrolW - this.scrolW_Vis;
		while(this.scrol0 < i0 && i-- > 0)
			if(iR > this.Tabs[this.scrol0].scrolX || t.scrolHidden == true) this.scroll(false);
			else break;
	}
	// public: scroll tabs to left or right
	this.scroll = function(left)
	{
		if(left == null) left = this.butP == 0;
		if(this.scrolW_All == null) if(!this.scrolInit()) return;
		var ii = this.Tabs.length - 1, j = 0, i = this.scrol0;
		var t = this.Tabs[i];
		while(true)
		{
			i += left ? -1 : 1;
			if(i < 0 || i > ii) return;
			if(this.Tabs[i].scrolW > 0) break;
		}
		this.scrol0 = i;
		this.show(left ? this.Tabs[i] : t, left);
		this.scrolFix();
	}
	this.show = function(t, vis)
	{
		if(t.scrolW < 1 || vis == (t.scrolHidden != true)) return;
		for(var i = 0; i < t.scrolTDs.length; i++) this.vis(t.scrolTDs[i], vis ? "" : null);
		t.scrolHidden = !vis;
	}
	// show/hide/enable buttons, hide right tabs
	this.scrolFix = function()
	{
		var t = this.Tabs[this.scrol0];
		if(t == null) return;
		var e, w0 = 0, w = 0, i = t.index, more = t.scrolI > 0;
		this.vis(e = this.buttons[2], more ? "" : null);
		if(more) w += (w0 = t.rect(e));
		this.butState(0, (more && this.enabled) ? -1 : 3);
		more = t.scrolW_Right + w0 > this.scrolW_Vis;
		this.butState(1, (more && this.enabled) ? -1 : 3);
		e = this.buttons[3];
		var vis = more && this.scrolHide;
		if(vis) w += t.rect(e);
		more = true;//not 1st
		if(this.scrolHide) while(i < this.Tabs.length)
		{
			t = this.Tabs[i++];
			if((w0 = t.scrolW) < 1) continue;
			w += w0;
			this.show(t, more || w <= this.scrolW_Vis);
			more = false;
		}
		if(vis) for(i = this.Tabs.length; --i > 0;) if(this.Tabs[i].scrolW > 0)
		{if(this.Tabs[i].scrolHidden != true) vis = false; break;}
		this.vis(e, vis ? "" : null);
	}
}
// Tab
function igtab_newT(id, prop, i, css0, own)
{
	this.owner = own;
	var o = igtab_getElementById(id + "_div" + i);
	this.elemDiv = (o == null) ? own.elemEmpty : o;
	this.elemIframe = igtab_getElementById(id + "_frame" + i);
	this.index = i;
	this.visible = ig_csom.notEmpty(own.val(prop, 0));
	this.enabled = ig_csom.notEmpty(own.val(prop, 1));
	this.state = this.enabled ? 0 : 3;
	// css
	// 2 - style flags: 0..15 (1-defStyle, 2-hovStyle, 4-selStyle, 8-disStyle)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -