bibcite_footnotes-8.x-1.0-beta3/js/build/bibciteFootnotes.js

js/build/bibciteFootnotes.js
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CKEditor5=t():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.bibciteFootnotes=t())}(self,()=>(()=>{var e={"ckeditor5/src/core.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/ui.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/ui.js")},"ckeditor5/src/widget.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/widget.js")},"dll-reference CKEditor5.dll":e=>{"use strict";e.exports=CKEditor5.dll}},t={};function i(o){var n=t[o];if(void 0!==n)return n.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,i),r.exports}i.d=(e,t)=>{for(var o in t)i.o(t,o)&&!i.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var o={};return(()=>{"use strict";i.d(o,{default:()=>s});var e=i("ckeditor5/src/core.js"),t=i("ckeditor5/src/ui.js"),n=i("ckeditor5/src/widget.js");class r extends e.Plugin{_currentElement=null;_references=[];static get requires(){return[t.ContextualBalloon,n.Widget]}init(){const e=this.editor,i=e.t;this._balloon=e.plugins.get(t.ContextualBalloon),this._loadReferences(),e.model.schema.register("bibciteFootnote",{inheritAllFrom:"$inlineObject",allowAttributes:["entityId","pageRange"]}),this._setupSimpleConversion(),e.keystrokes.set("Alt+C",(t,i)=>{const o=e.model.document.selection.getSelectedElement();o&&o.is("element","bibciteFootnote")?this.showUI(o):this.showUI(),i()}),e.ui.componentFactory.add("bibciteFootnotes",e=>{const o=new t.ButtonView(e);return o.set({label:i("Cite"),withText:!0,tooltip:i("Insert citation (Alt+C)")}),o.on("execute",()=>{this.showUI()}),o}),this.listenTo(e.editing.view.document,"click",(t,i)=>{const o=e.editing.mapper.toModelElement(i.target);o?.is("element","bibciteFootnote")&&this.showUI(o)}),this.listenTo(e.editing.view.document,"keydown",(t,i)=>{const o=e.editing.mapper.toModelElement(i.target);o?.is("element","bibciteFootnote")&&(13!==i.keyCode&&32!==i.keyCode||(i.preventDefault(),this.showUI(o)))}),e.accessibility.addKeystrokeInfos({keystrokes:[{label:i("Insert citation"),keystroke:"Alt+c"}]})}_loadReferences(){try{this._references=window.parent.drupalSettings?.bibcite_footnotes?.references||[]}catch(e){console.error("Could not access Drupal settings:",e)}}_setupSimpleConversion(){const e=this.editor,t={};this._references.forEach(e=>{t[e[1]]=e[0]}),e.conversion.for("editingDowncast").elementToElement({model:"bibciteFootnote",view:(e,{writer:i})=>{const o=e.getAttribute("entityId"),r=e.getAttribute("pageRange"),s=t[o]||`Citation ${o}`,c=((e,t=20)=>{if(!e||e.length<=t)return e;const i=e.substring(0,t).lastIndexOf(",");if(i>0&&i<=t)return e.substring(0,i)+"…";const o=e.substring(0,t).lastIndexOf(" ");return o>0&&o<=t?e.substring(0,o)+"…":e.substring(0,t-1)+"…"})(s),l=`Citation: ${s}${r?", pages "+r:""}`,a=r?`[${c}, pp. ${r}]`:`[${c}]`,d=i.createContainerElement("span",{class:"bibcite-footnote-placeholder",role:"button","aria-haspopup":"dialog","aria-label":l,tabindex:"0"},i.createText(a));return(0,n.toWidget)(d,i,{label:l})}}),e.conversion.for("dataDowncast").elementToElement({model:"bibciteFootnote",view:(e,{writer:t})=>{const i=e.getAttribute("entityId"),o=e.getAttribute("pageRange")||"";return t.createContainerElement("bibcite-footnote",{"data-entity-id":i,"data-page-range":o})}}),e.conversion.for("upcast").elementToElement({view:{name:"bibcite-footnote",attributes:["data-entity-id"]},model:(e,{writer:t})=>t.createElement("bibciteFootnote",{entityId:e.getAttribute("data-entity-id"),pageRange:e.getAttribute("data-page-range")||""})})}_createFormView(){const e=this.editor,i=e.t,o=new t.View(e.locale);return o.saveButtonView=new t.ButtonView(e.locale),o.saveButtonView.set({label:i("Save"),withText:!0,class:"ck-button-save"}),o.saveButtonView.on("execute",()=>{this._handleFormSubmit()}),o.cancelButtonView=new t.ButtonView(e.locale),o.cancelButtonView.set({label:i("Cancel"),withText:!0,class:"ck-button-cancel"}),o.cancelButtonView.on("execute",()=>{this._hideUI()}),o.setTemplate({tag:"div",attributes:{class:["ck","ck-bibcite-form"],tabindex:"-1"},children:[{tag:"div",attributes:{class:["ck","ck-bibcite-form__row"]},children:[{tag:"label",attributes:{for:"work-select",class:["ck","ck-label"]},children:[i("Work to cite")]},{tag:"select",attributes:{class:["ck","ck-input","ck-bibcite-work-select"],id:"work-select"},children:[]}]},{tag:"div",attributes:{class:["ck","ck-bibcite-form__row"]},children:[{tag:"label",attributes:{for:"page-input",class:["ck","ck-label"]},children:[i("Page(s)")]},{tag:"input",attributes:{class:["ck","ck-input","ck-bibcite-page-input"],type:"text",id:"page-input",placeholder:i("e.g., 42-45")}}]},{tag:"div",attributes:{class:["ck","ck-bibcite-form__actions"]},children:[o.cancelButtonView,o.saveButtonView]}]}),o.on("render",()=>{o.element&&o.element.addEventListener("keydown",e=>{"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),this._hideUI()):"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),this._handleFormSubmit())})}),o}_updateFormViewReferences(){if(!this.formView||!this.formView.element)return;const e=this.formView.element.querySelector(".ck-bibcite-work-select");if(!e)return;const t=e.value;e.innerHTML="";const i=document.createElement("option");if(i.value="",i.textContent=this.editor.t("-- Select --"),e.appendChild(i),this._references.forEach(t=>{const i=document.createElement("option");i.value=t[1],i.textContent=t[0],e.appendChild(i)}),t&&Array.from(e.options).some(e=>e.value===t))e.value=t;else if(this._currentElement){const t=this._currentElement.getAttribute("entityId");t&&Array.from(e.options).some(e=>e.value===t)&&(e.value=t)}console.log("Dropdown updated with",this._references.length,"references")}showUI(e=null){this._currentElement=e,this._loadReferences(),this.formView||(this.formView=this._createFormView()),this._balloon.hasView(this.formView)?(this._updateFormViewReferences(),this._focusForm()):(this._balloon.add({view:this.formView,position:this._getBalloonPositionData()}),setTimeout(()=>{this._updateFormViewReferences(),this._focusForm()},50))}_focusForm(){if(this.formView.element){const e=this.formView.element.querySelector(".ck-bibcite-work-select"),t=this.formView.element.querySelector(".ck-bibcite-page-input");if(this._currentElement){const i=this._currentElement.getAttribute("entityId");e&&(e.value=i||""),t&&(t.value=this._currentElement.getAttribute("pageRange")||"")}else e&&(e.selectedIndex=0),t&&(t.value="");e&&e.focus()}}_handleFormSubmit(){const e=this.editor,t=this.formView.element,i=t.querySelector(".ck-bibcite-work-select"),o=t.querySelector(".ck-bibcite-page-input");if(!i)return;const n=i.value,r=o.value.trim();n&&e.model.change(t=>{if(this._currentElement)t.setAttribute("entityId",n,this._currentElement),t.setAttribute("pageRange",r,this._currentElement);else{const i=e.model.document.selection.getFirstRange().start,o=t.createElement("bibciteFootnote",{entityId:n,pageRange:r});t.insert(o,i)}}),this._hideUI()}_hideUI(){this.formView&&this._balloon.hasView(this.formView)&&this._balloon.remove(this.formView),this._currentElement=null,this.editor.editing.view.focus()}_getBalloonPositionData(){const e=this.editor.editing.view;return{target:e.domConverter.viewRangeToDom(e.document.selection.getFirstRange())}}}const s={BibciteFootnotes:r}})(),o=o.default})());

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc