<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Travellers Tales</title>
<link>http://travel-lab.info/tech/pblog/index.php</link>
<pubDate>Thu, 17 Aug 2006 01:10:25 +0900</pubDate>
<description>
Travellers Tales - RSS 2.0 (Really Simple Syndication).
</description>
<item>
<title>Safari でも selectionStart, selectionEnd がサポートされている</title>
<link>http://travel-lab.info/tech/pblog/article.php?id=13</link>
<guid>http://travel-lab.info/tech/pblog/article.php?id=13</guid>
<pubDate>Thu, 17 Aug 2006 01:10:25 +0900</pubDate>
<description>P_BLOG でのスマイリーボタンやタグボタンでの挿入位置
事の発端は、P_BLOG でスマイリーボタンやタグボタンを押したときに、Safari ではカーソル位置に挿入されてほしい文字列が入力済みのテキストのいちばん後ろに追加されてしまうこ...</description>
<content:encoded>
<![CDATA[<h4>P_BLOG でのスマイリーボタンやタグボタンでの挿入位置</h4>
<p>事の発端は、P_BLOG でスマイリーボタンやタグボタンを押したときに、Safari ではカーソル位置に挿入されてほしい文字列が入力済みのテキストのいちばん後ろに追加されてしまうことでした。予期せぬ位置にカーソルが移動してしまうので、微妙に不便です。</p>
<p>同じ事を感じている人は少ないないのでしょう、既に改造されている方もいらっしゃいました。</p>
<p><a href="http://www.portalshit.net/article.php?id=594" class="ex-ref">portal shit! : 投稿画面のタグボタンをカスタマイズ</a></p>
<p>この改造、およびソースコードを眺めていて気が付いたのですが、Firefox では改造しなくてもカーソル位置に文字列が挿入され、選択テキストがある場合は、ちゃんとそれをタグで挟んでくれるように動作しています。Safari でそれが動かなかった原因は、Safari の JavaScript が selectionStart, selectionEnd をサポートしていなかったことにありました。</p>
<h4><code>selectionStart</code>, <code>selectionEnd</code> はいつからサポートされたか</h4>
<p>Safari での <code>selectionStart</code>, <code>selectionEnd</code> を調べてみると、<a href="http://blog.nomadscafe.jp/archives/000580.html">Mac OS 10.4.4 以降ではサポートされている</a>ことがわかりました。</p>
<blockquote cite="http://blog.nomadscafe.jp/archives/000580.html" title="Safari 2.0.3 supports setSelectionRange : blog.nomadscafe.jp"><p>Mac OS X 10.4.4に含まれるSafari 2.0.3でFirefoxと同じく、setSelectionRange、selectionStart、selectionEndがサポートされたようです。</p></blockquote>
<p>早速、<a href="http://travel-lab.info/tech/pblog/files/article.php?id=1">P_BLOG のscripts.js を修正してみました</a>。この改造はてっきり Mac OS 10.4.4 以降でしか有効でないのかと思ったら、Mac OS 10.3.9 の Safari でもちゃんと動きます。いつからサポートされていたのでしょうか。</p>
<p><!-- more -->
そこで調べてみると、Mac OS 10.3.9 では、Safari Update 1.3.2 を適用することで、selectionStart, selectionEnd がサポートされることがわかりました。（下記引用の強調部分。）</p>
<blockquote cite="https://cgi.cse.unsw.edu.au/~forums/support/viewtopic.php?p=136&sid=4c891bcb2161e62ccd8285114e6a0d63#136" titile="CSE Forums :: View topic - New CSE Account Status page - beta test">
<p>Issues addressed in Safari 1.3.2 Preview : </p>
<ul>
<li>window.write in same call chain as window.open failed to write if URL parameter was provided. </li>
<li>Flash in div with display:none style did not redraw when style was changed  to display:block. </li>
<li>HTMLTableElement.insertRow(n) inserted row at the beginning of the table. </li>
<li>Setting focus, by tabbing, searching, or with JavaScript will now scroll overflow:auto/scroll/overlay to reveal focused element. </li>
<li>Preloaded Image objects .src field was not a fully resolved path</li> 
<li>Improved Tidy code for text fields in table cells</li>
<li>CSS: Content displayed incorrectly in tables with TD style set overflow:hidde </li>
<li>Some values used with setAttribute() caused the attribute to be removed (null strings vs. empty strings) </li>
<li>Added support for "before unload" event and onbeforeunload handler </li>
<li>iframe swallowed events for overlapping elements </li>
<li>Using Swedish keyboard, page would get downloaded when you type '@'  in email field</li>
<li>Selecting a new radio button did not automatically clear the previous selected (outside &lt;form&gt; element) </li>
<li><strong>Added Text node support for .SelectionStart and .SelectionEnd</strong></li>
<li>Prevented adjacent text selection when quickly clicking an image. </li>
<li>Calling focus on contentEditable block elements now scrolls them into view </li>
<li>Line-height style settings are now reflected in textarea </li>
<li>Fixed crash in KJS::Window::clear</li>
<li>String.replace() does not support a function as a parameter
location.replace with dynamically written frameset doesn't change view  </li>
<li>XSLT page in Shift_JIS did not always decode correctly </li>
<li>Selects are now in the tab order in all keyboard modes </li>
<li>Fixed crash in inCSSStyleSelector::locateSharedStyle </li>
<li>Cursor and text in status bar was not always updated when mousing over links in a frame </li>
<li>Tabs are now treated as whitespace in option element</li>
</ul></blockquote>
<p>結局のところ、Mac OS 10.4.x Tiger でも OS 10.3.x Panther でも最新版の Safari (バージョン 2.0.3 または 1.3.2) を使っていれば、<code>selectionStart</code>, <code>selectionEnd</code> を使えることが判明しました。</p>
<p><a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=3401">The OpenDarwin Bugzilla - Bug 3401</a> にも、OS 10.3 で修正されていると書かれています。</p>
<h4>P_BLOG の scripts.js の改造</h4>
<p>上記の変更点を受けて、Safari でもカーソル位置にスマイリー記号・タグが挿入されるように<a href="http://travel-lab.info/tech/pblog/files/article.php?id=1">改造した scripts.js</a> を公開しました。</p>
<p><a href="http://travel-lab.info/tech/pblog/files/article.php?id=1">Travellers Tale : Downloads : P_BLOG 私家版 scripts.js</a></p>
<h5>追記</h5>
<p><a href="http://pbx.homeunix.org/p_blog/article.php?id=175">P_BLOG 本家でも紹介</a>していただきました。</p>
]]>
</content:encoded>
</item>
</channel>
</rss>