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

Thanks

goldenslotThanks to the information provided in this too. It is Me too

Finding the right person to

Finding the right person to have an Infertility Counseling with can be a daunting task. But once you have chosen the right person, you will be amazed at what you can learn. counselingeducation.org

Need how you can actually

Need how you can actually enhance publicity for a web website page, within a positive aside from steady methods? You will most likely not understand who yet many internet site workers use the identical key to set up visitors for the purpose of essentially very little.http://www.segmenters.com/

exam

nice

website click here

Recent times when net has so

Recent times when net has so often gossip mongering and clog; your proportion really refreshes me.new york city tours

Ayers Rock is probably the

Ayers Rock is probably the most popular option for campervan tourists coming to this region, but an alternative that is closer to Alice and every bit as rewarding for a self drive excursion is the West Macdonnell National Park. ormistoneducation.org

I recently found many useful

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. more followers youtube paid subscriptions

It has become common

It has become common knowledge that the toys we give our children to play with as a child can assist their learning experience. It can be argued that every single toy we provide our child helps them in some way to develop their skills and personality and is therefore 'educational' creativeeducationsummit.org

Civic also represents Honda's

Civic also represents Honda's first attempt at producing Hybrid Cars with the Civic Hybrid model which incidentally continues to do well in the US market. civicsports.org

Our own fellow inhabitants of

Our own fellow inhabitants of Kansas Metropolis began while using the industry-leading Sundek swimming deck covering products about 40 years back. Whether you might be building a fresh pool and also want any cooler as compared to concrete, non-slip surface area or remodeling a preexisting pool to be able to freshen the particular image, the Sundek Vintage Texture Overlay System is a superb solution. Epoxy Coatings

Dell Battery pack Latitude

Dell Battery pack Latitude E6400 E6410 E6500 E6510 Characteristic M2400 M4400 M4500 Electric batteries had long been being believe it or not the important chargeable notebook power packs any time. Businesses revered him / her considering that benefit were sensibly tiny and so they had long been being created with a more proficiency.http://www.electronicsegment.com/

The information

goldenslotThanks to the information provided in this too. It is Me too  

Thanks

goldenslotThanks to the information provided in this too. It is Me too   

An immense moonlike of

An immense moonlike of commendation, reserve it up. girlsdoporn

Never found such informative

Never found such informative articles sidney lucius

As a business, art investing

As a business, art investing can mean quite a return if the piece is held for long enough. Many investors new to the art buying industry have been attracted by the advertising of record art sales which have taken place in recent years. www.businessinarts.org

Can we unite the small

Can we unite the small businesses in the United States and use the synergy created and the efficiencies attained so they can compete against the big boys and multi-national corporate conglomerates? www.unitedsmallbusiness.org

Working at home, from home,

Working at home, from home, in your pajamas, in the nude, at the beach, working from bed or the easy chair - these are all the images and joys of home working that Kate and I enjoy and many others too. www.thehomestop.org

Three programs are available

Three programs are available to assist home buyers to purchase a home that the federal government considers rural property. Rural Home Loans, Rural Housing: Farm Labor Housing Loans and Grants and Rural Housing: Housing Repair Loans and Grants all enable eligible loan applicants to purchase or repair rural homes. All three loans fall under the U.S. repair-home.org

A tree commonly has numerous

A tree commonly has numerous optional extensions underpinned clear of the ground by the storage compartment. This trunk regularly contains woody tissue for quality, and vascular tissue to convey materials starting with one piece of the tree then onto the next.resume form

Thank you very much for this

Thank you very much for this great post.
free facebook likes
free youtube views

This specific paper

This specific paper excellent, in addition to My spouse and i enjoy all of the work that you have put in it. I'm sure that you will be setting up a actually intriguing point. jual besi beton perusahaan besi per kilo I seemed to be additionally impressed. Very good perform!

Stunning, this is truly

Stunning, this is truly fascinating perusing. I am happy I discovered this and got the opportunity to peruse it. Awesome occupation on this substance. I like it. Emotional Hook Formula Review

thaks INFORMATION

melissa : http://bit.ly/1TAxnHD  safira : http://bit.ly/1TXr2W9  nadya : http://bit.ly/1OWxAN4  rossa : http://bit.ly/1QCqy1Z /http://bit.ly/1QCqy1Z  silvia : http://bit.ly/1TXr8Nu  natalia : http://bit.ly/21S5bkz  bilqis : http://bit.ly/1QCqKhR  anggelina  : http://bit.ly/21OZZkP

Thanks

goldenslotThe information you provide is information that is useful to me, not ever.

todaygames

Do you like playing games? Now you can download games for pc free full version. You can download games full version for PC for free from our blog. There are countless lists of games that are available for you to download Download games for PC. Download our latest pc games see a full explanation.

You guys make it really easy

You guys make it really easy for all the folks out there. car covers

Thanks

goldenslotThe information you provide is information that is useful to me, not ever. 

Thanks

goldenslotThe information you provide is information that is useful to me, not ever.    

Thanks

goldenslotThanks to the information provided in this too. It is Me too

Thanks to

goldenslotThanks to the information provided in this too. It is Me too

Exictly whit i greit webstte

Exictly whit i greit webstte you've here. Pleise updite tt regulirly. Thts subject ts my curtostty. Thinks. . . See more

Xorauguynafxvar

FaurpardNah xaikalitag Tofenance http://usillumaror.com - iziananatt adanypsunsell http://gussannghor.com lanowsoms

or to pick a business

or to pick a business partner,"Says carol mongo.It's perhaps telling that many of the designers that are really successful today, like calvin klein or tom ford, are involved in every aspect of the business from licensing strategies to ad campaigns to actually designing the clothes. - See more at: Crocodile Jacket | amazon jacket

Will you be able to do that?

Will you be able to do that? resident evil Jacket on Amazon

In this session we'll discuss

In this session we'll discuss how agile analysis testinside HP2-B104 and project management processes can be applied to the specific and unique situations presented in a Drupal implementation. We'll discuss the setting of expectations for HP2-B104 exam

Sports

so nice of you. you are the awesome man fast 8 vest

re

we are great here, but things will change soon star wars finn jacket

バネ棒をベルトの接合部に通しておき、このバネ棒バーバリー

バネ棒をベルトの接合部に通しておき、このバネ棒バーバリー 腕時計 BU9702 メンズをラグにはめ込むスタイルが確立し、現代まで続くことになる。これと併行してコマをつないで装着感と強度を両立させたブレスレットも登場・発展していき、やはりバネ棒を介

A really great article. I am

A really great article. I am genuinely thankful on your article. You can find lots of approaches following visiting ones post. My partner and i has been specifically looking for. Cheers intended for such post as well as remember to keep writing. letter of reinstatement

There are so many different

There are so many different aspects when it comes to this topic. Thank you so much for sharing your knowledge on this particular aspect. pratamaandi78  in farmotor

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

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.