// JavaScript Document/* ============================================= */ /* Smart Phone JavaScript Library */ /* last update: 2012/2/3 */ /*============================================= */ var sp_lib = { ver: "1.3.3", /* ------------------------------------------------------------ 端末判定 ------------------------------------------------------------ */ ua: navigator.userAgent, is: { Android: navigator.userAgent.indexOf("Android") != -1, iPhone: navigator.userAgent.indexOf("iPhone") != -1, iPad: navigator.userAgent.indexOf("iPad") != -1, iOS: navigator.userAgent.indexOf("iPhone") != -1 || navigator.userAgent.indexOf("iPad") != -1, noJQAnimation: (function() { var exceptionUA = ["IS11PT", "N-01D"]; for (var i in exceptionUA) { if (navigator.userAgent.indexOf(exceptionUA[i]) != -1) { return true; } } return false; })() }, /* ------------------------------------------------------------ ライブラリー読み込みに実行、初期設定など ------------------------------------------------------------ */ init: new function() { $(function() { if (!location.hash && (sp_lib.is.iOS || sp_lib.is.Android)) { sp_lib.hideURL(); // ステータスバーを隠す } }); }, /* ------------------------------------------------------------ window.onload時に実行 ------------------------------------------------------------ */ onload: function(handler) { $(window).bind("load", handler); }, /* ------------------------------------------------------------ ページ内スクロール ------------------------------------------------------------ */ anchorLinkScroll: function() { $("a[href^='#'], area[href^='#']").attr("onclick", "sp_lib.anchorLinkScrollControl(this); return false;"); }, anchorLinkScrollControl: function(obj) { var pos = $($(obj).attr("href")).position(); if (pos) { $('html,body').animate({ scrollTop: pos.top }, { duration: 200 }); } }, /* ------------------------------------------------------------ 左右のスワイプイベント ------------------------------------------------------------ */ /* サンプル sp_lib.swipe("#id", sw_callback); function sw_callback(event) { eventにはスワイプ方向のleftかrightの文字列が返ってきます。 } */ swipe: function(id, callback, handler) { var sw_scrollStop = 10; // 水平移動でスクロールを止める距離 var sw_distanceX = 30; // スワイプイベントを発生させる距離 var sw_distanceY = 10; var $this = $(id); $this.bind("touchstart", function(event) { var data = event.originalEvent.touches[0]; var start = { x: data.pageX, y: data.pageY } if (handler) { if (handler.start) { handler.start(start); } } var stop; function moveHandler(event) { var data = event.originalEvent.touches[0]; stop = { x: data.pageX, y: data.pageY } if (Math.abs(start.x - stop.x) > sw_scrollStop) { event.preventDefault(); } if (handler) { if (handler.move) { handler.move(stop); } } } $this.bind("touchmove", moveHandler).one("touchend", function() { $this.unbind("touchmove", moveHandler); var swipeDirection; $("#debug5").html(Math.abs(start.x - stop.x)); if (Math.abs(start.x - stop.x) > sw_distanceX) { if (start.x < stop.x) swipeDirection = "swiperight"; else swipeDirection = "swipeleft"; callback(swipeDirection); } }); }); }, /* ------------------------------------------------------------ スワイプスライドショー ------------------------------------------------------------ */ // ※optionの省略されたときのバグを取る swipeSlide: function(selector, option) { /* optionについて loop: ループの有無 true or false auto: 自動スワイプ flick: フリックを有効にするか attach: 指に追従するか duration: スライドの待機時間 ms changeDuration: スライドのディゾルブ時間 ms controller: ネクストバックのコントローラーの有無(true or false) callback: コールバック関数 */ var $this = $(selector); var obj = { count: $(".swipeSlideInner ul li", $this).size(), current: 0, timerID: 0, flagSwipe: false, first: true, // スライドの最初の時はtrue last: false // スライドの最後の時はtrue }; if (option.loop) { var addSlide = "