$(function(){/**================================================================================================================================ * * *  rssloader.js for targa * *  required: jquery.js ( >= 1.2.6 ) *   * *================================================================================================================================**//*@cc_on _d=document;eval('var document=_d')@*/var isIE = /*@cc_on!@*/false;/** * *  グローバル変数 * **/window.__TARGA_RSSLOADER = {  //  topics: {    NUM_PER_PAGE: {      RECENT: 5,      LIST:   10    },    COUNT:  0,    PAGES:  1  },  //  information: {    NUM_PER_PAGE: {      RECENT: 3,      LIST:   10    },    COUNT:  0,    PAGES:  1  },  //  PAGE_CURRENT: 1};var RSSLOADER = window.__TARGA_RSSLOADER;  // グローバル変数の呼び出しを簡略化var _e = function( tagName )    { return document.createElement( tagName ); }  // document.createElement のシノニム  , _a = function( e, target )  { e.appendChild( target ); }                   // Element#appendChild の関数型簡略形  , _t = function( e, tagName ) { return e.getElementsByTagName( tagName ); }  //  , _v = function( e, tagName ) { return ( _t( e, tagName )[0]  &&  _t( e, tagName )[0].childNodes[0] )  ?   _t( e, tagName )[0].childNodes[0].nodeValue  :  undefined; };/** * *  @param   type  'topics', 'infomation' *  @param   target *  @param  ?mode  'recent', 'list' *  @param  ?num *  @param  ?page * **/var load_xml = function( param ) {  var type   = param.type    , target = param.target    , mode   = param.mode  ||  'recent'    , num    = param.num   ||  5    , page   = param.page  ||  1  ;  if( ! type  ||  ! target ) { return false; }  var url_xml = ( mode != 'recent'  ?  '../'  :  '' ) + 'rss/' + type + '.xml';  $.ajax( {    url:      url_xml,    type:     'get',    dataType: 'xml',    data: {    },    success: function( xml ) {      var opts = { target: target, type: type, mode: mode, num: num, page: page };      return list_xml( xml, opts );    },    error: function( xhr ) {      //console.debug( xhr.responseText );      return false;    }  } );};/** * * * *  XMLを整形する * * * **/var list_xml = function( xml, opts ) {  var target = opts.target    , type   = opts.type    , mode   = opts.mode    , num    = opts.num    , page   = opts.page  ;  var itemlist = $( 'item', xml );  // jQueryオブジェクト  var num_total = itemlist.size();  var i_from = ( page - 1 ) * num    , i_to   = page * num < num_total  ?  page * num  :  num_total  ;  if( ! xml ) { return false; }  if( ! RSSLOADER[ type ] ) { return false; }  RSSLOADER[ type ].COUNT = num_total;  RSSLOADER[ type ].PAGES = Math.ceil( RSSLOADER[ type ].COUNT / num );  var itemlist_grep = [];  for( var i = i_from; i < i_to; i++ ) {    var item = itemlist.get( i );    itemlist_grep.push( {      type:        _v( item, 'type' )  ||  '',      date:        _v( item, 'pubDate' ).replace( /-/, '年' ).replace( /-/, '月' ).replace( /$/, '日' ),      title:       _v( item, 'title' ),      link:        _v( item, 'link' ),      linkType:    _v( item, 'linkType' )  ||  'internal',      linkText:    _v( item, 'linkText' ),      description: _v( item, 'description' )    } );  }  target = $( target );  switch( true ) {  case type == 'topics'  &&  mode == 'recent':    list_xml_topics_recent( target, itemlist_grep );    break;  case type == 'topics'  &&  mode == 'list':    list_xml_list( type, target, itemlist_grep );    break;  case type == 'information'  &&  mode == 'recent':    list_xml_information_recent( target, itemlist_grep );    break;  case type == 'information'  &&  mode == 'list':    list_xml_list( type, target, itemlist_grep );    break;  default:    return false;  }  //  //  ページングのボタン  //  if( mode == 'list' ) {    $( '#news_navi #before a' ).css( { visibility: 'visible' } );    $( '#news_navi #after a'  ).css( { visibility: 'visible' } );    if( RSSLOADER.PAGE_CURRENT == 1 ) {      $( '#news_navi #before a' ).css( { visibility: 'hidden' } );    }    if( RSSLOADER.PAGE_CURRENT == RSSLOADER[ type ].PAGES ) {      $( '#news_navi #after a' ).css( { visibility: 'hidden' } );    }  }  return true;};/** * * *  XMLを整形する for Hot Topics @ index.html * * **/var list_xml_topics_recent = function( target, itemlist ) {/*			<tr>				<th abbr="">2008年7月15日</th>				<td>雑誌広告掲載のご案内</td>			</tr> */  target.empty();  for( var i = 0; i < itemlist.length; i++ ) {    (function(){      var item = itemlist[ i ];      var th = $( '<th abbr=""></th>' ).text( item.date )        , td = $( '<td></td>' )        , a  = $( '<a></a>' ).html( item.title )      ;      if( item.type == 'emergency' )    { td.addClass( 'emergency' ); }      if( item.link )                   { a.attr( 'href', item.link ); }      if( item.linkType == 'external' ) { a.attr( 'target', '_blank' ); }      if( item.linkType == 'external' ) { a.attr( 'class', 'external' ); }      if( item.linkType == 'pdf' ) { a.attr( 'target', '_blank' ); }      if( item.linkType == 'pdf' ) { a.attr( 'class', 'pdf' ); }            target.append(        $( '<tr></tr>' )          .append( th )          .append(            td              .append(                a              )          )      );    })();  }};/** * * *  XMLを整形する for information @ index.html * * **/var list_xml_information_recent = function( target, itemlist ) {/* 		<dl>			<dt>2008年7月15日 </dt>			<dd><a href="#">雑誌広告掲載のご案内</a></dd>		</dl> */  target.empty();  for( var i = 0; i < itemlist.length; i++ ) {    (function() {      var item = itemlist[i];      var dl = $( '<dl></dl>' ).append(  $( '<dt></dt>' ).text( item.date )  )        , dd = $( '<dd></dd>' )        , a  = $( '<a></a>' ).text( item.title )      ;      if( item.type == 'emergency' )    { dd.addClass( 'emergency' ); }      if( item.link )                   { a.attr( 'href', item.link ); }      if( item.linkType == 'external' ) { a.attr( 'href', 'info/' ); }      if( item.linkType == 'internal' ) { a.attr( 'href', 'info/' ); }/*20090702坪井追加分*/      if( item.linkType == 'pdf' ) { a.attr( 'href', 'info/' ); }      target.append(        dl          .append(            dd.append( a )          )      );    })();  }};/** * * *  XMLを整形する for topics/index.html and info/index.html * * **/var list_xml_list = function( type, target, itemlist ) {/*<div id="topics_inner"><table summary="News &amp; Topics">	<tr>		<th abbr="日付">2008年10月1日</th>		<td>タイトルが入ります。</td>	</tr></table><p>本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。</p><table summary="News &amp; Topics">	<tr>		<th abbr="日付">2008年10月1日</th>		<td><a href="#" class="open">タイトルが入ります。</a></td>	</tr></table><p>本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。本文が入ります。</p><p class="link_page"><a href="#">詳細ページへのリンク</a></p><table summary="News &amp; Topics">	<tr>		<th abbr="日付">2008年10月1日</th>		<td><a href="#" class="close">タイトルが入ります。</a></td>	</tr></table><table summary="News &amp; Topics">	<tr>		<th abbr="日付">2008年10月1日</th>		<td><a href="#" class="exit">タイトルが入ります。</a></td>	</tr></table></div><div id="news_navi"><!--news_navi-->	<ul>		<li id="before"><a href="#"><img src="../images/btn_back.jpg" alt="" width="55" height="17" title="" class="btn" /></a></li>		<li id="open"><a href="#"><img src="../images/btn_open.jpg" alt="" width="55" height="17" title="" class="btn" /></a></li>		<li id="close"><a href="#"><img src="../images/btn_close.jpg" alt="" width="55" height="17" title="" class="btn" /></a></li>		<li id="after"><a href="#"><img src="../images/btn_next.jpg" alt="" width="55" height="17" title="" class="btn" /></a></li>	</ul><!--news_navi--></div> */  target.empty();  for( var i = 0; i < itemlist.length; i++ ) {    var item = itemlist[i];    (function(){      var table          = $( '<table></table>' ).attr( 'summary', 'News &amp; Topics' )        , tr             = $( '<tr></tr>'   )        , th             = $( '<th></th>'   ).attr( 'abbr', '日付' ).text( item.date )        , td             = $( '<td></td>'   )        , a_title        = $( '<a></a>'     ).addClass( type + '-title open' ).text( item.title ).attr( 'id', type + '-title-' + i )        , div_body       = $( '<div></div>' ).addClass( type + '-description' ).attr( 'id', type + '-description-' + i )        , p_description  = $( '<p></p>'     )        , p_link         = $( '<p></p>'     ).addClass( 'link_page' )        , a_link         = $( '<a></a>'     )      ;      if( item.type == 'emergency' ) { td.addClass( 'emergency' ); }      /**       *        *       *  タイトルに関する設定       *         *       **/      //      //  ・リンクが設定されていない      //  ・本文が設定されている，かつ，リンクが設定されている，かつ，リンクテキストが設定されている，かつ      //      //    => タイトルをクリックで本文部分を開閉する      //      if( ! item.link   ||   ( item.description  &&  item.link) ) {        a_title.toggle( function() {          var __this = $( this );          var index = this.id.split( '-' )[2];          div_body.slideUp( function() {            __this.removeClass( 'open' ).addClass( 'close' );          } );        }, function() {          var __this = $( this );          div_body.slideDown( function() {            __this.removeClass( 'close' ).addClass( 'open' );          } );        } );      }      //      //  ・リンクが設定されている      //      //    => タイトルをクリックでリンク先へ移動する      //      else if( item.link ) {        if( item.linkType == 'internal' ) {          td.addClass( 'link_page' );        }        else if( item.linkType == 'external' ) {          a_title            .addClass( 'exit' )            .attr( 'target', '_blank' )          ;        }        a_title          .attr( 'href', item.link )          .removeClass( 'open' ).removeClass( 'close' )          .addClass( 'link' )        ;      }      target.append(        table.append(          tr.append( th )            .append( td.append( a_title ) )        )      );            /**       *       *       *  本文に関する設定       *         *       **/      //      //  本文が存在する      //            if( item.description ) {        div_body.append(          p_description.html( item.description )        );        //        //  リンクが存在する，かつ，リンクテキストが設定されている        //        if( item.link  &&  item.linkText ) {          if( item.linkType == 'external' ) {            a_link.addClass( 'exit' ).attr( 'target', '_blank' );			a_link.addClass( 'exit' ).attr( 'class', 'external' );          }          else if( item.linkType == 'pdf' ) {            a_link.addClass( 'exit' ).attr( 'target', '_blank' );			a_link.addClass( 'exit' ).attr( 'class', 'pdf' );          }          div_body.append(            p_link.append(              a_link                .attr( 'href', item.link )                .html( item.linkText  ||  item.link  )            )          );        }      }      target.append( div_body );    })();  }};/** * * *  メイン処理 * * **///////if( $( '.rssloader-recent' ).size() ) {  $( '.rssloader-recent' ).each( function() {    var id = $( this ).attr( 'id' );    switch( id ) {    case 'topics':      load_xml( {        type:   'topics',        num:    RSSLOADER.topics.NUM_PER_PAGE.RECENT,        target: '#topics table',        mode:   'recent'      } );      break;    case 'information':      load_xml( {        type:   'information',        num:    RSSLOADER.information.NUM_PER_PAGE.RECENT,        target: '#information #information_inner',        mode:   'recent'      } );      break;    }  } );}//////else {    $( '#topics_inner, #information_inner' ).each( function() {    var id = $( this ).attr( 'id' );      switch( true ) {    case id.match( 'topics' ) != null:      load_xml( {        type:   'topics',        num:    RSSLOADER.topics.NUM_PER_PAGE.LIST,        target: '#' + id,        mode:   'list'      } );      break;    case id.match( 'information' ) != null:      load_xml( {        type:   'information',        num:    RSSLOADER.information.NUM_PER_PAGE.LIST,        target: '#' + id,        mode:   'list'      } );      break;    default:      break;        }    } );  //  //  //  if( $( '#news_navi' ).get( 0 ) ) {  /*  <div id="news_navi"><!--news_navi-->  	<ul>  		<li id="before"><a href="#"><img src="../images/btn_back.jpg" alt="" width="55" height="17" title="" class="btn" /></a></li>  		<li id="open"><a href="#"><img src="../images/btn_open.jpg" alt="" width="55" height="17" title="" class="btn" /></a></li>  		<li id="close"><a href="#"><img src="../images/btn_close.jpg" alt="" width="55" height="17" title="" class="btn" /></a></li>  		<li id="after"><a href="#"><img src="../images/btn_next.jpg" alt="" width="55" height="17" title="" class="btn" /></a></li>  	</ul>  <!--news_navi--></div>  */    var type = location.href.match( /(topics|info)/ )[0];    if( type == 'info' ) { type = 'information'; }      $( '#navi_btn_area' )      //      //  すべて開く      //      .find( '#open a' )        .click( function() {          $( '.' + type + '-description' ).each( function() {            var __this = $( this );            var index = this.id.split( '-' )[2];            var a_title = $( '#' + type + '-title-' + index );            if( a_title.hasClass( 'close' ) ) {              __this.slideDown( function() {                a_title.click();              } );            }            else if( a_title.hasClass( 'link' ) ) {              __this.slideDown();            }          } );        } )        .end()      //      //  すべて閉じる      //      .find( '#close a' )        .click( function() {          $( '.' + type + '-description' ).each( function() {            var __this = $( this );            var index = this.id.split( '-' )[2];            var a_title = $( '#' + type + '-title-' + index );            if( a_title.hasClass( 'open' ) ) {              __this.slideUp( function() {                a_title.click();              } );            }            else if( a_title.hasClass( 'link' ) ) {              __this.slideUp();            }          } );        } )        .end()	;	 $( '#news_navi' )      //      //  前のページ      //      .find( '#before a' )        .css( { visibility: 'hidden' } )        .click( function() {          var __this = $( this );            if( RSSLOADER.PAGE_CURRENT > 1 ) {            --RSSLOADER.PAGE_CURRENT;          }          else {            RSSLOADER.PAGE_CURRENT;          }                load_xml( {            type:   type,            target: '#' +  type + '_inner',            num:    RSSLOADER[ type ].NUM_PER_PAGE.LIST,            page:   RSSLOADER.PAGE_CURRENT,            mode:   'list'          } );        } )        .end()      //      //  次のページ      //      .find( '#after a' )        .click( function() {          var __this = $( this );            if( RSSLOADER.PAGE_CURRENT >= RSSLOADER[ type ].PAGES ) {            RSSLOADER.PAGE_CURRENT = RSSLOADER[ type ].PAGES;          }          else {            ++RSSLOADER.PAGE_CURRENT;          }            load_xml( {            type:   type,            target: '#' + type + '_inner',            num:    RSSLOADER[ type ].NUM_PER_PAGE.LIST,            page:   RSSLOADER.PAGE_CURRENT,            mode:   'list'          } );          } )        .end()        ;  }}  /**================================================================================================================================**/});