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