WordPress 投稿エディタに LightBox のコードを挿入

2007/08/19 日曜日 11:38 投稿者 zon

コア部分を変更するのであまり参考にしない方がいいと思います。

変更後のイメージは以下のようになります。

LightBox のコードを挿入

■バージョン:2.1.3
■変更ファイル:/wp-admin/upload-js.php

修正点その1

【変更前】116行目:

h += "<label for='link-file'><input type='radio' name='link' id='link-file' value='file' checked='checked'/> <?php echo attribute_escape(__('File')); ?></label><br />";

【変更後】file のチェックをはずして、その上に LightBox のラジオボタンを追加

h += "<label for='link-lightbox'><input type='radio' name='link' id='link-lightbox' value='lightbox' checked='checked' /> <?php echo attribute_escape(__('LightBox')); ?></label><br />";
h += "<label for='link-file'><input type='radio' name='link' id='link-file' value='file' checked='checked'/> <?php echo attribute_escape(__('File')); ?></label><br />";  

修正点その2

【変更前】236行目~241行目:

if ( 'none' != link )
	h += "<a href='" + ( 'file' == link ? ( this.currentImage.srcBase + this.currentImage.src ) : ( this.currentImage.page + "' rel='attachment wp-att-" + this.currentImage.ID ) ) + "' title='" + this.currentImage.title + "'>";
if ( display && 'title' != display )
	h += "<img src='" + ( 'thumb' == display ? ( this.currentImage.thumbBase + this.currentImage.thumb ) : ( this.currentImage.srcBase + this.currentImage.src ) ) + "' alt='" + this.currentImage.title + "' />";
else
	h += this.currentImage.title;

【変更後】LightBox を選択時、rel 属性に lightbox[post-id] を設定する処理を追加。ついでに、img タグに width、height、title 属性を設定する処理を追加

if ( 'none' != link ) {
	h += "<a href='"
	if ( 'file' == link )
		h += this.currentImage.srcBase + this.currentImage.src;
	else if ( 'page' == link )
		h += this.currentImage.page + "' rel='attachment wp-att-" + this.currentImage.ID;
	else if ( 'lightbox' == link )
		h += this.currentImage.srcBase + this.currentImage.src + "' rel='lightbox[" + this.postID + "]";
	h += "' title='" + this.currentImage.title + "'>";
}
if ( display && 'title' != display ) {
	h += "<img src='";
	if ( 'thumb' == display ) {
		imageThumb = new Image();
		imageThumb.src = this.currentImage.thumbBase + this.currentImage.thumb;
		h += imageThumb.src + "' width='" + imageThumb.width + "' height='" + imageThumb.height;
	} else {
		imageBase = new Image();
		imageBase.src = this.currentImage.srcBase + this.currentImage.src;
		h +=  imageBase.src + "' width='" + imageBase.width + "' height='" + imageBase.height;
	}
	h += "' alt='" + this.currentImage.title + "' title='" + this.currentImage.title + "' />";
} else {
	h += this.currentImage.title;
}

img タグの width、height、title 属性は、LightBox とは関係ないのですが、W3C XHTML1.0 valid を意識して、毎回設定しているのが面倒になったので、コア部分を変更するならと、ついでにやっておきました。

プラグインを駆使してなんとかなるものなら、コア部分を変更せずになんとかしたいものですが分からないのです。

2.0系でこのカスタマイズを行いたければ、inline-uploading.php 辺りを変更すればいいのかと思って、ソースをざっくり追ってみましたが、2.1.3 の仕組みとは大きく変わっていたので追うのが面倒になりました。2.0系をカスタマイズしたい人は、ほとんど参考にならないと思います。

LightBoxとFLASHの周辺

2007/07/20 金曜日 16:42 投稿者 zon

FlashblogとLightBoxを連携させるためにいんぐりもんぐりやってみた。
ちなみにLightbBoxのバージョンは2.0.2。

参考URLは以下

引っかかったところ

  • rel属性無しでLightbox JS v2.02のカスタム方法で line180 近辺の部分は自分のソースと違ってた。if の最後に { がないので注意。もしくは } を削除しないといけない。
  • FLASHでHTMLを読み込んだ場合 target=”_blank” が入っていると上手く動作しない。

かなり前に書いた記事なので情報が古いかもですが、これを書いてたブログを閉めようと思っているので、こっちに移しました。

zontheworld HTML convert time: 0.149 sec. ( Login )