`
haohappy2
  • 浏览: 325816 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

How to use Drupal Behaviors

 
阅读更多

1. in your node add below scripts.

    <a href="#" id="togg-link">Click this link to toggle the content displayed below</a>
    <div id="togg">
    This content will be toggled open and closed using jQuery.
    Blah, blah, blah.
    </div>

 2. create a new file under   /sites/all/themes/xxx/patrick.js

Drupal 6:

Drupal.behaviors.togg = function (context) {
	$('a#togg-link:not(.togg-processed)', context).addClass('togg-processed').each(function () {
	$(this).click(function() {
		$("div#togg").toggle(400);
			return false;
		});
	});
};

 Drupal 7:

(function ($) {
	Drupal.behaviors.togg = {
		attach: function (context, settings) {
			$('a#togg-link:not(.togg-processed)', context).addClass('togg-processed').each(function() {
				$(this).click(function() {
					$("div#togg").toggle(400);
					return false;
				});
			});
		}
	};
})(jQuery);

3, please clear drupal cache

4. try to refresh the node and see the effect

分享到:
评论

相关推荐

    Drupal 8 Explained: Your Step-by-Step Guide to Drupal 8

    Drupal 8 Explained: Your Step-by-Step Guide to Drupal 8 (The Explained Series) by Stephen Burge English | 3 Apr. 2017 | ASIN: B06Y1VN2D7 | 283 Pages | AZW3 | 13.66 MB We're delighted to present the ...

    Drupal.8.for.Absolute.Beginners.1430264667

    You will then use Drush to apply a theme to Drupal, customizing everything to your liking, before publishing your work to the world. The book also covers some more advanced topics that beginners ...

    Drupal.8.Configuration.Management.1783985208

    For more advanced users, the book explains how to use the API to add custom configuration and how to upgrade custom modules to use the new Configuration Management system, covering some essential ...

    Drupal.8.Development.Beginners.Guide.2nd.Edition.epub

    If you are a developer who wants to use Drupal to enhance your website project and web application to manage content, this book is for you. Whether you are new to Drupal or an experienced web ...

    Decoupled Drupal in Practice

    You will learn how to architect and implement decoupled Drupal architectures across the stack―from building the back end and designing APIs to integrating with front-end technologies. You’ll also ...

    drupal的addtoany模块

    Drupal的AddToAny模块是一个非常实用的工具,尤其对于那些希望增强网站社交分享功能的用户而言。这个模块专为Drupal 6设计,旨在提供一种简便的方式,让访客能够订阅、收藏网页内容,并且能够通过电子邮件轻松地将...

    the definitive guide to drupal 7

    - **如何使用本书**(How to Use This Book) - 提供了指导读者如何根据自己的需求和兴趣来选择性阅读本书内容的建议。 - **Drupal 的工作原理**(How Drupal Works) - 解释了 Drupal 的基本架构和技术实现方式,...

    [Drupal] Drupal 响应式主题 开发教程 (英文版)

    Ideal for experienced Drupal developers, this book takes you through RWD basics and shows you how to build sites based on Aurora, Zen, and Omega—three popular base themes created by Drupal ...

    The.Definitive.Guide.to.Drupal.7

    #### 描述:本书为《The Definitive Guide to Drupal 7》(第一版),作者为 Benjamin Melançon,是一本详细介绍 Drupal 7 的专业书籍。 #### 知识点详解: ##### 一、Drupal 7 入门篇 1. **搭建 Drupal 7 网站 ...

    [Drupal] Drupal 7 媒体编程 (英文版)

    Learn how to use HTML5 for responsive web design and semantic websites, and implement a better cross-compatible web application ☆ 出版信息:☆ [作者信息] Liran Tal [出版机构] Packt Publishing ...

    Beginning Drupal 7 (英文)

    This book is for nontechnical users who need to use Drupal to manage content, as well as PHP developers who are new to Drupal.

    storybook-drupal-twig

    Failed to load config "@storybook/eslint-config-storybook" to extend from. Referenced from: /Users/daniel.lemon/coding/storybook-drupal-twig/node_modules/telejson/package.json @ ./node_modules/...

    drupal 6.12

    - To use Drupal's "Clean URLs" feature on an Apache web server, you will need the mod_rewrite module and the ability to use local .htaccess files. For Clean URLs support on IIS, see "Using Clean ...

Global site tag (gtag.js) - Google Analytics