You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
3.6 KiB
146 lines
3.6 KiB
/*
|
|
* author: lzy-aui
|
|
* tab.js
|
|
* http://azenui.com/
|
|
* http://a-ui.cn/
|
|
* http://588sucai.com/
|
|
*/
|
|
!function(window) {
|
|
"use strict";
|
|
|
|
var doc = window.document
|
|
, ydui = {};
|
|
|
|
$(window).on('load', function() {});
|
|
|
|
var util = ydui.util = {
|
|
|
|
parseOptions: function(string) {},
|
|
|
|
pageScroll: function() {}(),
|
|
|
|
localStorage: function() {}(),
|
|
|
|
sessionStorage: function() {}(),
|
|
|
|
serialize: function(value) {},
|
|
|
|
deserialize: function(value) {}
|
|
};
|
|
|
|
function storage(ls) {}
|
|
|
|
$.fn.emulateTransitionEnd = function(duration) {}
|
|
;
|
|
|
|
if (typeof define === 'function') {
|
|
define(ydui);
|
|
} else {
|
|
window.YDUI = ydui;
|
|
}
|
|
|
|
}(window);
|
|
|
|
!function(window) {
|
|
"use strict";
|
|
|
|
function Tab(element, options) {
|
|
this.$element = $(element);
|
|
this.options = $.extend({}, Tab.DEFAULTS, options || {});
|
|
this.init();
|
|
this.bindEvent();
|
|
this.transitioning = false;
|
|
}
|
|
|
|
Tab.TRANSITION_DURATION = 150;
|
|
|
|
Tab.DEFAULTS = {
|
|
nav: '.tab-nav-item',
|
|
panel: '.tab-panel-item',
|
|
activeClass: 'tab-active'
|
|
};
|
|
|
|
Tab.prototype.init = function() {
|
|
var _this = this
|
|
, $element = _this.$element;
|
|
|
|
_this.$nav = $element.find(_this.options.nav);
|
|
_this.$panel = $element.find(_this.options.panel);
|
|
}
|
|
;
|
|
|
|
Tab.prototype.bindEvent = function() {
|
|
var _this = this;
|
|
_this.$nav.each(function(e) {
|
|
$(this).on('http://www.17sucai.com/preview/1268063/2018-12-13/calculator/js/click.ydui.tab', function() {
|
|
_this.open(e);
|
|
});
|
|
});
|
|
}
|
|
;
|
|
|
|
Tab.prototype.open = function(index) {
|
|
var _this = this;
|
|
|
|
index = typeof index == 'number' ? index : _this.$nav.filter(index).index();
|
|
|
|
var $curNav = _this.$nav.eq(index);
|
|
|
|
_this.active($curNav, _this.$nav);
|
|
|
|
_this.active(_this.$panel.eq(index), _this.$panel, function() {
|
|
$curNav.trigger({
|
|
type: 'http://www.17sucai.com/preview/1268063/2018-12-13/calculator/js/opened.ydui.tab',
|
|
index: index
|
|
});
|
|
_this.transitioning = false;
|
|
});
|
|
}
|
|
;
|
|
|
|
Tab.prototype.active = function($element, $container, callback) {
|
|
var _this = this
|
|
, activeClass = _this.options.activeClass;
|
|
|
|
var $avtive = $container.filter('.' + activeClass);
|
|
|
|
function next() {
|
|
typeof callback == 'function' && callback();
|
|
}
|
|
|
|
$element.one('webkitTransitionEnd', next).emulateTransitionEnd(Tab.TRANSITION_DURATION);
|
|
|
|
$avtive.removeClass(activeClass);
|
|
$element.addClass(activeClass);
|
|
}
|
|
;
|
|
|
|
function Plugin(option) {
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
return this.each(function() {
|
|
var target = this
|
|
, $this = $(target)
|
|
, tab = $this.data('http://www.17sucai.com/preview/1268063/2018-12-13/calculator/js/ydui.tab');
|
|
|
|
if (!tab) {
|
|
$this.data('http://www.17sucai.com/preview/1268063/2018-12-13/calculator/js/ydui.tab', (tab = new Tab(target,option)));
|
|
}
|
|
|
|
if (typeof option == 'string') {
|
|
tab[option] && tab[option].apply(tab, args);
|
|
}
|
|
});
|
|
}
|
|
|
|
$(window).on('http://www.17sucai.com/preview/1268063/2018-12-13/calculator/js/load.ydui.tab', function() {
|
|
$('[data-ydui-tab]').each(function() {
|
|
var $this = $(this);
|
|
$this.tab(window.YDUI.util.parseOptions($this.data('ydui-tab')));
|
|
});
|
|
});
|
|
|
|
$.fn.tab = Plugin;
|
|
|
|
}(window);
|