pessek / pessek_lists
Elgg 的 AJAX 列表
4.1
2021-11-14 02:08 UTC
Requires
- php: >=7.4
- composer/installers: ^1.0.8
Conflicts
- elgg/elgg: <4.0
This package is not auto-updated.
Last update: 2024-09-30 14:31:00 UTC
README
一套工具,旨在提高用户体验并简化开发者常用的列表模式。
功能
- 无缝集成核心和现有插件
- AJAX 列表分页和无限制滚动
- 预加载前一个和后一个列表页面
- 自动刷新列表
- 创建可排序/可搜索列表的界面
服务器端
以下选项由 elgg_list_entities()
、elgg_view_entity_list()
以及 page/components/list
和 page/components/gallery
视图接受。如果您的选项中有 'pagination' => true
,则这些参数才会生效。需要传递给 jQuery 插件的附加选项可以用 data-
前缀。
'list_id'
STRING 是一个可选参数,但强烈建议传递给您的列表。列表 ID 必须对页面唯一。'pagination_type'
STRING 默认 (带页面导航的分页栏) 或infinite
(前后导航)'position'
STRING 可以用来指定分页项的位置。before
、after
、both
'num_pages'
INT 可以用来指定要显示的页面导航项数量,使用 0 仅显示 Next 和 Prev 链接'lazy_load'
INT 可以用来初始化页面预加载'auto_refresh'
INT 可以用来指定新项目应多久从服务器获取一次(以秒为单位)'reversed'
BOOL 可以用来指定倒序列表。如果列表是倒序的,则假定新项目位于列表的末尾
客户端
已从服务器端接收到必要参数的列表将被自动实例化。如果您需要以编程方式实例化列表,请使用 $.hypeList(options)
。
// Instantiate a new list $('.elgg-list.my-list').hypeList({ baseUrl: false, // Data source count: 0, // Number of items in the list offset: 0, // Current offset from the beginning of the list offsetKey: 'offset', // Offset key limit: 10, // Number of items per page listId: '', // List identifier unique to the page pagination: 'default', // Pagination type: 'default', 'infinite' paginationPosition: 'after', // Pagination position: 'before', 'after', 'both' paginationNumPages: 10, // Number of page links to display in the pager classActive: 'elgg-state-selected', // CSS class pertinent to active elements classDisabled: 'elgg-state-disabled', // CSS class pertinent to disabled elements classLoading: 'elgg-state-loading', // CSS class pertinent to pending elements textNoResults: '', // Text displayed when no items were found in the list textNext: elgg.echo('next'), // Text for next link textPrev: elgg.echo('previous'), // Text for previous link keyTextBefore: 'lists:add:before', // Language key for before link (will receive limit as parameter) keyTextAfter: 'lists:add:after', // Language key for before link (will receive limit as parameter) lazyLoad: 10, // Number of pages to lazy load autoRefresh: 60, // Fetch new items at this interval (in seconds) reversed: false, // List is reversed that is new items are appended to the end of the list scrollTopOffset: -100, // Additional offset in pixels for when the page is scrolled to the top of the list listTime: 0, // Timestamp at which the list was generated, sent with AJAX requests showEffect: 'highlight', // jQuery UI effect used for toggling item visibility selectorDelete: '.elgg-menu-item-delete > a', // CSS selector of an anchor that will trigger a delete action }); // Public methods // Navigate to a page with a certain index // For default pagination type, page with pageIndex is loaded and displayed // For infinite pagination type, all pages in range from currently visible pages to the page with pageIndex are loaded and displayed $('.elgg-list').trigger('goToPage', [pageIndex]); // Trigger refresh // Reloads the page and appends new items if any // If no pageIndex is provided, it's determined by pagination type // goToPage parameter can be used to navigate to the page once new items have been fetched // goToPage flag is useful when a new post was made and you want to display the post to the user $('.elgg-list').trigger('fetchNewItems', [pageIndex, goToPage]); // Remove items from the list and reindex $('.elgg-list').trigger('removeItems', [$items]); // Add new items to the list $('.elgg-list').trigger('addFetchedItems', [ajaxData]); // Events // Event triggered whenever the list is first rendered // Callback will receive list options as a second parameter $('.elgg-list').on('ready', callback); // Event triggered whenever an item is added, removed or hidden from a list // Callback will receive list options as a second parameter $('.elgg-list').on('change', callback);