1 | (function (global, factory) {
|
2 | if (typeof define === "function" && define.amd) {
|
3 | define([], factory);
|
4 | } else if (typeof exports !== "undefined") {
|
5 | factory();
|
6 | } else {
|
7 | var mod = {
|
8 | exports: {}
|
9 | };
|
10 | factory();
|
11 | global.bootstrapTableAddrbar = mod.exports;
|
12 | }
|
13 | })(this, function () {
|
14 | 'use strict';
|
15 |
|
16 | function _classCallCheck(instance, Constructor) {
|
17 | if (!(instance instanceof Constructor)) {
|
18 | throw new TypeError("Cannot call a class as a function");
|
19 | }
|
20 | }
|
21 |
|
22 | var _createClass = function () {
|
23 | function defineProperties(target, props) {
|
24 | for (var i = 0; i < props.length; i++) {
|
25 | var descriptor = props[i];
|
26 | descriptor.enumerable = descriptor.enumerable || false;
|
27 | descriptor.configurable = true;
|
28 | if ("value" in descriptor) descriptor.writable = true;
|
29 | Object.defineProperty(target, descriptor.key, descriptor);
|
30 | }
|
31 | }
|
32 |
|
33 | return function (Constructor, protoProps, staticProps) {
|
34 | if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
35 | if (staticProps) defineProperties(Constructor, staticProps);
|
36 | return Constructor;
|
37 | };
|
38 | }();
|
39 |
|
40 | function _possibleConstructorReturn(self, call) {
|
41 | if (!self) {
|
42 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
43 | }
|
44 |
|
45 | return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
46 | }
|
47 |
|
48 | var _get = function get(object, property, receiver) {
|
49 | if (object === null) object = Function.prototype;
|
50 | var desc = Object.getOwnPropertyDescriptor(object, property);
|
51 |
|
52 | if (desc === undefined) {
|
53 | var parent = Object.getPrototypeOf(object);
|
54 |
|
55 | if (parent === null) {
|
56 | return undefined;
|
57 | } else {
|
58 | return get(parent, property, receiver);
|
59 | }
|
60 | } else if ("value" in desc) {
|
61 | return desc.value;
|
62 | } else {
|
63 | var getter = desc.get;
|
64 |
|
65 | if (getter === undefined) {
|
66 | return undefined;
|
67 | }
|
68 |
|
69 | return getter.call(receiver);
|
70 | }
|
71 | };
|
72 |
|
73 | function _inherits(subClass, superClass) {
|
74 | if (typeof superClass !== "function" && superClass !== null) {
|
75 | throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
76 | }
|
77 |
|
78 | subClass.prototype = Object.create(superClass && superClass.prototype, {
|
79 | constructor: {
|
80 | value: subClass,
|
81 | enumerable: false,
|
82 | writable: true,
|
83 | configurable: true
|
84 | }
|
85 | });
|
86 | if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
87 | }
|
88 |
|
89 | var _slicedToArray = function () {
|
90 | function sliceIterator(arr, i) {
|
91 | var _arr = [];
|
92 | var _n = true;
|
93 | var _d = false;
|
94 | var _e = undefined;
|
95 |
|
96 | try {
|
97 | for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
98 | _arr.push(_s.value);
|
99 |
|
100 | if (i && _arr.length === i) break;
|
101 | }
|
102 | } catch (err) {
|
103 | _d = true;
|
104 | _e = err;
|
105 | } finally {
|
106 | try {
|
107 | if (!_n && _i["return"]) _i["return"]();
|
108 | } finally {
|
109 | if (_d) throw _e;
|
110 | }
|
111 | }
|
112 |
|
113 | return _arr;
|
114 | }
|
115 |
|
116 | return function (arr, i) {
|
117 | if (Array.isArray(arr)) {
|
118 | return arr;
|
119 | } else if (Symbol.iterator in Object(arr)) {
|
120 | return sliceIterator(arr, i);
|
121 | } else {
|
122 | throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
123 | }
|
124 | };
|
125 | }();
|
126 |
|
127 | |
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | (function ($) {
|
136 | |
137 |
|
138 |
|
139 |
|
140 |
|
141 | function _GET(key) {
|
142 | var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.search;
|
143 |
|
144 | |
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | var reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)');
|
151 | var result = url.substr(1).match(reg);
|
152 |
|
153 | if (result) {
|
154 | return decodeURIComponent(result[2]);
|
155 | }
|
156 | return null;
|
157 | }
|
158 |
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 | function _buildUrl(dict) {
|
172 | var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.search;
|
173 | var _iteratorNormalCompletion = true;
|
174 | var _didIteratorError = false;
|
175 | var _iteratorError = undefined;
|
176 |
|
177 | try {
|
178 | for (var _iterator = Object.entries(dict)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
179 | var _ref = _step.value;
|
180 |
|
181 | var _ref2 = _slicedToArray(_ref, 2);
|
182 |
|
183 | var key = _ref2[0];
|
184 | var val = _ref2[1];
|
185 |
|
186 |
|
187 | var pattern = key + '=([^&]*)';
|
188 | var targetStr = key + '=' + val;
|
189 |
|
190 | |
191 |
|
192 |
|
193 |
|
194 | if (url.match(pattern)) {
|
195 | var tmp = new RegExp('(' + key + '=)([^&]*)', 'gi');
|
196 | url = url.replace(tmp, targetStr);
|
197 | } else {
|
198 | var seperator = url.match('[?]') ? '&' : '?';
|
199 | url = url + seperator + targetStr;
|
200 | }
|
201 | }
|
202 | } catch (err) {
|
203 | _didIteratorError = true;
|
204 | _iteratorError = err;
|
205 | } finally {
|
206 | try {
|
207 | if (!_iteratorNormalCompletion && _iterator.return) {
|
208 | _iterator.return();
|
209 | }
|
210 | } finally {
|
211 | if (_didIteratorError) {
|
212 | throw _iteratorError;
|
213 | }
|
214 | }
|
215 | }
|
216 |
|
217 | return url;
|
218 | }
|
219 |
|
220 | $.BootstrapTable = function (_$$BootstrapTable) {
|
221 | _inherits(_class, _$$BootstrapTable);
|
222 |
|
223 | function _class() {
|
224 | _classCallCheck(this, _class);
|
225 |
|
226 | return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));
|
227 | }
|
228 |
|
229 | _createClass(_class, [{
|
230 | key: 'init',
|
231 | value: function init() {
|
232 | var _this2 = this;
|
233 |
|
234 |
|
235 | if (this.options.addrbar) {
|
236 |
|
237 | this.addrbarInit = true;
|
238 | var _prefix = this.options.addrPrefix || '';
|
239 |
|
240 |
|
241 | this.options.pageSize = this.options.pageSize || (_GET(_prefix + 'limit') ? parseInt(_GET(_prefix + 'limit')) : $.BootstrapTable.DEFAULTS.pageSize);
|
242 | this.options.pageNumber = this.options.pageNumber || (_GET(_prefix + 'page') ? parseInt(_GET(_prefix + 'page')) : $.BootstrapTable.DEFAULTS.pageNumber);
|
243 | this.options.sortOrder = this.options.sortOrder || (_GET(_prefix + 'order') ? _GET(_prefix + 'order') : $.BootstrapTable.DEFAULTS.sortOrder);
|
244 | this.options.sortName = this.options.sortName || (_GET(_prefix + 'sort') ? _GET(_prefix + 'sort') : 'id');
|
245 | this.options.searchText = this.options.searchText || (_GET(_prefix + 'search') ? _GET(_prefix + 'search') : $.BootstrapTable.DEFAULTS.searchText);
|
246 |
|
247 | var _onLoadSuccess = this.options.onLoadSuccess;
|
248 |
|
249 | this.options.onLoadSuccess = function (data) {
|
250 | if (_this2.addrbarInit) {
|
251 | _this2.addrbarInit = false;
|
252 | } else {
|
253 | var params = {};
|
254 | params[_prefix + 'page'] = _this2.options.pageNumber, params[_prefix + 'limit'] = _this2.options.pageSize, params[_prefix + 'order'] = _this2.options.sortOrder, params[_prefix + 'sort'] = _this2.options.sortName, params[_prefix + 'search'] = _this2.options.searchText;
|
255 |
|
256 | window.history.pushState({}, '', _buildUrl(params));
|
257 | }
|
258 |
|
259 | if (_onLoadSuccess) {
|
260 | _onLoadSuccess.call(_this2, data);
|
261 | }
|
262 | };
|
263 | }
|
264 | _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'init', this).call(this);
|
265 | }
|
266 | }]);
|
267 |
|
268 | return _class;
|
269 | }($.BootstrapTable);
|
270 | })(jQuery);
|
271 | }); |
\ | No newline at end of file |