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

📄 tabs.js

📁 持久层hibernate技术使用的一个例子
💻 JS
📖 第 1 页 / 共 3 页
字号:
 *	HTML <code>class</code> attribute value that includes <code>
 *	className</code> using a breadth-first algorithm.
 *	
 *	@param Element target
 *	@param string className
 *	@returns Element
 */
org.ditchnet.dom.DomUtils.getFirstDescendantByClassNameBreadthFirst = function (
																target,
																className) {
	var result;
	with (org.ditchnet.dom.DomUtils) {
		if (result = getFirstChildByClassName(target,className)) {
			return result;
		}
		for (var i = 0; i < target.childNodes.length; i++) {
			result = getFirstDescendantByClassNameBreadthFirst(
										target.childNodes.item(i),
										className );
			if (result) {
				return result;
			}
		}
		return null;
	}
};

/**
 *	Retreives <code>target</code>'s first descendant element with an
 *	HTML <code>class</code> attribute value that includes <code>
 *	className</code> using a depth-first algorithm.
 *	
 *	@param Element target
 *	@param string className
 *	@returns Element
 */
org.ditchnet.dom.DomUtils.getFirstDescendantByClassNameDepthFirst = function (
																target,
																className) {
	var child;
	var result;
	with (org.ditchnet.dom.DomUtils) {
		for (var i = 0; i < target.childNodes.length; i++) {
			child = target.childNodes.item(i);
			if (isElementNode(child) && hasClassName(child,className)) {
				return child;
			}
			result = getFirstDescendantByClassNameDepthFirst(
													target.childNodes.item(i),
													className );
			if (result) {
				return result;
			}
		}
		return null;
	}
};

/**
 *	Returns all descendant elements of <code>target</code> with HTML <code>
 *	class</code> attribute values that contain <code>className</code>
 *	as an Array. NOTE that unlike the
 *	algorithms specified in the DOM spec, a <code>NodeList</code> is NOT
 *	returned. This method searched for all descendants of <code>target
 *	</code> meeting the criteria using a breadth-first algorithm.
 *
 *	@param Element target
 *	@param string className
 *	@returns Element
 */
org.ditchnet.dom.DomUtils.getDescendantsByClassName = function (target,className) {
	var result = [];
	with (org.ditchnet.dom.DomUtils) {
		result.addAll(getChildrenByClassName(target,className));
		for (var i = 0; i < target.childNodes.length; i++) {
			result.addAll(getDescendantsByClassName(
											target.childNodes.item(i),
											className));
		}
		return result;
	}
};

/**
 *	@param MouseEvent evt
 *	@returns void
 */
org.ditchnet.jsp.TabUtils.tabClicked = function (evt) {
	var eventSource;
	with (org.ditchnet) {
		evt = new event.Event(evt);
		eventSource = evt.getSource();
		eventSource = dom.DomUtils.getFirstAncestorOrSelfByClassName(
												eventSource,
												jsp.TabUtils.TAB_CLASS_NAME );
		jsp.TabUtils.switchTab(eventSource);
		evt.consume();
	}
};

/**
 *	@param HTMLElement eventSource
 *	@returns void
 */
org.ditchnet.jsp.TabUtils.switchTab = function (eventSource) {
	with (org.ditchnet.jsp.TabUtils) {
		findTabElements(eventSource);
		selectedIndex = determineSelectedIndex(eventSource);
		toggleTabVisibility(selectedIndex);
		setTabCookie(selectedIndex);
	}
};

/**
 *	@param number selectedIndex
 *	@returns void
 */
org.ditchnet.jsp.TabUtils.setTabCookie = function (selectedIndex) {
	with (org.ditchnet) {
		var name  = "org.ditchnet.jsp.tabs:"+jsp.TabUtils.tabContainer.id;
		var value = selectedIndex;
		var c = new util.Cookie(name,value);
		util.Cookie.addPageCookie(c);
	}
};

/**
 *	@param HTMLElement eventSource
 *	@returns void
 */
org.ditchnet.jsp.TabUtils.findTabElements = function (eventSource) {
	with (org.ditchnet) {
		jsp.TabUtils.tab		  = eventSource;
		jsp.TabUtils.tabContainer = dom.DomUtils.getFirstAncestorByClassName(
										eventSource,
										jsp.TabUtils.TAB_CONTAINER_CLASS_NAME );
		jsp.TabUtils.tabWrap 	  	= dom.DomUtils.getFirstChildByClassName(
										jsp.TabUtils.tabContainer,
										jsp.TabUtils.TAB_WRAP_CLASS_NAME );
		jsp.TabUtils.tabs 		  = dom.DomUtils.getChildrenByClassName(
										jsp.TabUtils.tabWrap,
										jsp.TabUtils.TAB_CLASS_NAME );
		jsp.TabUtils.tabPaneWrap  = dom.DomUtils.getFirstChildByClassName(
										jsp.TabUtils.tabContainer,
										jsp.TabUtils.TAB_PANE_WRAP_CLASS_NAME );
		jsp.TabUtils.tabPanes  	  = dom.DomUtils.getChildrenByClassName(
										jsp.TabUtils.tabPaneWrap,
										jsp.TabUtils.TAB_PANE_CLASS_NAME );
	}
};

/**
 *	@param HTMLElement eventSource
 *	@returns number
 */
org.ditchnet.jsp.TabUtils.determineSelectedIndex = function (eventSource) {
	with (org.ditchnet.jsp.TabUtils) {
		for (var i = 0; i < tabs.length; i++) {
			if (tabs[i] == eventSource) {
				return i;
			}
		}
	}
	//throw new Error("Should not reach here: Did not find tab selectedIndex");
};

/**
 *	@param number selectedIndex
 *	@returns void
 */
org.ditchnet.jsp.TabUtils.toggleTabVisibility = function (selectedIndex) {
	with (org.ditchnet) {
		for (var i = 0; i < jsp.TabUtils.tabPanes.length; i++) {
			var tabPane = jsp.TabUtils.tabPanes[i];
			if (i == selectedIndex) {
				dom.DomUtils.show(tabPane);
				dom.DomUtils.setClassNameAsFocused(jsp.TabUtils.tabs[i]);
			} else {
				dom.DomUtils.hide(tabPane);
				dom.DomUtils.setClassNameAsUnFocused(jsp.TabUtils.tabs[i]);
			}
		}
	}
};

/**
 *	@param Event evt
 *	@param string tabContainerId
 *	@param number selectedIndex
 *	@returns void
 */
org.ditchnet.jsp.TabUtils.tabLinkClicked = function (evt,selectedTabPaneId) {
	var tabContainer,selectedTabPane,tabWrap,tabs,tabPaneWrap,tabPanes,
		selectedIndex;
	with (org.ditchnet) {
		evt = new event.Event(evt);
		selectedTabPane = document.getElementById(selectedTabPaneId);
		tabContainer    = dom.DomUtils.getFirstAncestorByClassName(
										selectedTabPane,
										jsp.TabUtils.TAB_CONTAINER_CLASS_NAME );
		tabWrap			= dom.DomUtils.getFirstChildByClassName(
										tabContainer,
										jsp.TabUtils.TAB_WRAP_CLASS_NAME );
		tabs			= dom.DomUtils.getChildrenByClassName(
										tabWrap,
										jsp.TabUtils.TAB_CLASS_NAME );
		tabPaneWrap		= dom.DomUtils.getFirstAncestorByClassName(
										selectedTabPane,
										jsp.TabUtils.TAB_PANE_WRAP_CLASS_NAME );
		tabPanes		= dom.DomUtils.getChildrenByClassName(
										tabPaneWrap,
										jsp.TabUtils.TAB_PANE_CLASS_NAME );
		for (var i = 0; i < tabPanes.length; i++) {
			if (tabPanes[i] == selectedTabPane) {
				selectedIndex = i;
				break;
			}
		}
		jsp.TabUtils.switchTab(tabs[selectedIndex]);
		window.scrollTo(0,0);
		evt.consume();
	}
};

/**
 *	@param Event evt
 *	@param string tabContainerId
 *	@returns void
 */
org.ditchnet.jsp.TabUtils.prevTabButtonClicked = function (evt,tabContainerId) {
	org.ditchnet.jsp.TabUtils.tabButtonClicked(evt,tabContainerId,true);
};

/**
 *	@param Event evt
 *	@param string tabContainerId
 *	@returns void
 */
org.ditchnet.jsp.TabUtils.nextTabButtonClicked = function (evt,tabContainerId) {
	org.ditchnet.jsp.TabUtils.tabButtonClicked(evt,tabContainerId,false);
};

/**
 *	@param Event evt
 *	@param string tabContainerId
 *	@returns void
 */
org.ditchnet.jsp.TabUtils.tabButtonClicked = function (evt,tabContainerId,isPrev) {
	var tabContainer,tabWrap,tabs,selectedIndex;
	with (org.ditchnet) {
		evt = new event.Event(evt);
		tabContainer = document.getElementById(tabContainerId);
		tabWrap 	 = dom.DomUtils.getFirstChildByClassName(
											tabContainer,
											jsp.TabUtils.TAB_WRAP_CLASS_NAME );
		tabs		 = dom.DomUtils.getChildrenByClassName(
											tabWrap,
											jsp.TabUtils.TAB_CLASS_NAME );
		for (var i = 0; i < tabs.length; i++) {
			if (dom.DomUtils.hasClassName(tabs[i],dom.DomUtils.FOCUSED_CLASS_NAME)) {
				selectedIndex = (isPrev) ? i-1 : i+1;
				selectedIndex = (selectedIndex >= tabs.length) ? 0 : 
								(0 > selectedIndex) ? tabs.length - 1  : 
								selectedIndex;
				break;
			}
		}
		jsp.TabUtils.switchTab(tabs[selectedIndex]);
		evt.consume();
	}
};

/**
 *	@constructor
 *	@param HTMLElement
 */
org.ditchnet.jsp.TabEvent = function (source) {
	this._source = source;
	with (org.ditchnet.jsp.TabUtils) {
		this._tabContainer = tabContainer;
		this._selectedIndex = selectedIndex;
		this._tabPane = tabPanes[selectedIndex];
	}
};

/**	@return HTMLElement */
org.ditchnet.jsp.TabEvent.prototype.getSource = function () {
	return this._source;
};
/**	@return number */
org.ditchnet.jsp.TabEvent.prototype.getSelectedIndex = function () {
	return this._selectedIndex;
};
/**	@return HTMLElement */
org.ditchnet.jsp.TabEvent.prototype.getTab = function () {
	return this._source;
};
/**	@return HTMLElement */
org.ditchnet.jsp.TabEvent.prototype.getTabContainer = function () {
	return this._tabContainer;
};
/**	@return HTMLElement */
org.ditchnet.jsp.TabEvent.prototype.getTabPane = function () {
	return this._tabPane;
};
/**	@return string */
org.ditchnet.jsp.TabEvent.prototype.toString = function () {
	return "[ org.ditchnet.jsp.TabEvent object ]";
};

/**
 *	@constructor
 *	@param MouseEvent evt
 */
org.ditchnet.event.Event = function (evt) {
	this._evt 	 = evt ? evt : window.event;
	this._source = this._evt.currentTarget ? 
				   this._evt.currentTarget : this._evt.srcElement;
};

/**
 *	@returns Element
 */
org.ditchnet.event.Event.prototype.getSource = function () {
	return this._source;
};

/**
 *	@returns void
 */
org.ditchnet.event.Event.prototype.consume = function () {
	if (this._evt.stopPropagation) {
		this._evt.stopPropagation();
		this._evt.preventDefault();
	} else if (this._evt.cancelBubble) {
		this._evt.cancelBubble = true;
		this._evt.returnValue  = false;
	}
};







/**
 *	<p>Bean that represents individual Cookie objects, packaging their 
 *	attributes into a convenient API that can more easily be manipulated and
 *	set.</p><p>Also contains 2 static convenience methods for setting and
 *	the cookies for the current page.
 *	@author		Todd Ditchendorf
 *	@constructor	Accepts initial values for the <code>name</code> and 
 *				<code>value</code> attribute values.
 *	@param	String	name		Initial <code>name</code> attribute value.	
 *	@param	String	value	Initial <code>value</code> attribute value.	
 */	
org.ditchnet.util.Cookie = function (name,value) {
	this._name;
	this._value;
	this._path;
	this._secure;
	this._domain;
	this._expires;
	if (name) {
		this.setName(name);
	}
	if (value) {
		this.setValue(value);
	}
};

// Static attributes
org.ditchnet.util.Cookie.EQUALS 			= "=";
org.ditchnet.util.Cookie.DELIM 				= "; ";
org.ditchnet.util.Cookie.PATH 				= "path";
org.ditchnet.util.Cookie.SECURE 			= "secure";
org.ditchnet.util.Cookie.DOMAIN 			= "domain";
org.ditchnet.util.Cookie.EXPIRES 			= "expires";
org.ditchnet.util.Cookie.SUB_VALUE_DELIM 	= ":"

/**
 *	Static convenience method that sets the given cookie for the current page.
 *	@param	Cookie	c	<code>Cookie</code> object to be set.
 *	@returns	void
 */
org.ditchnet.util.Cookie.addPageCookie = function (c) {
/*	if (!(c instanceof org.ditchnet.util.Cookie)) {
		throw new Error("IllegalArgumentException: Cookie.set() accepts only" +
			" one parameter of type Cookie");
	}*/
	document.cookie = c.toCookieString();
};

/**
 *	Static convenience method that returns all the <code>document.cookie</code>
 *	String for the current page.
 *	@returns	String
 */
org.ditchnet.util.Cookie.getPageCookieString = function () {
	return document.cookie;
};

/**
 *	Static convenience method that checks the <code>document.cookie</code>
 *	String for the current page to see if the give <code>Cookie</code> exists.
 *	@param	Cookie	c
 *	@returns	boolean
 */
org.ditchnet.util.Cookie.pageHasCookieWithNameAndValue = function (c) {
	var s = c.toNameValueString();
	return (Cookie.get().indexOf(s) > -1);
};

org.ditchnet.util.Cookie.pageHasCookieWithName = function (c) {
	var s = c.getName();
	return (Cookie.get().indexOf(s) > -1);
};

/**
 *	Returns a String representation of this <code>Cookie</cookie> in the 

⌨️ 快捷键说明

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