|
Line 0
Link Here
|
|
|
1 |
/* |
| 2 |
* File: TableTools.js |
| 3 |
* Version: 2.1.5 |
| 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-2013 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 */ |
| 677 |
this.s.dt.aoDestroyCallback.push( { |
| 678 |
"sName": "TableTools", |
| 679 |
"fn": function () { |
| 680 |
$(that.s.dt.nTBody).off( 'click.DTTT_Select', 'tr' ); |
| 681 |
$(that.dom.container).empty(); |
| 682 |
} |
| 683 |
} ); |
| 684 |
}, |
| 685 |
|
| 686 |
|
| 687 |
/** |
| 688 |
* Take the user defined settings and the default settings and combine them. |
| 689 |
* @method _fnCustomiseSettings |
| 690 |
* @param {Object} oOpts Same as TableTools constructor |
| 691 |
* @returns void |
| 692 |
* @private |
| 693 |
*/ |
| 694 |
"_fnCustomiseSettings": function ( oOpts ) |
| 695 |
{ |
| 696 |
/* Is this the master control instance or not? */ |
| 697 |
if ( typeof this.s.dt._TableToolsInit == 'undefined' ) |
| 698 |
{ |
| 699 |
this.s.master = true; |
| 700 |
this.s.dt._TableToolsInit = true; |
| 701 |
} |
| 702 |
|
| 703 |
/* We can use the table node from comparisons to group controls */ |
| 704 |
this.dom.table = this.s.dt.nTable; |
| 705 |
|
| 706 |
/* Clone the defaults and then the user options */ |
| 707 |
this.s.custom = $.extend( {}, TableTools.DEFAULTS, oOpts ); |
| 708 |
|
| 709 |
/* Flash file location */ |
| 710 |
this.s.swfPath = this.s.custom.sSwfPath; |
| 711 |
if ( typeof ZeroClipboard_TableTools != 'undefined' ) |
| 712 |
{ |
| 713 |
ZeroClipboard_TableTools.moviePath = this.s.swfPath; |
| 714 |
} |
| 715 |
|
| 716 |
/* Table row selecting */ |
| 717 |
this.s.select.type = this.s.custom.sRowSelect; |
| 718 |
this.s.select.preRowSelect = this.s.custom.fnPreRowSelect; |
| 719 |
this.s.select.postSelected = this.s.custom.fnRowSelected; |
| 720 |
this.s.select.postDeselected = this.s.custom.fnRowDeselected; |
| 721 |
|
| 722 |
// Backwards compatibility - allow the user to specify a custom class in the initialiser |
| 723 |
if ( this.s.custom.sSelectedClass ) |
| 724 |
{ |
| 725 |
this.classes.select.row = this.s.custom.sSelectedClass; |
| 726 |
} |
| 727 |
|
| 728 |
this.s.tags = this.s.custom.oTags; |
| 729 |
|
| 730 |
/* Button set */ |
| 731 |
this.s.buttonSet = this.s.custom.aButtons; |
| 732 |
}, |
| 733 |
|
| 734 |
|
| 735 |
/** |
| 736 |
* Take the user input arrays and expand them to be fully defined, and then add them to a given |
| 737 |
* DOM element |
| 738 |
* @method _fnButtonDefinations |
| 739 |
* @param {array} buttonSet Set of user defined buttons |
| 740 |
* @param {node} wrapper Node to add the created buttons to |
| 741 |
* @returns void |
| 742 |
* @private |
| 743 |
*/ |
| 744 |
"_fnButtonDefinations": function ( buttonSet, wrapper ) |
| 745 |
{ |
| 746 |
var buttonDef; |
| 747 |
|
| 748 |
for ( var i=0, iLen=buttonSet.length ; i<iLen ; i++ ) |
| 749 |
{ |
| 750 |
if ( typeof buttonSet[i] == "string" ) |
| 751 |
{ |
| 752 |
if ( typeof TableTools.BUTTONS[ buttonSet[i] ] == 'undefined' ) |
| 753 |
{ |
| 754 |
alert( "TableTools: Warning - unknown button type: "+buttonSet[i] ); |
| 755 |
continue; |
| 756 |
} |
| 757 |
buttonDef = $.extend( {}, TableTools.BUTTONS[ buttonSet[i] ], true ); |
| 758 |
} |
| 759 |
else |
| 760 |
{ |
| 761 |
if ( typeof TableTools.BUTTONS[ buttonSet[i].sExtends ] == 'undefined' ) |
| 762 |
{ |
| 763 |
alert( "TableTools: Warning - unknown button type: "+buttonSet[i].sExtends ); |
| 764 |
continue; |
| 765 |
} |
| 766 |
var o = $.extend( {}, TableTools.BUTTONS[ buttonSet[i].sExtends ], true ); |
| 767 |
buttonDef = $.extend( o, buttonSet[i], true ); |
| 768 |
} |
| 769 |
|
| 770 |
wrapper.appendChild( this._fnCreateButton( |
| 771 |
buttonDef, |
| 772 |
$(wrapper).hasClass(this.classes.collection.container) |
| 773 |
) ); |
| 774 |
} |
| 775 |
}, |
| 776 |
|
| 777 |
|
| 778 |
/** |
| 779 |
* Create and configure a TableTools button |
| 780 |
* @method _fnCreateButton |
| 781 |
* @param {Object} oConfig Button configuration object |
| 782 |
* @returns {Node} Button element |
| 783 |
* @private |
| 784 |
*/ |
| 785 |
"_fnCreateButton": function ( oConfig, bCollectionButton ) |
| 786 |
{ |
| 787 |
var nButton = this._fnButtonBase( oConfig, bCollectionButton ); |
| 788 |
|
| 789 |
if ( oConfig.sAction.match(/flash/) ) |
| 790 |
{ |
| 791 |
this._fnFlashConfig( nButton, oConfig ); |
| 792 |
} |
| 793 |
else if ( oConfig.sAction == "text" ) |
| 794 |
{ |
| 795 |
this._fnTextConfig( nButton, oConfig ); |
| 796 |
} |
| 797 |
else if ( oConfig.sAction == "div" ) |
| 798 |
{ |
| 799 |
this._fnTextConfig( nButton, oConfig ); |
| 800 |
} |
| 801 |
else if ( oConfig.sAction == "collection" ) |
| 802 |
{ |
| 803 |
this._fnTextConfig( nButton, oConfig ); |
| 804 |
this._fnCollectionConfig( nButton, oConfig ); |
| 805 |
} |
| 806 |
|
| 807 |
return nButton; |
| 808 |
}, |
| 809 |
|
| 810 |
|
| 811 |
/** |
| 812 |
* Create the DOM needed for the button and apply some base properties. All buttons start here |
| 813 |
* @method _fnButtonBase |
| 814 |
* @param {o} oConfig Button configuration object |
| 815 |
* @returns {Node} DIV element for the button |
| 816 |
* @private |
| 817 |
*/ |
| 818 |
"_fnButtonBase": function ( o, bCollectionButton ) |
| 819 |
{ |
| 820 |
var sTag, sLiner, sClass; |
| 821 |
|
| 822 |
if ( bCollectionButton ) |
| 823 |
{ |
| 824 |
sTag = o.sTag !== "default" ? o.sTag : this.s.tags.collection.button; |
| 825 |
sLiner = o.sLinerTag !== "default" ? o.sLiner : this.s.tags.collection.liner; |
| 826 |
sClass = this.classes.collection.buttons.normal; |
| 827 |
} |
| 828 |
else |
| 829 |
{ |
| 830 |
sTag = o.sTag !== "default" ? o.sTag : this.s.tags.button; |
| 831 |
sLiner = o.sLinerTag !== "default" ? o.sLiner : this.s.tags.liner; |
| 832 |
sClass = this.classes.buttons.normal; |
| 833 |
} |
| 834 |
|
| 835 |
var |
| 836 |
nButton = document.createElement( sTag ), |
| 837 |
nSpan = document.createElement( sLiner ), |
| 838 |
masterS = this._fnGetMasterSettings(); |
| 839 |
|
| 840 |
nButton.className = sClass+" "+o.sButtonClass; |
| 841 |
nButton.setAttribute('id', "ToolTables_"+this.s.dt.sInstance+"_"+masterS.buttonCounter ); |
| 842 |
nButton.appendChild( nSpan ); |
| 843 |
nSpan.innerHTML = o.sButtonText; |
| 844 |
|
| 845 |
masterS.buttonCounter++; |
| 846 |
|
| 847 |
return nButton; |
| 848 |
}, |
| 849 |
|
| 850 |
|
| 851 |
/** |
| 852 |
* Get the settings object for the master instance. When more than one TableTools instance is |
| 853 |
* assigned to a DataTable, only one of them can be the 'master' (for the select rows). As such, |
| 854 |
* we will typically want to interact with that master for global properties. |
| 855 |
* @method _fnGetMasterSettings |
| 856 |
* @returns {Object} TableTools settings object |
| 857 |
* @private |
| 858 |
*/ |
| 859 |
"_fnGetMasterSettings": function () |
| 860 |
{ |
| 861 |
if ( this.s.master ) |
| 862 |
{ |
| 863 |
return this.s; |
| 864 |
} |
| 865 |
else |
| 866 |
{ |
| 867 |
/* Look for the master which has the same DT as this one */ |
| 868 |
var instances = TableTools._aInstances; |
| 869 |
for ( var i=0, iLen=instances.length ; i<iLen ; i++ ) |
| 870 |
{ |
| 871 |
if ( this.dom.table == instances[i].s.dt.nTable ) |
| 872 |
{ |
| 873 |
return instances[i].s; |
| 874 |
} |
| 875 |
} |
| 876 |
} |
| 877 |
}, |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 882 |
* Button collection functions |
| 883 |
*/ |
| 884 |
|
| 885 |
/** |
| 886 |
* Create a collection button, when activated will present a drop down list of other buttons |
| 887 |
* @param {Node} nButton Button to use for the collection activation |
| 888 |
* @param {Object} oConfig Button configuration object |
| 889 |
* @returns void |
| 890 |
* @private |
| 891 |
*/ |
| 892 |
"_fnCollectionConfig": function ( nButton, oConfig ) |
| 893 |
{ |
| 894 |
var nHidden = document.createElement( this.s.tags.collection.container ); |
| 895 |
nHidden.style.display = "none"; |
| 896 |
nHidden.className = this.classes.collection.container; |
| 897 |
oConfig._collection = nHidden; |
| 898 |
document.body.appendChild( nHidden ); |
| 899 |
|
| 900 |
this._fnButtonDefinations( oConfig.aButtons, nHidden ); |
| 901 |
}, |
| 902 |
|
| 903 |
|
| 904 |
/** |
| 905 |
* Show a button collection |
| 906 |
* @param {Node} nButton Button to use for the collection |
| 907 |
* @param {Object} oConfig Button configuration object |
| 908 |
* @returns void |
| 909 |
* @private |
| 910 |
*/ |
| 911 |
"_fnCollectionShow": function ( nButton, oConfig ) |
| 912 |
{ |
| 913 |
var |
| 914 |
that = this, |
| 915 |
oPos = $(nButton).offset(), |
| 916 |
nHidden = oConfig._collection, |
| 917 |
iDivX = oPos.left, |
| 918 |
iDivY = oPos.top + $(nButton).outerHeight(), |
| 919 |
iWinHeight = $(window).height(), iDocHeight = $(document).height(), |
| 920 |
iWinWidth = $(window).width(), iDocWidth = $(document).width(); |
| 921 |
|
| 922 |
nHidden.style.position = "absolute"; |
| 923 |
nHidden.style.left = iDivX+"px"; |
| 924 |
nHidden.style.top = iDivY+"px"; |
| 925 |
nHidden.style.display = "block"; |
| 926 |
$(nHidden).css('opacity',0); |
| 927 |
|
| 928 |
var nBackground = document.createElement('div'); |
| 929 |
nBackground.style.position = "absolute"; |
| 930 |
nBackground.style.left = "0px"; |
| 931 |
nBackground.style.top = "0px"; |
| 932 |
nBackground.style.height = ((iWinHeight>iDocHeight)? iWinHeight : iDocHeight) +"px"; |
| 933 |
nBackground.style.width = ((iWinWidth>iDocWidth)? iWinWidth : iDocWidth) +"px"; |
| 934 |
nBackground.className = this.classes.collection.background; |
| 935 |
$(nBackground).css('opacity',0); |
| 936 |
|
| 937 |
document.body.appendChild( nBackground ); |
| 938 |
document.body.appendChild( nHidden ); |
| 939 |
|
| 940 |
/* Visual corrections to try and keep the collection visible */ |
| 941 |
var iDivWidth = $(nHidden).outerWidth(); |
| 942 |
var iDivHeight = $(nHidden).outerHeight(); |
| 943 |
|
| 944 |
if ( iDivX + iDivWidth > iDocWidth ) |
| 945 |
{ |
| 946 |
nHidden.style.left = (iDocWidth-iDivWidth)+"px"; |
| 947 |
} |
| 948 |
|
| 949 |
if ( iDivY + iDivHeight > iDocHeight ) |
| 950 |
{ |
| 951 |
nHidden.style.top = (iDivY-iDivHeight-$(nButton).outerHeight())+"px"; |
| 952 |
} |
| 953 |
|
| 954 |
this.dom.collection.collection = nHidden; |
| 955 |
this.dom.collection.background = nBackground; |
| 956 |
|
| 957 |
/* This results in a very small delay for the end user but it allows the animation to be |
| 958 |
* much smoother. If you don't want the animation, then the setTimeout can be removed |
| 959 |
*/ |
| 960 |
setTimeout( function () { |
| 961 |
$(nHidden).animate({"opacity": 1}, 500); |
| 962 |
$(nBackground).animate({"opacity": 0.25}, 500); |
| 963 |
}, 10 ); |
| 964 |
|
| 965 |
/* Resize the buttons to the Flash contents fit */ |
| 966 |
this.fnResizeButtons(); |
| 967 |
|
| 968 |
/* Event handler to remove the collection display */ |
| 969 |
$(nBackground).click( function () { |
| 970 |
that._fnCollectionHide.call( that, null, null ); |
| 971 |
} ); |
| 972 |
}, |
| 973 |
|
| 974 |
|
| 975 |
/** |
| 976 |
* Hide a button collection |
| 977 |
* @param {Node} nButton Button to use for the collection |
| 978 |
* @param {Object} oConfig Button configuration object |
| 979 |
* @returns void |
| 980 |
* @private |
| 981 |
*/ |
| 982 |
"_fnCollectionHide": function ( nButton, oConfig ) |
| 983 |
{ |
| 984 |
if ( oConfig !== null && oConfig.sExtends == 'collection' ) |
| 985 |
{ |
| 986 |
return; |
| 987 |
} |
| 988 |
|
| 989 |
if ( this.dom.collection.collection !== null ) |
| 990 |
{ |
| 991 |
$(this.dom.collection.collection).animate({"opacity": 0}, 500, function (e) { |
| 992 |
this.style.display = "none"; |
| 993 |
} ); |
| 994 |
|
| 995 |
$(this.dom.collection.background).animate({"opacity": 0}, 500, function (e) { |
| 996 |
this.parentNode.removeChild( this ); |
| 997 |
} ); |
| 998 |
|
| 999 |
this.dom.collection.collection = null; |
| 1000 |
this.dom.collection.background = null; |
| 1001 |
} |
| 1002 |
}, |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 1007 |
* Row selection functions |
| 1008 |
*/ |
| 1009 |
|
| 1010 |
/** |
| 1011 |
* Add event handlers to a table to allow for row selection |
| 1012 |
* @method _fnRowSelectConfig |
| 1013 |
* @returns void |
| 1014 |
* @private |
| 1015 |
*/ |
| 1016 |
"_fnRowSelectConfig": function () |
| 1017 |
{ |
| 1018 |
if ( this.s.master ) |
| 1019 |
{ |
| 1020 |
var |
| 1021 |
that = this, |
| 1022 |
i, iLen, |
| 1023 |
dt = this.s.dt, |
| 1024 |
aoOpenRows = this.s.dt.aoOpenRows; |
| 1025 |
|
| 1026 |
$(dt.nTable).addClass( this.classes.select.table ); |
| 1027 |
|
| 1028 |
$(dt.nTBody).on( 'click.DTTT_Select', 'tr', function(e) { |
| 1029 |
/* Sub-table must be ignored (odd that the selector won't do this with >) */ |
| 1030 |
if ( this.parentNode != dt.nTBody ) |
| 1031 |
{ |
| 1032 |
return; |
| 1033 |
} |
| 1034 |
|
| 1035 |
/* Check that we are actually working with a DataTables controlled row */ |
| 1036 |
if ( dt.oInstance.fnGetData(this) === null ) |
| 1037 |
{ |
| 1038 |
return; |
| 1039 |
} |
| 1040 |
|
| 1041 |
if ( that.fnIsSelected( this ) ) |
| 1042 |
{ |
| 1043 |
that._fnRowDeselect( this, e ); |
| 1044 |
} |
| 1045 |
else if ( that.s.select.type == "single" ) |
| 1046 |
{ |
| 1047 |
that.fnSelectNone(); |
| 1048 |
that._fnRowSelect( this, e ); |
| 1049 |
} |
| 1050 |
else if ( that.s.select.type == "multi" ) |
| 1051 |
{ |
| 1052 |
that._fnRowSelect( this, e ); |
| 1053 |
} |
| 1054 |
} ); |
| 1055 |
|
| 1056 |
// Bind a listener to the DataTable for when new rows are created. |
| 1057 |
// This allows rows to be visually selected when they should be and |
| 1058 |
// deferred rendering is used. |
| 1059 |
dt.oApi._fnCallbackReg( dt, 'aoRowCreatedCallback', function (tr, data, index) { |
| 1060 |
if ( dt.aoData[index]._DTTT_selected ) { |
| 1061 |
$(tr).addClass( that.classes.select.row ); |
| 1062 |
} |
| 1063 |
}, 'TableTools-SelectAll' ); |
| 1064 |
} |
| 1065 |
}, |
| 1066 |
|
| 1067 |
/** |
| 1068 |
* Select rows |
| 1069 |
* @param {*} src Rows to select - see _fnSelectData for a description of valid inputs |
| 1070 |
* @private |
| 1071 |
*/ |
| 1072 |
"_fnRowSelect": function ( src, e ) |
| 1073 |
{ |
| 1074 |
var |
| 1075 |
that = this, |
| 1076 |
data = this._fnSelectData( src ), |
| 1077 |
firstTr = data.length===0 ? null : data[0].nTr, |
| 1078 |
anSelected = [], |
| 1079 |
i, len; |
| 1080 |
|
| 1081 |
// Get all the rows that will be selected |
| 1082 |
for ( i=0, len=data.length ; i<len ; i++ ) |
| 1083 |
{ |
| 1084 |
if ( data[i].nTr ) |
| 1085 |
{ |
| 1086 |
anSelected.push( data[i].nTr ); |
| 1087 |
} |
| 1088 |
} |
| 1089 |
|
| 1090 |
// User defined pre-selection function |
| 1091 |
if ( this.s.select.preRowSelect !== null && !this.s.select.preRowSelect.call(this, e, anSelected, true) ) |
| 1092 |
{ |
| 1093 |
return; |
| 1094 |
} |
| 1095 |
|
| 1096 |
// Mark them as selected |
| 1097 |
for ( i=0, len=data.length ; i<len ; i++ ) |
| 1098 |
{ |
| 1099 |
data[i]._DTTT_selected = true; |
| 1100 |
|
| 1101 |
if ( data[i].nTr ) |
| 1102 |
{ |
| 1103 |
$(data[i].nTr).addClass( that.classes.select.row ); |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
// Post-selection function |
| 1108 |
if ( this.s.select.postSelected !== null ) |
| 1109 |
{ |
| 1110 |
this.s.select.postSelected.call( this, anSelected ); |
| 1111 |
} |
| 1112 |
|
| 1113 |
TableTools._fnEventDispatch( this, 'select', anSelected, true ); |
| 1114 |
}, |
| 1115 |
|
| 1116 |
/** |
| 1117 |
* Deselect rows |
| 1118 |
* @param {*} src Rows to deselect - see _fnSelectData for a description of valid inputs |
| 1119 |
* @private |
| 1120 |
*/ |
| 1121 |
"_fnRowDeselect": function ( src, e ) |
| 1122 |
{ |
| 1123 |
var |
| 1124 |
that = this, |
| 1125 |
data = this._fnSelectData( src ), |
| 1126 |
firstTr = data.length===0 ? null : data[0].nTr, |
| 1127 |
anDeselectedTrs = [], |
| 1128 |
i, len; |
| 1129 |
|
| 1130 |
// Get all the rows that will be deselected |
| 1131 |
for ( i=0, len=data.length ; i<len ; i++ ) |
| 1132 |
{ |
| 1133 |
if ( data[i].nTr ) |
| 1134 |
{ |
| 1135 |
anDeselectedTrs.push( data[i].nTr ); |
| 1136 |
} |
| 1137 |
} |
| 1138 |
|
| 1139 |
// User defined pre-selection function |
| 1140 |
if ( this.s.select.preRowSelect !== null && !this.s.select.preRowSelect.call(this, e, anDeselectedTrs, false) ) |
| 1141 |
{ |
| 1142 |
return; |
| 1143 |
} |
| 1144 |
|
| 1145 |
// Mark them as deselected |
| 1146 |
for ( i=0, len=data.length ; i<len ; i++ ) |
| 1147 |
{ |
| 1148 |
data[i]._DTTT_selected = false; |
| 1149 |
|
| 1150 |
if ( data[i].nTr ) |
| 1151 |
{ |
| 1152 |
$(data[i].nTr).removeClass( that.classes.select.row ); |
| 1153 |
} |
| 1154 |
} |
| 1155 |
|
| 1156 |
// Post-deselection function |
| 1157 |
if ( this.s.select.postDeselected !== null ) |
| 1158 |
{ |
| 1159 |
this.s.select.postDeselected.call( this, anDeselectedTrs ); |
| 1160 |
} |
| 1161 |
|
| 1162 |
TableTools._fnEventDispatch( this, 'select', anDeselectedTrs, false ); |
| 1163 |
}, |
| 1164 |
|
| 1165 |
/** |
| 1166 |
* Take a data source for row selection and convert it into aoData points for the DT |
| 1167 |
* @param {*} src Can be a single DOM TR node, an array of TR nodes (including a |
| 1168 |
* a jQuery object), a single aoData point from DataTables, an array of aoData |
| 1169 |
* points or an array of aoData indexes |
| 1170 |
* @returns {array} An array of aoData points |
| 1171 |
*/ |
| 1172 |
"_fnSelectData": function ( src ) |
| 1173 |
{ |
| 1174 |
var out = [], pos, i, iLen; |
| 1175 |
|
| 1176 |
if ( src.nodeName ) |
| 1177 |
{ |
| 1178 |
// Single node |
| 1179 |
pos = this.s.dt.oInstance.fnGetPosition( src ); |
| 1180 |
out.push( this.s.dt.aoData[pos] ); |
| 1181 |
} |
| 1182 |
else if ( typeof src.length !== 'undefined' ) |
| 1183 |
{ |
| 1184 |
// jQuery object or an array of nodes, or aoData points |
| 1185 |
for ( i=0, iLen=src.length ; i<iLen ; i++ ) |
| 1186 |
{ |
| 1187 |
if ( src[i].nodeName ) |
| 1188 |
{ |
| 1189 |
pos = this.s.dt.oInstance.fnGetPosition( src[i] ); |
| 1190 |
out.push( this.s.dt.aoData[pos] ); |
| 1191 |
} |
| 1192 |
else if ( typeof src[i] === 'number' ) |
| 1193 |
{ |
| 1194 |
out.push( this.s.dt.aoData[ src[i] ] ); |
| 1195 |
} |
| 1196 |
else |
| 1197 |
{ |
| 1198 |
out.push( src[i] ); |
| 1199 |
} |
| 1200 |
} |
| 1201 |
|
| 1202 |
return out; |
| 1203 |
} |
| 1204 |
else |
| 1205 |
{ |
| 1206 |
// A single aoData point |
| 1207 |
out.push( src ); |
| 1208 |
} |
| 1209 |
|
| 1210 |
return out; |
| 1211 |
}, |
| 1212 |
|
| 1213 |
|
| 1214 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 1215 |
* Text button functions |
| 1216 |
*/ |
| 1217 |
|
| 1218 |
/** |
| 1219 |
* Configure a text based button for interaction events |
| 1220 |
* @method _fnTextConfig |
| 1221 |
* @param {Node} nButton Button element which is being considered |
| 1222 |
* @param {Object} oConfig Button configuration object |
| 1223 |
* @returns void |
| 1224 |
* @private |
| 1225 |
*/ |
| 1226 |
"_fnTextConfig": function ( nButton, oConfig ) |
| 1227 |
{ |
| 1228 |
var that = this; |
| 1229 |
|
| 1230 |
if ( oConfig.fnInit !== null ) |
| 1231 |
{ |
| 1232 |
oConfig.fnInit.call( this, nButton, oConfig ); |
| 1233 |
} |
| 1234 |
|
| 1235 |
if ( oConfig.sToolTip !== "" ) |
| 1236 |
{ |
| 1237 |
nButton.title = oConfig.sToolTip; |
| 1238 |
} |
| 1239 |
|
| 1240 |
$(nButton).hover( function () { |
| 1241 |
if ( oConfig.fnMouseover !== null ) |
| 1242 |
{ |
| 1243 |
oConfig.fnMouseover.call( this, nButton, oConfig, null ); |
| 1244 |
} |
| 1245 |
}, function () { |
| 1246 |
if ( oConfig.fnMouseout !== null ) |
| 1247 |
{ |
| 1248 |
oConfig.fnMouseout.call( this, nButton, oConfig, null ); |
| 1249 |
} |
| 1250 |
} ); |
| 1251 |
|
| 1252 |
if ( oConfig.fnSelect !== null ) |
| 1253 |
{ |
| 1254 |
TableTools._fnEventListen( this, 'select', function (n) { |
| 1255 |
oConfig.fnSelect.call( that, nButton, oConfig, n ); |
| 1256 |
} ); |
| 1257 |
} |
| 1258 |
|
| 1259 |
$(nButton).click( function (e) { |
| 1260 |
//e.preventDefault(); |
| 1261 |
|
| 1262 |
if ( oConfig.fnClick !== null ) |
| 1263 |
{ |
| 1264 |
oConfig.fnClick.call( that, nButton, oConfig, null, e ); |
| 1265 |
} |
| 1266 |
|
| 1267 |
/* Provide a complete function to match the behaviour of the flash elements */ |
| 1268 |
if ( oConfig.fnComplete !== null ) |
| 1269 |
{ |
| 1270 |
oConfig.fnComplete.call( that, nButton, oConfig, null, null ); |
| 1271 |
} |
| 1272 |
|
| 1273 |
that._fnCollectionHide( nButton, oConfig ); |
| 1274 |
} ); |
| 1275 |
}, |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 1280 |
* Flash button functions |
| 1281 |
*/ |
| 1282 |
|
| 1283 |
/** |
| 1284 |
* Configure a flash based button for interaction events |
| 1285 |
* @method _fnFlashConfig |
| 1286 |
* @param {Node} nButton Button element which is being considered |
| 1287 |
* @param {o} oConfig Button configuration object |
| 1288 |
* @returns void |
| 1289 |
* @private |
| 1290 |
*/ |
| 1291 |
"_fnFlashConfig": function ( nButton, oConfig ) |
| 1292 |
{ |
| 1293 |
var that = this; |
| 1294 |
var flash = new ZeroClipboard_TableTools.Client(); |
| 1295 |
|
| 1296 |
if ( oConfig.fnInit !== null ) |
| 1297 |
{ |
| 1298 |
oConfig.fnInit.call( this, nButton, oConfig ); |
| 1299 |
} |
| 1300 |
|
| 1301 |
flash.setHandCursor( true ); |
| 1302 |
|
| 1303 |
if ( oConfig.sAction == "flash_save" ) |
| 1304 |
{ |
| 1305 |
flash.setAction( 'save' ); |
| 1306 |
flash.setCharSet( (oConfig.sCharSet=="utf16le") ? 'UTF16LE' : 'UTF8' ); |
| 1307 |
flash.setBomInc( oConfig.bBomInc ); |
| 1308 |
flash.setFileName( oConfig.sFileName.replace('*', this.fnGetTitle(oConfig)) ); |
| 1309 |
} |
| 1310 |
else if ( oConfig.sAction == "flash_pdf" ) |
| 1311 |
{ |
| 1312 |
flash.setAction( 'pdf' ); |
| 1313 |
flash.setFileName( oConfig.sFileName.replace('*', this.fnGetTitle(oConfig)) ); |
| 1314 |
} |
| 1315 |
else |
| 1316 |
{ |
| 1317 |
flash.setAction( 'copy' ); |
| 1318 |
} |
| 1319 |
|
| 1320 |
flash.addEventListener('mouseOver', function(client) { |
| 1321 |
if ( oConfig.fnMouseover !== null ) |
| 1322 |
{ |
| 1323 |
oConfig.fnMouseover.call( that, nButton, oConfig, flash ); |
| 1324 |
} |
| 1325 |
} ); |
| 1326 |
|
| 1327 |
flash.addEventListener('mouseOut', function(client) { |
| 1328 |
if ( oConfig.fnMouseout !== null ) |
| 1329 |
{ |
| 1330 |
oConfig.fnMouseout.call( that, nButton, oConfig, flash ); |
| 1331 |
} |
| 1332 |
} ); |
| 1333 |
|
| 1334 |
flash.addEventListener('mouseDown', function(client) { |
| 1335 |
if ( oConfig.fnClick !== null ) |
| 1336 |
{ |
| 1337 |
oConfig.fnClick.call( that, nButton, oConfig, flash ); |
| 1338 |
} |
| 1339 |
} ); |
| 1340 |
|
| 1341 |
flash.addEventListener('complete', function (client, text) { |
| 1342 |
if ( oConfig.fnComplete !== null ) |
| 1343 |
{ |
| 1344 |
oConfig.fnComplete.call( that, nButton, oConfig, flash, text ); |
| 1345 |
} |
| 1346 |
that._fnCollectionHide( nButton, oConfig ); |
| 1347 |
} ); |
| 1348 |
|
| 1349 |
this._fnFlashGlue( flash, nButton, oConfig.sToolTip ); |
| 1350 |
}, |
| 1351 |
|
| 1352 |
|
| 1353 |
/** |
| 1354 |
* Wait until the id is in the DOM before we "glue" the swf. Note that this function will call |
| 1355 |
* itself (using setTimeout) until it completes successfully |
| 1356 |
* @method _fnFlashGlue |
| 1357 |
* @param {Object} clip Zero clipboard object |
| 1358 |
* @param {Node} node node to glue swf to |
| 1359 |
* @param {String} text title of the flash movie |
| 1360 |
* @returns void |
| 1361 |
* @private |
| 1362 |
*/ |
| 1363 |
"_fnFlashGlue": function ( flash, node, text ) |
| 1364 |
{ |
| 1365 |
var that = this; |
| 1366 |
var id = node.getAttribute('id'); |
| 1367 |
|
| 1368 |
if ( document.getElementById(id) ) |
| 1369 |
{ |
| 1370 |
flash.glue( node, text ); |
| 1371 |
} |
| 1372 |
else |
| 1373 |
{ |
| 1374 |
setTimeout( function () { |
| 1375 |
that._fnFlashGlue( flash, node, text ); |
| 1376 |
}, 100 ); |
| 1377 |
} |
| 1378 |
}, |
| 1379 |
|
| 1380 |
|
| 1381 |
/** |
| 1382 |
* Set the text for the flash clip to deal with |
| 1383 |
* |
| 1384 |
* This function is required for large information sets. There is a limit on the |
| 1385 |
* amount of data that can be transferred between Javascript and Flash in a single call, so |
| 1386 |
* we use this method to build up the text in Flash by sending over chunks. It is estimated |
| 1387 |
* that the data limit is around 64k, although it is undocumented, and appears to be different |
| 1388 |
* between different flash versions. We chunk at 8KiB. |
| 1389 |
* @method _fnFlashSetText |
| 1390 |
* @param {Object} clip the ZeroClipboard object |
| 1391 |
* @param {String} sData the data to be set |
| 1392 |
* @returns void |
| 1393 |
* @private |
| 1394 |
*/ |
| 1395 |
"_fnFlashSetText": function ( clip, sData ) |
| 1396 |
{ |
| 1397 |
var asData = this._fnChunkData( sData, 8192 ); |
| 1398 |
|
| 1399 |
clip.clearText(); |
| 1400 |
for ( var i=0, iLen=asData.length ; i<iLen ; i++ ) |
| 1401 |
{ |
| 1402 |
clip.appendText( asData[i] ); |
| 1403 |
} |
| 1404 |
}, |
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 1409 |
* Data retrieval functions |
| 1410 |
*/ |
| 1411 |
|
| 1412 |
/** |
| 1413 |
* Convert the mixed columns variable into a boolean array the same size as the columns, which |
| 1414 |
* indicates which columns we want to include |
| 1415 |
* @method _fnColumnTargets |
| 1416 |
* @param {String|Array} mColumns The columns to be included in data retrieval. If a string |
| 1417 |
* then it can take the value of "visible" or "hidden" (to include all visible or |
| 1418 |
* hidden columns respectively). Or an array of column indexes |
| 1419 |
* @returns {Array} A boolean array the length of the columns of the table, which each value |
| 1420 |
* indicating if the column is to be included or not |
| 1421 |
* @private |
| 1422 |
*/ |
| 1423 |
"_fnColumnTargets": function ( mColumns ) |
| 1424 |
{ |
| 1425 |
var aColumns = []; |
| 1426 |
var dt = this.s.dt; |
| 1427 |
|
| 1428 |
if ( typeof mColumns == "object" ) |
| 1429 |
{ |
| 1430 |
for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ ) |
| 1431 |
{ |
| 1432 |
aColumns.push( false ); |
| 1433 |
} |
| 1434 |
|
| 1435 |
for ( i=0, iLen=mColumns.length ; i<iLen ; i++ ) |
| 1436 |
{ |
| 1437 |
aColumns[ mColumns[i] ] = true; |
| 1438 |
} |
| 1439 |
} |
| 1440 |
else if ( mColumns == "visible" ) |
| 1441 |
{ |
| 1442 |
for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ ) |
| 1443 |
{ |
| 1444 |
aColumns.push( dt.aoColumns[i].bVisible ? true : false ); |
| 1445 |
} |
| 1446 |
} |
| 1447 |
else if ( mColumns == "hidden" ) |
| 1448 |
{ |
| 1449 |
for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ ) |
| 1450 |
{ |
| 1451 |
aColumns.push( dt.aoColumns[i].bVisible ? false : true ); |
| 1452 |
} |
| 1453 |
} |
| 1454 |
else if ( mColumns == "sortable" ) |
| 1455 |
{ |
| 1456 |
for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ ) |
| 1457 |
{ |
| 1458 |
aColumns.push( dt.aoColumns[i].bSortable ? true : false ); |
| 1459 |
} |
| 1460 |
} |
| 1461 |
else /* all */ |
| 1462 |
{ |
| 1463 |
for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ ) |
| 1464 |
{ |
| 1465 |
aColumns.push( true ); |
| 1466 |
} |
| 1467 |
} |
| 1468 |
|
| 1469 |
return aColumns; |
| 1470 |
}, |
| 1471 |
|
| 1472 |
|
| 1473 |
/** |
| 1474 |
* New line character(s) depend on the platforms |
| 1475 |
* @method method |
| 1476 |
* @param {Object} oConfig Button configuration object - only interested in oConfig.sNewLine |
| 1477 |
* @returns {String} Newline character |
| 1478 |
*/ |
| 1479 |
"_fnNewline": function ( oConfig ) |
| 1480 |
{ |
| 1481 |
if ( oConfig.sNewLine == "auto" ) |
| 1482 |
{ |
| 1483 |
return navigator.userAgent.match(/Windows/) ? "\r\n" : "\n"; |
| 1484 |
} |
| 1485 |
else |
| 1486 |
{ |
| 1487 |
return oConfig.sNewLine; |
| 1488 |
} |
| 1489 |
}, |
| 1490 |
|
| 1491 |
|
| 1492 |
/** |
| 1493 |
* Get data from DataTables' internals and format it for output |
| 1494 |
* @method _fnGetDataTablesData |
| 1495 |
* @param {Object} oConfig Button configuration object |
| 1496 |
* @param {String} oConfig.sFieldBoundary Field boundary for the data cells in the string |
| 1497 |
* @param {String} oConfig.sFieldSeperator Field separator for the data cells |
| 1498 |
* @param {String} oConfig.sNewline New line options |
| 1499 |
* @param {Mixed} oConfig.mColumns Which columns should be included in the output |
| 1500 |
* @param {Boolean} oConfig.bHeader Include the header |
| 1501 |
* @param {Boolean} oConfig.bFooter Include the footer |
| 1502 |
* @param {Boolean} oConfig.bSelectedOnly Include only the selected rows in the output |
| 1503 |
* @returns {String} Concatenated string of data |
| 1504 |
* @private |
| 1505 |
*/ |
| 1506 |
"_fnGetDataTablesData": function ( oConfig ) |
| 1507 |
{ |
| 1508 |
var i, iLen, j, jLen; |
| 1509 |
var aRow, aData=[], sLoopData='', arr; |
| 1510 |
var dt = this.s.dt, tr, child; |
| 1511 |
var regex = new RegExp(oConfig.sFieldBoundary, "g"); /* Do it here for speed */ |
| 1512 |
var aColumnsInc = this._fnColumnTargets( oConfig.mColumns ); |
| 1513 |
var bSelectedOnly = (typeof oConfig.bSelectedOnly != 'undefined') ? oConfig.bSelectedOnly : false; |
| 1514 |
|
| 1515 |
/* |
| 1516 |
* Header |
| 1517 |
*/ |
| 1518 |
if ( oConfig.bHeader ) |
| 1519 |
{ |
| 1520 |
aRow = []; |
| 1521 |
|
| 1522 |
for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ ) |
| 1523 |
{ |
| 1524 |
if ( aColumnsInc[i] ) |
| 1525 |
{ |
| 1526 |
sLoopData = dt.aoColumns[i].sTitle.replace(/\n/g," ").replace( /<.*?>/g, "" ).replace(/^\s+|\s+$/g,""); |
| 1527 |
sLoopData = this._fnHtmlDecode( sLoopData ); |
| 1528 |
|
| 1529 |
aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) ); |
| 1530 |
} |
| 1531 |
} |
| 1532 |
|
| 1533 |
aData.push( aRow.join(oConfig.sFieldSeperator) ); |
| 1534 |
} |
| 1535 |
|
| 1536 |
/* |
| 1537 |
* Body |
| 1538 |
*/ |
| 1539 |
var aDataIndex = dt.aiDisplay; |
| 1540 |
var aSelected = this.fnGetSelected(); |
| 1541 |
if ( this.s.select.type !== "none" && bSelectedOnly && aSelected.length !== 0 ) |
| 1542 |
{ |
| 1543 |
aDataIndex = []; |
| 1544 |
for ( i=0, iLen=aSelected.length ; i<iLen ; i++ ) |
| 1545 |
{ |
| 1546 |
aDataIndex.push( dt.oInstance.fnGetPosition( aSelected[i] ) ); |
| 1547 |
} |
| 1548 |
} |
| 1549 |
|
| 1550 |
for ( j=0, jLen=aDataIndex.length ; j<jLen ; j++ ) |
| 1551 |
{ |
| 1552 |
tr = dt.aoData[ aDataIndex[j] ].nTr; |
| 1553 |
aRow = []; |
| 1554 |
|
| 1555 |
/* Columns */ |
| 1556 |
for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ ) |
| 1557 |
{ |
| 1558 |
if ( aColumnsInc[i] ) |
| 1559 |
{ |
| 1560 |
/* Convert to strings (with small optimisation) */ |
| 1561 |
var mTypeData = dt.oApi._fnGetCellData( dt, aDataIndex[j], i, 'display' ); |
| 1562 |
if ( oConfig.fnCellRender ) |
| 1563 |
{ |
| 1564 |
sLoopData = oConfig.fnCellRender( mTypeData, i, tr, aDataIndex[j] )+""; |
| 1565 |
} |
| 1566 |
else if ( typeof mTypeData == "string" ) |
| 1567 |
{ |
| 1568 |
/* Strip newlines, replace img tags with alt attr. and finally strip html... */ |
| 1569 |
sLoopData = mTypeData.replace(/\n/g," "); |
| 1570 |
sLoopData = |
| 1571 |
sLoopData.replace(/<img.*?\s+alt\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s>]+)).*?>/gi, |
| 1572 |
'$1$2$3'); |
| 1573 |
sLoopData = sLoopData.replace( /<.*?>/g, "" ); |
| 1574 |
} |
| 1575 |
else |
| 1576 |
{ |
| 1577 |
sLoopData = mTypeData+""; |
| 1578 |
} |
| 1579 |
|
| 1580 |
/* Trim and clean the data */ |
| 1581 |
sLoopData = sLoopData.replace(/^\s+/, '').replace(/\s+$/, ''); |
| 1582 |
sLoopData = this._fnHtmlDecode( sLoopData ); |
| 1583 |
|
| 1584 |
/* Bound it and add it to the total data */ |
| 1585 |
aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) ); |
| 1586 |
} |
| 1587 |
} |
| 1588 |
|
| 1589 |
aData.push( aRow.join(oConfig.sFieldSeperator) ); |
| 1590 |
|
| 1591 |
/* Details rows from fnOpen */ |
| 1592 |
if ( oConfig.bOpenRows ) |
| 1593 |
{ |
| 1594 |
arr = $.grep(dt.aoOpenRows, function(o) { return o.nParent === tr; }); |
| 1595 |
|
| 1596 |
if ( arr.length === 1 ) |
| 1597 |
{ |
| 1598 |
sLoopData = this._fnBoundData( $('td', arr[0].nTr).html(), oConfig.sFieldBoundary, regex ); |
| 1599 |
aData.push( sLoopData ); |
| 1600 |
} |
| 1601 |
} |
| 1602 |
} |
| 1603 |
|
| 1604 |
/* |
| 1605 |
* Footer |
| 1606 |
*/ |
| 1607 |
if ( oConfig.bFooter && dt.nTFoot !== null ) |
| 1608 |
{ |
| 1609 |
aRow = []; |
| 1610 |
|
| 1611 |
for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ ) |
| 1612 |
{ |
| 1613 |
if ( aColumnsInc[i] && dt.aoColumns[i].nTf !== null ) |
| 1614 |
{ |
| 1615 |
sLoopData = dt.aoColumns[i].nTf.innerHTML.replace(/\n/g," ").replace( /<.*?>/g, "" ); |
| 1616 |
sLoopData = this._fnHtmlDecode( sLoopData ); |
| 1617 |
|
| 1618 |
aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) ); |
| 1619 |
} |
| 1620 |
} |
| 1621 |
|
| 1622 |
aData.push( aRow.join(oConfig.sFieldSeperator) ); |
| 1623 |
} |
| 1624 |
|
| 1625 |
_sLastData = aData.join( this._fnNewline(oConfig) ); |
| 1626 |
return _sLastData; |
| 1627 |
}, |
| 1628 |
|
| 1629 |
|
| 1630 |
/** |
| 1631 |
* Wrap data up with a boundary string |
| 1632 |
* @method _fnBoundData |
| 1633 |
* @param {String} sData data to bound |
| 1634 |
* @param {String} sBoundary bounding char(s) |
| 1635 |
* @param {RegExp} regex search for the bounding chars - constructed outside for efficiency |
| 1636 |
* in the loop |
| 1637 |
* @returns {String} bound data |
| 1638 |
* @private |
| 1639 |
*/ |
| 1640 |
"_fnBoundData": function ( sData, sBoundary, regex ) |
| 1641 |
{ |
| 1642 |
if ( sBoundary === "" ) |
| 1643 |
{ |
| 1644 |
return sData; |
| 1645 |
} |
| 1646 |
else |
| 1647 |
{ |
| 1648 |
return sBoundary + sData.replace(regex, sBoundary+sBoundary) + sBoundary; |
| 1649 |
} |
| 1650 |
}, |
| 1651 |
|
| 1652 |
|
| 1653 |
/** |
| 1654 |
* Break a string up into an array of smaller strings |
| 1655 |
* @method _fnChunkData |
| 1656 |
* @param {String} sData data to be broken up |
| 1657 |
* @param {Int} iSize chunk size |
| 1658 |
* @returns {Array} String array of broken up text |
| 1659 |
* @private |
| 1660 |
*/ |
| 1661 |
"_fnChunkData": function ( sData, iSize ) |
| 1662 |
{ |
| 1663 |
var asReturn = []; |
| 1664 |
var iStrlen = sData.length; |
| 1665 |
|
| 1666 |
for ( var i=0 ; i<iStrlen ; i+=iSize ) |
| 1667 |
{ |
| 1668 |
if ( i+iSize < iStrlen ) |
| 1669 |
{ |
| 1670 |
asReturn.push( sData.substring( i, i+iSize ) ); |
| 1671 |
} |
| 1672 |
else |
| 1673 |
{ |
| 1674 |
asReturn.push( sData.substring( i, iStrlen ) ); |
| 1675 |
} |
| 1676 |
} |
| 1677 |
|
| 1678 |
return asReturn; |
| 1679 |
}, |
| 1680 |
|
| 1681 |
|
| 1682 |
/** |
| 1683 |
* Decode HTML entities |
| 1684 |
* @method _fnHtmlDecode |
| 1685 |
* @param {String} sData encoded string |
| 1686 |
* @returns {String} decoded string |
| 1687 |
* @private |
| 1688 |
*/ |
| 1689 |
"_fnHtmlDecode": function ( sData ) |
| 1690 |
{ |
| 1691 |
if ( sData.indexOf('&') === -1 ) |
| 1692 |
{ |
| 1693 |
return sData; |
| 1694 |
} |
| 1695 |
|
| 1696 |
var n = document.createElement('div'); |
| 1697 |
|
| 1698 |
return sData.replace( /&([^\s]*);/g, function( match, match2 ) { |
| 1699 |
if ( match.substr(1, 1) === '#' ) |
| 1700 |
{ |
| 1701 |
return String.fromCharCode( Number(match2.substr(1)) ); |
| 1702 |
} |
| 1703 |
else |
| 1704 |
{ |
| 1705 |
n.innerHTML = match; |
| 1706 |
return n.childNodes[0].nodeValue; |
| 1707 |
} |
| 1708 |
} ); |
| 1709 |
}, |
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 1714 |
* Printing functions |
| 1715 |
*/ |
| 1716 |
|
| 1717 |
/** |
| 1718 |
* Show print display |
| 1719 |
* @method _fnPrintStart |
| 1720 |
* @param {Event} e Event object |
| 1721 |
* @param {Object} oConfig Button configuration object |
| 1722 |
* @returns void |
| 1723 |
* @private |
| 1724 |
*/ |
| 1725 |
"_fnPrintStart": function ( oConfig ) |
| 1726 |
{ |
| 1727 |
var that = this; |
| 1728 |
var oSetDT = this.s.dt; |
| 1729 |
|
| 1730 |
/* Parse through the DOM hiding everything that isn't needed for the table */ |
| 1731 |
this._fnPrintHideNodes( oSetDT.nTable ); |
| 1732 |
|
| 1733 |
/* Show the whole table */ |
| 1734 |
this.s.print.saveStart = oSetDT._iDisplayStart; |
| 1735 |
this.s.print.saveLength = oSetDT._iDisplayLength; |
| 1736 |
|
| 1737 |
if ( oConfig.bShowAll ) |
| 1738 |
{ |
| 1739 |
oSetDT._iDisplayStart = 0; |
| 1740 |
oSetDT._iDisplayLength = -1; |
| 1741 |
oSetDT.oApi._fnCalculateEnd( oSetDT ); |
| 1742 |
oSetDT.oApi._fnDraw( oSetDT ); |
| 1743 |
} |
| 1744 |
|
| 1745 |
/* Adjust the display for scrolling which might be done by DataTables */ |
| 1746 |
if ( oSetDT.oScroll.sX !== "" || oSetDT.oScroll.sY !== "" ) |
| 1747 |
{ |
| 1748 |
this._fnPrintScrollStart( oSetDT ); |
| 1749 |
|
| 1750 |
// If the table redraws while in print view, the DataTables scrolling |
| 1751 |
// setup would hide the header, so we need to readd it on draw |
| 1752 |
$(this.s.dt.nTable).bind('draw.DTTT_Print', function () { |
| 1753 |
that._fnPrintScrollStart( oSetDT ); |
| 1754 |
} ); |
| 1755 |
} |
| 1756 |
|
| 1757 |
/* Remove the other DataTables feature nodes - but leave the table! and info div */ |
| 1758 |
var anFeature = oSetDT.aanFeatures; |
| 1759 |
for ( var cFeature in anFeature ) |
| 1760 |
{ |
| 1761 |
if ( cFeature != 'i' && cFeature != 't' && cFeature.length == 1 ) |
| 1762 |
{ |
| 1763 |
for ( var i=0, iLen=anFeature[cFeature].length ; i<iLen ; i++ ) |
| 1764 |
{ |
| 1765 |
this.dom.print.hidden.push( { |
| 1766 |
"node": anFeature[cFeature][i], |
| 1767 |
"display": "block" |
| 1768 |
} ); |
| 1769 |
anFeature[cFeature][i].style.display = "none"; |
| 1770 |
} |
| 1771 |
} |
| 1772 |
} |
| 1773 |
|
| 1774 |
/* Print class can be used for styling */ |
| 1775 |
$(document.body).addClass( this.classes.print.body ); |
| 1776 |
|
| 1777 |
/* Show information message to let the user know what is happening */ |
| 1778 |
if ( oConfig.sInfo !== "" ) |
| 1779 |
{ |
| 1780 |
this.fnInfo( oConfig.sInfo, 3000 ); |
| 1781 |
} |
| 1782 |
|
| 1783 |
/* Add a message at the top of the page */ |
| 1784 |
if ( oConfig.sMessage ) |
| 1785 |
{ |
| 1786 |
this.dom.print.message = document.createElement( "div" ); |
| 1787 |
this.dom.print.message.className = this.classes.print.message; |
| 1788 |
this.dom.print.message.innerHTML = oConfig.sMessage; |
| 1789 |
document.body.insertBefore( this.dom.print.message, document.body.childNodes[0] ); |
| 1790 |
} |
| 1791 |
|
| 1792 |
/* Cache the scrolling and the jump to the top of the page */ |
| 1793 |
this.s.print.saveScroll = $(window).scrollTop(); |
| 1794 |
window.scrollTo( 0, 0 ); |
| 1795 |
|
| 1796 |
/* Bind a key event listener to the document for the escape key - |
| 1797 |
* it is removed in the callback |
| 1798 |
*/ |
| 1799 |
$(document).bind( "keydown.DTTT", function(e) { |
| 1800 |
/* Only interested in the escape key */ |
| 1801 |
if ( e.keyCode == 27 ) |
| 1802 |
{ |
| 1803 |
e.preventDefault(); |
| 1804 |
that._fnPrintEnd.call( that, e ); |
| 1805 |
} |
| 1806 |
} ); |
| 1807 |
}, |
| 1808 |
|
| 1809 |
|
| 1810 |
/** |
| 1811 |
* Printing is finished, resume normal display |
| 1812 |
* @method _fnPrintEnd |
| 1813 |
* @param {Event} e Event object |
| 1814 |
* @returns void |
| 1815 |
* @private |
| 1816 |
*/ |
| 1817 |
"_fnPrintEnd": function ( e ) |
| 1818 |
{ |
| 1819 |
var that = this; |
| 1820 |
var oSetDT = this.s.dt; |
| 1821 |
var oSetPrint = this.s.print; |
| 1822 |
var oDomPrint = this.dom.print; |
| 1823 |
|
| 1824 |
/* Show all hidden nodes */ |
| 1825 |
this._fnPrintShowNodes(); |
| 1826 |
|
| 1827 |
/* Restore DataTables' scrolling */ |
| 1828 |
if ( oSetDT.oScroll.sX !== "" || oSetDT.oScroll.sY !== "" ) |
| 1829 |
{ |
| 1830 |
$(this.s.dt.nTable).unbind('draw.DTTT_Print'); |
| 1831 |
|
| 1832 |
this._fnPrintScrollEnd(); |
| 1833 |
} |
| 1834 |
|
| 1835 |
/* Restore the scroll */ |
| 1836 |
window.scrollTo( 0, oSetPrint.saveScroll ); |
| 1837 |
|
| 1838 |
/* Drop the print message */ |
| 1839 |
if ( oDomPrint.message !== null ) |
| 1840 |
{ |
| 1841 |
document.body.removeChild( oDomPrint.message ); |
| 1842 |
oDomPrint.message = null; |
| 1843 |
} |
| 1844 |
|
| 1845 |
/* Styling class */ |
| 1846 |
$(document.body).removeClass( 'DTTT_Print' ); |
| 1847 |
|
| 1848 |
/* Restore the table length */ |
| 1849 |
oSetDT._iDisplayStart = oSetPrint.saveStart; |
| 1850 |
oSetDT._iDisplayLength = oSetPrint.saveLength; |
| 1851 |
oSetDT.oApi._fnCalculateEnd( oSetDT ); |
| 1852 |
oSetDT.oApi._fnDraw( oSetDT ); |
| 1853 |
|
| 1854 |
$(document).unbind( "keydown.DTTT" ); |
| 1855 |
}, |
| 1856 |
|
| 1857 |
|
| 1858 |
/** |
| 1859 |
* Take account of scrolling in DataTables by showing the full table |
| 1860 |
* @returns void |
| 1861 |
* @private |
| 1862 |
*/ |
| 1863 |
"_fnPrintScrollStart": function () |
| 1864 |
{ |
| 1865 |
var |
| 1866 |
oSetDT = this.s.dt, |
| 1867 |
nScrollHeadInner = oSetDT.nScrollHead.getElementsByTagName('div')[0], |
| 1868 |
nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0], |
| 1869 |
nScrollBody = oSetDT.nTable.parentNode; |
| 1870 |
|
| 1871 |
/* Copy the header in the thead in the body table, this way we show one single table when |
| 1872 |
* in print view. Note that this section of code is more or less verbatim from DT 1.7.0 |
| 1873 |
*/ |
| 1874 |
var nTheadSize = oSetDT.nTable.getElementsByTagName('thead'); |
| 1875 |
if ( nTheadSize.length > 0 ) |
| 1876 |
{ |
| 1877 |
oSetDT.nTable.removeChild( nTheadSize[0] ); |
| 1878 |
} |
| 1879 |
|
| 1880 |
if ( oSetDT.nTFoot !== null ) |
| 1881 |
{ |
| 1882 |
var nTfootSize = oSetDT.nTable.getElementsByTagName('tfoot'); |
| 1883 |
if ( nTfootSize.length > 0 ) |
| 1884 |
{ |
| 1885 |
oSetDT.nTable.removeChild( nTfootSize[0] ); |
| 1886 |
} |
| 1887 |
} |
| 1888 |
|
| 1889 |
nTheadSize = oSetDT.nTHead.cloneNode(true); |
| 1890 |
oSetDT.nTable.insertBefore( nTheadSize, oSetDT.nTable.childNodes[0] ); |
| 1891 |
|
| 1892 |
if ( oSetDT.nTFoot !== null ) |
| 1893 |
{ |
| 1894 |
nTfootSize = oSetDT.nTFoot.cloneNode(true); |
| 1895 |
oSetDT.nTable.insertBefore( nTfootSize, oSetDT.nTable.childNodes[1] ); |
| 1896 |
} |
| 1897 |
|
| 1898 |
/* Now adjust the table's viewport so we can actually see it */ |
| 1899 |
if ( oSetDT.oScroll.sX !== "" ) |
| 1900 |
{ |
| 1901 |
oSetDT.nTable.style.width = $(oSetDT.nTable).outerWidth()+"px"; |
| 1902 |
nScrollBody.style.width = $(oSetDT.nTable).outerWidth()+"px"; |
| 1903 |
nScrollBody.style.overflow = "visible"; |
| 1904 |
} |
| 1905 |
|
| 1906 |
if ( oSetDT.oScroll.sY !== "" ) |
| 1907 |
{ |
| 1908 |
nScrollBody.style.height = $(oSetDT.nTable).outerHeight()+"px"; |
| 1909 |
nScrollBody.style.overflow = "visible"; |
| 1910 |
} |
| 1911 |
}, |
| 1912 |
|
| 1913 |
|
| 1914 |
/** |
| 1915 |
* Take account of scrolling in DataTables by showing the full table. Note that the redraw of |
| 1916 |
* the DataTable that we do will actually deal with the majority of the hard work here |
| 1917 |
* @returns void |
| 1918 |
* @private |
| 1919 |
*/ |
| 1920 |
"_fnPrintScrollEnd": function () |
| 1921 |
{ |
| 1922 |
var |
| 1923 |
oSetDT = this.s.dt, |
| 1924 |
nScrollBody = oSetDT.nTable.parentNode; |
| 1925 |
|
| 1926 |
if ( oSetDT.oScroll.sX !== "" ) |
| 1927 |
{ |
| 1928 |
nScrollBody.style.width = oSetDT.oApi._fnStringToCss( oSetDT.oScroll.sX ); |
| 1929 |
nScrollBody.style.overflow = "auto"; |
| 1930 |
} |
| 1931 |
|
| 1932 |
if ( oSetDT.oScroll.sY !== "" ) |
| 1933 |
{ |
| 1934 |
nScrollBody.style.height = oSetDT.oApi._fnStringToCss( oSetDT.oScroll.sY ); |
| 1935 |
nScrollBody.style.overflow = "auto"; |
| 1936 |
} |
| 1937 |
}, |
| 1938 |
|
| 1939 |
|
| 1940 |
/** |
| 1941 |
* Resume the display of all TableTools hidden nodes |
| 1942 |
* @method _fnPrintShowNodes |
| 1943 |
* @returns void |
| 1944 |
* @private |
| 1945 |
*/ |
| 1946 |
"_fnPrintShowNodes": function ( ) |
| 1947 |
{ |
| 1948 |
var anHidden = this.dom.print.hidden; |
| 1949 |
|
| 1950 |
for ( var i=0, iLen=anHidden.length ; i<iLen ; i++ ) |
| 1951 |
{ |
| 1952 |
anHidden[i].node.style.display = anHidden[i].display; |
| 1953 |
} |
| 1954 |
anHidden.splice( 0, anHidden.length ); |
| 1955 |
}, |
| 1956 |
|
| 1957 |
|
| 1958 |
/** |
| 1959 |
* Hide nodes which are not needed in order to display the table. Note that this function is |
| 1960 |
* recursive |
| 1961 |
* @method _fnPrintHideNodes |
| 1962 |
* @param {Node} nNode Element which should be showing in a 'print' display |
| 1963 |
* @returns void |
| 1964 |
* @private |
| 1965 |
*/ |
| 1966 |
"_fnPrintHideNodes": function ( nNode ) |
| 1967 |
{ |
| 1968 |
var anHidden = this.dom.print.hidden; |
| 1969 |
|
| 1970 |
var nParent = nNode.parentNode; |
| 1971 |
var nChildren = nParent.childNodes; |
| 1972 |
for ( var i=0, iLen=nChildren.length ; i<iLen ; i++ ) |
| 1973 |
{ |
| 1974 |
if ( nChildren[i] != nNode && nChildren[i].nodeType == 1 ) |
| 1975 |
{ |
| 1976 |
/* If our node is shown (don't want to show nodes which were previously hidden) */ |
| 1977 |
var sDisplay = $(nChildren[i]).css("display"); |
| 1978 |
if ( sDisplay != "none" ) |
| 1979 |
{ |
| 1980 |
/* Cache the node and it's previous state so we can restore it */ |
| 1981 |
anHidden.push( { |
| 1982 |
"node": nChildren[i], |
| 1983 |
"display": sDisplay |
| 1984 |
} ); |
| 1985 |
nChildren[i].style.display = "none"; |
| 1986 |
} |
| 1987 |
} |
| 1988 |
} |
| 1989 |
|
| 1990 |
if ( nParent.nodeName != "BODY" ) |
| 1991 |
{ |
| 1992 |
this._fnPrintHideNodes( nParent ); |
| 1993 |
} |
| 1994 |
} |
| 1995 |
}; |
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 2000 |
* Static variables |
| 2001 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 2002 |
|
| 2003 |
/** |
| 2004 |
* Store of all instances that have been created of TableTools, so one can look up other (when |
| 2005 |
* there is need of a master) |
| 2006 |
* @property _aInstances |
| 2007 |
* @type Array |
| 2008 |
* @default [] |
| 2009 |
* @private |
| 2010 |
*/ |
| 2011 |
TableTools._aInstances = []; |
| 2012 |
|
| 2013 |
|
| 2014 |
/** |
| 2015 |
* Store of all listeners and their callback functions |
| 2016 |
* @property _aListeners |
| 2017 |
* @type Array |
| 2018 |
* @default [] |
| 2019 |
*/ |
| 2020 |
TableTools._aListeners = []; |
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 2025 |
* Static methods |
| 2026 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 2027 |
|
| 2028 |
/** |
| 2029 |
* Get an array of all the master instances |
| 2030 |
* @method fnGetMasters |
| 2031 |
* @returns {Array} List of master TableTools instances |
| 2032 |
* @static |
| 2033 |
*/ |
| 2034 |
TableTools.fnGetMasters = function () |
| 2035 |
{ |
| 2036 |
var a = []; |
| 2037 |
for ( var i=0, iLen=TableTools._aInstances.length ; i<iLen ; i++ ) |
| 2038 |
{ |
| 2039 |
if ( TableTools._aInstances[i].s.master ) |
| 2040 |
{ |
| 2041 |
a.push( TableTools._aInstances[i] ); |
| 2042 |
} |
| 2043 |
} |
| 2044 |
return a; |
| 2045 |
}; |
| 2046 |
|
| 2047 |
/** |
| 2048 |
* Get the master instance for a table node (or id if a string is given) |
| 2049 |
* @method fnGetInstance |
| 2050 |
* @returns {Object} ID of table OR table node, for which we want the TableTools instance |
| 2051 |
* @static |
| 2052 |
*/ |
| 2053 |
TableTools.fnGetInstance = function ( node ) |
| 2054 |
{ |
| 2055 |
if ( typeof node != 'object' ) |
| 2056 |
{ |
| 2057 |
node = document.getElementById(node); |
| 2058 |
} |
| 2059 |
|
| 2060 |
for ( var i=0, iLen=TableTools._aInstances.length ; i<iLen ; i++ ) |
| 2061 |
{ |
| 2062 |
if ( TableTools._aInstances[i].s.master && TableTools._aInstances[i].dom.table == node ) |
| 2063 |
{ |
| 2064 |
return TableTools._aInstances[i]; |
| 2065 |
} |
| 2066 |
} |
| 2067 |
return null; |
| 2068 |
}; |
| 2069 |
|
| 2070 |
|
| 2071 |
/** |
| 2072 |
* Add a listener for a specific event |
| 2073 |
* @method _fnEventListen |
| 2074 |
* @param {Object} that Scope of the listening function (i.e. 'this' in the caller) |
| 2075 |
* @param {String} type Event type |
| 2076 |
* @param {Function} fn Function |
| 2077 |
* @returns void |
| 2078 |
* @private |
| 2079 |
* @static |
| 2080 |
*/ |
| 2081 |
TableTools._fnEventListen = function ( that, type, fn ) |
| 2082 |
{ |
| 2083 |
TableTools._aListeners.push( { |
| 2084 |
"that": that, |
| 2085 |
"type": type, |
| 2086 |
"fn": fn |
| 2087 |
} ); |
| 2088 |
}; |
| 2089 |
|
| 2090 |
|
| 2091 |
/** |
| 2092 |
* An event has occurred - look up every listener and fire it off. We check that the event we are |
| 2093 |
* going to fire is attached to the same table (using the table node as reference) before firing |
| 2094 |
* @method _fnEventDispatch |
| 2095 |
* @param {Object} that Scope of the listening function (i.e. 'this' in the caller) |
| 2096 |
* @param {String} type Event type |
| 2097 |
* @param {Node} node Element that the event occurred on (may be null) |
| 2098 |
* @param {boolean} [selected] Indicate if the node was selected (true) or deselected (false) |
| 2099 |
* @returns void |
| 2100 |
* @private |
| 2101 |
* @static |
| 2102 |
*/ |
| 2103 |
TableTools._fnEventDispatch = function ( that, type, node, selected ) |
| 2104 |
{ |
| 2105 |
var listeners = TableTools._aListeners; |
| 2106 |
for ( var i=0, iLen=listeners.length ; i<iLen ; i++ ) |
| 2107 |
{ |
| 2108 |
if ( that.dom.table == listeners[i].that.dom.table && listeners[i].type == type ) |
| 2109 |
{ |
| 2110 |
listeners[i].fn( node, selected ); |
| 2111 |
} |
| 2112 |
} |
| 2113 |
}; |
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 2121 |
* Constants |
| 2122 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
TableTools.buttonBase = { |
| 2127 |
// Button base |
| 2128 |
"sAction": "text", |
| 2129 |
"sTag": "default", |
| 2130 |
"sLinerTag": "default", |
| 2131 |
"sButtonClass": "DTTT_button_text", |
| 2132 |
"sButtonText": "Button text", |
| 2133 |
"sTitle": "", |
| 2134 |
"sToolTip": "", |
| 2135 |
|
| 2136 |
// Common button specific options |
| 2137 |
"sCharSet": "utf8", |
| 2138 |
"bBomInc": false, |
| 2139 |
"sFileName": "*.csv", |
| 2140 |
"sFieldBoundary": "", |
| 2141 |
"sFieldSeperator": "\t", |
| 2142 |
"sNewLine": "auto", |
| 2143 |
"mColumns": "all", /* "all", "visible", "hidden" or array of column integers */ |
| 2144 |
"bHeader": true, |
| 2145 |
"bFooter": true, |
| 2146 |
"bOpenRows": false, |
| 2147 |
"bSelectedOnly": false, |
| 2148 |
|
| 2149 |
// Callbacks |
| 2150 |
"fnMouseover": null, |
| 2151 |
"fnMouseout": null, |
| 2152 |
"fnClick": null, |
| 2153 |
"fnSelect": null, |
| 2154 |
"fnComplete": null, |
| 2155 |
"fnInit": null, |
| 2156 |
"fnCellRender": null |
| 2157 |
}; |
| 2158 |
|
| 2159 |
|
| 2160 |
/** |
| 2161 |
* @namespace Default button configurations |
| 2162 |
*/ |
| 2163 |
TableTools.BUTTONS = { |
| 2164 |
"csv": $.extend( {}, TableTools.buttonBase, { |
| 2165 |
"sAction": "flash_save", |
| 2166 |
"sButtonClass": "DTTT_button_csv", |
| 2167 |
"sButtonText": "CSV", |
| 2168 |
"sFieldBoundary": '"', |
| 2169 |
"sFieldSeperator": ",", |
| 2170 |
"fnClick": function( nButton, oConfig, flash ) { |
| 2171 |
this.fnSetText( flash, this.fnGetTableData(oConfig) ); |
| 2172 |
} |
| 2173 |
} ), |
| 2174 |
|
| 2175 |
"xls": $.extend( {}, TableTools.buttonBase, { |
| 2176 |
"sAction": "flash_save", |
| 2177 |
"sCharSet": "utf16le", |
| 2178 |
"bBomInc": true, |
| 2179 |
"sButtonClass": "DTTT_button_xls", |
| 2180 |
"sButtonText": "Excel", |
| 2181 |
"fnClick": function( nButton, oConfig, flash ) { |
| 2182 |
this.fnSetText( flash, this.fnGetTableData(oConfig) ); |
| 2183 |
} |
| 2184 |
} ), |
| 2185 |
|
| 2186 |
"copy": $.extend( {}, TableTools.buttonBase, { |
| 2187 |
"sAction": "flash_copy", |
| 2188 |
"sButtonClass": "DTTT_button_copy", |
| 2189 |
"sButtonText": "Copy", |
| 2190 |
"fnClick": function( nButton, oConfig, flash ) { |
| 2191 |
this.fnSetText( flash, this.fnGetTableData(oConfig) ); |
| 2192 |
}, |
| 2193 |
"fnComplete": function(nButton, oConfig, flash, text) { |
| 2194 |
var |
| 2195 |
lines = text.split('\n').length, |
| 2196 |
len = this.s.dt.nTFoot === null ? lines-1 : lines-2, |
| 2197 |
plural = (len==1) ? "" : "s"; |
| 2198 |
this.fnInfo( '<h6>Table copied</h6>'+ |
| 2199 |
'<p>Copied '+len+' row'+plural+' to the clipboard.</p>', |
| 2200 |
1500 |
| 2201 |
); |
| 2202 |
} |
| 2203 |
} ), |
| 2204 |
|
| 2205 |
"pdf": $.extend( {}, TableTools.buttonBase, { |
| 2206 |
"sAction": "flash_pdf", |
| 2207 |
"sNewLine": "\n", |
| 2208 |
"sFileName": "*.pdf", |
| 2209 |
"sButtonClass": "DTTT_button_pdf", |
| 2210 |
"sButtonText": "PDF", |
| 2211 |
"sPdfOrientation": "portrait", |
| 2212 |
"sPdfSize": "A4", |
| 2213 |
"sPdfMessage": "", |
| 2214 |
"fnClick": function( nButton, oConfig, flash ) { |
| 2215 |
this.fnSetText( flash, |
| 2216 |
"title:"+ this.fnGetTitle(oConfig) +"\n"+ |
| 2217 |
"message:"+ oConfig.sPdfMessage +"\n"+ |
| 2218 |
"colWidth:"+ this.fnCalcColRatios(oConfig) +"\n"+ |
| 2219 |
"orientation:"+ oConfig.sPdfOrientation +"\n"+ |
| 2220 |
"size:"+ oConfig.sPdfSize +"\n"+ |
| 2221 |
"--/TableToolsOpts--\n" + |
| 2222 |
this.fnGetTableData(oConfig) |
| 2223 |
); |
| 2224 |
} |
| 2225 |
} ), |
| 2226 |
|
| 2227 |
"print": $.extend( {}, TableTools.buttonBase, { |
| 2228 |
"sInfo": "<h6>Print view</h6><p>Please use your browser's print function to "+ |
| 2229 |
"print this table. Press escape when finished.", |
| 2230 |
"sMessage": null, |
| 2231 |
"bShowAll": true, |
| 2232 |
"sToolTip": "View print view", |
| 2233 |
"sButtonClass": "DTTT_button_print", |
| 2234 |
"sButtonText": "Print", |
| 2235 |
"fnClick": function ( nButton, oConfig ) { |
| 2236 |
this.fnPrint( true, oConfig ); |
| 2237 |
} |
| 2238 |
} ), |
| 2239 |
|
| 2240 |
"text": $.extend( {}, TableTools.buttonBase ), |
| 2241 |
|
| 2242 |
"select": $.extend( {}, TableTools.buttonBase, { |
| 2243 |
"sButtonText": "Select button", |
| 2244 |
"fnSelect": function( nButton, oConfig ) { |
| 2245 |
if ( this.fnGetSelected().length !== 0 ) { |
| 2246 |
$(nButton).removeClass( this.classes.buttons.disabled ); |
| 2247 |
} else { |
| 2248 |
$(nButton).addClass( this.classes.buttons.disabled ); |
| 2249 |
} |
| 2250 |
}, |
| 2251 |
"fnInit": function( nButton, oConfig ) { |
| 2252 |
$(nButton).addClass( this.classes.buttons.disabled ); |
| 2253 |
} |
| 2254 |
} ), |
| 2255 |
|
| 2256 |
"select_single": $.extend( {}, TableTools.buttonBase, { |
| 2257 |
"sButtonText": "Select button", |
| 2258 |
"fnSelect": function( nButton, oConfig ) { |
| 2259 |
var iSelected = this.fnGetSelected().length; |
| 2260 |
if ( iSelected == 1 ) { |
| 2261 |
$(nButton).removeClass( this.classes.buttons.disabled ); |
| 2262 |
} else { |
| 2263 |
$(nButton).addClass( this.classes.buttons.disabled ); |
| 2264 |
} |
| 2265 |
}, |
| 2266 |
"fnInit": function( nButton, oConfig ) { |
| 2267 |
$(nButton).addClass( this.classes.buttons.disabled ); |
| 2268 |
} |
| 2269 |
} ), |
| 2270 |
|
| 2271 |
"select_all": $.extend( {}, TableTools.buttonBase, { |
| 2272 |
"sButtonText": "Select all", |
| 2273 |
"fnClick": function( nButton, oConfig ) { |
| 2274 |
this.fnSelectAll(); |
| 2275 |
}, |
| 2276 |
"fnSelect": function( nButton, oConfig ) { |
| 2277 |
if ( this.fnGetSelected().length == this.s.dt.fnRecordsDisplay() ) { |
| 2278 |
$(nButton).addClass( this.classes.buttons.disabled ); |
| 2279 |
} else { |
| 2280 |
$(nButton).removeClass( this.classes.buttons.disabled ); |
| 2281 |
} |
| 2282 |
} |
| 2283 |
} ), |
| 2284 |
|
| 2285 |
"select_none": $.extend( {}, TableTools.buttonBase, { |
| 2286 |
"sButtonText": "Deselect all", |
| 2287 |
"fnClick": function( nButton, oConfig ) { |
| 2288 |
this.fnSelectNone(); |
| 2289 |
}, |
| 2290 |
"fnSelect": function( nButton, oConfig ) { |
| 2291 |
if ( this.fnGetSelected().length !== 0 ) { |
| 2292 |
$(nButton).removeClass( this.classes.buttons.disabled ); |
| 2293 |
} else { |
| 2294 |
$(nButton).addClass( this.classes.buttons.disabled ); |
| 2295 |
} |
| 2296 |
}, |
| 2297 |
"fnInit": function( nButton, oConfig ) { |
| 2298 |
$(nButton).addClass( this.classes.buttons.disabled ); |
| 2299 |
} |
| 2300 |
} ), |
| 2301 |
|
| 2302 |
"ajax": $.extend( {}, TableTools.buttonBase, { |
| 2303 |
"sAjaxUrl": "/xhr.php", |
| 2304 |
"sButtonText": "Ajax button", |
| 2305 |
"fnClick": function( nButton, oConfig ) { |
| 2306 |
var sData = this.fnGetTableData(oConfig); |
| 2307 |
$.ajax( { |
| 2308 |
"url": oConfig.sAjaxUrl, |
| 2309 |
"data": [ |
| 2310 |
{ "name": "tableData", "value": sData } |
| 2311 |
], |
| 2312 |
"success": oConfig.fnAjaxComplete, |
| 2313 |
"dataType": "json", |
| 2314 |
"type": "POST", |
| 2315 |
"cache": false, |
| 2316 |
"error": function () { |
| 2317 |
alert( "Error detected when sending table data to server" ); |
| 2318 |
} |
| 2319 |
} ); |
| 2320 |
}, |
| 2321 |
"fnAjaxComplete": function( json ) { |
| 2322 |
alert( 'Ajax complete' ); |
| 2323 |
} |
| 2324 |
} ), |
| 2325 |
|
| 2326 |
"div": $.extend( {}, TableTools.buttonBase, { |
| 2327 |
"sAction": "div", |
| 2328 |
"sTag": "div", |
| 2329 |
"sButtonClass": "DTTT_nonbutton", |
| 2330 |
"sButtonText": "Text button" |
| 2331 |
} ), |
| 2332 |
|
| 2333 |
"collection": $.extend( {}, TableTools.buttonBase, { |
| 2334 |
"sAction": "collection", |
| 2335 |
"sButtonClass": "DTTT_button_collection", |
| 2336 |
"sButtonText": "Collection", |
| 2337 |
"fnClick": function( nButton, oConfig ) { |
| 2338 |
this._fnCollectionShow(nButton, oConfig); |
| 2339 |
} |
| 2340 |
} ) |
| 2341 |
}; |
| 2342 |
/* |
| 2343 |
* on* callback parameters: |
| 2344 |
* 1. node - button element |
| 2345 |
* 2. object - configuration object for this button |
| 2346 |
* 3. object - ZeroClipboard reference (flash button only) |
| 2347 |
* 4. string - Returned string from Flash (flash button only - and only on 'complete') |
| 2348 |
*/ |
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
/** |
| 2353 |
* @namespace Classes used by TableTools - allows the styles to be override easily. |
| 2354 |
* Note that when TableTools initialises it will take a copy of the classes object |
| 2355 |
* and will use its internal copy for the remainder of its run time. |
| 2356 |
*/ |
| 2357 |
TableTools.classes = { |
| 2358 |
"container": "DTTT_container", |
| 2359 |
"buttons": { |
| 2360 |
"normal": "DTTT_button", |
| 2361 |
"disabled": "DTTT_disabled" |
| 2362 |
}, |
| 2363 |
"collection": { |
| 2364 |
"container": "DTTT_collection", |
| 2365 |
"background": "DTTT_collection_background", |
| 2366 |
"buttons": { |
| 2367 |
"normal": "DTTT_button", |
| 2368 |
"disabled": "DTTT_disabled" |
| 2369 |
} |
| 2370 |
}, |
| 2371 |
"select": { |
| 2372 |
"table": "DTTT_selectable", |
| 2373 |
"row": "DTTT_selected" |
| 2374 |
}, |
| 2375 |
"print": { |
| 2376 |
"body": "DTTT_Print", |
| 2377 |
"info": "DTTT_print_info", |
| 2378 |
"message": "DTTT_PrintMessage" |
| 2379 |
} |
| 2380 |
}; |
| 2381 |
|
| 2382 |
|
| 2383 |
/** |
| 2384 |
* @namespace ThemeRoller classes - built in for compatibility with DataTables' |
| 2385 |
* bJQueryUI option. |
| 2386 |
*/ |
| 2387 |
TableTools.classes_themeroller = { |
| 2388 |
"container": "DTTT_container ui-buttonset ui-buttonset-multi", |
| 2389 |
"buttons": { |
| 2390 |
"normal": "DTTT_button ui-button ui-state-default" |
| 2391 |
}, |
| 2392 |
"collection": { |
| 2393 |
"container": "DTTT_collection ui-buttonset ui-buttonset-multi" |
| 2394 |
} |
| 2395 |
}; |
| 2396 |
|
| 2397 |
|
| 2398 |
/** |
| 2399 |
* @namespace TableTools default settings for initialisation |
| 2400 |
*/ |
| 2401 |
TableTools.DEFAULTS = { |
| 2402 |
"sSwfPath": "media/swf/copy_csv_xls_pdf.swf", |
| 2403 |
"sRowSelect": "none", |
| 2404 |
"sSelectedClass": null, |
| 2405 |
"fnPreRowSelect": null, |
| 2406 |
"fnRowSelected": null, |
| 2407 |
"fnRowDeselected": null, |
| 2408 |
"aButtons": [ "copy", "csv", "xls", "pdf", "print" ], |
| 2409 |
"oTags": { |
| 2410 |
"container": "div", |
| 2411 |
"button": "a", // We really want to use buttons here, but Firefox and IE ignore the |
| 2412 |
// click on the Flash element in the button (but not mouse[in|out]). |
| 2413 |
"liner": "span", |
| 2414 |
"collection": { |
| 2415 |
"container": "div", |
| 2416 |
"button": "a", |
| 2417 |
"liner": "span" |
| 2418 |
} |
| 2419 |
} |
| 2420 |
}; |
| 2421 |
|
| 2422 |
|
| 2423 |
/** |
| 2424 |
* Name of this class |
| 2425 |
* @constant CLASS |
| 2426 |
* @type String |
| 2427 |
* @default TableTools |
| 2428 |
*/ |
| 2429 |
TableTools.prototype.CLASS = "TableTools"; |
| 2430 |
|
| 2431 |
|
| 2432 |
/** |
| 2433 |
* TableTools version |
| 2434 |
* @constant VERSION |
| 2435 |
* @type String |
| 2436 |
* @default See code |
| 2437 |
*/ |
| 2438 |
TableTools.VERSION = "2.1.5"; |
| 2439 |
TableTools.prototype.VERSION = TableTools.VERSION; |
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| 2445 |
* Initialisation |
| 2446 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 2447 |
|
| 2448 |
/* |
| 2449 |
* Register a new feature with DataTables |
| 2450 |
*/ |
| 2451 |
if ( typeof $.fn.dataTable == "function" && |
| 2452 |
typeof $.fn.dataTableExt.fnVersionCheck == "function" && |
| 2453 |
$.fn.dataTableExt.fnVersionCheck('1.9.0') ) |
| 2454 |
{ |
| 2455 |
$.fn.dataTableExt.aoFeatures.push( { |
| 2456 |
"fnInit": function( oDTSettings ) { |
| 2457 |
var oOpts = typeof oDTSettings.oInit.oTableTools != 'undefined' ? |
| 2458 |
oDTSettings.oInit.oTableTools : {}; |
| 2459 |
|
| 2460 |
var oTT = new TableTools( oDTSettings.oInstance, oOpts ); |
| 2461 |
TableTools._aInstances.push( oTT ); |
| 2462 |
|
| 2463 |
return oTT.dom.container; |
| 2464 |
}, |
| 2465 |
"cFeature": "T", |
| 2466 |
"sFeature": "TableTools" |
| 2467 |
} ); |
| 2468 |
} |
| 2469 |
else |
| 2470 |
{ |
| 2471 |
alert( "Warning: TableTools 2 requires DataTables 1.9.0 or newer - www.datatables.net/download"); |
| 2472 |
} |
| 2473 |
|
| 2474 |
$.fn.DataTable.TableTools = TableTools; |
| 2475 |
|
| 2476 |
})(jQuery, window, document); |