jQuery で Nucleusのテキストエリアをリサイズ可能にする

ちょっと引っかかったのでメモ。

Nucleusuのコメントページ、並びにメンバーページにあるテキストエリアは、nucleus_cf_bodyというCSSのIDが振られている。nucleus/formsのフォルダ以下にある次の4つのファイルが元ファイル。

  • commentform-loggedin.template
  • commentform-notloggedin.template
  • membermailform-loggedin.template
  • membermailform-notloggedin.template
画像:commentform-notloggedin.template

で、jQuery TextAreaResizerで試してみた。サンプルでの実行コードはこんな感じ。

jQuery(function() {
        $('textarea#nucleus_cf_body:not(.processed)').TextAreaResizer();
});

しかしこれでは、テキストエリアがないページでエラーが起こるみたい。うーん。スキンでif使って切り分けてもいいけど、PHPの処理、というかコードはなるべく減らしたい。そこでjQuery側で、「もしもCSSのあるIDが存在する場合に実行する」という処理を書けば・・・ はて、jQueryってどうやってif書くの?



というわけで、ろくろく自前で考えもせず検索したらすぐHITした。トップの画像素敵。

なるほど、.length 使える!
というわけで下記のように書いた。

jQuery(function() {
        if ($('textarea#nucleus_cf_body').length) {
                $('textarea#nucleus_cf_body:not(.processed)').TextAreaResizer();
        };
});
/
Skooler Records

No comments yet

%3c%69%6e%70%75%74%20%74%79%70%65%3d%22%68%69%64%64%65%6e%22%20%6e%61%6d%65%3d%22%6e%70%5f%70%72%6f%74%65%63%74%62%79%6d%64%35%22%20%76%61%6c%75%65%3d%22%38%30%37%38%62%63%62%35%38%35%61%63%65%63%38%33%37%65%34%36%39%34%66%32%30%39%31%65%37%31%66%32%22%3e %3c%69%6e%70%75%74%20%74%79%70%65%3d%22%68%69%64%64%65%6e%22%20%6e%61%6d%65%3d%22%6e%70%5f%70%72%6f%74%65%63%74%62%79%6d%64%35%5f%68%61%73%68%22%20%76%61%6c%75%65%3d%22%62%30%62%39%33%33%32%39%61%35%65%66%61%34%35%65%33%62%35%66%62%66%66%31%66%64%37%34%39%37%64%66%22%3e
© 2006 – 2024 by Luvsic. Some rights reserved.