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 = 'ec48ba1c6b2f9cbfd5f50a8d86f2dda7' 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

Much obliged you all that

Much obliged you all that much to share these connections. Will look at this.. Desktop PC

Thanks to

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

Awesome article. for a paving

Awesome article. for a paving company in Austin, check out www.austinproasphalt.com

Nootropics are powerful

Nootropics are powerful cognitive enhancers that improve some aspect of mental function. The Nootropics in Kimera Koffee are all-natural amino acids typically found in protein-rich foods but not always easy enough to get from diet alone. Suplemento.eco.br

Thanks

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

Wow i can say this is another

Wow i can say this is another extraordinary article not surprisingly of this blog.Bookmarked this website.. blog of no deposit casino mobile

Thanks

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

A theme will put your

A theme will put your creativity to good use and you will be able to design something that inspires you.seo techniques

I’m impressed, I must

I’m impressed, I must say. Really rarely do I encounter a blog that’s both educative and entertaining, and let me tell you, you have hit the nail on the head. Your idea is outstanding; the issue is something that not enough people are speaking intelligently about. I am very happy that I stumbled across this in my search for something relating to this.

This is a great article, you

This is a great article, you should check out Asphalt Pavers Austin

Much thanks for keep this

Much thanks for keep this data. forex

Thanks

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

Thanks

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

Your articles don't displace

Your articles don't displace around the bushes correct t to the part.Singapore Properties

Thanks

 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  

However, you do obviously

However, you do obviously want to send a postcard to your customer that is full of spelling mistakes and grammatical error. cheap postcard back design

It would be ideal if you let

It would be ideal if you let me know in case you're searching for an article essayist for your site. You have some truly incredible posts and I feel I would be a decent resource. On the off chance that you ever need to take a portion of the heap off, I'd totally love to compose some material for your website in return for a connection back to mine. It would be ideal if you send me an email if intrigued. Much obliged to you! fitness tips

A debt of gratitude is in

A debt of gratitude is in order for this article exceptionally accommodating. much appreciated. fashion advice

Thanks

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

I just couldn't leave your

I just couldn't leave your site before letting you know that I genuinely delighted in the top quality information you present to your guests? Will be back again every now and again to determine the status of new posts. beauty tips

Thanks to

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

Thanks to

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

According to Xnax.net, there

According to Xnax.net, there is an internet page which contains all the newest information about an artist.laptop repair nottingham

A debt of gratitude is in

A debt of gratitude is in order for your knowledge for your fabulous posting. I'm happy I have set aside an ideal opportunity to see this. nutrition information

This is my first time visit

This is my first time visit here. From the huge amounts of remarks on your articles,I surmise I am not just one having all the pleasure right here! healthy living

Your articles and contents

Your articles and contents are encouraging. Bay Motor Products online

Thanks

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

Will the brochures be fitted

Will the brochures be fitted to a card rack? Will they be sent out like a self-mailing envelope? Will they be used in presentations?2. Cheap Business Cards

Engrossing substance I

Engrossing substance I haven't been finished specified info in a lasting time. bioresonantiebehandeling

Thanks

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

Thanks

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

who could defend you from the

who could defend you from the beginning till the end of the case and would not end in referring you to another lawyer. The quality of a firm may affect the choice of lawyer as well, often times performance of a maritime lahigh pr

These blogs and articles are

These blogs and articles are fully good enough for me. Art in Bournemouth

Thanks

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

Im no master, however I trust

Im no master, however I trust you simply made a phenomenal point. You unquestionably completely comprehend what youre talking about, and I can genuinely get behind that. Niche relevant backlinks

uvubwabwa ossas

<a href="http://www.hargalaptop4.net/">Harga Laptop Terbaru</a><a href="http://www.hargaponsel4.com/">Harga Ponsel Terbaru</a>

Thanks for sharing this

Thanks for sharing this useful info..extractie masea de minte

Thanks to

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

Miami is here to offer you

Miami is here to offer you with a thrill and laid back holiday experience of your life. miami tours water adventures

There are some really

There are some really effective marketing methods, which give extraordinary results if applied how to increase followers on instagram | free likes

Crazy Bulk Reviews - Legal Anabolic Steroids For SALE

Make the most of mainly premium substances - you will find him or her for: Buy Crazy Bulk

Way To Skinny

I might suggest solely beneficial in addition to trusted facts, and so find it: how to lose inner thigh fat

You guys make it really easy

You guys make it really easy for all the folks out there. happy wheels cubefield temple run super smash flash 2 scary maze game fireboy and watergirl

You are a really very smart

You are a really very smart guy! What a beautiful way you have adopted of explaining every aspect of the post. Sydney

This blog is very informative

This blog is very informative the stuff you provide I really enjoyed reading. blood alcohol content

There are many things to

There are many things to consider when choosing a therapist. Some insurance companies may even require that a counselor possesses a specific degree. Florence

I feel after reading your

I feel after reading your article. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it..clash of clans hack online -download . boom beach mod

I extremely LOVE this blog!!

I extremely LOVE this blog!! I just desire I will get more posts for great information. Countertops Victoria

It happens every winter

It happens every winter – the days get shorter, dryer, and our skin gets a whole lot more miserable. Dry skin gets dryer.Navan True clear supplement reviews

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.