//collapsibleList 折叠列表
import web.layout.behavior.expandableList;

namespace web.layout.behavior;

var expandableList = expandableList; 

namespace collapsibleList { 
	onAttach = expandableList.onAttach;
	onMouseDown = expandableList.onMouseDown;
	onMouseDblClick = expandableList.onMouseDblClick;
	onActiveChild = expandableList.onActiveChild;
	onKeyDown = expandableList.onKeyDown;

	setCurrentItem = function( ltOwner, ltTarget )  {
		// get previously expanded ltTarget:
		var prev = ltOwner.querySelector(":root > :expanded");
		var prevCurrent = ltOwner.querySelector(":root > :current");
		
		if(prevCurrent != ltTarget && prevCurrent)
			prevCurrent.modifyState(0,  0x20/*_HL_STATE_CURRENT*/);
		
		if( prev == ltTarget ) {
			prev.modifyState(0,  0x200/*_HL_STATE_EXPANDED*/); 
			prev.postEvent(0x90/*_HL_ELEMENT_COLLAPSED*/,0, prev); // source here is old collapsed tab itself
		}
		else {
			if( prev ) {
  				prev.modifyState(0,  0x200/*_HL_STATE_EXPANDED*/); // collapse old one
  				prev.postEvent(0x90/*_HL_ELEMENT_COLLAPSED*/,0, prev); // source here is old collapsed tab itself
			}
			ltTarget.modifyState( 0x20/*_HL_STATE_CURRENT*/ |  0x200/*_HL_STATE_EXPANDED*/); // set new expanded.
			ltTarget.postEvent(0x91/*_HL_ELEMENT_EXPANDED*/,0, item);  // source here is new expanded tab itself
		}
		ltTarget.scrollToView();
	} 
}