PhoneGapã¨jQuery Mobileã¨HTML5ã使ã£ã¦JSONãDumpããã¢ããªããµã¯ãã¨ä½ã
少し前にphonegapを知ったã®ã§JavaScriptã使ã£ã¦iPhoneã¢ããªãä½ã£ã¦ã¿ãã
inputã«JSON APIã®URLãå
¥åããã¨ãªã¹ã表示ãã¦ãããDumperã
monmon/dump-for-dd · GitHub
試ãã«ä½ã£ãã ããªã®ã§ã¨ã©ã¼å¦çã¨ãç¹ã«ãã¦ãªããã©ã
http://search.twitter.com/search.json?rpp=50&q=twitter
ã¿ãããªã®ãå
¥åãã¦åããã®ã¯ç¢ºèªããã
ブラウザでも試せるようにしたãã©ããã£ã¡ã¯Ajaxã§åã£ã¦æ¥ããªãã®ã§textareaã«jsonæååå
¥ãã¦dumpã§ããããã«ãã¦ããã
PhoneGapã使ã
PhoneGapã®ã¤ã³ã¹ãã¼ã«ã¯downloadããzipãã¡ã¤ã«è½ã¨ãã¦ãä¸ã«ããiOS/PhoneGapLibInstaller.pkgãéãã ãã§ããã¾ãã
ãã®å¾ã¯Get Startedã«ããéããXcodeã®ãUser TemplatesãããPhoneGapç¨ã®ãã³ãã¬ã¼ããé¸ã³ããã¸ã§ã¯ããä½ãã°OKã
ãã¨ã¯wwwé
ä¸ã®index.htmlå
ã«ããonDeviceReadyã§ãã¤ãéãJavaScriptãæ¸ãã¦ããã°ããã
æ¸ãçµãã£ãããã«ããã¦ã·ãã¥ã¬ã¼ã¿ã§ç¢ºèªããã ãã
Accelerometerã¨ãCameraãªããã使ãããå ´åã«ã¯PhoneGapのAPIãè¦ãã¨ãµã³ãã«ãè¼ã£ã¦ãã®ã§ããããããã
jQuery Mobileã使ã
jQuery Mobileã¯ダウンロードページãããã¦ã³ãã¼ããã¦index.htmlå ã§jQueryã¨ä¸ç·ã«èªã¿è¾¼ãã°ããã
<link rel="stylesheet" href="lib/jquery.mobile-1.0a2.min.css" /> <script type="text/javascript" src="lib/jquery-1.4.4.min.js"></script> <script type="text/javascript" src="lib/jquery.mobile-1.0a2.js"></script>
ãã¨ã¯htmlã¨JavaScriptãæ¸ãã¦ãã
ããããã¨ãã©ã¦ã¶ãªãã§éããæã«jQuery Mobileãæ®éã®HTMLã®ãã¼ã¸ãããã£ã½ãä½ãç´ãã¦ãããã
デフォルト設定の変更とかもできるãã©ãä»åã¯ã¨ããããããã©ã«ãã§è©¦ãã¾ããã
ã¾ãã¯ページについてのドキュメントãçä¼¼ããªãããã¼ã¸ä½ãã
ãã¼ã ã®ãã¼ã¸ã¨ãªãé¨åãä½æããããªæãã§<body>ã®ä¸ã«æ¸ãã
<div id="home" data-role="page" data-theme="c"> <div data-role="header"> <h1>JSON Dumper</h1> </div> <div data-role="content"> <input type="text" name="url" value="" placeholder="input url"> <a href="#dump" data-role="button">Dump</a> <textarea placeholder="debug"></textarea> </div> </div><!-- /#home -->
ãdata-ãã§å§ã¾ãattributeã§jquerymobileãä¸æããã¨ãã£ã¦ãããã
ä¾ãã°data-themeã§jquerymobileã®ãã¼ããé¸ã¹ãã
ここã¨ãここã«è¼ã£ã¦ãã
ãã¨ã¯ããdata-role="page"ããä¸ã¤ã®ãã¼ã¸ã表ãã
ãdata-role="header"ãã¯ãã®ãããé¨åã
http://jquerymobile.com/test/docs/toolbars/docs-headers.html
ãdata-role="content"ãã¯ã¡ã¤ã³é¨åã
ãdata-role="footer"ãã§ããã¿é¨åãä»ããããdata-position="fixed"ãã§ãããåºå®ã§ããããããã ãã©ããã§ã¯çç¥ã
ヘッダのドキュメントãフッタのドキュメントã«è²ã
è¼ã£ã¦ãã
Dumpããæã®ãã¿ã³ã®ä½ãæ¹ã ãã©ãããã¯ドキュメントã«ãããéããdata-role="button"ãã£ã¦æ¸ãã ãã§ããã£ã½ãã®ãä½ãããã
jQuery Mobileã®å ´åãaã¿ã°ã®hrefã§#dumpã¿ããã«æå®ããã¨<div id="dump">ãæ¢ãã¦ã
ãã®divã¸ç§»åããæã«ãã¼ã¸é·ç§»ãã¦ãããããªã¢ãã¡ã¼ã·ã§ã³ï¼ããã©ã«ãã¯slideï¼ãæãã®ã§ä½ãæ°ã«ããªãã¦ããã
ãã ãç¬èªã«ãã¼ã¿ãåå¾ããå ´åãªããã¯ãã¼ã¿åå¾ãã¦ãããã¼ã¸é·ç§»ãããã®ã§
$.mobile.pageLoading(); // ãã¼ãã£ã³ã°éå§ $.mobile.pageLoading(true); // ãã¼ãã£ã³ã°åæ¢
ã¿ãããªæãã§ãã¼ãã£ã³ã°ç»åãå ¥ããããã
ãã¦ãã¦ãdumpãçµãã£ãå¾ã®ãªã¹ã表示ã«ã¤ãã¦ã§ããã
ãªã¹ãã«ã¤ãã¦ãドキュメントãããã®ã§ãããçä¼¼ããã°ããã
æ®éã®
<ul> <li></li> </ul>
ã«.attr('data-role', 'listview')ãã¦ãããã°mobileç¨ã®ãªã¹ããã§ããããã
ãªã¹ãã®ãã¼ãã«ã¤ãã¦ã¯ここã«æ¸ãã¦ããã®ã§å¥ã®ã«ããããã°data-themeãå¤ããã°ããã
ãã¨ã.data('role', 'listview')ã§ãããããã¨æã£ããã©
å
é¨ãã¼ã¿ã¨ãã¦ä¿æããã ãã§<ul data-role="listview">ã«ã¯ãªããªãã¿ããã§ä¸æããããªãã£ãã
ãã ãããªã¹ãã®ãã£ã«ã¿ã表示ãããããã®data-filter="true"ã«é¢ãã¦ã¯.data('filter', 'true')ã§ä¸æããã£ãã®ã§ãããããããã¿ã¤ãã³ã°ã®ããããã
æå¾ã«ãã£ã«ã¿ã«é¢ãã¦ã ãã©ãå ¥åããã¨ã«Enterãæ¼ãããã¨ãã¼ã¸é·ç§»ãããã¨ãã¦ãã¾ãã®ã§submitå¦çãèµ·ãããªãããã«ããã
// ãã£ã«ã¿ã®submitã§ãã¼ã¸é·ç§»ãã¦ãã¾ããªãããã« // filterãä½ããããsubmitå¦çãä¸æ¸ããã $('div').live('pagecreate', function() { $('form[role=search]').submit(function(){ return false; }); });
ãã£ã«ã¿ç¨ã®formã¯jQuery Mobileãåæã«ä½ãã®ã§ãã¢ãã¤ã«ç¨ã®ãã¼ã¸ãä½ã£ãã¿ã¤ãã³ã°(pagecreate)ã§submitå¦çãæ¶ãããã«ãã¦ããã
他にもpagebeforeshowやpageshowなんかãããã
ãã®ä»ã®è©±
ãã³ãã¯HTML5ã®openDatabaseãªããã試ãã¦dumpããå±¥æ´ç®¡çã¨ããããã£ããã ãã©ãã¨ããããlocalStorageã ã使ã£ãã
URLå
¥åãã¦dumpããããã®urlãlocalStorage.ddã«å
¥ãã¦ããã¦ã次åå®è¡æããã¯ãããå
¥åãã¦ããã¦ããã
ã¾ã¨ã
JavaScriptããµã¯ãã¨æ¸ãã¦è©¦ããã®ã¯æ¥½ã
ãã æ®æ®µããObjective-Cã§ä½ã£ã¦ã人ã«ã¨ã£ã¦ã¯æ©è½ããããªããã ãããªã¨æãã