Widgets.Search / Result List

In addition to the Widgets.Base these options are available in the API for the Search Widget.

Rendering

itemTemplate

Specifies that a custom HTML template for each item should be used instead of the default one. Any of the custom templates uploaded with the custom widget can be assigned to this property directly.

Example
afterInitialize: function () {
	this.itemTemplate = this.customResources['myTemplate.html'];
},
Arguments

To see which parameters are passed into this template by default, you can use the following template for testing:

myTemplate.html
<%- JSON.stringify(arguments[0]) %>
Escaping

To show the title, which may include search highlighting, it is recommended to use the item.escape() method. This will generate escaped HTML, so it should be used with the <%= … %> syntax, instead of the usual <%- … %>. Example:

myTemplate.html
<h4>
    <a href="<%- displayLink %>" rel="noopener noreferrer" class="js-link">
        <%= item.escape('title') %>
    </a>
</h4>
Example

An example template, which roughly reproduces the default item template behaviour, would look as follows:

NOTE Until Squirro 2.6.5, the displayLink parameter used to be called itemLink.

myTemplate.html
<div class="item-link js-link">
    <div class="inner-content">
		<h4>
        	<%= item.escape('title') || $.t('item:untitled') %>
        </h4>
		<h5 class="additional-info ellipsis">
        	<%- displayTime %>
            · 
            <%- displayLink %>
        </h5>
        <div class="abstract">
            <%= abstract %>
        </div>
    </div>
</div>

getItemTemplateParams

widget.getItemTemplateParams()

If implemented, and if itemTemplate is defined, the returned value of getItemTemplateParams() will be passed onto the HTML side.

Example
getItemTemplateParams: function () {
    return {
		external_id: 1234,
	};
},

getCustomItemDetailOptions

widget.getCustomItemDetailOptions()

Starting from Squirro 2.6.5, the item detail view which opens when clicking an item in the list, can be customised by implementing this method.

Customising the toolbar

To the right of the item detail panel, there is a toolbar which can be customised and extended.

It is possible to hide any default action, change its icon (note that the star action requires two icons), and add new actions to the toolbar.

All the icons are expected to be string identifiers of the icons from Material Design set (http://archives.materializecss.com/0.100.2/icons.html)


Example
getCustomItemDetailOptions: function (options) {
    var item = options.item;

    return {
		toolbar: {
            star: {
                hide: false,
                iconStarred: '',
                iconUnstarred: '',
            },
            email: {
                hide: false,
                icon: '',
            },
            link: {
                hide: false,
                icon: '',
            },
            print: {
                hide: false,
                icon: '',
            },
            smartfilter: {
                hide: false,
                icon: '',
            },
            tags: {
                hide: false,
                icon: '',
            },
            explain: {
                hide: false,
                icon: '',
            },
            stlToggle: {
                hide: false,
                icon: '',
            },
            // Custom actions
            custom: [
                {
                    icon: '',
                    handler: () => { 
                        // NOTE ES6 notation, convert to ES5 if targeting older browsers
						// The item is accessible under options.item
                    },
                    after: 'print', // Can be any name as shown above (ie, star, email, link)
                    title: '', // Tooltip for the action
                }
            ],
        },
	};
},

customDetailTemplate

Specifies that a custom HTML template to replace the existing Item Detail content. Any of the custom templates uploaded with the custom widget can be assigned to this property directly.

Example
afterInitialize: function () {
	this.customDetailTemplate = this.customResources['myTemplate.html'];
},
Arguments

To see which parameters are passed into this template by default, you can use the following template for testing:

myTemplate.html
<%- JSON.stringify(arguments[0]) %>
Escaping

To show the title, which may include search highlighting, it is recommended to use the item.escape() method. This will generate escaped HTML, so it should be used with the <%= … %> syntax, instead of the usual <%- … %>. Example:

myTemplate.html
<h4>
    <a href="<%- displayLink %>" rel="noopener noreferrer" class="js-link">
        <%= item.escape('title') %>
    </a>
</h4>
Example

An example template, which reproduces the default item template behaviour, would look as follows:

NOTE Until Squirro 2.6.5, the displayLink parameter used to be called itemLink.

myTemplate.html
<% if (stlViewerEnabled) { %>
    <div class="stlviewer-placeholder"></div>
<% } %>
<article class="clearfix">
    <header class="respect-article-width">
        <h2 class="item-title">
            <% if (link) { %><a href="<%- link %>" rel="noopener noreferrer" target="_blank" class="js-itemlink"><% } %>
            <%= item.escape('title') /* escaped to correctly add search highlighting (see: ItemModel) */ %>
            <% if (link) { %></a><% } %>
        </h2>

        <div class="metaData">
            <span class="date"><%- displayTime %></span>
            <% _.each(sources, function (source) { %>
                <span class="middot">·</span>
                <a class="js-facet source"
                    data-value="source:<%- source.id %>">
                    <%- source.title %>
                </a>
            <% }) %>
            <% if (link) { %>
                <span class="middot">·</span>
                <a href="<%- link %>" rel="noopener noreferrer" target="_blank" class="js-itemlink link">
                    <%- linkTitle %>
                    <button type="button" data-clipboard-text="<%- link %>" class="copy-link js-copy btn btn-flat">
                        <i class="material-icons grey-text">content_copy</i>
                    </button>
                </a>
            <% } %>
        </div>
    </header>

    <% if (pdfViewerEnabled) { %>
        <div class="pdfviewer-placeholder"></div>
    <% } else if (item.get('body')) { %>
        <div class="body respect-article-width">
            <%= item.highlight('body', item.get('body')) %>
        </div>
    <% } else if (item.get('abstract')) { %>
        <% if (item.hasThumbnail() && (item.get('webshot_width') > 100 || item.get('webshot_height') > 100)) { %>
            <div class="thumbnail respect-article-width">
                <img src="<%- item.getThumbnailURL(245, false, false) %>"/>
            </div>
        <% } %>
        <p class="body respect-article-width">
            <%= item.escape('abstract') /* escaped to correctly add search highlighting (see: ItemModel) */ %>…
            <% if (link) { %>
                <a href="<%- link %>" rel="noopener noreferrer" target="_blank" class="js-itemlink"><%- $.t('itemDetail:more') %></a>
            <% } %>
        </p>
    <% } %>
    <div class="keywords-toggle js-keywords-toggle toggle-show hide respect-article-width">
        <a class="keywords-toggle-inner js-toggleKeywords">
            <span class="keywords-toggle-show">
                <%- $.t('itemDetail:keywords:toggle:show') %>
            </span>
            <span class="keywords-toggle-hide">
                <%- $.t('itemDetail:keywords:toggle:hide') %>
            </span>
        </a>
    </div>
    <div class="keywords-placeholder js-keywords-placeholder hide respect-article-width"></div>
    <% if (item.has('explanation')) { %>
        <div class="item-detail-explain-placeholder"></div>
    <% } %>
</article>

getCustomDetailTemplateParams

widget.getCustomDetailTemplateParams()

If implemented, and if customDetailTemplate is defined, the returned value of getCustomDetailTemplateParams() will be passed onto the HTML side.

Example
getCustomDetailTemplateParams: function () {
    return {
		external_id: 1234,
	};
},

customItemDetailHandler

If implemented, you can completely replace the '_onDetail' execution pattern with your own custom code used in conjunction with 'customItemDetailHandlerOptions'.

Internally we execute the following code:

Example
_onDetail(e) {
    const handler = this.options.customItemDetailHandler;
    const handlerOptions = {
        ...this.options.customItemDetailHandlerOptions,
        item: this.model,
    };
    const prehookResult = handler && handler(handlerOptions);
    
    if (prehookResult) {
        return;
    }

// [... remaining code here for _onDetail]
}

customItemDetailHandlerOptions

If implemented, you can completely replace the '_onDetail' execution with your own custom code used in conjunction with 'customItemDetailHandler'.

onDetail

Helper function, called when showing the item detail view, it allows you to add additional code to the normal execution of opening an item.

onItemRendered

Helper function, called when after the item detail has finished rendering.