PageSourceSearch

https://imgvideoarchive.com/instance/assets/0_7efce1a/searchBase.js

js imgvideoarchive.com collected 2026-10-04 18:04:19 UTC 44,211 bytes, 886 lines download raw bytes

1"use strict";
2class SearchContextMenu {
3    constructor() {
4        this.contextMenu();
5    }
6    contextMenu() {
7        iwMenu.setMenuArray('searchHit', {
8            title: iwCore.capitaliseFirst(iwi18n.gettext('search', 'Record options')),
9            groups: [
10                [
11                    {
12                        name: iwi18n.gettext(undefined, 'Parent record'),
13                        icon: 'iw-icon-view-parent',
14                        cbFn: "searchResultsContextMenu.viewParent",
15                        condition: 'iwissegment'
16                    },
17                    {
18                        name: iwi18n.gettext(undefined, 'View'),
19                        icon: 'iw-icon-view',
20                        cbFn: "searchResultsContextMenu.viewItem",
21                        condition: 'iwrecordview'
22                    },
23                    {
24                        name: iwi18n.gettext(undefined, 'View clip'),
25                        icon: 'iw-icon-view',
26                        cbFn: "searchResultsContextMenu.viewClip",
27                        condition: 'iwcanviewclip'
28                    },
29                    {
30                        name: iwi18n.gettext(undefined, 'View in new tab'),
31                        icon: 'iw-icon-view',
32                        cbFn: "searchResultsContextMenu.viewItemNewTab",
33                        condition: 'iwrecordview'
34                    },
35                    {
36                        name: iwi18n.gettext(undefined, 'Edit in and out points'),
37                        icon: 'iw-icon-edit',
38                        cbFn: "searchResultsContextMenu.editInOutPoints",
39                        condition: 'iweditinandout'
40                    },
41                    {
42                        name: iwi18n.gettext(undefined, 'Jump to point of interest'),
43                        icon: 'iw-icon-play',
44                        cbFn: "searchResultsContextMenu.playFromSearchTerm",
45                        condition: 'iwjumpto'
46                    }
47                ], [
48                    {
49                        name: iwi18n.gettext(undefined, 'Edit'),
50                        icon: 'iw-icon-edit',
51                        cbFn: "searchResultsContextMenu.editRecord",
52                        cbState: "Record",
53                        condition: 'iwcanedit'
54                    },
55                    {
56                        name: iwi18n.gettext(undefined, 'Add to %1', iw.collectionsName),
57                        icon: 'iw-icon-collection-add',
58                        cbFn: "searchResultsContextMenu.addToCollection",
59                        condition: 'iwcreatecollections'
60                    },
61                    {
62                        name: iwi18n.gettext(undefined, 'Add to basket'),
63                        icon: 'iw-icon-basket',
64                        cbFn: "searchResultsContextMenu.addToBasket",
65                        condition: 'iwbasketsenabled'
66                    },
67                    {
68                        name: iwi18n.gettext(undefined, 'Download'),
69                        icon: 'iw-icon-download',
70                        cbFn: "searchResultsContextMenu.individualDownloadForSearchResults",
71                        condition: 'iwshowdownloadlink'
72                    },
73                    {
74                        name: iwi18n.gettext(undefined, 'Run workflow'),
75                        icon: 'iw-icon-workflow',
76                        cbFn: "searchResultsContextMenu.runWorkflowForSearchHits",
77                        condition: 'iwcanrunworkflow'
78                    }
79                ], [
80                    {
81                        name: iwi18n.gettext(undefined, 'Delete'),
82                        icon: 'iw-icon-remove',
83                        delete: true,
84                        cbFn: "searchResultsContextMenu.deleteRecord",
85                        condition: 'iwcandelete'
86                    },
87                    {
88                        name: iwi18n.gettext(undefined, 'Close'),
89                        icon: 'iw-icon-close',
90                        delete: true,
91                        cbFn: "searchResultsContextMenu.closeRecord",
92                        condition: 'iwisrecordpanelopen'
93                    },
94                ]
95            ]
96        });
97    }
98}
99class SearchPagination {
100    constructor() {
101        this.totalItems = 0;
102        this.totalPages = 0;
103        this.currentPage = 1;
104        this.oldPage = this.currentPage;
105        this.displayPagination = '';
106    }
107    pageChanged(newPage) {
108        newPage = (newPage + 1);
109        this.currentPage = this.oldPage;
110        EVENT.custom('closeRecordPanel');
111        EVENT.custom('SendSearch', {
112            page: newPage,
113            fromPagination: true
114        });
115    }
116    setUpPaginator(el) {
117        if (typeof iwPaginator !== "undefined") {
118            this.paginator = iwPaginator.create();
119            el.appendChild(this.paginator.wrapper);
120            this.setPaginatorTotal(true);
121            let filter = document.getElementById('iw-search-filters'), paginationParent = document.getElementsByClassName('pagination--searchResultsBottom')[0], transitionStartFunction = () => {
122                iwCore.addClassName(paginationParent, 'is-transitioning');
123            }, transitionEndFunction = () => {
124                this.paginator.resize();
125                iwCore.removeClassName(paginationParent, 'is-transitioning');
126            };
127            EVENT.attach(filter, 'transitionstart', transitionStartFunction);
128            EVENT.attach(filter, 'transitionend', transitionEndFunction);
129        }
130    }
131    setPaginatorTotal(pageLoad) {
132        if (this.paginator) {
133            if (!pageLoad) {
134                this.paginator.setCBFunction(null);
135            }
136            this.paginator.setContainer(document.getElementById('searchResults'));
137            this.paginator.setTotal(this.totalPages, (this.currentPage - 1));
138            let callback = (newPage) => this.pageChanged(newPage);
139            this.paginator.setCBFunction(callback);
140        }
141    }
142    getPageNumberByView(prevViewType, prevPageNumber, newViewType) {
143        let prevLimit = SearchTemplates.resultsPerPage[prevViewType], prevResultsOffset = (prevLimit * (prevPageNumber - 1)) + 1, newLimit = SearchTemplates.resultsPerPage[newViewType];
144        return Math.ceil(prevResultsOffset / newLimit);
145    }
146    calculateTtlPages(type) {
147        this.totalPages = Math.ceil((this.totalItems / SearchTemplates.resultsPerPage[type]));
148        if (typeof this.currentPage !== "number" ||
149            this.currentPage > this.totalPages ||
150            this.currentPage <= 0) {
151            this.currentPage = 1;
152        }
153    }
154    updatePagination(ttlResults, page, type) {
155        this.totalItems = ttlResults;
156        this.currentPage = this.oldPage = page;
157        this.calculateTtlPages(type);
158        this.displayPagination = iwi18n.gettext(undefined, "Page %1 of %2", this.currentPage.toString(), this.totalPages.toString());
159    }
160}
161class SearchPayload {
162    constructor(vars) {
163        this.resultsPerPage = SearchTemplates.resultsPerPage.list;
164        this.keyword = '';
165        this.sort = '';
166        this.page = 1;
167        this.spellCheck = true;
168        this.customPage = [];
169        this.savedSearch = '';
170        this.clipOnly = false;
171        this.type = vars.defaultView;
172        this.collectionText = vars.collectionName;
173        this.filter = vars.defaultFilter;
174        this.showEditRecordLink = vars.showEditRecordLink === 1;
175        this.showDeleteRecordLink = vars.showDeleteRecordLink === 1;
176        this.showRunWorkflowLink = vars.showRunWorkflowLink === 1;
177        this.showDownloadLink = vars.showDownloadLink === 1;
178        this.openSearchSidePanel = vars.openSearchSidePanel === 0;
179        this.showFullPortrait = vars.showFullPortrait === 1;
180        this.showClipToggle = vars.showClipToggle === 1;
181    }
182}
183class SearchSelection extends ItemSelection {
184    constructor() {
185        super(null, null);
186        this.view();
187    }
188    onSelectionCallback() { }
189    isSelected(searchHit) {
190        var _a, _b;
191        let item = RecordItem.formatSelectionObject(searchHit.recordID, searchHit.annotation_mediaID || -1, searchHit.annotation_id || null, (_a = searchHit.annotation_startFrame) !== null && _a !== void 0 ? _a : null, (_b = searchHit.annotation_endFrame) !== null && _b !== void 0 ? _b : null, {
192            isClip: searchHit.isClip,
193            caption: searchHit.annotation_description || searchHit.Title || '',
194        });
195        return this.findIndex(item) !== -1;
196    }
197    setDomElements() {
198        this.selectionsCount = document.getElementsByClassName("multiSelect-selectionsCount")[0];
199    }
200    getSelections() {
201        if (this.selections.isEntireHitList) {
202            return true;
203        }
204        return this.getSelectionIds();
205    }
206    getSelectionIds() {
207        let recordIds = [];
208        for (let i = 0, l = this.selections.items.length; i < l; i++) {
209            recordIds.push(this.selections.items[i].recordID);
210        }
211        return recordIds;
212    }
213    clearSelections() {
214        this.clearSelect();
215        this.checkContext();
216    }
217    selectAll() {
218        super.selectAll(this.selections.isEntireHitList);
219        this.checkContext();
220    }
221    checkContext() {
222        if (this.hasSelections()) {
223            EVENT.custom('turnOffContextRightClicks');
224        }
225        else {
226            EVENT.custom('turnOnContextRightClicks');
227        }
228    }
229    hasSelections() {
230        return this.selections.items && this.selections.items.length;
231    }
232}
233class SearchTemplates {
234}
235SearchTemplates.templates = {
236    'listViewResult': '/search/templates/list-view-item',
237    'gridViewResult': '/search/templates/grid-view-item',
238    'flexViewResult': '/search/templates/flex-view-item'
239};
240SearchTemplates.resultsPerPage = {
241    list: 20,
242    grid: 100,
243    flex: 100
244};
245(function () {
246    let onLoad = EVENT.DOMcontentLoadedPoly(), viewedResults = JSON.parse(sessionStorage.getItem('viewedRecords') || '[]'), init = () => {
247        EVENT.attach(document, 'resultsRendered', function () {
248            let clipViewEnabled = !!document.getElementsByClassName('is-clipView')[0];
249            for (let i = 0; i < viewedResults.length; i++) {
250                let recordId = viewedResults[i], searchHit = document.querySelector(`.searchHit-item[data-record-id="${recordId}"]`);
251                if (searchHit && !clipViewEnabled) {
252                    searchHit.classList.add('searchHit-item--viewed');
253                }
254            }
255        });
256    };
257    if (searchAppConstructVars.showViewedState && !iw.isGuest) {
258        onLoad(window, init);
259    }
260}());
261class SearchFilters extends BaseSearchFilters {
262    constructor(cbFn) {
263        super();
264        this.containerClass = 'searchFilters';
265        this.filterEl = document.getElementById('general-page');
266        this.iwEdit = true;
267        this.cbFn = cbFn;
268        this.setUpEvents();
269        this.setUpView();
270    }
271    setUpEvents() {
272        super.setUpEvents();
273        EVENT.attach(document, 'SearchPanel', this.cbFn);
274    }
275    setFilters(filters, ttlResults, sorts) {
276        super.setFilters(filters, ttlResults, sorts);
277        if (ttlResults > 0) {
278            this.filterEl.classList.remove('hide');
279            this.filterEl.append(this.content);
280        }
281        else {
282            this.filterEl.classList.add('hide');
283        }
284    }
285    destroy() {
286        super.destroy();
287        EVENT.remove(document, 'SearchPanel', this.cbFn);
288    }
289}
290class RecordViewPanel extends BaseInfoPanel {
291    constructor(panelID, isOpen, smartClippingEnabled) {
292        super();
293        this.open = false;
294        this.maxHit = 100;
295        this.events = {};
296        this.orderWorkflows = {};
297        this.costings = {};
298        this.rate = {};
299        this.smartClips = {};
300        this.panel = document.getElementById(panelID);
301        this.smartClippingEnabled = smartClippingEnabled;
302        this.events = {};
303        this.open = isOpen;
304        this.setUpEvents();
305    }
306    setUpEvents() {
307        iwKeys.attach("esc", {
308            fn: this.close.bind(this),
309            name: iwi18n.gettext(undefined, "Close panel")
310        });
311        iwKeys.attach("a", {
312            fn: function () {
313            }.bind(this),
314            name: iwi18n.gettext(undefined, "Add to collection")
315        });
316        iwKeys.attach("left", {
317            fn: this.skipRecord.bind(this, -1),
318            name: iwi18n.gettext(undefined, "Previous result")
319        });
320        iwKeys.attach("right", {
321            fn: this.skipRecord.bind(this, 1),
322            name: iwi18n.gettext(undefined, "Next result")
323        });
324        EVENT.attach(document, 'closeRecordPanel', this.close.bind(this));
325        this.events.addSelectedClass = () => this.addSelectedClass();
326        EVENT.attach(document, 'resultsRendered', this.events.addSelectedClass);
327        EVENT.attach(document, 'iwPlayerReady', () => {
328            let player = iwPlayer.getPlayer();
329            if (player) {
330                player.player.scrollIntoView();
331            }
332        });
333    }
334    closeIcon() {
335        let close = iwUI.createEl('BUTTON', { class: 'btn-round iw-icon-close-thin', 'aria-label': iwi18n.gettext(undefined, 'Close'), 'type': 'button' });
336        EVENT.attach(close, 'click', this.close.bind(this));
337        iwToolTips.addTip(close, iwi18n.gettext(undefined, 'Close'));
338        return close;
339    }
340    buttonWrap() {
341        let wrap = iwUI.createEl('DIV', { class: 'preview-actions' }), arrowForward = iwUI.createEl('BUTTON', {
342            class: 'iw-icon-forward btn-round iw_tool_tip_link',
343            'data-tool-tip': iwi18n.gettext(undefined, 'Next'),
344            'aria-label': iwi18n.gettext(undefined, 'Next'),
345            'type': 'button'
346        }), arrowBack = iwUI.createEl('BUTTON', {
347            class: 'iw-icon-back btn-round iw_tool_tip_link',
348            'data-tool-tip': iwi18n.gettext(undefined, 'Previous'),
349            'aria-label': iwi18n.gettext(undefined, 'Previous'),
350            'type': 'button'
351        });
352        if (this.maxHit === 1) {
353            arrowBack.classList.add('is-disabled');
354            arrowForward.classList.add('is-disabled');
355        }
356        else if (this.key === 0) {
357            arrowBack.classList.add('is-disabled');
358        }
359        else if (this.key === this.maxHit - 1) {
360            arrowForward.classList.add('is-disabled');
361        }
362        EVENT.attach(arrowForward, 'click', this.skipRecord.bind(this, 1), false, true);
363        EVENT.attach(arrowBack, 'click', this.skipRecord.bind(this, -1), false, true);
364        wrap.append(arrowBack, arrowForward);
365        if (this.searchResult.dataSource !== 'collection') {
366            wrap.append(iwMenu.createMenuLink('searchHit', this.ctxMenuParams()));
367        }
368        wrap.appendChild(this.closeIcon());
369        return wrap;
370    }
371    clearSelectedClass() {
372        let results = document.getElementsByClassName('searchHit');
373        if (results.length === 0) {
374            results = document.getElementsByClassName('selected_record');
375        }
376        iwCore.massClass(iwCore.removeClassName, results, 'selected_record');
377    }
378    ;
379    addSelectedClass() {
380        let hit = document.getElementById("iw-search-hit-" + this.key), clipView = document.getElementsByClassName("clipView")[0];
381        if (hit && !clipView) {
382            this.clearSelectedClass();
383            hit.classList.add('selected_record');
384        }
385    }
386    view() {
387        let frag = document.createDocumentFragment(), container = iwUI.createEl('DIV', { class: 'search-preview' }), contentCont = iwUI.createEl('DIV', { class: 'preview-template' }), imgWrap = iwUI.createEl('DIV', {
388            class: 'preview-mediaWrap preview-mediaWrap--' + this.getValue(this.searchResult.mediaType)
389        }), mInfoWrap = iwUI.createEl('DIV', { class: 'preview-mInfoWrap' }), mInfo = iwUI.createEl('DIV', { class: 'preview-mInfo' }), typeMedia = iwUI.createEl('DIV', { class: 'preview-type media-type iw_tool_tip_link' + ' ' + ('media-type--' + this.getValue(this.searchResult.mediaType)),
390            'data-tool-tip': iwi18n.gettext(undefined, 'Media type is %1', this.getValue(this.searchResult.mediaType)), 'aria-label': iwi18n.gettext(undefined, 'Media type is %1', this.getValue(this.searchResult.mediaType)) }
390), multipleMedia = iwUI.createEl('DIV', { class: 'iw-icon iw-icon-multiple-media media-type--multiple iw_tool_tip_link',
391            'data-tool-tip': iwi18n.gettext(undefined, "Record has multiple media objects"), 'aria-label': iwi18n.gettext(undefined, 'Record has multiple media objects') }), footer = iwUI.createEl('DIV', { class: 'preview__mInfo-footer' }), validMediaType = this.checkValidMediaType(this.searchResult.mediaType);
392        footer.append(this.dateRow(this.searchResult), typeMedia);
393        if (this.searchResult.mediaObject.length > 1) {
394            footer.append(multipleMedia);
395        }
396        mInfo.append(this.titleRow(this.searchResult), this.summaryRow(this.searchResult), footer);
397        if (this.searchResult.dataSource !== 'collection' && this.searchResult.previewMedia === true) {
398            imgWrap.appendChild(iwUI.previewTag());
399        }
400        imgWrap.appendChild(this.createMediaContainer(this.searchResult));
401        this.mediaWrap = imgWrap;
402        mInfoWrap.append(mInfo);
403        if (this.smartClippingEnabled && validMediaType) {
404            this.getSmartClips(contentCont, mInfoWrap);
405        }
406        else {
407            this.fetchData(contentCont);
408        }
409        container.append(imgWrap, mInfoWrap, this.buttonWrap(), contentCont);
410        frag.append(container);
411        return frag;
412    }
413    checkValidMediaType(mediaType) {
414        let validTypes = ['video', 'audio', 'image', 'live'], typesValid;
415        if (Array.isArray(mediaType)) {
416            for (let i = 0; i < mediaType.length; i++) {
417                const type = this.getValue(mediaType[i].toLowerCase());
418                if (validTypes.indexOf(type) >= 0) {
419                    typesValid = true;
420                    break;
421                }
422            }
423        }
424        else {
425            typesValid = validTypes.indexOf(this.getValue(mediaType)) >= 0;
426        }
427        return typesValid;
428    }
429    ctxMenuParams() {
430        let params = {};
431        params.title = iwCore.capitaliseFirst(iwi18n.gettext('search', 'Options', iw.collectionsName));
432        params.recordid = this.searchResult.recordID;
433        params.mediatype = JSON.stringify(this.searchResult.mediaType);
434        params.mediaid = this.searchResult.mediaObject[0];
435        params.datasource = this.searchResult.dataSource;
436        params.mediaobject = JSON.stringify(this.searchResult.mediaObject);
437        params.url = '/record/' + this.searchResult.recordID;
438        params.hit = this.key;
439        params.createcollections = this.searchResult.externalSearchHit ? false : !!(!iw.isGuest && iw.createCollections && searchAppConstructVars.showAddToCollectionLink);
440        params.canedit = searchAppConstructVars.showEditRecordLink && this.searchResult.canEdit;
441        params.candelete = searchAppConstructVars.showDeleteRecordLink && this.searchResult.canDelete;
442        params.canrunworkflow = this.searchResult.dataSource !== 'Live' &&
443            searchAppConstructVars.showRunWorkflowLink &&
444            this.searchResult.canEdit &&
445            !this.searchResult.previewMedia;
446        params.issegment = this.searchResult.parentMediaObject && this.searchResult.parentMediaObject > 0;
447        params.parentid = this.searchResult.parentMediaObject || '';
448        params.basketsenabled = this.basketsEnabled() ? 1 : '';
449        params.showdownloadlink = searchAppConstructVars.showDownloadLink && this.searchResult.canDownload;
450        params.recordview = true;
451        return params;
452    }
453    ;
454    render() {
455        this.requests.forEach((f) => f.abort());
456        this.requests = [];
457        let view = this.view();
458        iwCore.clearElement(this.panel);
459        this.panel.appendChild(view);
460    }
461    updateTemplate(container, data) {
462        container.insertAdjacentHTML('beforeend', data);
463    }
464    fetchData(container) {
465        this.requests.push(iwCore.ajax({
466            type: 'GET',
467            dataType: 'json',
468            scope: this,
469            url: '/record/retrieve',
470            data: {
471                id: this.searchResult.recordID
472            },
473            success: (response) => {
474                this.recordData = response.data;
475                this.updateTemplate(container, response.template);
476            },
477            error: (e) => {
478                if (e.readyState !== 0 && e.readyState !== 4) {
479                    iwNotifications.error(iwi18n.gettext(undefined, 'There was a problem retrieving record 
479information'));
480                }
481            }
482        }));
483    }
484    skipRecord(direction) {
485        let selectorString = '[data-record-id="' + this.searchResult.recordID + '"]';
486        selectorString += '[data-record-datasource="' + this.searchResult.dataSource + '"]';
487        let recordElm = document.querySelector(selectorString), target;
488        if (recordElm) {
489            if (direction > 0 && recordElm.nextElementSibling) {
490                target = recordElm.nextElementSibling;
491            }
492            if (direction < 0 && recordElm.previousElementSibling) {
493                target = recordElm.previousElementSibling;
494            }
495            if (target) {
496                let searchHitKey = parseInt(target.getAttribute('data-record-key'), 10);
497                EVENT.custom('openRecord', { hit: searchHitKey });
498            }
499        }
500    }
501    basketsEnabled() {
502        if (this.searchResult) {
503            return !(this.searchResult.previewMedia ||
504                this.searchResult.dataSource === 'collection' ||
505                this.searchResult.mediaType === 'Live') &&
506                (iw.basketsEnabled &&
507                    (this.searchResult.mediaObjectState.indexOf('archived') !== -1 &&
508                        this.searchResult.mediaObject.length > 0));
509        }
510        return iw.basketsEnabled;
511    }
512    ;
513    updateView(hit, key, count) {
514        if (!this.searchResult || !(this.searchResult.recordID === hit.recordID && this.searchResult.dataSource === hit.dataSource)) {
515            this.maxHit = count;
516            this.key = key;
517            this.searchResult = JSON.parse(JSON.stringify(hit));
518            requestAnimationFrame(() => this.addSelectedClass());
519            if (!this.open) {
520                this.panel.classList.remove('sidePanel-hide');
521                document.body.classList.add('previewPanel-active');
522                this.open = true;
523            }
524            EVENT.custom('iwSearch', { action: 'Panel open', label: this.searchResult.recordID });
525            this.render();
526        }
527        else if (this.open) {
528            this.close();
529        }
530        return this.open;
531    }
532    close() {
533        if (this.searchResult.recordID !== -1) {
534            EVENT.custom('iwSearch', { action: 'Panel close', label: this.searchResult.recordID });
535        }
536        this.searchResult.recordID = -1;
537        this.searchResult.dataSource = "";
538        if (this.panel) {
539            this.panel.classList.add('sidePanel-hide');
540        }
541        document.body.classList.remove('previewPanel-active');
542        this.clearSelectedClass();
543        this.open = false;
544        this.requests.forEach((f) => f.abort());
545        this.requests = [];
546        iwCore.clearElement(this.mediaContainer);
547        EVENT.custom('toggleRecordView');
548    }
549    getSmartClips(contentCont, imgWrap) {
550        let paramStr = window.location.hash.replace('#', '').replace('/', ''), searchParams = new URLSearchParams(paramStr), params = {
551            recordID: this.searchResult.recordID
552        };
553        if (searchParams.has('query')) {
554            params.query = searchParams.get('query');
555        }
556        iwCore.ajax({
557            type: 'GET',
558            url: '/search/getsmartclips',
559            data: params,
560            beforeSend: () => iwCore.loading(true),
561            complete: () => iwCore.loading(false),
562            success: (e) => {
563                if (e.success) {
564                    this.showOrder = e.showOrder;
565                    this.showOrderFor = e.showOrderFor;
566                    this.orderWorkflows = e.workflows;
567                    this.costings = e.costings;
568                    this.rate = e.rate;
569                    this.name = e.name;
570                    this.mediaType = e.mediaType;
571                    if (e.items.length) {
572                        this.createTabs(contentCont, imgWrap, e);
573                    }
574                    else {
575                        this.fetchData(contentCont);
576                    }
577                }
578                else {
579                    iwNotifications.error(iwi18n.gettext(undefined, 'Something went wrong, please try again later'));
580                }
581            },
582            error: () => iwNotifications.error(iwi18n.gettext(undefined, 'Something went wrong, please try again later'))
583        });
584    }
585    createTabs(contentCont, imgWrap, e) {
586        let smartClipsCont = iwUI.createEl('div', { class: 'iw-smart-clips' }), metadataCont = iwUI.createEl('div', { class: 'hide' }), desc = iwUI.createEl('DIV', { class: 'preview__smart-clip-hits' }), smartClipListCont = iwUI.createEl('UL', { class: 'iw-list' }), smartClipActions = iwUI.createEl('DIV', { class: 'iw-smart-clips__actions' }), clipsForRecord = [], params = {
587            createcollections: this.searchResult.externalSearchHit ? false : !!(!iw.isGuest && iw.createCollections && searchAppConstructVars.showAddToCollectionLink)
588        }, changeTab = (isSmart) => {
589            if (isSmart) {
590                iwCore.addClassName(metadataCont, 'hide');
591                iwCore.removeClassName(smartClipsCont, 'hide');
592            }
593            else {
594                if (!metadataCont.children.length) {
595                    this.fetchData(metadataCont);
596                }
597                iwCore.addClassName(smartClipsCont, 'hide');
598                iwCore.removeClassName(metadataCont, 'hide');
599            }
600        }, tabs = new Tabs([
601            { title: iwi18n.gettext(undefined, 'Clips'), cbFn: () => changeTab(true) },
602            { title: iwi18n.gettext(undefined, 'Metadata'), cbFn: () => changeTab(false) },
603        ], null, false), createMediaTitle = (item) => {
604            let titleContainer = iwUI.createEl('DIV', { class: 'iw-list-item iw-list-item--media-name' }), title = iwUI.createEl('H2', { class: 'media-name--title' }), titleActions = iwUI.createEl('DIV', { class: 'media-name--actions' }), ctxName = "smartClipMediaCtx-group", hasWorkflows = this.orderWorkflows && this.orderWorkflows && Object.keys(this.orderWorkflows).length > 0, ctxParams = {
605                mediatype: this.mediaType,
606                rate: this.rate,
607                costings: JSON.stringify(this.costings),
608                isclip: true,
609                objectname: 'clip',
610                caption: item.name,
611                recordid: this.searchResult.recordID,
612                mediaid: item.annotation_mediaID,
613                createcollections: this.searchResult.externalSearchHit ? false : !!(!iw.isGuest && iw.createCollections && searchAppConstructVars.showAddToCollectionLink),
614                showorder: this.showOrder && item.isTemporal && hasWorkflows,
615                showorderfor: this.showOrderFor && item.isTemporal && hasWorkflows,
616            };
617            if (item.name) {
618                title.textContent = item.name;
619            }
620            else {
621                title.textContent = iwi18n.gettext(undefined, 'Media object: %1', item.annotation_mediaID);
622            }
623            titleActions.append(iwMenu.createMenuLink(ctxName, ctxParams));
624            titleContainer.append(title, titleActions);
625            return titleContainer;
626        }, createClipItem = (item) => {
627            if (this.searchResult.mediaType[0] === 'Live' && this.searchResult.mediaOriginalFileName[0]) {
628                let stillsInterval = 5, closestStill = Math.max(0, Math.floor(item.annotation_startFrame / item.rate / stillsInterval));
629                item.thumbnail = this.searchResult.mediaOriginalFileName[0].replace('video.m3u8', 't/out' + closestStill + '.jpg');
630            }
631            let cont = iwUI.createEl('LI', { class: 'iw-list-item iw-list-item--smart-clip' }), thumbWrap = iwUI.createEl('DIV', { class: 'iw-list-item__thumbWrap' }), content = iwUI.createEl('DIV', { class: 'iw-list-item__content' }), time = iwUI.createEl('DIV', { class: 'iw-list-item__title' }), desc = iwUI.createEl('DIV', { class: 'iw-list-item__desc' }), actions = iwUI.createEl('DIV', { class: 'iw-list-item__actions' }), mediaIndex = this.getMediaObjectIndex(item.annotation_mediaID), thumb = iwUI.createEl('IMG', {
632                class: 'iw-list-item__thumb',
633                src: iwUI.imageFallback(this.getValue(this.searchResult.mediaType[mediaIndex]), item.thumbnail),
634                onerror: 'this.src = "' + iwUI.imageFallback(this.getValue(this.searchResult.mediaType[mediaIndex])) + '"'
635            }), hasWorkflows = this.orderWorkflows && this.orderWorkflows && Object.keys(this.orderWorkflows).length > 0, ctxParams = {
636                recordid: this.searchResult.recordID,
637                mediaid: item.annotation_mediaID,
638                startframe: item.annotation_startFrame,
639                endframe: item.annotation_endFrame,
640                caption: item.annotation_description.slice(0, 255),
641                createcollections: this.searchResult.externalSearchHit ? false : !!(!iw.isGuest && iw.createCollections && searchAppConstructVars.showAddToCollectionLink),
642                clipurl: item.clipURL,
643                istemporal: item.isTemporal,
644                objectname: 'clip',
645                showorder: this.showOrder && item.isTemporal && hasWorkflows,
646                showorderfor: this.showOrderFor && item.isTemporal && hasWorkflows,
647                costings: JSON.stringify(this.costings),
648                type: 'order',
649                rate: this.rate,
650                caneditclip: this.searchResult.canEdit && item.isTemporal,
651                isimage: !item.isTemporal,
652                imageurl: item.imageUrl
653            };
654            if (typeof item.startTime !== 'undefined' && typeof item.endTime !== 'undefined') {
655                time.textContent = item.startTime.replace('00:00', '00') + ' - ' + item.endTime.replace('00:00', '00');
656            }
657            if (item.annotation_description) {
658                desc.innerHTML = iwEmoji.toImage(iwCore.escapeHTML(item.annotation_description).replace(/(\r\n|\n|\r)/gm, ' '));
659            }
660            EVENT.attach(cont, 'click', () => this.updatePlayer(item));
661            actions.append(iwMenu.createMenuLink('smartClipCtx-single', ctxParams));
662            thumbWrap.appendChild(thumb);
663            content.append(time, desc);
664            thumb.setAttribute('alt', iwi18n.gettext(undefined, 'Clip thumbnail for %1', item.annotation_description));
665            cont.append(thumbWrap, content, actions);
666            return cont;
667        };
668        desc.textContent = iwi18n.ngettext(undefined, '%1 clip found', '%1 clips found', e.items.length, e.items.length.toString());
669        this.smartClips = {};
670        e.items.forEach((f) => {
671            if (f.annotation_mediaID === parseInt(this.searchResult.mediaObject[0], 10)) {
672                clipsForRecord.push({ startFrame: f.annotation_startFrame, endFrame: f.annotation_endFrame, title: f.annotation_description });
673            }
674            if (!this.smartClips[f.annotation_mediaID]) {
675                this.smartClips[f.annotation_mediaID] = [];
676            }
677            f.isClip = true;
678            f.mediaID = f.annotation_mediaID;
679            this.smartClips[f.annotation_mediaID].push(f);
680        });
681        for (let group in this.smartClips) {
682            if (this.smartClips.hasOwnProperty(group)) {
683                let items = this.smartClips[group];
684                if (items.length > 0) {
685                    smartClipListCont.append(createMediaTitle(items[0]));
686                }
687                items.forEach(item => {
688                    smartClipListCont.append(createClipItem(item));
689                });
690            }
691        }
692        iwMenu.setMenuArray('smartClipCtx-single', {
693            title: '',
694            groups: [
695                [
696                    { name: iwi18n.gettext('collections', 'View above'), icon: 'iw-icon-eye', cbFn: this.updateImagePreview.bind(this), condition: 'iwisimage' },
697                    { name: iwi18n.gettext('collections', 'View'), icon: 'iw-icon-view', cbFn: this.clipsFromMulti.bind(this), condition: 'iwisimage' },
698                    { name: iwi18n.gettext('collections', 'Play above'), icon: 'iw-icon-play', cbFn: this.updatePlayer.bind(this), condition: 'iwistemporal' },
699                    { name: iwi18n.gettext('collections', 'View clip'), icon: 'iw-icon-view', linkRef: 'iwclipurl', condition: 'iwistemporal' },
700                    { name: iwi18n.gettext('collections', 'Edit in and out points'), icon: 'iw-icon-edit', cbFn: (params) => { this.clipsFromSingle(params); }, condition: 'iwcaneditclip' }
701                ],
702                [
703                    { name: iwi18n.gettext('collections', 'Add to %1', iw.collectionsName), icon: 'iw-icon-collection-add', cbFn: "searchResultsContextMenu.addToCollection", condition: 'iwcreatecollections' },
704                    { name: iwCore.capitaliseFirst(iwi18n.gettext('collections', '%1 a download...', iw.ordersTitleTerm)), icon: 'iw-icon-order', cbFn: 'CISSendJobWidgets.send', condition: 'iwshoworder' },
705                    { name: iwCore.capitaliseFirst(iwi18n.gettext('collections', '%1 a download for...', iw.ordersTitleTerm)), icon: 'iw-icon-order', cbFn: 'CISSendJobWidgets.sendFor', condition: 'iwshoworderfor' },
706                ]
707            ]
708        });
709        iwMenu.setMenuArray("smartClipMediaCtx-group", {
710            title: '',
711            groups: [[
712                    {
713                        name: iwi18n.gettext('collections', 'View all clips'),
714                        icon: 'iw-icon-view',
715                        cbFn: (params) => {
716                            this.clipsFromMulti(params);
717                        }
718                    },
719                    {
720                        name: iwi18n.gettext('collections', 'Add all clips to %1', iw.collectionsName),
721                        icon: 'iw-icon-collection-add',
722                        cbFn: (params, el) => CISCollectionsLink.fireMultiSelectRecordAdd(el, this.smartClips[params.iwmediaid]),
723                        condition: 'iwcreatecollections'
724                    },
725                    {
726                        name: iwCore.capitaliseFirst(iwi18n.gettext('collections', '%1 all downloads...', iw.ordersTitleTerm)),
727                        icon: 'iw-icon-order',
728                        cbFn: (params, el) => {
729                            params.clip = this.smartClips[params.iwmediaid];
730                            CISSendJobWidgets.send(params, el, false, false);
731                        },
732                        condition: 'iwshoworder'
733                    },
734                    {
735                        name: iwCore.capitaliseFirst(iwi18n.gettext('collections', '%1 all downloads for...', iw.ordersTitleTerm)),
736                        icon: 'iw-icon-order',
737                        cbFn: (params, el) => {
738                            params.clip = this.smartClips[params.iwmediaid];
739                            CISSendJobWidgets.send(params, el, false, true);
740                        },
741                        condition: 'iwshoworderfor'
742                    }
743                ]]
744        });
745        iwMenu.setMenuArray('smartClipAllCtx', {
746            title: '',
747            groups: [[{
748                        name: iwi18n.gettext('collections', 'Add all clips to %1', iw.collectionsName),
749                        icon: 'iw-icon-collection-add',
750                        cbFn: (params, el) => {
751                            let items = e.items.map((m) => {
752                                return {
753                                    recordID: this.searchResult.recordID,
754                                    mediaID: m.annotation_mediaID,
755                                    startFrame: m.annotation_startFrame,
756                                    endFrame: m.annotation_endFrame,
757                                    caption: m.annotation_description.substr(0, 255),
758                                    isClip: true,
759                                    objectname: 'clip'
760                                };
761                            });
762                            CISCollectionsLink.fireMultiSelectRecordAdd(el, items);
763                        },
764                        condition: 'iwcreatecollections'
765                    }
766                ]]
767        });
768        smartClipActions.append(desc);
769        if (params.createcollections) {
770            smartClipActions.append(iwMenu.createMenuLink('smartClipAllCtx', params));
771        }
772        imgWrap.append(tabs.mainContainer);
773        smartClipsCont.append(smartClipActions, smartClipListCont);
774        contentCont.append(smartClipsCont, metadataCont);
775    }
776    clipsFromSingle(params) {
777        let clips = [];
778        clips.push({
779            title: decodeURIComponent(params.iwcaption),
780            startFrame: params.iwstartframe,
781            endFrame: params.iwendframe
782        });
783        iwSearchUIApi.goToInOutPoints(params.iwrecordid, params.iwmediaid, clips, false);
784    }
785    clipsFromMulti(params) {
786        let fullClips = this.smartClips[params.iwmediaid], clips = [];
787        for (let i = 0; i < fullClips.length; i++) {
788            clips.push({
789                title: fullClips[i].title,
790                startFrame: fullClips[i].startFrame,
791                endFrame: fullClips[i].endFrame
792            });
793        }
794        iwSearchUIApi.goToInOutPoints(params.iwrecordid, params.iwmediaid, clips, false);
795    }
796    updatePlayer(clipItem) {
797        var _a, _b, _c, _d, _e;
798        iwCore.clearElement(this.mediaWrap);
799        this.mediaWrap.className = 'preview-mediaWrap preview-mediaWrap--video';
800        this.mediaContainer = iwUI.createEl('DIV', { class: 'preview-video' });
801        this.requests.forEach((f) => f.abort());
802        this.requests = [];
803        this.requests.push(mediaPreviewer.insertPlayer(this.mediaContainer, (_b = (_a = clipItem.iwmediaid) !== null && _a !== void 0 ? _a : clipItem.annotation_mediaID) !== null && _b !== void 0 ? _b : -1, (_c = this.searchResult.recordID) !== null && _c !== void 0 ? _c : -1, (_d = clipItem.iwstartframe) !== null && _d !== void 0 ? _d : clipItem.annotation_startFrame, (_e = clipItem.iwendframe) !== null && _e !== void 0 ? _e : clipItem.annotation_endFrame, null, { autoPlay: true }, ''));
804        this.mediaWrap.append(this.mediaContainer);
805    }
806    updateImagePreview(clipItem) {
807        var _a;
808        let currentMediaId = clipItem.iwmediaid || clipItem.annotation_mediaID, mediaIndex = this.getMediaObjectIndex(currentMediaId);
809        iwCore.clearElement(this.mediaWrap);
810        this.mediaWrap.className = 'preview-mediaWrap preview-mediaWrap--image';
811        this.mediaContainer = iwUI.createEl('IMG', {
812            class: 'preview-img',
813            src: decodeURIComponent(clipItem.iwimageurl),
814            alt: (_a = decodeURIComponent(clipItem.iwcaption)) !== null && _a !== void 0 ? _a : '',
815            onerror: 'this.src="' + iwUI.imageFallback("image") + '"'
816        });
817        if (this.searchResult.thumbnailWidth[mediaIndex] && this.searchResult.thumbnailHeight[mediaIndex] && iwUI.isPortrait(this.searchResult.thumbnailWidth[mediaIndex], this.searchResult.thumbnailHeight[mediaIndex])) {
818            this.mediaContainer.classList.add('preview-img--portrait');
819        }
820        EVENT.attach(this.mediaContainer, 'click', () => this.clipsFromMulti({ iwrecordid: clipItem.iwrecordid, iwmediaid: clipItem.iwmediaid }));
821        this.mediaWrap.append(this.mediaContainer);
822    }
823    getMediaObjectIndex(mediaID) {
824        let mediaIndex = 0;
825        mediaIndex = this.searchResult.mediaObject.findIndex((id) => parseInt(id, 10) === parseInt(mediaID, 10));
826        return mediaIndex;
827    }
828    destroy() {
829        EVENT.remove(document, 'resultsRendered', this.events.addSelectedClass);
830    }
831}
832class CollectionViewPanel extends RecordViewPanel {
833    constructor(panelID, isOpen) {
834        super(panelID, isOpen, false);
835    }
836    render() {
837        let view = this.view();
838        iwCore.clearElement(this.panel);
839        this.panel.appendChild(view);
840    }
841    dateEl(title, date) {
842        let dateContainer = iwUI.createEl('div', { class: 'iPanel__date-item' }), dateTitle = iwUI.createEl('p', { class: 'iPanel__date-lbl' }), dateText = iwUI.createEl('p', { class: 'iPanel__date-txt' });
843        dateTitle.textContent = title;
844        dateText.textContent = date;
845        dateContainer.append(dateTitle, dateText);
846        return dateContainer;
847    }
848    cTitleRow(searchResult) {
849        let title = iwUI.createEl('H2', { class: 'preview-title' }), titleTxt = iwUI.createEl('SPAN', {
850            class: 'preview-title-txt iw_tool_tip_link',
851            'data-tool-tip': iwi18n.gettext(undefined, 'View %1', iw.collectionsName),
852        }), titleIcon = iwUI.createEl('BUTTON', { class: 'icon-view iw-icon-left-arrow iw_tool_tip_link',
853            'aria-label': iwi18n.gettext(undefined, 'View %1', iw.collectionsName),
854            'type': 'button',
855            'data-tool-tip': iwi18n.gettext(undefined, 'View %1', iw.collectionsName),
856        });
857        titleTxt.textContent = searchResult.fieldClasses.title;
858        title.append(titleTxt, titleIcon);
859        EVENT.attach(title, 'click', () => { window.location.href = searchResult.url; });
860        return title;
861    }
862    view() {
863        let frag = document.createDocumentFragment(), container = iwUI.createEl('div', { class: 'search-preview search-preview--collections' }), imgWrap = iwUI.createEl('div', { class: 'preview-mediaWrap' }), buttonsEl = this.buttonWrap(), cInfoWrap = iwUI.createEl('div', { class: 'preview-mInfoWrap' }), cInfo = iwUI.createEl('div', { class: 'preview-mInfo' }), avatar = iwUI.createEl('div', { class: 'owner-icon owner-icon--iPanel iw_tool_tip_link', 'data-tool-tip': this.searchResult.collectionOwner }), dateRow = iwUI.createEl('div', { class: 'iPanel__date' }), editedDate = new Date(this.searchResult.collectionModifiedDate).toLocaleDateString(iwi18n.getLocale()), descriptionWrap = iwUI.createEl('div', { class: 'iPanel__desc-wrap' }), description = iwUI.createEl('p', { class: 'iPanel-desc' }), cFooter = iwUI.createEl('div', { class: 'iPanel__footer' }), collectionCount = iwUI.createEl('p', { class: 'iPanel-numItems' });
864        imgWrap.appendChild(this.createMediaContainer(this.searchResult));
865        dateRow.append(this.dateEl(iwi18n.gettext('collections', 'Created:'), this.searchResult.fieldClasses.date), this.dateEl(iwi18n.gettext('collections', 'Edited:'), editedDate));
866        cInfo.append(this.cTitleRow(this.searchResult), dateRow);
867        cInfoWrap.append(cInfo);
868        avatar.textContent = this.searchResult.collectionOwner.slice(0, 2).toUpperCase();
869        imgWrap.append(buttonsEl, avatar, cInfoWrap);
870        description.textContent = this.searchResult.collectionDescription || iwi18n.gettext('collections', 'No description set for this %1', iw.collectionsName);
871        descriptionWrap.append(description);
872        collectionCount.textContent = iwi18n.ngettext(undefined, '%1 item in %2', '%1 items in %2', this.searchResult.collectionNumItems, iw.collectionsName);
873        cFooter.append(collectionCount);
874        container.append(imgWrap, descriptionWrap, cFooter);
875        frag.append(container);
876        return frag;
877    }
878}
879var ViewType;
880(function (ViewType) {
881    ViewType[ViewType["list"] = 0] = "list";
882    ViewType[ViewType["grid"] = 1] = "grid";
883    ViewType[ViewType["flex"] = 2] = "flex";
884    ViewType[ViewType["playlist"] = 3] = "playlist";
885})(ViewType || (ViewType = {}));
886//# sourceMappingURL=searchBase.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.