/*global SyntaxHighlighter,editor*/ if ( window.$ ) { $(document).ready( function () { // // Modify the tabs from the DataTables default examples to show the // extras information we want for Editor // // Ajax load data - rename and move to the end $('ul.tabs li').eq(3).html('Ajax load').appendTo( 'ul.tabs' ); $('div.tabs > div').eq(3).appendTo( 'div.tabs' ); // Ajax data interchange between Editor and the server $('ul.tabs').append( '
Editor submits and retrieves information by Ajax requests. The two blocks below show the data that Editor submits and receives, to and from the server. This is updated live as you interact with Editor so you can see what is submitted.
'+ 'The following shows the data that has been submitted to the server when a request is made to add, edit or delete data from the table.
'+ '// No data yet submitted
'+
'The following shows the data that has been returned by the server in response to the data submitted on the left and is then acted upon.
'+ '// No data yet received
'+
'
').text( decodeURI(
jQuery.param( data ).replace(/&/g, '\n').replace(/\+/g, ' ')
) )
);
SyntaxHighlighter.highlight( {}, $('div.ajax-data-send code')[0] );
} );
editor.on('postSubmit', function (e, json, data) {
$('div.ajax-data-receive div.syntaxhighlighter').remove();
$('div.ajax-data-receive').append(
$('
').text( JSON.stringify( json, null, 2 ) )
);
SyntaxHighlighter.highlight( {}, $('div.ajax-data-receive code')[0] );
} );
// Server-side script - replace the DataTables script display with
// one customised for Editor. This is actually tab index 4 from the
// DT tabs, but due to the reorder above it gets moved down one
var server = $('div.tabs > div').eq(3);
var table = $('#example').DataTable();
var url = table.ajax.url();
if ( url && url.indexOf('php') !== -1 ) {
$('ul.tabs li').eq(3).html('Server script').css('display', 'block');
server.find('p').eq(0).html( 'The following script is used by DataTables and Editor to process the data requests sent by the client on the server-side.' );
$.ajax( {
url: '../resources/examples.php',
data: {
src: table.ajax.url()
},
dataType: 'text',
type: 'post',
success: function ( txt ) {
$('div.tabs > div.php').append(
$('
').text(txt)
);
SyntaxHighlighter.highlight( {}, $('div.tabs div.php code')[0] );
}
} );
}
} );
} );
}