テーマ更新。 JS を jQuery に

テーマを更新しました。 JS を全て jQuery に。クッキーも Cookie Plugin for jQuery を使いました。

$(function(){
    // 検索キーワードの入力ボックス
    $("#searchKeyword")
        .focus(function() {
            if( this.value == "Keyword(s)" ) {
                this.value = "";
            }
        })
        .blur(function() {
            if( this.value == "" ) {
                this.value = "Keyword(s)";
            }
        });
});
$(function(){
    // コメント投稿フォーム入力ボックス
    $('#comment-text')
        .focus(function() {
            if( this.value == 'Add Your Comment' ) {
                this.value = '';
            }
        })
        .blur(function() {
            if( this.value == '' ) {
                this.value = 'Add Your Comment';
            }
        });
    // Cookie に記憶するかのラジオボタンを作成
    $('dl#name-email + dl > dt:first-child + dd')
        .after(
            '<dt>情報をクッキーに保存</dt>' +
            '<dd>' +
            '<input type="radio" class="radio" id="bakecookie" name="bakecookie" />' +
            '<label for="bakecookie">Yes</label>' +
            '<input type="radio" class="radio" id="forget" name="bakecookie" value="Forget Info" />' +
            '<label for="forget">No</label>' +
            '</dd>'
        );

// Cookie の値を取得してフォームの内容に反映
$('#comment-author').attr( 'value', $.cookie( 'wp-comment-author' ) );
$('#comment-email').attr( 'value', $.cookie( 'wp-comment-email' ) );
$('#comment-url').attr( 'value', $.cookie( 'wp-comment-url' ) );

if( $.cookie('wp-comment-author') ) { // クッキーが設定されていれば
$('#bakecookie').attr( 'checked', true );
} else {
$('#forget').attr( 'checked', true );
}

$('#commentsForm')
.submit(function() {
// クッキーの保存
if( $('#bakecookie').attr( 'checked' ) ) {
var CookieOptions = { expires: 365, path: '/' }
$.cookie( 'wp-comment-author', $('#comment-author').attr( 'value' ), CookieOptions );
$.cookie( 'wp-comment-email', $('#comment-email').attr( 'value' ), CookieOptions );
$.cookie( 'wp-comment-url', $('#comment-url').attr( 'value' ), CookieOptions );
}
});

$('#forget')
.click(function() {
// クッキーの削除
$.cookie( 'wp-comment-author', null );
$.cookie( 'wp-comment-email', null );
$.cookie( 'wp-comment-url', null );
})
.keypress(function() {
// クッキーの削除
$.cookie( 'wp-comment-author', null );
$.cookie( 'wp-comment-email', null );
$.cookie( 'wp-comment-url', null );
});

});



コメント投稿テストしてみて分かったんですが、この JS と WP 本体とで二つ Cookie が保存されていることに気が付きました。だったらわざわざ JS でやることないような。 wp.Vicuna で WP 本体のクッキーを使っていないのは、何か不都合があるのかな。

インフォメーション

公開日時
2007年9月21日 午後7時0分6秒
最終更新日時
2007年12月29日 午前9時40分34秒
カテゴリ
WordPress