搜尋
首頁php教程php手册Drupal 7 扩展Overlay的方法详解?

在Drupal 7 以后我们可以轻松使用类似模态框的overlay模块来实现一个弹出层。下面我介绍2个实例,如何自定义扩展Overlay。

Drupal overlay examples

扩展 Overlay 模块头部显示用户头像实例

在你的自定义模块中加入overlay脚本JS文件,通过overlay的钩子:

function mymodule_overlay_child_initialize() {
  // Add our custom JavaScript.
  drupal_add_js(drupal_get_path('module', 'mymodule') . '/overlay-child.js');
}

然后通过Add JS 头像路径到header中。

<?php
/**
 * @see hook_js_alter().
 */
function yourtheme_js_alter(&$javascript) {
    global $theme, $user;
    if (isset($user->picture) && is_string($user->picture)) {
        $picture = file_load($user->picture);
    } elseif (isset($user->picture) && is_object($user->picture)) {
        $picture = $user->picture;
    }
    if (isset($picture) && $picture && isset($picture->uri)) {
        $filepath = file_create_url($picture->uri);
        $javascript[&#39;settings&#39;][&#39;data&#39;][][&#39;user_picture&#39;] = $filepath;
    }
}
?>

在overlay - child.js文件中加入以下Javascript 代码:

(function ($) {
    Drupal.behaviors.yourmodule = {
        attach : function (context) {
            $(&#39;#overlay:not(.your-module-adjusted)&#39;, context).each(function () {
                if (Drupal.settings.user_picture) {
                    $(&#39;#overlay-titlebar&#39;, this).css(&#39;padding-left&#39;, 0);
                    $(&#39;#overlay-title-wrapper&#39;, this).find(&#39;h1#overlay-title&#39;).prepend(&#39;<img  src="/static/imghwm/default1.png"  data-src="&#39; + Drupal.settings.user_picture + &#39;"  class="lazy"   / alt="Drupal 7 扩展Overlay的方法详解? " >&#39;);
                }
            }).addClass(&#39;your-module-adjusted&#39;);
            $(&#39;.overlay .footer&#39;).hide();
        }
    };
})(jQuery);

完成后,你就可以看到如上面的图片的效果。

修改overlay覆盖层的宽度和隐藏元素实例

下面这个例子向你展示如何修改overlay (覆盖层) 内的内容,当一个指定的节点类型(test)被展示在overlay 覆盖层。这个脚本向你展示修改overlay层的宽度为450px 和 隐藏一些不想见到的元素。


在你的模块中同样需要想上面的例子那样加入overlay-child.js脚本。

在overlay-child.js文件中加入以下Javascript 代码:

(function ($) {
    // Adjust the overlay dimensions.
    Drupal.behaviors.myModule = {
        attach : function (context) {
            $(&#39;#overlay:not(.mymodule-adjusted)&#39;, context).each(function () {
                var $test = $(this).find(&#39;.node-type-test&#39;);
                if ($test.length) {
                    // adjust the overlay
                    $(this).css({
                        &#39;width&#39; : &#39;450px&#39;,
                        &#39;min-width&#39; : &#39;450px&#39;
                    });
                    www.phprm.com
                    $(&#39;.add-or-remove-shortcuts&#39;, this).hide(); // hide "add short-cut" button
                    $(&#39;#branding&#39;, this).hide(); // hide branding container
                }
            }).addClass(&#39;mymodule-adjusted&#39;);
        }
    };
})(jQuery);

如果你想修改所有overlay层里的布局,请找到overlay.tpl.php然后修改它。

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境