Skip to content

Commit

Permalink
Refactor content load code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheep-y committed Dec 25, 2016
1 parent fc6bba0 commit 532a6fb
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions html/action_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ <h1 id="act_view_h_title"></h1>
'parse_action_id' : function act_view_parse_action_id () {
var id = od.gui.act_id, action = od.action.view;
var idList = id.substr( 'view='.length ).split( ',' );
var loadCount = idList.length;
action.clear();
idList.forEach( function act_view_show_each ( id ) {
// Parse id
Expand All @@ -79,12 +80,8 @@ <h1 id="act_view_h_title"></h1>
_( '#act_view_pnl_content')[0].appendChild( div );
// Load and fill div
cat.load_data( id, function act_view_show_load () {
var content = '<div class="detail" id="' + id + '">' + cat.data[ id ] + '</div>';
div.innerHTML = od.gui.highlight( content );
if ( idList.length === 1 ) {
var h1 = content.match( /<h1[^>]*>(.+?)<\/h1\s*>/ );
action.set_title( h1[1].replace( /<(\w+)[^>]*>.*<\/\1>|<br\/?>| \[Attack Technique\]/g, '' ) );
}
if ( --loadCount === 0 )
action.show_entries( div, cat, idList );
} );
} );

Expand Down Expand Up @@ -149,6 +146,16 @@ <h1 id="act_view_h_title"></h1>
od.gui.update_title( title );
},

"show_entries" : function act_view_show_entries ( div, cat, idList ) {
var action = od.action.view;
var content = idList.map( function act_view_show_entries_each( id ) {
return '<div class="detail" id="' + id + '">' + cat.data[ id ] + '</div>';
} ).join( '' );
div.innerHTML = od.gui.highlight( content );
var h1 = content.match( /<h1[^>]*>(.+?)<\/h1\s*>/ );
action.set_title( h1[1].replace( /<(\w+)[^>]*>.*<\/\1>|<br\/?>| \[Attack Technique\]/g, '' ) );
},

"update_nav_button" : function act_view_update_nav_button () {
var action = od.action.view;
_.hide( '#act_view_btn_prev, #act_view_btn_next' );
Expand Down

0 comments on commit 532a6fb

Please sign in to comment.