tting) {//检测选项卡是否存在
123 var divs = _tabcontent.options.selector.children("div"), divdata, hasdata;
124 hasdata = { selector: undefined, has: false };
125 $.each(divs, function () {
126 divdata = $(this).data("data");
127 if (!divdata) return true;
128 if (divdata.bindcode === setting.bindcode) {
129 hasdata = { selector: $(this), has: true };
130 return false;
131 };
132 });
133 return hasdata;
134 };
135 };
136
137 var droplist = function () {
138 this.options = {
139 selector: undefined,
140 ulpanel: undefined
141 };
142
143 this.init = function (panel) {
144 var li = $('<li class="dropdown pull-right"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><b class="caret"></b></a><ul class="dropdown-menu"></ul></li>');
145 this.options.selector = li.css({ "visibility": "hidden" });
146 this.options.ulpanel = li.children("ul");
147 this.options.selector.appendTo(panel);
148 };
149
150 this.addDropItem = function () {
151 additem(this.options.selector, this.options.ulpanel);
152 };
153
154 function additem(li, ul) {
155 var item = options.selector.children("li").not(li).last();
156 li.css({ "visibility": "visible" });
157 if (item.length <= 0) return;
158 item.find("span.close").hide();
159 ul.append(item);
160 item.one("click", function () {
161 itemtarget(this, li, ul);
162 });
163 };
164
165 function itemtarget(target, selector, ulpanel) {
166 var item = options.selector.children("li").not(selector).last();
167 $(target).find("span.close").show();
168 $(target).prependTo(options.selector);
169 if (item.length <= 0) return;
170 if (selector.position().top > options.selector.position().top) {
171 item.find("span.close").hide();
172 ulpanel.append(item);
173 };
174 item.one("click", function () {
175 itemtarget(this, selector, ulpanel);
176 });
177 };
178 };
179
180 function init(setting) {
181 $.extend(options, setting);
182 if (!options.selector) {
183 return;
184 };
185 if (options.selector[0].tagName.toLowerCase() != "ul") {
186 var selector = $('<ul class="nav nav-tabs pagetabs"></ul>').appendTo(options.selector);
187 options.selector = selector;
188 };
189 if (!_drop) {
190 _drop = new droplist();
191 };
192 _drop.init(options.selector);
193
194 if (!_tabcontent) {
195 _tabcontent = new tabcontent();
196 };
197 _tabcontent.init();
198 if (!_newtab) {
199 _newtab = new tab();
200 };
201 };
202
203 function addtab(setting) {
204 if (!_newtab) {
205 _newtab = new tab();
206 };
207 _newtab.addtab(setting);
208 if (!_tabcontent) {
209 _tabcontent = new tabcontent();
210 };
211 _tabcontent.addContent(setting);
212 options.selector.find('li>a').filter('[href=#page' + setting.bindcode + ']').tab("show");
213 };
214
215 return {
216 init: function (setting) {
217 init(setting);
218 }, addtab: function (setting) {
219 addtab(setting);
220 }
221 };
222 })(jQuery);
View Code
效果如下:
|