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;
55 $(window).bind('orientationchange', function(){
58 setTimeout(scrollTo, 300, 0, 1);
62 $('#index').load(web_root + session_id + '/index', reinit);
64 function adjust_map() {
65 if ($('#map_canvas').length != 0) {
66 var pos = $(document).height() - 20;
67 setTimeout(scrollTo, 300, 0, 1);
68 $('#map_canvas').height(pos);
72 function inner_reload(url, anim, param) {
74 $('#loading').css('display', 'block').height($(document).height());
75 $('body').append($('<div id="'+url.replace('/','_')+'"></div>').attr('animation', anim).load(web_root + session_id + '/' + url, param, reinit));
77 if (url.match(/all\/[0-9]+/) && !ws) {
78 ws = new WebSocket('ws://' + location.host + '/' + session_id + '/push');
79 ws.addEventListener("open",
83 ws.addEventListener("close",
87 ws.addEventListener("message",
99 function format_date(unixtime) {
100 var d = new Date(unixtime * 1000);
101 var h = String(d.getHours());
102 if (h.length < 2) h = '0' + h;
103 var m = String(d.getMinutes());
104 if (m.length < 2) m = '0' + m;
108 function adjust_height() {
109 $('.scroll_wrap').each(function() {
112 var hi = $('.current:first').height();
113 $('.toolbar, .edit, .info').each(function() {
114 hi -= $(this).attr('offsetHeight');
116 $('.scroll_wrap').each(function() {
121 function reinit(resp, status, xhr) {
122 if (status != 'success' || typeof resp == 'undefined' || resp == '' || xhr.status != 200) {
123 var reload_url = window.location.protocol + '//' + window.location.host + web_root;
124 window.location.replace(reload_url);
128 var from = $('.current');
130 var animation = to.attr('animation');
132 if (animation_end != false && animation && animation != '') {
133 to.addClass(animation + ' in current').one(animation_end, _animation_callback);
134 from.addClass(animation + ' out');
136 to.addClass('current');
137 _animation_callback();
139 $('#loading').css('display', 'none').height(0);
141 function _animation_callback() {
143 to.removeClass('in reverse slide');
145 setTimeout(scrollTo, 300, 0, 1);
147 $('.internal').one('click', function() {
148 var anim = ($(this).hasClass('no_anime') ? '' : $(this).hasClass('reverse') ? 'slide reverse' : 'slide');
149 inner_reload($(this).attr('rel'), anim);
153 $('.internal_form').bind('submit', function () {
155 inner_reload($(this).attr('action'), '', $(this).serializeArray());
159 $('.menu_button').bind('click', function() {
160 $('.floaty').toggle();
161 $('#send_location').forcus();
165 if (!navigator.geolocation) {
166 $('#post_location').css({'display': 'none'});
169 if ($('#map_canvas').length != 0) {
173 $.getScript(web_root + 'geopost-keitairc.js', function() {
181 if ($('#scroll').length != 0) {
182 if (typeof myScroll != 'undefined' && myScroll != null) {
183 myScroll.element.removeEventListener('touchstart', myScroll);
184 myScroll.element.removeEventListener('touchmove', myScroll);
185 myScroll.element.removeEventListener('touchend', myScroll);
186 myScroll.element.removeEventListener('DOMSubtreeModified', myScroll);
187 window.removeEventListener('orientationchange', myScroll);
190 myScroll = new iScroll('scroll');
191 var sc = $('#scroll');
192 var mark = $('#reload_mark');
193 if (mark.length != 0) {
194 sc.bind('touchmove', function() {
195 if (myScroll.y > 30) {
196 mark.attr('reload', 'on').show();
199 sc.bind('touchend', function() {
201 if (mark.attr('reload') == 'on') {
202 mark.removeAttr('reload');
203 inner_reload(mark.attr('rel'), '');
207 $('.toolbar h1').bind('click', function() {
208 myScroll.scrollTo(0,0);