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 has_ws = ('WebSocket' in window);
55 $(window).bind('orientationchange', function(){
58 setTimeout(scrollTo, 300, 0, 1);
62 $('#index').load(web_root + session_id + '/index', reinit);
69 setTimeout(_ws_ping, 10000);
74 function adjust_map() {
75 if ($('#map_canvas').length != 0) {
76 var pos = $(document).height() - 20;
77 setTimeout(scrollTo, 300, 0, 1);
78 $('#map_canvas').height(pos);
83 function adjust_height() {
84 $('.scroll_wrap').each(function() {
87 var hi = $('.current:first').height();
88 $('.toolbar, .edit, .info').each(function() {
89 hi -= $(this).attr('offsetHeight');
91 $('.scroll_wrap').each(function() {
96 function reinit(resp, status, xhr) {
97 if (status != 'success' || typeof resp == 'undefined' || resp == '' || xhr.status != 200) {
98 var reload_url = window.location.protocol + '//' + window.location.host + web_root;
99 window.location.replace(reload_url);
103 var from = $('.current');
105 var animation = to.attr('animation');
107 if (animation_end != false && animation && animation != '') {
108 to.addClass(animation + ' in current').one(animation_end, _animation_callback);
109 from.addClass(animation + ' out');
111 to.addClass('current');
112 _animation_callback();
114 $('#loading').css('display', 'none').height(0);
116 function inner_reload(url, anim, param) {
118 $('#loading').css('display', 'block').height($(document).height());
119 $('body').append($('<div id="'+url.replace('/','_')+'"></div>').attr('animation', anim).load(web_root + session_id + '/' + url, param, reinit));
126 if (has_ws && url.match(/all\/([0-9]+)/)) {
128 ws = new WebSocket('ws://' + location.host + '/' + session_id + '/push/' + cid);
129 ws.addEventListener("open",
133 ws.addEventListener("close",
137 ws.addEventListener("message",
139 var data = JSON.parse(e.data);
140 $('div.scroll_wrap ul.edgetoedge li.sep').after(data.formatted);
147 function _animation_callback() {
149 to.removeClass('in reverse slide');
151 setTimeout(scrollTo, 300, 0, 1);
153 $('.internal').one('click', function() {
154 var anim = ($(this).hasClass('no_anime') ? '' : $(this).hasClass('reverse') ? 'slide reverse' : 'slide');
155 inner_reload($(this).attr('rel'), anim);
159 $('.internal_form').bind('submit', function () {
162 ws.send(JSON.stringify({url: $(this).attr('action'),
163 param: $(this).serializeArray()}));
164 $('#m', this).val('');
165 $("input[name='stamp']", this).val(parseInt((new Date)/1000));
166 $('li.messagenew').addClass('message').removeClass('messagenew');
168 inner_reload($(this).attr('action'), '', $(this).serializeArray());
173 $('.menu_button').bind('click', function() {
174 $('.floaty').toggle();
175 $('#send_location').forcus();
179 if (!navigator.geolocation) {
180 $('#post_location').css({'display': 'none'});
183 if ($('#map_canvas').length != 0) {
187 $.getScript(web_root + 'geopost-keitairc.js', function() {
195 if ($('#scroll').length != 0) {
196 if (typeof myScroll != 'undefined' && myScroll != null) {
197 myScroll.element.removeEventListener('touchstart', myScroll);
198 myScroll.element.removeEventListener('touchmove', myScroll);
199 myScroll.element.removeEventListener('touchend', myScroll);
200 myScroll.element.removeEventListener('DOMSubtreeModified', myScroll);
201 window.removeEventListener('orientationchange', myScroll);
204 myScroll = new iScroll('scroll');
205 var sc = $('#scroll');
206 var mark = $('#reload_mark');
207 if (mark.length != 0) {
208 sc.bind('touchmove', function() {
209 if (myScroll.y > 30) {
210 mark.attr('reload', 'on').show();
213 sc.bind('touchend', function() {
215 if (mark.attr('reload') == 'on') {
216 mark.removeAttr('reload');
217 inner_reload(mark.attr('rel'), '');
221 $('.toolbar h1').bind('click', function() {
222 myScroll.scrollTo(0,0);