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 |
|
174 | for (var _iterator = function (target) {
|
175 | return Object.keys(target).map(function (key) {
|
176 | return [key, target[key]];
|
177 | });
|
178 | }(dict), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
179 | var _ref;
|
180 |
|
181 | if (_isArray) {
|
182 | if (_i >= _iterator.length) break;
|
183 | _ref = _iterator[_i++];
|
184 | } else {
|
185 | _i = _iterator.next();
|
186 | if (_i.done) break;
|
187 | _ref = _i.value;
|
188 | }
|
189 |
|
190 | var _ref2 = _ref,
|
191 | _ref3 = _slicedToArray(_ref2, 2),
|
192 | key = _ref3[0],
|
193 | val = _ref3[1];
|
194 |
|
195 |
|
196 | var pattern = key + '=([^&]*)';
|
197 | var targetStr = key + '=' + val;
|
198 |
|
199 | |
200 |
|
201 |
|
202 |
|
203 | if (url.match(pattern)) {
|
204 | var tmp = new RegExp('(' + key + '=)([^&]*)', 'gi');
|
205 | url = url.replace(tmp, targetStr);
|
206 | } else {
|
207 | var seperator = url.match('[?]') ? '&' : '?';
|
208 | url = url + seperator + targetStr;
|
209 | }
|
210 | }
|
211 | if (location.hash) {
|
212 | url += location.hash;
|
213 | }
|
214 | return url;
|
215 | }
|
216 |
|
217 | $.BootstrapTable = function (_$$BootstrapTable) {
|
218 | _inherits(_class, _$$BootstrapTable);
|
219 |
|
220 | function _class() {
|
221 | _classCallCheck(this, _class);
|
222 |
|
223 | return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));
|
224 | }
|
225 |
|
226 | _createClass(_class, [{
|
227 | key: 'init',
|
228 | value: function init() {
|
229 | var _this2 = this;
|
230 |
|
231 |
|
232 | if (this.options.addrbar) {
|
233 |
|
234 | this.addrbarInit = true;
|
235 | var _prefix = this.options.addrPrefix || '';
|
236 |
|
237 |
|
238 | this.options.pageSize = this.options.pageSize || (_GET(_prefix + 'limit') ? parseInt(_GET(_prefix + 'limit')) : $.BootstrapTable.DEFAULTS.pageSize);
|
239 | this.options.pageNumber = this.options.pageNumber || (_GET(_prefix + 'page') ? parseInt(_GET(_prefix + 'page')) : $.BootstrapTable.DEFAULTS.pageNumber);
|
240 | this.options.sortOrder = this.options.sortOrder || (_GET(_prefix + 'order') ? _GET(_prefix + 'order') : $.BootstrapTable.DEFAULTS.sortOrder);
|
241 | this.options.sortName = this.options.sortName || (_GET(_prefix + 'sort') ? _GET(_prefix + 'sort') : 'id');
|
242 | this.options.searchText = this.options.searchText || (_GET(_prefix + 'search') ? _GET(_prefix + 'search') : $.BootstrapTable.DEFAULTS.searchText);
|
243 |
|
244 | var _onLoadSuccess = this.options.onLoadSuccess;
|
245 |
|
246 | this.options.onLoadSuccess = function (data) {
|
247 | if (_this2.addrbarInit) {
|
248 | _this2.addrbarInit = false;
|
249 | } else {
|
250 | var params = {};
|
251 | 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;
|
252 |
|
253 | window.history.pushState({}, '', _buildUrl(params));
|
254 | }
|
255 |
|
256 | if (_onLoadSuccess) {
|
257 | _onLoadSuccess.call(_this2, data);
|
258 | }
|
259 | };
|
260 | }
|
261 | _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'init', this).call(this);
|
262 | }
|
263 | }]);
|
264 |
|
265 | return _class;
|
266 | }($.BootstrapTable);
|
267 | })(jQuery);
|
268 | }); |
\ | No newline at end of file |