cf00409596645a3d2f21e7ae2180cfc93893eb99
[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 'bPaginate': false,
29 'bJQueryUI': true,
30 'bLengthChange': false,
31 'iDisplayLength': 15,
32 'bStateSave': true,
33 "fnCookieCallback": function (sNameFile, oData, sExpires, sPath) {
34 // append mod.php to cookiePath to avoid sending cookie-data to images etc. without reason
35 return sNameFile + "=" + encodeURIComponent($.fn.dataTableExt.oApi._fnJsonString(oData)) + "; expires=" + sExpires +"; path=" + sPath + "mod.php";
36 }
37 });
38
39 // restore filter
40 if (this.datatable.length && getVars['search']) {
41 this.datatable.fnFilter(getVars['search']);
42 }
43 },
44 // Initializes the download view
45 documentationDownloadView: function(getVars) {
46 this.datatable = jQuery('#typo3-documentation-download').dataTable({
47 'bPaginate': false,
48 'bJQueryUI': true,
49 'bLengthChange': false,
50 'iDisplayLength': 15,
51 'bStateSave': true,
52 'aaSorting': [[ 1, 'asc' ]],
53 "fnCookieCallback": function (sNameFile, oData, sExpires, sPath) {
54 // append mod.php to cookiePath to avoid sending cookie-data to images etc. without reason
55 return sNameFile + "=" + encodeURIComponent($.fn.dataTableExt.oApi._fnJsonString(oData)) + "; expires=" + sExpires +"; path=" + sPath + "mod.php";
56 }
57 });
58
59 // restore filter
60 if (this.datatable.length && getVars['search']) {
61 this.datatable.fnFilter(getVars['search']);
62 }
63 }
64 };
65
66 // IIFE for faster access to $ and save $ use
67 (function ($) {
68
69 $(document).ready(function() {
70 // Initialize the view
71 TYPO3.DocumentationApplication.initializeView();
72
73 // Make the data table filter react to the clearing of the filter field
74 $('.dataTables_wrapper .dataTables_filter input').clearable({
75 onClear: function() {
76 TYPO3.DocumentationApplication.datatable.fnFilter('');
77 }
78 });
79 });
80 }(jQuery));