corrade-nucleus-nucleons – Blame information for rev 24
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | /** |
2 | * @author: KingYang |
||
3 | * @webSite: https://github.com/kingyang |
||
4 | * @version: v1.0.0 |
||
5 | */ |
||
6 | |||
7 | ! function ($) { |
||
8 | |||
9 | 'use strict'; |
||
10 | |||
11 | $.extend($.fn.bootstrapTable.defaults, { |
||
12 | treeShowField: null, |
||
13 | idField: 'id', |
||
14 | parentIdField: 'pid', |
||
15 | treeVerticalcls: 'vertical', |
||
16 | treeVerticalLastcls: 'vertical last', |
||
17 | treeSpacecls: 'space', |
||
18 | treeNodecls: 'node', |
||
19 | treeCellcls: 'treenode', |
||
20 | treeTextcls: 'text', |
||
21 | onTreeFormatter: function (row) { |
||
22 | var that = this, |
||
23 | options = that.options, |
||
24 | level = row._level || 0, |
||
25 | plevel = row._parent && row._parent._level || 0, |
||
26 | paddings = []; |
||
27 | for (var i = 0; i < plevel; i++) { |
||
28 | paddings.push('<i class="' + options.treeVerticalcls + '"></i>'); |
||
29 | paddings.push('<i class="' + options.treeSpacecls + '"></i>'); |
||
30 | } |
||
31 | |||
32 | for (var i = plevel; i < level; i++) { |
||
33 | if (row._last && i === (level - 1)) { |
||
34 | paddings.push('<i class="' + options.treeVerticalLastcls + '"></i>'); |
||
35 | } else { |
||
36 | paddings.push('<i class="' + options.treeVerticalcls + '"></i>'); |
||
37 | } |
||
38 | paddings.push('<i class="' + options.treeNodecls + '"></i>'); |
||
39 | } |
||
40 | return paddings.join(''); |
||
41 | }, onGetNodes: function (row, data) { |
||
42 | var that = this; |
||
43 | var nodes = []; |
||
44 | $.each(data, function (i, item) { |
||
45 | if (row[that.options.idField] === item[that.options.parentIdField]) { |
||
46 | nodes.push(item); |
||
47 | } |
||
48 | }); |
||
49 | return nodes; |
||
50 | }, |
||
51 | onCheckLeaf: function (row, data) { |
||
52 | if (row.isLeaf !== undefined) { |
||
53 | return row.isLeaf; |
||
54 | } |
||
55 | return !row._nodes || !row._nodes.length; |
||
56 | }, onCheckRoot: function (row, data) { |
||
57 | var that = this; |
||
58 | return !row[that.options.parentIdField]; |
||
59 | } |
||
60 | }); |
||
61 | |||
62 | var BootstrapTable = $.fn.bootstrapTable.Constructor, |
||
63 | _initRow = BootstrapTable.prototype.initRow, |
||
64 | _initHeader = BootstrapTable.prototype.initHeader; |
||
65 | |||
66 | BootstrapTable.prototype.initHeader = function () { |
||
67 | var that = this; |
||
68 | _initHeader.apply(that, Array.prototype.slice.apply(arguments)); |
||
69 | var treeShowField = that.options.treeShowField; |
||
70 | if (treeShowField) { |
||
71 | $.each(this.header.fields, function (i, field) { |
||
72 | if (treeShowField === field) { |
||
73 | that.treeEnable = true; |
||
74 | var _formatter = that.header.formatters[i]; |
||
75 | var _class = [that.options.treeCellcls]; |
||
76 | if (that.header.classes[i]) { |
||
77 | _class.push(that.header.classes[i].split('"')[1] || ''); |
||
78 | } |
||
79 | that.header.classes[i] = 'class="' + _class.join(' ') + '"'; |
||
80 | that.header.formatters[i] = function (value, row, index) { |
||
81 | var colTree = [that.options.onTreeFormatter.apply(that, [row])]; |
||
82 | colTree.push('<span class="' + that.options.treeTextcls + '">'); |
||
83 | if (_formatter) { |
||
84 | colTree.push(_formatter.apply(this, Array.prototype.slice.apply(arguments))); |
||
85 | } else { |
||
86 | colTree.push(value); |
||
87 | } |
||
88 | colTree.push('</span>'); |
||
89 | return colTree.join(''); |
||
90 | }; |
||
91 | return false; |
||
92 | } |
||
93 | }); |
||
94 | } |
||
95 | }; |
||
96 | |||
97 | var initNode = function (item, idx, data, parentDom) { |
||
98 | var that = this; |
||
99 | var nodes = that.options.onGetNodes.apply(that, [item, data]); |
||
100 | item._nodes = nodes; |
||
101 | parentDom.append(_initRow.apply(that, [item, idx, data, parentDom])); |
||
102 | var len = nodes.length - 1; |
||
103 | for (var i = 0; i <= len; i++) { |
||
104 | var node = nodes[i]; |
||
105 | node._level = item._level + 1; |
||
106 | node._parent = item; |
||
107 | if (i === len) |
||
108 | node._last = 1; |
||
109 | initNode.apply(that, [node, $.inArray(node, data), data, parentDom]); |
||
110 | } |
||
111 | }; |
||
112 | |||
113 | |||
114 | BootstrapTable.prototype.initRow = function (item, idx, data, parentDom) { |
||
115 | var that = this; |
||
116 | if (that.treeEnable) { |
||
117 | if (that.options.onCheckRoot.apply(that, [item, data])) { |
||
118 | if (item._level === undefined) { |
||
119 | item._level = 0; |
||
120 | } |
||
121 | initNode.apply(that, [item, idx, data, parentDom]); |
||
122 | return true; |
||
123 | } |
||
124 | return false; |
||
125 | |||
126 | } |
||
127 | return _initRow.apply(that, Array.prototype.slice.apply(arguments)); |
||
128 | }; |
||
129 | |||
130 | } (jQuery); |