MobifyでGoogleAnalyticsなどを流用する際の方法
konfで残したいスクリプトに、特定のクラスを付与して、
それ以外のスクリプトは取り除くと言う方法で明示しています。
例として、残すスクリプトをモジュールとしてテンプレートに組み込んでいます。
■konfファイル
// <script>タグは全てリムーブして「script」ブロックに格納されている。
// リムーブしたスクリプトを使用する場合は、テンプレートファイルに「{script.script}」と記述する。
// リムーブしないスクリプトは「x-keep」というクラスを付与する。
'script': {
'keep':function() {
$('script').each(function(){
$html = $(this).html();
if($html.match(/s_code|_gaq|_trackPageview|eco-tag|__ect|_fout_queue/)){
$(this).addClass('x-keep');
}
});
$('script[x-src*="s_code.js"]').addClass('x-keep');
return $('.x-keep').remove();
},
'script':function() {
return $('script').not('.x-keep,.x-stay').remove();
}
},
■base.tmpl
{+scripts}
{/scripts}
<div id="x-script">
{script.keep}
</div>
</body>