$(function(){ // 処理用変数の初期化 var timer = false; // 画面更新タイマーのフラグ var menuTop = parseInt($('#menu').css('top').replace('px', ''), 10); // メニュー初期top位置 var supportedWebGL = LW.Check.WebGL(document.getElementById('bg-canvas')); var audio = null; // Cookieの値を変換 getArgValues(); // 背景画像をキャッシングしておく if ((cookieVal['NML_BACK'] != 'plain') && (cysBack['img'] != '')) { var imgBack = new Image(); imgBack.src = '/common/img/back/' + cysBack['img']; imgBack.fileSize; } // Cookie無効なら一応警告しておく if (!navigator.cookieEnabled) { $("noscript").after('

Cookieが無効になっているため、設定の保存が行えません。
現在セーフモードで起動中です。

'); } // ウインドウ関係 $(window) // 画面リサイズ時のcanvas要素サイズ調整および再描画 .resize(function() { if (supportedWebGL && cookieVal['WALLPAPER_NAME'] != 'Normal') { // 処理が重いため、200ms経過で操作がなければ実行する if (timer !== false) { clearTimeout(timer); } timer = setTimeout(function() { LW.Renderer.Resize(cookieVal['LIV_QUOLITY']); wallCanvasResize(cookieVal['LIV_QUOLITY']); }, 200); } }) // 画面スクロール時のメニュー追従 .scroll(function () { // モバイルなら追従しない(fixed) if ($('#mob-nav:hidden').length > 0) { var offset = menuTop + $(window).scrollTop() + 'px'; $('#menu').animate({top:offset}, {duration:800, easing:'easeInOutQuint', queue:false}); } }); $('body') // 設定ページで設定が変更された場合の再描画 .on('redraw', function(event, newCookieVal){ cookieVal = newCookieVal; getArgValues(); LW.Renderer.Stop(); // ライブ壁紙をフェードアウト $("#bg-canvas").animate({opacity:'0.01'}, 1500, function(){ setWallpaper(); }); }); // ヘッダ $('header') // クリックしたらリロード .click(function(){ location.reload(); }); // ウインドウ最小化 $('#minimize') .on('click', function(){ if ($(this).hasClass('action')) { $('#contents').show(50, function(){ $('#minimize').removeClass('action'); }); } else { $('#contents').hide(50, function(){ $('#minimize').addClass('action'); }); } }); // メインメニュー $('.mnMainClm') // クリックによるサブメニューの展開 .click(function(){ $('.mnMainClm img').fadeIn(); $('ul.mnSubClm').hide(200); if($('+ul.mnSubClm', this).is(':hidden')){ $('img', this).css({display:'none'}); $('+ul.mnSubClm', this).show(150); } }); // モバイル時のメニュー動作 $('#mob-nav') .on('click', function(){ if ($(this).hasClass('action')) { $(this).removeClass('action'); $('#menu').animate({'right':'-160px'}, 50); } else { $(this).addClass('action'); $('#menu').animate({'right':'5px'}, 50); } }); /** * メインフレーム内容リクエスト関数 * @param anchor {object} Ajaxでリクエストを行うリンクのエレメント */ function requestMainFrame(anchor) { // 既に読込処理中はキャンセルする if ($('#cntMainFrame')[0].getAttribute('data-loading') == 1) { return false; } // リクエスト先の取得 var href = $(anchor).attr('href'); // ロード中を設定 $('#cntMainFrame')[0].setAttribute('data-loading', 1); // サブメニューの現在ページを変更 $('#menu .here').removeClass('here'); $(anchor).addClass('here'); // タイトル表示内容変更 $('#title > h1').addClass('action'); var targetUrl = href.split('#'); if (targetUrl.length > 0) { // 表示中のページを更新 $('#cntMainFrame')[0].setAttribute('data-href', href); // スクロールをトップに移動 $('html, body').animate({'scrollTop':'0'}, {queue:false}); // Now Loading表示 $('#loading').addClass('action'); // メニューを先頭に移動 $('#menu').animate({top:menuTop}, 100); // フレームを非表示 $('#cntMainFrame').animate({'opacity':0}, 100, 'easeOutCubic', function(){ // リンクをAjaxリクエスト $('#cntMainFrame').ajaxLoad({ type: 'GET', url: targetUrl[0], timeout: 10000 }); }); } } // サブメニューリンク $('.mnSubClm a[target="mainFrame"]') .click(function(){ // モバイルならメニュー選択時にメニューを隠す $('#mob-nav.action').trigger('click'); // リンクをリクエスト requestMainFrame(this); return false; }); // 設定ページ $('#setting a') .click(function(){ // モバイルならメニュー選択時にメニューを隠す $('#mob-nav.action').trigger('click'); // リンクをリクエスト requestMainFrame(this); return false; }); // コンテンツ読み込み時のフレームサイズ調整およびアニメーション表示 $('#cntMainFrame') // Ajaxで取得したフレーム内コンテンツの置換 .on('ajaxsuccess', function(event){ // フレーム内容読み込み完了後の表示処理を行うためのscript var bootingScript = ''; // フレームの表示内容を入れ替え $(this).html('
' + event.responseData + bootingScript + '
'); }) // フレーム内の描画完了時にtriggerで実行 .on('booting', function(event, title){ var $frame = $(this); // タイトルを変更 document.title = 'にゃんにゃん共和国フィーブル藩国/' + title; // ページ内のリンクにイベントを設定 $frame.find('a[target="mainFrame"]') .click(function(){ requestMainFrame(this); return false; }); // フレーム操作 var bodyHeight = $('#cntMainFrameBody')[0].offsetHeight; var animateDuration = Math.abs(this.offsetHeight - bodyHeight); $frame.animate({'max-height':bodyHeight, 'min-height':bodyHeight}, animateDuration, 'linear', function(){ // Now Loading非表示 $('#loading').removeClass('action'); // フレームのサイズ調整が完了したらページを表示する $frame.animate({opacity:'1'}, 200); // タイトルを表示する var splitTitle = title.split('/'); if ($('#title > h1').text().indexOf('brighten up') > -1) $('#title > h1').removeClass('action').text('FAB, new world.'); else $('#title > h1').removeClass('action').text(splitTitle[0]); // ページ内リンクへの遷移の場合、読み込み完了後に手動でリンクに移動する var targetUrl = this.getAttribute('data-href').split('#'); if (targetUrl.length > 1) { var linkPos = Math.ceil($('#cntMainFrame span#anc-'+targetUrl[1]).offset().top); $('html, body').animate({scrollTop:linkPos}, 200); } // フレームの高さ決定にフレーム内の描画が追い付かないと、フレームサイズが合わなくなるので念のため、スタイルを消す $frame.css({'max-height':'', 'min-height':''}); // ロード中を解除 this.setAttribute('data-loading', 0); }); }); // audiojsを初期化 audiojs.events.ready(function() { var a = audiojs.createAll(); audio = a[0]; }); $('#bgm-wrapper') .bind('click', '.play-pause', function(){ if (!$('#bgm')[0].paused) { $('#bgm-border').addClass('action'); } else { $('#bgm-border').removeClass('action'); } }); // ページ表示アニメーションが完了したら、インデックスページの表示と背景描画を開始する $('#cntMain') .bind('animationend webkitAnimationEnd oAnimationEnd mozAnimationEnd', function(){ $('#title > h1').addClass('action'); $('#loading').addClass('action'); $('#cntMainFrame').ajaxLoad({url: $('#cntMainFrame')[0].getAttribute('data-href')}); setWallpaper(); $(this).unbind('animationend webkitAnimationEnd oAnimationEnd mozAnimationEnd'); }); // 背景用canvasのサイズ調整(ウインドウサイズに合わせる)関数 function wallCanvasResize(quality) { if ($("#bg-canvas").is(':visible')) { $("#bg-canvas").attr({width:$(window).width() / quality}); $("#bg-canvas").attr({height:$(window).height() / quality}); $("#bg-canvas").css({width:$(window).width() + 'px'}); $("#bg-canvas").css({height:$(window).height() + 'px'}); } } function setWallpaper() { if (!supportedWebGL || cookieVal['WALLPAPER_NAME'] == 'Normal') { $('#bg-canvas').css('display', 'none'); var gradation = ''; if (cookieVal['NML_GRADATION']) { gradation = 'linear-gradient(' + cookieVal['NML_GRD_DEG'] + 'deg, ' + nmlClrA + ', ' + nmlClrB + ')'; } if (cookieVal['NML_BACK'] != 'plain') { var bgImg = 'url(\'/common/img/back/' + nmlBack + '\')'; if (cookieVal['NML_GRADATION']) bgImg = gradation + ', ' + bgImg; $('body').css({ 'background-image': bgImg, 'background-color': cookieVal['NML_BGCOLOR'] }); } else { if (cookieVal['NML_GRADATION']) $('body').css('background-image', gradation); $('body').css('background-color', cookieVal['NML_BGCOLOR']); } setBgmSrc('ZephyrToBlow.mp3', '西風が吹く'); } else { $('#bg-canvas').css('display', 'block'); // ライブ壁紙初期化 switch (cookieVal['WALLPAPER_NAME']) { case 'FeebleCastle': LW.Set.FeebleCastle($('#bg-canvas')[0], cookieVal['LIV_QUOLITY'], cookieVal['FBL_ONEDAY'], cookieVal['FBL_CLOUDS'], cookieVal['FBL_STARS']); setBgmSrc('ZephyrToBlow.mp3', '西風が吹く'); break; case 'CyberSpace': LW.Set.CyberSpace($('#bg-canvas')[0], cookieVal['LIV_QUOLITY'], cysBack, cysFog, cysAmbient, cysPoint, cysClrRing, cookieVal['CYS_PARTICLES'], cysClrPt); setBgmSrc('BattleHack.mp3', 'BATTLE HACK'); break; case 'Anohoshi': LW.Set.Anohoshi($('#bg-canvas')[0], cookieVal['LIV_QUOLITY'], cookieVal['ANO_BGCOLOR'], cookieVal['ANO_ANOHOSHI'], cookieVal['ANO_CLIMAX'], anoColor, cookieVal['ANO_KING']); setBgmSrc('ZephyrToBlow.mp3', '西風が吹く'); break; } // ステータス表示 if (cookieVal['LIV_STATS']) LW.Stats.Add(); // canvasを画面に合わせる wallCanvasResize(cookieVal['LIV_QUOLITY']); // レンダリング開始 LW.Renderer.Start(); // 画面を徐々に表示 $("#bg-canvas").delay(1000).animate({opacity:'1'}, 1500); } // BGM再生 if (cookieVal['BGM_AUTO']) { playBgm(true); } } /** * BGMを設定する * @param src {string} 再生するファイルの名前(省略可) */ function setBgmSrc(src, title) { $('audio#bgm').attr('src', '/sound/' + src); $('#bgm-title').text('♪ ' + title).css('opacity', 1.0); } /** * BGMを再生する * @param play {booloan} 再生/停止 */ function playBgm(play) { if ($('.audiojs.playing').length > 0) { $('.audiojs.playing .play-pause').trigger('click'); } if (play) { $('.audiojs .play-pause').trigger('click'); $('#bgm-border').addClass('action'); } } });