@cable8mm/jquery-infinite-with-template 1.0.4 → 1.1.2
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/.editorconfig +14 -0
- package/.github/workflows/publish.yml +24 -0
- package/.github/workflows/static.yml +49 -0
- package/.github/workflows/test.yml +33 -0
- package/.vscode/settings.json +4 -0
- package/AGENTS.md +216 -0
- package/README.md +266 -180
- package/examples/data_sources.json +84 -0
- package/examples/generate +55 -11
- package/examples/index.html +3 -3
- package/jest.config.js +8 -0
- package/jquery.infiniteScrollWithTemplate.d.ts +65 -0
- package/jquery.infiniteScrollWithTemplate.js +95 -10
- package/jquery.infiniteScrollWithTemplate.min.js +1 -1
- package/package.json +20 -2
- package/scripts/prepare-dist.js +72 -0
- package/tests/jquery.infiniteScrollWithTemplate.test.js +310 -0
- package/tests/setup.js +16 -0
- package/examples/data_sources.ajax +0 -84
package/.editorconfig
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [created]
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v7
|
|
11
|
+
- uses: actions/setup-node@v6
|
|
12
|
+
with:
|
|
13
|
+
node-version: "24"
|
|
14
|
+
registry-url: "https://registry.npmjs.org"
|
|
15
|
+
|
|
16
|
+
- name: Update version
|
|
17
|
+
run: |
|
|
18
|
+
VERSION=${GITHUB_REF#refs/tags/v}
|
|
19
|
+
npm version $VERSION --no-git-tag-version
|
|
20
|
+
|
|
21
|
+
- run: npm install
|
|
22
|
+
- run: npm publish
|
|
23
|
+
env:
|
|
24
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Simple workflow for deploying static content to GitHub Pages
|
|
2
|
+
name: Deploy static content to Pages
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
release:
|
|
6
|
+
types: [created]
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
pages: write
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
14
|
+
concurrency:
|
|
15
|
+
group: "pages"
|
|
16
|
+
cancel-in-progress: false
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
deploy:
|
|
20
|
+
environment:
|
|
21
|
+
name: github-pages
|
|
22
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- name: Checkout
|
|
26
|
+
uses: actions/checkout@v6
|
|
27
|
+
|
|
28
|
+
- name: Setup Node.js
|
|
29
|
+
uses: actions/setup-node@v6
|
|
30
|
+
with:
|
|
31
|
+
node-version: "24"
|
|
32
|
+
|
|
33
|
+
- name: Install Dependencies
|
|
34
|
+
run: npm install
|
|
35
|
+
|
|
36
|
+
- name: Build
|
|
37
|
+
run: npm run build
|
|
38
|
+
|
|
39
|
+
- name: Setup Pages
|
|
40
|
+
uses: actions/configure-pages@v6
|
|
41
|
+
|
|
42
|
+
- name: Upload artifact
|
|
43
|
+
uses: actions/upload-pages-artifact@v5
|
|
44
|
+
with:
|
|
45
|
+
path: "./dist"
|
|
46
|
+
|
|
47
|
+
- name: Deploy to GitHub Pages
|
|
48
|
+
id: deployment
|
|
49
|
+
uses: actions/deploy-pages@v5
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master, develop]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, master, develop]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
node-version: [24.x]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v7
|
|
19
|
+
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v6
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
cache: "npm"
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: npm ci
|
|
28
|
+
|
|
29
|
+
- name: Run tests
|
|
30
|
+
run: npm test
|
|
31
|
+
|
|
32
|
+
- name: Run build
|
|
33
|
+
run: npm run build
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# AGENTS.md - AI Agent Configuration
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
|
|
5
|
+
jQuery infinite scroll plugin with template rendering. Lightweight (~3KB minified), well-tested (16 tests), production-ready.
|
|
6
|
+
|
|
7
|
+
## Tech Stack
|
|
8
|
+
|
|
9
|
+
- jQuery 3.7.0
|
|
10
|
+
- jsRender 1.0.10 (template engine)
|
|
11
|
+
- Jest 29.7.0 (testing)
|
|
12
|
+
- Terser (minification)
|
|
13
|
+
- http-server (dev server)
|
|
14
|
+
|
|
15
|
+
## File Structure
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
├── jquery.infiniteScrollWithTemplate.js # Main plugin (EDIT THIS)
|
|
19
|
+
├── jquery.infiniteScrollWithTemplate.min.js # Generated by build
|
|
20
|
+
├── jquery.infiniteScrollWithTemplate.d.ts # TypeScript defs
|
|
21
|
+
├── package.json # Scripts & deps
|
|
22
|
+
├── README.md # Documentation
|
|
23
|
+
├── examples/
|
|
24
|
+
│ ├── index.html # Demo page
|
|
25
|
+
│ ├── data_sources.json # Demo data
|
|
26
|
+
│ └── generate # PHP data generator
|
|
27
|
+
├── tests/
|
|
28
|
+
│ ├── setup.js # Test config
|
|
29
|
+
│ └── jquery.infiniteScrollWithTemplate.test.js # 16 tests
|
|
30
|
+
├── scripts/
|
|
31
|
+
│ └── prepare-dist.js # Build script
|
|
32
|
+
└── .github/workflows/
|
|
33
|
+
└── test.yml # CI/CD
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Coding Conventions
|
|
37
|
+
|
|
38
|
+
### JavaScript
|
|
39
|
+
|
|
40
|
+
- ES5 syntax (jQuery plugin pattern)
|
|
41
|
+
- Single quotes for strings
|
|
42
|
+
- 2-space indentation
|
|
43
|
+
- Semicolons required
|
|
44
|
+
- No trailing commas in objects/arrays
|
|
45
|
+
- camelCase for variables/functions
|
|
46
|
+
- PascalCase for constructors
|
|
47
|
+
|
|
48
|
+
### jQuery Plugin Pattern
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
(function ($) {
|
|
52
|
+
$.fn.pluginName = function (settings) {
|
|
53
|
+
var $this = $(this);
|
|
54
|
+
var opts = $.extend({}, defaults, settings);
|
|
55
|
+
|
|
56
|
+
// Always return this for chaining
|
|
57
|
+
return this;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
$.fn.pluginName.defaults = { ... };
|
|
61
|
+
})(jQuery);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Key Rules
|
|
65
|
+
|
|
66
|
+
### 1. Plugin Initialization
|
|
67
|
+
|
|
68
|
+
- Always validate required options (templateSelector, dataPath)
|
|
69
|
+
- Return jQuery object for chaining
|
|
70
|
+
- Use namespace for event handlers: `.infiniteTemplate_` + random string
|
|
71
|
+
|
|
72
|
+
### 2. AJAX Data Loading
|
|
73
|
+
|
|
74
|
+
- Build URLs with `buildUrl(baseUrl, page)` function
|
|
75
|
+
- Handle both absolute and relative URLs
|
|
76
|
+
- Support query parameters via `opts.query`
|
|
77
|
+
- Add cache buster when `opts.preventCache` is true
|
|
78
|
+
|
|
79
|
+
### 3. Template Rendering
|
|
80
|
+
|
|
81
|
+
- Use jsRender: `$.templates(selector).render(data)`
|
|
82
|
+
- Merge `opts.templateHelpers` with each item
|
|
83
|
+
- Use DocumentFragment for performance (already implemented)
|
|
84
|
+
|
|
85
|
+
### 4. Callbacks
|
|
86
|
+
|
|
87
|
+
- `loadingCallback()` - before AJAX
|
|
88
|
+
- `loadedCallback()` - after AJAX (success or error)
|
|
89
|
+
- `zeroCallback()` - when no data on first page
|
|
90
|
+
- `errorCallback(error)` - on AJAX/JSON parse error
|
|
91
|
+
|
|
92
|
+
### 5. State Management
|
|
93
|
+
|
|
94
|
+
- `currentScrollPage` - track current page
|
|
95
|
+
- `scrollTriggered` - prevent duplicate requests
|
|
96
|
+
- `isFinished` - stop when no more data
|
|
97
|
+
|
|
98
|
+
## Testing
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm test # Run 16 tests
|
|
102
|
+
npm run build # Minify + create dist/
|
|
103
|
+
npm run dev # Start dev server with auto-open
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Test Structure
|
|
107
|
+
|
|
108
|
+
- Use jest with jsdom environment
|
|
109
|
+
- Mock jQuery.ajax
|
|
110
|
+
- Test all callbacks
|
|
111
|
+
- Test URL building
|
|
112
|
+
- Test edge cases (empty data, JSON parse errors)
|
|
113
|
+
|
|
114
|
+
## Build Process
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npm run build
|
|
118
|
+
# 1. Minify with terser (creates .min.js)
|
|
119
|
+
# 2. Run scripts/prepare-dist.js
|
|
120
|
+
# - Creates dist/ folder
|
|
121
|
+
# - Copies examples/ to dist/examples/
|
|
122
|
+
# - Copies plugin files to dist/
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Important Patterns
|
|
126
|
+
|
|
127
|
+
### Scroll Detection
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
$(window).on("scroll" + namespace, function () {
|
|
131
|
+
if (
|
|
132
|
+
$(this).scrollTop() >
|
|
133
|
+
$(document.body).height() -
|
|
134
|
+
$(window).height() * (opts.scrollThreshold || 2) &&
|
|
135
|
+
!isFinished
|
|
136
|
+
) {
|
|
137
|
+
triggerDataLoad();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Click Loading (Alternative)
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
if (opts.loadSelector) {
|
|
146
|
+
$(document).on("click" + namespace, opts.loadSelector, function () {
|
|
147
|
+
triggerDataLoad();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### JSON Parsing
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
if (typeof result === "string") {
|
|
156
|
+
try {
|
|
157
|
+
result = JSON.parse(result);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
// Handle error
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Common Tasks
|
|
165
|
+
|
|
166
|
+
### Adding New Feature
|
|
167
|
+
|
|
168
|
+
1. Update `jquery.infiniteScrollWithTemplate.js`
|
|
169
|
+
2. Add option to `$.fn.infiniteTemplate.defaults`
|
|
170
|
+
3. Add tests in `tests/jquery.infiniteScrollWithTemplate.test.js`
|
|
171
|
+
4. Update README.md options table
|
|
172
|
+
5. Run `npm test` to verify
|
|
173
|
+
|
|
174
|
+
### Fixing Bug
|
|
175
|
+
|
|
176
|
+
1. Check console.error messages in plugin
|
|
177
|
+
2. Add test case that reproduces bug
|
|
178
|
+
3. Fix in main plugin file
|
|
179
|
+
4. Verify test passes
|
|
180
|
+
5. Run `npm run build` to update dist/
|
|
181
|
+
|
|
182
|
+
### Updating Documentation
|
|
183
|
+
|
|
184
|
+
- README.md: User-facing docs
|
|
185
|
+
- Code comments: Inline documentation
|
|
186
|
+
- AGENTS.md: This file (AI guidance)
|
|
187
|
+
|
|
188
|
+
## DO NOT
|
|
189
|
+
|
|
190
|
+
- Modify `jquery.infiniteScrollWithTemplate.min.js` directly (auto-generated)
|
|
191
|
+
- Use ES6+ syntax (ES5 only for jQuery compatibility)
|
|
192
|
+
- Remove event namespace (causes memory leaks)
|
|
193
|
+
- Forget to return `this` (breaks chaining)
|
|
194
|
+
- Use `==` instead of `===` for comparisons
|
|
195
|
+
|
|
196
|
+
## CI/CD
|
|
197
|
+
|
|
198
|
+
GitHub Actions runs on:
|
|
199
|
+
|
|
200
|
+
- Push to main/master/develop
|
|
201
|
+
- Pull requests to main/master/develop
|
|
202
|
+
- Tests on Node.js 16.x, 18.x, 20.x
|
|
203
|
+
- Runs: npm ci → npm test → npm run build
|
|
204
|
+
|
|
205
|
+
## Deployment
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
npm run build
|
|
209
|
+
# Deploy dist/ folder to hosting
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Notes
|
|
213
|
+
|
|
214
|
+
- examples/generate is PHP script (ignore IDE warnings)
|
|
215
|
+
- .vscode/settings.json excludes PHP linter for generate
|
|
216
|
+
- Online demo: https://www.palgle.com/jquery-infinite-with-template/examples/index.html
|