<?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>digital matter &#187; JavaScript</title>
	<atom:link href="http://blog.loadlimits.info/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.loadlimits.info</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:43:32 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>html5uploaderで複数アップロード時のバグ修正</title>
		<link>http://blog.loadlimits.info/2011/03/html5uploader%e3%81%a7%e8%a4%87%e6%95%b0%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e6%99%82%e3%81%ae%e3%83%90%e3%82%b0%e4%bf%ae%e6%ad%a3/</link>
		<comments>http://blog.loadlimits.info/2011/03/html5uploader%e3%81%a7%e8%a4%87%e6%95%b0%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e6%99%82%e3%81%ae%e3%83%90%e3%82%b0%e4%bf%ae%e6%ad%a3/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 08:05:20 +0000</pubDate>
		<dc:creator>hotpi</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[解決]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.loadlimits.info/2011/03/html5uploader%e3%81%a7%e8%a4%87%e6%95%b0%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e6%99%82%e3%81%ae%e3%83%90%e3%82%b0%e4%bf%ae%e6%ad%a3/</guid>
		<description><![CDATA[Gmailのようなドラッグアンドドロップでファイルをアップロードする機能が使いたかったので探していたところ、見つけたのがhtml5uploaderです。JSと、サーバーサイドのPHPが付いてます。 html5uploader デモ http://www.weeby.pl/blog/html5uploader/uploader.html 比較的簡単な構造で最低限のアップロード機能を実装しているので、elFinderと組み合わせて使うことにしました。 で、表題のバグですが、複数のファイルを同時にアップロードすることはできるのですが、時々サーバからNo file to uploadというメッセージが返ってくることがあります。リクエストを見ると、送るはずのContent-Lengthが0バイトで、データを送信していないようです。 原因はonloadendイベントの関数でreaderオブジェクトを直接呼び出して使ってるからですね。というわけで修正。 // Once the process of reading file this.loadEnd = function() { bin = reader.result; を // Once the process of reading file this.loadEnd = function() { bin = event.target.result; に修正して完了です。 Pluploadの方が高性能かつソースもきれいでよく出来てるのですが、GPLなんですよね。コマーシャルライセンスは10ユーロなんで良心的で安いんですが。今回はファイルマネージャーに統合しちゃいたかったので、小型のhtml5uploaderにしてみました。 elFinderがDnDのアップロードに対応しないかなぁ。]]></description>
			<content:encoded><![CDATA[<p>Gmailのようなドラッグアンドドロップでファイルをアップロードする機能が使いたかったので探していたところ、見つけたのがhtml5uploaderです。JSと、サーバーサイドのPHPが付いてます。</p>
<p><a href="http://code.google.com/p/html5uploader/" target="_blank">html5uploader</a></p>
<p>デモ   <br /><a title="http://www.weeby.pl/blog/html5uploader/uploader.html" href="http://www.weeby.pl/blog/html5uploader/uploader.html">http://www.weeby.pl/blog/html5uploader/uploader.html</a></p>
<p>比較的簡単な構造で最低限のアップロード機能を実装しているので、<a href="http://elrte.org/jp/elfinder/" target="_blank">elFinder</a>と組み合わせて使うことにしました。</p>
<p>で、表題のバグですが、複数のファイルを同時にアップロードすることはできるのですが、時々サーバからNo file to uploadというメッセージが返ってくることがあります。リクエストを見ると、送るはずのContent-Lengthが0バイトで、データを送信していないようです。</p>
<p>原因はonloadendイベントの関数でreaderオブジェクトを直接呼び出して使ってるからですね。というわけで修正。</p>
<div style="padding-bottom: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;float: none;padding-top: 0px" class="wlWriterEditableSmartContent">
<pre>// Once the process of reading file
this.loadEnd = function() {
	bin = reader.result;
</pre>
</div>
<p>を</p>
<div style="padding-bottom: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;float: none;padding-top: 0px" class="wlWriterEditableSmartContent">
<pre>// Once the process of reading file
this.loadEnd = function() {
	bin = event.target.result;
</pre>
</div>
<p>に修正して完了です。</p>
<p><a href="http://www.plupload.com/" target="_blank">Plupload</a>の方が高性能かつソースもきれいでよく出来てるのですが、GPLなんですよね。コマーシャルライセンスは10ユーロなんで良心的で安いんですが。今回はファイルマネージャーに統合しちゃいたかったので、小型のhtml5uploaderにしてみました。</p>
<p>elFinderがDnDのアップロードに対応しないかなぁ。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.loadlimits.info/2011/03/html5uploader%e3%81%a7%e8%a4%87%e6%95%b0%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e6%99%82%e3%81%ae%e3%83%90%e3%82%b0%e4%bf%ae%e6%ad%a3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>リバースProxy環境でのmixiアプリのOAuth</title>
		<link>http://blog.loadlimits.info/2009/11/%e3%83%aa%e3%83%90%e3%83%bc%e3%82%b9proxy%e7%92%b0%e5%a2%83%e3%81%a7%e3%81%aemixi%e3%82%a2%e3%83%97%e3%83%aa%e3%81%aeoauth/</link>
		<comments>http://blog.loadlimits.info/2009/11/%e3%83%aa%e3%83%90%e3%83%bc%e3%82%b9proxy%e7%92%b0%e5%a2%83%e3%81%a7%e3%81%aemixi%e3%82%a2%e3%83%97%e3%83%aa%e3%81%aeoauth/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 15:32:11 +0000</pubDate>
		<dc:creator>hotpi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mixiアプリ]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.loadlimits.info/2009/11/%e3%83%aa%e3%83%90%e3%83%bc%e3%82%b9proxy%e7%92%b0%e5%a2%83%e3%81%a7%e3%81%aemixi%e3%82%a2%e3%83%97%e3%83%aa%e3%81%aeoauth/</guid>
		<description><![CDATA[CakePHPでmixiアプリのOAuthを処理させる方法は以下のサイト参照。ホントにシンプルでわかりやすい解説。 [cakephp] mixiアプリのOAuthのリクエストを受け取る &#8211; 「のーぶるじゃすぱー」略して「のぶじゃす」のBLOG 通常の環境ではこのまま実装すればOK。 で、このあとロードバランサーの入ったサーバに持ってきたらOAuthが正しく認証されない。 OAuthRequestのhttp_urlを見てみると、 http://192.168.0.2:8001:80//api/hoge/hoge/… という悲しいことになっていて、これがどうも問題のようだと。というか、ホスト：ポート：ポートってどういうことだ… 本来ならもちろん、 http://mixiapp.sample.com:80/api/hoge/hoge/… みたいなアドレスになっていないといけない。 ちなみに送信側はmixiアプリのサンプルそのまんまな感じのJavaScript var params = {}; params[gadgets.io.RequestParameters.REFRESH_INTERVAL] = 0; params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED; params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT; var url = "http://mixiapp.sample.com/api/hoge/hoge/"; gadgets.io.makeRequest(url, func, params); 解決策は function validateOAuth () { $get = $_GET; unset($get['url']); $http_url = 'http://mixiapp.sample.com:80/' . ltrim($_SERVER['REQUEST_URI'],'/'); $request = OAuthRequest::from_request(null, $http_url, array_merge($get, $_POST)); if [...]]]></description>
			<content:encoded><![CDATA[<p>CakePHPでmixiアプリのOAuthを処理させる方法は以下のサイト参照。ホントにシンプルでわかりやすい解説。</p>
<p><a href="http://test.noble-jasper.com/blog/2009/08/cakephp-mixioauth.html" target="_blank">[cakephp] mixiアプリのOAuthのリクエストを受け取る &#8211; 「のーぶるじゃすぱー」略して「のぶじゃす」のBLOG</a></p>
<p>通常の環境ではこのまま実装すればOK。</p>
<p>で、このあとロードバランサーの入ったサーバに持ってきたらOAuthが正しく認証されない。</p>
<p>OAuthRequestのhttp_urlを見てみると、</p>
<blockquote><p>http://192.168.0.2:8001:80//api/hoge/hoge/…</p>
</blockquote>
<p>という悲しいことになっていて、これがどうも問題のようだと。というか、ホスト：ポート：ポートってどういうことだ…</p>
<p>本来ならもちろん、</p>
<blockquote><p>http://mixiapp.sample.com:80/api/hoge/hoge/…</p>
</blockquote>
<p>みたいなアドレスになっていないといけない。</p>
<p>ちなみに送信側はmixiアプリのサンプルそのまんまな感じのJavaScript</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:f9cc1684-ee04-4e83-b0aa-070f94da3be5" class="wlWriterEditableSmartContent">
<pre name="code" class="js">var params = {};
params[gadgets.io.RequestParameters.REFRESH_INTERVAL] = 0;
params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
var url = "http://mixiapp.sample.com/api/hoge/hoge/";
gadgets.io.makeRequest(url, func, params);
</pre>
</div>
<p>解決策は</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ee9beadb-9dbe-4811-bc01-e61a7a00d780" class="wlWriterEditableSmartContent">
<pre name="code" class="php">function validateOAuth () {

    $get = $_GET;
    unset($get['url']);
    $http_url = 'http://mixiapp.sample.com:80/' . ltrim($_SERVER['REQUEST_URI'],'/');
    $request = OAuthRequest::from_request(null, $http_url, array_merge($get, $_POST));
    if ($_GET['oauth_consumer_key'] == 'mixi.jp') {
        @$signature_valid = $this-&gt;MixiAppliOauth-&gt;check_signature($request, null, null, $get["oauth_signature"]);
    }

    if ($signature_valid == true || Configure::read('debug')) {

        $this-&gt;oauth_valid = true;
        $this-&gt;viewer_id   = $get['opensocial_viewer_id'];
        $this-&gt;owner_id    = $get['opensocial_owner_id'];

        return $get;

    }

    return false;

}
</pre>
</div>
<p>というように、from_requestの第二引数にURLを指定してやればOK。なぜかスラッシュが２つ付いていたので削って付けなおしてます。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.loadlimits.info/2009/11/%e3%83%aa%e3%83%90%e3%83%bc%e3%82%b9proxy%e7%92%b0%e5%a2%83%e3%81%a7%e3%81%aemixi%e3%82%a2%e3%83%97%e3%83%aa%e3%81%aeoauth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhoneのSafariでtouchendイベントを使うときの注意</title>
		<link>http://blog.loadlimits.info/2009/10/iphone%e3%81%aesafari%e3%81%a7touchend%e3%82%a4%e3%83%99%e3%83%b3%e3%83%88%e3%82%92%e4%bd%bf%e3%81%86%e3%81%a8%e3%81%8d%e3%81%ae%e6%b3%a8%e6%84%8f/</link>
		<comments>http://blog.loadlimits.info/2009/10/iphone%e3%81%aesafari%e3%81%a7touchend%e3%82%a4%e3%83%99%e3%83%b3%e3%83%88%e3%82%92%e4%bd%bf%e3%81%86%e3%81%a8%e3%81%8d%e3%81%ae%e6%b3%a8%e6%84%8f/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 04:45:22 +0000</pubDate>
		<dc:creator>hotpi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[解決]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.loadlimits.info/2009/10/iphone%e3%81%aesafari%e3%81%a7touchend%e3%82%a4%e3%83%99%e3%83%b3%e3%83%88%e3%82%92%e4%bd%bf%e3%81%86%e3%81%a8%e3%81%8d%e3%81%ae%e6%b3%a8%e6%84%8f/</guid>
		<description><![CDATA[iPhone用のドラッグアンドドロップで操作できるWebアプリを作っていて、うっかりはまったtouchendの挙動についてのメモ。 最初に書いたコードはこんな感じでした。 function touchhandler(e) { var x = e.touches[0].pageX; switch (e.type) { case 'touchstart': break; case 'touchmove': break; case 'touchend': break; } } document.getElementById('sample').addEventListener("touchend", touchhandler, false); このプログラムではtouchendの処理が実行されません。 というのもまぁ、気づけば簡単なことなんですが、最後の指をスクリーンから離してtouchendのイベントが発生するときは、もうスクリーンに触ってないのでe.touches[0]がundefinedになるんですね… なので、touchendのときは、引数で受け取ったe.touchesは注意しましょうという話。 今回参考にさせていただいたのは以下のサイト。 flashcast：フリーで働くITエンジニア集団のブログ: ipod touch用のWeb Applicationを作成してみる（canvasでお絵かき編） SitePen Web開発参考サイト &#8211; iPhone 3G DevWiki]]></description>
			<content:encoded><![CDATA[<p>iPhone用のドラッグアンドドロップで操作できるWebアプリを作っていて、うっかりはまったtouchendの挙動についてのメモ。</p>
<p>最初に書いたコードはこんな感じでした。</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:a708bcd8-fefa-4a86-aa53-3caf65403c88" class="wlWriterEditableSmartContent">
<pre name="code" class="js">function touchhandler(e) {
    var x = e.touches[0].pageX;
    switch (e.type) {
        case 'touchstart':
            break;
        case 'touchmove':
            break;
        case 'touchend':
            break;
    }
}

document.getElementById('sample').addEventListener("touchend", touchhandler, false);
</pre>
</div>
<p>このプログラムではtouchendの処理が実行されません。</p>
<p>というのもまぁ、気づけば簡単なことなんですが、最後の指をスクリーンから離してtouchendのイベントが発生するときは、もうスクリーンに触ってないのでe.touches[0]がundefinedになるんですね…</p>
<p>なので、touchendのときは、引数で受け取ったe.touchesは注意しましょうという話。</p>
<p>今回参考にさせていただいたのは以下のサイト。</p>
<p><a href="http://flashcast.jp/blog/2008/12/ipod-touchweb-applicationcanvas.html" target="_blank">flashcast：フリーで働くITエンジニア集団のブログ: ipod touch用のWeb Applicationを作成してみる（canvasでお絵かき編）</a></p>
<p><a href="http://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone/" target="_blank">SitePen</a></p>
<p><a title="http://wiki.sohaya.com/index.php/Web%E9%96%8B%E7%99%BA%E5%8F%82%E8%80%83%E3%82%B5%E3%82%A4%E3%83%88" href="http://wiki.sohaya.com/index.php/Web%E9%96%8B%E7%99%BA%E5%8F%82%E8%80%83%E3%82%B5%E3%82%A4%E3%83%88" target="_blank">Web開発参考サイト &#8211; iPhone 3G DevWiki</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.loadlimits.info/2009/10/iphone%e3%81%aesafari%e3%81%a7touchend%e3%82%a4%e3%83%99%e3%83%b3%e3%83%88%e3%82%92%e4%bd%bf%e3%81%86%e3%81%a8%e3%81%8d%e3%81%ae%e6%b3%a8%e6%84%8f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pythonのwin32comからSilverlightを使おうと試みる</title>
		<link>http://blog.loadlimits.info/2009/10/python%e3%81%aewin32com%e3%81%8b%e3%82%89silverlight%e3%82%92%e4%bd%bf%e3%81%8a%e3%81%86%e3%81%a8%e8%a9%a6%e3%81%bf%e3%82%8b/</link>
		<comments>http://blog.loadlimits.info/2009/10/python%e3%81%aewin32com%e3%81%8b%e3%82%89silverlight%e3%82%92%e4%bd%bf%e3%81%8a%e3%81%86%e3%81%a8%e8%a9%a6%e3%81%bf%e3%82%8b/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 06:56:25 +0000</pubDate>
		<dc:creator>hotpi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[疑問]]></category>
		<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.loadlimits.info/2009/10/python%e3%81%aewin32com%e3%81%8b%e3%82%89silverlight%e3%82%92%e4%bd%bf%e3%81%8a%e3%81%86%e3%81%a8%e8%a9%a6%e3%81%bf%e3%82%8b/</guid>
		<description><![CDATA[最終的にはPythonで書かれたWindowsアプリケーションで、Silverlightのコンテンツをロードしたいという目的なのですが、とりあえずSilverlightのActiveXコントロールを読み込んで動作を確認してみたいので色々実験。 まず、インストールされているSilverlightのバージョンを調べてみる。 Javascriptで書かれたコードがいくつか見つかったのでそれを書き直す。 以下はJS版。 var control = new ActiveXObject('AgControl.AgControl'); alert(control.IsVersionSupported('3.0')); これをPythonで書いてみる。 import win32com.client control = win32com.client.Dispatch("AgControl.AgControl") print control.IsVersionSupported('3.0') Silverlight 3がインストールされていればTrueが表示されます。 他にどんなメソッドが定義されているのかを調べるために、Visual StudioからAgControlを参照して、オブジェクトブラウザで調査。 というか、Silverlightのプラグインのリファレンスがあった。 Silverlight プラグインのオブジェクト リファレンス が…Sourceを指定してもIsLoadedプロパティがTrueにならない…うーん…もう少し調べてみる。]]></description>
			<content:encoded><![CDATA[<p>最終的にはPythonで書かれたWindowsアプリケーションで、Silverlightのコンテンツをロードしたいという目的なのですが、とりあえずSilverlightのActiveXコントロールを読み込んで動作を確認してみたいので色々実験。</p>
<p>まず、インストールされているSilverlightのバージョンを調べてみる。</p>
<p>Javascriptで書かれたコードがいくつか見つかったのでそれを書き直す。</p>
<p>以下はJS版。</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:1fad3344-c133-4716-b122-991f00b3f96e" class="wlWriterEditableSmartContent">
<pre name="code" class="js">var control = new ActiveXObject('AgControl.AgControl');
alert(control.IsVersionSupported('3.0'));
</pre>
</div>
<p>これをPythonで書いてみる。</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:2ef33f5a-557a-48de-85a2-d2d00e450645" class="wlWriterEditableSmartContent">
<pre name="code" class="py">import win32com.client
control = win32com.client.Dispatch("AgControl.AgControl")
print control.IsVersionSupported('3.0')</pre>
</div>
<p>Silverlight 3がインストールされていればTrueが表示されます。</p>
<p>他にどんなメソッドが定義されているのかを調べるために、Visual StudioからAgControlを参照して、オブジェクトブラウザで調査。</p>
<p>というか、Silverlightのプラグインのリファレンスがあった。</p>
<p><a href="http://msdn.microsoft.com/ja-jp/library/cc838259(VS.95).aspx" target="_blank">Silverlight プラグインのオブジェクト リファレンス</a></p>
<p>が…Sourceを指定してもIsLoadedプロパティがTrueにならない…うーん…もう少し調べてみる。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.loadlimits.info/2009/10/python%e3%81%aewin32com%e3%81%8b%e3%82%89silverlight%e3%82%92%e4%bd%bf%e3%81%8a%e3%81%86%e3%81%a8%e8%a9%a6%e3%81%bf%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

