var articles = null;
var currentarticle = null;
var jsswitcharticles = true;
var directlinks = false;
function getArticles( articleid, firstarticledefault ) {
if( articles === null ) {
jQuery.get( '/includes/modules/m_viewcategoryarticles/tmpl/getArticleListing.php', {
}, function( result ) {
var jsonstring = JSON.parse(result);
var html = "";
if( jsonstring.message == 'success' ) {
articles = jsonstring.articles;
if( articleid ) {
for( a=0; a < articles.length ; a++ ) {
if( articles[a].id == articleid ) {
history.replaceState({"index":a}, null);
getArticle(a, false);
return;
}
}
} else if( firstarticledefault ) {
history.replaceState({"index":0}, null);
getArticle(0, false);
return;
}
listArticles( );
} else { listArticles( ); }
} );
} else {
listArticles( );
}
}
function listArticles( ) {
var html = "";
if( !articles ) { return; }
if( articles.length > 0 ) {
for( a=0; a < articles.length ; a++ ) {
html += '
';
html += articles[a].link;
html += "";
}
}
jQuery( '#articlelistingholder' ).html( html ).show( );
jQuery( '#articlelistingholder a' ).css( { 'color' : jQuery( '#pathview' ).css( 'background-color' ) } ); if( directlinks == false ) {
jQuery( "#articlelistingholder a" ).on("click", function(e){e.preventDefault();});
}
jQuery( '#articleholder' ).hide( );
}
function getArticle( index, myPushState ) {
jQuery.post( '/includes/modules/m_viewcategoryarticles/tmpl/getArticle.php', {
aid : articles[index].id
}, function( result ) {
var jsonstring = JSON.parse(result);
checkRead( jsonstring.article.url );
//console.log(jsonstring);
var html = "";
if(history.pushState){
if( myPushState ) {
history.pushState( { "index" : index }, null, jsonstring.article.url );
}
}
if( jsonstring.message == 'success' ) {
html = jsonstring.article.content;
currentarticle = jsonstring.article;
} else {
currentarticle = null;
}
jQuery( '#relatedmaterials' ).html( "" );
if( jsonstring.article.relatedmaterials.length ) {
jQuery( '#relatedmaterials' ).html( jsonstring.article.relatedmaterials );
jQuery( '.topboxtext' ).css( { 'background-color' : jQuery( '#pathview' ).css( "background-color" ) } );
jQuery( '.relatedmaterial.borderbottom' ).css( { 'border-color' : jQuery( '#pathview' ).css( "background-color" ) } );
jQuery( '.relatedmaterial a' ).css( { 'color' : jQuery( '#pathview' ).css( 'background-color' ) } );
}
jQuery( '#articlelistingholder, #article' ).html( "" ).hide( );
jQuery( '#articleholder' ).html( html ).show( );
prepareGroup( );
jQuery( '#articleholder a' ).css( { 'color' : jQuery( '#pathview' ).css( 'background-color' ) } ); jQuery( '.ui-widget-header' ).css( { 'background-color' : jQuery( '#pathview' ).css( "background-color" ) } );
jQuery( 'html, body' ).animate( { scrollTop: 0 }, "slow" );
if( jQuery( '.rsbtn_play' ).length > 0 ) {
//id = jQuery( '.rsbtn_play' ).parent( ).attr( 'id' ).substring( 18 );
//jQuery( '#articleholder' ).attr( 'id', 'rs_read_this' + id );
addRSFunctionality();
}
showButtons( index );
} );
}
function showButtons( index ) {
var html = ''
jQuery.get( '/includes/modules/m_viewcategoryarticles/tmpl/getButtons.php', {
showleft : ( index > 0 ? articles[index-1].jslink : '' ),
showright : ( articles.length > ( index + 1 ) ? articles[index+1].jslink : '' ),
aid : articles[index].id
}, function( result ) {
var jsonstring = JSON.parse(result);
jQuery( '#articlebuttonholder' ).remove( );
jQuery( '#articleholder' ).after( '' + jsonstring.html + '
' );
} );
}
jQuery(document).ready(function(){
getArticles(0, 0);
});
if( history.pushState ) {
jQuery( window ).on( "popstate", function( e ) {
if( history.state && history.state.index !== undefined ) {
getArticle( history.state.index, history.state );
e.preventDefault( );
}
} );
}