Skip to content

Commit f8b65db

Browse files
committed
format editable extension
1 parent 171873e commit f8b65db

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

src/extensions/editable/bootstrap-table-editable.js

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
* extensions: https://github.com/vitalets/x-editable
44
*/
55

6-
!function ($) {
6+
(function($) {
77

88
'use strict';
99

1010
$.extend($.fn.bootstrapTable.defaults, {
1111
editable: true,
12-
onEditableInit: function () {
12+
onEditableInit: function() {
1313
return false;
1414
},
15-
onEditableSave: function (field, row, oldValue, $el) {
15+
onEditableSave: function(field, row, oldValue, $el) {
1616
return false;
1717
},
18-
onEditableShown: function (field, row, $el, editable) {
18+
onEditableShown: function(field, row, $el, editable) {
1919
return false;
2020
},
21-
onEditableHidden: function (field, row, $el, reason) {
21+
onEditableHidden: function(field, row, $el, reason) {
2222
return false;
2323
}
2424
});
@@ -34,50 +34,54 @@
3434
_initTable = BootstrapTable.prototype.initTable,
3535
_initBody = BootstrapTable.prototype.initBody;
3636

37-
BootstrapTable.prototype.initTable = function () {
37+
BootstrapTable.prototype.initTable = function() {
3838
var that = this;
3939
_initTable.apply(this, Array.prototype.slice.apply(arguments));
4040

4141
if (!this.options.editable) {
4242
return;
4343
}
4444

45-
$.each(this.columns, function (i, column) {
45+
$.each(this.columns, function(i, column) {
4646
if (!column.editable) {
4747
return;
4848
}
4949

50-
var editableOptions = {}, editableDataMarkup = [], editableDataPrefix = 'editable-';
50+
var editableOptions = {},
51+
editableDataMarkup = [],
52+
editableDataPrefix = 'editable-';
5153

5254
var processDataOptions = function(key, value) {
53-
// Replace camel case with dashes.
54-
var dashKey = key.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();});
55-
if (dashKey.slice(0, editableDataPrefix.length) == editableDataPrefix) {
56-
var dataKey = dashKey.replace(editableDataPrefix, 'data-');
57-
editableOptions[dataKey] = value;
58-
}
55+
// Replace camel case with dashes.
56+
var dashKey = key.replace(/([A-Z])/g, function($1) {
57+
return "-" + $1.toLowerCase();
58+
});
59+
if (dashKey.slice(0, editableDataPrefix.length) == editableDataPrefix) {
60+
var dataKey = dashKey.replace(editableDataPrefix, 'data-');
61+
editableOptions[dataKey] = value;
62+
}
5963
};
6064

6165
$.each(that.options, processDataOptions);
6266

63-
column.formatter || column.formatter = function (value, row, index) {
67+
column.formatter = column.formatter || function(value, row, index) {
6468
return value;
6569
};
66-
column._formatter = column._formatter? column._formatter: column.formatter;
67-
column.formatter = function (value, row, index) {
68-
var result = column._formatter? column._formatter(value, row, index): value;
70+
column._formatter = column._formatter ? column._formatter : column.formatter;
71+
column.formatter = function(value, row, index) {
72+
var result = column._formatter ? column._formatter(value, row, index) : value;
6973

7074
$.each(column, processDataOptions);
7175

72-
$.each(editableOptions, function (key, value) {
76+
$.each(editableOptions, function(key, value) {
7377
editableDataMarkup.push(' ' + key + '="' + value + '"');
7478
});
75-
79+
7680
var _dont_edit_formatter = false;
7781
if (column.editable.hasOwnProperty('noeditFormatter')) {
7882
_dont_edit_formatter = column.editable.noeditFormatter(value, row, index);
7983
}
80-
84+
8185
if (_dont_edit_formatter === false) {
8286
return ['<a href="javascript:void(0)"',
8387
' data-name="' + column.field + '"',
@@ -94,21 +98,21 @@
9498
});
9599
};
96100

97-
BootstrapTable.prototype.initBody = function () {
101+
BootstrapTable.prototype.initBody = function() {
98102
var that = this;
99103
_initBody.apply(this, Array.prototype.slice.apply(arguments));
100104

101105
if (!this.options.editable) {
102106
return;
103107
}
104108

105-
$.each(this.columns, function (i, column) {
109+
$.each(this.columns, function(i, column) {
106110
if (!column.editable) {
107111
return;
108112
}
109113

110114
that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
111-
.off('save').on('save', function (e, params) {
115+
.off('save').on('save', function(e, params) {
112116
var data = that.getData(),
113117
index = $(this).parents('tr[data-index]').data('index'),
114118
row = data[index],
@@ -120,23 +124,23 @@
120124
that.resetFooter();
121125
});
122126
that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
123-
.off('shown').on('shown', function (e, editable) {
127+
.off('shown').on('shown', function(e, editable) {
124128
var data = that.getData(),
125129
index = $(this).parents('tr[data-index]').data('index'),
126130
row = data[index];
127-
131+
128132
that.trigger('editable-shown', column.field, row, $(this), editable);
129133
});
130134
that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
131-
.off('hidden').on('hidden', function (e, reason) {
135+
.off('hidden').on('hidden', function(e, reason) {
132136
var data = that.getData(),
133137
index = $(this).parents('tr[data-index]').data('index'),
134138
row = data[index];
135-
139+
136140
that.trigger('editable-hidden', column.field, row, $(this), reason);
137141
});
138142
});
139143
this.trigger('editable-init');
140144
};
141145

142-
}(jQuery);
146+
})(jQuery);

0 commit comments

Comments
 (0)