<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>@blog.justoneplanet.info &#187; jQuery</title>
	<atom:link href="http://blog.justoneplanet.info/category/computer-language/javascript/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.justoneplanet.info</link>
	<description>日々勉強</description>
	<lastBuildDate>Wed, 08 Feb 2012 02:57:17 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>overflowがscrollの時にアンカーにsmooth scrollできるjQueryプラグインを作ってみた</title>
		<link>http://blog.justoneplanet.info/2011/05/04/overflow%e3%81%8cscroll%e3%81%ae%e6%99%82%e3%81%ab%e3%82%a2%e3%83%b3%e3%82%ab%e3%83%bc%e3%81%absmooth-scroll%e3%81%a7%e3%81%8d%e3%82%8bjquery%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%82%92/</link>
		<comments>http://blog.justoneplanet.info/2011/05/04/overflow%e3%81%8cscroll%e3%81%ae%e6%99%82%e3%81%ab%e3%82%a2%e3%83%b3%e3%82%ab%e3%83%bc%e3%81%absmooth-scroll%e3%81%a7%e3%81%8d%e3%82%8bjquery%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%82%92/#comments</comments>
		<pubDate>Tue, 03 May 2011 15:39:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=4457</guid>
		<description><![CDATA[久しぶりのjQueryでのちょっとしたスクリプト。 ■クライアントコード // a[href=&#34;#target&#34;]をクリックすると#targetに#mainがスムーズスクロールする。 $('a[hre [...]]]></description>
			<content:encoded><![CDATA[<p>久しぶりのjQueryでのちょっとしたスクリプト。</p>
<p><script src="https://gist.github.com/1259350.js?file=jquery-box-scroll.js"></script><br />
<script src="https://gist.github.com/1259350.js?file=jquery-position-in.js"></script></p>
<h3>■クライアントコード</h3>
<pre class="brush: jscript;">
// a[href=&quot;#target&quot;]をクリックすると#targetに#mainがスムーズスクロールする。
$('a[href=&quot;#target&quot;]').click(function(e){
    e.preventDefault();
    $('#main').boxScroll($(&quot;#target-wrapper&quot;), $('#target'));
});
</pre>
<p>こんな感じで使う。気が向いたらブラッシュアップする。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2011/05/04/overflow%e3%81%8cscroll%e3%81%ae%e6%99%82%e3%81%ab%e3%82%a2%e3%83%b3%e3%82%ab%e3%83%bc%e3%81%absmooth-scroll%e3%81%a7%e3%81%8d%e3%82%8bjquery%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%82%92/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File APIを使ってドロップでファイルをアップロードできるjQueryプラグインを作ってみる</title>
		<link>http://blog.justoneplanet.info/2010/09/15/file-api%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%89%e3%83%ad%e3%83%83%e3%83%97%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e3%81%a7/</link>
		<comments>http://blog.justoneplanet.info/2010/09/15/file-api%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%89%e3%83%ad%e3%83%83%e3%83%97%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e3%81%a7/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 16:32:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=3047</guid>
		<description><![CDATA[■ダウンロード クリックしてダウンロードして下さい。 ■動作ブラウザ Firefox 3.6+, Google Chrome 6+ ■使い方 1.HTMLでプラグインを読み込む jQuery本体を読み込んだ後にプラグイン [...]]]></description>
			<content:encoded><![CDATA[<h3>■ダウンロード</h3>
<p><a href="/wp-content/uploads/jquery/jquery.dropUploader/jquery.dropUploader.0.1.0.zip">クリックしてダウンロード</a>して下さい。</p>
<h3>■動作ブラウザ</h3>
<p>Firefox 3.6+, Google Chrome 6+</p>
<h3>■使い方</h3>
<h4>1.HTMLでプラグインを読み込む</h4>
<p>jQuery本体を読み込んだ後にプラグインのJavaScriptを読み込む。</p>
<pre class="brush: xml;">
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery.dropUploader.js&quot;&gt;&lt;/script&gt;
</pre>
<h4>2.JavaScriptでプラグインを設置する</h4>
<p>以下のようにして、p.uploaderにファイルをドロップすると、ファイルをアップロードすることができる。</p>
<pre class="brush: jscript;">
$(function(){
    $('p.uploader').dropUploader({
        &quot;action&quot; : &quot;./save.php&quot;,
        &quot;allowedMimetypes&quot; : [
            'image/png',
            'image/jpeg',
            'image/gif'
        ],
        /*
        &quot;onDragstart&quot; : function(elm){
            //alert('dragstart');
        },
        &quot;onMouseover&quot; : function(elm){
            //alert('mouseover');
        },
        */
        &quot;onProgress&quot; : function(value){
            //console.log(value);
        },
        &quot;onPartialError&quot; : function(){
            alert('onPartialError');
        },
        &quot;onComplete&quot; : function(){
            alert('finished');
        }
    });
});
</pre>
<h4>3.サーバーサイド（./save.php）でファイルを保存する</h4>
<p>以下のようにするとPHPでファイルを保存することができる。但し、以下のコードはチェックを行っていないので、実際に使用する際にはファイルサイズや拡張子などのチェックを必ずしなくてはならない。</p>
<pre class="brush: php;">
file_put_contents(basename($_GET['filename']), fopen('php://input', 'r'));
</pre>
<section class="kakomi">
<h4>プラグイン本体</h4>
<p>ワクワクする部分★</p>
<pre class="brush: jscript;">
(function($){
    $.fn.dropUploader = function(options){
        var self    = this;
        var options = options;

        /**
         * _onDragstart
         * @param {Object} elm
         */
        var _onDragstart = function(elm){
            if(typeof options['onDragstart'] === 'function'){
                options['onDragstart']();
            }
            else{
                $(elm).css({
                    &quot;border&quot; : &quot;5px dotted #cccccc&quot;
                });
            }
        }

        /**
         * _onMouseover
         * @param {Object} elm
         */
        var _onMouseover = function(elm){
            if(typeof options['onMouseover'] === 'function'){
                options['onMouseover']();
            }
            else{
                $(elm).css({
                    &quot;border&quot; : &quot;5px dotted #cccccc&quot;
                });
            }
        }

        /**
         * _onMouseout
         * @param {Object} elm
         */
        var _onMouseout = function(elm){
            if(typeof options['onMouseout'] === 'function'){
                options['onMouseout']();
            }
            else{
                $(elm).css({
                    &quot;border&quot; : &quot;none&quot;
                });
            }
        }

        /**
         * _getAction
         * @param {string} action
         * @param {string} filename
         */
        var _getAction = function(action, filename){
            var url = '';
            if(action.indexOf('?') &gt; -1){
                url = action + '&amp;filename=' + encodeURIComponent(filename);
            }
            else{
                url = action + '?filename=' + encodeURIComponent(filename);
            }
            if(options['params']){
                for(var i = 0, n = options['params'].length; i &lt; n; i++){
                    for(param in options['params'][i]){
                        url += '&amp;' + encodeURIComponent(param) + '=' + encodeURIComponent(options['params'][i][param]);
                    }
                }
            }
            return url;
        }

        var result = this.each(function(){
            var elm = this;
            if(window.addEventListener){
                elm.addEventListener(
                    'dragstart',
                    function(e){
                        _onDragstart(this);
                        e.preventDefault();
                    },
                    false
                );
                elm.addEventListener(
                    'dragenter',
                    function(e){
                        _onMouseover(this);
                        e.preventDefault();
                    },
                    false
                );
                elm.addEventListener(
                    'dragover',
                    function(e){
                        _onMouseover(this);
                        e.preventDefault();
                    },
                    false
                );
                elm.addEventListener(
                    'dragout',
                    function(e){
                        _onMouseout(this);
                        e.preventDefault();
                    },
                    false
                );
                elm.addEventListener(
                    'drop',
                    function(e){
                        e.preventDefault();
                        var files    = e.dataTransfer.files;
                        var total    = 0;
                        var loaded   = 0;
                        var progress = 0;
                        var counter  = 0;
                        var xcounter = 0;
                        var response = [];
                        $(this).addClass('wait');
                        for(var i = 0; i &lt; files.length; i++){
                            if($.inArray(files[i].type, options['allowedMimetypes']) &gt; -1){
                                var xhr = new XMLHttpRequest();
                                total = total + files[i].size;
                                xhr.upload.onprogress = function(e){
                                    loaded = loaded + e.loaded;
                                    if(typeof options['onProgress'] === 'function'){
                                        options['onProgress']((loaded / total) * 100 + &quot;%&quot;);
                                    }
                                }
                                xhr.upload.onload = function(e){
                                    counter++;
                                    if(i === counter){// upload is finished
                                        if(typeof options['onComplete'] === 'function'){
                                            options['onComplete']();
                                        }
                                        $(this).removeClass('wait');
                                        if(typeof options['onProgress'] === 'function'){
                                            options['onProgress'](0);
                                        }
                                    }
                                    else{
                                    }
                                }
                                var filename = files[i].name;
                                var action = _getAction(options['action'], files[i].fileName);
                                xhr.open('post', action);
                                xhr.onreadystatechange = function(e){
                                    if(this instanceof XMLHttpRequest &amp;&amp; this.readyState === 4){
                                        xcounter++;
                                        try{
                                            response.push(this.responseText);
                                            if(i === xcounter){// upload is finished
                                                $(this).removeClass('wait');
                                                if(typeof options['onProgress'] === 'function'){
                                                    options['onProgress'](0);
                                                }
                                                options['onComplete'](response);
                                            }
                                            else{
                                            }
                                        }
                                        catch(e){
                                            if(typeof options['onError'] === 'function'){
                                                options['onError']();
                                            }
                                        }
                                    }
                                }
                                xhr.send(files[i]);
                            }
                            else{
                                if(i === counter){// upload is finished
                                    if(typeof options['onComplete'] === 'function'){
                                        options['onComplete']();
                                    }
                                    $(this).removeClass('wait');
                                    if(typeof options['onProgress'] === 'function'){
                                        options['onProgress'](0);
                                    }
                                }
                                counter++;
                            }
                        }
                    },
                    false
                );
            }
        });
        return result;
    }
})(jQuery);
</pre>
<p>クロスブラウザにしないとなー♪((Ｏ(〃⌒∇⌒〃)Ｏ))♪</p>
</section>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/09/15/file-api%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%89%e3%83%ad%e3%83%83%e3%83%97%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e3%81%a7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>document.querySelectorをつかう</title>
		<link>http://blog.justoneplanet.info/2010/06/05/document-queryselector%e3%82%92%e3%81%a4%e3%81%8b%e3%81%86/</link>
		<comments>http://blog.justoneplanet.info/2010/06/05/document-queryselector%e3%82%92%e3%81%a4%e3%81%8b%e3%81%86/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 08:50:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=4061</guid>
		<description><![CDATA[CSSセレクタは凄く分かりやすくjQueryでも頻繁に使用する。 $('h3.hoge'); これだけのためにjQueryを使いたくはないので、querySelectorメソッドを使用する。 document.query [...]]]></description>
			<content:encoded><![CDATA[<p>CSSセレクタは凄く分かりやすくjQueryでも頻繁に使用する。</p>
<pre class="brush: jscript;">
$('h3.hoge');
</pre>
<p>これだけのためにjQueryを使いたくはないので、querySelectorメソッドを使用する。</p>
<pre class="brush: jscript;">
document.querySelector('h3.hoge');
</pre>
<p>上述だと最初の要素しか選択されないので、下述のようにquerySelectorAllメソッドを使用する。</p>
<pre class="brush: jscript;">
document.querySelectorAll('h3.hoge');
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/06/05/document-queryselector%e3%82%92%e3%81%a4%e3%81%8b%e3%81%86/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>textareaでmaxlengthを使えるようにする</title>
		<link>http://blog.justoneplanet.info/2010/05/23/textarea%e3%81%a7maxlength%e3%82%92%e4%bd%bf%e3%81%88%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab%e3%81%99%e3%82%8b/</link>
		<comments>http://blog.justoneplanet.info/2010/05/23/textarea%e3%81%a7maxlength%e3%82%92%e4%bd%bf%e3%81%88%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Sun, 23 May 2010 09:11:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2585</guid>
		<description><![CDATA[以下のようにする。 var textarea = $('textarea[maxlength]'); textarea.bind( &#34;keydown keyup click&#34;, function(){ [...]]]></description>
			<content:encoded><![CDATA[<p>以下のようにする。</p>
<pre class="brush: jscript;">
var textarea = $('textarea[maxlength]');
textarea.bind(
    &quot;keydown keyup click&quot;,
    function(){
        var max = $(this).attr('maxlength');
        if($(this).val().length &gt; max){
            $(this).val($(this).val().substr(0, max));
        }
    }
);
</pre>
<p>面倒なのでjQueryを使用してます。ちなみにHTML5ではネイティブで使えるので以上のコードは必要ない。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/05/23/textarea%e3%81%a7maxlength%e3%82%92%e4%bd%bf%e3%81%88%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IEはradioボタンをappendChildしてもつかえない</title>
		<link>http://blog.justoneplanet.info/2010/01/29/ie%e3%81%afradio%e3%83%9c%e3%82%bf%e3%83%b3%e3%82%92appendchild%e3%81%97%e3%81%a6%e3%82%82%e3%81%a4%e3%81%8b%e3%81%88%e3%81%aa%e3%81%84/</link>
		<comments>http://blog.justoneplanet.info/2010/01/29/ie%e3%81%afradio%e3%83%9c%e3%82%bf%e3%83%b3%e3%82%92appendchild%e3%81%97%e3%81%a6%e3%82%82%e3%81%a4%e3%81%8b%e3%81%88%e3%81%aa%e3%81%84/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 17:03:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2369</guid>
		<description><![CDATA[IE6~7でラジオボタンをappendChildした場合、そのラジオボタンはクリックできない。ラジオボタンとして致命的なバグである。 ■失敗例 以下のようにDOM要素を操作する。 var input = document [...]]]></description>
			<content:encoded><![CDATA[<p>IE6~7でラジオボタンをappendChildした場合、そのラジオボタンはクリックできない。ラジオボタンとして致命的なバグである。</p>
<h3>■失敗例</h3>
<p>以下のようにDOM要素を操作する。</p>
<pre class="brush: jscript;">
var input = document.createElement('input');
var p     = document.createElement('p');
p.appendChild(input);
</pre>
<p>ちなみにjQueryを使うと以下のようになる。</p>
<pre class="brush: jscript;">
var input = document.createElement('input');
var p     = document.createElement('p');
$(p).append(input);
</pre>
<h3>■解決策</h3>
<p>IEだけinnerHTMLを使う。</p>
<pre class="brush: jscript;">
var input = document.createElement('input');
var p     = document.createElement('p');
if(!!(!window.opera &amp;&amp; window.attachEvent)){
    p.innerHTML = '&lt;input type=&quot;radio&quot; name=&quot;id&quot; /&gt;';
}
else{
    p.appendChild(input);
}
</pre>
<p>ちなみにjQueryを使うと以下のようになる。</p>
<pre class="brush: jscript;">
var input = document.createElement('input');
var p     = document.createElement('p');
if($.browser.msie){
    $(p).append('&lt;input type=&quot;radio&quot; name=&quot;id&quot; /&gt;');
}
else{
    $(p).append(input);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/01/29/ie%e3%81%afradio%e3%83%9c%e3%82%bf%e3%83%b3%e3%82%92appendchild%e3%81%97%e3%81%a6%e3%82%82%e3%81%a4%e3%81%8b%e3%81%88%e3%81%aa%e3%81%84/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScriptで画像を縦横比を維持しつつ指定サイズに丸める</title>
		<link>http://blog.justoneplanet.info/2010/01/23/javascript%e3%81%a7%e7%94%bb%e5%83%8f%e3%82%92%e7%b8%a6%e6%a8%aa%e6%af%94%e3%82%92%e7%b6%ad%e6%8c%81%e3%81%97%e3%81%a4%e3%81%a4%e6%8c%87%e5%ae%9a%e3%82%b5%e3%82%a4%e3%82%ba%e3%81%ab%e4%b8%b8%e3%82%81/</link>
		<comments>http://blog.justoneplanet.info/2010/01/23/javascript%e3%81%a7%e7%94%bb%e5%83%8f%e3%82%92%e7%b8%a6%e6%a8%aa%e6%af%94%e3%82%92%e7%b6%ad%e6%8c%81%e3%81%97%e3%81%a4%e3%81%a4%e6%8c%87%e5%ae%9a%e3%82%b5%e3%82%a4%e3%82%ba%e3%81%ab%e4%b8%b8%e3%82%81/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 09:02:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2349</guid>
		<description><![CDATA[SVGやcanvasを使えば確かそのままトリミングもできた気がするが、別にそこまでしたくない用の関数。画像のオリジナルサイズを取得し計算する感じだ。面倒なのでjQueryを使う。 var frameWidth = 700 [...]]]></description>
			<content:encoded><![CDATA[<p>SVGやcanvasを使えば確かそのままトリミングもできた気がするが、別にそこまでしたくない用の関数。画像のオリジナルサイズを取得し計算する感じだ。面倒なのでjQueryを使う。</p>
<pre class="brush: jscript;">
var frameWidth  = 700;
var frameHeight = 400;
$('li').css({
    &quot;overflow&quot; : &quot;hidden&quot;
});
$('li img').each(function(){
    var nWidth  = this.naturalWidth  || getNaturalSize(this).width;//ff : ie
    var nHeight = this.naturalHeight || getNaturalSize(this).height;//ff : ie
    if(nHeight &lt; nWidth * (frameHeight / frameWidth)){
        this.width  = nWidth * frameHeight / nHeight;
        this.height = frameHeight;
        $(this).css({
            &quot;width&quot;  : nWidth * frameHeight / nHeight + 'px',
            &quot;height&quot; : frameHeight + 'px',
            &quot;position&quot; : &quot;relative&quot;,
            &quot;left&quot; : -((nWidth * frameHeight / nHeight) - frameWidth) / 2 + 'px'
        });
    }
    else{
        this.width  = frameWidth;
        this.height = nHeight * frameWidth / nWidth;
        $(this).css({
            &quot;width&quot;  : frameWidth + 'px',
            &quot;height&quot; : nHeight * frameWidth / nWidth + 'px',
            &quot;position&quot; : &quot;relative&quot;,
            &quot;top&quot; : -((nHeight * frameWidth / nWidth) - frameHeight) / 2 + 'px'
        });
    }
});
</pre>
<p>以下の部分でブラウザ分岐をしている。IEとOpera以外はimgオブジェクトにオリジナルのサイズが格納されたプロパティ（naturalWidth、naturalHeight）を持つ。</p>
<pre class="brush: jscript;">
var nWidth  = this.naturalWidth  || getNaturalSize(this).width;//ff : ie
var nHeight = this.naturalHeight || getNaturalSize(this).height;//ff : ie
</pre>
<p>getNaturalSize関数は以下のようになる。</p>
<pre class="brush: jscript;">
var getNaturalSize = function(image){
    var w, h, key = &quot;actual&quot;, run, mem;
    if(window.opera){
    }
    if (image[key] &amp;&amp; image[key].src === image.src) {
        return image[key];
    }
    run = image.runtimeStyle;
    mem = {
        &quot;w&quot; : run.width,
        &quot;h&quot; : run.height
    }; // keep runtimeStyle
    run.width  = &quot;auto&quot;; // override
    run.height = &quot;auto&quot;;
    w = image.width;
    h = image.height;
    run.width  = mem.w; // restore
    run.height = mem.h;
    image[key] = {
        &quot;width&quot;  : w,
        &quot;height&quot; : h,
        &quot;src&quot;    : image.src
    };
    return image[key]; // bond
};
</pre>
<p>ちなみにOperaには対応していない。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/01/23/javascript%e3%81%a7%e7%94%bb%e5%83%8f%e3%82%92%e7%b8%a6%e6%a8%aa%e6%af%94%e3%82%92%e7%b6%ad%e6%8c%81%e3%81%97%e3%81%a4%e3%81%a4%e6%8c%87%e5%ae%9a%e3%82%b5%e3%82%a4%e3%82%ba%e3%81%ab%e4%b8%b8%e3%82%81/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>tinyMCEはjQueryのcloneで複製できない</title>
		<link>http://blog.justoneplanet.info/2010/01/17/tinymce%e3%81%afjquery%e3%81%aeclone%e3%81%a7%e8%a4%87%e8%a3%bd%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/</link>
		<comments>http://blog.justoneplanet.info/2010/01/17/tinymce%e3%81%afjquery%e3%81%aeclone%e3%81%a7%e8%a4%87%e8%a3%bd%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 18:06:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2328</guid>
		<description><![CDATA[jQueryのtinyMCEプラグインを使用する。 ■cloneメソッド そっくりそのままコピーができるが、コピーされたtinyMCEは機能しないはずだ。この不具合は、tinyMCEをsortable要素にした時にも生じ [...]]]></description>
			<content:encoded><![CDATA[<p>jQueryのtinyMCEプラグインを使用する。</p>
<h3>■cloneメソッド</h3>
<p>そっくりそのままコピーができるが、コピーされたtinyMCEは機能しないはずだ。この不具合は、tinyMCEをsortable要素にした時にも生じる。恐らく、tinyMCEが内部的にiframeを使用していることに起因するのではないだろうか。</p>
<pre class="brush: jscript;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;無題ドキュメント&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;tiny_mce/tiny_mce.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;tiny_mce/jquery.tinymce.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(function(){
	$('textarea.tinymce').tinymce({
		theme : &quot;advanced&quot;,
		plugins : &quot;safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template&quot;,
		theme_advanced_buttons1 : &quot;save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect&quot;,
		theme_advanced_buttons2 : &quot;cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor&quot;,
		theme_advanced_buttons3 : &quot;tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen&quot;,
		theme_advanced_toolbar_location   : &quot;top&quot;,
		theme_advanced_toolbar_align      : &quot;left&quot;,
		theme_advanced_statusbar_location : &quot;bottom&quot;,
		theme_advanced_resizing : true,
		init_instance_callback : function(){
			var clone = $('div.parts').clone(true);
			$('div.parts').after(clone);
		}
	});
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;parts&quot;&gt;
&lt;form method=&quot;post&quot; action=&quot;&quot;&gt;
&lt;textarea class=&quot;tinymce&quot; name=&quot;&quot; rows=&quot;15&quot; cols=&quot;60&quot;&gt;&lt;/textarea&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>■解決策</h3>
<p>document.createElementでtextareaから生成したtextareaに対して、tinymce()する。</p>
<pre class="brush: jscript;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;無題ドキュメント&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;tiny_mce/tiny_mce.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;tiny_mce/jquery.tinymce.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(function(){
	$('textarea.tinymce').tinymce({
		theme : &quot;advanced&quot;,
		plugins : &quot;safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template&quot;,
		theme_advanced_buttons1 : &quot;save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect&quot;,
		theme_advanced_buttons2 : &quot;cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor&quot;,
		theme_advanced_buttons3 : &quot;tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen&quot;,
		theme_advanced_toolbar_location   : &quot;top&quot;,
		theme_advanced_toolbar_align      : &quot;left&quot;,
		theme_advanced_statusbar_location : &quot;bottom&quot;,
		theme_advanced_resizing : true,
		init_instance_callback : function(){
			var div      = document.createElement('div');
			var form     = document.createElement('form');
			var textarea = document.createElement('textarea');
			$(div).attr('class', 'parts');
			$(div).append(form);
			$(form).append(textarea);
			$(textarea).attr('class', 'tinymce');
			$(textarea).attr('rows', '15');
			$(textarea).attr('cols', '60');
			$('div.parts:last').append(div);
			$(textarea).tinymce({
				theme : &quot;advanced&quot;,
				plugins : &quot;safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template&quot;,
				theme_advanced_buttons1 : &quot;save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect&quot;,
				theme_advanced_buttons2 : &quot;cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor&quot;,
				theme_advanced_buttons3 : &quot;tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen&quot;,
				theme_advanced_toolbar_location   : &quot;top&quot;,
				theme_advanced_toolbar_align      : &quot;left&quot;,
				theme_advanced_statusbar_location : &quot;bottom&quot;,
				theme_advanced_resizing : true
			});
		}
	});
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;parts&quot;&gt;
&lt;form method=&quot;post&quot; action=&quot;&quot;&gt;
&lt;textarea class=&quot;tinymce&quot; name=&quot;&quot; rows=&quot;15&quot; cols=&quot;60&quot;&gt;&lt;/textarea&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>しっかり機能するtinyMCEが生成されるはずだ。</p>
<h4>init_instance_callback</h4>
<p>エディタが完成するとコールされる。tinymce()から完成までは時間がかかり、気をつけなくてはいけないのは、その間にscript処理が止まらない。従って、完成した（直後の）エディタに対してscriptからアクセスする場合は、init_instance_callbackを使用する必要がある。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/01/17/tinymce%e3%81%afjquery%e3%81%aeclone%e3%81%a7%e8%a4%87%e8%a3%bd%e3%81%a7%e3%81%8d%e3%81%aa%e3%81%84/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

