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

The subject and haven't had

The subject and haven't had any luck up until this point, You just got a new biggest fan!recuperacao de hd

online english speech program

SpeechSchool.TV is the world's #1 provider of online speech training.We're based on campus at a major university and in central London.  Whether you want to learn to speak with a Standard English accent or become a seasoned public speaker, our courses can transform your confidence.

with me. I am appreciating it

with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! All the beshigh pr

What Is Apple Pay?

It s easy to lost your weight and What Is Apple Pay? must be do exercise regular basis and i am happy to read your valuable article.

Good

I really enjoying this essay writing australia site, your blog have good efforts and also nice stuff. I really love this type of blogs, I definitely sharing this rushessay.com site, they are like this type of blogs. We usually are promoting essay writingweb sites, most of college students follows this type of web sites. Good

Sydney Swimmers

Thanks for giving information on pg year .Sydney Swimmers I get lot of new information from this post . You are nice writer the post is written very well .

location-based marketing rank

location-based marketing rank very well search engine finding on internet and provide you information about how many Passbeemedia people check in for a certain era or business.

We stand behind our products

We stand behind our products quality and ensure that people can use them without any worries. We even take up the concern of our customers directly to the watch manufacturers if we get any and make sure that watches of concerned people are fixed as quickly as possible. Original watches in Pakistan Watches brands in Pakistan Branded watches in Pakistan

So whether you are looking

So whether you are looking for perfect property or an ideal investment, al farooq real estate is your perfect partner to work with and find real estate solutions in Ajman. Villa for Sale in UAE Villa for Rent in UAE Buy properties in UAE

Inside botany, a sapling is

Inside botany, a sapling is usually a perennial vegetable with an elongated base, or maybe trunk area, encouraging limbs as well as foliage for most kinds. In certain usages, this is of the sapling can be narrower, which includes solely woody plant life having supplementary expansion.webryze-seo

This is a fantastic website

This is a fantastic website and I can not recommend you guys enough. Full of useful resource and great layout very easy on the eyes. Please do keep up this great work... . http://ibc.betnesia.com/

You should comment on the

You should comment on the competition comparison of the blog. You can highlight it's mind boggling. Your blog exploration/tour will broaden your conversions. http://ibetsbo.com/

paraphrase website

Thank you for this interesting post about the forest and the trees. I have long been interested in nature, so your post is useful to me. Thank you.

Perché una ditta individuale

Perché una ditta individuale è indistinguibile metric unit of measurement suo proprietario, unica tassazione individuale è abbastanza semplice. Il reddito guadagnato costi ditta individuale public prosecutor una ditta individuale è il reddito guadagnato metric unit of measurement suo proprietario. world organisation unico titolare riporta il solo reddito e / o perdite e costi compilando e la presentazione di una schema C, insieme con lo customary individuale.

We stand behind our products

We stand behind our products quality and ensure that people can use them without any worries. We even take up the concern of our customers directly to the watch manufacturers if we get any and make sure that watches of concerned people are fixed as quickly as possible. http://7star.pk/ http://7star.pk/33_citizen-watches http://7star.pk/new-products

Reply

Cara pemesanan obat herbal ace maxs I think this is a very good article, And this could be a recommendation for me. Same like a Pengobatan epilepsi

salam sehat

Reply

Cara mengeluarkan batu ginjal tanpa operasi is a very Nice info sir, I'm very like this article, because same like a Kista tumbuh lagi setelah operasi .......................

Obat Step anak

I am very pleased to be able to visit this website , Because the news is very interesting to see and thanks for providing this website to say joined commented

This continually is amazing

This continually is amazing to me how bloggers such as yourself can find the time and also the dedication to keep on creating fantastic blog posts. This is wonderful and one of my have to rineganlox read on the web. I simply want to say thanks.

A brief story you have shared

A brief story you have shared in this post I have visited uchihalumia this post first time. I want to say thanks for this post and storify.

Thanks for this great post, i

Thanks for this great post, i aguscreated find it very interesting and very well thought out and put together. I look forward to reading your work in the future. Thanks for sharing. my blog: remikanews , remikareseplah and rebelmouse.

thank

thank

I have seen this best best

I have seen this best best website. Your website very updated. Thanks for taking time to share this useful post about Drupal behavior. Rubber flooring with slip resistance from slip-not.co.uk

I am really impressed by this

I am really impressed by this on-line journal! extraordinarily clear clarification of problems is given and it's receptive each living soul. I actually have perused your post, really you've got given this extraordinary informative knowledge regarding it. Best Village Resort

Obat Asam Lambung

Drupal is one of software in this world which is used by many users. it is usefull for personal or business. Keep going on.Obat Asam Lambung

HELP!Someone send for me

HELP!Someone send for me document to learn Drupal. I need it.Mail: vanchuyenkienvangvietnam@gmail.comI code for Taxi tai kien vang Thanks fo that!

موقع مصرى

thanks alot

We stand behind our products

We stand behind our products quality and ensure that people can use them without any worries. We even take up the concern of our customers directly to the watch manufacturers if we get any and make sure that watches of concerned people are fixed as quickly as possible. http://7star.pk/ http://7star.pk/33_citizen-watches http://7star.pk/new-products

THanks

I feel very happy after reading your article . Because with such that Icould broaden my knowledge of science and technology and other sciences .The point of all this is when I read your website , I became inspired to write and learn again
Obat Herbal Green World
Obat Penyakit Diabetes
Obat Maag
Tips Tubuh Langsing
Obat Pelancar Peredaran Darah
Obat Gagal Ginjal

You have a great sense of

You have a great sense of writing I must say. Your post has those facts which are not accessible from anywhere else. It’s my humble request to u please keep writing such remarkable articles. <a href=" http://goo.gl/swRR59 ">Vig Power Capsule</a>
<a href=" http://distributorgreenworldindonesia.web.id/slimming-capsule ">slimming capsule</a>

dsds

and you wont belive that i easned so much 
http://2015rugbyworldcuplivestreaming.com/watch-england-v-wales-live-str... ">England vs Wales rugby worl dcup 2015 live streaming </a>

I am very happy to be on the

I am very happy to be on the website when you though the words china but I can understand what the intent and purpose of your writing this
Obat Penyakit Kuning
Obat Impotensi
Obat Herbal Rambut Rontok
Obat Tumor Bibir

Drupal

Drupal 8 is coming!

thansk

thansk

thanks for the info it , we

thanks for the info it , we as human beings must respect each other and concrete examples in the online world is the best to exchange comments . may god bless ingsaalloh
<

marun

Cilalahttp://obatparuparutradisional.blogspot.com
http://pengobatanalternatif-ampuh.blogspot.com/2015/05/obat-herbal-penet...
http://obatparuparubasah.weebly.com/

great

reply

A full 21% of youth are defined as heavy media users who spend more than 16 hours with media a day. Another 63% are defined as moderate users who use media 3-16 hours a day. Youth who fall into the light user category are those who consume less than 3 hours of media a day. Jamu kuat ml alami Jamu kuat ml Obat kuat seks Obat kuat ml http://saco-indonesia.com/?backlink=222&idd=32997/Obat-Anemia

reply

Within these averages there are significant differences and knowing where your child or teen falls within these ranges is the first step in understanding whether or not you want to adjust the amount of time they spend online, or if you suspect a larger problem is brewing. Tips bersetubuh agar kuat dan tahan lama Tips bersetubuh agar tahan lama Cara mengatasi masalah ejakulasi dini pada pria Obat kuat bercinta alami Obat kuat bercinta

reply

Bullying can be defined by many things. It's teasing, name-calling, stereotyping, fighting, exclusion, spreading rumors, public shaming and aggressive intimidation. It can be in person and online. But it can no longer be considered a rite of passage that strengthens character, new research suggests. Obat herbal tahan lama saat berhubungan intim Obat tahan lama berhubungan intim di apotik Obat tahan lama berhubungan intim Cara agar tahan lama diatas ranjang makanan yang bisa bikin tahan lama bercinta

Thanks

Thanks for sharing. it is very useful information. Thanks a lot

thanks Cara Mengobati Sendi

They will quit teasing and

They will quit teasing and having a laugh at you after you used the methods on how to make your penis bigger naturally. Maybe you have been teased to have a tiny winner when you believe it is all right? Do you think you're one of the average guys who had the regular size penis which is pretty much the size of your thumb? Then stop, go through, and pay attention to what this post is going to tell you. hopes this works but learn more simply click here

very good article and check

very good article and check for the latest <a href="http://www.aprilfoolpranks2015.com/2015/10/happy-diwali-wishes-cards-greetings-english-hindi-sms-2015.html">Happy diwali 2015 sms in English</a> very good right? if you are willing  to check more visit here <a href="http://www.aprilfoolpranks2015.com/2015/10/happy-diwali-wishes-cards-greetings-english-hindi-sms-2015.html">Happy diwali 2015 sms in hindi</a>

happy new year 2016

This is great.Now, you can send new year pictures to your friends & family.http://www.happynewyear2016s.org/2015/10/happy-new-year-pictures-2016.html

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.