As always we start like this:
Create a document library to hold your scripts (or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Javascript” (a sub site named “test” with a sub site named “English” with a document library named “Javascript”):
The jQuery-library is found
here. The pictures and the sourcecode refers to jquery-1.3.2.min. If you download another version, be sure to update the script reference in the sourcecode.
The code for the file “LimitMultilineTextInView.js” is found below.
This will work in standard views and in grouped views, but has not been adapted to work with “Boxed” views.
Add a CEWP below the list view and add this code:
1 | <script type= "text/javascript" src= "/test/English/Javascript/jquery-1.3.2.min.js" ></script> |
2 | <script type= "text/javascript" src= "/test/English/Javascript/LimitMultilineTextInView.js" ></script> |
3 | <script type= "text/javascript" > |
5 | limitMultiLineText( 'MultilineText' ,100); |
Parameters explained:
- FieldInternalName: The “FieldInternalName” of the field containing the multi line text. Use DisplayName if the multiline field is of type rich or enhanced rich text. (how to find the FieldInternalName)
- initialLength: Limit the initial displayed text to this number of characters. This argument is overridden by the next, if supplied.
- inPlaceHoverText: If set, this argument will override the previous, and add a “inPlace” text that can be hovered to view the full text.
When hovered there are a delay for 650 milliseconds to prevent flickering when you move the mouse rapidly over multiple cells.
The code for the file “LimitMultilineTextInView.js” looks like this:
23 | function limitMultiLineText(FieldInternalName,initialLength,inPlaceHoverText){ |
24 | if ( typeof (FieldInternalName)!= 'undefined' ){ |
25 | intName = FieldInternalName; |
26 | initLength = initialLength; |
27 | inPlaceText = inPlaceHoverText; |
28 | $( ".ms-viewheadertr th.ms-vh2-nograd" ).each( function (){ |
29 | if ($( this ).text()==intName){ |
30 | colIndex = $( this ).attr( 'cellIndex' ); |
35 | $( "table.ms-listviewtable tbody:not([id^='aggr']) tr:has(td.ms-vb2) >td[cellIndex=" + colIndex + "][beenthere!=1]" ).each( function (){ |
36 | $( this ).attr( 'beenthere' ,1); |
38 | if (inPlaceText!= '' && inPlaceText!=undefined){ |
39 | var teaserText = inPlaceText; |
41 | var teaserText = thisTd.text().substring(0,initLength); |
43 | thisTd.wrapInner( "<div style='background-color:white;border:thin silver ridge;padding:4px;display:none'></div>" ) |
44 | .prepend( "<span style='cursor:default'>" +teaserText+ "...</span>" ) |
46 | thisTd.addClass( 'dummyHoverClass ms-dialogSelectedRow' ); |
47 | setTimeout( function (){ |
48 | if (thisTd.hasClass( 'dummyHoverClass' )){ |
49 | var offset = thisTd.offset(); |
50 | var tdWidth = thisTd.width(); |
51 | thisTd.find( 'div:first' ) |
52 | .css({ 'position' : 'absolute' , |
62 | if (thisTd.hasClass( 'dummyHoverClass' )){ |
63 | thisTd.removeClass( 'dummyHoverClass ms-dialogSelectedRow' ); |
64 | thisTd.find( 'div:first' ).stop( true , true ).fadeOut(100).prev().show(); |
71 | function ExpGroupRenderData(htmlToRender, groupName, isLoaded){ |
72 | var tbody=document.getElementById( "tbod" +groupName+ "_" ); |
73 | var wrapDiv=document.createElement( "DIV" ); |
74 | wrapDiv.innerHTML= "<TABLE><TBODY id=\"tbod" +groupName+ "_\" isLoaded=\"" +isLoaded+ "\">" +htmlToRender+ "</TBODY></TABLE>" ; |
75 | tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild,tbody); |
Save the file as “LimitMultilineTextInView.js”, mind the file extension, and upload to the scriptlibrary as shown above.
No comments:
Post a Comment