61712a1ea95b3da6d29fbaad681975653d9c7fcb
[Packages/TYPO3.CMS.git] / typo3 / sysext / documentation / Resources / Public / JavaScript / main.js
1 TYPO3.DocumentationApplication = {
2 datatable: null,
3 // Utility method to retrieve query parameters
4 getUrlVars: function getUrlVars() {
5 var vars = [], hash;
6 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
7 for(var i = 0; i < hashes.length; i++) {
8 hash = hashes[i].split('=');
9 vars.push(hash[0]);
10 vars[hash[0]] = hash[1];
11 }
12 return vars;
13 },
14 // Initializes the data table, depending on the current view
15 initializeView: function() {
16 var getVars = this.getUrlVars();
17 // getVars[1] contains the name of the action key
18 // List view is the default view
19 if (getVars[getVars[1]] == 'download') {
20 this.documentationDownloadView(getVars);
21 } else {
22 this.documentationListView(getVars);
23 }
24 },
25 // Initializes the list view
26 documentationListView: function(getVars) {
27 this.datatable = jQuery('#typo3-documentation-list').DataTable({
28 'paging': false,
29 'jQueryUI': true,
30 'lengthChange': false,
31 'pageLength': 15,
32 'stateSave': true
33 });
34
35 // restore filter
36 if (this.datatable.length && getVars['search']) {
37 this.datatable.search(getVars['search']);
38 }
39 },
40 // Initializes the download view
41 documentationDownloadView: function(getVars) {
42 this.datatable = jQuery('#typo3-documentation-download').DataTable({
43 'paging': false,
44 'jQueryUI': true,
45 'lengthChange': false,
46 'pageLength': 15,
47 'stateSave': true,
48 'order': [[ 1, 'asc' ]]
49 });
50
51 // restore filter
52 if (this.datatable.length && getVars['search']) {
53 this.datatable.search(getVars['search']);
54 }
55 }
56 };
57
58 // IIFE for faster access to $ and save $ use
59 (function ($) {
60
61 $(document).ready(function() {
62 // Initialize the view
63 TYPO3.DocumentationApplication.initializeView();
64
65 // Make the data table filter react to the clearing of the filter field
66 $('.dataTables_wrapper .dataTables_filter input').clearable({
67 onClear: function() {
68 TYPO3.DocumentationApplication.datatable.search('');
69 }
70 });
71 });
72 }(jQuery));