私はWordpress Stack ExchangeのHow can I make the “Preview Post” button save and preview in the same window?に尋ねましたが、これはより直接的にコーディングに関連しているので、Stack Overflowにとってはより良い質問かもしれません。Wordpressの「プレビュー」リンクを同じウィンドウで開くにはどうすればよいですか?
Wordpressのあなたは、プレビューを保存し、あなたのブログの投稿を公開することができますボックスを持っています
Picture.png http://img854.imageshack.us/img854/7986/picturek.png
「プレビュー」ボタンは、実際にボタンとしてスタイルのリンクです:
<a tabindex="4" id="post-preview" target="wp-preview"
href="/?p=67&preview=true" class="preview button">Preview</a>
私の問題は、現在のウィンドウでそのリンクを開く方法を見つけることができないということです。 target="wp-preview"
の部分に注目してください。私はその部分を取り除こうとしていますが、バインドを解除してtarget
属性を削除しても、現在のタブ/ウィンドウで実際に開くことができないため、その要素にバインドされた別の関数があると思います。
プラグインの一部として次のコードを実行しています(このプラグインをプラグインとして実行する方法について詳しくはこちらをご覧ください)。これをコピーしてChromeまたはFirefoxのコンソールに貼り付けてテストすることもできますこれはWordpressを改変することなく自分自身で実行できます。テスト時に$
の代わりにjQuery
を使用する必要があります。Wordpressはnoconflict
メソッドを使用しますが、下のコードはそのまま動作します。
//select the node and cache the selection into a variable
var $node = jQuery('a.preview');
//add a 1px dotted outline to show we have the right element
$node.css('outline','1px dotted red');
//show current target
console.log($node.prop('target'));
//show if anything is bound - nothing is for me ('undefined')
console.log($node.data('events'));
//remove anything bound to it
$node.unbind();
//set target to _self (current window), just in case
$node.prop('target','_self');
//the remove the target attribute all together
$node.removeAttr('target');
//clone the node
var $clone = $node.clone();
//change the text to new
$clone.text('new');
//remove target from clone
$clone.removeAttr('target');
//unbind the clone
$clone.unbind();
//insert the clone after the original node
$node.after($clone);
//show current target - now shows undefined for me
console.log($node.prop('target'));
//show if anything is bound - still 'undefined'
console.log($node.data('events'));
これは、あなたがテーマやプラグインにコードをどのように動作するかです:ここでは
// set up an action to set a function to run in the wp admin_footer
add_action('admin_footer','my_admin_footer_script',9999);
はJavaScriptを追加機能である:
//this function can then be used to add javascript code to the footer
function my_admin_footer_script(){ ?>
<script type="text/javascript">
jQuery(function($){
(above js code here)
});
</script>
<?php
}
これは私が終了した結果でありますと一緒に。 「テスト」リンクをクリックすると、同じウィンドウで開きます。プレビューリンクをクリックすると、新しいタブで開きます。
Picture.png http://img832.imageshack.us/img832/4163/picturesf.png
PS:私は、バインドされたイベントを確認するためにThings you may not know about jQueryからメソッドを使用している、と私はバインド何かを見つけることができませんでした、と私はWordpressのは、主に私はこれがあることとは思わないのjQueryを使用しています信じています別のイベントハンドラにバインドされます。
イベント委任を使用している場合は、データ(イベント)トリックを使用することはできません。とにかく、jQueryの新しいバージョンでは、とにかくそれを取り除いた可能性があります。 –
しかし、バインド解除はそれがネイティブ関数なのでそのまま動作するはずです。 jQueryのドキュメントごとに: '$( '#foo')。unbind(); //このバージョンは、型に関係なくハンドラを削除します。' – cwd
デリゲートを使用していればアンバインドは機能しません。なぜなら実際にその要素にバインドされたイベントがないからです。 デリゲートの仕組みは、DOMの上位のイベントを聴いてから、イベントオブジェクトがどこから来たのかを調べることです。イベントがバインドされている要素を特定できる場合は、undelegateを使用できます。 とにかく、これは私の言うところの純粋な推測です。私は彼らがデリゲートを使っているのかどうかはわかりません。 –