Blame view

datalets/datatable-datalet/js/DataTables-master/examples/resources/demo.js 3.12 KB
abeb4a17   Luigi Serra   Update components...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  
  /*global SyntaxHighlighter*/
  SyntaxHighlighter.config.tagName = 'code';
  
  if ( window.$ ) {
  	$(document).ready( function () {
  		if ( ! $.fn.dataTable ) {
  			return;
  		}
  		var dt110 = $.fn.dataTable.Api ? true : false;
  
  		// Work around for WebKit bug 55740
  		var info = $('div.info');
  
  		if ( info.height() < 115 ) {
  			info.css( 'min-height', '8em' );
  		}
  
  		var escapeHtml = function ( str ) {
  			return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  		};
  
  		// css
  		var cssContainer = $('div.tabs div.css');
  		if ( $.trim( cssContainer.find('code').text() ) === '' ) {
  			cssContainer.find('code, p:eq(0), div').css('display', 'none');
  		}
  
  		// init html
  		var table = $('<p/>').append( $('table').clone() ).html();
  		$('div.tabs div.table').append(
  			'<code class="multiline language-html">\t\t\t'+
  				escapeHtml( table )+
  			'</code>'
  		);
  		//SyntaxHighlighter.highlight({}, $('#display-init-html')[0]);
  
  		// Allow the demo code to run if DT 1.9 is used
  		if ( dt110 ) {
  			// json
  			var ajaxTab = $('ul.tabs li').eq(3).css('display', 'none');
  
  			$(document).on( 'init.dt', function ( e, settings ) {
  				if ( e.namespace !== 'dt' ) {
  					return;
  				}
  
  				var api = new $.fn.dataTable.Api( settings );
  
  				var show = function ( str ) {
  					ajaxTab.css( 'display', 'block' );
  					$('div.tabs div.ajax code').remove();
  					$('div.tabs div.ajax div.syntaxhighlighter').remove();
  
  					// Old IE :-|
  					try {
  						str = JSON.stringify( str, null, 2 );
  					} catch ( e ) {}
  
  					$('div.tabs div.ajax').append(
  						'<code class="multiline language-js">'+str+'</code>'
  					);
  
  					// This can be really slow for large builds
  					setTimeout( function () {
  						SyntaxHighlighter.highlight( {}, $('div.tabs div.ajax code')[0] );
  					}, 500 );
  				};
  
  				// First draw
  				var json = api.ajax.json();
  				if ( json ) {
  					show( json );
  				}
  
  				// Subsequent draws
  				api.on( 'xhr.dt', function ( e, settings, json ) {
  					show( json );
  				} );
  			} );
  
  			// php
  			var phpTab = $('ul.tabs li').eq(4).css('display', 'none');
  
  			$(document).on( 'init.dt.demoSSP', function ( e, settings ) {
  				if ( e.namespace !== 'dt' ) {
  					return;
  				}
  
  				if ( settings.oFeatures.bServerSide ) {
  					if ( $.isFunction( settings.ajax ) ) {
  						return;
  					}
  					$.ajax( {
  						url: '../resources/examples.php',
  						data: {
  							src: settings.sAjaxSource || settings.ajax.url || settings.ajax
  						},
  						dataType: 'text',
  						type: 'post',
  						success: function ( txt ) {
  							phpTab.css( 'display', 'block' );
  							$('div.tabs div.php').append(
  								'<code class="multiline language-php">'+txt+'</code>'
  							);
  							SyntaxHighlighter.highlight( {}, $('div.tabs div.php code')[0] );
  						}
  					} );
  				}
  			} );
  		}
  		else {
  			$('ul.tabs li').eq(3).css('display', 'none');
  			$('ul.tabs li').eq(4).css('display', 'none');
  		}
  
  		// Tabs
  		$('ul.tabs').on( 'click', 'li', function () {
  			$('ul.tabs li.active').removeClass('active');
  			$(this).addClass('active');
  
  			$('div.tabs>div')
  				.css('display', 'none')
  				.eq( $(this).index() ).css('display', 'block');
  		} );
  		$('ul.tabs li.active').click();
  	} );
  }