Warning: Table './drupal_fandt_old/accesslog' is marked as crashed and last (automatic?) repair failed query: SELECT uid, timestamp FROM accesslog WHERE (path = 'node/142' OR uid > 0) AND sid = '6aac473b7f7fda010fac2a1370b4417e' ORDER BY timestamp DESC LIMIT 0, 1 in /var/www/akishige/fandt/includes/database.mysqli.inc on line 128
Drupal 7 における jQuery | FOREST & trees

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

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

Thanks to

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

A debt of gratitude is in

A debt of gratitude is in order for the blog entry mate! Keep them coming... fahrrad navi

if you are from any british

if you are from any british university and looking for expert services for assignments. Do not waste your time and contact our team immediately as we are booking our clients on advance. John Crestani Super Affiliate System Review

thanks for information

Blackberry Messenger (BBM) merupakan aplikasi chatting yang sangat populer di dunia, Selain terkenal sebagai aplikasi pesan cepat bbm juga terkenal dengan tampilannya yang elegan dan bisa di modfikasi (MOD) di BBMKu ada banyak sekali bbm yang sudah di modifikasi dengan tampilan yang berbeda seperti contohnya BBM Delta bbm mod yang sedang populer saat ini, bbm ini selain memiliki tampilan yang elegan tapi juga memiliki fitur unggulan yg gak kalah dengan BBM Official ataupun BBM MOD Official. Selain bbm dengan tampilan official ada juga beberapa bbm dengan tampilan unik seperti bbm naruto ataupun animasi lain seperti Bbm Doraemon dan juga BBM Liverpool. Selain itu ada juga apliksi bbm yang bisa di pasang secara bersamaan di satu android atau orang sering menyebutnya sebagai aplikasi BBM1, BBM2, BBM3, BBM4 . jika di lihat dari namanya memang sangat unik tapi, dalam bbm tersebut sudah memiliki tampilan yang super keren dan tentunya menghemat pembelian android dengan pakai BBM MOD IOS. dan jangn lupa kunjungi Nonton Film Online

Your blog is extremely

Your blog is extremely brilliant especially the quality content is really appreciable. Absolute Draining & Plumbing

Your thing is shows latent, m

Your thing is shows latent, m gona add this to my bookmarks. mikrowelle tests

To keep it simple,

To keep it simple, we’ll be listing only the most important characteristics for each camera: Video resolution, overall video quality, reliability, memory capacity, and a list of the extra features such as Wi-Fi or GPS. rexing v1p review

Thanks a lot for enjoying

Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! All the best! download showbox apk

i was simply scanning along

i was simply scanning along and happened upon your site. simply needed to say great site and this article truly helped me. Essay plagiarism checker

Your composing is purely

Your composing is purely awe-inspiring that I desired to read such high quality material... The Genesis Academy

Good quality info. Lucky to

Good quality info. Lucky to me I came to your website not on purpose, but now I have bookmarked it. gold IRA companies

Thanks to

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

I generally don’t

I generally don’t comment in the Blogs but your blog is the only one that forced me to, amazing work... general contractor victoria

This webpage comprises of a

This webpage comprises of a pleasant knowledge and giving lessons as well, I loved it lots more. write my essay

Main Page

You have to make your Main Page different from others. Ted McGrath's Teds Woodworking

This blog website is pretty

This blog website is pretty cool! How was it made ! Standmixer

Practice

For best practice you have to do it again and again. Bathmate Hydro Pump Reviews

Trees Secure

There is a notice that no one can cut the trees. Tao of Badass Reviews

Problems

Getting problems when converting from 6 module to 7 module. DIY Smart Saw system

I wish more writers of this

I wish more writers of this kind of substance would take the time you did to explore and compose so well. I am extremely inspired with your vision and knowledge. dabrigdeals

The people not reading your

The people not reading your blogs are missing out a lot of quality contents. options in outdoor fountains

Thanks

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

I appreciate you and hopping

I appreciate you and hopping for some more informative posts. happy new year 2016 new year 2016 happy new year 2016 images feliz año nuevo 2016

Jual Laptop Notebook PC HP Lenovo Printer Tinta Toner Epson Mura

On this subject internet page, you'll see my best information, be sure to look over this level of detail. Jual Printer

Trees

We have to install new trees in our area. MaleExtra Review

Face to face

Need a solution to get it out from here. How To Get Bigger Boobs Naturally Fast

Thanks

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

I'm gladsome to mature so

I'm gladsome to mature so more serviceable and informative assemblage on your website. assisted living in asheville

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

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.