better-staridc-MNBT
1;jQuery( function() {
2 // 工具提示
3 if($('[data-toggle="tooltip"]')[0]) {
4 $('[data-toggle="tooltip"]').tooltip({
5 "container" : 'body',
6 });
7 }
8
9 // POP弹出框
10 if($('[data-toggle="popover"]')[0]) {
11 $('[data-toggle="popover"]').popover();
12 }
13
14 // 关闭卡片
15 $(document).on('click', '.card-btn-close', function() {
16 $(this).closest('.card').fadeOut(150, function() {
17 if ($(this).parent().children().length == 1) {
18 $(this).parent().remove();
19 } else {
20 $(this).remove();
21 }
22 });
23 });
24
25 // 卡片收缩与打开
26 $(document).on('click', '.card-btn-slide', function(){
27 $(this).toggleClass('rotate-180').closest('.card').find('.card-body').slideToggle();
28 });
29
30 /**
31 * 如果页面中需要用到滚动条,请先导入perfect-scrollbar.min.js
32 */
33 if($('.lyear-scroll')[0]) {
34 $('.lyear-scroll').each(function(){
35 new PerfectScrollbar(this, {
36 swipeEasing: false,
37 suppressScrollX: true
38 });
39 });
40 }
41
42 // 颜色选取
43 jQuery('.js-colorpicker').each(function() {
44 var $colorpicker = jQuery(this);
45 var $colorpickerMode = $colorpicker.data('colorpicker-mode') ? $colorpicker.data('colorpicker-mode') : 'auto';
46 $colorpicker.colorpicker({
47 'format': $colorpickerMode,
48 });
49 });
50
51 // 日期选择器
52 jQuery("[data-provide = 'datepicker']").each(function() {
53 var options = {
54 language: 'zh-CN', // 默认简体中文
55 multidateSeparator: ', ' // 默认多个日期用,分隔
56 }
57
58 options = $.extend( options, getDataOptions( $(this) ));
59
60 if ( $(this).prop("tagName") != 'INPUT' ) {
61 options.inputs = [$(this).find('input:first'), $(this).find('input:last')];
62 }
63
64 $(this).datepicker(options);
65 });
66
67 // 时间选择器
68 jQuery("[data-provide = 'clockpicker']").each(function() {
69 $(this).clockpicker({
70 donetext: 'Done'
71 });
72 });
73
74 // 时间日期选择器
75 jQuery("[data-provide = 'datetimepicker']").each(function() {
76 var options = {
77 locale: moment.locale(),
78 }
79
80 options = $.extend( options, getDataOptions( $(this) ));
81
82 if ( $(this).prop("tagName") != 'INPUT' ) {
83 options.inputs = [$(this).find('input:first'), $(this).find('input:last')];
84 }
85 console.log(options);
86 $(this).datetimepicker(options);
87 });
88
89 // 标签
90 $('.js-tags-input').each(function() {
91 var $this = $(this);
92 $this.tagsInput({
93 height: $this.data('height') ? $this.data('height') : '36px',
94 width: '100%',
95 defaultText: $this.attr("placeholder"),
96 removeWithBackspace: true,
97 delimiter: [',']
98 });
99 });
100
101 // 复选框全选
102 $("#check-all").change(function () {
103 if ($boxname = $(this).data('name')) {
104 $(this).closest('table').find("input[name='" + $boxname + "']").prop('checked', $(this).prop("checked"));
105 } else {
106 $(this).closest('table').find(".custom-checkbox input[type='checkbox']").prop('checked', $(this).prop("checked"));
107 }
108 });
109
110 // iframe打开tab
111 $(document).on('click', '.js-create-tab', function(){
112 parent.$(parent.document).data('multitabs').create({
113 iframe : true,
114 title : $(this).data('title') ? $(this).data('title') : '标题',
115 url : $(this).data('url') ? $(this).data('url') : 'lyear-main.html'
116 }, true);
117 });
118
119 //模态框最大化
120 $(document).on('click', '.modal-fullscreen-btn', function(){
121 $(this).closest('.modal').toggleClass('modal-fullscreen');
122 });
123});
124
125
126// 参考国外模板的写法,获取当前的配置,以data-*(*指插件原有的配置名)
127getDataOptions = function(el, castList) {
128 var options = {};
129
130 $.each( $(el).data(), function(key, value){
131
132 key = dataToOption(key);
133
134 if ( key == 'provide' ) {
135 return;
136 }
137 options[key] = value;
138 });
139
140 return options;
141}
142
143dataToOption = function(name) {
144 return name.replace(/-([a-z])/g, function(x){return x[1].toUpperCase();});
145}