richardhj/contao-ajax_reload_element
Composer 安装命令:
composer require richardhj/contao-ajax_reload_element
包简介
AjaxReloadElement for Contao OpenSource CMS
README 文档
README
AjaxReloadElement gives you the possibility to fetch a particular front end module or content element via an ajax request.
Scroll down to see some nice animated screenshots 😎
Usage
You need to tick the box «Allow ajax reload» for the module/element in the back end input mask and include a JavaScript.
Basic/custom usage
If you are using jQuery you can use something like this. Modify this code snippet for your purposes. (Create a
j_myajaxreload.html5 template and include it in the layout.)
This code snippet will replace the HTML node .mod_my_module when clicking on a.reloadThisElementOnClick.
<script> $(".mod_my_module a.reloadThisElementOnClick").click(function (event) { var element; // Don't follow the link event.preventDefault(); // This is the elements div container like ".mod_my_module". "Allow ajax reload" has to be ticket for this element in the backend element = $(this).closest('[class^="ce_"],[class^="mod_"]'); // Add a css class to this element. An overlay and spinning icon can be set via css element.addClass('ajax-reload-element-overlay'); $.ajax({ method: 'POST', url: location.href, data: { // The data- attribute is set automatically ajax_reload_element: element.attr('data-ajax-reload-element') } }) .done(function (response, status, xhr) { if ('ok' === response.status) { // Replace the DOM element.replaceWith(response.html); } else { // Reload the page as fallback location.reload(); } }); }); </script>
Ajax Calendar
Add this to the cal_default.html5 template. Don't forget to activate ajax reload on the module.
<script> $(".calendar .head.previous a, .calendar .head.next a").click(function (event) { var element; // Get url of next/previous month var $url = window.location.origin + '/' + $(this).attr('href'); // Don't follow the link event.preventDefault(); // This is the element's div container like ".mod_my_module". "Allow ajax reload" has to be enabled for this module in the back end element = $(this).closest('[class^="ce_"],[class^="mod_"]'); // Add a css class to this element. An overlay and spinning icon can be set via css. element.addClass('ajax-reload-element-overlay'); $.ajax({ method: 'POST', url: $url, data: { // The data- attribute is set automatically ajax_reload_element: element.attr('data-ajax-reload-element') } }) .done(function (response, status, xhr) { if ('ok' === response.status) { // Replace the DOM element.replaceWith(response.html); } else { // Reload the page as fallback location.reload(); } }); }); </script>
Ajax forms
This one comes out of the box.
For all modules that integrate forms, you can tick the box «Update a form via ajax». Additionally, the template "j_ajaxforms" has to be included in the page layout. Instead of reloading the entire page, forms will update itself.
This feature is supported for all Contao core forms like change password, personal data, login form etc. and forms from third-party apps that are programmed in Contao style.
Demonstration
When the login was successful, the redirect processed in the login form will be followed.
Modal editing
This one is a bit more advanced.
First of all, this is the list of requirements for this plugin:
- jquery-ui.js (with at least the
Dialogwidget) - jquery.dialogOptions.js (can be optional, if you adjust the script)
- jQuery.modal-editing.js (the jQuery plugin written for this extension)
Then we create a template called j_modal_editing.js and include it in the page layout:
<?php $GLOBALS['TL_JAVASCRIPT'][] = 'files/js/jquery-ui.min.js'; $GLOBALS['TL_JAVASCRIPT'][] = 'files/js/jquery.dialogOptions.js'; $GLOBALS['TL_JAVASCRIPT'][] = 'files/js/jquery.modal-editing.js'; ?> <script> $(function () { $(document).modalEditing({ container: '.mm-list-participants', trigger: '.item a', element: 'mod::24', closeText: 'Schließen', /* If you want to internationalize the label, you can use (with Haste installed): <?= Haste\Util\Format::dcaLabel('default', 'close'); ?>*/ title: 'Edit element' }); $(document).modalEditing({ container: '.mm-list-participants', trigger: '.addUrl a', element: 'mod::24', closeText: 'Close', title: 'Add element' }); }); </script>
This code snippet is tailored to a MetaModel frontend editing. You set the id of the editing form as the element
option. In addition, you enable the ajax form as stated above (see paragraph «Ajax forms»).
Demonstration
richardhj/contao-ajax_reload_element 适用场景与选型建议
richardhj/contao-ajax_reload_element 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.37k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2016 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ajax」 「contao」 「ajaxform」 「ajax reload」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 richardhj/contao-ajax_reload_element 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 richardhj/contao-ajax_reload_element 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 richardhj/contao-ajax_reload_element 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Contao Open Source CMS
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Selenium4 (WebDriver) driver for Mink framework
laravel middleware to allow ajax only calls
Sitemap crawler/generator. For the given URL it will return sitemap XML file with URLs and images.
This is a laravel 4 package for the server and client side of datatables at http://datatables.net/
统计信息
- 总下载量: 4.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2016-06-01

