mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Editable: Add editable_trimContent option
This commit is contained in:
parent
3b30cd0cbe
commit
f1e32a26fe
@ -412,6 +412,34 @@ td.no-edit, span.no-edit {
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr id="editable-trimcontent">
|
||||
<td><a href="#" class="permalink">editable_trimContent</a></td>
|
||||
<td>Trim the content within the editable cell (<span class="version">v2.17.8</span>)
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
When a table cell is formatted as follows:
|
||||
<pre class="prettyprint lang-html"><td>
|
||||
John
|
||||
</td></pre>All carriage returns and tab(s) within the table cell would be included before editing. Once the contenteditable element has focus, the content is cleaned up.<br>
|
||||
<br>
|
||||
If this option is <code>true</code>, this widget will trim content <em>upon initialization</em>; this is necessary if you need cleaned it up content before editing, like with an autocomplete script.<br>
|
||||
<br>
|
||||
Use this option as follows:
|
||||
<pre class="prettyprint lang-js">$(function(){
|
||||
|
||||
$('#table').tablesorter({
|
||||
widgets : ['editable'],
|
||||
widgetOptions : {
|
||||
editable_trimContent : true
|
||||
}
|
||||
});
|
||||
|
||||
});</pre>
|
||||
Default value: <code>true</code>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr id="editable-wrapcontent">
|
||||
<td><a href="#" class="permalink">editable_wrapContent</a></td>
|
||||
<td>Wrap the editable cell content with this element (<span class="version">v2.17.8</span>)
|
||||
|
@ -15,6 +15,7 @@
|
||||
editable_autoAccept : true,
|
||||
editable_autoResort : false,
|
||||
editable_wrapContent : '<div>', // wrap the cell content... makes this widget work in IE, and with autocomplete
|
||||
editable_trimContent : true, // trim content inside of contenteditable (remove tabs & carriage returns)
|
||||
editable_validate : null, // function(text, originalText){ return text; }
|
||||
editable_focused : null, // function(text, columnIndex, $element) {}
|
||||
editable_blur : null, // function(text, columnIndex, $element) { }
|
||||
@ -77,8 +78,21 @@
|
||||
}
|
||||
if ($t.children().length) {
|
||||
// make all children content editable
|
||||
$t.children().not('.' + wo.editable_noEdit).prop( 'contenteditable', true );
|
||||
$t.children().not('.' + wo.editable_noEdit).each(function(){
|
||||
var $this = $(this);
|
||||
if (wo.editable_trimContent) {
|
||||
$this.text(function(i, txt){
|
||||
return $.trim(txt);
|
||||
});
|
||||
}
|
||||
$this.prop( 'contenteditable', true );
|
||||
});
|
||||
} else {
|
||||
if (wo.editable_trimContent) {
|
||||
$t.text(function(i, txt){
|
||||
return $.trim(txt);
|
||||
});
|
||||
}
|
||||
$t.prop( 'contenteditable', true );
|
||||
}
|
||||
});
|
||||
@ -134,6 +148,7 @@
|
||||
c.$table.data( 'contentFocused', false );
|
||||
return false;
|
||||
}
|
||||
// accept on enter (if set), alt-enter (always) or if autoAccept is set and element is blurred or unfocused
|
||||
t = e.which === 13 && ( wo.editable_enterToAccept || e.altKey ) || wo.editable_autoAccept && e.type !== 'keydown';
|
||||
// change if new or user hits enter (if option set)
|
||||
if ( t && $this.data('before') !== txt ) {
|
||||
|
Loading…
Reference in New Issue
Block a user