diff --git a/features/lengthChange.js b/features/lengthChange.js deleted file mode 100644 index 4f06a72..0000000 --- a/features/lengthChange.js +++ /dev/null @@ -1,84 +0,0 @@ -(function(window, document, $, undefined) { - - -$.fn.dataTableExt.oApi.fnLengthChange = function ( oSettings, iDisplay ) { - oSettings._iDisplayLength = iDisplay; - oSettings.oApi._fnCalculateEnd( oSettings ); - - /* If we have space to show extra rows (backing up from the end point - then do so */ - if ( oSettings._iDisplayEnd == oSettings.aiDisplay.length ) { - oSettings._iDisplayStart = oSettings._iDisplayEnd - oSettings._iDisplayLength; - if ( oSettings._iDisplayStart < 0 ) { - oSettings._iDisplayStart = 0; - } - } - - if ( oSettings._iDisplayLength == -1 ) { - oSettings._iDisplayStart = 0; - } - - oSettings.oApi._fnDraw( oSettings ); -}; - - -$.fn.dataTable.LengthLinks = function ( oSettings ) { - var container = $('
').addClass( oSettings.oClasses.sLength ); - var lastLength = -1; - var draw = function () { - // No point in updating - nothing has changed - if ( oSettings._iDisplayLength === lastLength ) { - return; - } - - var menu = oSettings.aLengthMenu; - var lang = menu.length===2 && $.isArray(menu[0]) ? menu[1] : menu; - var lens = menu.length===2 && $.isArray(menu[0]) ? menu[0] : menu; - - var out = $.map( lens, function (el, i) { - return el == oSettings._iDisplayLength ? - ''+lang[i]+'' : - ''+lang[i]+''; - } ); - - container.html( oSettings.oLanguage.sLengthMenu.replace( '_MENU_', out.join(' ') ) ); - lastLength = oSettings._iDisplayLength; - }; - - // API, so the feature wrapper can return the node to insert - this.container = container; - - // Update on each draw - oSettings.aoDrawCallback.push( { - "fn": function () { - draw(); - }, - "sName": "PagingControl" - } ); - - // Listen for events to change the page length - container.on( 'click', 'a', function (e) { - e.preventDefault(); - oSettings.oInstance.fnLengthChange( parseInt( $(this).attr('data-length'), 10 ) ); - } ); -} - -// Subscribe the feature plug-in to DataTables, ready for use -$.fn.dataTableExt.aoFeatures.push( { - "fnInit": function( oSettings ) { - var l = new $.fn.dataTable.LengthLinks( oSettings ); - return l.container[0]; - }, - "cFeature": "L", - "sFeature": "LengthLinks" -} ); - - -})(window, document, jQuery); - - -// DataTables initialisation -$(document).ready(function() { - $('#example').dataTable( { - "sDom": "Lfrtip" - } ); -} ); \ No newline at end of file diff --git a/features/lengthLinks/dataTables.lengthLinks.css b/features/lengthLinks/dataTables.lengthLinks.css new file mode 100644 index 0000000..c78d21d --- /dev/null +++ b/features/lengthLinks/dataTables.lengthLinks.css @@ -0,0 +1,4 @@ + +div.dataTables_length a.active { + color: black; +} \ No newline at end of file diff --git a/features/lengthLinks/dataTables.lengthLinks.js b/features/lengthLinks/dataTables.lengthLinks.js new file mode 100644 index 0000000..af80e45 --- /dev/null +++ b/features/lengthLinks/dataTables.lengthLinks.js @@ -0,0 +1,89 @@ +/*! Page length control via links for DataTables + * 2014 SpryMedia Ltd - datatables.net/license + */ + +/** + * @summary LengthLinks + * @description Page length control via links for DataTables + * @version 1.1.0 + * @file dataTables.searchHighlight.js + * @author SpryMedia Ltd (www.sprymedia.co.uk) + * @contact www.sprymedia.co.uk/contact + * @copyright Copyright 2014 SpryMedia Ltd. + * @license MIT - http://datatables.net/license/mit + * + * This feature plug-in for DataTables adds page length control links to the + * DataTable. The `dom` option can be used to insert the control using the `L` + * character option and it uses the `lengthMenu` options of DataTables to + * determine what to display. + * + * @example + * $('#myTable').DataTable( { + * dom: 'Lfrtip' + * } ); + * + * @example + * $('#myTable').DataTable( { + * lengthMenu: [ [10, 25, 50, -1], [10, 25, 50, "All"] ] + * dom: 'Lfrtip' + * } ); + */ + +(function(window, document, $, undefined) { + + +$.fn.dataTable.LengthLinks = function ( inst ) { + var api = new $.fn.dataTable.Api( inst ); + var settings = api.settings()[0]; + var container = $('').addClass( settings.oClasses.sLength ); + var lastLength = -1; + + // API so the feature wrapper can return the node to insert + this.container = function () { + return container[0]; + }; + + // Listen for events to change the page length + container.on( 'click.dtll', 'a', function (e) { + e.preventDefault(); + api.page.len( $(this).data('length')*1 ).draw( false ); + } ); + + // Update on each draw + api.on( 'draw', function () { + // No point in updating - nothing has changed + if ( api.page.len() === lastLength ) { + return; + } + + var menu = settings.aLengthMenu; + var lang = menu.length===2 && $.isArray(menu[0]) ? menu[1] : menu; + var lens = menu.length===2 && $.isArray(menu[0]) ? menu[0] : menu; + + var out = $.map( lens, function (el, i) { + return el == api.page.len() ? + ''+lang[i]+'' : + ''+lang[i]+''; + } ); + + container.html( settings.oLanguage.sLengthMenu.replace( '_MENU_', out.join(' | ') ) ); + lastLength = api.page.len(); + } ); + + api.on( 'destroy', function () { + container.off( 'click.dtll', 'a' ); + } ); +}; + +// Subscribe the feature plug-in to DataTables, ready for use +$.fn.dataTable.ext.feature.push( { + "fnInit": function( settings ) { + var l = new $.fn.dataTable.LengthLinks( settings ); + return l.container(); + }, + "cFeature": "L", + "sFeature": "LengthLinks" +} ); + + +})(window, document, jQuery); diff --git a/features/lengthLinks/dataTables.lengthLinks.min.js b/features/lengthLinks/dataTables.lengthLinks.min.js new file mode 100644 index 0000000..ef28bd4 --- /dev/null +++ b/features/lengthLinks/dataTables.lengthLinks.min.js @@ -0,0 +1,5 @@ +/*! Page length control via links for DataTables + * 2014 SpryMedia Ltd - datatables.net/license + */ +(function(i,j,a){a.fn.dataTable.LengthLinks=function(d){var c=new a.fn.dataTable.Api(d),f=c.settings()[0],e=a("").addClass(f.oClasses.sLength),h=-1;this.container=function(){return e[0]};e.on("click.dtll","a",function(b){b.preventDefault();c.page.len(1*a(this).data("length")).draw(!1)});c.on("draw",function(){if(c.page.len()!==h){var b=f.aLengthMenu,d=2===b.length&&a.isArray(b[0])?b[1]:b,g=2===b.length&&a.isArray(b[0])?b[0]:b,b=a.map(g,function(b,a){return b==c.page.len()?''+d[a]+"":''+d[a]+""});e.html(f.oLanguage.sLengthMenu.replace("_MENU_",b.join(" | ")));h=c.page.len()}});c.on("destroy",function(){e.off("click.dtll","a")})};a.fn.dataTable.ext.feature.push({fnInit:function(d){return(new a.fn.dataTable.LengthLinks(d)).container()},cFeature:"L",sFeature:"LengthLinks"})})(window,document,jQuery); diff --git a/make.sh b/make.sh index 0cf6430..a5a7c73 100644 --- a/make.sh +++ b/make.sh @@ -14,6 +14,7 @@ scss_compile $DT_SRC/extensions/Plugins/integration/jqueryui/dataTables.jqueryui js_compress $DT_SRC/extensions/Plugins/features/searchHighlight/dataTables.searchHighlight.js js_compress $DT_SRC/extensions/Plugins/features/alphabetSearch/dataTables.alphabetSearch.js +js_compress $DT_SRC/extensions/Plugins/features/lengthLinks/dataTables.lengthLinks.js # Only copying the integration files rsync -r integration $OUT_DIR