(function() { //if ( 'undefined' === Cookies ) { throw( "Cookies.js is required" ); } if ('undefined' === typeof jQuery) { throw ("jQuery is required"); } var $ = jQuery; var Peatix = {}; Peatix.Util = { isMobileAgent: function () { // based on https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser var ua = navigator.userAgent; if ( ua.match(/Android/i) || ua.match(/iPhone/i) || ua.match(/iPad/i) || ua.match(/iPod/i) || ua.match(/Windows Phone/i) ) { return true; } return false; }, legacy_ie: function(version) { if (!version) version = 7; var legacy = false; if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) legacy = (new Number(RegExp.$1)) <= version; return legacy; }, canSupportCS: function() { return 'undefined' !== typeof WebSocket && 'undefined' !== typeof localStorage; }, canSupportHTML5Scanner: function () { return 'undefined' !== typeof window.navigator.getUserMedia && 'undefined' !== typeof window.AudioContext; }, distanceBetween: function ( lat1, lng1, lat2, lng2 ) { var R = 6371; var dLat = Math.PI * (lat2-lat1) / 180; var dLng = Math.PI * (lng2-lng1) / 180; var lat1 = Math.PI * lat1 / 180; var lat2 = Math.PI * lat2 / 180; var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.sin(dLng/2) * Math.sin(dLng/2) * Math.cos(lat1) * Math.cos(lat2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); return R * c; }, hasGeoLocationSupport: function () { return 'undefined' !== typeof navigator && 'undefined' !== typeof navigator.geolocation; }, deviceDistanceFor: function ( lat, lng, cb, error_cb, locationManager ) { var retryCount = 1; var done = function ( e, lat, lng, cb ) { var d = Peatix.Util.distanceBetween( lat, lng, e.coords.latitude, e.coords.longitude ); cb(d,e); }; var fail = function ( error, error_cb ) { // NOTE #66481006 // Besides, often you can't get your location because navigator.geolocation.getCurrentPosition get "POSITION_UNAVAILABLE:2" error. // => Retry navigator.geolocation.getCurrentPosition if it get the error above. if(2 == error.code && retryCount < 3) { retryCount++; getPosition( lat, lng, cb, error_cb ); } else { error_cb(error); } }; var getPosition = function ( lat, lng, cb, error_cb ) { if( 'undefined' !== typeof locationManager && 'undefined' !== typeof locationManager.getKnownLocation ) { var jsonString = locationManager.getKnownLocation(); if(null != jsonString) { var location = JSON.parse(jsonString); done(location, lat, lng, cb); return; } } navigator.geolocation.getCurrentPosition(function (e) { done(e, lat, lng, cb); } , function (error) { fail(error, error_cb); } ,{ // NOTE #66481006 // You can't get your location by GPS, not Wifi, on azuki-android and each browsers, on Android. // => navigator.geolocation.getCurrentPosition use "enableHighAccuracy : true". enableHighAccuracy : true, // NOTE #66481006 // ColorSync retry before navigator.geolocation.getCurrentPosition has finished. // => Set a timeout value which should be small than the timeout value in checkColorsyncReady. timeout : 1000 * 25, }); }; getPosition( lat, lng, cb, error_cb ); }, formatNumber: function( num, opt ) { if (num === 0) return "0"; var defaultOpt = { "decimalPrecision": 2, "decimalSeparator": ".", "thousandSeparator": "," }; if (typeof opt === "undefined") opt = defaultOpt; else { if (typeof opt["decimalPrecision"] === "undefined") opt["decimalPrecision"] = defaultOpt.decimalPrecision; if (typeof opt["decimalSeparator"] === "undefined") opt["decimalSeparator"] = defaultOpt.decimalSeparator; if (typeof opt["thousandSeparator"] === "undefined") opt["thousandSeparator"] = defaultOpt.thousandSeparator; } var negate = false; if (num < 0) { negate = true; num = Math.abs(num); } var numStr = num.toFixed(opt.decimalPrecision); if (numStr === "0") return "0"; var numParts = numStr.split("."); // this is always "." according to ECMA var integerPart = numParts[0]; if (integerPart.length % 3 === 1) integerPart = "00" + integerPart; else if (integerPart.length % 3 === 2) integerPart = "0" + integerPart; var thousands = integerPart.split(/(.{3})/).filter(Boolean); integerPart = thousands.join(opt.thousandSeparator); integerPart = integerPart.replace(/^0+/, ""); numParts[0] = integerPart; if (negate) numParts[0] = '-' + numParts[0]; var localNumStr = numParts.join(opt.decimalSeparator); return localNumStr; }, isDateInputAvailable: function() { var input = document.createElement('input'); input.setAttribute('type','date'); var val = 'not-valid-date-value'; input.setAttribute('value', val); return (input.value !== val); } }; var waitings = {}; Peatix.UI = { open_modal_window: function(event, popID, popURL, opts) { var DefaultOptions = { closeButton: true, // TODO: more better name e.g. exclusive mode...? }; opts = $.extend(DefaultOptions, opts); if (!popID) popID = $(this).attr('rel'); //Get Popup Name if (!popURL) popURL = $(this).attr('href'); //Get Popup href to define size var query = popURL.split('?'); var dim; if (2 < query.length) dim = query[2].split('&'); else dim = query[1].split('&'); var popWidth = dim[0].split('=')[1]; //Gets the first query string value //Fade in the Popup and add close button var closeButtonHtml = 'Close'; if ($(this).is('.popreload')) closeButtonHtml = 'Close'; if (legacy_ie(8)) { $('a.close').remove(); $('.popup_block').hide(); if (legacy_ie(6)) $('#wrap').css({ 'width': Number(popWidth) }); var popDiv = $('#' + popID).detach(); popDiv.css({ 'position': 'absolute', 'top': $(window).scrollTop() + 'px', 'left': (document.body.scrollWidth / 2 - popWidth / 2) + 'px', 'width': Number(popWidth), 'background-color': '#FFF', 'border': '5px solid #666' }); $('#wrap').prepend(popDiv); popDiv.stop().fadeIn(function() { if ( opts.closeButton ) { $(this).prepend(closeButtonHtml); } }); if ( !opts.closeButton ) { window.Config.__popupIsExclusive = true; }; } else { $('#' + popID).css({ 'width': Number(popWidth) }) .stop() .fadeIn(function() { if ( opts.closeButton ) { $(this).prepend(closeButtonHtml); } }); $('#fade').stop().fadeIn(function() { $('body').css({ 'width': document.body.scrollWidth }); $(this).css({ 'overflow-y': 'scroll' }); }); if ( !opts.closeButton ) { window.__popupIsExclusive = true; }; } // prevent dismiss if opts.dismiss = false; if (opts.hasOwnProperty('dismiss') && !opts.dismiss) { $('a.close').remove(); $('#fade').on('click', function (e) { e.stopPropagation(); }); } var iframe = document.getElementById('ifr-' + popID); if (iframe) { if (legacy_ie()) resize_iframe(popID, iframe.contentWindow.document.body.scrollHeight); else { $(iframe).css({ width: (popWidth - 40) }); iframe.contentWindow.postMessage('popup_opened::' + popID, iframe.getAttribute('src')); } } $('body').trigger('popupOpened', [popID]); return false; }, close_modal_window: function(e) { var element; if (e) element = e.target; else element = this; if ( window.__popupIsExclusive === true ) { if ( $(element).is('#fade') ) { return true; } } window.__popupIsExclusive = false; var ids = new Array(); $('.popup_block:visible').each(function(k, v) { ids.push($(this).attr('id')); }); // Reset these styles to normal $('body').css({ 'width': '100%' }); $('#fade').css({ 'overflow-y': 'hidden' }).stop().fadeOut(function() { $('.popup_block').hide(); $('body').css({ 'width': '100%' }); }); if ($(element).is('.popreload')) window.location.reload(); if (!legacy_ie()) { var popID = $(element).attr('rel'); var iframe = document.getElementById('ifr-' + popID); if (iframe) iframe.contentWindow.postMessage('popup_closed::' + popID, iframe.getAttribute('src')); $.each(ids, function(i, v) { $('body').trigger('popupClosed', [v]); }); } return false; }, /** * @param dismiss boolean, prevent dismiss when click outside * **/ confirm: function(opts) { var DefaultOptions = { }; opts = $.extend(DefaultOptions, opts); function fadeout () { $('#fade').css({ 'overflow-y': 'hidden' }).stop().fadeOut(function() { $('.popup_block').hide(); $('body').css({ 'overflow': 'auto', 'width': '100%' }); }); } var $popup = $(opts.popupSelector); $popup.find(opts.confirmSelector) .off('click') .on('click', function () { opts.confirm(); fadeout(); }); $popup.find(opts.cancelSelector) .off('click') .on('click', function () { opts.cancel(); fadeout(); }); $('#fade').stop().fadeIn(function() { $('body').css({ 'width': document.body.scrollWidth }); $(this).css({ 'overflow-y': 'scroll' }); }); $popup.stop().fadeIn(); // prevent dismiss if opts.dismiss = false; if (opts.hasOwnProperty('dismiss') && !opts.dismiss) { $('a.close').remove(); $('#fade').on('click', function (e) { e.stopPropagation(); }); } }, add_global_message: function(message, type, ttl) { var opts = { type: type, container: $('#global-message').empty(), ttl: ttl }; if ( type === 'success' && 'undefined' === ttl ) { opts.ttl = 2000; } Peatix.Notification.notify( message, opts ); }, close_message: function(anchor) { $(anchor).parent('.msg-error,.msg-info,.msg-success').stop().fadeOut('fast'); }, clear_global_messages: function() { $('#global-message div').remove(); }, clear_errors: function() { $('.error.txt-field,select.error').removeClass('error'); }, resize_iframe: function(id, height) { if (!id) id = document.body.id; if (!id) return; try { height = parseInt(height); var my_frame = document.getElementById('ifr-' + id); var current_height = parseInt($(my_frame).css('height').replace(/\D/, '')); if (current_height < height) { if (/Firefox/.test(navigator.userAgent)) $(my_frame).css({ height: height + 10 }); else $(my_frame).animate({ height: height + 10 }); } else if ((current_height > height) && (current_height > 360)) { if (/Firefox/.test(navigator.userAgent)) { my_frame.style.height = '0px'; my_frame.style.height = (Math.max(height + 10, 360)) + 'px'; } else $(my_frame).animate({ height: Math.max(height + 10, 360) }); } } catch (ex) {} }, add_chromeless_message: function(type, id, message, parent_id) { return Peatix.Notification.notify(message, { type: type, id: id, container: parent_id ? $( '#' + parent_id ) : $('.window-message') }); }, clear_chromeless_messages: function(duration) { $('.window-message div').stop().fadeOut(duration); }, update_view: function(json_data) { if (json_data) { for (var idx in json_data) { if (!json_data.hasOwnProperty(idx)) continue; var element = $('#field-event-' + idx); var parent = element.parent(); if (element) { parent.hide(); var html = json_data[idx].html; if ($(html).is('.add-link')) { element.parents('.editable').addClass('empty-field'); } else { element.parents('.editable').removeClass('empty-field'); } element.parents('.editable').removeClass('no-highlight'); element.replaceWith(html); parent.fadeIn(); } $('#event-' + idx).find('.event-required').remove(); } } }, pop_load_iframe: function(pop_id, url, callback) { $('#ifr-' + pop_id).load(function() { if (typeof callback == 'function') callback(); open_modal_window(undefined, pop_id, '#?w=520'); }); $('#ifr-' + pop_id)[0].contentWindow.location.href = url; $('#ifr-' + pop_id).attr('src', url); }, email_alert: function(frame_id) { $('input[type=email]').blur(function() { var email_address = $(this).val(); if (!email_address) return; var email_parts = email_address.split('@'); var email_domain = email_parts[email_parts.length - 1]; email_domain = $.trim(email_domain); var warning_message; var warning_accepted = ''; if (legacy_ie(8)) warning_accepted = '内容を確認しました'; if ($.inArray(email_domain, ['yahoo.co.jp', 'ybb.ne.jp']) >= 0) { warning_message = '
お申込み前に必ずご確認ください!
Yahoo!メールをご利用のお客様はPeatixからのメールが迷惑メールフォルダに受信される可能性がございます。
'; warning_message += warning_accepted; warning_message += 'お申込み前に必ずご確認ください!
迷惑メール対策などのためにドメイン指定受信を利用されているお客様は、お持ちの携帯電話にて「@peatix.com」を受信できるように設定してください。
'; if (email_domain == 'docomo.ne.jp' || email_domain == 'disneymobile.ne.jp') warning_message += '' else if (email_domain == 'softbank.ne.jp' || email_domain == 'disney.ne.jp' || email_domain.match(/vodafone\.ne\.jp/)) warning_message += 'iPhoneをご利用のお客様は「@i.softbank.jp」のメールアドレスを上のEメール欄に入力してください。
' warning_message += '受信設定を行わずにお申込みいただいたくと、お申込み詳細メールをお届けすることができません。
「 @ezweb.ne.jp」のメールアドレス宛にPeatixから送ったメールは本文が表示されない場合があります。
Gmailなど他のメールアドレスを登録してください。
「 @au.com」のメールアドレス宛にPeatixから送ったメールは本文が表示されない場合があります。
Gmailなど他のメールアドレスを登録してください。