@@ -48,6 +48,15 @@ var _dtButtons = DataTable.ext.buttons;
48
48
*/
49
49
var Buttons = function ( dt , config )
50
50
{
51
+ // If not created with a `new` keyword then we return a wrapper function that
52
+ // will take the settings object for a DT. This allows easy use of new instances
53
+ // with the `layout` option - e.g. `topLeft: $.fn.dataTable.Buttons( ... )`.
54
+ if ( ! ( this instanceof Buttons ) ) {
55
+ return function ( settings ) {
56
+ return new Buttons ( settings , dt ) . container ( ) ;
57
+ } ;
58
+ }
59
+
51
60
// If there is no config set it to an empty object
52
61
if ( typeof ( config ) === 'undefined' ) {
53
62
config = { } ;
@@ -248,12 +257,16 @@ $.extend( Buttons.prototype, {
248
257
} ,
249
258
250
259
/**
251
- * Get a button's node
252
- * @param {node } node Button node
253
- * @return {jQuery } Button element
260
+ * Get a button's node of the buttons container if no button is given
261
+ * @param {node } [ node] Button node
262
+ * @return {jQuery } Button element, or container
254
263
*/
255
264
node : function ( node )
256
265
{
266
+ if ( ! node ) {
267
+ return this . dom . container ;
268
+ }
269
+
257
270
var button = this . _nodeToButton ( node ) ;
258
271
return $ ( button . node ) ;
259
272
} ,
@@ -1902,17 +1915,24 @@ $(document).on( 'init.dt plugin-init.dt', function (e, settings) {
1902
1915
}
1903
1916
} ) ;
1904
1917
1918
+ function _init ( settings ) {
1919
+ var api = new DataTable . Api ( settings ) ;
1920
+ var opts = api . init ( ) . buttons || DataTable . defaults . buttons ;
1921
+
1922
+ return new Buttons ( api , opts ) . container ( ) ;
1923
+ }
1924
+
1905
1925
// DataTables `dom` feature option
1906
1926
DataTable . ext . feature . push ( {
1907
- fnInit : function ( settings ) {
1908
- var api = new DataTable . Api ( settings ) ;
1909
- var opts = api . init ( ) . buttons || DataTable . defaults . buttons ;
1910
-
1911
- return new Buttons ( api , opts ) . container ( ) ;
1912
- } ,
1927
+ fnInit : _init ,
1913
1928
cFeature : "B"
1914
1929
} ) ;
1915
1930
1931
+ // DataTables 2 layout feature
1932
+ if ( DataTable . ext . features ) {
1933
+ DataTable . ext . features . register ( 'buttons' , _init ) ;
1934
+ }
1935
+
1916
1936
1917
1937
return Buttons ;
1918
1938
} ) ) ;
0 commit comments