UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

3 lines 6.56 kB
/* @license */ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("kendo.core.min.js"),require("kendo.icons.min.js"),require("kendo.html.button.min.js"),require("kendo.popup.min.js"),require("kendo.chip.min.js")):typeof define==`function`&&define.amd?define([`exports`,`kendo.core.min`,`kendo.icons.min`,`kendo.html.button.min`,`kendo.popup.min`,`kendo.chip.min`],t):(e=typeof globalThis<`u`?globalThis:e||self,t((e.kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Citation={}),e.kendo._globals.Core,e.kendo._globals.Icons,e.kendo._globals.HtmlButton,e.kendo._globals.Popup,e.kendo._globals.Chip))})(this,function(e,t,n,r,i,a){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let o={id:`citation`,name:`Citation`,category:`web`,description:`The Citation component.`,depends:[`core`,`html.button`,`chip`,`icons`,`popup`]};(function(e,t){let n=window.kendo,r=n.ui.Widget,i=n.htmlEncode,a=`.kendoCitation`,o=`open`,s=`click`,c=r.extend({init:function(e,t){let i=this;r.fn.init.call(i,e,t),i._hostElement=i.element,i._docNS=`.kendoCitation.`+n.guid().replace(/-/g,``),i._isOpen=!1,i._currentPage=0,i._render(),i._bindEvents(),n.notify(i)},options:{name:`Citation`,sources:[],label:null,svgIcon:`globe`,showAdditionalCount:!0,showOn:`hover`,sourceIcon:`globe`,sourceSVGIcon:null,popoverWidth:318,bodyTemplate:null,messages:{previousSourceAction:`Previous source`,nextSourceAction:`Next source`}},events:[o],_render:function(){let t=this,r=t.options,a=r.label===null?t._deriveLabel():r.label,o=r.showAdditionalCount===!0&&r.sources.length>1?r.sources.length-1:0,s=[a,o>0?`+${o}`:null].filter(Boolean).join(` `);t.element.empty(),t._chip=new n.ui.Chip(t.element,{attributes:{"aria-pressed":`false`,class:`k-citation`},fillMode:`outline`,icon:r.svgIcon,label:i(s),rounded:`full`,size:`small`}),t.wrapper=t._chip.wrapper,t._chipElement=t._chip.element,t.element=t.wrapper,t._popoverContent=e(`<div class="k-popover k-citation-popover" aria-hidden="true"></div>`),t._popup=new n.ui.Popup(t._popoverContent,{anchor:t.wrapper,origin:`bottom left`,position:`top left`,collision:`fit flip`,animation:!1}),r.popoverWidth&&t._popoverContent.css(`width`,r.popoverWidth),t._renderPopover()},_deriveLabel:function(){let e=this.options.sources;if(e&&e.length>0&&e[0].url)try{return new URL(e[0].url).hostname}catch{return``}return``},_renderPopover:function(){let e=this,t=e.options;if(t.bodyTemplate!==null){let n=t.bodyTemplate;e._popoverContent.html(n({sources:t.sources}));return}let r=`<div class="k-popover-header k-citation-popover-header"><span class="k-citation-pages"></span><div class="k-button-group k-button-group-flat" role="group">${n.html.renderButton(`<button class="k-group-start k-citation-prev" aria-label="${i(t.messages.previousSourceAction)}"></button>`,{fillMode:`flat`,icon:`arrow-left`,size:`small`})}${n.html.renderButton(`<button class="k-group-end k-citation-next" aria-label="${i(t.messages.nextSourceAction)}"></button>`,{fillMode:`flat`,icon:`arrow-right`,size:`small`})}</div></div>`,a=`<div class="k-popover-body">`+t.sources.map(t=>`<div class="k-citation-popover-view">${e._sourceHtml(t)}</div>`).join(``)+`</div>`;e._popoverContent.html(r+a),e._updatePage()},_updatePage:function(){let e=this,t=e._currentPage,n=e.options.sources.length;e._popoverContent[0].style.setProperty(`--kendo-citation-popover-view-current`,String(t+1)),e._popoverContent.find(`.k-citation-pages`).text(`${t+1}/${n}`),e._popoverContent.find(`.k-citation-prev`).prop(`disabled`,t===0).toggleClass(`k-disabled`,t===0),e._popoverContent.find(`.k-citation-next`).prop(`disabled`,t>=n-1).toggleClass(`k-disabled`,t>=n-1)},_sourceHtml:function(e){let t=this.options,r=e.title?`<div class="k-citation-popover-view-title">${i(e.title)}</div>`:``,a=t.sourceSVGIcon||t.sourceIcon,o=e.url?`<a href="${n.sanitizeLink(e.url)}" class="k-citation-popover-view-source" target="_blank" rel="noopener noreferrer">${n.ui.icon({icon:a})}${i(e.url)}</a>`:``,s=e.description?`<span class="k-citation-popover-view-body">${i(e.description)}</span>`:``;return r+o+s},_bindEvents:function(){let t=this;t.options.showOn===`click`?(t.wrapper.on(`click.kendoCitation`,t._onChipClick.bind(t)),e(document).on(s+t._docNS,function(n){t._isOpen&&!t._popoverContent.is(n.target)&&!e.contains(t._popoverContent[0],n.target)&&!t.wrapper.is(n.target)&&!e.contains(t.wrapper[0],n.target)&&t.close()})):(t.wrapper.on(`mouseenter.kendoCitation`,t.open.bind(t)),t.wrapper.on(`mouseleave.kendoCitation`,function(n){!t._popoverContent.is(n.relatedTarget)&&!e.contains(t._popoverContent[0],n.relatedTarget)&&t.close()}),t._popoverContent.on(`mouseleave.kendoCitation`,function(n){!t.wrapper.is(n.relatedTarget)&&!e.contains(t.wrapper[0],n.relatedTarget)&&t.close()}),t.wrapper.on(`focusin.kendoCitation`,t.open.bind(t)),t.wrapper.on(`focusout.kendoCitation`,function(n){!t.wrapper.is(n.relatedTarget)&&!e.contains(t.wrapper[0],n.relatedTarget)&&!t._popoverContent.is(n.relatedTarget)&&!e.contains(t._popoverContent[0],n.relatedTarget)&&t.close()})),t._popoverContent.on(`click.kendoCitation`,`.k-citation-prev`,function(){t._navigate(`prev`)}),t._popoverContent.on(`click.kendoCitation`,`.k-citation-next`,function(){t._navigate(`next`)})},_onChipClick:function(){let e=this;e._isOpen?e.close():e.open()},open:function(){let e=this;e.trigger(o,{sources:e.options.sources})||(e._currentPage=0,e._updatePage(),e._popup.open(),e._popoverContent.attr(`aria-hidden`,`false`),e.wrapper.addClass(`k-chip-selected`).attr(`aria-pressed`,`true`),e._isOpen=!0)},close:function(){let e=this;e._popup.close(),e._popoverContent.attr(`aria-hidden`,`true`),e.wrapper.removeClass(`k-chip-selected`).attr(`aria-pressed`,`false`),e._isOpen=!1},_navigate:function(e){let t=this,n=t.options.sources.length;e===`prev`?t._currentPage=Math.max(0,t._currentPage-1):t._currentPage=Math.min(n-1,t._currentPage+1),t._updatePage()},setOptions:function(t){let n=this;n.close(),e(document).off(s+n._docNS),n.wrapper.off(a),n._popup&&n._popup.destroy(),n._chip.destroy(),n._chipElement.insertBefore(n.wrapper),n.wrapper.remove(),n.element=n._chipElement,r.fn.setOptions.call(n,t),n._render(),n._bindEvents()},destroy:function(){let t=this;t.wrapper.off(a),e(document).off(s+t._docNS),t._popoverContent.off(a),t._popup&&=(t._popup.destroy(),null),t._chip&&=(t._chip.destroy(),null),t.element=t._hostElement,r.fn.destroy.call(t)}});n.ui.plugin(c)})(window.kendo.jQuery);var s=kendo;e.__meta__=o,e.default=s}); //# sourceMappingURL=kendo.citation.min.js.map