]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - js/datatables-ellipsis.js
Fix del_usermeta() not working for both sql_db and file_db
[irc/unrealircd/unrealircd-webpanel.git] / js / datatables-ellipsis.js
1 /*! © SpryMedia Ltd - datatables.net/license */
2
3 (function( factory ){
4 if ( typeof define === 'function' && define.amd ) {
5 // AMD
6 define( ['jquery', 'datatables.net'], function ( $ ) {
7 return factory( $, window, document );
8 } );
9 }
10 else if ( typeof exports === 'object' ) {
11 // CommonJS
12 var jq = require('jquery');
13 var cjsRequires = function (root, $) {
14 if ( ! $.fn.dataTable ) {
15 require('datatables.net')(root, $);
16 }
17 };
18
19 if (typeof window !== 'undefined') {
20 module.exports = function (root, $) {
21 if ( ! root ) {
22 // CommonJS environments without a window global must pass a
23 // root. This will give an error otherwise
24 root = window;
25 }
26
27 if ( ! $ ) {
28 $ = jq( root );
29 }
30
31 cjsRequires( root, $ );
32 return factory( $, root, root.document );
33 };
34 }
35 else {
36 cjsRequires( window, jq );
37 module.exports = factory( jq, window, window.document );
38 }
39 }
40 else {
41 // Browser
42 factory( jQuery, window, document );
43 }
44 }(function( $, window, document, undefined ) {
45 'use strict';
46 var DataTable = $.fn.dataTable;
47
48
49 /**
50 * This data rendering helper method can be useful for cases where you have
51 * potentially large data strings to be shown in a column that is restricted by
52 * width. The data for the column is still fully searchable and sortable, but if
53 * it is longer than a give number of characters, it will be truncated and
54 * shown with ellipsis. A browser provided tooltip will show the full string
55 * to the end user on mouse hover of the cell.
56 *
57 * This function should be used with the `dt-init columns.render` configuration
58 * option of DataTables.
59 *
60 * It accepts three parameters:
61 *
62 * 1. `-type integer` - The number of characters to restrict the displayed data
63 * to.
64 * 2. `-type boolean` (optional - default `false`) - Indicate if the truncation
65 * of the string should not occur in the middle of a word (`true`) or if it
66 * can (`false`). This can allow the display of strings to look nicer, at the
67 * expense of showing less characters.
68 * 2. `-type boolean` (optional - default `false`) - Escape HTML entities
69 * (`true`) or not (`false` - default).
70 *
71 * @name ellipsis
72 * @summary Restrict output data to a particular length, showing anything
73 * longer with ellipsis and a browser provided tooltip on hover.
74 * @author [Allan Jardine](http://datatables.net)
75 * @requires DataTables 1.10+
76 *
77 * @returns {Number} Calculated average
78 *
79 * @example
80 * // Restrict a column to 17 characters, don't split words
81 * $('#example').DataTable( {
82 * columnDefs: [ {
83 * targets: 1,
84 * render: DataTable.render.ellipsis( 17, true )
85 * } ]
86 * } );
87 *
88 * @example
89 * // Restrict a column to 10 characters, do split words
90 * $('#example').DataTable( {
91 * columnDefs: [ {
92 * targets: 2,
93 * render: DataTable.render.ellipsis( 10 )
94 * } ]
95 * } );
96 */
97 DataTable.render.ellipsis = function (cutoff, wordbreak, escapeHtml) {
98 var esc = function (t) {
99 return ('' + t)
100 .replace(/&/g, '&')
101 .replace(/</g, '&lt;')
102 .replace(/>/g, '&gt;')
103 .replace(/"/g, '&quot;');
104 };
105 return function (d, type, row) {
106 // Order, search and type get the original data
107 if (type !== 'display') {
108 return d;
109 }
110 if (typeof d !== 'number' && typeof d !== 'string') {
111 if (escapeHtml) {
112 return esc(d);
113 }
114 return d;
115 }
116 d = d.toString(); // cast numbers
117 if (d.length <= cutoff) {
118 if (escapeHtml) {
119 return esc(d);
120 }
121 return d;
122 }
123 var shortened = d.substr(0, cutoff - 1);
124 // Find the last white space character in the string
125 if (wordbreak) {
126 shortened = shortened.replace(/\s([^\s]*)$/, '');
127 }
128 // Protect against uncontrolled HTML input
129 if (escapeHtml) {
130 shortened = esc(shortened);
131 }
132 return ('<span class="ellipsis" title="' +
133 esc(d) +
134 '">' +
135 shortened +
136 '&#8230;</span>');
137 };
138 };
139
140
141 return DataTable;
142 }));