定制 srhinow/srlayer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

srhinow/srlayer

Composer 安装命令:

composer require srhinow/srlayer

包简介

Dependency-free layer/popup front-end module for Contao 5. Displays a configurable overlay without any JavaScript library. Supports auto-show on page load, click triggers via CSS class or rel="openlayer", GET-parameter triggers for landing pages, and cookie/session-based display control.

README 文档

README

A configurable layer/popup module for Contao CMS 5.x.
No jQuery, no external dependencies — pure vanilla JavaScript.

Requirements

  • PHP ^8.2
  • Contao ^5.3

Installation

composer require srhinow/srlayer

Then run the Contao install tool (or contao:migrate) to apply the database schema:

php bin/console contao:migrate --no-interaction
php bin/console assets:install --symlink

Usage

  1. Go to Modules in the Contao back end and create a new module of type SR-Layer.
  2. Configure the module (see options below).
  3. Include the module in a page layout or add it to a page via an article.

The module renders an overlay and a layer container. Both elements are hidden by default and shown/hidden via JavaScript.

Module options

Layer content (layer_legend)

FieldDescription
Layer contentHTML content of the layer. Contao insert tags like {{insert_content::23}} or {{insert_article::5}} are fully supported.
CSS fileOptional custom CSS file (file picker). If none is selected the bundled srl_default.css is used automatically.

Visibility settings (show_legend)

Controls when the layer is triggered.

FieldDescription
Show without parameterThe layer opens immediately on page load.
Open layer via linkLinks with the CSS class openlayer (or rel="openlayer") open the layer on click. The layer is rendered but stays hidden until a matching link is clicked.
GET parameterThe layer opens when the given key appears in the URL query string — e.g. set srl and the layer opens for https://example.com/page?srl=1. The value of the parameter is irrelevant; only the key is matched.
Display delay (ms)Number of milliseconds to wait before opening the layer after the page has loaded (e.g. 2000 = 2 seconds). Works together with Show without parameter and GET parameter.
Show fromDate/time from which the layer becomes active.
Show untilDate/time after which the layer is no longer shown.

Tip: Show without parameter and GET parameter can both be active at the same time. The layer opens if either condition is met.

Session cookie (session_legend)

FieldDescription
Set session cookieThe layer is shown only once per browser session. On the next page load within the same session it is suppressed.

Domain cookie (cookie_legend)

Set domain cookie

Restrict repeated display via a persistent cookie.

FieldDefaultDescription
Cookie nameLAYER_<id>_COOKIEName of the cookie. Leave empty to use the auto-generated name.
Cookie lifetime (seconds)3600How long the cookie persists. 86400 = 1 day, 604800 = 1 week.

When active, the layer is shown once and then suppressed for the cookie lifetime. The cookie is set by the server on the first display.

Evaluate domain cookie

Show the layer only when a specific cookie is already present in the browser. This is useful for showing a popup to users who previously submitted a form (see Form-triggered cookies).

FieldDescription
Cookie nameExact name of the cookie that must be present for the layer to appear.

Expert options (expert_legend)

FieldDescription
Hide overlaySuppresses the semi-transparent background overlay. Only the layer container is rendered.

JavaScript options (js_legend)

Activate this section to override the default element IDs, CSS classes and behaviour.

FieldDefaultDescription
Overlay IDsrl_overLayid attribute of the overlay <div>.
Layer IDsrl_layerid attribute of the layer <div>.
Open link classopenlayerCSS class that turns any <a> tag into an open-trigger.
Close button IDsrl_closeBtnid of the built-in close button inside the layer.
Close link classsrl_closerAny element with this class closes the layer on click.
Overlay opacity0.7Opacity of the background overlay (0.0 = invisible, 1.0 = fully opaque).
Transition speed (ms)300Duration of the fade-in/fade-out animation in milliseconds. Set to 0 to disable animation.
Layer width (px)(CSS default)Fixed pixel width applied to the layer element via JavaScript. Leave empty to rely on CSS.
Layer height (px)(CSS default)Fixed pixel height applied to the layer element via JavaScript.
Close with ESC keyWhen checked, pressing the Escape key closes the layer.
Close by clicking overlayWhen checked, clicking the background overlay closes the layer.
Center horizontallyJavaScript keeps the layer centered on the X axis, even on window resize.
Center verticallyJavaScript keeps the layer centered on the Y axis, even on window resize.
Additional JS optionsRaw key-value pairs appended to the SrLayer constructor. See below.

Styling

The default stylesheet (bundles/srhinowsrlayer/css/srl_default.css) sets up a centered, fixed-position popup with a dark overlay. Override any rule in your own CSS or select a custom stylesheet in the module settings.

The default HTML structure rendered by the module:

<div id="srl_overLay"></div>
<div id="srl_layer">
    <div id="srl_closeBtn">Schließen</div>
    <div class="srl_content">
        <!-- your layer content -->
    </div>
</div>

The close button label uses the translatable string MSC.srl_close (German: Schließen, English: Close, and several other languages).

Opening the layer from a link

Set the module option Open layer via link and add the CSS class openlayer to any anchor tag on the same page:

<a href="#" class="openlayer">Open popup</a>

Alternatively use the rel attribute (legacy):

<a href="#" rel="openlayer">Open popup</a>

Closing the layer from a custom element

Any element with the CSS class srl_closer (or the class configured in Close link class) closes the layer when clicked. You can place these elements inside or outside the layer container:

<a href="#" class="srl_closer">Cancel</a>

Additional JS options

The Additional JS options field lets you pass extra key-value pairs directly to the SrLayer constructor without writing any PHP. The content is inserted verbatim, so standard JavaScript syntax applies:

showNow: true, centerX: false

The full list of available options with their defaults:

new SrLayer({
    overLayID:          'srl_overLay',
    layerID:            'srl_layer',
    closeID:            'srl_closeBtn',
    closeClass:         'srl_closer',
    openClass:          'openlayer',
    overLayOpacity:     0.7,
    closePerLayerClick: true,
    closePerEsc:        true,
    mkLinkEvents:       true,
    centerX:            true,
    centerY:            true,
    duration:           300,   // ms
    layerWidth:         0,     // 0 = use CSS
    layerHeight:        0,     // 0 = use CSS
    delay:              0,     // ms — only delays auto-open; click listeners register immediately
    openParam:          '',    // GET parameter key whose presence in a link href opens the layer on click
    showNow:            false
});

Form-triggered cookies

Use the PrepareFormDataListener to set a cookie when a Contao form is submitted. Add hidden fields to the form:

Field nameExample valueDescription
srlayer_set_cookieNEWSLETTER_COOKIEName of the cookie to set on submit.
srlayer_check_fieldemailThe form field that must be non-empty for the cookie to be set.
srlayer_cookie_duration2592000Cookie lifetime in seconds (default: 3600).

Workflow example — show a newsletter teaser only to visitors who have not yet subscribed:

  1. Create a newsletter signup form with the hidden fields above.
  2. Create an SR-Layer module with Evaluate domain cookieNEWSLETTER_COOKIE.
  3. Add both to the page layout.

After the visitor submits the form the cookie is set and the layer is suppressed on all future visits.

Multilingual back end

The module back end labels are available in:

de · en · cs · es · fr · it · nl · pl · pt · ru

Development

Running tests

The unit tests require PHPUnit and symfony/http-foundation. When working inside a Contao project where the bundle is symlinked into vendor/, point the bootstrap to the project's autoloader:

SRLAYER_AUTOLOAD=/path/to/contao5/vendor/autoload.php phpunit

For standalone use, run composer install in the package directory first, then:

composer test

Code style

PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix

Changelog

See CHANGELOG.md.

License

LGPL-3.0-or-later — see LICENSE for details.
Author: Sven Rhinow

srhinow/srlayer 适用场景与选型建议

srhinow/srlayer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.33k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「layer」 「modal」 「lightbox」 「contao」 「popup」 「overlay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 srhinow/srlayer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 srhinow/srlayer 我们能提供哪些服务?
定制开发 / 二次开发

基于 srhinow/srlayer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2017-06-20