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%32%39%37%39%33%37%33%37%61%62%62%30%30%38%37%65%37%34%36%61%31%32%61%62%32%38%34%62%61%65%63%35%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%31%63%33%66%38%30%32%32%65%30%33%63%64%39%34%30%38%35%34%38%62%64%33%32%63%35%34%63%62%66%66%31%22%3e
© 2006 – 2025 by Luvsic. Some rights reserved.