2 -*- mode: javascript; coding: utf-8 -*-
5 Copyright (c) 2010 ISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
6 This program is covered by the GNU General Public License 2
9 function noreferrer(a){
10 if (!$(a).hasClass('href_replaced')) {
11 var url = $(a).attr('href');
12 var html = '<html><head><script type="text/javascript">'
13 + 'document.write(\'<meta http-equiv="refresh" content="0;url='+url+'">\');'
14 + '<'+'/script></head><body></body></html>';
15 $(a).attr('href', 'data:text/html;charset=utf-8,'+encodeURIComponent(html)).addClass('href_replaced');
19 function restore_original(a){
20 $(a).attr('href', $(a).attr('o_href')).removeClass('href_replaced');
24 /* だいぶカオスってきたので整理しないとダメだな こりゃ(わら */
25 jQuery(document).ready(function($) {
27 var preload_image = new Array('right_arrow.png', 'stripe.png',
28 'twg_iphone_toolbar_icons/icon_arrow_left.png',
29 'twg_iphone_toolbar_icons/icon_circle_arrow_right.png',
30 'twg_iphone_toolbar_icons/icon_blog.png',
31 'twg_iphone_toolbar_icons/icon_users.png',
32 'twg_iphone_toolbar_icons/icon_post.png',
33 'twg_iphone_toolbar_icons/icon_flag.png',
34 'twg_iphone_toolbar_icons/icon_cancel.png',
37 for (i = 0; i < preload_image.length; i++) {
38 $('#preload').append('<img src="' + web_root + preload_image[i] + '" />');
41 /* animation end event がハンドリングできるか判定 */
42 var animation_end = false;
43 var el = document.createElement('div');
44 if ('WebkitTransform' in el.style) {
45 animation_end = 'webkitAnimationEnd';
49 var reconnect = false;
54 $(window).bind('orientationchange', function(){
57 setTimeout(scrollTo, 300, 0, 0);
61 $('#index').load(web_root + session_id + '/index', reinit);
63 function adjust_map() {
64 if ($('#map_canvas').length != 0) {
65 var pos = $(document).height() - 20;
66 setTimeout(scrollTo, 300, 0, 0);
67 $('#map_canvas').height(pos);
71 function inner_reload(url, anim, param) {
73 $('#loading').css('display', 'block').height($(document).height());
74 $('body').append($('<div id="'+url.replace('/','_')+'"></div>').attr('animation', anim).load(web_root + session_id + '/' + url, param, reinit));
78 function format_date(unixtime) {
79 var d = new Date(unixtime * 1000);
80 var h = String(d.getHours());
81 if (h.length < 2) h = '0' + h;
82 var m = String(d.getMinutes());
83 if (m.length < 2) m = '0' + m;
87 function adjust_height() {
88 $('.scroll_wrap').each(function() {
91 var hi = $('.current:first').height();
92 $('.toolbar, .edit, .info').each(function() {
93 hi -= $(this).attr('offsetHeight');
95 $('.scroll_wrap').each(function() {
100 function reinit(resp, status, xhr) {
101 if (status != 'success' || typeof resp == 'undefined' || resp == '' || xhr.status != 200) {
102 var reload_url = window.location.protocol + '//' + window.location.host + web_root;
103 window.location.replace(reload_url);
107 var from = $('.current');
109 var animation = to.attr('animation');
111 if (animation_end != false && animation && animation != '') {
112 to.addClass(animation + ' in current').one(animation_end, _animation_callback);
113 from.addClass(animation + ' out');
115 to.addClass('current');
116 _animation_callback();
118 $('#loading').css('display', 'none').height(0);
120 function _animation_callback() {
122 to.removeClass('in reverse slide');
124 setTimeout(scrollTo, 300, 0, 0);
126 $('.internal').one('click', function() {
127 var anim = ($(this).hasClass('no_anime') ? '' : $(this).hasClass('reverse') ? 'slide reverse' : 'slide');
128 inner_reload($(this).attr('rel'), anim);
132 $('.internal_form').bind('submit', function () {
134 inner_reload($(this).attr('action'), '', $(this).serializeArray());
138 $('.menu_button').bind('click', function() {
139 $('.floaty').toggle();
140 $('#send_location').forcus();
144 if (!navigator.geolocation) {
145 $('#post_location').css({'display': 'none'});
148 if ($('#map_canvas').length != 0) {
152 $.getScript(web_root + 'geopost-keitairc.js', function() {
160 if ($('#scroll').length != 0) {
161 if (typeof myScroll != 'undefined' && myScroll != null) {
162 myScroll.element.removeEventListener('touchstart', myScroll);
163 myScroll.element.removeEventListener('touchmove', myScroll);
164 myScroll.element.removeEventListener('touchend', myScroll);
165 myScroll.element.removeEventListener('DOMSubtreeModified', myScroll);
166 window.removeEventListener('orientationchange', myScroll);
169 myScroll = new iScroll('scroll');
170 var sc = $('#scroll');
171 var mark = $('#reload_mark');
172 if (mark.length != 0) {
173 sc.bind('touchmove', function() {
174 if (myScroll.y > 30) {
175 mark.attr('reload', 'on').show();
178 sc.bind('touchend', function() {
180 if (mark.attr('reload') == 'on') {
181 mark.removeAttr('reload');
182 inner_reload(mark.attr('rel'), '');
186 $('.toolbar h1').bind('click', function() {
187 myScroll.scrollTo(0,0);