Editable: Add editable_trimContent option

This commit is contained in:
Mottie 2014-09-02 15:29:28 -05:00
parent 3b30cd0cbe
commit f1e32a26fe
2 changed files with 44 additions and 1 deletions

View File

@ -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">&lt;td&gt;
John
&lt;/td&gt;</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>)

View File

@ -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 ) {