/[projects]/misc/horsensspejder-web/jquery/DataTables-1.9.4/extras/TableTools/media/js/TableTools.js
ViewVC logotype

Contents of /misc/horsensspejder-web/jquery/DataTables-1.9.4/extras/TableTools/media/js/TableTools.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2125 - (show annotations) (download) (as text)
Wed Mar 12 19:30:05 2014 UTC (10 years, 3 months ago) by torben
File MIME type: application/javascript
File size: 64139 byte(s)
initial import
1 /*
2 * File: TableTools.js
3 * Version: 2.1.4
4 * Description: Tools and buttons for DataTables
5 * Author: Allan Jardine (www.sprymedia.co.uk)
6 * Language: Javascript
7 * License: GPL v2 or BSD 3 point style
8 * Project: DataTables
9 *
10 * Copyright 2009-2012 Allan Jardine, all rights reserved.
11 *
12 * This source file is free software, under either the GPL v2 license or a
13 * BSD style license, available at:
14 * http://datatables.net/license_gpl2
15 * http://datatables.net/license_bsd
16 */
17
18 /* Global scope for TableTools */
19 var TableTools;
20
21 (function($, window, document) {
22
23 /**
24 * TableTools provides flexible buttons and other tools for a DataTables enhanced table
25 * @class TableTools
26 * @constructor
27 * @param {Object} oDT DataTables instance
28 * @param {Object} oOpts TableTools options
29 * @param {String} oOpts.sSwfPath ZeroClipboard SWF path
30 * @param {String} oOpts.sRowSelect Row selection options - 'none', 'single' or 'multi'
31 * @param {Function} oOpts.fnPreRowSelect Callback function just prior to row selection
32 * @param {Function} oOpts.fnRowSelected Callback function just after row selection
33 * @param {Function} oOpts.fnRowDeselected Callback function when row is deselected
34 * @param {Array} oOpts.aButtons List of buttons to be used
35 */
36 TableTools = function( oDT, oOpts )
37 {
38 /* Santiy check that we are a new instance */
39 if ( ! this instanceof TableTools )
40 {
41 alert( "Warning: TableTools must be initialised with the keyword 'new'" );
42 }
43
44
45 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
46 * Public class variables
47 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
48
49 /**
50 * @namespace Settings object which contains customisable information for TableTools instance
51 */
52 this.s = {
53 /**
54 * Store 'this' so the instance can be retrieved from the settings object
55 * @property that
56 * @type object
57 * @default this
58 */
59 "that": this,
60
61 /**
62 * DataTables settings objects
63 * @property dt
64 * @type object
65 * @default <i>From the oDT init option</i>
66 */
67 "dt": oDT.fnSettings(),
68
69 /**
70 * @namespace Print specific information
71 */
72 "print": {
73 /**
74 * DataTables draw 'start' point before the printing display was shown
75 * @property saveStart
76 * @type int
77 * @default -1
78 */
79 "saveStart": -1,
80
81 /**
82 * DataTables draw 'length' point before the printing display was shown
83 * @property saveLength
84 * @type int
85 * @default -1
86 */
87 "saveLength": -1,
88
89 /**
90 * Page scrolling point before the printing display was shown so it can be restored
91 * @property saveScroll
92 * @type int
93 * @default -1
94 */
95 "saveScroll": -1,
96
97 /**
98 * Wrapped function to end the print display (to maintain scope)
99 * @property funcEnd
100 * @type Function
101 * @default function () {}
102 */
103 "funcEnd": function () {}
104 },
105
106 /**
107 * A unique ID is assigned to each button in each instance
108 * @property buttonCounter
109 * @type int
110 * @default 0
111 */
112 "buttonCounter": 0,
113
114 /**
115 * @namespace Select rows specific information
116 */
117 "select": {
118 /**
119 * Select type - can be 'none', 'single' or 'multi'
120 * @property type
121 * @type string
122 * @default ""
123 */
124 "type": "",
125
126 /**
127 * Array of nodes which are currently selected
128 * @property selected
129 * @type array
130 * @default []
131 */
132 "selected": [],
133
134 /**
135 * Function to run before the selection can take place. Will cancel the select if the
136 * function returns false
137 * @property preRowSelect
138 * @type Function
139 * @default null
140 */
141 "preRowSelect": null,
142
143 /**
144 * Function to run when a row is selected
145 * @property postSelected
146 * @type Function
147 * @default null
148 */
149 "postSelected": null,
150
151 /**
152 * Function to run when a row is deselected
153 * @property postDeselected
154 * @type Function
155 * @default null
156 */
157 "postDeselected": null,
158
159 /**
160 * Indicate if all rows are selected (needed for server-side processing)
161 * @property all
162 * @type boolean
163 * @default false
164 */
165 "all": false,
166
167 /**
168 * Class name to add to selected TR nodes
169 * @property selectedClass
170 * @type String
171 * @default ""
172 */
173 "selectedClass": ""
174 },
175
176 /**
177 * Store of the user input customisation object
178 * @property custom
179 * @type object
180 * @default {}
181 */
182 "custom": {},
183
184 /**
185 * SWF movie path
186 * @property swfPath
187 * @type string
188 * @default ""
189 */
190 "swfPath": "",
191
192 /**
193 * Default button set
194 * @property buttonSet
195 * @type array
196 * @default []
197 */
198 "buttonSet": [],
199
200 /**
201 * When there is more than one TableTools instance for a DataTable, there must be a
202 * master which controls events (row selection etc)
203 * @property master
204 * @type boolean
205 * @default false
206 */
207 "master": false,
208
209 /**
210 * Tag names that are used for creating collections and buttons
211 * @namesapce
212 */
213 "tags": {}
214 };
215
216
217 /**
218 * @namespace Common and useful DOM elements for the class instance
219 */
220 this.dom = {
221 /**
222 * DIV element that is create and all TableTools buttons (and their children) put into
223 * @property container
224 * @type node
225 * @default null
226 */
227 "container": null,
228
229 /**
230 * The table node to which TableTools will be applied
231 * @property table
232 * @type node
233 * @default null
234 */
235 "table": null,
236
237 /**
238 * @namespace Nodes used for the print display
239 */
240 "print": {
241 /**
242 * Nodes which have been removed from the display by setting them to display none
243 * @property hidden
244 * @type array
245 * @default []
246 */
247 "hidden": [],
248
249 /**
250 * The information display saying telling the user about the print display
251 * @property message
252 * @type node
253 * @default null
254 */
255 "message": null
256 },
257
258 /**
259 * @namespace Nodes used for a collection display. This contains the currently used collection
260 */
261 "collection": {
262 /**
263 * The div wrapper containing the buttons in the collection (i.e. the menu)
264 * @property collection
265 * @type node
266 * @default null
267 */
268 "collection": null,
269
270 /**
271 * Background display to provide focus and capture events
272 * @property background
273 * @type node
274 * @default null
275 */
276 "background": null
277 }
278 };
279
280 /**
281 * @namespace Name space for the classes that this TableTools instance will use
282 * @extends TableTools.classes
283 */
284 this.classes = $.extend( true, {}, TableTools.classes );
285 if ( this.s.dt.bJUI )
286 {
287 $.extend( true, this.classes, TableTools.classes_themeroller );
288 }
289
290
291 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
292 * Public class methods
293 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
294
295 /**
296 * Retreieve the settings object from an instance
297 * @method fnSettings
298 * @returns {object} TableTools settings object
299 */
300 this.fnSettings = function () {
301 return this.s;
302 };
303
304
305 /* Constructor logic */
306 if ( typeof oOpts == 'undefined' )
307 {
308 oOpts = {};
309 }
310
311 this._fnConstruct( oOpts );
312
313 return this;
314 };
315
316
317
318 TableTools.prototype = {
319 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
320 * Public methods
321 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
322
323 /**
324 * Retreieve the settings object from an instance
325 * @returns {array} List of TR nodes which are currently selected
326 * @param {boolean} [filtered=false] Get only selected rows which are
327 * available given the filtering applied to the table. By default
328 * this is false - i.e. all rows, regardless of filtering are
329 selected.
330 */
331 "fnGetSelected": function ( filtered )
332 {
333 var
334 out = [],
335 data = this.s.dt.aoData,
336 displayed = this.s.dt.aiDisplay,
337 i, iLen;
338
339 if ( filtered )
340 {
341 // Only consider filtered rows
342 for ( i=0, iLen=displayed.length ; i<iLen ; i++ )
343 {
344 if ( data[ displayed[i] ]._DTTT_selected )
345 {
346 out.push( data[ displayed[i] ].nTr );
347 }
348 }
349 }
350 else
351 {
352 // Use all rows
353 for ( i=0, iLen=data.length ; i<iLen ; i++ )
354 {
355 if ( data[i]._DTTT_selected )
356 {
357 out.push( data[i].nTr );
358 }
359 }
360 }
361
362 return out;
363 },
364
365
366 /**
367 * Get the data source objects/arrays from DataTables for the selected rows (same as
368 * fnGetSelected followed by fnGetData on each row from the table)
369 * @returns {array} Data from the TR nodes which are currently selected
370 */
371 "fnGetSelectedData": function ()
372 {
373 var out = [];
374 var data=this.s.dt.aoData;
375 var i, iLen;
376
377 for ( i=0, iLen=data.length ; i<iLen ; i++ )
378 {
379 if ( data[i]._DTTT_selected )
380 {
381 out.push( this.s.dt.oInstance.fnGetData(i) );
382 }
383 }
384
385 return out;
386 },
387
388
389 /**
390 * Check to see if a current row is selected or not
391 * @param {Node} n TR node to check if it is currently selected or not
392 * @returns {Boolean} true if select, false otherwise
393 */
394 "fnIsSelected": function ( n )
395 {
396 var pos = this.s.dt.oInstance.fnGetPosition( n );
397 return (this.s.dt.aoData[pos]._DTTT_selected===true) ? true : false;
398 },
399
400
401 /**
402 * Select all rows in the table
403 * @param {boolean} [filtered=false] Select only rows which are available
404 * given the filtering applied to the table. By default this is false -
405 * i.e. all rows, regardless of filtering are selected.
406 */
407 "fnSelectAll": function ( filtered )
408 {
409 var s = this._fnGetMasterSettings();
410
411 this._fnRowSelect( (filtered === true) ?
412 s.dt.aiDisplay :
413 s.dt.aoData
414 );
415 },
416
417
418 /**
419 * Deselect all rows in the table
420 * @param {boolean} [filtered=false] Deselect only rows which are available
421 * given the filtering applied to the table. By default this is false -
422 * i.e. all rows, regardless of filtering are deselected.
423 */
424 "fnSelectNone": function ( filtered )
425 {
426 var s = this._fnGetMasterSettings();
427
428 this._fnRowDeselect( this.fnGetSelected(filtered) );
429 },
430
431
432 /**
433 * Select row(s)
434 * @param {node|object|array} n The row(s) to select. Can be a single DOM
435 * TR node, an array of TR nodes or a jQuery object.
436 */
437 "fnSelect": function ( n )
438 {
439 if ( this.s.select.type == "single" )
440 {
441 this.fnSelectNone();
442 this._fnRowSelect( n );
443 }
444 else if ( this.s.select.type == "multi" )
445 {
446 this._fnRowSelect( n );
447 }
448 },
449
450
451 /**
452 * Deselect row(s)
453 * @param {node|object|array} n The row(s) to deselect. Can be a single DOM
454 * TR node, an array of TR nodes or a jQuery object.
455 */
456 "fnDeselect": function ( n )
457 {
458 this._fnRowDeselect( n );
459 },
460
461
462 /**
463 * Get the title of the document - useful for file names. The title is retrieved from either
464 * the configuration object's 'title' parameter, or the HTML document title
465 * @param {Object} oConfig Button configuration object
466 * @returns {String} Button title
467 */
468 "fnGetTitle": function( oConfig )
469 {
470 var sTitle = "";
471 if ( typeof oConfig.sTitle != 'undefined' && oConfig.sTitle !== "" ) {
472 sTitle = oConfig.sTitle;
473 } else {
474 var anTitle = document.getElementsByTagName('title');
475 if ( anTitle.length > 0 )
476 {
477 sTitle = anTitle[0].innerHTML;
478 }
479 }
480
481 /* Strip characters which the OS will object to - checking for UTF8 support in the scripting
482 * engine
483 */
484 if ( "\u00A1".toString().length < 4 ) {
485 return sTitle.replace(/[^a-zA-Z0-9_\u00A1-\uFFFF\.,\-_ !\(\)]/g, "");
486 } else {
487 return sTitle.replace(/[^a-zA-Z0-9_\.,\-_ !\(\)]/g, "");
488 }
489 },
490
491
492 /**
493 * Calculate a unity array with the column width by proportion for a set of columns to be
494 * included for a button. This is particularly useful for PDF creation, where we can use the
495 * column widths calculated by the browser to size the columns in the PDF.
496 * @param {Object} oConfig Button configuration object
497 * @returns {Array} Unity array of column ratios
498 */
499 "fnCalcColRatios": function ( oConfig )
500 {
501 var
502 aoCols = this.s.dt.aoColumns,
503 aColumnsInc = this._fnColumnTargets( oConfig.mColumns ),
504 aColWidths = [],
505 iWidth = 0, iTotal = 0, i, iLen;
506
507 for ( i=0, iLen=aColumnsInc.length ; i<iLen ; i++ )
508 {
509 if ( aColumnsInc[i] )
510 {
511 iWidth = aoCols[i].nTh.offsetWidth;
512 iTotal += iWidth;
513 aColWidths.push( iWidth );
514 }
515 }
516
517 for ( i=0, iLen=aColWidths.length ; i<iLen ; i++ )
518 {
519 aColWidths[i] = aColWidths[i] / iTotal;
520 }
521
522 return aColWidths.join('\t');
523 },
524
525
526 /**
527 * Get the information contained in a table as a string
528 * @param {Object} oConfig Button configuration object
529 * @returns {String} Table data as a string
530 */
531 "fnGetTableData": function ( oConfig )
532 {
533 /* In future this could be used to get data from a plain HTML source as well as DataTables */
534 if ( this.s.dt )
535 {
536 return this._fnGetDataTablesData( oConfig );
537 }
538 },
539
540
541 /**
542 * Pass text to a flash button instance, which will be used on the button's click handler
543 * @param {Object} clip Flash button object
544 * @param {String} text Text to set
545 */
546 "fnSetText": function ( clip, text )
547 {
548 this._fnFlashSetText( clip, text );
549 },
550
551
552 /**
553 * Resize the flash elements of the buttons attached to this TableTools instance - this is
554 * useful for when initialising TableTools when it is hidden (display:none) since sizes can't
555 * be calculated at that time.
556 */
557 "fnResizeButtons": function ()
558 {
559 for ( var cli in ZeroClipboard_TableTools.clients )
560 {
561 if ( cli )
562 {
563 var client = ZeroClipboard_TableTools.clients[cli];
564 if ( typeof client.domElement != 'undefined' &&
565 client.domElement.parentNode )
566 {
567 client.positionElement();
568 }
569 }
570 }
571 },
572
573
574 /**
575 * Check to see if any of the ZeroClipboard client's attached need to be resized
576 */
577 "fnResizeRequired": function ()
578 {
579 for ( var cli in ZeroClipboard_TableTools.clients )
580 {
581 if ( cli )
582 {
583 var client = ZeroClipboard_TableTools.clients[cli];
584 if ( typeof client.domElement != 'undefined' &&
585 client.domElement.parentNode == this.dom.container &&
586 client.sized === false )
587 {
588 return true;
589 }
590 }
591 }
592 return false;
593 },
594
595
596 /**
597 * Programmatically enable or disable the print view
598 * @param {boolean} [bView=true] Show the print view if true or not given. If false, then
599 * terminate the print view and return to normal.
600 * @param {object} [oConfig={}] Configuration for the print view
601 * @param {boolean} [oConfig.bShowAll=false] Show all rows in the table if true
602 * @param {string} [oConfig.sInfo] Information message, displayed as an overlay to the
603 * user to let them know what the print view is.
604 * @param {string} [oConfig.sMessage] HTML string to show at the top of the document - will
605 * be included in the printed document.
606 */
607 "fnPrint": function ( bView, oConfig )
608 {
609 if ( oConfig === undefined )
610 {
611 oConfig = {};
612 }
613
614 if ( bView === undefined || bView )
615 {
616 this._fnPrintStart( oConfig );
617 }
618 else
619 {
620 this._fnPrintEnd();
621 }
622 },
623
624
625 /**
626 * Show a message to the end user which is nicely styled
627 * @param {string} message The HTML string to show to the user
628 * @param {int} time The duration the message is to be shown on screen for (mS)
629 */
630 "fnInfo": function ( message, time ) {
631 var nInfo = document.createElement( "div" );
632 nInfo.className = this.classes.print.info;
633 nInfo.innerHTML = message;
634
635 document.body.appendChild( nInfo );
636
637 setTimeout( function() {
638 $(nInfo).fadeOut( "normal", function() {
639 document.body.removeChild( nInfo );
640 } );
641 }, time );
642 },
643
644
645
646 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
647 * Private methods (they are of course public in JS, but recommended as private)
648 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
649
650 /**
651 * Constructor logic
652 * @method _fnConstruct
653 * @param {Object} oOpts Same as TableTools constructor
654 * @returns void
655 * @private
656 */
657 "_fnConstruct": function ( oOpts )
658 {
659 var that = this;
660
661 this._fnCustomiseSettings( oOpts );
662
663 /* Container element */
664 this.dom.container = document.createElement( this.s.tags.container );
665 this.dom.container.className = this.classes.container;
666
667 /* Row selection config */
668 if ( this.s.select.type != 'none' )
669 {
670 this._fnRowSelectConfig();
671 }
672
673 /* Buttons */
674 this._fnButtonDefinations( this.s.buttonSet, this.dom.container );
675
676 /* Destructor - need to wipe the DOM for IE's garbage collector */
677 this.s.dt.aoDestroyCallback.push( {
678 "sName": "TableTools",
679 "fn": function () {
680 that.dom.container.innerHTML = "";
681 }
682 } );
683 },
684
685
686 /**
687 * Take the user defined settings and the default settings and combine them.
688 * @method _fnCustomiseSettings
689 * @param {Object} oOpts Same as TableTools constructor
690 * @returns void
691 * @private
692 */
693 "_fnCustomiseSettings": function ( oOpts )
694 {
695 /* Is this the master control instance or not? */
696 if ( typeof this.s.dt._TableToolsInit == 'undefined' )
697 {
698 this.s.master = true;
699 this.s.dt._TableToolsInit = true;
700 }
701
702 /* We can use the table node from comparisons to group controls */
703 this.dom.table = this.s.dt.nTable;
704
705 /* Clone the defaults and then the user options */
706 this.s.custom = $.extend( {}, TableTools.DEFAULTS, oOpts );
707
708 /* Flash file location */
709 this.s.swfPath = this.s.custom.sSwfPath;
710 if ( typeof ZeroClipboard_TableTools != 'undefined' )
711 {
712 ZeroClipboard_TableTools.moviePath = this.s.swfPath;
713 }
714
715 /* Table row selecting */
716 this.s.select.type = this.s.custom.sRowSelect;
717 this.s.select.preRowSelect = this.s.custom.fnPreRowSelect;
718 this.s.select.postSelected = this.s.custom.fnRowSelected;
719 this.s.select.postDeselected = this.s.custom.fnRowDeselected;
720
721 // Backwards compatibility - allow the user to specify a custom class in the initialiser
722 if ( this.s.custom.sSelectedClass )
723 {
724 this.classes.select.row = this.s.custom.sSelectedClass;
725 }
726
727 this.s.tags = this.s.custom.oTags;
728
729 /* Button set */
730 this.s.buttonSet = this.s.custom.aButtons;
731 },
732
733
734 /**
735 * Take the user input arrays and expand them to be fully defined, and then add them to a given
736 * DOM element
737 * @method _fnButtonDefinations
738 * @param {array} buttonSet Set of user defined buttons
739 * @param {node} wrapper Node to add the created buttons to
740 * @returns void
741 * @private
742 */
743 "_fnButtonDefinations": function ( buttonSet, wrapper )
744 {
745 var buttonDef;
746
747 for ( var i=0, iLen=buttonSet.length ; i<iLen ; i++ )
748 {
749 if ( typeof buttonSet[i] == "string" )
750 {
751 if ( typeof TableTools.BUTTONS[ buttonSet[i] ] == 'undefined' )
752 {
753 alert( "TableTools: Warning - unknown button type: "+buttonSet[i] );
754 continue;
755 }
756 buttonDef = $.extend( {}, TableTools.BUTTONS[ buttonSet[i] ], true );
757 }
758 else
759 {
760 if ( typeof TableTools.BUTTONS[ buttonSet[i].sExtends ] == 'undefined' )
761 {
762 alert( "TableTools: Warning - unknown button type: "+buttonSet[i].sExtends );
763 continue;
764 }
765 var o = $.extend( {}, TableTools.BUTTONS[ buttonSet[i].sExtends ], true );
766 buttonDef = $.extend( o, buttonSet[i], true );
767 }
768
769 wrapper.appendChild( this._fnCreateButton(
770 buttonDef,
771 $(wrapper).hasClass(this.classes.collection.container)
772 ) );
773 }
774 },
775
776
777 /**
778 * Create and configure a TableTools button
779 * @method _fnCreateButton
780 * @param {Object} oConfig Button configuration object
781 * @returns {Node} Button element
782 * @private
783 */
784 "_fnCreateButton": function ( oConfig, bCollectionButton )
785 {
786 var nButton = this._fnButtonBase( oConfig, bCollectionButton );
787
788 if ( oConfig.sAction.match(/flash/) )
789 {
790 this._fnFlashConfig( nButton, oConfig );
791 }
792 else if ( oConfig.sAction == "text" )
793 {
794 this._fnTextConfig( nButton, oConfig );
795 }
796 else if ( oConfig.sAction == "div" )
797 {
798 this._fnTextConfig( nButton, oConfig );
799 }
800 else if ( oConfig.sAction == "collection" )
801 {
802 this._fnTextConfig( nButton, oConfig );
803 this._fnCollectionConfig( nButton, oConfig );
804 }
805
806 return nButton;
807 },
808
809
810 /**
811 * Create the DOM needed for the button and apply some base properties. All buttons start here
812 * @method _fnButtonBase
813 * @param {o} oConfig Button configuration object
814 * @returns {Node} DIV element for the button
815 * @private
816 */
817 "_fnButtonBase": function ( o, bCollectionButton )
818 {
819 var sTag, sLiner, sClass;
820
821 if ( bCollectionButton )
822 {
823 sTag = o.sTag !== "default" ? o.sTag : this.s.tags.collection.button;
824 sLiner = o.sLinerTag !== "default" ? o.sLiner : this.s.tags.collection.liner;
825 sClass = this.classes.collection.buttons.normal;
826 }
827 else
828 {
829 sTag = o.sTag !== "default" ? o.sTag : this.s.tags.button;
830 sLiner = o.sLinerTag !== "default" ? o.sLiner : this.s.tags.liner;
831 sClass = this.classes.buttons.normal;
832 }
833
834 var
835 nButton = document.createElement( sTag ),
836 nSpan = document.createElement( sLiner ),
837 masterS = this._fnGetMasterSettings();
838
839 nButton.className = sClass+" "+o.sButtonClass;
840 nButton.setAttribute('id', "ToolTables_"+this.s.dt.sInstance+"_"+masterS.buttonCounter );
841 nButton.appendChild( nSpan );
842 nSpan.innerHTML = o.sButtonText;
843
844 masterS.buttonCounter++;
845
846 return nButton;
847 },
848
849
850 /**
851 * Get the settings object for the master instance. When more than one TableTools instance is
852 * assigned to a DataTable, only one of them can be the 'master' (for the select rows). As such,
853 * we will typically want to interact with that master for global properties.
854 * @method _fnGetMasterSettings
855 * @returns {Object} TableTools settings object
856 * @private
857 */
858 "_fnGetMasterSettings": function ()
859 {
860 if ( this.s.master )
861 {
862 return this.s;
863 }
864 else
865 {
866 /* Look for the master which has the same DT as this one */
867 var instances = TableTools._aInstances;
868 for ( var i=0, iLen=instances.length ; i<iLen ; i++ )
869 {
870 if ( this.dom.table == instances[i].s.dt.nTable )
871 {
872 return instances[i].s;
873 }
874 }
875 }
876 },
877
878
879
880 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
881 * Button collection functions
882 */
883
884 /**
885 * Create a collection button, when activated will present a drop down list of other buttons
886 * @param {Node} nButton Button to use for the collection activation
887 * @param {Object} oConfig Button configuration object
888 * @returns void
889 * @private
890 */
891 "_fnCollectionConfig": function ( nButton, oConfig )
892 {
893 var nHidden = document.createElement( this.s.tags.collection.container );
894 nHidden.style.display = "none";
895 nHidden.className = this.classes.collection.container;
896 oConfig._collection = nHidden;
897 document.body.appendChild( nHidden );
898
899 this._fnButtonDefinations( oConfig.aButtons, nHidden );
900 },
901
902
903 /**
904 * Show a button collection
905 * @param {Node} nButton Button to use for the collection
906 * @param {Object} oConfig Button configuration object
907 * @returns void
908 * @private
909 */
910 "_fnCollectionShow": function ( nButton, oConfig )
911 {
912 var
913 that = this,
914 oPos = $(nButton).offset(),
915 nHidden = oConfig._collection,
916 iDivX = oPos.left,
917 iDivY = oPos.top + $(nButton).outerHeight(),
918 iWinHeight = $(window).height(), iDocHeight = $(document).height(),
919 iWinWidth = $(window).width(), iDocWidth = $(document).width();
920
921 nHidden.style.position = "absolute";
922 nHidden.style.left = iDivX+"px";
923 nHidden.style.top = iDivY+"px";
924 nHidden.style.display = "block";
925 $(nHidden).css('opacity',0);
926
927 var nBackground = document.createElement('div');
928 nBackground.style.position = "absolute";
929 nBackground.style.left = "0px";
930 nBackground.style.top = "0px";
931 nBackground.style.height = ((iWinHeight>iDocHeight)? iWinHeight : iDocHeight) +"px";
932 nBackground.style.width = ((iWinWidth>iDocWidth)? iWinWidth : iDocWidth) +"px";
933 nBackground.className = this.classes.collection.background;
934 $(nBackground).css('opacity',0);
935
936 document.body.appendChild( nBackground );
937 document.body.appendChild( nHidden );
938
939 /* Visual corrections to try and keep the collection visible */
940 var iDivWidth = $(nHidden).outerWidth();
941 var iDivHeight = $(nHidden).outerHeight();
942
943 if ( iDivX + iDivWidth > iDocWidth )
944 {
945 nHidden.style.left = (iDocWidth-iDivWidth)+"px";
946 }
947
948 if ( iDivY + iDivHeight > iDocHeight )
949 {
950 nHidden.style.top = (iDivY-iDivHeight-$(nButton).outerHeight())+"px";
951 }
952
953 this.dom.collection.collection = nHidden;
954 this.dom.collection.background = nBackground;
955
956 /* This results in a very small delay for the end user but it allows the animation to be
957 * much smoother. If you don't want the animation, then the setTimeout can be removed
958 */
959 setTimeout( function () {
960 $(nHidden).animate({"opacity": 1}, 500);
961 $(nBackground).animate({"opacity": 0.25}, 500);
962 }, 10 );
963
964 /* Resize the buttons to the Flash contents fit */
965 this.fnResizeButtons();
966
967 /* Event handler to remove the collection display */
968 $(nBackground).click( function () {
969 that._fnCollectionHide.call( that, null, null );
970 } );
971 },
972
973
974 /**
975 * Hide a button collection
976 * @param {Node} nButton Button to use for the collection
977 * @param {Object} oConfig Button configuration object
978 * @returns void
979 * @private
980 */
981 "_fnCollectionHide": function ( nButton, oConfig )
982 {
983 if ( oConfig !== null && oConfig.sExtends == 'collection' )
984 {
985 return;
986 }
987
988 if ( this.dom.collection.collection !== null )
989 {
990 $(this.dom.collection.collection).animate({"opacity": 0}, 500, function (e) {
991 this.style.display = "none";
992 } );
993
994 $(this.dom.collection.background).animate({"opacity": 0}, 500, function (e) {
995 this.parentNode.removeChild( this );
996 } );
997
998 this.dom.collection.collection = null;
999 this.dom.collection.background = null;
1000 }
1001 },
1002
1003
1004
1005 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1006 * Row selection functions
1007 */
1008
1009 /**
1010 * Add event handlers to a table to allow for row selection
1011 * @method _fnRowSelectConfig
1012 * @returns void
1013 * @private
1014 */
1015 "_fnRowSelectConfig": function ()
1016 {
1017 if ( this.s.master )
1018 {
1019 var
1020 that = this,
1021 i, iLen,
1022 dt = this.s.dt,
1023 aoOpenRows = this.s.dt.aoOpenRows;
1024
1025 $(dt.nTable).addClass( this.classes.select.table );
1026
1027 $('tr', dt.nTBody).live( 'click', function(e) {
1028 /* Sub-table must be ignored (odd that the selector won't do this with >) */
1029 if ( this.parentNode != dt.nTBody )
1030 {
1031 return;
1032 }
1033
1034 /* Check that we are actually working with a DataTables controlled row */
1035 if ( dt.oInstance.fnGetData(this) === null )
1036 {
1037 return;
1038 }
1039
1040 if ( that.fnIsSelected( this ) )
1041 {
1042 that._fnRowDeselect( this, e );
1043 }
1044 else if ( that.s.select.type == "single" )
1045 {
1046 that.fnSelectNone();
1047 that._fnRowSelect( this, e );
1048 }
1049 else if ( that.s.select.type == "multi" )
1050 {
1051 that._fnRowSelect( this, e );
1052 }
1053 } );
1054
1055 // Bind a listener to the DataTable for when new rows are created.
1056 // This allows rows to be visually selected when they should be and
1057 // deferred rendering is used.
1058 dt.oApi._fnCallbackReg( dt, 'aoRowCreatedCallback', function (tr, data, index) {
1059 if ( dt.aoData[index]._DTTT_selected ) {
1060 $(tr).addClass( that.classes.select.row );
1061 }
1062 }, 'TableTools-SelectAll' );
1063 }
1064 },
1065
1066 /**
1067 * Select rows
1068 * @param {*} src Rows to select - see _fnSelectData for a description of valid inputs
1069 * @private
1070 */
1071 "_fnRowSelect": function ( src, e )
1072 {
1073 var
1074 that = this,
1075 data = this._fnSelectData( src ),
1076 firstTr = data.length===0 ? null : data[0].nTr,
1077 anSelected = [],
1078 i, len;
1079
1080 // Get all the rows that will be selected
1081 for ( i=0, len=data.length ; i<len ; i++ )
1082 {
1083 if ( data[i].nTr )
1084 {
1085 anSelected.push( data[i].nTr );
1086 }
1087 }
1088
1089 // User defined pre-selection function
1090 if ( this.s.select.preRowSelect !== null && !this.s.select.preRowSelect.call(this, e, anSelected, true) )
1091 {
1092 return;
1093 }
1094
1095 // Mark them as selected
1096 for ( i=0, len=data.length ; i<len ; i++ )
1097 {
1098 data[i]._DTTT_selected = true;
1099
1100 if ( data[i].nTr )
1101 {
1102 $(data[i].nTr).addClass( that.classes.select.row );
1103 }
1104 }
1105
1106 // Post-selection function
1107 if ( this.s.select.postSelected !== null )
1108 {
1109 this.s.select.postSelected.call( this, anSelected );
1110 }
1111
1112 TableTools._fnEventDispatch( this, 'select', anSelected, true );
1113 },
1114
1115 /**
1116 * Deselect rows
1117 * @param {*} src Rows to deselect - see _fnSelectData for a description of valid inputs
1118 * @private
1119 */
1120 "_fnRowDeselect": function ( src, e )
1121 {
1122 var
1123 that = this,
1124 data = this._fnSelectData( src ),
1125 firstTr = data.length===0 ? null : data[0].nTr,
1126 anDeselectedTrs = [],
1127 i, len;
1128
1129 // Get all the rows that will be deselected
1130 for ( i=0, len=data.length ; i<len ; i++ )
1131 {
1132 if ( data[i].nTr )
1133 {
1134 anDeselectedTrs.push( data[i].nTr );
1135 }
1136 }
1137
1138 // User defined pre-selection function
1139 if ( this.s.select.preRowSelect !== null && !this.s.select.preRowSelect.call(this, e, anDeselectedTrs, false) )
1140 {
1141 return;
1142 }
1143
1144 // Mark them as deselected
1145 for ( i=0, len=data.length ; i<len ; i++ )
1146 {
1147 data[i]._DTTT_selected = false;
1148
1149 if ( data[i].nTr )
1150 {
1151 $(data[i].nTr).removeClass( that.classes.select.row );
1152 }
1153 }
1154
1155 // Post-deselection function
1156 if ( this.s.select.postDeselected !== null )
1157 {
1158 this.s.select.postDeselected.call( this, anDeselectedTrs );
1159 }
1160
1161 TableTools._fnEventDispatch( this, 'select', anDeselectedTrs, false );
1162 },
1163
1164 /**
1165 * Take a data source for row selection and convert it into aoData points for the DT
1166 * @param {*} src Can be a single DOM TR node, an array of TR nodes (including a
1167 * a jQuery object), a single aoData point from DataTables, an array of aoData
1168 * points or an array of aoData indexes
1169 * @returns {array} An array of aoData points
1170 */
1171 "_fnSelectData": function ( src )
1172 {
1173 var out = [], pos, i, iLen;
1174
1175 if ( src.nodeName )
1176 {
1177 // Single node
1178 pos = this.s.dt.oInstance.fnGetPosition( src );
1179 out.push( this.s.dt.aoData[pos] );
1180 }
1181 else if ( typeof src.length !== 'undefined' )
1182 {
1183 // jQuery object or an array of nodes, or aoData points
1184 for ( i=0, iLen=src.length ; i<iLen ; i++ )
1185 {
1186 if ( src[i].nodeName )
1187 {
1188 pos = this.s.dt.oInstance.fnGetPosition( src[i] );
1189 out.push( this.s.dt.aoData[pos] );
1190 }
1191 else if ( typeof src[i] === 'number' )
1192 {
1193 out.push( this.s.dt.aoData[ src[i] ] );
1194 }
1195 else
1196 {
1197 out.push( src[i] );
1198 }
1199 }
1200
1201 return out;
1202 }
1203 else
1204 {
1205 // A single aoData point
1206 out.push( src );
1207 }
1208
1209 return out;
1210 },
1211
1212
1213 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1214 * Text button functions
1215 */
1216
1217 /**
1218 * Configure a text based button for interaction events
1219 * @method _fnTextConfig
1220 * @param {Node} nButton Button element which is being considered
1221 * @param {Object} oConfig Button configuration object
1222 * @returns void
1223 * @private
1224 */
1225 "_fnTextConfig": function ( nButton, oConfig )
1226 {
1227 var that = this;
1228
1229 if ( oConfig.fnInit !== null )
1230 {
1231 oConfig.fnInit.call( this, nButton, oConfig );
1232 }
1233
1234 if ( oConfig.sToolTip !== "" )
1235 {
1236 nButton.title = oConfig.sToolTip;
1237 }
1238
1239 $(nButton).hover( function () {
1240 if ( oConfig.fnMouseover !== null )
1241 {
1242 oConfig.fnMouseover.call( this, nButton, oConfig, null );
1243 }
1244 }, function () {
1245 if ( oConfig.fnMouseout !== null )
1246 {
1247 oConfig.fnMouseout.call( this, nButton, oConfig, null );
1248 }
1249 } );
1250
1251 if ( oConfig.fnSelect !== null )
1252 {
1253 TableTools._fnEventListen( this, 'select', function (n) {
1254 oConfig.fnSelect.call( that, nButton, oConfig, n );
1255 } );
1256 }
1257
1258 $(nButton).click( function (e) {
1259 //e.preventDefault();
1260
1261 if ( oConfig.fnClick !== null )
1262 {
1263 oConfig.fnClick.call( that, nButton, oConfig, null );
1264 }
1265
1266 /* Provide a complete function to match the behaviour of the flash elements */
1267 if ( oConfig.fnComplete !== null )
1268 {
1269 oConfig.fnComplete.call( that, nButton, oConfig, null, null );
1270 }
1271
1272 that._fnCollectionHide( nButton, oConfig );
1273 } );
1274 },
1275
1276
1277
1278 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1279 * Flash button functions
1280 */
1281
1282 /**
1283 * Configure a flash based button for interaction events
1284 * @method _fnFlashConfig
1285 * @param {Node} nButton Button element which is being considered
1286 * @param {o} oConfig Button configuration object
1287 * @returns void
1288 * @private
1289 */
1290 "_fnFlashConfig": function ( nButton, oConfig )
1291 {
1292 var that = this;
1293 var flash = new ZeroClipboard_TableTools.Client();
1294
1295 if ( oConfig.fnInit !== null )
1296 {
1297 oConfig.fnInit.call( this, nButton, oConfig );
1298 }
1299
1300 flash.setHandCursor( true );
1301
1302 if ( oConfig.sAction == "flash_save" )
1303 {
1304 flash.setAction( 'save' );
1305 flash.setCharSet( (oConfig.sCharSet=="utf16le") ? 'UTF16LE' : 'UTF8' );
1306 flash.setBomInc( oConfig.bBomInc );
1307 flash.setFileName( oConfig.sFileName.replace('*', this.fnGetTitle(oConfig)) );
1308 }
1309 else if ( oConfig.sAction == "flash_pdf" )
1310 {
1311 flash.setAction( 'pdf' );
1312 flash.setFileName( oConfig.sFileName.replace('*', this.fnGetTitle(oConfig)) );
1313 }
1314 else
1315 {
1316 flash.setAction( 'copy' );
1317 }
1318
1319 flash.addEventListener('mouseOver', function(client) {
1320 if ( oConfig.fnMouseover !== null )
1321 {
1322 oConfig.fnMouseover.call( that, nButton, oConfig, flash );
1323 }
1324 } );
1325
1326 flash.addEventListener('mouseOut', function(client) {
1327 if ( oConfig.fnMouseout !== null )
1328 {
1329 oConfig.fnMouseout.call( that, nButton, oConfig, flash );
1330 }
1331 } );
1332
1333 flash.addEventListener('mouseDown', function(client) {
1334 if ( oConfig.fnClick !== null )
1335 {
1336 oConfig.fnClick.call( that, nButton, oConfig, flash );
1337 }
1338 } );
1339
1340 flash.addEventListener('complete', function (client, text) {
1341 if ( oConfig.fnComplete !== null )
1342 {
1343 oConfig.fnComplete.call( that, nButton, oConfig, flash, text );
1344 }
1345 that._fnCollectionHide( nButton, oConfig );
1346 } );
1347
1348 this._fnFlashGlue( flash, nButton, oConfig.sToolTip );
1349 },
1350
1351
1352 /**
1353 * Wait until the id is in the DOM before we "glue" the swf. Note that this function will call
1354 * itself (using setTimeout) until it completes successfully
1355 * @method _fnFlashGlue
1356 * @param {Object} clip Zero clipboard object
1357 * @param {Node} node node to glue swf to
1358 * @param {String} text title of the flash movie
1359 * @returns void
1360 * @private
1361 */
1362 "_fnFlashGlue": function ( flash, node, text )
1363 {
1364 var that = this;
1365 var id = node.getAttribute('id');
1366
1367 if ( document.getElementById(id) )
1368 {
1369 flash.glue( node, text );
1370 }
1371 else
1372 {
1373 setTimeout( function () {
1374 that._fnFlashGlue( flash, node, text );
1375 }, 100 );
1376 }
1377 },
1378
1379
1380 /**
1381 * Set the text for the flash clip to deal with
1382 *
1383 * This function is required for large information sets. There is a limit on the
1384 * amount of data that can be transferred between Javascript and Flash in a single call, so
1385 * we use this method to build up the text in Flash by sending over chunks. It is estimated
1386 * that the data limit is around 64k, although it is undocumented, and appears to be different
1387 * between different flash versions. We chunk at 8KiB.
1388 * @method _fnFlashSetText
1389 * @param {Object} clip the ZeroClipboard object
1390 * @param {String} sData the data to be set
1391 * @returns void
1392 * @private
1393 */
1394 "_fnFlashSetText": function ( clip, sData )
1395 {
1396 var asData = this._fnChunkData( sData, 8192 );
1397
1398 clip.clearText();
1399 for ( var i=0, iLen=asData.length ; i<iLen ; i++ )
1400 {
1401 clip.appendText( asData[i] );
1402 }
1403 },
1404
1405
1406
1407 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1408 * Data retrieval functions
1409 */
1410
1411 /**
1412 * Convert the mixed columns variable into a boolean array the same size as the columns, which
1413 * indicates which columns we want to include
1414 * @method _fnColumnTargets
1415 * @param {String|Array} mColumns The columns to be included in data retrieval. If a string
1416 * then it can take the value of "visible" or "hidden" (to include all visible or
1417 * hidden columns respectively). Or an array of column indexes
1418 * @returns {Array} A boolean array the length of the columns of the table, which each value
1419 * indicating if the column is to be included or not
1420 * @private
1421 */
1422 "_fnColumnTargets": function ( mColumns )
1423 {
1424 var aColumns = [];
1425 var dt = this.s.dt;
1426
1427 if ( typeof mColumns == "object" )
1428 {
1429 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
1430 {
1431 aColumns.push( false );
1432 }
1433
1434 for ( i=0, iLen=mColumns.length ; i<iLen ; i++ )
1435 {
1436 aColumns[ mColumns[i] ] = true;
1437 }
1438 }
1439 else if ( mColumns == "visible" )
1440 {
1441 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
1442 {
1443 aColumns.push( dt.aoColumns[i].bVisible ? true : false );
1444 }
1445 }
1446 else if ( mColumns == "hidden" )
1447 {
1448 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
1449 {
1450 aColumns.push( dt.aoColumns[i].bVisible ? false : true );
1451 }
1452 }
1453 else if ( mColumns == "sortable" )
1454 {
1455 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
1456 {
1457 aColumns.push( dt.aoColumns[i].bSortable ? true : false );
1458 }
1459 }
1460 else /* all */
1461 {
1462 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
1463 {
1464 aColumns.push( true );
1465 }
1466 }
1467
1468 return aColumns;
1469 },
1470
1471
1472 /**
1473 * New line character(s) depend on the platforms
1474 * @method method
1475 * @param {Object} oConfig Button configuration object - only interested in oConfig.sNewLine
1476 * @returns {String} Newline character
1477 */
1478 "_fnNewline": function ( oConfig )
1479 {
1480 if ( oConfig.sNewLine == "auto" )
1481 {
1482 return navigator.userAgent.match(/Windows/) ? "\r\n" : "\n";
1483 }
1484 else
1485 {
1486 return oConfig.sNewLine;
1487 }
1488 },
1489
1490
1491 /**
1492 * Get data from DataTables' internals and format it for output
1493 * @method _fnGetDataTablesData
1494 * @param {Object} oConfig Button configuration object
1495 * @param {String} oConfig.sFieldBoundary Field boundary for the data cells in the string
1496 * @param {String} oConfig.sFieldSeperator Field separator for the data cells
1497 * @param {String} oConfig.sNewline New line options
1498 * @param {Mixed} oConfig.mColumns Which columns should be included in the output
1499 * @param {Boolean} oConfig.bHeader Include the header
1500 * @param {Boolean} oConfig.bFooter Include the footer
1501 * @param {Boolean} oConfig.bSelectedOnly Include only the selected rows in the output
1502 * @returns {String} Concatenated string of data
1503 * @private
1504 */
1505 "_fnGetDataTablesData": function ( oConfig )
1506 {
1507 var i, iLen, j, jLen;
1508 var aRow, aData=[], sLoopData='', arr;
1509 var dt = this.s.dt, tr, child;
1510 var regex = new RegExp(oConfig.sFieldBoundary, "g"); /* Do it here for speed */
1511 var aColumnsInc = this._fnColumnTargets( oConfig.mColumns );
1512 var bSelectedOnly = (typeof oConfig.bSelectedOnly != 'undefined') ? oConfig.bSelectedOnly : false;
1513
1514 /*
1515 * Header
1516 */
1517 if ( oConfig.bHeader )
1518 {
1519 aRow = [];
1520
1521 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
1522 {
1523 if ( aColumnsInc[i] )
1524 {
1525 sLoopData = dt.aoColumns[i].sTitle.replace(/\n/g," ").replace( /<.*?>/g, "" ).replace(/^\s+|\s+$/g,"");
1526 sLoopData = this._fnHtmlDecode( sLoopData );
1527
1528 aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) );
1529 }
1530 }
1531
1532 aData.push( aRow.join(oConfig.sFieldSeperator) );
1533 }
1534
1535 /*
1536 * Body
1537 */
1538 var aDataIndex = dt.aiDisplay;
1539 var aSelected = this.fnGetSelected();
1540 if ( this.s.select.type !== "none" && bSelectedOnly && aSelected.length !== 0 )
1541 {
1542 aDataIndex = [];
1543 for ( i=0, iLen=aSelected.length ; i<iLen ; i++ )
1544 {
1545 aDataIndex.push( dt.oInstance.fnGetPosition( aSelected[i] ) );
1546 }
1547 }
1548
1549 for ( j=0, jLen=aDataIndex.length ; j<jLen ; j++ )
1550 {
1551 tr = dt.aoData[ aDataIndex[j] ].nTr;
1552 aRow = [];
1553
1554 /* Columns */
1555 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
1556 {
1557 if ( aColumnsInc[i] )
1558 {
1559 /* Convert to strings (with small optimisation) */
1560 var mTypeData = dt.oApi._fnGetCellData( dt, aDataIndex[j], i, 'display' );
1561 if ( oConfig.fnCellRender )
1562 {
1563 sLoopData = oConfig.fnCellRender( mTypeData, i, tr, aDataIndex[j] )+"";
1564 }
1565 else if ( typeof mTypeData == "string" )
1566 {
1567 /* Strip newlines, replace img tags with alt attr. and finally strip html... */
1568 sLoopData = mTypeData.replace(/\n/g," ");
1569 sLoopData =
1570 sLoopData.replace(/<img.*?\s+alt\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s>]+)).*?>/gi,
1571 '$1$2$3');
1572 sLoopData = sLoopData.replace( /<.*?>/g, "" );
1573 }
1574 else
1575 {
1576 sLoopData = mTypeData+"";
1577 }
1578
1579 /* Trim and clean the data */
1580 sLoopData = sLoopData.replace(/^\s+/, '').replace(/\s+$/, '');
1581 sLoopData = this._fnHtmlDecode( sLoopData );
1582
1583 /* Bound it and add it to the total data */
1584 aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) );
1585 }
1586 }
1587
1588 aData.push( aRow.join(oConfig.sFieldSeperator) );
1589
1590 /* Details rows from fnOpen */
1591 if ( oConfig.bOpenRows )
1592 {
1593 arr = $.grep(dt.aoOpenRows, function(o) { return o.nParent === tr; });
1594
1595 if ( arr.length === 1 )
1596 {
1597 sLoopData = this._fnBoundData( $('td', arr[0].nTr).html(), oConfig.sFieldBoundary, regex );
1598 aData.push( sLoopData );
1599 }
1600 }
1601 }
1602
1603 /*
1604 * Footer
1605 */
1606 if ( oConfig.bFooter && dt.nTFoot !== null )
1607 {
1608 aRow = [];
1609
1610 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
1611 {
1612 if ( aColumnsInc[i] && dt.aoColumns[i].nTf !== null )
1613 {
1614 sLoopData = dt.aoColumns[i].nTf.innerHTML.replace(/\n/g," ").replace( /<.*?>/g, "" );
1615 sLoopData = this._fnHtmlDecode( sLoopData );
1616
1617 aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) );
1618 }
1619 }
1620
1621 aData.push( aRow.join(oConfig.sFieldSeperator) );
1622 }
1623
1624 _sLastData = aData.join( this._fnNewline(oConfig) );
1625 return _sLastData;
1626 },
1627
1628
1629 /**
1630 * Wrap data up with a boundary string
1631 * @method _fnBoundData
1632 * @param {String} sData data to bound
1633 * @param {String} sBoundary bounding char(s)
1634 * @param {RegExp} regex search for the bounding chars - constructed outside for efficiency
1635 * in the loop
1636 * @returns {String} bound data
1637 * @private
1638 */
1639 "_fnBoundData": function ( sData, sBoundary, regex )
1640 {
1641 if ( sBoundary === "" )
1642 {
1643 return sData;
1644 }
1645 else
1646 {
1647 return sBoundary + sData.replace(regex, sBoundary+sBoundary) + sBoundary;
1648 }
1649 },
1650
1651
1652 /**
1653 * Break a string up into an array of smaller strings
1654 * @method _fnChunkData
1655 * @param {String} sData data to be broken up
1656 * @param {Int} iSize chunk size
1657 * @returns {Array} String array of broken up text
1658 * @private
1659 */
1660 "_fnChunkData": function ( sData, iSize )
1661 {
1662 var asReturn = [];
1663 var iStrlen = sData.length;
1664
1665 for ( var i=0 ; i<iStrlen ; i+=iSize )
1666 {
1667 if ( i+iSize < iStrlen )
1668 {
1669 asReturn.push( sData.substring( i, i+iSize ) );
1670 }
1671 else
1672 {
1673 asReturn.push( sData.substring( i, iStrlen ) );
1674 }
1675 }
1676
1677 return asReturn;
1678 },
1679
1680
1681 /**
1682 * Decode HTML entities
1683 * @method _fnHtmlDecode
1684 * @param {String} sData encoded string
1685 * @returns {String} decoded string
1686 * @private
1687 */
1688 "_fnHtmlDecode": function ( sData )
1689 {
1690 if ( sData.indexOf('&') === -1 )
1691 {
1692 return sData;
1693 }
1694
1695 var n = document.createElement('div');
1696
1697 return sData.replace( /&([^\s]*);/g, function( match, match2 ) {
1698 if ( match.substr(1, 1) === '#' )
1699 {
1700 return String.fromCharCode( Number(match2.substr(1)) );
1701 }
1702 else
1703 {
1704 n.innerHTML = match;
1705 return n.childNodes[0].nodeValue;
1706 }
1707 } );
1708 },
1709
1710
1711
1712 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1713 * Printing functions
1714 */
1715
1716 /**
1717 * Show print display
1718 * @method _fnPrintStart
1719 * @param {Event} e Event object
1720 * @param {Object} oConfig Button configuration object
1721 * @returns void
1722 * @private
1723 */
1724 "_fnPrintStart": function ( oConfig )
1725 {
1726 var that = this;
1727 var oSetDT = this.s.dt;
1728
1729 /* Parse through the DOM hiding everything that isn't needed for the table */
1730 this._fnPrintHideNodes( oSetDT.nTable );
1731
1732 /* Show the whole table */
1733 this.s.print.saveStart = oSetDT._iDisplayStart;
1734 this.s.print.saveLength = oSetDT._iDisplayLength;
1735
1736 if ( oConfig.bShowAll )
1737 {
1738 oSetDT._iDisplayStart = 0;
1739 oSetDT._iDisplayLength = -1;
1740 oSetDT.oApi._fnCalculateEnd( oSetDT );
1741 oSetDT.oApi._fnDraw( oSetDT );
1742 }
1743
1744 /* Adjust the display for scrolling which might be done by DataTables */
1745 if ( oSetDT.oScroll.sX !== "" || oSetDT.oScroll.sY !== "" )
1746 {
1747 this._fnPrintScrollStart( oSetDT );
1748
1749 // If the table redraws while in print view, the DataTables scrolling
1750 // setup would hide the header, so we need to readd it on draw
1751 $(this.s.dt.nTable).bind('draw.DTTT_Print', function () {
1752 that._fnPrintScrollStart( oSetDT );
1753 } );
1754 }
1755
1756 /* Remove the other DataTables feature nodes - but leave the table! and info div */
1757 var anFeature = oSetDT.aanFeatures;
1758 for ( var cFeature in anFeature )
1759 {
1760 if ( cFeature != 'i' && cFeature != 't' && cFeature.length == 1 )
1761 {
1762 for ( var i=0, iLen=anFeature[cFeature].length ; i<iLen ; i++ )
1763 {
1764 this.dom.print.hidden.push( {
1765 "node": anFeature[cFeature][i],
1766 "display": "block"
1767 } );
1768 anFeature[cFeature][i].style.display = "none";
1769 }
1770 }
1771 }
1772
1773 /* Print class can be used for styling */
1774 $(document.body).addClass( this.classes.print.body );
1775
1776 /* Show information message to let the user know what is happening */
1777 if ( oConfig.sInfo !== "" )
1778 {
1779 this.fnInfo( oConfig.sInfo, 3000 );
1780 }
1781
1782 /* Add a message at the top of the page */
1783 if ( oConfig.sMessage )
1784 {
1785 this.dom.print.message = document.createElement( "div" );
1786 this.dom.print.message.className = this.classes.print.message;
1787 this.dom.print.message.innerHTML = oConfig.sMessage;
1788 document.body.insertBefore( this.dom.print.message, document.body.childNodes[0] );
1789 }
1790
1791 /* Cache the scrolling and the jump to the top of the page */
1792 this.s.print.saveScroll = $(window).scrollTop();
1793 window.scrollTo( 0, 0 );
1794
1795 /* Bind a key event listener to the document for the escape key -
1796 * it is removed in the callback
1797 */
1798 $(document).bind( "keydown.DTTT", function(e) {
1799 /* Only interested in the escape key */
1800 if ( e.keyCode == 27 )
1801 {
1802 e.preventDefault();
1803 that._fnPrintEnd.call( that, e );
1804 }
1805 } );
1806 },
1807
1808
1809 /**
1810 * Printing is finished, resume normal display
1811 * @method _fnPrintEnd
1812 * @param {Event} e Event object
1813 * @returns void
1814 * @private
1815 */
1816 "_fnPrintEnd": function ( e )
1817 {
1818 var that = this;
1819 var oSetDT = this.s.dt;
1820 var oSetPrint = this.s.print;
1821 var oDomPrint = this.dom.print;
1822
1823 /* Show all hidden nodes */
1824 this._fnPrintShowNodes();
1825
1826 /* Restore DataTables' scrolling */
1827 if ( oSetDT.oScroll.sX !== "" || oSetDT.oScroll.sY !== "" )
1828 {
1829 $(this.s.dt.nTable).unbind('draw.DTTT_Print');
1830
1831 this._fnPrintScrollEnd();
1832 }
1833
1834 /* Restore the scroll */
1835 window.scrollTo( 0, oSetPrint.saveScroll );
1836
1837 /* Drop the print message */
1838 if ( oDomPrint.message !== null )
1839 {
1840 document.body.removeChild( oDomPrint.message );
1841 oDomPrint.message = null;
1842 }
1843
1844 /* Styling class */
1845 $(document.body).removeClass( 'DTTT_Print' );
1846
1847 /* Restore the table length */
1848 oSetDT._iDisplayStart = oSetPrint.saveStart;
1849 oSetDT._iDisplayLength = oSetPrint.saveLength;
1850 oSetDT.oApi._fnCalculateEnd( oSetDT );
1851 oSetDT.oApi._fnDraw( oSetDT );
1852
1853 $(document).unbind( "keydown.DTTT" );
1854 },
1855
1856
1857 /**
1858 * Take account of scrolling in DataTables by showing the full table
1859 * @returns void
1860 * @private
1861 */
1862 "_fnPrintScrollStart": function ()
1863 {
1864 var
1865 oSetDT = this.s.dt,
1866 nScrollHeadInner = oSetDT.nScrollHead.getElementsByTagName('div')[0],
1867 nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0],
1868 nScrollBody = oSetDT.nTable.parentNode;
1869
1870 /* Copy the header in the thead in the body table, this way we show one single table when
1871 * in print view. Note that this section of code is more or less verbatim from DT 1.7.0
1872 */
1873 var nTheadSize = oSetDT.nTable.getElementsByTagName('thead');
1874 if ( nTheadSize.length > 0 )
1875 {
1876 oSetDT.nTable.removeChild( nTheadSize[0] );
1877 }
1878
1879 if ( oSetDT.nTFoot !== null )
1880 {
1881 var nTfootSize = oSetDT.nTable.getElementsByTagName('tfoot');
1882 if ( nTfootSize.length > 0 )
1883 {
1884 oSetDT.nTable.removeChild( nTfootSize[0] );
1885 }
1886 }
1887
1888 nTheadSize = oSetDT.nTHead.cloneNode(true);
1889 oSetDT.nTable.insertBefore( nTheadSize, oSetDT.nTable.childNodes[0] );
1890
1891 if ( oSetDT.nTFoot !== null )
1892 {
1893 nTfootSize = oSetDT.nTFoot.cloneNode(true);
1894 oSetDT.nTable.insertBefore( nTfootSize, oSetDT.nTable.childNodes[1] );
1895 }
1896
1897 /* Now adjust the table's viewport so we can actually see it */
1898 if ( oSetDT.oScroll.sX !== "" )
1899 {
1900 oSetDT.nTable.style.width = $(oSetDT.nTable).outerWidth()+"px";
1901 nScrollBody.style.width = $(oSetDT.nTable).outerWidth()+"px";
1902 nScrollBody.style.overflow = "visible";
1903 }
1904
1905 if ( oSetDT.oScroll.sY !== "" )
1906 {
1907 nScrollBody.style.height = $(oSetDT.nTable).outerHeight()+"px";
1908 nScrollBody.style.overflow = "visible";
1909 }
1910 },
1911
1912
1913 /**
1914 * Take account of scrolling in DataTables by showing the full table. Note that the redraw of
1915 * the DataTable that we do will actually deal with the majority of the hard work here
1916 * @returns void
1917 * @private
1918 */
1919 "_fnPrintScrollEnd": function ()
1920 {
1921 var
1922 oSetDT = this.s.dt,
1923 nScrollBody = oSetDT.nTable.parentNode;
1924
1925 if ( oSetDT.oScroll.sX !== "" )
1926 {
1927 nScrollBody.style.width = oSetDT.oApi._fnStringToCss( oSetDT.oScroll.sX );
1928 nScrollBody.style.overflow = "auto";
1929 }
1930
1931 if ( oSetDT.oScroll.sY !== "" )
1932 {
1933 nScrollBody.style.height = oSetDT.oApi._fnStringToCss( oSetDT.oScroll.sY );
1934 nScrollBody.style.overflow = "auto";
1935 }
1936 },
1937
1938
1939 /**
1940 * Resume the display of all TableTools hidden nodes
1941 * @method _fnPrintShowNodes
1942 * @returns void
1943 * @private
1944 */
1945 "_fnPrintShowNodes": function ( )
1946 {
1947 var anHidden = this.dom.print.hidden;
1948
1949 for ( var i=0, iLen=anHidden.length ; i<iLen ; i++ )
1950 {
1951 anHidden[i].node.style.display = anHidden[i].display;
1952 }
1953 anHidden.splice( 0, anHidden.length );
1954 },
1955
1956
1957 /**
1958 * Hide nodes which are not needed in order to display the table. Note that this function is
1959 * recursive
1960 * @method _fnPrintHideNodes
1961 * @param {Node} nNode Element which should be showing in a 'print' display
1962 * @returns void
1963 * @private
1964 */
1965 "_fnPrintHideNodes": function ( nNode )
1966 {
1967 var anHidden = this.dom.print.hidden;
1968
1969 var nParent = nNode.parentNode;
1970 var nChildren = nParent.childNodes;
1971 for ( var i=0, iLen=nChildren.length ; i<iLen ; i++ )
1972 {
1973 if ( nChildren[i] != nNode && nChildren[i].nodeType == 1 )
1974 {
1975 /* If our node is shown (don't want to show nodes which were previously hidden) */
1976 var sDisplay = $(nChildren[i]).css("display");
1977 if ( sDisplay != "none" )
1978 {
1979 /* Cache the node and it's previous state so we can restore it */
1980 anHidden.push( {
1981 "node": nChildren[i],
1982 "display": sDisplay
1983 } );
1984 nChildren[i].style.display = "none";
1985 }
1986 }
1987 }
1988
1989 if ( nParent.nodeName != "BODY" )
1990 {
1991 this._fnPrintHideNodes( nParent );
1992 }
1993 }
1994 };
1995
1996
1997
1998 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1999 * Static variables
2000 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001
2002 /**
2003 * Store of all instances that have been created of TableTools, so one can look up other (when
2004 * there is need of a master)
2005 * @property _aInstances
2006 * @type Array
2007 * @default []
2008 * @private
2009 */
2010 TableTools._aInstances = [];
2011
2012
2013 /**
2014 * Store of all listeners and their callback functions
2015 * @property _aListeners
2016 * @type Array
2017 * @default []
2018 */
2019 TableTools._aListeners = [];
2020
2021
2022
2023 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2024 * Static methods
2025 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2026
2027 /**
2028 * Get an array of all the master instances
2029 * @method fnGetMasters
2030 * @returns {Array} List of master TableTools instances
2031 * @static
2032 */
2033 TableTools.fnGetMasters = function ()
2034 {
2035 var a = [];
2036 for ( var i=0, iLen=TableTools._aInstances.length ; i<iLen ; i++ )
2037 {
2038 if ( TableTools._aInstances[i].s.master )
2039 {
2040 a.push( TableTools._aInstances[i] );
2041 }
2042 }
2043 return a;
2044 };
2045
2046 /**
2047 * Get the master instance for a table node (or id if a string is given)
2048 * @method fnGetInstance
2049 * @returns {Object} ID of table OR table node, for which we want the TableTools instance
2050 * @static
2051 */
2052 TableTools.fnGetInstance = function ( node )
2053 {
2054 if ( typeof node != 'object' )
2055 {
2056 node = document.getElementById(node);
2057 }
2058
2059 for ( var i=0, iLen=TableTools._aInstances.length ; i<iLen ; i++ )
2060 {
2061 if ( TableTools._aInstances[i].s.master && TableTools._aInstances[i].dom.table == node )
2062 {
2063 return TableTools._aInstances[i];
2064 }
2065 }
2066 return null;
2067 };
2068
2069
2070 /**
2071 * Add a listener for a specific event
2072 * @method _fnEventListen
2073 * @param {Object} that Scope of the listening function (i.e. 'this' in the caller)
2074 * @param {String} type Event type
2075 * @param {Function} fn Function
2076 * @returns void
2077 * @private
2078 * @static
2079 */
2080 TableTools._fnEventListen = function ( that, type, fn )
2081 {
2082 TableTools._aListeners.push( {
2083 "that": that,
2084 "type": type,
2085 "fn": fn
2086 } );
2087 };
2088
2089
2090 /**
2091 * An event has occurred - look up every listener and fire it off. We check that the event we are
2092 * going to fire is attached to the same table (using the table node as reference) before firing
2093 * @method _fnEventDispatch
2094 * @param {Object} that Scope of the listening function (i.e. 'this' in the caller)
2095 * @param {String} type Event type
2096 * @param {Node} node Element that the event occurred on (may be null)
2097 * @param {boolean} [selected] Indicate if the node was selected (true) or deselected (false)
2098 * @returns void
2099 * @private
2100 * @static
2101 */
2102 TableTools._fnEventDispatch = function ( that, type, node, selected )
2103 {
2104 var listeners = TableTools._aListeners;
2105 for ( var i=0, iLen=listeners.length ; i<iLen ; i++ )
2106 {
2107 if ( that.dom.table == listeners[i].that.dom.table && listeners[i].type == type )
2108 {
2109 listeners[i].fn( node, selected );
2110 }
2111 }
2112 };
2113
2114
2115
2116
2117
2118
2119 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2120 * Constants
2121 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2122
2123
2124
2125 TableTools.buttonBase = {
2126 // Button base
2127 "sAction": "text",
2128 "sTag": "default",
2129 "sLinerTag": "default",
2130 "sButtonClass": "DTTT_button_text",
2131 "sButtonText": "Button text",
2132 "sTitle": "",
2133 "sToolTip": "",
2134
2135 // Common button specific options
2136 "sCharSet": "utf8",
2137 "bBomInc": false,
2138 "sFileName": "*.csv",
2139 "sFieldBoundary": "",
2140 "sFieldSeperator": "\t",
2141 "sNewLine": "auto",
2142 "mColumns": "all", /* "all", "visible", "hidden" or array of column integers */
2143 "bHeader": true,
2144 "bFooter": true,
2145 "bOpenRows": false,
2146 "bSelectedOnly": false,
2147
2148 // Callbacks
2149 "fnMouseover": null,
2150 "fnMouseout": null,
2151 "fnClick": null,
2152 "fnSelect": null,
2153 "fnComplete": null,
2154 "fnInit": null,
2155 "fnCellRender": null
2156 };
2157
2158
2159 /**
2160 * @namespace Default button configurations
2161 */
2162 TableTools.BUTTONS = {
2163 "csv": $.extend( {}, TableTools.buttonBase, {
2164 "sAction": "flash_save",
2165 "sButtonClass": "DTTT_button_csv",
2166 "sButtonText": "CSV",
2167 "sFieldBoundary": '"',
2168 "sFieldSeperator": ",",
2169 "fnClick": function( nButton, oConfig, flash ) {
2170 this.fnSetText( flash, this.fnGetTableData(oConfig) );
2171 }
2172 } ),
2173
2174 "xls": $.extend( {}, TableTools.buttonBase, {
2175 "sAction": "flash_save",
2176 "sCharSet": "utf16le",
2177 "bBomInc": true,
2178 "sButtonClass": "DTTT_button_xls",
2179 "sButtonText": "Excel",
2180 "fnClick": function( nButton, oConfig, flash ) {
2181 this.fnSetText( flash, this.fnGetTableData(oConfig) );
2182 }
2183 } ),
2184
2185 "copy": $.extend( {}, TableTools.buttonBase, {
2186 "sAction": "flash_copy",
2187 "sButtonClass": "DTTT_button_copy",
2188 "sButtonText": "Copy",
2189 "fnClick": function( nButton, oConfig, flash ) {
2190 this.fnSetText( flash, this.fnGetTableData(oConfig) );
2191 },
2192 "fnComplete": function(nButton, oConfig, flash, text) {
2193 var
2194 lines = text.split('\n').length,
2195 len = this.s.dt.nTFoot === null ? lines-1 : lines-2,
2196 plural = (len==1) ? "" : "s";
2197 this.fnInfo( '<h6>Table copied</h6>'+
2198 '<p>Copied '+len+' row'+plural+' to the clipboard.</p>',
2199 1500
2200 );
2201 }
2202 } ),
2203
2204 "pdf": $.extend( {}, TableTools.buttonBase, {
2205 "sAction": "flash_pdf",
2206 "sNewLine": "\n",
2207 "sFileName": "*.pdf",
2208 "sButtonClass": "DTTT_button_pdf",
2209 "sButtonText": "PDF",
2210 "sPdfOrientation": "portrait",
2211 "sPdfSize": "A4",
2212 "sPdfMessage": "",
2213 "fnClick": function( nButton, oConfig, flash ) {
2214 this.fnSetText( flash,
2215 "title:"+ this.fnGetTitle(oConfig) +"\n"+
2216 "message:"+ oConfig.sPdfMessage +"\n"+
2217 "colWidth:"+ this.fnCalcColRatios(oConfig) +"\n"+
2218 "orientation:"+ oConfig.sPdfOrientation +"\n"+
2219 "size:"+ oConfig.sPdfSize +"\n"+
2220 "--/TableToolsOpts--\n" +
2221 this.fnGetTableData(oConfig)
2222 );
2223 }
2224 } ),
2225
2226 "print": $.extend( {}, TableTools.buttonBase, {
2227 "sInfo": "<h6>Print view</h6><p>Please use your browser's print function to "+
2228 "print this table. Press escape when finished.",
2229 "sMessage": null,
2230 "bShowAll": true,
2231 "sToolTip": "View print view",
2232 "sButtonClass": "DTTT_button_print",
2233 "sButtonText": "Print",
2234 "fnClick": function ( nButton, oConfig ) {
2235 this.fnPrint( true, oConfig );
2236 }
2237 } ),
2238
2239 "text": $.extend( {}, TableTools.buttonBase ),
2240
2241 "select": $.extend( {}, TableTools.buttonBase, {
2242 "sButtonText": "Select button",
2243 "fnSelect": function( nButton, oConfig ) {
2244 if ( this.fnGetSelected().length !== 0 ) {
2245 $(nButton).removeClass( this.classes.buttons.disabled );
2246 } else {
2247 $(nButton).addClass( this.classes.buttons.disabled );
2248 }
2249 },
2250 "fnInit": function( nButton, oConfig ) {
2251 $(nButton).addClass( this.classes.buttons.disabled );
2252 }
2253 } ),
2254
2255 "select_single": $.extend( {}, TableTools.buttonBase, {
2256 "sButtonText": "Select button",
2257 "fnSelect": function( nButton, oConfig ) {
2258 var iSelected = this.fnGetSelected().length;
2259 if ( iSelected == 1 ) {
2260 $(nButton).removeClass( this.classes.buttons.disabled );
2261 } else {
2262 $(nButton).addClass( this.classes.buttons.disabled );
2263 }
2264 },
2265 "fnInit": function( nButton, oConfig ) {
2266 $(nButton).addClass( this.classes.buttons.disabled );
2267 }
2268 } ),
2269
2270 "select_all": $.extend( {}, TableTools.buttonBase, {
2271 "sButtonText": "Select all",
2272 "fnClick": function( nButton, oConfig ) {
2273 this.fnSelectAll();
2274 },
2275 "fnSelect": function( nButton, oConfig ) {
2276 if ( this.fnGetSelected().length == this.s.dt.fnRecordsDisplay() ) {
2277 $(nButton).addClass( this.classes.buttons.disabled );
2278 } else {
2279 $(nButton).removeClass( this.classes.buttons.disabled );
2280 }
2281 }
2282 } ),
2283
2284 "select_none": $.extend( {}, TableTools.buttonBase, {
2285 "sButtonText": "Deselect all",
2286 "fnClick": function( nButton, oConfig ) {
2287 this.fnSelectNone();
2288 },
2289 "fnSelect": function( nButton, oConfig ) {
2290 if ( this.fnGetSelected().length !== 0 ) {
2291 $(nButton).removeClass( this.classes.buttons.disabled );
2292 } else {
2293 $(nButton).addClass( this.classes.buttons.disabled );
2294 }
2295 },
2296 "fnInit": function( nButton, oConfig ) {
2297 $(nButton).addClass( this.classes.buttons.disabled );
2298 }
2299 } ),
2300
2301 "ajax": $.extend( {}, TableTools.buttonBase, {
2302 "sAjaxUrl": "/xhr.php",
2303 "sButtonText": "Ajax button",
2304 "fnClick": function( nButton, oConfig ) {
2305 var sData = this.fnGetTableData(oConfig);
2306 $.ajax( {
2307 "url": oConfig.sAjaxUrl,
2308 "data": [
2309 { "name": "tableData", "value": sData }
2310 ],
2311 "success": oConfig.fnAjaxComplete,
2312 "dataType": "json",
2313 "type": "POST",
2314 "cache": false,
2315 "error": function () {
2316 alert( "Error detected when sending table data to server" );
2317 }
2318 } );
2319 },
2320 "fnAjaxComplete": function( json ) {
2321 alert( 'Ajax complete' );
2322 }
2323 } ),
2324
2325 "div": $.extend( {}, TableTools.buttonBase, {
2326 "sAction": "div",
2327 "sTag": "div",
2328 "sButtonClass": "DTTT_nonbutton",
2329 "sButtonText": "Text button"
2330 } ),
2331
2332 "collection": $.extend( {}, TableTools.buttonBase, {
2333 "sAction": "collection",
2334 "sButtonClass": "DTTT_button_collection",
2335 "sButtonText": "Collection",
2336 "fnClick": function( nButton, oConfig ) {
2337 this._fnCollectionShow(nButton, oConfig);
2338 }
2339 } )
2340 };
2341 /*
2342 * on* callback parameters:
2343 * 1. node - button element
2344 * 2. object - configuration object for this button
2345 * 3. object - ZeroClipboard reference (flash button only)
2346 * 4. string - Returned string from Flash (flash button only - and only on 'complete')
2347 */
2348
2349
2350
2351 /**
2352 * @namespace Classes used by TableTools - allows the styles to be override easily.
2353 * Note that when TableTools initialises it will take a copy of the classes object
2354 * and will use its internal copy for the remainder of its run time.
2355 */
2356 TableTools.classes = {
2357 "container": "DTTT_container",
2358 "buttons": {
2359 "normal": "DTTT_button",
2360 "disabled": "DTTT_disabled"
2361 },
2362 "collection": {
2363 "container": "DTTT_collection",
2364 "background": "DTTT_collection_background",
2365 "buttons": {
2366 "normal": "DTTT_button",
2367 "disabled": "DTTT_disabled"
2368 }
2369 },
2370 "select": {
2371 "table": "DTTT_selectable",
2372 "row": "DTTT_selected"
2373 },
2374 "print": {
2375 "body": "DTTT_Print",
2376 "info": "DTTT_print_info",
2377 "message": "DTTT_PrintMessage"
2378 }
2379 };
2380
2381
2382 /**
2383 * @namespace ThemeRoller classes - built in for compatibility with DataTables'
2384 * bJQueryUI option.
2385 */
2386 TableTools.classes_themeroller = {
2387 "container": "DTTT_container ui-buttonset ui-buttonset-multi",
2388 "buttons": {
2389 "normal": "DTTT_button ui-button ui-state-default"
2390 },
2391 "collection": {
2392 "container": "DTTT_collection ui-buttonset ui-buttonset-multi"
2393 }
2394 };
2395
2396
2397 /**
2398 * @namespace TableTools default settings for initialisation
2399 */
2400 TableTools.DEFAULTS = {
2401 "sSwfPath": "media/swf/copy_csv_xls_pdf.swf",
2402 "sRowSelect": "none",
2403 "sSelectedClass": null,
2404 "fnPreRowSelect": null,
2405 "fnRowSelected": null,
2406 "fnRowDeselected": null,
2407 "aButtons": [ "copy", "csv", "xls", "pdf", "print" ],
2408 "oTags": {
2409 "container": "div",
2410 "button": "a", // We really want to use buttons here, but Firefox and IE ignore the
2411 // click on the Flash element in the button (but not mouse[in|out]).
2412 "liner": "span",
2413 "collection": {
2414 "container": "div",
2415 "button": "a",
2416 "liner": "span"
2417 }
2418 }
2419 };
2420
2421
2422 /**
2423 * Name of this class
2424 * @constant CLASS
2425 * @type String
2426 * @default TableTools
2427 */
2428 TableTools.prototype.CLASS = "TableTools";
2429
2430
2431 /**
2432 * TableTools version
2433 * @constant VERSION
2434 * @type String
2435 * @default See code
2436 */
2437 TableTools.VERSION = "2.1.4";
2438 TableTools.prototype.VERSION = TableTools.VERSION;
2439
2440
2441
2442
2443 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2444 * Initialisation
2445 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2446
2447 /*
2448 * Register a new feature with DataTables
2449 */
2450 if ( typeof $.fn.dataTable == "function" &&
2451 typeof $.fn.dataTableExt.fnVersionCheck == "function" &&
2452 $.fn.dataTableExt.fnVersionCheck('1.9.0') )
2453 {
2454 $.fn.dataTableExt.aoFeatures.push( {
2455 "fnInit": function( oDTSettings ) {
2456 var oOpts = typeof oDTSettings.oInit.oTableTools != 'undefined' ?
2457 oDTSettings.oInit.oTableTools : {};
2458
2459 var oTT = new TableTools( oDTSettings.oInstance, oOpts );
2460 TableTools._aInstances.push( oTT );
2461
2462 return oTT.dom.container;
2463 },
2464 "cFeature": "T",
2465 "sFeature": "TableTools"
2466 } );
2467 }
2468 else
2469 {
2470 alert( "Warning: TableTools 2 requires DataTables 1.9.0 or newer - www.datatables.net/download");
2471 }
2472
2473 $.fn.DataTable.TableTools = TableTools;
2474
2475 })(jQuery, window, document);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20