@@ -80,25 +80,49 @@ define([
80
80
) ;
81
81
} ,
82
82
83
- /**
84
- * @param {String } paramName
85
- * @param {* } paramValue
86
- * @param {* } defaultValue
87
- */
88
- changeUrl : function ( paramName , paramValue , defaultValue ) {
83
+ getUrlParams : function ( ) {
89
84
var decode = window . decodeURIComponent ,
90
85
urlPaths = this . options . url . split ( '?' ) ,
91
- baseUrl = urlPaths [ 0 ] ,
92
86
urlParams = urlPaths [ 1 ] ? urlPaths [ 1 ] . split ( '&' ) : [ ] ,
93
- paramData = { } ,
94
- parameters , i , form , params , key , input , formKey ;
87
+ params = { } , parameters , i ;
95
88
96
89
for ( i = 0 ; i < urlParams . length ; i ++ ) {
97
90
parameters = urlParams [ i ] . split ( '=' ) ;
98
- paramData [ decode ( parameters [ 0 ] ) ] = parameters [ 1 ] !== undefined ?
91
+ params [ decode ( parameters [ 0 ] ) ] = parameters [ 1 ] !== undefined ?
99
92
decode ( parameters [ 1 ] . replace ( / \+ / g, '%20' ) ) :
100
93
'' ;
101
94
}
95
+
96
+ return params ;
97
+ } ,
98
+
99
+ getCurrentLimit : function ( )
100
+ {
101
+ var currentLimit = this . getUrlParams ( ) [ this . options . limit ] ;
102
+
103
+ if ( currentLimit === undefined ) {
104
+ currentLimit = this . options . limitDefault ;
105
+ }
106
+
107
+ return currentLimit ;
108
+ } ,
109
+
110
+
111
+ /**
112
+ * @param {String } paramName
113
+ * @param {* } paramValue
114
+ * @param {* } defaultValue
115
+ */
116
+ changeUrl : function ( paramName , paramValue , defaultValue ) {
117
+ var urlPaths = this . options . url . split ( '?' ) ,
118
+ baseUrl = urlPaths [ 0 ] ,
119
+ paramData = this . getUrlParams ( ) ,
120
+ form , params , key , input , formKey ;
121
+
122
+ if ( paramName === this . options . limit && paramValue > this . getCurrentLimit ( ) ) {
123
+ delete paramData [ 'p' ] ;
124
+ }
125
+
102
126
paramData [ paramName ] = paramValue ;
103
127
104
128
if ( this . options . post ) {
@@ -130,6 +154,7 @@ define([
130
154
if ( paramValue == defaultValue ) { //eslint-disable-line eqeqeq
131
155
delete paramData [ paramName ] ;
132
156
}
157
+
133
158
paramData = $ . param ( paramData ) ;
134
159
location . href = baseUrl + ( paramData . length ? '?' + paramData : '' ) ;
135
160
}
0 commit comments