/********* tab *************/ var configItems; Tab = Control.subClass({ items: true, init: function(config) { config.css = util.combine(config.css, { headerArea: null, bodyArea: null, itemHeader: null, itemBody: null, selectedItemHeader: "tab-A-item-selectedHeader", itemText: null, itemImage: null, itemIcon: null, itemCloseBtn: null }); this.selected = null; Control.call(this, config); }, getContainerTemplate: function() { var template = this.getTemplate("Tab", "container"); return template; }, onCreateContainer: function(container) { container.headerOuter = $("#headerOuter", container); var header = container.header = $("#headerArea", container); this.addClass(header, this.config.css.headerArea); header.data("marginLeft", 0); header.goLeft = $("#goLeft", container); header.goRight = $("#goRight", container); header.goLeft.click(function() { /* let headerParentArea = header.parent(); let headerParentArea_left = headerParentArea[0].offsetLeft; let headerParentArea_Width = headerParentArea[0].clientWidth; */ let headerArea_left = header[0].offsetLeft; //let headerArea_Width = header[0].clientWidth; if (headerArea_left < 0) { var marginLeft = header.data("marginLeft"); marginLeft = marginLeft + 120; header.css({"margin-left": marginLeft + "px"}); header.data("marginLeft", marginLeft); } }); header.goRight.click(function() { let headerParentArea = header.parent(); let headerParentArea_left = headerParentArea[0].offsetLeft; let headerParentArea_Width = headerParentArea[0].clientWidth; let headerArea_left = header[0].offsetLeft; let headerArea_Width = header[0].clientWidth; if ((headerArea_left + headerArea_Width) > (headerParentArea_left + headerParentArea_Width) ) { var marginLeft = header.data("marginLeft"); marginLeft = marginLeft - 120; header.css({"margin-left": marginLeft + "px"}); header.data("marginLeft", marginLeft); } }); var body = container.body = $("#bodyArea", container); this.addClass(body, this.config.css.bodyArea); }, createItem: function(container, option) { var me = this, config = this.config; //0. item var item = { subItems: [] }; item.id = option.id; //1. item header var itemHeader = item.itemHeader = $(this.getTemplate("Tab", "item_header")); this.addClass(itemHeader, config.css.itemHeader); /* itemHeader.click(function() { me.setItemSelected(item); }); */ itemHeader.unbind("mousedown").bind("contextmenu", function (e) { e.preventDefault(); return false; }); itemHeader.unbind("mousedown").bind("mousedown", function (event) { if (event.which == 3) { //alert("我单击了右键"); //选中界面 me.setItemSelected(item); //右键显示小菜单 me.shouTabMenu(item); }else if(event.which == 1){ //alert("我单击了左键"); me.setItemSelected(item); } }); //2. text var text = itemHeader.text = $("#headerText", itemHeader); this.setText(text, option.text || option.title, config.css.itemText); //2. image and icon if (option.icon) { var icon = itemHeader.image = $("#headerIcon", itemHeader); this.setIcon(icon, option.icon, config.css.itemIcon); itemHeader.prepend(icon); } //3. item close button var closeBtn = itemHeader.closeBtn = $("#closeBtn", itemHeader); this.addClass(closeBtn, config.css.itemCloseBtn); closeBtn.click(function() { me.removeItem(item); //this.deleteItem(item); /* let container = item.itemHeader.parent(); item.itemHeader.remove(); let children = container.children(); let w_ = children[0] ? children[0].offsetWidth + 5 : 0; let width_ = children.length * w_; container.css({"width": width_ + "px"}); //内容的最左,最右 //边框的最左,最右 let container_left = container[0].offsetLeft; let container_right = container_left + width_; let range = container.parent() let range_left = range[0].offsetLeft; let range_right = range_left + range[0].clientWidth; //判断内容的最右侧是否<右边框 if (container_right < (range_right - 24)) {//小于 //判断内容最左侧是否<左边框 if (container_left < 0) {//小于 //内容向右移动一格 var marginLeft = container.data("marginLeft"); marginLeft = marginLeft + 120; container.css({"margin-left": marginLeft + "px"}); container.data("marginLeft", marginLeft); } } item.itemBody.remove(); for (var i = 0; i < configItems.items.length; i++) { var itemA = configItems.items[i]; if (itemA.id == item.id) { if (i == 0 && i < configItems.items.length) { configItems.setItemSelected(configItems.items[i+1]) } else if (i != 0) { configItems.setItemSelected(configItems.items[i-1]) } configItems.items.splice(i, 1); if (configItems.items.length == 0) { $("#firstPage").css('display','block'); } } } */ }); //4. body if (option.url) { var itemBody = item.itemBody = $(this.getTemplate("Tab", "item_iframeBody")); this.addClass(itemBody, config.css.itemBody); itemBody.attr("name", option.id); itemBody[0].style.width = "100%"; itemBody[0].style["background-color"] = "#fff"; itemBody[0].style["z-index"] = 5; itemBody[0].style.position = "absolute"; var bodyFrame = itemBody.bodyFrame = $("#bodyFrame", itemBody); util.pageTo(bodyFrame, option.url); } else if (option.element) { var itemBody = item.itemBody = $(this.getTemplate("Tab", "item_divBody")); this.addClass(itemBody, config.css.itemBody); itemBody.append(option.element); } else if (option.contentText) { var itemBody = item.itemBody = $(this.getTemplate("Tab", "item_divBody")); this.addClass(itemBody, config.css.itemBody); itemBody.html(option.text || option.title); } else { var itemBody = item.itemBody = $(this.getTemplate("Tab", "item_divBody")); this.addClass(itemBody, config.css.itemBody); } return item; }, createSubItem: function(option) { var item = this.selected; if (!item) { return; } var subItem = {}; /* var itemBody = item.itemBody = $(this.getTemplate("Tab", "item_iframeBody")); this.addClass(itemBody, config.css.itemBody); var bodyFrame = itemBody.bodyFrame = $("#bodyFrame", itemBody); pageTo(bodyFrame, option.url); */ var subbody = subItem.body = $(this.getTemplate("Tab", "item_iframeSubbody")); // this.addClass(body, config.css.itemBody); var subbodyFrame = subbody.bodyFrame = $("#bodyFrame", subbody); util.pageTo(subbodyFrame, option.url); item.itemBody.append(subbody); subbodyFrame.animate({"margin-left": 0}); item.subItems.push(subItem); }, showSubItem: function(option) { this.createSubItem(option); }, deleteSubItem: function() { var item = this.selected; if (!item) { return; } var subItems = item.subItems; if (!subItems.length) { return; } var subItem = subItems[subItems.length - 1]; subItem.body.animate({"margin-left": "-100%"}, { complete: function() { subItem.body.remove(); subItems.splice(subItems.length - 1, 1); } }); }, hideSubItem: function() { this.deleteSubItem(); }, attachItem: function(container, item) { //1.1 attach header container.header.append(item.itemHeader); let w_ = item.itemHeader[0].offsetWidth + 5; let children = container.header.children(); let width_ = children.length * w_; container.header.css({"width": width_ + "px"}); container.body.append(item.itemBody); //1.2 attach body // var overflow = container.header.width() > container.headerOuter.width(); // $.fm.setVisible(container.header.goLeft, overflow); // $.fm.setVisible(container.header.goRight, overflow); }, deleteItem: function(item) { item.header.remove(); item.body.remove(); }, showItem: function(option, isRefresh) { //1. get item if (!option.id) { option.id = this.createSequenceValue("Tab"); } var item = this.getItemBy("id", option.id); if (!item) { item = this.doAddItem(this, this.container, option); } //2. select this.setItemSelected(item, isRefresh); }, open: function(option, isRefresh) { let me = this; configItems = this; this.showItem(option, isRefresh); if (configItems.container.body[0].children.length > 1) { $("#firstPage").css('display','none'); } }, setShowListener: function(id, listener) { var item = this.getItemBy("id", id); if (!item) { return; } item.onShow = listener; }, shouTabMenu: function(item) { var me = this; var isF = false; var menu_this_ = $(".tab-A-item_menu", $("#content")); if (menu_this_) { menu_this_.remove(); } //创建右键菜单并设置显示位置 var item_menu = item.item_menu = $(this.getTemplate("Tab", "item_menu")); var menu_this = $("#menu_this", $(item_menu)); var menu_left = $("#menu_left", $(item_menu)); var menu_right = $("#menu_right", $(item_menu)); if(item.itemHeader.prevAll().length < 1) { // $(menu_left).empty(); $(menu_left).hide() } if(item.itemHeader.nextAll().length < 1) { // $(menu_right).empty(); $(menu_right).hide(); } //获取当前元素 var this_sub = item.itemHeader[0]; menu_this.click(function() { me.removeItem(item); item_menu.remove(); }); //获取同级之前的元素 menu_left.click(function() { me.removeItemLeft(item); item_menu.remove(); }); //获取同级之后的元素 menu_right.click(function() { me.removeItemRight(item); item_menu.remove(); }); var h_ = this_sub.offsetHeight; var w_ = this_sub.offsetWidth; var top_ = this_sub.offsetTop + h_; var left_ = this_sub.offsetLeft + w_; item_menu.css('position','absolute'); item_menu.css('top', top_ + "px"); item_menu.css('left', left_ + "px"); item_menu.css('z-index','100'); $("#content").append(item_menu); setTimeout(function() { if(!isF) { item_menu.remove(); } },"5000"); }, removeItem: function(item) { let container = item.itemHeader.parent(); item.itemHeader.remove(); let children = container.children(); let w_ = children[0] ? children[0].offsetWidth + 5 : 0; let width_ = children.length * w_; container.css({"width": width_ + "px"}); //内容的最左,最右 //边框的最左,最右 let container_left = container[0].offsetLeft; let container_right = container_left + width_; let range = container.parent() let range_left = range[0].offsetLeft; let range_right = range_left + range[0].clientWidth; //判断内容的最右侧是否<右边框 if (container_right < (range_right - 24)) {//小于 //判断内容最左侧是否<左边框 if (container_left < 0) {//小于 //内容向右移动一格 var marginLeft = container.data("marginLeft"); marginLeft = marginLeft + 120; container.css({"margin-left": marginLeft + "px"}); container.data("marginLeft", marginLeft); } } item.itemBody.remove(); for (var i = 0; i < configItems.items.length; i++) { var itemA = configItems.items[i]; if (itemA.id == item.id) { if (i == 0 && i < configItems.items.length) { configItems.setItemSelected(configItems.items[i+1]) } else if (i != 0) { configItems.setItemSelected(configItems.items[i-1]) } configItems.items.splice(i, 1); if (configItems.items.length == 0) { $("#firstPage").css('display','block'); } } } }, removeItemLeft: function(item) { this.setItemSelected(item); var prevAll_ = item.itemHeader.prevAll(); var prevBodyAll_ = item.itemBody.prevAll(); prevAll_.remove(); prevBodyAll_.remove(); configItems.items.splice(0, prevAll_.length); }, removeItemRight: function(item) { this.setItemSelected(item); var prevAll_ = item.itemHeader.prevAll(); var nextAll_ = item.itemHeader.nextAll(); var nextBodyAll_ = item.itemBody.nextAll(); nextAll_.remove(); nextBodyAll_.remove(); configItems.items.splice(prevAll_.length+1, nextAll_.length); }, removeItemOther: function(id) { //获取当前 var item = this.getItemBy("id", id); //关闭左侧 var prevAll_ = item.itemHeader.prevAll(); var prevBodyAll_ = item.itemBody.prevAll(); prevAll_.remove(); prevBodyAll_.remove(); configItems.items.splice(0, prevAll_.length); //关闭右侧 var nextAll_ = item.itemHeader.nextAll(); var nextBodyAll_ = item.itemBody.nextAll(); nextAll_.remove(); nextBodyAll_.remove(); configItems.items.splice(1, nextAll_.length); }, setItemSelected: function(item, isRefresh) { var old = this.selected; if (item == old) { if (isRefresh) { item.itemBody.bodyFrame[0].contentWindow.location.reload(true); } return; } if (old) { this.changeItemCss(old, "item-unselect"); // old.itemBody.hide(); old.itemBody[0].style["z-index"] = 1; } if (item) { this.selected = item; this.changeItemCss(item, "item-select"); if (item.onShow) { item.onShow(item); } // item.itemBody.show(); item.itemBody[0].style["z-index"] = 5; if (isRefresh) { item.itemBody.bodyFrame[0].contentWindow.location.reload(true); } } }, changeItemCss: function(item, event) { var config = this.config, header = item.itemHeader; if ("item-select" == event) { this.removeClass(header, config.css.itemHeader); this.addClass(header, config.css.selectedItemHeader); } else if ("item-unselect" == event) { this.removeClass(header, config.css.selectedItemHeader); this.addClass(header, config.css.itemHeader); } } }); //************************************* Tab_TemplateA = {}; Tab_TemplateB = {}; Tab_TemplateA.container = [ '