Changeset 6686
- Timestamp:
- 10/20/15 09:13:20 (9 years ago)
- Location:
- vlo/branches/vlo-3.3/vlo-web-app/src/main
- Files:
-
- 1 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.3/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/JavaScriptResources.java
r6685 r6686 38 38 private final static CssResourceReference JQUERY_UI_CSS = new CssResourceReference(VloBasePage.class, "jquery-ui-1.11.4.custom/jquery-ui.min.css"); 39 39 private final static JavaScriptResourceReference JQUERY_WATERMARK = new JavaScriptResourceReference(VloBasePage.class, "jquery.watermark-3.1.4/jquery.watermark.min.js"); 40 private final static JavaScriptResourceReference HIGHLIGHT = new JavaScriptResourceReference(RecordPage.class, " searchhi.js");40 private final static JavaScriptResourceReference HIGHLIGHT = new JavaScriptResourceReference(RecordPage.class, "jquery.highlight.js"); 41 41 42 42 public static JavaScriptResourceReference getVloFrontJS() { -
vlo/branches/vlo-3.3/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/HighlightSearchTermBehavior.java
r5161 r6686 17 17 package eu.clarin.cmdi.vlo.wicket; 18 18 19 import com.google.common.collect.ImmutableSet; 19 20 import eu.clarin.cmdi.vlo.JavaScriptResources; 21 import java.util.Collection; 20 22 import org.apache.wicket.Component; 21 23 import org.apache.wicket.behavior.Behavior; … … 23 25 import org.apache.wicket.markup.head.JavaScriptHeaderItem; 24 26 import org.apache.wicket.markup.head.OnDomReadyHeaderItem; 27 import org.apache.wicket.request.Request; 28 import org.apache.wicket.util.string.StringValue; 25 29 26 30 /** … … 33 37 public class HighlightSearchTermBehavior extends Behavior { 34 38 35 private static final String HIGHLIGHT_FUNCTION = "searchhi.init()"; 39 private static final String HIGHLIGHT_FUNCTION = "$('#%s').highlight(%s, {className:'%s'})"; 40 private static final Collection<String> DEFAULT_EXCLUDE_WORDS = ImmutableSet.of("and", "or", "not", "to"); 36 41 37 42 @Override … … 39 44 // include highlight script 40 45 response.render(JavaScriptHeaderItem.forReference(JavaScriptResources.getHighlightJS())); 41 // after load, highlight 42 response.render(OnDomReadyHeaderItem.forScript(HIGHLIGHT_FUNCTION)); 46 47 final StringValue words = getWordList(component); 48 if (!words.isEmpty()) { 49 // after load, highlight 50 response.render(OnDomReadyHeaderItem.forScript(String.format(HIGHLIGHT_FUNCTION, 51 component.getMarkupId(), makeWordListArray(words.toString()), 52 getSearchWordClass() 53 ))); 54 } 55 } 56 57 /** 58 * 59 * @param wordList string of whitespace separated words 60 * @return a string representing a sanitised javascript array of words 61 */ 62 private CharSequence makeWordListArray(String wordList) { 63 final StringBuilder sb = new StringBuilder("["); 64 final String[] words = wordList.split("\\s"); 65 for (int i = 0; i < words.length; i++) { 66 final String word = sanitise(words[i]); //remove white space and quotes at beginning or end 67 // is on exclude list? 68 if (!getExcludeWords().contains(word.toLowerCase())) { 69 // wrap in quotes 70 sb.append("'").append(word).append("'"); 71 if (i + 1 < words.length) { 72 // prepare to append next 73 sb.append(","); 74 } 75 } 76 } 77 return sb.append("]"); 78 } 79 80 private String sanitise(String word) { 81 return word.replaceAll("^[\\s'\"]+|[\\s'\"]+$", ""); 82 } 83 84 /** 85 * 86 * @return CSS class to mark matches with 87 */ 88 protected String getSearchWordClass() { 89 return "searchword"; 90 } 91 92 protected StringValue getWordList(Component component) { 93 Request request = component.getPage().getRequestCycle().getRequest(); 94 return request.getQueryParameters().getParameterValue(getQueryParam()); 95 } 96 97 protected String getQueryParam() { 98 return "q"; 99 } 100 101 /** 102 * 103 * @return Words not to highlight 104 */ 105 protected Collection<String> getExcludeWords() { 106 return DEFAULT_EXCLUDE_WORDS; 43 107 } 44 108 -
vlo/branches/vlo-3.3/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/RecordPage.html
r6330 r6686 51 51 <div id="recorddetails"> 52 52 <a wicket:id="landingPageLink" target="_blank" id="recordlandingpage">Show this record in its original context</a> 53 < wicket:container wicket:id="documentProperties">[PROPERTIES TABLE]</wicket:container>53 <div id="recordProperties" wicket:id="documentProperties">[PROPERTIES TABLE]</div> 54 54 </div> 55 55 -
vlo/branches/vlo-3.3/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/RecordPage.java
r6611 r6686 130 130 131 131 addComponents(); 132 add(new HighlightSearchTermBehavior());133 132 } 134 133 … … 138 137 139 138 final WebMarkupContainer topNavigation = new WebMarkupContainer("topnavigation"); 140 topNavigation.setOutputMarkupId(true);141 add(topNavigation);142 143 topNavigation.add(new BreadCrumbPanel("breadcrumbs", selectionModel));144 topNavigation.add(createPermalink("permalink", topNavigation));139 add(topNavigation 140 .add(new BreadCrumbPanel("breadcrumbs", selectionModel)) 141 .add(createPermalink("permalink", topNavigation)) 142 .setOutputMarkupId(true) 143 ); 145 144 146 145 // General information section 147 146 add(new SolrFieldLabel("name", getModel(), FacetConstants.FIELD_NAME, getString("recordpage.unnamedrecord"))); 148 147 add(createLandingPageLink("landingPageLink")); 149 add(new FieldsTablePanel("documentProperties", new DocumentFieldsProvider(getModel(), basicPropertiesFilter, fieldOrder))); 148 149 final FieldsTablePanel fieldsTable = new FieldsTablePanel("documentProperties", new DocumentFieldsProvider(getModel(), basicPropertiesFilter, fieldOrder)); 150 fieldsTable.add(new HighlightSearchTermBehavior()); 151 add(fieldsTable); 150 152 151 153 // Resources section
Note: See TracChangeset
for help on using the changeset viewer.