A modern, class-based JavaScript library for binding JSON API data to DOM elements. KViews provides a clean, declarative way to work with REST APIs and render data using Handlebars templates.
- ✅ Class-based architecture - Modern ES6 classes for better organization
- ✅ JSON API support - Full JSON API specification support
- ✅ Template rendering - Handlebars template support for flexible rendering
- ✅ Event system - Comprehensive event handling for reactivity
- ✅ jQuery required - Uses jQuery exclusively for DOM manipulation
- ✅ Filtering - Built-in form filtering support
- ✅ CRUD operations - Create, Read, Update, Delete support
- ✅ Bundle & ES6 modules - Use as bundle or ES6 modules
- ✅ TypeScript ready - Written in modern JavaScript
Download dist/kviews.js and include it in your HTML:
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.min.js"></script>
<script src="./dist/kviews.js"></script>npm install kviewsOr copy the src/ directory to your project.
- Handlebars (required) - For template compilation
- jQuery (required) - For DOM manipulation
- Modern Browser - ES6 support (Chrome 61+, Firefox 60+, Safari 11+, Edge 16+)
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.min.js"></script>
<script src="./dist/kviews.js"></script>
</head>
<body>
<div id="posts">
<div class="post">
<h2>{{title}}</h2>
<p>{{content}}</p>
</div>
</div>
<script>
KViews.createCollectionInstance('#posts', {
url: '/api/posts',
type: 'posts'
});
</script>
</body>
</html><!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.min.js"></script>
</head>
<body>
<div id="posts">
<div class="post">
<h2>{{title}}</h2>
<p>{{content}}</p>
</div>
</div>
<script type="module">
import { KViews } from './src/index.js';
KViews.createCollectionInstance('#posts', {
url: '/api/posts',
type: 'posts'
});
</script>
</body>
</html>// Create a collection
const collection = KViews.createCollectionInstance('#posts', {
url: '/api/posts',
type: 'posts',
pageSize: 20
});
// Listen to events
collection.on('load', (collection) => {
log('Loaded', collection.items.length, 'items');
});
// Add new item
collection.append({
attributes: {
title: 'New Post',
content: 'Post content'
}
});// Create an item
const item = KViews.createItemInstance('#post-detail', {
url: '/api/posts/1',
type: 'posts'
});
// Update item
item.update({
attributes: {
title: 'Updated Title'
}
});
// Delete item
item.delete();// Fill form with item data
KViews.helpers.fillForm('#edit-form', item);
// Capture form submission
KViews.helpers.captureFormSubmit('#create-form', (formData) => {
collection.append({ attributes: formData });
});const collection = KViews.createCollectionInstance('#posts', {
url: '/api/posts',
type: 'posts',
filter: '#filter-form' // Form element for filtering
});KViews.createCollectionInstance(el, opts)- Create collection instanceKViews.createItemInstance(el, opts, data)- Create item instanceKViews.baseUrl- Base URL for all API requestsKViews.helpers- Utility functions (fillForm, captureFormSubmit, fetchFormData)
loadFromRemote()- Load data from APIappend(itemData)- Add new itemrender()- Render collectionon(event, callback)- Event listenersitems- Array of Item instances
loadFromRemote()- Load item from APIupdate(data)- Update itemdelete()- Delete itemrender()- Render itemon(event, callback)- Event listeners
Comprehensive documentation is available in the docs/ directory:
- API Reference - Complete API documentation
- User Guides - Step-by-step guides
- Examples - Code examples
# Clone repository
git clone <repository-url>
cd kviews.js
# Install dependencies
npm install# Build bundle (normal + minified)
npm run buildThis creates:
dist/kviews.js- Normal bundle with sourcemapdist/kviews.min.js- Minified bundle
# Run unit tests
npm run test
# Run tests in watch mode
npm run test:watch
# Run with coverage
npm run test:coverage
# Run E2E tests
npm run test:e2e
# Run all tests
npm run test:all# Python
npm run serve:python
# PHP
npm run serve:php
# Node.js
npm run serve:nodekviews.js/
├── src/ # Source code
│ ├── KViews.js # Main factory class
│ ├── Item.js # Item class
│ ├── Collection.js # Collection class
│ ├── Storage.js # HTTP operations
│ ├── URL.js # URL parsing
│ ├── utilities.js # Utility functions
│ └── ...
├── dist/ # Built bundles
├── docs/ # Documentation
│ ├── api/ # API reference
│ ├── guides/ # User guides
│ └── examples/ # Code examples
├── tests/ # Test suite
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ └── e2e/ # End-to-end tests
└── build.js # Build script
- Chrome 61+
- Firefox 60+
- Safari 11+
- Edge 16+
- IE11+ (with polyfills for bundle version)
KViews expects data in JSON API format:
{
"data": {
"id": "1",
"type": "posts",
"attributes": {
"title": "Post Title",
"content": "Post content"
},
"relationships": {
"author": {
"data": {
"id": "123",
"type": "users"
}
}
}
}
}Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow existing code style
- Add tests for new features
- Update documentation as needed
- Ensure all tests pass
This project is licensed under the MIT License - see the LICENSE file for details.
Event System Refactoring:
- ✅ Unified event system - Removed dual callback system (
onafterrender,onbeforeloadproperties) - ✅ New event methods - Added
off(),once(),emit(),hasListeners()methods - ✅ Standardized events - All events now use
on()method exclusively - ✅ New Item events - Added
beforeload,load,afterrenderevents (previously missing or inconsistent) - ✅ Collection events - Added
beforeloadevent - ✅ Return value consistency -
Collection.onupdate()now returnsthisfor chaining
Breaking Changes:
- ❌ Removed:
collection.onafterrenderandcollection.onbeforeloadproperties - ❌ Removed:
item.onafterrenderproperty - ✅ Migration: Use
collection.on('afterrender', callback)instead ofcollection.onafterrender = callback - ✅ Migration: Use
collection.on('beforeload', callback)instead ofcollection.onbeforeload = callback
Improvements:
- Event listeners can now be removed with
off() - One-time listeners supported with
once() - Manual event triggering with
emit() - Consistent event API across Collection and Item classes
- Fixed bundle to properly expose
KViews.createCollectionInstanceandKViews.createItemInstance - Refactored Paging to ES6 class
- Templates now expose attributes directly (use
{{title}}instead of{{attributes.title}}) - Utilities exposed via
KViews.helpers(recommended access method) - Removed
getUtilities()instance methods - Storage class now uses Fetch API exclusively (no jQuery dependency)
- Added comprehensive test suite (Vitest + Playwright)
- Improved build script to generate both normal and minified bundles
- Initial release
- Class-based architecture
- JSON API support
- Handlebars templating
- Event system
- Form utilities
- Bundle and ES6 module support
For issues, questions, or contributions:
- Open an issue on GitHub
- Check the documentation
- Review examples
- Built with modern JavaScript (ES6+)
- Uses Handlebars for templating
- Inspired by modern data-binding patterns
Made with ❤️ for modern web development