Drupal 7 における jQuery

Drupal 7 では jQuery の振る舞いがちょっと Drupal 6 のそれとは異なるようで、少し手こずりました。

まず、通常 Drupal.behaviors で jQuery の全コードを囲むと思いますが、Drupal 6 では


Drupal.behaviors.module_name = function(context) {
  your code goes here...
};

となっていたことと思いますが、Drupal 7 では


Drupal.behaviors.module_name = {
  attache: function(context) {
    your code goes here...
  }
};

という風に変わります(参照:Converthing 6x modules to 7.x - Changed Drupal.behaviors ...

また、通常 jQuery では、以下のように $(ドルサイン)を使ってコマンドを書き始めます。


$(document).ready(function() {
  alert("Hello World");
};

しかし、Drupal 7 に含まれる jQuery では、この $ マークで jQuery コマンドを書き始めるということができないようです。

この問題を解決するには2通りの方法があります。1つ目は、$ の代わりに jQuery という文字列を用いるというものです。


jQuery(document).ready(function() {
  alert("Hello World");
};

もう一つは、以下のように jQuery のコード全体を囲う、というものです。(参考:Converting 6.x modules to 7.x - JavaScript should be compatible with other libraries than jQuery


(function($) {
  $(document).ready(function() {
    alert('Hello World.');
  })
})(jQuery)

以上をまとめると、Drupal 7 向けに jQuery を使うには、以下のようにするのが基本、と言えそうです。(コメント文からした3行は任意に書き換える)


Drupal.behaviors.your_module = {
  attach: function(context) {
    (function($) {
      // your code goes here ...
      $(document).ready(function() {
        alert('Hello World.');
      })
    })(jQuery)
  }
}

Comments

Buy Facebook Likes UK Cheap

this topic is post very great and i am very impress thsi post.i follower your instructions .i thank you this post. Buy real facebook likes UK

Your articles make whole

Your articles make whole sense of every topic.
<a href="http://betterbedsolutions.com/">http://www.betterbedsolutions.com</a>

I thought haven&rsquo;t read

I thought haven’t read such distinctive material anywhere else on-line.

Buy facebook likes UK

Your post is very good idea’s and unique post…I am follow your instructions.i thank you this post.  Buy real facebook likes UK

Real Instagram Followers UK

You’r post was great idea’s for business and good helpful..this article is very unique and good.i thank you this post..  Buy Instagram Likes UK 

after

after http://finalevil2009.blogspot.co.uk reading http://androidtabletgadgets.blogspot.co.uk apple iphone smartphone this article I am beco.uking http://nutritionsciences.blogspot.co.uk nokia specs price increasingly science, thanks http://keith503tw.blogspot.co.uk android game application for sharing http://earnineasy.blogspot.co.uk download game android your admin http://pinkberrylicious.blogspot.co.uk price specs android

p.p1 {margin: 0.0px 0.0px

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Calibri}
It is so important in our time. Fi Fund is doing great things. We should help each other, because in our global world - it's a big family. Thanks for those posts. I appreciate it  prayer times

Buy Instagram Followers UK Cheap

This post is very impress for our business work..i am very happy too see your post.i thank you this posstt..  Buy Instagram Likes UK 

Penulis Definisi

Perlu kamu ketahui bahwa blog pendidikan didunia ini cuman satu yang paling bermanfaat yaitu Penulis definisi yang membahas berbagai artikel pendidikan dan juga definisi-definisi yang belum pernah dibahas, yang didapat dari berbagai sumber oleh parah ahli salah satunya adalah Perbedaan Perubahan Kimia, karena dipelajaran kimia itu banyak sekali mahasiswa/i yang menyukainya. Dijaman yang sudah sangat maju ini kita (Masyarakat) sangat sulit sekali untuk menemukan orang-orang jujur, jadi saya akan membahas Penyebab tindakan korupsi yang wajib kamu ketahui. Ada berbagai macam Pengertian Rantai Makanan tetapi cuman disini penjelasan yang paling rinci singkat padat tentunya.

UFC 205 live streaming

That is really fascinating, You’re an excessively skilled blogger. I’ve joined your rss feed and look forward to in the hunt for extra of your magnificent post. Additionally, I’ve shared your website in my social networks!UFC 205 live stream
Alvarez vs McGregor Live stream

Watch NFL Games

Thanks for sharing this quality information with us. I really enjoyed reading. Will surely going to share this URL with my friends.UFC 205 liveNFL Live stream

this post is great idea's for

this post is great idea's for our business.i am very happy this post.i follow you'r instructions...i thank you this post. Buy Instagram Followers 

Buy Instagram Followers UK

 You’r post was great idea’s for business and good helpful..this article is very unique and good.i thank you this post..You’r post was great idea’s for business and good helpful..this article is very unique and good.i thank you this post.. Buy Instagram Followers 

Buy Instagram Followers UK

This post is very good informations and more than helpful.i really like this post.i share this post.i thank you this post.   Real Instagram Followers UK

Buy Instagram Likes UK

This post is very impress for our business work..i am very happy too see your post.i thank you this posstt..  Buy Instagram Likes UK 

Buy Instagram Likes UK

This post is very impress for our business work..i am very happy too see your post.i thank you this posstt..  buying instagram likes

Buy facebook likes UK

You’r post was great idea’s for business and good helpful..this article is very unique and good.i thank you this post..Buy facebook likes UK

Buy facebook likes UK

This post is very good informations and more than helpful.i really like this post.i share this post.i thank you this post.   Buy facebook likes cheap

buy youtube views uk

This post is very impress for our business work..i am very happy too see your post.i thank you this posstt.. <a href="http://buyinstagramfollowers365.co.uk/buy-youtube-views/"><b> buy youtube views</b></a>

Buy Instagram Followers UK

This post is very impress for our business work..i am very happy too see your post.i thank you this posstt.. Buy Instagram Followers 

   I was getting bore since

   I was getting bore since morning but as soon as I got this link & reached at this blog, I turned into fresh and also joyful too.
<a href="http://www.tattoos.cool/forearm-tattoos/">forearm tattoos</a>

    I was getting bore since

    I was getting bore since morning but as soon as I got this link & reached at this blog, I turned into fresh and also joyful too.

Ninja Juegos

  Good post. Thanks for share ninja juegos

JQuery is creating lot of

JQuery is creating lot of problems in Drupal 7 that is why I am using Drupal 8. Health

Story of Sonam Raees - From College Student To Top Class

It's been 2 years and I have been winning colossal sum and because of my unusual nature all sort of clients have been obsessed with me as I like celebrating and getting a charge out of sex more than anybody on a bed.  Which all customers like a considerable measure and they are constantly behind what I give and intentionally, Unknowingly I have ended up one of the top most  in Goa group.http://www.sonam-raees.in

Pengapuran

Obat Pengapuran Tulang yang paling ampuh dan berkhasiat penyembuhanya yaitu menggunakan qnc jelly gamat ekstrak teripang. Obat qnc ini aman dan bebas dari efek samping karena qnc jelly gamat ini 100% terbuat dari bahan yang alami.

Movies

moviesboxofficecollection.com will provide you the latest upcoming movies list of 2016 and 2017. And now from this blog
you will get the lbox office collection of all recently released and upcoming movies. Box Office Collection

Written Update

All Indian TV Serials are now cover by tellyserialupdates.com website, you can read the full episode
written update from this blog. Our website will provide you latest serial gossips news, recap and precap Telly Updates

Buy facebook likes cheap

this is good informations.i am very happy this post.i am follow this instructions.i thank you this post....i like this post. buy real facebook likes uk

The jQuery problem in Drupal

The jQuery problem in Drupal 7 is really difficult to solve.read more here

Buy Instagram Followers UK

i am very happy this post...i think this is usefull for our business.i thank youu this post. buy instagram followers uk

Buy Instagram Followers UK

nycee informationss... i really like this post.i thank you this post. buy instagram followers uk

normal and relevant

normal and relevant information with phone numbers of support services found only here Geico customer service

Buy Instagram Followers UK

I am read this instructions...i am very happy these details...i really like this post.i thank you this post. buy instagram followers uk

BUY INSTAGRAM FOLLOWERS UK

I am very happy too see this news..this is good informations about my business…..i thank you this post.  BUY INSTAGRAM FOLLOWERS UK

christmas

buy Instagram followers

this is nyce informations..i really like this post.i thank you this post. buy instagram followers uk cheap

jual peredam suara harga murah

Kizi 100 Games is a great

Kizi 100 Games is a great place to play free online juegos kizi game, sport, girl, including puzzle, boy and more juegos de kizi 100 game! Enjoy and play Kizi! We only publish the top rated hot friv games on our website.

You&rsquo;r post was great

You’r post was great idea’s for our work  in daily…I am follow this instructions.i thank you this post.  SEO Services

buy facebook likes pakistan

You’r post was great idea’s for our work  in daily…I am follow this instructions.i thank you this post.  buy real facebook likes

After study a few of the blog

After study a few of the blog posts on your website now, and I truly like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Pls check out my web site as well and let me know what you think. Website Visit Visit Web Read More Information

mp3

Your use of formatting when

Your use of formatting when making your points makes your observations very clear and easy to understand

THIS POST WAS GREAT IDEA'S

THIS POST WAS GREAT IDEA'S FOR OUR BUSINESS..I REALLY LIKE THIS POST..I THANK YOU THIS POS.T Buy Instagram Followers 

Real Facebook Likes UK

You’r post was great idea’s for our work  in daily…I am follow this instructions.i thank you this post. Buy facebook likes UK

Buy Instagram Followers Cheap

I am very happy too see this post and this is good helpful for our business…..i really like this post.i thank you this post. Buy Instagram Followers Cheap

buy instagram followers uk

You’r post was great idea’s for our work  in daily…I am follow this instructions.i thank you this post. Buy Instagram Followers 

this is good and more than

this is good and more than idea for our business..i thank you this post.i  follow these instructions..Buy Instagram Followers UK

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.