@cable8mm/jquery-infinite-with-template 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
|
-
jQuery Infinite With Template Plugin
|
|
2
|
-
|
|
1
|
+
# jQuery Infinite With Template Plugin
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
3
10
|
|
|
4
11
|
JQuery plugin for ajax-enabled infinite page scroll with template.
|
|
5
12
|
|
|
6
13
|
If you like jQuery until now, this little library will help.
|
|
7
14
|
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
on npm
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm i @cable8mm/jquery-infinite-with-template
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
on html
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<script src="https://cdn.jsdelivr.net/npm/@cable8mm/jquery-infinite-with-template@1.0.4/jquery.infiniteScrollWithTemplate.min.js" integrity="sha256-bX3iyCp0T50YmDRgpUl1tY/LGlpPGsKR4TqUkpcq6WA=" crossorigin="anonymous"></script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
on ESM
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<script type="module"> import @cable8mm/jquery-infinite-with-template from https://cdn.jsdelivr.net/npm/@cable8mm/jquery-infinite-with-template@1.0.4/+esm </script>
|
|
33
|
+
```
|
|
34
|
+
|
|
8
35
|
## Demo
|
|
9
36
|
|
|
10
37
|
For convinient `http-server` need:
|
|
@@ -39,7 +66,10 @@ $("#result").infiniteTemplate({
|
|
|
39
66
|
query: "word=ajax",
|
|
40
67
|
templateHelpers: {
|
|
41
68
|
authId : 354
|
|
42
|
-
}
|
|
69
|
+
},
|
|
70
|
+
zeroCallback: function () {
|
|
71
|
+
alert("zero alert");
|
|
72
|
+
},
|
|
43
73
|
});
|
|
44
74
|
```
|
|
45
75
|
|
|
@@ -109,6 +139,8 @@ Result:
|
|
|
109
139
|
|
|
110
140
|
**templateHelpers** - (optional) Merge with json to load
|
|
111
141
|
|
|
142
|
+
**key** - (optional) data(default)
|
|
143
|
+
|
|
112
144
|
**query** - (optional) Additional query
|
|
113
145
|
|
|
114
146
|
**method** - (optional) GET(default), POST, PUT, DELETE
|
|
@@ -121,6 +153,8 @@ Result:
|
|
|
121
153
|
|
|
122
154
|
**preventCache** - (optional) false(default) if true, Add timestamp
|
|
123
155
|
|
|
156
|
+
**zeroCallback** - (optional) null(default) if function, call zeroCallback when result is nothing
|
|
157
|
+
|
|
124
158
|
## Examples
|
|
125
159
|
|
|
126
160
|
```html
|
|
@@ -209,4 +243,6 @@ Result:
|
|
|
209
243
|
initialPage: 3,
|
|
210
244
|
});
|
|
211
245
|
</script>
|
|
212
|
-
```
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
The jQuery Infinite With Template Plugin project is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
package/examples/index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* JQuery plugin for ajax-enabled infinite page scroll with template.
|
|
4
4
|
*
|
|
5
5
|
* Author: Sam Lee (https://github.com/cable8mm)
|
|
6
|
-
* Version: 1.0.
|
|
6
|
+
* Version: 1.0.4
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
(function ($) {
|
|
@@ -52,15 +52,24 @@
|
|
|
52
52
|
url: opts.dataPath + "?page=" + currentScrollPage + query + timestamp,
|
|
53
53
|
method: opts.method,
|
|
54
54
|
success: function (result) {
|
|
55
|
-
if ("string"
|
|
55
|
+
if (typeof result === "string") {
|
|
56
56
|
result = JSON.parse(result);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
if (result) {
|
|
60
|
-
if (result[
|
|
60
|
+
if (result[opts.key].length == 0) {
|
|
61
61
|
isFinished = true;
|
|
62
|
+
|
|
63
|
+
// if zero, call zeroCallback
|
|
64
|
+
console.log(currentScrollPage + " " + opts.zeroCallback);
|
|
65
|
+
if (
|
|
66
|
+
currentScrollPage == 1 &&
|
|
67
|
+
typeof opts.zeroCallback === "function"
|
|
68
|
+
) {
|
|
69
|
+
opts.zeroCallback();
|
|
70
|
+
}
|
|
62
71
|
} else {
|
|
63
|
-
$.each(result[
|
|
72
|
+
$.each(result[opts.key], function (_, item) {
|
|
64
73
|
if (opts.templateHelpers) {
|
|
65
74
|
item = Object.assign(item, opts.templateHelpers);
|
|
66
75
|
}
|
|
@@ -90,11 +99,13 @@
|
|
|
90
99
|
dataPath: null,
|
|
91
100
|
templateSelector: null,
|
|
92
101
|
query: null,
|
|
102
|
+
key: "data",
|
|
93
103
|
method: "GET",
|
|
94
104
|
templateHelpers: null,
|
|
95
105
|
loadAtStart: true,
|
|
96
106
|
loadSelector: null,
|
|
97
107
|
initialPage: 1,
|
|
98
108
|
preventCache: false,
|
|
109
|
+
zeroCallback: null,
|
|
99
110
|
};
|
|
100
111
|
})(jQuery);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){e.fn.infiniteTemplate=function(t){var
|
|
1
|
+
!function(e){e.fn.infiniteTemplate=function(t){var l=e(this);if(!l.length)return l;var a=e.extend({},e.fn.infiniteTemplate.defaults,t),n=a.initialPage,o=!1,i=!1;function r(){if(!o&&!i){o=!0;var t=e.templates(a.templateSelector),r=a.query?"&"+a.query:"",c=a.preventCache?"&t="+(new Date).getTime():"";e.ajax({url:a.dataPath+"?page="+n+r+c,method:a.method,success:function(r){"string"==typeof r&&(r=JSON.parse(r)),r&&(0==r[a.key].length?(i=!0,console.log(n+" "+a.zeroCallback),1==n&&"function"==typeof a.zeroCallback&&a.zeroCallback()):(e.each(r[a.key],function(n,o){a.templateHelpers&&(o=Object.assign(o,a.templateHelpers));var i=t.render(o);e(i).appendTo(l)}),n+=1)),o=!1}})}}return a.loadSelector?e(document).on("click",a.loadSelector,function(){r()}):e(window).on("scroll",function(){e(this).scrollTop()>e(document.body).height()-2*e(this).height()&&!i&&r()}),a.loadAtStart&&r(),this},e.fn.infiniteTemplate.defaults={dataPath:null,templateSelector:null,query:null,key:"data",method:"GET",templateHelpers:null,loadAtStart:!0,loadSelector:null,initialPage:1,preventCache:!1,zeroCallback:null}}(jQuery);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cable8mm/jquery-infinite-with-template",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"title": "jQuery Infinite With Template",
|
|
5
5
|
"description": "JQuery plugin for ajax-enabled infinite page scroll with template. If you like jQuery until now, this little library will help.",
|
|
6
6
|
"main": "jquery.infiniteScrollWithTemplate.js",
|
/package/{LICENSE → LICENSE.md}
RENAMED
|
File without changes
|