dataTables.jqueryui.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*! DataTables jQuery UI integration
  2. * ©2011-2014 SpryMedia Ltd - datatables.net/license
  3. */
  4. /**
  5. * DataTables integration for jQuery UI. This requires jQuery UI and
  6. * DataTables 1.10 or newer.
  7. *
  8. * This file sets the defaults and adds options to DataTables to style its
  9. * controls using jQuery UI. See http://datatables.net/manual/styling/jqueryui
  10. * for further information.
  11. */
  12. (function( factory ){
  13. if ( typeof define === 'function' && define.amd ) {
  14. // AMD
  15. define( ['jquery', 'datatables.net'], function ( $ ) {
  16. return factory( $, window, document );
  17. } );
  18. }
  19. else if ( typeof exports === 'object' ) {
  20. // CommonJS
  21. module.exports = function (root, $) {
  22. if ( ! root ) {
  23. root = window;
  24. }
  25. if ( ! $ || ! $.fn.dataTable ) {
  26. $ = require('datatables.net')(root, $).$;
  27. }
  28. return factory( $, root, root.document );
  29. };
  30. }
  31. else {
  32. // Browser
  33. factory( jQuery, window, document );
  34. }
  35. }(function( $, window, document, undefined ) {
  36. 'use strict';
  37. var DataTable = $.fn.dataTable;
  38. var sort_prefix = 'css_right ui-icon ui-icon-';
  39. var toolbar_prefix = 'fg-toolbar ui-toolbar ui-widget-header ui-helper-clearfix ui-corner-';
  40. /* Set the defaults for DataTables initialisation */
  41. $.extend( true, DataTable.defaults, {
  42. dom:
  43. '<"'+toolbar_prefix+'tl ui-corner-tr"lfr>'+
  44. 't'+
  45. '<"'+toolbar_prefix+'bl ui-corner-br"ip>',
  46. renderer: 'jqueryui'
  47. } );
  48. $.extend( DataTable.ext.classes, {
  49. "sWrapper": "dataTables_wrapper dt-jqueryui",
  50. /* Full numbers paging buttons */
  51. "sPageButton": "fg-button ui-button ui-state-default",
  52. "sPageButtonActive": "ui-state-disabled",
  53. "sPageButtonDisabled": "ui-state-disabled",
  54. /* Features */
  55. "sPaging": "dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi "+
  56. "ui-buttonset-multi paging_", /* Note that the type is postfixed */
  57. /* Sorting */
  58. "sSortAsc": "ui-state-default sorting_asc",
  59. "sSortDesc": "ui-state-default sorting_desc",
  60. "sSortable": "ui-state-default sorting",
  61. "sSortableAsc": "ui-state-default sorting_asc_disabled",
  62. "sSortableDesc": "ui-state-default sorting_desc_disabled",
  63. "sSortableNone": "ui-state-default sorting_disabled",
  64. "sSortIcon": "DataTables_sort_icon",
  65. /* Scrolling */
  66. "sScrollHead": "dataTables_scrollHead "+"ui-state-default",
  67. "sScrollFoot": "dataTables_scrollFoot "+"ui-state-default",
  68. /* Misc */
  69. "sHeaderTH": "ui-state-default",
  70. "sFooterTH": "ui-state-default"
  71. } );
  72. DataTable.ext.renderer.header.jqueryui = function ( settings, cell, column, classes ) {
  73. // Calculate what the unsorted class should be
  74. var noSortAppliedClass = sort_prefix+'carat-2-n-s';
  75. var asc = $.inArray('asc', column.asSorting) !== -1;
  76. var desc = $.inArray('desc', column.asSorting) !== -1;
  77. if ( !column.bSortable || (!asc && !desc) ) {
  78. noSortAppliedClass = '';
  79. }
  80. else if ( asc && !desc ) {
  81. noSortAppliedClass = sort_prefix+'carat-1-n';
  82. }
  83. else if ( !asc && desc ) {
  84. noSortAppliedClass = sort_prefix+'carat-1-s';
  85. }
  86. // Setup the DOM structure
  87. $('<div/>')
  88. .addClass( 'DataTables_sort_wrapper' )
  89. .append( cell.contents() )
  90. .append( $('<span/>')
  91. .addClass( classes.sSortIcon+' '+noSortAppliedClass )
  92. )
  93. .appendTo( cell );
  94. // Attach a sort listener to update on sort
  95. $(settings.nTable).on( 'order.dt', function ( e, ctx, sorting, columns ) {
  96. if ( settings !== ctx ) {
  97. return;
  98. }
  99. var colIdx = column.idx;
  100. cell
  101. .removeClass( classes.sSortAsc +" "+classes.sSortDesc )
  102. .addClass( columns[ colIdx ] == 'asc' ?
  103. classes.sSortAsc : columns[ colIdx ] == 'desc' ?
  104. classes.sSortDesc :
  105. column.sSortingClass
  106. );
  107. cell
  108. .find( 'span.'+classes.sSortIcon )
  109. .removeClass(
  110. sort_prefix+'triangle-1-n' +" "+
  111. sort_prefix+'triangle-1-s' +" "+
  112. sort_prefix+'carat-2-n-s' +" "+
  113. sort_prefix+'carat-1-n' +" "+
  114. sort_prefix+'carat-1-s'
  115. )
  116. .addClass( columns[ colIdx ] == 'asc' ?
  117. sort_prefix+'triangle-1-n' : columns[ colIdx ] == 'desc' ?
  118. sort_prefix+'triangle-1-s' :
  119. noSortAppliedClass
  120. );
  121. } );
  122. };
  123. /*
  124. * TableTools jQuery UI compatibility
  125. * Required TableTools 2.1+
  126. */
  127. if ( DataTable.TableTools ) {
  128. $.extend( true, DataTable.TableTools.classes, {
  129. "container": "DTTT_container ui-buttonset ui-buttonset-multi",
  130. "buttons": {
  131. "normal": "DTTT_button ui-button ui-state-default"
  132. },
  133. "collection": {
  134. "container": "DTTT_collection ui-buttonset ui-buttonset-multi"
  135. }
  136. } );
  137. }
  138. return DataTable;
  139. }));