]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/static/AdminLTE-2.3.7/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js
2 * 2009-2015 SpryMedia Ltd - datatables.net/license
5 * Author: Joseph Huckaby - MIT licensed
10 * @description Tools and buttons for DataTables
12 * @file dataTables.tableTools.js
13 * @author SpryMedia Ltd (www.sprymedia.co.uk)
14 * @contact www.sprymedia.co.uk/contact
15 * @copyright Copyright 2009-2015 SpryMedia Ltd.
17 * This source file is free software, available under the following license:
18 * MIT license - http://datatables.net/license/mit
20 * This source file is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
24 * For details please refer to: http://www.datatables.net
28 /* Global scope for TableTools for backwards compatibility.
29 * Will be removed in 2.3
33 (function(window
, document
, undefined) {
36 var factory = function( $, DataTable
) {
40 //include ZeroClipboard.js
41 /* ZeroClipboard 1.0.4
42 * Author: Joseph Huckaby
45 var ZeroClipboard_TableTools
= {
47 version
: "1.0.4-TableTools2",
48 clients
: {}, // registered upload clients on page, indexed by id
49 moviePath
: '', // URL to movie
50 nextId
: 1, // ID of next movie
53 // simple DOM lookup utility function
54 if (typeof(thingy
) == 'string') {
55 thingy
= document
.getElementById(thingy
);
57 if (!thingy
.addClass
) {
58 // extend element with a few useful methods
59 thingy
.hide = function() { this.style
.display
= 'none'; };
60 thingy
.show = function() { this.style
.display
= ''; };
61 thingy
.addClass = function(name
) { this.removeClass(name
); this.className
+= ' ' + name
; };
62 thingy
.removeClass = function(name
) {
63 this.className
= this.className
.replace( new RegExp("\\s*" + name
+ "\\s*"), " ").replace(/^\s+/, '').replace(/\s+$/, '');
65 thingy
.hasClass = function(name
) {
66 return !!this.className
.match( new RegExp("\\s*" + name
+ "\\s*") );
72 setMoviePath: function(path
) {
73 // set path to ZeroClipboard.swf
74 this.moviePath
= path
;
77 dispatch: function(id
, eventName
, args
) {
78 // receive event from flash movie, send to client
79 var client
= this.clients
[id
];
81 client
.receiveEvent(eventName
, args
);
85 register: function(id
, client
) {
86 // register new client to receive events
87 this.clients
[id
] = client
;
90 getDOMObjectPosition: function(obj
) {
91 // get absolute coordinates for dom element
95 width
: obj
.width
? obj
.width
: obj
.offsetWidth
,
96 height
: obj
.height
? obj
.height
: obj
.offsetHeight
99 if ( obj
.style
.width
!== "" ) {
100 info
.width
= obj
.style
.width
.replace("px","");
103 if ( obj
.style
.height
!== "" ) {
104 info
.height
= obj
.style
.height
.replace("px","");
108 info
.left
+= obj
.offsetLeft
;
109 info
.top
+= obj
.offsetTop
;
110 obj
= obj
.offsetParent
;
116 Client: function(elem
) {
117 // constructor for new simple upload client
121 this.id
= ZeroClipboard_TableTools
.nextId
++;
122 this.movieId
= 'ZeroClipboard_TableToolsMovie_' + this.id
;
124 // register client with singleton to receive flash events
125 ZeroClipboard_TableTools
.register(this.id
, this);
134 ZeroClipboard_TableTools
.Client
.prototype = {
136 id
: 0, // unique ID for us
137 ready
: false, // whether movie is ready to receive events or not
138 movie
: null, // reference to movie object
139 clipText
: '', // text to copy to clipboard
140 fileName
: '', // default file save name
141 action
: 'copy', // action to perform
142 handCursorEnabled
: true, // whether to show hand cursor, or default pointer cursor
143 cssEffects
: true, // enable CSS mouse effects on dom container
144 handlers
: null, // user event handlers
147 glue: function(elem
, title
) {
148 // glue to DOM element
149 // elem can be ID or actual DOM element object
150 this.domElement
= ZeroClipboard_TableTools
.$(elem
);
152 // float just above object, or zIndex 99 if dom element isn't set
154 if (this.domElement
.style
.zIndex
) {
155 zIndex
= parseInt(this.domElement
.style
.zIndex
, 10) + 1;
158 // find X/Y position of domElement
159 var box
= ZeroClipboard_TableTools
.getDOMObjectPosition(this.domElement
);
161 // create floating DIV above element
162 this.div
= document
.createElement('div');
163 var style
= this.div
.style
;
164 style
.position
= 'absolute';
167 style
.width
= (box
.width
) + 'px';
168 style
.height
= box
.height
+ 'px';
169 style
.zIndex
= zIndex
;
171 if ( typeof title
!= "undefined" && title
!== "" ) {
172 this.div
.title
= title
;
174 if ( box
.width
!== 0 && box
.height
!== 0 ) {
178 // style.backgroundColor = '#f00'; // debug
179 if ( this.domElement
) {
180 this.domElement
.appendChild(this.div
);
181 this.div
.innerHTML
= this.getHTML( box
.width
, box
.height
).replace(/&/g
, '&');
185 positionElement: function() {
186 var box
= ZeroClipboard_TableTools
.getDOMObjectPosition(this.domElement
);
187 var style
= this.div
.style
;
189 style
.position
= 'absolute';
190 //style.left = (this.domElement.offsetLeft)+'px';
191 //style.top = this.domElement.offsetTop+'px';
192 style
.width
= box
.width
+ 'px';
193 style
.height
= box
.height
+ 'px';
195 if ( box
.width
!== 0 && box
.height
!== 0 ) {
201 var flash
= this.div
.childNodes
[0];
202 flash
.width
= box
.width
;
203 flash
.height
= box
.height
;
206 getHTML: function(width
, height
) {
207 // return HTML for movie
209 var flashvars
= 'id=' + this.id
+
213 if (navigator
.userAgent
.match(/MSIE/)) {
214 // IE gets an OBJECT tag
215 var protocol
= location
.href
.match(/^https/i) ? 'https://' : 'http://';
216 html
+= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+protocol
+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="'+width
+'" height="'+height
+'" id="'+this.movieId
+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard_TableTools
.moviePath
+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars
+'"/><param name="wmode" value="transparent"/></object>';
219 // all other browsers get an EMBED tag
220 html
+= '<embed id="'+this.movieId
+'" src="'+ZeroClipboard_TableTools
.moviePath
+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width
+'" height="'+height
+'" name="'+this.movieId
+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars
+'" wmode="transparent" />';
226 // temporarily hide floater offscreen
228 this.div
.style
.left
= '-2000px';
233 // show ourselves after a call to hide()
237 destroy: function() {
238 // destroy control and floater
239 if (this.domElement
&& this.div
) {
241 this.div
.innerHTML
= '';
243 var body
= document
.getElementsByTagName('body')[0];
244 try { body
.removeChild( this.div
); } catch(e
) {}
246 this.domElement
= null;
251 reposition: function(elem
) {
252 // reposition our floating div, optionally to new container
253 // warning: container CANNOT change size, only position
255 this.domElement
= ZeroClipboard_TableTools
.$(elem
);
256 if (!this.domElement
) {
261 if (this.domElement
&& this.div
) {
262 var box
= ZeroClipboard_TableTools
.getDOMObjectPosition(this.domElement
);
263 var style
= this.div
.style
;
264 style
.left
= '' + box
.left
+ 'px';
265 style
.top
= '' + box
.top
+ 'px';
269 clearText: function() {
270 // clear the text to be copy / saved
273 this.movie
.clearText();
277 appendText: function(newText
) {
278 // append text to that which is to be copied / saved
279 this.clipText
+= newText
;
280 if (this.ready
) { this.movie
.appendText(newText
) ;}
283 setText: function(newText
) {
284 // set text to be copied to be copied / saved
285 this.clipText
= newText
;
286 if (this.ready
) { this.movie
.setText(newText
) ;}
289 setCharSet: function(charSet
) {
290 // set the character set (UTF16LE or UTF8)
291 this.charSet
= charSet
;
292 if (this.ready
) { this.movie
.setCharSet(charSet
) ;}
295 setBomInc: function(bomInc
) {
296 // set if the BOM should be included or not
297 this.incBom
= bomInc
;
298 if (this.ready
) { this.movie
.setBomInc(bomInc
) ;}
301 setFileName: function(newText
) {
303 this.fileName
= newText
;
305 this.movie
.setFileName(newText
);
309 setAction: function(newText
) {
310 // set action (save or copy)
311 this.action
= newText
;
313 this.movie
.setAction(newText
);
317 addEventListener: function(eventName
, func
) {
318 // add user event listener for event
319 // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
320 eventName
= eventName
.toString().toLowerCase().replace(/^on/, '');
321 if (!this.handlers
[eventName
]) {
322 this.handlers
[eventName
] = [];
324 this.handlers
[eventName
].push(func
);
327 setHandCursor: function(enabled
) {
328 // enable hand cursor (true), or default arrow cursor (false)
329 this.handCursorEnabled
= enabled
;
331 this.movie
.setHandCursor(enabled
);
335 setCSSEffects: function(enabled
) {
336 // enable or disable CSS effects on DOM container
337 this.cssEffects
= !!enabled
;
340 receiveEvent: function(eventName
, args
) {
343 // receive event from flash
344 eventName
= eventName
.toString().toLowerCase().replace(/^on/, '');
346 // special behavior for certain events
349 // movie claims it is ready, but in IE this isn't always the case...
350 // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
351 this.movie
= document
.getElementById(this.movieId
);
354 setTimeout( function() { self
.receiveEvent('load', null); }, 1 );
358 // firefox on pc needs a "kick" in order to set these in certain cases
359 if (!this.ready
&& navigator
.userAgent
.match(/Firefox/) && navigator
.userAgent
.match(/Windows/)) {
361 setTimeout( function() { self
.receiveEvent('load', null); }, 100 );
367 this.movie
.clearText();
368 this.movie
.appendText( this.clipText
);
369 this.movie
.setFileName( this.fileName
);
370 this.movie
.setAction( this.action
);
371 this.movie
.setCharSet( this.charSet
);
372 this.movie
.setBomInc( this.incBom
);
373 this.movie
.setHandCursor( this.handCursorEnabled
);
377 if (this.domElement
&& this.cssEffects
) {
378 //this.domElement.addClass('hover');
379 if (this.recoverActive
) {
380 this.domElement
.addClass('active');
386 if (this.domElement
&& this.cssEffects
) {
387 this.recoverActive
= false;
388 if (this.domElement
.hasClass('active')) {
389 this.domElement
.removeClass('active');
390 this.recoverActive
= true;
392 //this.domElement.removeClass('hover');
397 if (this.domElement
&& this.cssEffects
) {
398 this.domElement
.addClass('active');
403 if (this.domElement
&& this.cssEffects
) {
404 this.domElement
.removeClass('active');
405 this.recoverActive
= false;
408 } // switch eventName
410 if (this.handlers
[eventName
]) {
411 for (var idx
= 0, len
= this.handlers
[eventName
].length
; idx
< len
; idx
++) {
412 var func
= this.handlers
[eventName
][idx
];
414 if (typeof(func
) == 'function') {
415 // actual function reference
418 else if ((typeof(func
) == 'object') && (func
.length
== 2)) {
419 // PHP style object + method, i.e. [myObject, 'myMethod']
420 func
[0][ func
[1] ](this, args
);
422 else if (typeof(func
) == 'string') {
424 window
[func
](this, args
);
426 } // foreach event handler defined
427 } // user defined handler for event
432 // For the Flash binding to work, ZeroClipboard_TableTools must be on the global
434 window
.ZeroClipboard_TableTools
= ZeroClipboard_TableTools
;
435 //include TableTools.js
437 * 2009-2015 SpryMedia Ltd - datatables.net/license
440 /*globals TableTools,ZeroClipboard_TableTools*/
443 (function($, window
, document
) {
446 * TableTools provides flexible buttons and other tools for a DataTables enhanced table
449 * @param {Object} oDT DataTables instance. When using DataTables 1.10 this can
450 * also be a jQuery collection, jQuery selector, table node, DataTables API
451 * instance or DataTables settings object.
452 * @param {Object} oOpts TableTools options
453 * @param {String} oOpts.sSwfPath ZeroClipboard SWF path
454 * @param {String} oOpts.sRowSelect Row selection options - 'none', 'single', 'multi' or 'os'
455 * @param {Function} oOpts.fnPreRowSelect Callback function just prior to row selection
456 * @param {Function} oOpts.fnRowSelected Callback function just after row selection
457 * @param {Function} oOpts.fnRowDeselected Callback function when row is deselected
458 * @param {Array} oOpts.aButtons List of buttons to be used
460 TableTools = function( oDT
, oOpts
)
462 /* Santiy check that we are a new instance */
463 if ( ! this instanceof TableTools
)
465 alert( "Warning: TableTools must be initialised with the keyword 'new'" );
468 // In 1.10 we can use the API to get the settings object from a number of
470 var dtSettings
= $.fn
.dataTable
.Api
?
471 new $.fn
.dataTable
.Api( oDT
).settings()[0] :
475 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
476 * Public class variables
477 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
480 * @namespace Settings object which contains customisable information for TableTools instance
484 * Store 'this' so the instance can be retrieved from the settings object
492 * DataTables settings objects
495 * @default <i>From the oDT init option</i>
500 * @namespace Print specific information
504 * DataTables draw 'start' point before the printing display was shown
505 * @property saveStart
512 * DataTables draw 'length' point before the printing display was shown
513 * @property saveLength
520 * Page scrolling point before the printing display was shown so it can be restored
521 * @property saveScroll
528 * Wrapped function to end the print display (to maintain scope)
531 * @default function () {}
533 "funcEnd": function () {}
537 * A unique ID is assigned to each button in each instance
538 * @property buttonCounter
545 * @namespace Select rows specific information
549 * Select type - can be 'none', 'single' or 'multi'
557 * Array of nodes which are currently selected
565 * Function to run before the selection can take place. Will cancel the select if the
566 * function returns false
567 * @property preRowSelect
571 "preRowSelect": null,
574 * Function to run when a row is selected
575 * @property postSelected
579 "postSelected": null,
582 * Function to run when a row is deselected
583 * @property postDeselected
587 "postDeselected": null,
590 * Indicate if all rows are selected (needed for server-side processing)
598 * Class name to add to selected TR nodes
599 * @property selectedClass
607 * Store of the user input customisation object
624 * @property buttonSet
631 * When there is more than one TableTools instance for a DataTable, there must be a
632 * master which controls events (row selection etc)
640 * Tag names that are used for creating collections and buttons
648 * @namespace Common and useful DOM elements for the class instance
652 * DIV element that is create and all TableTools buttons (and their children) put into
653 * @property container
660 * The table node to which TableTools will be applied
668 * @namespace Nodes used for the print display
672 * Nodes which have been removed from the display by setting them to display none
680 * The information display saying telling the user about the print display
689 * @namespace Nodes used for a collection display. This contains the currently used collection
693 * The div wrapper containing the buttons in the collection (i.e. the menu)
694 * @property collection
701 * Background display to provide focus and capture events
702 * @property background
711 * @namespace Name space for the classes that this TableTools instance will use
712 * @extends TableTools.classes
714 this.classes
= $.extend( true, {}, TableTools
.classes
);
715 if ( this.s
.dt
.bJUI
)
717 $.extend( true, this.classes
, TableTools
.classes_themeroller
);
721 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
722 * Public class methods
723 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
726 * Retreieve the settings object from an instance
728 * @returns {object} TableTools settings object
730 this.fnSettings = function () {
735 /* Constructor logic */
736 if ( typeof oOpts
== 'undefined' )
742 TableTools
._aInstances
.push( this );
743 this._fnConstruct( oOpts
);
750 TableTools
.prototype = {
751 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
753 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
756 * Retreieve the settings object from an instance
757 * @returns {array} List of TR nodes which are currently selected
758 * @param {boolean} [filtered=false] Get only selected rows which are
759 * available given the filtering applied to the table. By default
760 * this is false - i.e. all rows, regardless of filtering are
763 "fnGetSelected": function ( filtered
)
767 data
= this.s
.dt
.aoData
,
768 displayed
= this.s
.dt
.aiDisplay
,
773 // Only consider filtered rows
774 for ( i
=0, iLen
=displayed
.length
; i
<iLen
; i
++ )
776 if ( data
[ displayed
[i
] ]._DTTT_selected
)
778 out
.push( data
[ displayed
[i
] ].nTr
);
785 for ( i
=0, iLen
=data
.length
; i
<iLen
; i
++ )
787 if ( data
[i
]._DTTT_selected
)
789 out
.push( data
[i
].nTr
);
799 * Get the data source objects/arrays from DataTables for the selected rows (same as
800 * fnGetSelected followed by fnGetData on each row from the table)
801 * @returns {array} Data from the TR nodes which are currently selected
803 "fnGetSelectedData": function ()
806 var data
=this.s
.dt
.aoData
;
809 for ( i
=0, iLen
=data
.length
; i
<iLen
; i
++ )
811 if ( data
[i
]._DTTT_selected
)
813 out
.push( this.s
.dt
.oInstance
.fnGetData(i
) );
822 * Get the indexes of the selected rows
823 * @returns {array} List of row indexes
824 * @param {boolean} [filtered=false] Get only selected rows which are
825 * available given the filtering applied to the table. By default
826 * this is false - i.e. all rows, regardless of filtering are
829 "fnGetSelectedIndexes": function ( filtered
)
833 data
= this.s
.dt
.aoData
,
834 displayed
= this.s
.dt
.aiDisplay
,
839 // Only consider filtered rows
840 for ( i
=0, iLen
=displayed
.length
; i
<iLen
; i
++ )
842 if ( data
[ displayed
[i
] ]._DTTT_selected
)
844 out
.push( displayed
[i
] );
851 for ( i
=0, iLen
=data
.length
; i
<iLen
; i
++ )
853 if ( data
[i
]._DTTT_selected
)
865 * Check to see if a current row is selected or not
866 * @param {Node} n TR node to check if it is currently selected or not
867 * @returns {Boolean} true if select, false otherwise
869 "fnIsSelected": function ( n
)
871 var pos
= this.s
.dt
.oInstance
.fnGetPosition( n
);
872 return (this.s
.dt
.aoData
[pos
]._DTTT_selected
===true) ? true : false;
877 * Select all rows in the table
878 * @param {boolean} [filtered=false] Select only rows which are available
879 * given the filtering applied to the table. By default this is false -
880 * i.e. all rows, regardless of filtering are selected.
882 "fnSelectAll": function ( filtered
)
884 this._fnRowSelect( filtered
?
885 this.s
.dt
.aiDisplay
:
892 * Deselect all rows in the table
893 * @param {boolean} [filtered=false] Deselect only rows which are available
894 * given the filtering applied to the table. By default this is false -
895 * i.e. all rows, regardless of filtering are deselected.
897 "fnSelectNone": function ( filtered
)
899 this._fnRowDeselect( this.fnGetSelectedIndexes(filtered
) );
905 * @param {node|object|array} n The row(s) to select. Can be a single DOM
906 * TR node, an array of TR nodes or a jQuery object.
908 "fnSelect": function ( n
)
910 if ( this.s
.select
.type
== "single" )
913 this._fnRowSelect( n
);
917 this._fnRowSelect( n
);
924 * @param {node|object|array} n The row(s) to deselect. Can be a single DOM
925 * TR node, an array of TR nodes or a jQuery object.
927 "fnDeselect": function ( n
)
929 this._fnRowDeselect( n
);
934 * Get the title of the document - useful for file names. The title is retrieved from either
935 * the configuration object's 'title' parameter, or the HTML document title
936 * @param {Object} oConfig Button configuration object
937 * @returns {String} Button title
939 "fnGetTitle": function( oConfig
)
942 if ( typeof oConfig
.sTitle
!= 'undefined' && oConfig
.sTitle
!== "" ) {
943 sTitle
= oConfig
.sTitle
;
945 var anTitle
= document
.getElementsByTagName('title');
946 if ( anTitle
.length
> 0 )
948 sTitle
= anTitle
[0].innerHTML
;
952 /* Strip characters which the OS will object to - checking for UTF8 support in the scripting
955 if ( "\u00A1".toString().length
< 4 ) {
956 return sTitle
.replace(/[^a-zA-Z0-9_\u00A1-\uFFFF\.,\-_ !\(\)]/g, "");
958 return sTitle
.replace(/[^a-zA-Z0-9_\.,\-_ !\(\)]/g, "");
964 * Calculate a unity array with the column width by proportion for a set of columns to be
965 * included for a button. This is particularly useful for PDF creation, where we can use the
966 * column widths calculated by the browser to size the columns in the PDF.
967 * @param {Object} oConfig Button configuration object
968 * @returns {Array} Unity array of column ratios
970 "fnCalcColRatios": function ( oConfig
)
973 aoCols
= this.s
.dt
.aoColumns
,
974 aColumnsInc
= this._fnColumnTargets( oConfig
.mColumns
),
976 iWidth
= 0, iTotal
= 0, i
, iLen
;
978 for ( i
=0, iLen
=aColumnsInc
.length
; i
<iLen
; i
++ )
980 if ( aColumnsInc
[i
] )
982 iWidth
= aoCols
[i
].nTh
.offsetWidth
;
984 aColWidths
.push( iWidth
);
988 for ( i
=0, iLen
=aColWidths
.length
; i
<iLen
; i
++ )
990 aColWidths
[i
] = aColWidths
[i
] / iTotal
;
993 return aColWidths
.join('\t');
998 * Get the information contained in a table as a string
999 * @param {Object} oConfig Button configuration object
1000 * @returns {String} Table data as a string
1002 "fnGetTableData": function ( oConfig
)
1004 /* In future this could be used to get data from a plain HTML source as well as DataTables */
1007 return this._fnGetDataTablesData( oConfig
);
1013 * Pass text to a flash button instance, which will be used on the button's click handler
1014 * @param {Object} clip Flash button object
1015 * @param {String} text Text to set
1017 "fnSetText": function ( clip
, text
)
1019 this._fnFlashSetText( clip
, text
);
1024 * Resize the flash elements of the buttons attached to this TableTools instance - this is
1025 * useful for when initialising TableTools when it is hidden (display:none) since sizes can't
1026 * be calculated at that time.
1028 "fnResizeButtons": function ()
1030 for ( var cli
in ZeroClipboard_TableTools
.clients
)
1034 var client
= ZeroClipboard_TableTools
.clients
[cli
];
1035 if ( typeof client
.domElement
!= 'undefined' &&
1036 client
.domElement
.parentNode
)
1038 client
.positionElement();
1046 * Check to see if any of the ZeroClipboard client's attached need to be resized
1048 "fnResizeRequired": function ()
1050 for ( var cli
in ZeroClipboard_TableTools
.clients
)
1054 var client
= ZeroClipboard_TableTools
.clients
[cli
];
1055 if ( typeof client
.domElement
!= 'undefined' &&
1056 client
.domElement
.parentNode
== this.dom
.container
&&
1057 client
.sized
=== false )
1068 * Programmatically enable or disable the print view
1069 * @param {boolean} [bView=true] Show the print view if true or not given. If false, then
1070 * terminate the print view and return to normal.
1071 * @param {object} [oConfig={}] Configuration for the print view
1072 * @param {boolean} [oConfig.bShowAll=false] Show all rows in the table if true
1073 * @param {string} [oConfig.sInfo] Information message, displayed as an overlay to the
1074 * user to let them know what the print view is.
1075 * @param {string} [oConfig.sMessage] HTML string to show at the top of the document - will
1076 * be included in the printed document.
1078 "fnPrint": function ( bView
, oConfig
)
1080 if ( oConfig
=== undefined )
1085 if ( bView
=== undefined || bView
)
1087 this._fnPrintStart( oConfig
);
1097 * Show a message to the end user which is nicely styled
1098 * @param {string} message The HTML string to show to the user
1099 * @param {int} time The duration the message is to be shown on screen for (mS)
1101 "fnInfo": function ( message
, time
) {
1102 var info
= $('<div/>')
1103 .addClass( this.classes
.print
.info
)
1105 .appendTo( 'body' );
1107 setTimeout( function() {
1108 info
.fadeOut( "normal", function() {
1117 * Get the container element of the instance for attaching to the DOM
1118 * @returns {node} DOM node
1120 "fnContainer": function () {
1121 return this.dom
.container
;
1126 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1127 * Private methods (they are of course public in JS, but recommended as private)
1128 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1132 * @method _fnConstruct
1133 * @param {Object} oOpts Same as TableTools constructor
1137 "_fnConstruct": function ( oOpts
)
1141 this._fnCustomiseSettings( oOpts
);
1143 /* Container element */
1144 this.dom
.container
= document
.createElement( this.s
.tags
.container
);
1145 this.dom
.container
.className
= this.classes
.container
;
1147 /* Row selection config */
1148 if ( this.s
.select
.type
!= 'none' )
1150 this._fnRowSelectConfig();
1154 this._fnButtonDefinations( this.s
.buttonSet
, this.dom
.container
);
1157 this.s
.dt
.aoDestroyCallback
.push( {
1158 "sName": "TableTools",
1161 .off( 'click.DTTT_Select', that
.s
.custom
.sRowSelector
)
1162 .off( 'mousedown.DTTT_Select', 'tr' )
1163 .off( 'mouseup.DTTT_Select', 'tr' );
1165 $(that
.dom
.container
).empty();
1167 // Remove the instance
1168 var idx
= $.inArray( that
, TableTools
._aInstances
);
1170 TableTools
._aInstances
.splice( idx
, 1 );
1178 * Take the user defined settings and the default settings and combine them.
1179 * @method _fnCustomiseSettings
1180 * @param {Object} oOpts Same as TableTools constructor
1184 "_fnCustomiseSettings": function ( oOpts
)
1186 /* Is this the master control instance or not? */
1187 if ( typeof this.s
.dt
._TableToolsInit
== 'undefined' )
1189 this.s
.master
= true;
1190 this.s
.dt
._TableToolsInit
= true;
1193 /* We can use the table node from comparisons to group controls */
1194 this.dom
.table
= this.s
.dt
.nTable
;
1196 /* Clone the defaults and then the user options */
1197 this.s
.custom
= $.extend( {}, TableTools
.DEFAULTS
, oOpts
);
1199 /* Flash file location */
1200 this.s
.swfPath
= this.s
.custom
.sSwfPath
;
1201 if ( typeof ZeroClipboard_TableTools
!= 'undefined' )
1203 ZeroClipboard_TableTools
.moviePath
= this.s
.swfPath
;
1206 /* Table row selecting */
1207 this.s
.select
.type
= this.s
.custom
.sRowSelect
;
1208 this.s
.select
.preRowSelect
= this.s
.custom
.fnPreRowSelect
;
1209 this.s
.select
.postSelected
= this.s
.custom
.fnRowSelected
;
1210 this.s
.select
.postDeselected
= this.s
.custom
.fnRowDeselected
;
1212 // Backwards compatibility - allow the user to specify a custom class in the initialiser
1213 if ( this.s
.custom
.sSelectedClass
)
1215 this.classes
.select
.row
= this.s
.custom
.sSelectedClass
;
1218 this.s
.tags
= this.s
.custom
.oTags
;
1221 this.s
.buttonSet
= this.s
.custom
.aButtons
;
1226 * Take the user input arrays and expand them to be fully defined, and then add them to a given
1228 * @method _fnButtonDefinations
1229 * @param {array} buttonSet Set of user defined buttons
1230 * @param {node} wrapper Node to add the created buttons to
1234 "_fnButtonDefinations": function ( buttonSet
, wrapper
)
1238 for ( var i
=0, iLen
=buttonSet
.length
; i
<iLen
; i
++ )
1240 if ( typeof buttonSet
[i
] == "string" )
1242 if ( typeof TableTools
.BUTTONS
[ buttonSet
[i
] ] == 'undefined' )
1244 alert( "TableTools: Warning - unknown button type: "+buttonSet
[i
] );
1247 buttonDef
= $.extend( {}, TableTools
.BUTTONS
[ buttonSet
[i
] ], true );
1251 if ( typeof TableTools
.BUTTONS
[ buttonSet
[i
].sExtends
] == 'undefined' )
1253 alert( "TableTools: Warning - unknown button type: "+buttonSet
[i
].sExtends
);
1256 var o
= $.extend( {}, TableTools
.BUTTONS
[ buttonSet
[i
].sExtends
], true );
1257 buttonDef
= $.extend( o
, buttonSet
[i
], true );
1260 var button
= this._fnCreateButton(
1262 $(wrapper
).hasClass(this.classes
.collection
.container
)
1266 wrapper
.appendChild( button
);
1273 * Create and configure a TableTools button
1274 * @method _fnCreateButton
1275 * @param {Object} oConfig Button configuration object
1276 * @returns {Node} Button element
1279 "_fnCreateButton": function ( oConfig
, bCollectionButton
)
1281 var nButton
= this._fnButtonBase( oConfig
, bCollectionButton
);
1283 if ( oConfig
.sAction
.match(/flash/) )
1285 if ( ! this._fnHasFlash() ) {
1289 this._fnFlashConfig( nButton
, oConfig
);
1291 else if ( oConfig
.sAction
== "text" )
1293 this._fnTextConfig( nButton
, oConfig
);
1295 else if ( oConfig
.sAction
== "div" )
1297 this._fnTextConfig( nButton
, oConfig
);
1299 else if ( oConfig
.sAction
== "collection" )
1301 this._fnTextConfig( nButton
, oConfig
);
1302 this._fnCollectionConfig( nButton
, oConfig
);
1305 if ( this.s
.dt
.iTabIndex
!== -1 ) {
1307 .attr( 'tabindex', this.s
.dt
.iTabIndex
)
1308 .attr( 'aria-controls', this.s
.dt
.sTableId
)
1309 .on( 'keyup.DTTT', function (e
) {
1310 // Trigger the click event on return key when focused.
1311 // Note that for Flash buttons this has no effect since we
1312 // can't programmatically trigger the Flash export
1313 if ( e
.keyCode
=== 13 ) {
1314 e
.stopPropagation();
1316 $(this).trigger( 'click' );
1319 .on( 'mousedown.DTTT', function (e
) {
1320 // On mousedown we want to stop the focus occurring on the
1321 // button, focus is used only for the keyboard navigation.
1322 // But using preventDefault for the flash buttons stops the
1323 // flash action. However, it is not the button that gets
1324 // focused but the flash element for flash buttons, so this
1326 if ( ! oConfig
.sAction
.match(/flash/) ) {
1337 * Create the DOM needed for the button and apply some base properties. All buttons start here
1338 * @method _fnButtonBase
1339 * @param {o} oConfig Button configuration object
1340 * @returns {Node} DIV element for the button
1343 "_fnButtonBase": function ( o
, bCollectionButton
)
1345 var sTag
, sLiner
, sClass
;
1347 if ( bCollectionButton
)
1349 sTag
= o
.sTag
&& o
.sTag
!== "default" ? o
.sTag
: this.s
.tags
.collection
.button
;
1350 sLiner
= o
.sLinerTag
&& o
.sLinerTag
!== "default" ? o
.sLiner
: this.s
.tags
.collection
.liner
;
1351 sClass
= this.classes
.collection
.buttons
.normal
;
1355 sTag
= o
.sTag
&& o
.sTag
!== "default" ? o
.sTag
: this.s
.tags
.button
;
1356 sLiner
= o
.sLinerTag
&& o
.sLinerTag
!== "default" ? o
.sLiner
: this.s
.tags
.liner
;
1357 sClass
= this.classes
.buttons
.normal
;
1361 nButton
= document
.createElement( sTag
),
1362 nSpan
= document
.createElement( sLiner
),
1363 masterS
= this._fnGetMasterSettings();
1365 nButton
.className
= sClass
+" "+o
.sButtonClass
;
1366 nButton
.setAttribute('id', "ToolTables_"+this.s
.dt
.sInstance
+"_"+masterS
.buttonCounter
);
1367 nButton
.appendChild( nSpan
);
1368 nSpan
.innerHTML
= o
.sButtonText
;
1370 masterS
.buttonCounter
++;
1377 * Get the settings object for the master instance. When more than one TableTools instance is
1378 * assigned to a DataTable, only one of them can be the 'master' (for the select rows). As such,
1379 * we will typically want to interact with that master for global properties.
1380 * @method _fnGetMasterSettings
1381 * @returns {Object} TableTools settings object
1384 "_fnGetMasterSettings": function ()
1386 if ( this.s
.master
)
1392 /* Look for the master which has the same DT as this one */
1393 var instances
= TableTools
._aInstances
;
1394 for ( var i
=0, iLen
=instances
.length
; i
<iLen
; i
++ )
1396 if ( this.dom
.table
== instances
[i
].s
.dt
.nTable
)
1398 return instances
[i
].s
;
1406 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1407 * Button collection functions
1411 * Create a collection button, when activated will present a drop down list of other buttons
1412 * @param {Node} nButton Button to use for the collection activation
1413 * @param {Object} oConfig Button configuration object
1417 "_fnCollectionConfig": function ( nButton
, oConfig
)
1419 var nHidden
= document
.createElement( this.s
.tags
.collection
.container
);
1420 nHidden
.style
.display
= "none";
1421 nHidden
.className
= this.classes
.collection
.container
;
1422 oConfig
._collection
= nHidden
;
1423 document
.body
.appendChild( nHidden
);
1425 this._fnButtonDefinations( oConfig
.aButtons
, nHidden
);
1430 * Show a button collection
1431 * @param {Node} nButton Button to use for the collection
1432 * @param {Object} oConfig Button configuration object
1436 "_fnCollectionShow": function ( nButton
, oConfig
)
1440 oPos
= $(nButton
).offset(),
1441 nHidden
= oConfig
._collection
,
1443 iDivY
= oPos
.top
+ $(nButton
).outerHeight(),
1444 iWinHeight
= $(window
).height(), iDocHeight
= $(document
).height(),
1445 iWinWidth
= $(window
).width(), iDocWidth
= $(document
).width();
1447 nHidden
.style
.position
= "absolute";
1448 nHidden
.style
.left
= iDivX
+"px";
1449 nHidden
.style
.top
= iDivY
+"px";
1450 nHidden
.style
.display
= "block";
1451 $(nHidden
).css('opacity',0);
1453 var nBackground
= document
.createElement('div');
1454 nBackground
.style
.position
= "absolute";
1455 nBackground
.style
.left
= "0px";
1456 nBackground
.style
.top
= "0px";
1457 nBackground
.style
.height
= ((iWinHeight
>iDocHeight
)? iWinHeight
: iDocHeight
) +"px";
1458 nBackground
.style
.width
= ((iWinWidth
>iDocWidth
)? iWinWidth
: iDocWidth
) +"px";
1459 nBackground
.className
= this.classes
.collection
.background
;
1460 $(nBackground
).css('opacity',0);
1462 document
.body
.appendChild( nBackground
);
1463 document
.body
.appendChild( nHidden
);
1465 /* Visual corrections to try and keep the collection visible */
1466 var iDivWidth
= $(nHidden
).outerWidth();
1467 var iDivHeight
= $(nHidden
).outerHeight();
1469 if ( iDivX
+ iDivWidth
> iDocWidth
)
1471 nHidden
.style
.left
= (iDocWidth
-iDivWidth
)+"px";
1474 if ( iDivY
+ iDivHeight
> iDocHeight
)
1476 nHidden
.style
.top
= (iDivY
-iDivHeight
-$(nButton
).outerHeight())+"px";
1479 this.dom
.collection
.collection
= nHidden
;
1480 this.dom
.collection
.background
= nBackground
;
1482 /* This results in a very small delay for the end user but it allows the animation to be
1483 * much smoother. If you don't want the animation, then the setTimeout can be removed
1485 setTimeout( function () {
1486 $(nHidden
).animate({"opacity": 1}, 500);
1487 $(nBackground
).animate({"opacity": 0.25}, 500);
1490 /* Resize the buttons to the Flash contents fit */
1491 this.fnResizeButtons();
1493 /* Event handler to remove the collection display */
1494 $(nBackground
).click( function () {
1495 that
._fnCollectionHide
.call( that
, null, null );
1501 * Hide a button collection
1502 * @param {Node} nButton Button to use for the collection
1503 * @param {Object} oConfig Button configuration object
1507 "_fnCollectionHide": function ( nButton
, oConfig
)
1509 if ( oConfig
!== null && oConfig
.sExtends
== 'collection' )
1514 if ( this.dom
.collection
.collection
!== null )
1516 $(this.dom
.collection
.collection
).animate({"opacity": 0}, 500, function (e
) {
1517 this.style
.display
= "none";
1520 $(this.dom
.collection
.background
).animate({"opacity": 0}, 500, function (e
) {
1521 this.parentNode
.removeChild( this );
1524 this.dom
.collection
.collection
= null;
1525 this.dom
.collection
.background
= null;
1531 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1532 * Row selection functions
1536 * Add event handlers to a table to allow for row selection
1537 * @method _fnRowSelectConfig
1541 "_fnRowSelectConfig": function ()
1543 if ( this.s
.master
)
1549 aoOpenRows
= this.s
.dt
.aoOpenRows
;
1551 $(dt
.nTable
).addClass( this.classes
.select
.table
);
1553 // When using OS style selection, we want to cancel the shift text
1554 // selection, but only when the shift key is used (so you can
1555 // actually still select text in the table)
1556 if ( this.s
.select
.type
=== 'os' ) {
1557 $(dt
.nTBody
).on( 'mousedown.DTTT_Select', 'tr', function(e
) {
1561 .css( '-moz-user-select', 'none' )
1562 .one('selectstart.DTTT_Select', 'tr', function () {
1568 $(dt
.nTBody
).on( 'mouseup.DTTT_Select', 'tr', function(e
) {
1569 $(dt
.nTBody
).css( '-moz-user-select', '' );
1574 $(dt
.nTBody
).on( 'click.DTTT_Select', this.s
.custom
.sRowSelector
, function(e
) {
1575 var row
= this.nodeName
.toLowerCase() === 'tr' ?
1577 $(this).parents('tr')[0];
1579 var select
= that
.s
.select
;
1580 var pos
= that
.s
.dt
.oInstance
.fnGetPosition( row
);
1582 /* Sub-table must be ignored (odd that the selector won't do this with >) */
1583 if ( row
.parentNode
!= dt
.nTBody
) {
1587 /* Check that we are actually working with a DataTables controlled row */
1588 if ( dt
.oInstance
.fnGetData(row
) === null ) {
1592 // Shift click, ctrl click and simple click handling to make
1593 // row selection a lot like a file system in desktop OSs
1594 if ( select
.type
== 'os' ) {
1595 if ( e
.ctrlKey
|| e
.metaKey
) {
1596 // Add or remove from the selection
1597 if ( that
.fnIsSelected( row
) ) {
1598 that
._fnRowDeselect( row
, e
);
1601 that
._fnRowSelect( row
, e
);
1604 else if ( e
.shiftKey
) {
1605 // Add a range of rows, from the last selected row to
1607 var rowIdxs
= that
.s
.dt
.aiDisplay
.slice(); // visible rows
1608 var idx1
= $.inArray( select
.lastRow
, rowIdxs
);
1609 var idx2
= $.inArray( pos
, rowIdxs
);
1611 if ( that
.fnGetSelected().length
=== 0 || idx1
=== -1 ) {
1612 // select from top to here - slightly odd, but both
1613 // Windows and Mac OS do this
1614 rowIdxs
.splice( $.inArray( pos
, rowIdxs
)+1, rowIdxs
.length
);
1617 // reverse so we can shift click 'up' as well as down
1618 if ( idx1
> idx2
) {
1624 rowIdxs
.splice( idx2
+1, rowIdxs
.length
);
1625 rowIdxs
.splice( 0, idx1
);
1628 if ( ! that
.fnIsSelected( row
) ) {
1630 that
._fnRowSelect( rowIdxs
, e
);
1633 // Deselect range - need to keep the clicked on row selected
1634 rowIdxs
.splice( $.inArray( pos
, rowIdxs
), 1 );
1635 that
._fnRowDeselect( rowIdxs
, e
);
1639 // No cmd or shift click. Deselect current if selected,
1640 // or select this row only
1641 if ( that
.fnIsSelected( row
) && that
.fnGetSelected().length
=== 1 ) {
1642 that
._fnRowDeselect( row
, e
);
1645 that
.fnSelectNone();
1646 that
._fnRowSelect( row
, e
);
1650 else if ( that
.fnIsSelected( row
) ) {
1651 that
._fnRowDeselect( row
, e
);
1653 else if ( select
.type
== "single" ) {
1654 that
.fnSelectNone();
1655 that
._fnRowSelect( row
, e
);
1657 else if ( select
.type
== "multi" ) {
1658 that
._fnRowSelect( row
, e
);
1661 select
.lastRow
= pos
;
1662 } );//.on('selectstart', function () { return false; } );
1664 // Bind a listener to the DataTable for when new rows are created.
1665 // This allows rows to be visually selected when they should be and
1666 // deferred rendering is used.
1667 dt
.oApi
._fnCallbackReg( dt
, 'aoRowCreatedCallback', function (tr
, data
, index
) {
1668 if ( dt
.aoData
[index
]._DTTT_selected
) {
1669 $(tr
).addClass( that
.classes
.select
.row
);
1671 }, 'TableTools-SelectAll' );
1677 * @param {*} src Rows to select - see _fnSelectData for a description of valid inputs
1680 "_fnRowSelect": function ( src
, e
)
1684 data
= this._fnSelectData( src
),
1685 firstTr
= data
.length
===0 ? null : data
[0].nTr
,
1689 // Get all the rows that will be selected
1690 for ( i
=0, len
=data
.length
; i
<len
; i
++ )
1694 anSelected
.push( data
[i
].nTr
);
1698 // User defined pre-selection function
1699 if ( this.s
.select
.preRowSelect
!== null && !this.s
.select
.preRowSelect
.call(this, e
, anSelected
, true) )
1704 // Mark them as selected
1705 for ( i
=0, len
=data
.length
; i
<len
; i
++ )
1707 data
[i
]._DTTT_selected
= true;
1711 $(data
[i
].nTr
).addClass( that
.classes
.select
.row
);
1715 // Post-selection function
1716 if ( this.s
.select
.postSelected
!== null )
1718 this.s
.select
.postSelected
.call( this, anSelected
);
1721 TableTools
._fnEventDispatch( this, 'select', anSelected
, true );
1726 * @param {*} src Rows to deselect - see _fnSelectData for a description of valid inputs
1729 "_fnRowDeselect": function ( src
, e
)
1733 data
= this._fnSelectData( src
),
1734 firstTr
= data
.length
===0 ? null : data
[0].nTr
,
1735 anDeselectedTrs
= [],
1738 // Get all the rows that will be deselected
1739 for ( i
=0, len
=data
.length
; i
<len
; i
++ )
1743 anDeselectedTrs
.push( data
[i
].nTr
);
1747 // User defined pre-selection function
1748 if ( this.s
.select
.preRowSelect
!== null && !this.s
.select
.preRowSelect
.call(this, e
, anDeselectedTrs
, false) )
1753 // Mark them as deselected
1754 for ( i
=0, len
=data
.length
; i
<len
; i
++ )
1756 data
[i
]._DTTT_selected
= false;
1760 $(data
[i
].nTr
).removeClass( that
.classes
.select
.row
);
1764 // Post-deselection function
1765 if ( this.s
.select
.postDeselected
!== null )
1767 this.s
.select
.postDeselected
.call( this, anDeselectedTrs
);
1770 TableTools
._fnEventDispatch( this, 'select', anDeselectedTrs
, false );
1774 * Take a data source for row selection and convert it into aoData points for the DT
1775 * @param {*} src Can be a single DOM TR node, an array of TR nodes (including a
1776 * a jQuery object), a single aoData point from DataTables, an array of aoData
1777 * points or an array of aoData indexes
1778 * @returns {array} An array of aoData points
1780 "_fnSelectData": function ( src
)
1782 var out
= [], pos
, i
, iLen
;
1787 pos
= this.s
.dt
.oInstance
.fnGetPosition( src
);
1788 out
.push( this.s
.dt
.aoData
[pos
] );
1790 else if ( typeof src
.length
!== 'undefined' )
1792 // jQuery object or an array of nodes, or aoData points
1793 for ( i
=0, iLen
=src
.length
; i
<iLen
; i
++ )
1795 if ( src
[i
].nodeName
)
1797 pos
= this.s
.dt
.oInstance
.fnGetPosition( src
[i
] );
1798 out
.push( this.s
.dt
.aoData
[pos
] );
1800 else if ( typeof src
[i
] === 'number' )
1802 out
.push( this.s
.dt
.aoData
[ src
[i
] ] );
1812 else if ( typeof src
=== 'number' )
1814 out
.push(this.s
.dt
.aoData
[src
]);
1818 // A single aoData point
1826 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1827 * Text button functions
1831 * Configure a text based button for interaction events
1832 * @method _fnTextConfig
1833 * @param {Node} nButton Button element which is being considered
1834 * @param {Object} oConfig Button configuration object
1838 "_fnTextConfig": function ( nButton
, oConfig
)
1842 if ( oConfig
.fnInit
!== null )
1844 oConfig
.fnInit
.call( this, nButton
, oConfig
);
1847 if ( oConfig
.sToolTip
!== "" )
1849 nButton
.title
= oConfig
.sToolTip
;
1852 $(nButton
).hover( function () {
1853 if ( oConfig
.fnMouseover
!== null )
1855 oConfig
.fnMouseover
.call( this, nButton
, oConfig
, null );
1858 if ( oConfig
.fnMouseout
!== null )
1860 oConfig
.fnMouseout
.call( this, nButton
, oConfig
, null );
1864 if ( oConfig
.fnSelect
!== null )
1866 TableTools
._fnEventListen( this, 'select', function (n
) {
1867 oConfig
.fnSelect
.call( that
, nButton
, oConfig
, n
);
1871 $(nButton
).click( function (e
) {
1872 //e.preventDefault();
1874 if ( oConfig
.fnClick
!== null )
1876 oConfig
.fnClick
.call( that
, nButton
, oConfig
, null, e
);
1879 /* Provide a complete function to match the behaviour of the flash elements */
1880 if ( oConfig
.fnComplete
!== null )
1882 oConfig
.fnComplete
.call( that
, nButton
, oConfig
, null, null );
1885 that
._fnCollectionHide( nButton
, oConfig
);
1891 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1892 * Flash button functions
1896 * Check if the Flash plug-in is available
1897 * @method _fnHasFlash
1898 * @returns {boolean} `true` if Flash available, `false` otherwise
1901 "_fnHasFlash": function ()
1904 var fo
= new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
1911 navigator
.mimeTypes
&&
1912 navigator
.mimeTypes
['application/x-shockwave-flash'] !== undefined &&
1913 navigator
.mimeTypes
['application/x-shockwave-flash'].enabledPlugin
1924 * Configure a flash based button for interaction events
1925 * @method _fnFlashConfig
1926 * @param {Node} nButton Button element which is being considered
1927 * @param {o} oConfig Button configuration object
1931 "_fnFlashConfig": function ( nButton
, oConfig
)
1934 var flash
= new ZeroClipboard_TableTools
.Client();
1936 if ( oConfig
.fnInit
!== null )
1938 oConfig
.fnInit
.call( this, nButton
, oConfig
);
1941 flash
.setHandCursor( true );
1943 if ( oConfig
.sAction
== "flash_save" )
1945 flash
.setAction( 'save' );
1946 flash
.setCharSet( (oConfig
.sCharSet
=="utf16le") ? 'UTF16LE' : 'UTF8' );
1947 flash
.setBomInc( oConfig
.bBomInc
);
1948 flash
.setFileName( oConfig
.sFileName
.replace('*', this.fnGetTitle(oConfig
)) );
1950 else if ( oConfig
.sAction
== "flash_pdf" )
1952 flash
.setAction( 'pdf' );
1953 flash
.setFileName( oConfig
.sFileName
.replace('*', this.fnGetTitle(oConfig
)) );
1957 flash
.setAction( 'copy' );
1960 flash
.addEventListener('mouseOver', function(client
) {
1961 if ( oConfig
.fnMouseover
!== null )
1963 oConfig
.fnMouseover
.call( that
, nButton
, oConfig
, flash
);
1967 flash
.addEventListener('mouseOut', function(client
) {
1968 if ( oConfig
.fnMouseout
!== null )
1970 oConfig
.fnMouseout
.call( that
, nButton
, oConfig
, flash
);
1974 flash
.addEventListener('mouseDown', function(client
) {
1975 if ( oConfig
.fnClick
!== null )
1977 oConfig
.fnClick
.call( that
, nButton
, oConfig
, flash
);
1981 flash
.addEventListener('complete', function (client
, text
) {
1982 if ( oConfig
.fnComplete
!== null )
1984 oConfig
.fnComplete
.call( that
, nButton
, oConfig
, flash
, text
);
1986 that
._fnCollectionHide( nButton
, oConfig
);
1989 if ( oConfig
.fnSelect
!== null )
1991 TableTools
._fnEventListen( this, 'select', function (n
) {
1992 oConfig
.fnSelect
.call( that
, nButton
, oConfig
, n
);
1996 this._fnFlashGlue( flash
, nButton
, oConfig
.sToolTip
);
2001 * Wait until the id is in the DOM before we "glue" the swf. Note that this function will call
2002 * itself (using setTimeout) until it completes successfully
2003 * @method _fnFlashGlue
2004 * @param {Object} clip Zero clipboard object
2005 * @param {Node} node node to glue swf to
2006 * @param {String} text title of the flash movie
2010 "_fnFlashGlue": function ( flash
, node
, text
)
2013 var id
= node
.getAttribute('id');
2015 if ( document
.getElementById(id
) )
2017 flash
.glue( node
, text
);
2021 setTimeout( function () {
2022 that
._fnFlashGlue( flash
, node
, text
);
2029 * Set the text for the flash clip to deal with
2031 * This function is required for large information sets. There is a limit on the
2032 * amount of data that can be transferred between Javascript and Flash in a single call, so
2033 * we use this method to build up the text in Flash by sending over chunks. It is estimated
2034 * that the data limit is around 64k, although it is undocumented, and appears to be different
2035 * between different flash versions. We chunk at 8KiB.
2036 * @method _fnFlashSetText
2037 * @param {Object} clip the ZeroClipboard object
2038 * @param {String} sData the data to be set
2042 "_fnFlashSetText": function ( clip
, sData
)
2044 var asData
= this._fnChunkData( sData
, 8192 );
2047 for ( var i
=0, iLen
=asData
.length
; i
<iLen
; i
++ )
2049 clip
.appendText( asData
[i
] );
2055 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2056 * Data retrieval functions
2060 * Convert the mixed columns variable into a boolean array the same size as the columns, which
2061 * indicates which columns we want to include
2062 * @method _fnColumnTargets
2063 * @param {String|Array} mColumns The columns to be included in data retrieval. If a string
2064 * then it can take the value of "visible" or "hidden" (to include all visible or
2065 * hidden columns respectively). Or an array of column indexes
2066 * @returns {Array} A boolean array the length of the columns of the table, which each value
2067 * indicating if the column is to be included or not
2070 "_fnColumnTargets": function ( mColumns
)
2075 var columns
= dt
.aoColumns
;
2076 var columnCount
= columns
.length
;
2078 if ( typeof mColumns
== "function" )
2080 var a
= mColumns
.call( this, dt
);
2082 for ( i
=0, iLen
=columnCount
; i
<iLen
; i
++ )
2084 aColumns
.push( $.inArray( i
, a
) !== -1 ? true : false );
2087 else if ( typeof mColumns
== "object" )
2089 for ( i
=0, iLen
=columnCount
; i
<iLen
; i
++ )
2091 aColumns
.push( false );
2094 for ( i
=0, iLen
=mColumns
.length
; i
<iLen
; i
++ )
2096 aColumns
[ mColumns
[i
] ] = true;
2099 else if ( mColumns
== "visible" )
2101 for ( i
=0, iLen
=columnCount
; i
<iLen
; i
++ )
2103 aColumns
.push( columns
[i
].bVisible
? true : false );
2106 else if ( mColumns
== "hidden" )
2108 for ( i
=0, iLen
=columnCount
; i
<iLen
; i
++ )
2110 aColumns
.push( columns
[i
].bVisible
? false : true );
2113 else if ( mColumns
== "sortable" )
2115 for ( i
=0, iLen
=columnCount
; i
<iLen
; i
++ )
2117 aColumns
.push( columns
[i
].bSortable
? true : false );
2122 for ( i
=0, iLen
=columnCount
; i
<iLen
; i
++ )
2124 aColumns
.push( true );
2133 * New line character(s) depend on the platforms
2135 * @param {Object} oConfig Button configuration object - only interested in oConfig.sNewLine
2136 * @returns {String} Newline character
2138 "_fnNewline": function ( oConfig
)
2140 if ( oConfig
.sNewLine
== "auto" )
2142 return navigator
.userAgent
.match(/Windows/) ? "\r\n" : "\n";
2146 return oConfig
.sNewLine
;
2152 * Get data from DataTables' internals and format it for output
2153 * @method _fnGetDataTablesData
2154 * @param {Object} oConfig Button configuration object
2155 * @param {String} oConfig.sFieldBoundary Field boundary for the data cells in the string
2156 * @param {String} oConfig.sFieldSeperator Field separator for the data cells
2157 * @param {String} oConfig.sNewline New line options
2158 * @param {Mixed} oConfig.mColumns Which columns should be included in the output
2159 * @param {Boolean} oConfig.bHeader Include the header
2160 * @param {Boolean} oConfig.bFooter Include the footer
2161 * @param {Boolean} oConfig.bSelectedOnly Include only the selected rows in the output
2162 * @returns {String} Concatenated string of data
2165 "_fnGetDataTablesData": function ( oConfig
)
2167 var i
, iLen
, j
, jLen
;
2168 var aRow
, aData
=[], sLoopData
='', arr
;
2169 var dt
= this.s
.dt
, tr
, child
;
2170 var regex
= new RegExp(oConfig
.sFieldBoundary
, "g"); /* Do it here for speed */
2171 var aColumnsInc
= this._fnColumnTargets( oConfig
.mColumns
);
2172 var bSelectedOnly
= (typeof oConfig
.bSelectedOnly
!= 'undefined') ? oConfig
.bSelectedOnly
: false;
2177 if ( oConfig
.bHeader
)
2181 for ( i
=0, iLen
=dt
.aoColumns
.length
; i
<iLen
; i
++ )
2183 if ( aColumnsInc
[i
] )
2185 sLoopData
= dt
.aoColumns
[i
].sTitle
.replace(/\n/g," ").replace( /<.*?>/g, "" ).replace(/^\s+|\s+$/g,"");
2186 sLoopData
= this._fnHtmlDecode( sLoopData
);
2188 aRow
.push( this._fnBoundData( sLoopData
, oConfig
.sFieldBoundary
, regex
) );
2192 aData
.push( aRow
.join(oConfig
.sFieldSeperator
) );
2195 bSelectedOnly
= true;
2201 var aSelected
= this.fnGetSelectedIndexes();
2202 bSelectedOnly
= this.s
.select
.type
!== "none" && bSelectedOnly
&& aSelected
.length
!== 0;
2204 if ( bSelectedOnly
) {
2205 // Use the selected indexes
2206 aDataIndex
= aSelected
;
2208 else if ( DataTable
.Api
) {
2210 aDataIndex
= new DataTable
.Api( dt
)
2211 .rows( oConfig
.oSelectorOpts
)
2218 aDataIndex
= dt
.oInstance
2219 .$('tr', oConfig
.oSelectorOpts
)
2220 .map( function (id
, row
) {
2221 return dt
.oInstance
.fnGetPosition( row
);
2226 for ( j
=0, jLen
=aDataIndex
.length
; j
<jLen
; j
++ )
2228 tr
= dt
.aoData
[ aDataIndex
[j
] ].nTr
;
2232 for ( i
=0, iLen
=dt
.aoColumns
.length
; i
<iLen
; i
++ )
2234 if ( aColumnsInc
[i
] )
2236 /* Convert to strings (with small optimisation) */
2237 var mTypeData
= dt
.oApi
._fnGetCellData( dt
, aDataIndex
[j
], i
, 'display' );
2238 if ( oConfig
.fnCellRender
)
2240 sLoopData
= oConfig
.fnCellRender( mTypeData
, i
, tr
, aDataIndex
[j
] )+"";
2242 else if ( typeof mTypeData
== "string" )
2244 /* Strip newlines, replace img tags with alt attr. and finally strip html... */
2245 sLoopData
= mTypeData
.replace(/\n/g," ");
2247 sLoopData
.replace(/<img.*?\s+alt\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s>]+)).*?>/gi,
2249 sLoopData
= sLoopData
.replace( /<.*?>/g, "" );
2253 sLoopData
= mTypeData
+"";
2256 /* Trim and clean the data */
2257 sLoopData
= sLoopData
.replace(/^\s+/, '').replace(/\s+$/, '');
2258 sLoopData
= this._fnHtmlDecode( sLoopData
);
2260 /* Bound it and add it to the total data */
2261 aRow
.push( this._fnBoundData( sLoopData
, oConfig
.sFieldBoundary
, regex
) );
2265 aData
.push( aRow
.join(oConfig
.sFieldSeperator
) );
2267 /* Details rows from fnOpen */
2268 if ( oConfig
.bOpenRows
)
2270 arr
= $.grep(dt
.aoOpenRows
, function(o
) { return o
.nParent
=== tr
; });
2272 if ( arr
.length
=== 1 )
2274 sLoopData
= this._fnBoundData( $('td', arr
[0].nTr
).html(), oConfig
.sFieldBoundary
, regex
);
2275 aData
.push( sLoopData
);
2283 if ( oConfig
.bFooter
&& dt
.nTFoot
!== null )
2287 for ( i
=0, iLen
=dt
.aoColumns
.length
; i
<iLen
; i
++ )
2289 if ( aColumnsInc
[i
] && dt
.aoColumns
[i
].nTf
!== null )
2291 sLoopData
= dt
.aoColumns
[i
].nTf
.innerHTML
.replace(/\n/g," ").replace( /<.*?>/g, "" );
2292 sLoopData
= this._fnHtmlDecode( sLoopData
);
2294 aRow
.push( this._fnBoundData( sLoopData
, oConfig
.sFieldBoundary
, regex
) );
2298 aData
.push( aRow
.join(oConfig
.sFieldSeperator
) );
2301 var _sLastData
= aData
.join( this._fnNewline(oConfig
) );
2307 * Wrap data up with a boundary string
2308 * @method _fnBoundData
2309 * @param {String} sData data to bound
2310 * @param {String} sBoundary bounding char(s)
2311 * @param {RegExp} regex search for the bounding chars - constructed outside for efficiency
2313 * @returns {String} bound data
2316 "_fnBoundData": function ( sData
, sBoundary
, regex
)
2318 if ( sBoundary
=== "" )
2324 return sBoundary
+ sData
.replace(regex
, sBoundary
+sBoundary
) + sBoundary
;
2330 * Break a string up into an array of smaller strings
2331 * @method _fnChunkData
2332 * @param {String} sData data to be broken up
2333 * @param {Int} iSize chunk size
2334 * @returns {Array} String array of broken up text
2337 "_fnChunkData": function ( sData
, iSize
)
2340 var iStrlen
= sData
.length
;
2342 for ( var i
=0 ; i
<iStrlen
; i
+=iSize
)
2344 if ( i
+iSize
< iStrlen
)
2346 asReturn
.push( sData
.substring( i
, i
+iSize
) );
2350 asReturn
.push( sData
.substring( i
, iStrlen
) );
2359 * Decode HTML entities
2360 * @method _fnHtmlDecode
2361 * @param {String} sData encoded string
2362 * @returns {String} decoded string
2365 "_fnHtmlDecode": function ( sData
)
2367 if ( sData
.indexOf('&') === -1 )
2372 var n
= document
.createElement('div');
2374 return sData
.replace( /&([^\s]*?);/g, function( match
, match2
) {
2375 if ( match
.substr(1, 1) === '#' )
2377 return String
.fromCharCode( Number(match2
.substr(1)) );
2381 n
.innerHTML
= match
;
2382 return n
.childNodes
[0].nodeValue
;
2389 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2390 * Printing functions
2394 * Show print display
2395 * @method _fnPrintStart
2396 * @param {Event} e Event object
2397 * @param {Object} oConfig Button configuration object
2401 "_fnPrintStart": function ( oConfig
)
2404 var oSetDT
= this.s
.dt
;
2406 /* Parse through the DOM hiding everything that isn't needed for the table */
2407 this._fnPrintHideNodes( oSetDT
.nTable
);
2409 /* Show the whole table */
2410 this.s
.print
.saveStart
= oSetDT
._iDisplayStart
;
2411 this.s
.print
.saveLength
= oSetDT
._iDisplayLength
;
2413 if ( oConfig
.bShowAll
)
2415 oSetDT
._iDisplayStart
= 0;
2416 oSetDT
._iDisplayLength
= -1;
2417 if ( oSetDT
.oApi
._fnCalculateEnd
) {
2418 oSetDT
.oApi
._fnCalculateEnd( oSetDT
);
2420 oSetDT
.oApi
._fnDraw( oSetDT
);
2423 /* Adjust the display for scrolling which might be done by DataTables */
2424 if ( oSetDT
.oScroll
.sX
!== "" || oSetDT
.oScroll
.sY
!== "" )
2426 this._fnPrintScrollStart( oSetDT
);
2428 // If the table redraws while in print view, the DataTables scrolling
2429 // setup would hide the header, so we need to readd it on draw
2430 $(this.s
.dt
.nTable
).bind('draw.DTTT_Print', function () {
2431 that
._fnPrintScrollStart( oSetDT
);
2435 /* Remove the other DataTables feature nodes - but leave the table! and info div */
2436 var anFeature
= oSetDT
.aanFeatures
;
2437 for ( var cFeature
in anFeature
)
2439 if ( cFeature
!= 'i' && cFeature
!= 't' && cFeature
.length
== 1 )
2441 for ( var i
=0, iLen
=anFeature
[cFeature
].length
; i
<iLen
; i
++ )
2443 this.dom
.print
.hidden
.push( {
2444 "node": anFeature
[cFeature
][i
],
2447 anFeature
[cFeature
][i
].style
.display
= "none";
2452 /* Print class can be used for styling */
2453 $(document
.body
).addClass( this.classes
.print
.body
);
2455 /* Show information message to let the user know what is happening */
2456 if ( oConfig
.sInfo
!== "" )
2458 this.fnInfo( oConfig
.sInfo
, 3000 );
2461 /* Add a message at the top of the page */
2462 if ( oConfig
.sMessage
)
2465 .addClass( this.classes
.print
.message
)
2466 .html( oConfig
.sMessage
)
2467 .prependTo( 'body' );
2470 /* Cache the scrolling and the jump to the top of the page */
2471 this.s
.print
.saveScroll
= $(window
).scrollTop();
2472 window
.scrollTo( 0, 0 );
2474 /* Bind a key event listener to the document for the escape key -
2475 * it is removed in the callback
2477 $(document
).bind( "keydown.DTTT", function(e
) {
2478 /* Only interested in the escape key */
2479 if ( e
.keyCode
== 27 )
2482 that
._fnPrintEnd
.call( that
, e
);
2489 * Printing is finished, resume normal display
2490 * @method _fnPrintEnd
2491 * @param {Event} e Event object
2495 "_fnPrintEnd": function ( e
)
2498 var oSetDT
= this.s
.dt
;
2499 var oSetPrint
= this.s
.print
;
2500 var oDomPrint
= this.dom
.print
;
2502 /* Show all hidden nodes */
2503 this._fnPrintShowNodes();
2505 /* Restore DataTables' scrolling */
2506 if ( oSetDT
.oScroll
.sX
!== "" || oSetDT
.oScroll
.sY
!== "" )
2508 $(this.s
.dt
.nTable
).unbind('draw.DTTT_Print');
2510 this._fnPrintScrollEnd();
2513 /* Restore the scroll */
2514 window
.scrollTo( 0, oSetPrint
.saveScroll
);
2516 /* Drop the print message */
2517 $('div.'+this.classes
.print
.message
).remove();
2520 $(document
.body
).removeClass( 'DTTT_Print' );
2522 /* Restore the table length */
2523 oSetDT
._iDisplayStart
= oSetPrint
.saveStart
;
2524 oSetDT
._iDisplayLength
= oSetPrint
.saveLength
;
2525 if ( oSetDT
.oApi
._fnCalculateEnd
) {
2526 oSetDT
.oApi
._fnCalculateEnd( oSetDT
);
2528 oSetDT
.oApi
._fnDraw( oSetDT
);
2530 $(document
).unbind( "keydown.DTTT" );
2535 * Take account of scrolling in DataTables by showing the full table
2539 "_fnPrintScrollStart": function ()
2543 nScrollHeadInner
= oSetDT
.nScrollHead
.getElementsByTagName('div')[0],
2544 nScrollHeadTable
= nScrollHeadInner
.getElementsByTagName('table')[0],
2545 nScrollBody
= oSetDT
.nTable
.parentNode
,
2546 nTheadSize
, nTfootSize
;
2548 /* Copy the header in the thead in the body table, this way we show one single table when
2549 * in print view. Note that this section of code is more or less verbatim from DT 1.7.0
2551 nTheadSize
= oSetDT
.nTable
.getElementsByTagName('thead');
2552 if ( nTheadSize
.length
> 0 )
2554 oSetDT
.nTable
.removeChild( nTheadSize
[0] );
2557 if ( oSetDT
.nTFoot
!== null )
2559 nTfootSize
= oSetDT
.nTable
.getElementsByTagName('tfoot');
2560 if ( nTfootSize
.length
> 0 )
2562 oSetDT
.nTable
.removeChild( nTfootSize
[0] );
2566 nTheadSize
= oSetDT
.nTHead
.cloneNode(true);
2567 oSetDT
.nTable
.insertBefore( nTheadSize
, oSetDT
.nTable
.childNodes
[0] );
2569 if ( oSetDT
.nTFoot
!== null )
2571 nTfootSize
= oSetDT
.nTFoot
.cloneNode(true);
2572 oSetDT
.nTable
.insertBefore( nTfootSize
, oSetDT
.nTable
.childNodes
[1] );
2575 /* Now adjust the table's viewport so we can actually see it */
2576 if ( oSetDT
.oScroll
.sX
!== "" )
2578 oSetDT
.nTable
.style
.width
= $(oSetDT
.nTable
).outerWidth()+"px";
2579 nScrollBody
.style
.width
= $(oSetDT
.nTable
).outerWidth()+"px";
2580 nScrollBody
.style
.overflow
= "visible";
2583 if ( oSetDT
.oScroll
.sY
!== "" )
2585 nScrollBody
.style
.height
= $(oSetDT
.nTable
).outerHeight()+"px";
2586 nScrollBody
.style
.overflow
= "visible";
2592 * Take account of scrolling in DataTables by showing the full table. Note that the redraw of
2593 * the DataTable that we do will actually deal with the majority of the hard work here
2597 "_fnPrintScrollEnd": function ()
2601 nScrollBody
= oSetDT
.nTable
.parentNode
;
2603 if ( oSetDT
.oScroll
.sX
!== "" )
2605 nScrollBody
.style
.width
= oSetDT
.oApi
._fnStringToCss( oSetDT
.oScroll
.sX
);
2606 nScrollBody
.style
.overflow
= "auto";
2609 if ( oSetDT
.oScroll
.sY
!== "" )
2611 nScrollBody
.style
.height
= oSetDT
.oApi
._fnStringToCss( oSetDT
.oScroll
.sY
);
2612 nScrollBody
.style
.overflow
= "auto";
2618 * Resume the display of all TableTools hidden nodes
2619 * @method _fnPrintShowNodes
2623 "_fnPrintShowNodes": function ( )
2625 var anHidden
= this.dom
.print
.hidden
;
2627 for ( var i
=0, iLen
=anHidden
.length
; i
<iLen
; i
++ )
2629 anHidden
[i
].node
.style
.display
= anHidden
[i
].display
;
2631 anHidden
.splice( 0, anHidden
.length
);
2636 * Hide nodes which are not needed in order to display the table. Note that this function is
2638 * @method _fnPrintHideNodes
2639 * @param {Node} nNode Element which should be showing in a 'print' display
2643 "_fnPrintHideNodes": function ( nNode
)
2645 var anHidden
= this.dom
.print
.hidden
;
2647 var nParent
= nNode
.parentNode
;
2648 var nChildren
= nParent
.childNodes
;
2649 for ( var i
=0, iLen
=nChildren
.length
; i
<iLen
; i
++ )
2651 if ( nChildren
[i
] != nNode
&& nChildren
[i
].nodeType
== 1 )
2653 /* If our node is shown (don't want to show nodes which were previously hidden) */
2654 var sDisplay
= $(nChildren
[i
]).css("display");
2655 if ( sDisplay
!= "none" )
2657 /* Cache the node and it's previous state so we can restore it */
2659 "node": nChildren
[i
],
2662 nChildren
[i
].style
.display
= "none";
2667 if ( nParent
.nodeName
.toUpperCase() != "BODY" )
2669 this._fnPrintHideNodes( nParent
);
2676 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2678 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2681 * Store of all instances that have been created of TableTools, so one can look up other (when
2682 * there is need of a master)
2683 * @property _aInstances
2688 TableTools
._aInstances
= [];
2692 * Store of all listeners and their callback functions
2693 * @property _aListeners
2697 TableTools
._aListeners
= [];
2701 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2703 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2706 * Get an array of all the master instances
2707 * @method fnGetMasters
2708 * @returns {Array} List of master TableTools instances
2711 TableTools
.fnGetMasters = function ()
2714 for ( var i
=0, iLen
=TableTools
._aInstances
.length
; i
<iLen
; i
++ )
2716 if ( TableTools
._aInstances
[i
].s
.master
)
2718 a
.push( TableTools
._aInstances
[i
] );
2725 * Get the master instance for a table node (or id if a string is given)
2726 * @method fnGetInstance
2727 * @returns {Object} ID of table OR table node, for which we want the TableTools instance
2730 TableTools
.fnGetInstance = function ( node
)
2732 if ( typeof node
!= 'object' )
2734 node
= document
.getElementById(node
);
2737 for ( var i
=0, iLen
=TableTools
._aInstances
.length
; i
<iLen
; i
++ )
2739 if ( TableTools
._aInstances
[i
].s
.master
&& TableTools
._aInstances
[i
].dom
.table
== node
)
2741 return TableTools
._aInstances
[i
];
2749 * Add a listener for a specific event
2750 * @method _fnEventListen
2751 * @param {Object} that Scope of the listening function (i.e. 'this' in the caller)
2752 * @param {String} type Event type
2753 * @param {Function} fn Function
2758 TableTools
._fnEventListen = function ( that
, type
, fn
)
2760 TableTools
._aListeners
.push( {
2769 * An event has occurred - look up every listener and fire it off. We check that the event we are
2770 * going to fire is attached to the same table (using the table node as reference) before firing
2771 * @method _fnEventDispatch
2772 * @param {Object} that Scope of the listening function (i.e. 'this' in the caller)
2773 * @param {String} type Event type
2774 * @param {Node} node Element that the event occurred on (may be null)
2775 * @param {boolean} [selected] Indicate if the node was selected (true) or deselected (false)
2780 TableTools
._fnEventDispatch = function ( that
, type
, node
, selected
)
2782 var listeners
= TableTools
._aListeners
;
2783 for ( var i
=0, iLen
=listeners
.length
; i
<iLen
; i
++ )
2785 if ( that
.dom
.table
== listeners
[i
].that
.dom
.table
&& listeners
[i
].type
== type
)
2787 listeners
[i
].fn( node
, selected
);
2797 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2799 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2803 TableTools
.buttonBase
= {
2807 "sLinerTag": "default",
2808 "sButtonClass": "DTTT_button_text",
2809 "sButtonText": "Button text",
2813 // Common button specific options
2816 "sFileName": "*.csv",
2817 "sFieldBoundary": "",
2818 "sFieldSeperator": "\t",
2820 "mColumns": "all", /* "all", "visible", "hidden" or array of column integers */
2824 "bSelectedOnly": false,
2825 "oSelectorOpts": undefined, // See http://datatables.net/docs/DataTables/1.9.4/#$ for full options
2828 "fnMouseover": null,
2834 "fnCellRender": null
2839 * @namespace Default button configurations
2841 TableTools
.BUTTONS
= {
2842 "csv": $.extend( {}, TableTools
.buttonBase
, {
2843 "sAction": "flash_save",
2844 "sButtonClass": "DTTT_button_csv",
2845 "sButtonText": "CSV",
2846 "sFieldBoundary": '"',
2847 "sFieldSeperator": ",",
2848 "fnClick": function( nButton
, oConfig
, flash
) {
2849 this.fnSetText( flash
, this.fnGetTableData(oConfig
) );
2853 "xls": $.extend( {}, TableTools
.buttonBase
, {
2854 "sAction": "flash_save",
2855 "sCharSet": "utf16le",
2857 "sButtonClass": "DTTT_button_xls",
2858 "sButtonText": "Excel",
2859 "fnClick": function( nButton
, oConfig
, flash
) {
2860 this.fnSetText( flash
, this.fnGetTableData(oConfig
) );
2864 "copy": $.extend( {}, TableTools
.buttonBase
, {
2865 "sAction": "flash_copy",
2866 "sButtonClass": "DTTT_button_copy",
2867 "sButtonText": "Copy",
2868 "fnClick": function( nButton
, oConfig
, flash
) {
2869 this.fnSetText( flash
, this.fnGetTableData(oConfig
) );
2871 "fnComplete": function(nButton
, oConfig
, flash
, text
) {
2872 var lines
= text
.split('\n').length
;
2873 if (oConfig
.bHeader
) lines
--;
2874 if (this.s
.dt
.nTFoot
!== null && oConfig
.bFooter
) lines
--;
2875 var plural
= (lines
==1) ? "" : "s";
2876 this.fnInfo( '<h6>Table copied</h6>'+
2877 '<p>Copied '+lines
+' row'+plural
+' to the clipboard.</p>',
2883 "pdf": $.extend( {}, TableTools
.buttonBase
, {
2884 "sAction": "flash_pdf",
2886 "sFileName": "*.pdf",
2887 "sButtonClass": "DTTT_button_pdf",
2888 "sButtonText": "PDF",
2889 "sPdfOrientation": "portrait",
2892 "fnClick": function( nButton
, oConfig
, flash
) {
2893 this.fnSetText( flash
,
2894 "title:"+ this.fnGetTitle(oConfig
) +"\n"+
2895 "message:"+ oConfig
.sPdfMessage
+"\n"+
2896 "colWidth:"+ this.fnCalcColRatios(oConfig
) +"\n"+
2897 "orientation:"+ oConfig
.sPdfOrientation
+"\n"+
2898 "size:"+ oConfig
.sPdfSize
+"\n"+
2899 "--/TableToolsOpts--\n" +
2900 this.fnGetTableData(oConfig
)
2905 "print": $.extend( {}, TableTools
.buttonBase
, {
2906 "sInfo": "<h6>Print view</h6><p>Please use your browser's print function to "+
2907 "print this table. Press escape when finished.</p>",
2910 "sToolTip": "View print view",
2911 "sButtonClass": "DTTT_button_print",
2912 "sButtonText": "Print",
2913 "fnClick": function ( nButton
, oConfig
) {
2914 this.fnPrint( true, oConfig
);
2918 "text": $.extend( {}, TableTools
.buttonBase
),
2920 "select": $.extend( {}, TableTools
.buttonBase
, {
2921 "sButtonText": "Select button",
2922 "fnSelect": function( nButton
, oConfig
) {
2923 if ( this.fnGetSelected().length
!== 0 ) {
2924 $(nButton
).removeClass( this.classes
.buttons
.disabled
);
2926 $(nButton
).addClass( this.classes
.buttons
.disabled
);
2929 "fnInit": function( nButton
, oConfig
) {
2930 $(nButton
).addClass( this.classes
.buttons
.disabled
);
2934 "select_single": $.extend( {}, TableTools
.buttonBase
, {
2935 "sButtonText": "Select button",
2936 "fnSelect": function( nButton
, oConfig
) {
2937 var iSelected
= this.fnGetSelected().length
;
2938 if ( iSelected
== 1 ) {
2939 $(nButton
).removeClass( this.classes
.buttons
.disabled
);
2941 $(nButton
).addClass( this.classes
.buttons
.disabled
);
2944 "fnInit": function( nButton
, oConfig
) {
2945 $(nButton
).addClass( this.classes
.buttons
.disabled
);
2949 "select_all": $.extend( {}, TableTools
.buttonBase
, {
2950 "sButtonText": "Select all",
2951 "fnClick": function( nButton
, oConfig
) {
2954 "fnSelect": function( nButton
, oConfig
) {
2955 if ( this.fnGetSelected().length
== this.s
.dt
.fnRecordsDisplay() ) {
2956 $(nButton
).addClass( this.classes
.buttons
.disabled
);
2958 $(nButton
).removeClass( this.classes
.buttons
.disabled
);
2963 "select_none": $.extend( {}, TableTools
.buttonBase
, {
2964 "sButtonText": "Deselect all",
2965 "fnClick": function( nButton
, oConfig
) {
2966 this.fnSelectNone();
2968 "fnSelect": function( nButton
, oConfig
) {
2969 if ( this.fnGetSelected().length
!== 0 ) {
2970 $(nButton
).removeClass( this.classes
.buttons
.disabled
);
2972 $(nButton
).addClass( this.classes
.buttons
.disabled
);
2975 "fnInit": function( nButton
, oConfig
) {
2976 $(nButton
).addClass( this.classes
.buttons
.disabled
);
2980 "ajax": $.extend( {}, TableTools
.buttonBase
, {
2981 "sAjaxUrl": "/xhr.php",
2982 "sButtonText": "Ajax button",
2983 "fnClick": function( nButton
, oConfig
) {
2984 var sData
= this.fnGetTableData(oConfig
);
2986 "url": oConfig
.sAjaxUrl
,
2988 { "name": "tableData", "value": sData
}
2990 "success": oConfig
.fnAjaxComplete
,
2994 "error": function () {
2995 alert( "Error detected when sending table data to server" );
2999 "fnAjaxComplete": function( json
) {
3000 alert( 'Ajax complete' );
3004 "div": $.extend( {}, TableTools
.buttonBase
, {
3007 "sButtonClass": "DTTT_nonbutton",
3008 "sButtonText": "Text button"
3011 "collection": $.extend( {}, TableTools
.buttonBase
, {
3012 "sAction": "collection",
3013 "sButtonClass": "DTTT_button_collection",
3014 "sButtonText": "Collection",
3015 "fnClick": function( nButton
, oConfig
) {
3016 this._fnCollectionShow(nButton
, oConfig
);
3021 * on* callback parameters:
3022 * 1. node - button element
3023 * 2. object - configuration object for this button
3024 * 3. object - ZeroClipboard reference (flash button only)
3025 * 4. string - Returned string from Flash (flash button only - and only on 'complete')
3028 // Alias to match the other plug-ins styling
3029 TableTools
.buttons
= TableTools
.BUTTONS
;
3033 * @namespace Classes used by TableTools - allows the styles to be override easily.
3034 * Note that when TableTools initialises it will take a copy of the classes object
3035 * and will use its internal copy for the remainder of its run time.
3037 TableTools
.classes
= {
3038 "container": "DTTT_container",
3040 "normal": "DTTT_button",
3041 "disabled": "DTTT_disabled"
3044 "container": "DTTT_collection",
3045 "background": "DTTT_collection_background",
3047 "normal": "DTTT_button",
3048 "disabled": "DTTT_disabled"
3052 "table": "DTTT_selectable",
3053 "row": "DTTT_selected selected"
3056 "body": "DTTT_Print",
3057 "info": "DTTT_print_info",
3058 "message": "DTTT_PrintMessage"
3064 * @namespace ThemeRoller classes - built in for compatibility with DataTables'
3067 TableTools
.classes_themeroller
= {
3068 "container": "DTTT_container ui-buttonset ui-buttonset-multi",
3070 "normal": "DTTT_button ui-button ui-state-default"
3073 "container": "DTTT_collection ui-buttonset ui-buttonset-multi"
3079 * @namespace TableTools default settings for initialisation
3081 TableTools
.DEFAULTS
= {
3082 "sSwfPath": "../swf/copy_csv_xls_pdf.swf",
3083 "sRowSelect": "none",
3084 "sRowSelector": "tr",
3085 "sSelectedClass": null,
3086 "fnPreRowSelect": null,
3087 "fnRowSelected": null,
3088 "fnRowDeselected": null,
3089 "aButtons": [ "copy", "csv", "xls", "pdf", "print" ],
3092 "button": "a", // We really want to use buttons here, but Firefox and IE ignore the
3093 // click on the Flash element in the button (but not mouse[in|out]).
3103 // Alias to match the other plug-ins
3104 TableTools
.defaults
= TableTools
.DEFAULTS
;
3108 * Name of this class
3111 * @default TableTools
3113 TableTools
.prototype.CLASS
= "TableTools";
3117 * TableTools version
3122 TableTools
.version
= "2.2.4";
3126 // DataTables 1.10 API
3128 // This will be extended in a big way in in TableTools 3 to provide API methods
3129 // such as rows().select() and rows.selected() etc, but for the moment the
3130 // tabletools() method simply returns the instance.
3132 if ( $.fn
.dataTable
.Api
) {
3133 $.fn
.dataTable
.Api
.register( 'tabletools()', function () {
3136 if ( this.context
.length
> 0 ) {
3137 tt
= TableTools
.fnGetInstance( this.context
[0].nTable
);
3147 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3149 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
3152 * Register a new feature with DataTables
3154 if ( typeof $.fn
.dataTable
== "function" &&
3155 typeof $.fn
.dataTableExt
.fnVersionCheck
== "function" &&
3156 $.fn
.dataTableExt
.fnVersionCheck('1.9.0') )
3158 $.fn
.dataTableExt
.aoFeatures
.push( {
3159 "fnInit": function( oDTSettings
) {
3160 var init
= oDTSettings
.oInit
;
3162 init
.tableTools
|| init
.oTableTools
|| {} :
3165 return new TableTools( oDTSettings
.oInstance
, opts
).dom
.container
;
3168 "sFeature": "TableTools"
3173 alert( "Warning: TableTools requires DataTables 1.9.0 or newer - www.datatables.net/download");
3176 $.fn
.DataTable
.TableTools
= TableTools
;
3178 })(jQuery
, window
, document
);
3181 * Register a new feature with DataTables
3183 if ( typeof $.fn
.dataTable
== "function" &&
3184 typeof $.fn
.dataTableExt
.fnVersionCheck
== "function" &&
3185 $.fn
.dataTableExt
.fnVersionCheck('1.9.0') )
3187 $.fn
.dataTableExt
.aoFeatures
.push( {
3188 "fnInit": function( oDTSettings
) {
3189 var oOpts
= typeof oDTSettings
.oInit
.oTableTools
!= 'undefined' ?
3190 oDTSettings
.oInit
.oTableTools
: {};
3192 var oTT
= new TableTools( oDTSettings
.oInstance
, oOpts
);
3193 TableTools
._aInstances
.push( oTT
);
3195 return oTT
.dom
.container
;
3198 "sFeature": "TableTools"
3203 alert( "Warning: TableTools 2 requires DataTables 1.9.0 or newer - www.datatables.net/download");
3207 $.fn
.dataTable
.TableTools
= TableTools
;
3208 $.fn
.DataTable
.TableTools
= TableTools
;
3215 // Define as an AMD module if possible
3216 if ( typeof define
=== 'function' && define
.amd
) {
3217 define( ['jquery', 'datatables'], factory
);
3219 else if ( typeof exports
=== 'object' ) {
3221 factory( require('jquery'), require('datatables') );
3223 else if ( jQuery
&& !jQuery
.fn
.dataTable
.TableTools
) {
3224 // Otherwise simply initialise as normal, stopping multiple evaluation
3225 factory( jQuery
, jQuery
.fn
.dataTable
);
3229 })(window
, document
);