PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/public/DataTables/media/js/dataTables.semanticui.js

https://gitlab.com/dae.nuli/resep
JavaScript | 208 lines | 148 code | 32 blank | 28 comment | 21 complexity | 7b820b3018992ea026630ab66877a892 MD5 | raw file
  1. /*! DataTables Bootstrap 3 integration
  2. * ©2011-2015 SpryMedia Ltd - datatables.net/license
  3. */
  4. /**
  5. * DataTables integration for Bootstrap 3. This requires Bootstrap 3 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 Bootstrap. See http://datatables.net/manual/styling/bootstrap
  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, which attaches to jQuery, including
  27. // jQuery if needed and have a $ property so we can access the
  28. // jQuery object that is used
  29. $ = require('datatables.net')(root, $).$;
  30. }
  31. return factory( $, root, root.document );
  32. };
  33. }
  34. else {
  35. // Browser
  36. factory( jQuery, window, document );
  37. }
  38. }(function( $, window, document, undefined ) {
  39. 'use strict';
  40. var DataTable = $.fn.dataTable;
  41. /* Set the defaults for DataTables initialisation */
  42. $.extend( true, DataTable.defaults, {
  43. dom:
  44. "<'ui grid'"+
  45. "<'row'"+
  46. "<'eight wide column'l>"+
  47. "<'right aligned eight wide column'f>"+
  48. ">"+
  49. "<'row dt-table'"+
  50. "<'sixteen wide column'tr>"+
  51. ">"+
  52. "<'row'"+
  53. "<'seven wide column'i>"+
  54. "<'right aligned nine wide column'p>"+
  55. ">"+
  56. ">",
  57. renderer: 'semanticUI'
  58. } );
  59. /* Default class modification */
  60. $.extend( DataTable.ext.classes, {
  61. sWrapper: "dataTables_wrapper dt-semanticUI",
  62. sFilter: "dataTables_filter ui input",
  63. sProcessing: "dataTables_processing ui segment",
  64. sPageButton: "paginate_button item"
  65. } );
  66. /* Bootstrap paging button renderer */
  67. DataTable.ext.renderer.pageButton.semanticUI = function ( settings, host, idx, buttons, page, pages ) {
  68. var api = new DataTable.Api( settings );
  69. var classes = settings.oClasses;
  70. var lang = settings.oLanguage.oPaginate;
  71. var aria = settings.oLanguage.oAria.paginate || {};
  72. var btnDisplay, btnClass, counter=0;
  73. var attach = function( container, buttons ) {
  74. var i, ien, node, button;
  75. var clickHandler = function ( e ) {
  76. e.preventDefault();
  77. if ( !$(e.currentTarget).hasClass('disabled') && api.page() != e.data.action ) {
  78. api.page( e.data.action ).draw( 'page' );
  79. }
  80. };
  81. for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
  82. button = buttons[i];
  83. if ( $.isArray( button ) ) {
  84. attach( container, button );
  85. }
  86. else {
  87. btnDisplay = '';
  88. btnClass = '';
  89. switch ( button ) {
  90. case 'ellipsis':
  91. btnDisplay = '&#x2026;';
  92. btnClass = 'disabled';
  93. break;
  94. case 'first':
  95. btnDisplay = lang.sFirst;
  96. btnClass = button + (page > 0 ?
  97. '' : ' disabled');
  98. break;
  99. case 'previous':
  100. btnDisplay = lang.sPrevious;
  101. btnClass = button + (page > 0 ?
  102. '' : ' disabled');
  103. break;
  104. case 'next':
  105. btnDisplay = lang.sNext;
  106. btnClass = button + (page < pages-1 ?
  107. '' : ' disabled');
  108. break;
  109. case 'last':
  110. btnDisplay = lang.sLast;
  111. btnClass = button + (page < pages-1 ?
  112. '' : ' disabled');
  113. break;
  114. default:
  115. btnDisplay = button + 1;
  116. btnClass = page === button ?
  117. 'active' : '';
  118. break;
  119. }
  120. var tag = btnClass.indexOf( 'disabled' ) === -1 ?
  121. 'a' :
  122. 'div';
  123. if ( btnDisplay ) {
  124. node = $('<'+tag+'>', {
  125. 'class': classes.sPageButton+' '+btnClass,
  126. 'id': idx === 0 && typeof button === 'string' ?
  127. settings.sTableId +'_'+ button :
  128. null,
  129. 'href': '#',
  130. 'aria-controls': settings.sTableId,
  131. 'aria-label': aria[ button ],
  132. 'data-dt-idx': counter,
  133. 'tabindex': settings.iTabIndex
  134. } )
  135. .html( btnDisplay )
  136. .appendTo( container );
  137. settings.oApi._fnBindAction(
  138. node, {action: button}, clickHandler
  139. );
  140. counter++;
  141. }
  142. }
  143. }
  144. };
  145. // IE9 throws an 'unknown error' if document.activeElement is used
  146. // inside an iframe or frame.
  147. var activeEl;
  148. try {
  149. // Because this approach is destroying and recreating the paging
  150. // elements, focus is lost on the select button which is bad for
  151. // accessibility. So we want to restore focus once the draw has
  152. // completed
  153. activeEl = $(host).find(document.activeElement).data('dt-idx');
  154. }
  155. catch (e) {}
  156. attach(
  157. $(host).empty().html('<div class="ui pagination menu"/>').children(),
  158. buttons
  159. );
  160. if ( activeEl ) {
  161. $(host).find( '[data-dt-idx='+activeEl+']' ).focus();
  162. }
  163. };
  164. // Javascript enhancements on table initialisation
  165. $(document).on( 'init.dt', function (e, ctx) {
  166. if ( e.namespace !== 'dt' ) {
  167. return;
  168. }
  169. // Length menu drop down
  170. if ( $.fn.dropdown ) {
  171. var api = new $.fn.dataTable.Api( ctx );
  172. $( 'div.dataTables_length select', api.table().container() ).dropdown();
  173. }
  174. } );
  175. return DataTable;
  176. }));