iPhoneOSにも対応が迫られているざんす。
不毛だなーとはおもうけれども専用サイトをつくることになって頑張っている。
ライブラリとして選択したのはjQTouchというライブラリ。
xm2jsonも使って既存サイトのxmlデータを取り込んで表示させるようにしているので、記事の新規作成はない。(自慢が入っているか?)
全てのXMLを読み込んで表示させれば苦労は無いけど、200件の教室データとかまで読み込むには時間が掛かるので別サイトにしたい。
そこで問題になるのが「もどる」ボタンの処理で悩んでいる。
index.html home>room>i_info.html#params <li class='arrow'><a href='i_info.html?"+$building+"?"+$rowid+"' target='_webapp'>"+$name+"教室</a></li>
こんな感じでメインのページから他のページにパラメータコミでリンクしている。i_indo.htmlから戻りたいのは「home」ではなくて「room」なんだよー
試したのはコレ
i_info.html <a class='back' target='_webapp' href='index.html#room'>room</a>
「room」とidを指定しているが、homeにリダイレクトされてしまう。悲しい・・・
そこで見つけたのが
jQT-hash-linking.patch http://code.google.com/p/jqtouch/issues/detail?id=133 Reported by bmoeskau, Oct 29, 2009 I need to have support for hash-based urls (e.g., http://mysite.com/index.html#foo) for bookmarking, linking, etc. that will load dynamically as pages within jQT. By default, it always redirects to whatever node in the index page has the "current" class and of course does not support remote loading from the hash value. Here is my patch to provide that support. Anytime you load a page remotely via href, it now caches that id/href in localStorage. Then during the jQT startup phase, if there is a hash value in the url, it checks localStorage to see if a corresponding url has been loaded previously and if so loads it. I also added a new optional config setting for a default home page id so that the jQT back button will have something to navigate to by default (since we are loading into the middle of the app somewhere now). It's a first pass that seems to work decently for what I need, but feedback is certainly welcome. I would have liked to write this as a proper extension, but I did not see a way to do that based on where the code had to be modified. Please let me know what you think.
svnを使うことが前提のファイル、使っていないのでなんとか解読中・・・
続く。
続き。
svnファイルを読み解くやり方がよくわからん。
それでも強引にやってみる。
@@ -166,7 +166,7 @@ } }); - // This additionally gets rid of form focusses + // This additionally gets rid of form focuses $body.mousedown(function(e){ var timeDiff = (new Date()).getTime() - lastAnimationTime; if (timeDiff < 200)
「@@」は行番号を指しているんだろうなー、「166行目から7行を削除、166行目から7行を追加」だと想像、取り除くのが「-」で加えるのが「+」だろう。
だとすると、上記は「focusses」を「focusse」と複数形を単数にしただけ。
@@ -175,24 +175,52 @@ 長いので中略
この部分は179行目から192行目を削除
// Make sure exactly one child of body has "current" class if ($('body > .current').length == 0) { currentPage = $('body > *:first'); } else { currentPage = $('body > .current:first'); $('body > .current').removeClass('current'); } // Go to the top of the "current" page $(currentPage).addClass('current'); location.hash = $(currentPage).attr('id'); addPageToHistory(currentPage); scrollTo(0, 0); dumbLoopStart();
代わりに挿入
if(location.hash.length > 1){ // The url has a hash value, so let's try to use that as our starting page id currentPage = $(location.hash); if (currentPage.length == 0) { currentPage = null; // There is not a matching DOM element, so let's see if it matches // a url stored in the local cache that we can try to load below var href = localStorage[location.hash]; } } // If we already have a currentPage from the url hash use it // otherwise get it from the page if(!currentPage){ if ($('body > .current').length == 0) { currentPage = $('body > *:first'); } else { currentPage = $('body > .current:first'); } } // Make sure exactly one child of body has "current" class $('body > .current').removeClass('current'); addPageToHistory(currentPage); // Go to the top of the "current" page scrollTo(0, 0); dumbLoopStart(); if(href){ // Load the page using the url retrieved from localStorage showPageByHref(href); } else { // The page is already there so just show it currentPage.addClass('current'); if(location.hash != currentPage.attr('id')){ location.hash = currentPage.attr('id'); } }
インデントなタブを消したからコピペされるとずれる。
@@ -443,6 +471,7 @@ var firstPage = insertPages(data, settings.animation); if (firstPage) { + localStorage['#'+firstPage.attr('id')] = href; if (settings.method == 'GET' && jQTSettings.cacheGetRequests && settings.$referrer) { settings.$referrer.attr('href', '#' + firstPage.attr('id'));
オリジナルの445と446の間に1行を加えるだけ。
localStorage['#'+firstPage.attr('id')] = href;
を挿入する。
目的のコレ
i_info.html <a class='back' target='_webapp' href='index.html#room'>room</a>
動かない・・・と思っていたら、「jqtouch.min.js」を指定していた。直したら動いたよ!!!
「わーい」と喜んでいたものの、index.html#roomから#homeボタンを押したら
No pages in history. [Break on this error] console.error('No pages in history.');\n
homeから辿らない場合、すべてのページ内リンクがダメになる。
「戻る」が使えないのはNGなので、元に戻すことにした(泣
2010/6/8追記
http://groupaware.mobi/iphone/index.html
http://github.com/ntaku/iphone-samples
これを使えば解決できそう。ためしていないけど。
ついでに
jQTouchちらつき対応
http://www.studio-bloom.net/archives/2235/
対策しておく。きれいに表示されて大満足!!