Extensis Logo SUPPORT | FORUMS | KNOWLEDGE BASE

Wrap long file names


#1

We have long file names that use underscores to signify spaces. Our end goal is to have these long file names wrap to new lines. We are looking to use jquery to swap the underscores for spaces.

Something like this:
jsfiddle.net/KQwXW/

Snippet from detail.np

<!-------------------------->  
<!-- Detail field listing -->  
<!-------------------------->          
<% var fieldValue = ""; %>
<% var fieldName = ""; %>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$('.file-name').each(function() {
    var $this = $(this);

    $this.text($this.text().replace(/_/g, ' '));
    
});
</script>

<span class="file-name">
<% fieldName = 'Filename'; %>
<% fieldValue =RecordSet.record.get(unescape('Filename')); %>
<%   if (fieldValue != "[undefined]" && fieldValue != "") { %>

    <strong><%=fieldName%></strong>: 
	    <% if(fieldName == "Keywords") {%>
			<% urlKeywords(fieldValue, "results.np", "mainFrame",Text.UrlKeywordsTitleText);%>
		 	<% }else if(fieldName == "File Size") {%>
		 			<%= Math.round(fieldValue/1024*100)/100 %> MB
		 	<% }else{ %>
			<%= htmlEncode(LocalizeFieldValue(fieldValue)) %>
			<% } %>
   
    <% } %>
</span> 
<!-------------------------->  
<!-- End of field listing -->
<!-------------------------->  

Has anyone used this tactic successfully? Also, is there something basic we overlooked? Thanks.


#2

There’s no need to to do this client side just because of NP. If you’re already loading jQuery that’s fine but if adding it only for this why not do it server-side.

The String.replace() function is available in the NP server-side JavaScript. I tend to run a custom NP library file (added in to pages templates via the library() include). This makes it easiy to fix out-of-the-box shortcomings like:

  • Text Block fields (e.g. Descriptions) paragraphs aren’t rendered correctly.

  • Multi-valued field values are returned as comma-delimited list. Comma+Space is far more readable and customers usually want.

  • Date field default rendering is rarely acceptable to the customer.

Passing a reference to the current record & a field name to such a custom library makes it trivially easy to get a lot of field data customisation. You can always use a separate NP library filed to store a mapping of Field Name to Data visualisation type that you main visualisation can look at for very granular customisation and re-use across multiple sides/customers.