diff --git a/phpBB/adm/style/acp_posting_buttons.html b/phpBB/adm/style/acp_posting_buttons.html index 08c81de0c0..82c35dc65c 100644 --- a/phpBB/adm/style/acp_posting_buttons.html +++ b/phpBB/adm/style/acp_posting_buttons.html @@ -8,8 +8,7 @@ // ]]> - - + diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index 1421c9fa7b..d0d97dba72 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -1676,7 +1676,9 @@ fieldset.submit-buttons legend { font-weight: bold; } -.atwho-view { /* mention-container */ +.mention-container { /* mention-container */ + overflow: auto; /* placed here for list to scroll with arrow key press */ + max-height: 200px; text-align: left; background-color: #ffffff; border-radius: 2px; @@ -1689,13 +1691,11 @@ fieldset.submit-buttons legend { transition: all 0.2s ease; } -.rtl .atwho-view { /* mention-container */ +.rtl .mention-container { /* mention-container */ text-align: right; } -.atwho-view-ul { /* mention-list */ - overflow: auto; /* placed here for list to scroll with arrow key press */ - max-height: 200px; +.mention-container ul { /* mention-list */ margin: 0; padding: 0; list-style-type: none; diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js index 0fc3fad2e3..2e726868bf 100644 --- a/phpBB/assets/javascript/editor.js +++ b/phpBB/assets/javascript/editor.js @@ -562,7 +562,7 @@ function getCaretPosition(txtarea) { } /** - * atwho.js remoteFilter callback filter function + * remoteFilter callback filter function * @param {string} query Query string * @param {function} callback Callback function for filtered items */ diff --git a/phpBB/assets/javascript/jquery.atwho.min.js b/phpBB/assets/javascript/jquery.atwho.min.js deleted file mode 100644 index 857bb93126..0000000000 --- a/phpBB/assets/javascript/jquery.atwho.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(t,e){"function"==typeof define&&define.amd?define(["jquery"],function(t){return e(t)}):"object"==typeof exports?module.exports=e(require("jquery")):e(jQuery)}(this,function(t){var e,i;i={ESC:27,TAB:9,ENTER:13,CTRL:17,A:65,P:80,N:78,LEFT:37,UP:38,RIGHT:39,DOWN:40,BACKSPACE:8,SPACE:32},e={beforeSave:function(t){return r.arrayToDefaultHash(t)},matcher:function(t,e,i,n){var r,o,s,a,h;return t=t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&"),i&&(t="(?:^|\\s)"+t),r=decodeURI("%C3%80"),o=decodeURI("%C3%BF"),h=n?" ":"",a=new RegExp(t+"([A-Za-z"+r+"-"+o+"0-9_"+h+"'.+-]*)$|"+t+"([^\\x00-\\xff]*)$","gi"),s=a.exec(e),s?s[2]||s[1]:null},filter:function(t,e,i){var n,r,o,s;for(n=[],r=0,s=e.length;s>r;r++)o=e[r],~new String(o[i]).toLowerCase().indexOf(t.toLowerCase())&&n.push(o);return n},remoteFilter:null,sorter:function(t,e,i){var n,r,o,s;if(!t)return e;for(n=[],r=0,s=e.length;s>r;r++)o=e[r],o.atwho_order=new String(o[i]).toLowerCase().indexOf(t.toLowerCase()),o.atwho_order>-1&&n.push(o);return n.sort(function(t,e){return t.atwho_order-e.atwho_order})},tplEval:function(t,e){var i,n,r;r=t;try{return"string"!=typeof t&&(r=t(e)),r.replace(/\$\{([^\}]*)\}/g,function(t,i,n){return e[i]})}catch(n){return i=n,""}},highlighter:function(t,e){var i;return e?(i=new RegExp(">\\s*([^<]*?)("+e.replace("+","\\+")+")([^<]*)\\s*<","ig"),t.replace(i,function(t,e,i,n){return"> "+e+""+i+""+n+" <"})):t},beforeInsert:function(t,e,i){return t},beforeReposition:function(t){return t},afterMatchFailed:function(t,e){}};var n;n=function(){function e(e){this.currentFlag=null,this.controllers={},this.aliasMaps={},this.$inputor=t(e),this.setupRootElement(),this.listen()}return e.prototype.createContainer=function(e){var i;return null!=(i=this.$el)&&i.remove(),t(e.body).append(this.$el=t("
"))},e.prototype.setupRootElement=function(e,i){var n,r;if(null==i&&(i=!1),e)this.window=e.contentWindow,this.document=e.contentDocument||this.window.document,this.iframe=e;else{this.document=this.$inputor[0].ownerDocument,this.window=this.document.defaultView||this.document.parentWindow;try{this.iframe=this.window.frameElement}catch(r){if(n=r,this.iframe=null,t.fn.atwho.debug)throw new Error("iframe auto-discovery is failed.\nPlease use `setIframe` to set the target iframe manually.\n"+n)}}return this.createContainer((this.iframeAsRoot=i)?this.document:document)},e.prototype.controller=function(t){var e,i,n,r;if(this.aliasMaps[t])i=this.controllers[this.aliasMaps[t]];else{r=this.controllers;for(n in r)if(e=r[n],n===t){i=e;break}}return i?i:this.controllers[this.currentFlag]},e.prototype.setContextFor=function(t){return this.currentFlag=t,this},e.prototype.reg=function(t,e){var i,n;return n=(i=this.controllers)[t]||(i[t]=this.$inputor.is("[contentEditable]")?new l(this,t):new s(this,t)),e.alias&&(this.aliasMaps[e.alias]=t),n.init(e),this},e.prototype.listen=function(){return this.$inputor.on("compositionstart",function(t){return function(e){var i;return null!=(i=t.controller())&&i.view.hide(),t.isComposing=!0,null}}(this)).on("compositionend",function(t){return function(e){return t.isComposing=!1,setTimeout(function(e){return t.dispatch(e)}),null}}(this)).on("keyup.atwhoInner",function(t){return function(e){return t.onKeyup(e)}}(this)).on("keydown.atwhoInner",function(t){return function(e){return t.onKeydown(e)}}(this)).on("blur.atwhoInner",function(t){return function(e){var i;return(i=t.controller())?(i.expectedQueryCBId=null,i.view.hide(e,i.getOpt("displayTimeout"))):void 0}}(this)).on("click.atwhoInner",function(t){return function(e){return t.dispatch(e)}}(this)).on("scroll.atwhoInner",function(t){return function(){var e;return e=t.$inputor.scrollTop(),function(i){var n,r;return n=i.target.scrollTop,e!==n&&null!=(r=t.controller())&&r.view.hide(i),e=n,!0}}}(this)())},e.prototype.shutdown=function(){var t,e,i;i=this.controllers;for(t in i)e=i[t],e.destroy(),delete this.controllers[t];return this.$inputor.off(".atwhoInner"),this.$el.remove()},e.prototype.dispatch=function(t){var e,i,n,r;if(void 0!==t){n=this.controllers,r=[];for(e in n)i=n[e],r.push(i.lookUp(t));return r}},e.prototype.onKeyup=function(e){var n;switch(e.keyCode){case i.ESC:e.preventDefault(),null!=(n=this.controller())&&n.view.hide();break;case i.DOWN:case i.UP:case i.CTRL:case i.ENTER:t.noop();break;case i.P:case i.N:e.ctrlKey||this.dispatch(e);break;default:this.dispatch(e)}},e.prototype.onKeydown=function(e){var n,r;if(r=null!=(n=this.controller())?n.view:void 0,r&&r.visible())switch(e.keyCode){case i.ESC:e.preventDefault(),r.hide(e);break;case i.UP:e.preventDefault(),r.prev();break;case i.DOWN:e.preventDefault(),r.next();break;case i.P:if(!e.ctrlKey)return;e.preventDefault(),r.prev();break;case i.N:if(!e.ctrlKey)return;e.preventDefault(),r.next();break;case i.TAB:case i.ENTER:case i.SPACE:if(!r.visible())return;if(!this.controller().getOpt("spaceSelectsMatch")&&e.keyCode===i.SPACE)return;if(!this.controller().getOpt("tabSelectsMatch")&&e.keyCode===i.TAB)return;r.highlighted()?(e.preventDefault(),r.choose(e)):r.hide(e);break;default:t.noop()}},e}();var r,o=[].slice;r=function(){function i(e,i){this.app=e,this.at=i,this.$inputor=this.app.$inputor,this.id=this.$inputor[0].id||this.uid(),this.expectedQueryCBId=null,this.setting=null,this.query=null,this.pos=0,this.range=null,0===(this.$el=t("#atwho-ground-"+this.id,this.app.$el)).length&&this.app.$el.append(this.$el=t("
")),this.model=new u(this),this.view=new c(this)}return i.prototype.uid=function(){return(Math.random().toString(16)+"000000000").substr(2,8)+(new Date).getTime()},i.prototype.init=function(e){return this.setting=t.extend({},this.setting||t.fn.atwho["default"],e),this.view.init(),this.model.reload(this.setting.data)},i.prototype.destroy=function(){return this.trigger("beforeDestroy"),this.model.destroy(),this.view.destroy(),this.$el.remove()},i.prototype.callDefault=function(){var i,n,r,s;s=arguments[0],i=2<=arguments.length?o.call(arguments,1):[];try{return e[s].apply(this,i)}catch(r){return n=r,t.error(n+" Or maybe At.js doesn't have function "+s)}},i.prototype.trigger=function(t,e){var i,n;return null==e&&(e=[]),e.push(this),i=this.getOpt("alias"),n=i?t+"-"+i+".atwho":t+".atwho",this.$inputor.trigger(n,e)},i.prototype.callbacks=function(t){return this.getOpt("callbacks")[t]||e[t]},i.prototype.getOpt=function(t,e){var i,n;try{return this.setting[t]}catch(n){return i=n,null}},i.prototype.insertContentFor=function(e){var i,n;return n=this.getOpt("insertTpl"),i=t.extend({},e.data("item-data"),{"atwho-at":this.at}),this.callbacks("tplEval").call(this,n,i,"onInsert")},i.prototype.renderView=function(t){var e;return e=this.getOpt("searchKey"),t=this.callbacks("sorter").call(this,this.query.text,t.slice(0,1001),e),this.view.render(t.slice(0,this.getOpt("limit")))},i.arrayToDefaultHash=function(e){var i,n,r,o;if(!t.isArray(e))return e;for(o=[],i=0,r=e.length;r>i;i++)n=e[i],t.isPlainObject(n)?o.push(n):o.push({name:n});return o},i.prototype.lookUp=function(t){var e,i;if((!t||"click"!==t.type||this.getOpt("lookUpOnClick"))&&(!this.getOpt("suspendOnComposing")||!this.app.isComposing))return(e=this.catchQuery(t))?(this.app.setContextFor(this.at),(i=this.getOpt("delay"))?this._delayLookUp(e,i):this._lookUp(e),e):(this.expectedQueryCBId=null,e)},i.prototype._delayLookUp=function(t,e){var i,n;return i=Date.now?Date.now():(new Date).getTime(),this.previousCallTime||(this.previousCallTime=i),n=e-(i-this.previousCallTime),n>0&&e>n?(this.previousCallTime=i,this._stopDelayedCall(),this.delayedCallTimeout=setTimeout(function(e){return function(){return e.previousCallTime=0,e.delayedCallTimeout=null,e._lookUp(t)}}(this),e)):(this._stopDelayedCall(),this.previousCallTime!==i&&(this.previousCallTime=0),this._lookUp(t))},i.prototype._stopDelayedCall=function(){return this.delayedCallTimeout?(clearTimeout(this.delayedCallTimeout),this.delayedCallTimeout=null):void 0},i.prototype._generateQueryCBId=function(){return{}},i.prototype._lookUp=function(e){var i;return i=function(t,e){return t===this.expectedQueryCBId?e&&e.length>0?this.renderView(this.constructor.arrayToDefaultHash(e)):this.view.hide():void 0},this.expectedQueryCBId=this._generateQueryCBId(),this.model.query(e.text,t.proxy(i,this,this.expectedQueryCBId))},i}();var s,a=function(t,e){function i(){this.constructor=t}for(var n in e)h.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},h={}.hasOwnProperty;s=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return a(i,e),i.prototype.catchQuery=function(){var t,e,i,n,r,o,s;return e=this.$inputor.val(),t=this.$inputor.caret("pos",{iframe:this.app.iframe}),s=e.slice(0,t),r=this.callbacks("matcher").call(this,this.at,s,this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar")),n="string"==typeof r,n&&r.length0?t.getRangeAt(0):void 0},n.prototype._setRange=function(e,i,n){return null==n&&(n=this._getRange()),n&&i?(i=t(i)[0],"after"===e?(n.setEndAfter(i),n.setStartAfter(i)):(n.setEndBefore(i),n.setStartBefore(i)),n.collapse(!1),this._clearRange(n)):void 0},n.prototype._clearRange=function(t){var e;return null==t&&(t=this._getRange()),e=this.app.window.getSelection(),null==this.ctrl_a_pressed?(e.removeAllRanges(),e.addRange(t)):void 0},n.prototype._movingEvent=function(t){var e;return"click"===t.type||(e=t.which)===i.RIGHT||e===i.LEFT||e===i.UP||e===i.DOWN},n.prototype._unwrap=function(e){var i;return e=t(e).unwrap().get(0),(i=e.nextSibling)&&i.nodeValue&&(e.nodeValue+=i.nodeValue,t(i).remove()),e},n.prototype.catchQuery=function(e){var n,r,o,s,a,h,l,u,c,p,f,d;if((d=this._getRange())&&d.collapsed){if(e.which===i.ENTER)return(r=t(d.startContainer).closest(".atwho-query")).contents().unwrap(),r.is(":empty")&&r.remove(),(r=t(".atwho-query",this.app.document)).text(r.text()).contents().last().unwrap(),void this._clearRange();if(/firefox/i.test(navigator.userAgent)){if(t(d.startContainer).is(this.$inputor))return void this._clearRange();e.which===i.BACKSPACE&&d.startContainer.nodeType===document.ELEMENT_NODE&&(c=d.startOffset-1)>=0?(o=d.cloneRange(),o.setStart(d.startContainer,c),t(o.cloneContents()).contents().last().is(".atwho-inserted")&&(a=t(d.startContainer).contents().get(c),this._setRange("after",t(a).contents().last()))):e.which===i.LEFT&&d.startContainer.nodeType===document.TEXT_NODE&&(n=t(d.startContainer.previousSibling),n.is(".atwho-inserted")&&0===d.startOffset&&this._setRange("after",n.contents().last()))}if(t(d.startContainer).closest(".atwho-inserted").addClass("atwho-query").siblings().removeClass("atwho-query"),(r=t(".atwho-query",this.app.document)).length>0&&r.is(":empty")&&0===r.text().length&&r.remove(),this._movingEvent(e)||r.removeClass("atwho-inserted"),r.length>0)switch(e.which){case i.LEFT:return this._setRange("before",r.get(0),d),void r.removeClass("atwho-query");case i.RIGHT:return this._setRange("after",r.get(0).nextSibling,d),void r.removeClass("atwho-query")}if(r.length>0&&(f=r.attr("data-atwho-at-query"))&&(r.empty().html(f).attr("data-atwho-at-query",null),this._setRange("after",r.get(0),d)),o=d.cloneRange(),o.setStart(d.startContainer,0),u=this.callbacks("matcher").call(this,this.at,o.toString(),this.getOpt("startWithSpace"),this.getOpt("acceptSpaceBar")),h="string"==typeof u,0===r.length&&h&&(s=d.startOffset-this.at.length-u.length)>=0&&(d.setStart(d.startContainer,s),r=t("",this.app.document).attr(this.getOpt("editableAtwhoQueryAttrs")).addClass("atwho-query"),d.surroundContents(r.get(0)),l=r.contents().last().get(0),l&&(/firefox/i.test(navigator.userAgent)?(d.setStart(l,l.length),d.setEnd(l,l.length),this._clearRange(d)):this._setRange("after",l,d))),!(h&&u.length=0&&(this._movingEvent(e)&&r.hasClass("atwho-inserted")?r.removeClass("atwho-query"):!1!==this.callbacks("afterMatchFailed").call(this,this.at,r)&&this._setRange("after",this._unwrap(r.text(r.text()).contents().first()))),null)}},n.prototype.rect=function(){var e,i,n;return n=this.query.el.offset(),n&&this.query.el[0].getClientRects().length?(this.app.iframe&&!this.app.iframeAsRoot&&(i=(e=t(this.app.iframe)).offset(),n.left+=i.left-this.$inputor.scrollLeft(),n.top+=i.top-this.$inputor.scrollTop()),n.bottom=n.top+this.query.el.height(),n):void 0},n.prototype.insert=function(t,e){var i,n,r,o,s;return this.$inputor.is(":focus")||this.$inputor.focus(),n=this.getOpt("functionOverrides"),n.insert?n.insert.call(this,t,e):(o=""===(o=this.getOpt("suffix"))?o:o||" ",i=e.data("item-data"),this.query.el.removeClass("atwho-query").addClass("atwho-inserted").html(t).attr("data-atwho-at-query",""+i["atwho-at"]+this.query.text).attr("contenteditable","false"),(r=this._getRange())&&(this.query.el.length&&r.setEndAfter(this.query.el[0]),r.collapse(!1),r.insertNode(s=this.app.document.createTextNode(""+o)),this._setRange("after",s,r)),this.$inputor.is(":focus")||this.$inputor.focus(),this.$inputor.change())},n}(r);var u;u=function(){function e(t){this.context=t,this.at=this.context.at,this.storage=this.context.$inputor}return e.prototype.destroy=function(){return this.storage.data(this.at,null)},e.prototype.saved=function(){return this.fetch()>0},e.prototype.query=function(t,e){var i,n,r;return n=this.fetch(),r=this.context.getOpt("searchKey"),n=this.context.callbacks("filter").call(this.context,t,n,r)||[],i=this.context.callbacks("remoteFilter"),n.length>0||!i&&0===n.length?e(n):i.call(this.context,t,e)},e.prototype.fetch=function(){return this.storage.data(this.at)||[]},e.prototype.save=function(t){return this.storage.data(this.at,this.context.callbacks("beforeSave").call(this.context,t||[]))},e.prototype.load=function(t){return!this.saved()&&t?this._load(t):void 0},e.prototype.reload=function(t){return this._load(t)},e.prototype._load=function(e){return"string"==typeof e?t.ajax(e,{dataType:"json"}).done(function(t){return function(e){return t.save(e)}}(this)):this.save(e)},e}();var c;c=function(){function e(e){this.context=e,this.$el=t("
    "),this.$elUl=this.$el.children(),this.timeoutID=null,this.context.$el.append(this.$el),this.bindEvent()}return e.prototype.init=function(){var t,e;return e=this.context.getOpt("alias")||this.context.at.charCodeAt(0),t=this.context.getOpt("headerTpl"),t&&1===this.$el.children().length&&this.$el.prepend(t),this.$el.attr({id:"at-view-"+e})},e.prototype.destroy=function(){return this.$el.remove()},e.prototype.bindEvent=function(){var e,i,n;return e=this.$el.find("ul"),i=0,n=0,e.on("mousemove.atwho-view","li",function(r){return function(r){var o;if((i!==r.clientX||n!==r.clientY)&&(i=r.clientX,n=r.clientY,o=t(r.currentTarget),!o.hasClass("cur")))return e.find(".cur").removeClass("cur"),o.addClass("cur")}}(this)).on("click.atwho-view","li",function(i){return function(n){return e.find(".cur").removeClass("cur"),t(n.currentTarget).addClass("cur"),i.choose(n),n.preventDefault()}}(this))},e.prototype.visible=function(){return t.expr.filters.visible(this.$el[0])},e.prototype.highlighted=function(){return this.$el.find(".cur").length>0},e.prototype.choose=function(t){var e,i;return(e=this.$el.find(".cur")).length&&(i=this.context.insertContentFor(e),this.context._stopDelayedCall(),this.context.insert(this.context.callbacks("beforeInsert").call(this.context,i,e,t),e),this.context.trigger("inserted",[e,t]),this.hide(t)),this.context.getOpt("hideWithoutSuffix")?this.stopShowing=!0:void 0},e.prototype.reposition=function(e){var i,n,r,o;return i=this.context.app.iframeAsRoot?this.context.app.window:window,e.bottom+this.$el.height()-t(i).scrollTop()>t(i).height()&&(e.bottom=e.top-this.$el.height()),e.left>(r=t(i).width()-this.$el.width()-5)&&(e.left=r),n={left:e.left,top:e.bottom},null!=(o=this.context.callbacks("beforeReposition"))&&o.call(this.context,n),this.$el.offset(n),this.context.trigger("reposition",[n])},e.prototype.next=function(){var t,e,i,n;return t=this.$el.find(".cur").removeClass("cur"),e=t.next(),e.length||(e=this.$el.find("li:first")),e.addClass("cur"),i=e[0],n=i.offsetTop+i.offsetHeight+(i.nextSibling?i.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,n-this.$el.height()))},e.prototype.prev=function(){var t,e,i,n;return t=this.$el.find(".cur").removeClass("cur"),i=t.prev(),i.length||(i=this.$el.find("li:last")),i.addClass("cur"),n=i[0],e=n.offsetTop+n.offsetHeight+(n.nextSibling?n.nextSibling.offsetHeight:0),this.scrollTop(Math.max(0,e-this.$el.height()))},e.prototype.scrollTop=function(t){var e;return e=this.context.getOpt("scrollDuration"),e?this.$elUl.animate({scrollTop:t},e):this.$elUl.scrollTop(t)},e.prototype.show=function(){var t;return this.stopShowing?void(this.stopShowing=!1):(this.visible()||(this.$el.show(),this.$el.scrollTop(0),this.context.trigger("shown")),(t=this.context.rect())?this.reposition(t):void 0)},e.prototype.hide=function(t,e){var i;if(this.visible())return isNaN(e)?(this.$el.hide(),this.context.trigger("hidden",[t])):(i=function(t){return function(){return t.hide()}}(this),clearTimeout(this.timeoutID),this.timeoutID=setTimeout(i,e))},e.prototype.render=function(e){var i,n,r,o,s,a,h;if(!(t.isArray(e)&&e.length>0))return void this.hide();for(this.$el.find("ul").empty(),n=this.$el.find("ul"),h=this.context.getOpt("displayTpl"),r=0,s=e.length;s>r;r++)o=e[r],o=t.extend({},o,{"atwho-at":this.context.at}),a=this.context.callbacks("tplEval").call(this.context,h,o,"onDisplay"),i=t(this.context.callbacks("highlighter").call(this.context,a,this.context.query.text)),i.data("item-data",o),n.append(i);return this.show(),this.context.getOpt("highlightFirst")?n.find("li:first").addClass("cur"):void 0},e}();var p;p={load:function(t,e){var i;return(i=this.controller(t))?i.model.load(e):void 0},isSelecting:function(){var t;return!!(null!=(t=this.controller())?t.view.visible():void 0)},hide:function(){var t;return null!=(t=this.controller())?t.view.hide():void 0},reposition:function(){var t;return(t=this.controller())?t.view.reposition(t.rect()):void 0},setIframe:function(t,e){return this.setupRootElement(t,e),null},run:function(){return this.dispatch()},destroy:function(){return this.shutdown(),this.$inputor.data("atwho",null)}},t.fn.atwho=function(e){var i,r;return i=arguments,r=null,this.filter('textarea, input, [contenteditable=""], [contenteditable=true]').each(function(){var o,s;return(s=(o=t(this)).data("atwho"))||o.data("atwho",s=new n(this)),"object"!=typeof e&&e?p[e]&&s?r=p[e].apply(s,Array.prototype.slice.call(i,1)):t.error("Method "+e+" does not exist on jQuery.atwho"):s.reg(e.at,e)}),null!=r?r:this},t.fn.atwho["default"]={at:void 0,alias:void 0,data:null,displayTpl:"
  • ${name}
  • ",insertTpl:"${atwho-at}${name}",headerTpl:null,callbacks:e,functionOverrides:{},searchKey:"name",suffix:void 0,hideWithoutSuffix:!1,startWithSpace:!0,acceptSpaceBar:!1,highlightFirst:!0,limit:5,maxLen:20,minLen:0,displayTimeout:300,delay:null,spaceSelectsMatch:!1,tabSelectsMatch:!0,editableAtwhoQueryAttrs:{},scrollDuration:150,suspendOnComposing:!0,lookUpOnClick:!0},t.fn.atwho.debug=!1}); \ No newline at end of file diff --git a/phpBB/assets/javascript/jquery.caret.min.js b/phpBB/assets/javascript/jquery.caret.min.js deleted file mode 100644 index a25584e2ae..0000000000 --- a/phpBB/assets/javascript/jquery.caret.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! jquery.caret 2016-02-27 */ -!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(c){return a.returnExportsGlobal=b(c)}):"object"==typeof exports?module.exports=b(require("jquery")):b(jQuery)}(this,function(a){"use strict";var b,c,d,e,f,g,h,i,j,k,l;k="caret",b=function(){function b(a){this.$inputor=a,this.domInputor=this.$inputor[0]}return b.prototype.setPos=function(a){var b,c,d,e;return(e=j.getSelection())&&(d=0,c=!1,(b=function(a,f){var g,i,j,k,l,m;for(l=f.childNodes,m=[],j=0,k=l.length;k>j&&(g=l[j],!c);j++)if(3===g.nodeType){if(d+g.length>=a){c=!0,i=h.createRange(),i.setStart(g,a-d),e.removeAllRanges(),e.addRange(i);break}m.push(d+=g.length)}else m.push(b(a,g));return m})(a,this.domInputor)),this.domInputor},b.prototype.getIEPosition=function(){return this.getPosition()},b.prototype.getPosition=function(){var a,b;return b=this.getOffset(),a=this.$inputor.offset(),b.left-=a.left,b.top-=a.top,b},b.prototype.getOldIEPos=function(){var a,b;return b=h.selection.createRange(),a=h.body.createTextRange(),a.moveToElementText(this.domInputor),a.setEndPoint("EndToEnd",b),a.text.length},b.prototype.getPos=function(){var a,b,c;return(c=this.range())?(a=c.cloneRange(),a.selectNodeContents(this.domInputor),a.setEnd(c.endContainer,c.endOffset),b=a.toString().length,a.detach(),b):h.selection?this.getOldIEPos():void 0},b.prototype.getOldIEOffset=function(){var a,b;return a=h.selection.createRange().duplicate(),a.moveStart("character",-1),b=a.getBoundingClientRect(),{height:b.bottom-b.top,left:b.left,top:b.top}},b.prototype.getOffset=function(){var b,c,d,e,f;return j.getSelection&&(d=this.range())?(d.endOffset-1>0&&d.endContainer!==this.domInputor&&(b=d.cloneRange(),b.setStart(d.endContainer,d.endOffset-1),b.setEnd(d.endContainer,d.endOffset),e=b.getBoundingClientRect(),c={height:e.height,left:e.left+e.width,top:e.top},b.detach()),c&&0!==(null!=c?c.height:void 0)||(b=d.cloneRange(),f=a(h.createTextNode("|")),b.insertNode(f[0]),b.selectNode(f[0]),e=b.getBoundingClientRect(),c={height:e.height,left:e.left,top:e.top},f.remove(),b.detach())):h.selection&&(c=this.getOldIEOffset()),c&&(c.top+=a(j).scrollTop(),c.left+=a(j).scrollLeft()),c},b.prototype.range=function(){var a;if(j.getSelection)return a=j.getSelection(),a.rangeCount>0?a.getRangeAt(0):null},b}(),c=function(){function b(a){this.$inputor=a,this.domInputor=this.$inputor[0]}return b.prototype.getIEPos=function(){var a,b,c,d,e,f,g;return b=this.domInputor,f=h.selection.createRange(),e=0,f&&f.parentElement()===b&&(d=b.value.replace(/\r\n/g,"\n"),c=d.length,g=b.createTextRange(),g.moveToBookmark(f.getBookmark()),a=b.createTextRange(),a.collapse(!1),e=g.compareEndPoints("StartToEnd",a)>-1?c:-g.moveStart("character",-c)),e},b.prototype.getPos=function(){return h.selection?this.getIEPos():this.domInputor.selectionStart},b.prototype.setPos=function(a){var b,c;return b=this.domInputor,h.selection?(c=b.createTextRange(),c.move("character",a),c.select()):b.setSelectionRange&&b.setSelectionRange(a,a),b},b.prototype.getIEOffset=function(a){var b,c,d,e;return c=this.domInputor.createTextRange(),a||(a=this.getPos()),c.move("character",a),d=c.boundingLeft,e=c.boundingTop,b=c.boundingHeight,{left:d,top:e,height:b}},b.prototype.getOffset=function(b){var c,d,e;return c=this.$inputor,h.selection?(d=this.getIEOffset(b),d.top+=a(j).scrollTop()+c.scrollTop(),d.left+=a(j).scrollLeft()+c.scrollLeft(),d):(d=c.offset(),e=this.getPosition(b),d={left:d.left+e.left-c.scrollLeft(),top:d.top+e.top-c.scrollTop(),height:e.height})},b.prototype.getPosition=function(a){var b,c,e,f,g,h,i;return b=this.$inputor,f=function(a){return a=a.replace(/<|>|`|"|&/g,"?").replace(/\r\n|\r|\n/g,"
    "),/firefox/i.test(navigator.userAgent)&&(a=a.replace(/\s/g," ")),a},void 0===a&&(a=this.getPos()),i=b.val().slice(0,a),e=b.val().slice(a),g=""+f(i)+"",g+="|",g+=""+f(e)+"",h=new d(b),c=h.create(g).rect()},b.prototype.getIEPosition=function(a){var b,c,d,e,f;return d=this.getIEOffset(a),c=this.$inputor.offset(),e=d.left-c.left,f=d.top-c.top,b=d.height,{left:e,top:f,height:b}},b}(),d=function(){function b(a){this.$inputor=a}return b.prototype.css_attr=["borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopStyle","borderRightStyle","borderBottomStyle","borderLeftStyle","borderTopWidth","boxSizing","fontFamily","fontSize","fontWeight","height","letterSpacing","lineHeight","marginBottom","marginLeft","marginRight","marginTop","outlineWidth","overflow","overflowX","overflowY","paddingBottom","paddingLeft","paddingRight","paddingTop","textAlign","textOverflow","textTransform","whiteSpace","wordBreak","wordWrap"],b.prototype.mirrorCss=function(){var b,c=this;return b={position:"absolute",left:-9999,top:0,zIndex:-2e4},"TEXTAREA"===this.$inputor.prop("tagName")&&this.css_attr.push("width"),a.each(this.css_attr,function(a,d){return b[d]=c.$inputor.css(d)}),b},b.prototype.create=function(b){return this.$mirror=a("
    "),this.$mirror.css(this.mirrorCss()),this.$mirror.html(b),this.$inputor.after(this.$mirror),this},b.prototype.rect=function(){var a,b,c;return a=this.$mirror.find("#caret"),b=a.position(),c={left:b.left,top:b.top,height:a.height()},this.$mirror.remove(),c},b}(),e={contentEditable:function(a){return!(!a[0].contentEditable||"true"!==a[0].contentEditable)}},g={pos:function(a){return a||0===a?this.setPos(a):this.getPos()},position:function(a){return h.selection?this.getIEPosition(a):this.getPosition(a)},offset:function(a){var b;return b=this.getOffset(a)}},h=null,j=null,i=null,l=function(a){var b;return(b=null!=a?a.iframe:void 0)?(i=b,j=b.contentWindow,h=b.contentDocument||j.document):(i=void 0,j=window,h=document)},f=function(a){var b;h=a[0].ownerDocument,j=h.defaultView||h.parentWindow;try{return i=j.frameElement}catch(c){b=c}},a.fn.caret=function(d,f,h){var i;return g[d]?(a.isPlainObject(f)?(l(f),f=void 0):l(h),i=e.contentEditable(this)?new b(this):new c(this),g[d].apply(i,[f])):a.error("Method "+d+" does not exist on jQuery.caret")},a.fn.caret.EditableCaret=b,a.fn.caret.InputCaret=c,a.fn.caret.Utils=e,a.fn.caret.apis=g}); \ No newline at end of file diff --git a/phpBB/assets/javascript/jquery.tribute.js b/phpBB/assets/javascript/jquery.tribute.js deleted file mode 100644 index 9c46e63577..0000000000 --- a/phpBB/assets/javascript/jquery.tribute.js +++ /dev/null @@ -1,1898 +0,0 @@ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global = global || self, global.Tribute = factory()); -}(this, (function () { 'use strict'; - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } - - function _slicedToArray(arr, i) { - return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); - } - - function _arrayWithHoles(arr) { - if (Array.isArray(arr)) return arr; - } - - function _iterableToArrayLimit(arr, i) { - if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; - var _arr = []; - var _n = true; - var _d = false; - var _e = undefined; - - try { - for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { - _arr.push(_s.value); - - if (i && _arr.length === i) break; - } - } catch (err) { - _d = true; - _e = err; - } finally { - try { - if (!_n && _i["return"] != null) _i["return"](); - } finally { - if (_d) throw _e; - } - } - - return _arr; - } - - function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(n); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } - - function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - - for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; - - return arr2; - } - - function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - } - - if (!Array.prototype.find) { - Array.prototype.find = function (predicate) { - if (this === null) { - throw new TypeError('Array.prototype.find called on null or undefined'); - } - - if (typeof predicate !== 'function') { - throw new TypeError('predicate must be a function'); - } - - var list = Object(this); - var length = list.length >>> 0; - var thisArg = arguments[1]; - var value; - - for (var i = 0; i < length; i++) { - value = list[i]; - - if (predicate.call(thisArg, value, i, list)) { - return value; - } - } - - return undefined; - }; - } - - if (window && typeof window.CustomEvent !== "function") { - var CustomEvent$1 = function CustomEvent(event, params) { - params = params || { - bubbles: false, - cancelable: false, - detail: undefined - }; - var evt = document.createEvent('CustomEvent'); - evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); - return evt; - }; - - if (typeof window.Event !== 'undefined') { - CustomEvent$1.prototype = window.Event.prototype; - } - - window.CustomEvent = CustomEvent$1; - } - - var TributeEvents = /*#__PURE__*/function () { - function TributeEvents(tribute) { - _classCallCheck(this, TributeEvents); - - this.tribute = tribute; - this.tribute.events = this; - } - - _createClass(TributeEvents, [{ - key: "bind", - value: function bind(element) { - element.boundKeydown = this.keydown.bind(element, this); - element.boundKeyup = this.keyup.bind(element, this); - element.boundInput = this.input.bind(element, this); - element.addEventListener("keydown", element.boundKeydown, false); - element.addEventListener("keyup", element.boundKeyup, false); - element.addEventListener("input", element.boundInput, false); - } - }, { - key: "unbind", - value: function unbind(element) { - element.removeEventListener("keydown", element.boundKeydown, false); - element.removeEventListener("keyup", element.boundKeyup, false); - element.removeEventListener("input", element.boundInput, false); - delete element.boundKeydown; - delete element.boundKeyup; - delete element.boundInput; - } - }, { - key: "keydown", - value: function keydown(instance, event) { - if (instance.shouldDeactivate(event)) { - instance.tribute.isActive = false; - instance.tribute.hideMenu(); - } - - var element = this; - instance.commandEvent = false; - TributeEvents.keys().forEach(function (o) { - if (o.key === event.keyCode) { - instance.commandEvent = true; - instance.callbacks()[o.value.toLowerCase()](event, element); - } - }); - } - }, { - key: "input", - value: function input(instance, event) { - instance.inputEvent = true; - instance.keyup.call(this, instance, event); - } - }, { - key: "click", - value: function click(instance, event) { - var tribute = instance.tribute; - - if (tribute.menu && tribute.menu.contains(event.target)) { - var li = event.target; - event.preventDefault(); - event.stopPropagation(); - - while (li.nodeName.toLowerCase() !== "li") { - li = li.parentNode; - - if (!li || li === tribute.menu) { - throw new Error("cannot find the
  • container for the click"); - } - } - - tribute.selectItemAtIndex(li.getAttribute("data-index"), event); - tribute.hideMenu(); // TODO: should fire with externalTrigger and target is outside of menu - } else if (tribute.current.element && !tribute.current.externalTrigger) { - tribute.current.externalTrigger = false; - setTimeout(function () { - return tribute.hideMenu(); - }); - } - } - }, { - key: "keyup", - value: function keyup(instance, event) { - if (instance.inputEvent) { - instance.inputEvent = false; - } - - instance.updateSelection(this); - if (event.keyCode === 27) return; - - if (!instance.tribute.allowSpaces && instance.tribute.hasTrailingSpace) { - instance.tribute.hasTrailingSpace = false; - instance.commandEvent = true; - instance.callbacks()["space"](event, this); - return; - } - - if (!instance.tribute.isActive) { - if (instance.tribute.autocompleteMode) { - instance.callbacks().triggerChar(event, this, ""); - } else { - var keyCode = instance.getKeyCode(instance, this, event); - if (isNaN(keyCode) || !keyCode) return; - var trigger = instance.tribute.triggers().find(function (trigger) { - return trigger.charCodeAt(0) === keyCode; - }); - - if (typeof trigger !== "undefined") { - instance.callbacks().triggerChar(event, this, trigger); - } - } - } - - if (instance.tribute.current.mentionText.length < instance.tribute.current.collection.menuShowMinLength) { - return; - } - - if ((instance.tribute.current.trigger || instance.tribute.autocompleteMode) && instance.commandEvent === false || instance.tribute.isActive && event.keyCode === 8) { - instance.tribute.showMenuFor(this, true); - } - } - }, { - key: "shouldDeactivate", - value: function shouldDeactivate(event) { - if (!this.tribute.isActive) return false; - - if (this.tribute.current.mentionText.length === 0) { - var eventKeyPressed = false; - TributeEvents.keys().forEach(function (o) { - if (event.keyCode === o.key) eventKeyPressed = true; - }); - return !eventKeyPressed; - } - - return false; - } - }, { - key: "getKeyCode", - value: function getKeyCode(instance, el, event) { - - var tribute = instance.tribute; - var info = tribute.range.getTriggerInfo(false, tribute.hasTrailingSpace, true, tribute.allowSpaces, tribute.autocompleteMode); - - if (info) { - return info.mentionTriggerChar.charCodeAt(0); - } else { - return false; - } - } - }, { - key: "updateSelection", - value: function updateSelection(el) { - this.tribute.current.element = el; - var info = this.tribute.range.getTriggerInfo(false, this.tribute.hasTrailingSpace, true, this.tribute.allowSpaces, this.tribute.autocompleteMode); - - if (info) { - this.tribute.current.selectedPath = info.mentionSelectedPath; - this.tribute.current.mentionText = info.mentionText; - this.tribute.current.selectedOffset = info.mentionSelectedOffset; - } - } - }, { - key: "callbacks", - value: function callbacks() { - var _this = this; - - return { - triggerChar: function triggerChar(e, el, trigger) { - var tribute = _this.tribute; - tribute.current.trigger = trigger; - var collectionItem = tribute.collection.find(function (item) { - return item.trigger === trigger; - }); - tribute.current.collection = collectionItem; - - if (tribute.current.mentionText.length >= tribute.current.collection.menuShowMinLength && tribute.inputEvent) { - tribute.showMenuFor(el, true); - } - }, - enter: function enter(e, el) { - // choose selection - if (_this.tribute.isActive && _this.tribute.current.filteredItems) { - e.preventDefault(); - e.stopPropagation(); - setTimeout(function () { - _this.tribute.selectItemAtIndex(_this.tribute.menuSelected, e); - - _this.tribute.hideMenu(); - }, 0); - } - }, - escape: function escape(e, el) { - if (_this.tribute.isActive) { - e.preventDefault(); - e.stopPropagation(); - _this.tribute.isActive = false; - - _this.tribute.hideMenu(); - } - }, - tab: function tab(e, el) { - // choose first match - _this.callbacks().enter(e, el); - }, - space: function space(e, el) { - if (_this.tribute.isActive) { - if (_this.tribute.spaceSelectsMatch) { - _this.callbacks().enter(e, el); - } else if (!_this.tribute.allowSpaces) { - e.stopPropagation(); - setTimeout(function () { - _this.tribute.hideMenu(); - - _this.tribute.isActive = false; - }, 0); - } - } - }, - up: function up(e, el) { - // navigate up ul - if (_this.tribute.isActive && _this.tribute.current.filteredItems) { - e.preventDefault(); - e.stopPropagation(); - var count = _this.tribute.current.filteredItems.length, - selected = _this.tribute.menuSelected; - - if (count > selected && selected > 0) { - _this.tribute.menuSelected--; - - _this.setActiveLi(); - } else if (selected === 0) { - _this.tribute.menuSelected = count - 1; - - _this.setActiveLi(); - - _this.tribute.menu.scrollTop = _this.tribute.menu.scrollHeight; - } - } - }, - down: function down(e, el) { - // navigate down ul - if (_this.tribute.isActive && _this.tribute.current.filteredItems) { - e.preventDefault(); - e.stopPropagation(); - var count = _this.tribute.current.filteredItems.length - 1, - selected = _this.tribute.menuSelected; - - if (count > selected) { - _this.tribute.menuSelected++; - - _this.setActiveLi(); - } else if (count === selected) { - _this.tribute.menuSelected = 0; - - _this.setActiveLi(); - - _this.tribute.menu.scrollTop = 0; - } - } - }, - "delete": function _delete(e, el) { - if (_this.tribute.isActive && _this.tribute.current.mentionText.length < 1) { - _this.tribute.hideMenu(); - } else if (_this.tribute.isActive) { - _this.tribute.showMenuFor(el); - } - } - }; - } - }, { - key: "setActiveLi", - value: function setActiveLi(index) { - var lis = this.tribute.menu.querySelectorAll("li"), - length = lis.length >>> 0; - if (index) this.tribute.menuSelected = parseInt(index); - - for (var i = 0; i < length; i++) { - var li = lis[i]; - - if (i === this.tribute.menuSelected) { - li.classList.add(this.tribute.current.collection.selectClass); - var liClientRect = li.getBoundingClientRect(); - var menuClientRect = this.tribute.menu.getBoundingClientRect(); - - if (liClientRect.bottom > menuClientRect.bottom) { - var scrollDistance = liClientRect.bottom - menuClientRect.bottom; - this.tribute.menu.scrollTop += scrollDistance; - } else if (liClientRect.top < menuClientRect.top) { - var _scrollDistance = menuClientRect.top - liClientRect.top; - - this.tribute.menu.scrollTop -= _scrollDistance; - } - } else { - li.classList.remove(this.tribute.current.collection.selectClass); - } - } - } - }, { - key: "getFullHeight", - value: function getFullHeight(elem, includeMargin) { - var height = elem.getBoundingClientRect().height; - - if (includeMargin) { - var style = elem.currentStyle || window.getComputedStyle(elem); - return height + parseFloat(style.marginTop) + parseFloat(style.marginBottom); - } - - return height; - } - }], [{ - key: "keys", - value: function keys() { - return [{ - key: 9, - value: "TAB" - }, { - key: 8, - value: "DELETE" - }, { - key: 13, - value: "ENTER" - }, { - key: 27, - value: "ESCAPE" - }, { - key: 32, - value: "SPACE" - }, { - key: 38, - value: "UP" - }, { - key: 40, - value: "DOWN" - }]; - } - }]); - - return TributeEvents; - }(); - - var TributeMenuEvents = /*#__PURE__*/function () { - function TributeMenuEvents(tribute) { - _classCallCheck(this, TributeMenuEvents); - - this.tribute = tribute; - this.tribute.menuEvents = this; - this.menu = this.tribute.menu; - } - - _createClass(TributeMenuEvents, [{ - key: "bind", - value: function bind(menu) { - var _this = this; - - this.menuClickEvent = this.tribute.events.click.bind(null, this); - this.menuContainerScrollEvent = this.debounce(function () { - if (_this.tribute.isActive) { - _this.tribute.showMenuFor(_this.tribute.current.element, false); - } - }, 300, false); - this.windowResizeEvent = this.debounce(function () { - if (_this.tribute.isActive) { - _this.tribute.range.positionMenuAtCaret(true); - } - }, 300, false); // fixes IE11 issues with mousedown - - this.tribute.range.getDocument().addEventListener("MSPointerDown", this.menuClickEvent, false); - this.tribute.range.getDocument().addEventListener("mousedown", this.menuClickEvent, false); - window.addEventListener("resize", this.windowResizeEvent); - - if (this.menuContainer) { - this.menuContainer.addEventListener("scroll", this.menuContainerScrollEvent, false); - } else { - window.addEventListener("scroll", this.menuContainerScrollEvent); - } - } - }, { - key: "unbind", - value: function unbind(menu) { - this.tribute.range.getDocument().removeEventListener("mousedown", this.menuClickEvent, false); - this.tribute.range.getDocument().removeEventListener("MSPointerDown", this.menuClickEvent, false); - window.removeEventListener("resize", this.windowResizeEvent); - - if (this.menuContainer) { - this.menuContainer.removeEventListener("scroll", this.menuContainerScrollEvent, false); - } else { - window.removeEventListener("scroll", this.menuContainerScrollEvent); - } - } - }, { - key: "debounce", - value: function debounce(func, wait, immediate) { - var _arguments = arguments, - _this2 = this; - - var timeout; - return function () { - var context = _this2, - args = _arguments; - - var later = function later() { - timeout = null; - if (!immediate) func.apply(context, args); - }; - - var callNow = immediate && !timeout; - clearTimeout(timeout); - timeout = setTimeout(later, wait); - if (callNow) func.apply(context, args); - }; - } - }]); - - return TributeMenuEvents; - }(); - - var TributeRange = /*#__PURE__*/function () { - function TributeRange(tribute) { - _classCallCheck(this, TributeRange); - - this.tribute = tribute; - this.tribute.range = this; - } - - _createClass(TributeRange, [{ - key: "getDocument", - value: function getDocument() { - var iframe; - - if (this.tribute.current.collection) { - iframe = this.tribute.current.collection.iframe; - } - - if (!iframe) { - return document; - } - - return iframe.contentWindow.document; - } - }, { - key: "positionMenuAtCaret", - value: function positionMenuAtCaret(scrollTo) { - var _this = this; - - var context = this.tribute.current, - coordinates; - var info = this.getTriggerInfo(false, this.tribute.hasTrailingSpace, true, this.tribute.allowSpaces, this.tribute.autocompleteMode); - - if (typeof info !== 'undefined') { - if (!this.tribute.positionMenu) { - this.tribute.menu.style.cssText = "display: block;"; - return; - } - - if (!this.isContentEditable(context.element)) { - coordinates = this.getTextAreaOrInputUnderlinePosition(this.tribute.current.element, info.mentionPosition); - } else { - coordinates = this.getContentEditableCaretPosition(info.mentionPosition); - } - - this.tribute.menu.style.cssText = "top: ".concat(coordinates.top, "px;\n left: ").concat(coordinates.left, "px;\n right: ").concat(coordinates.right, "px;\n bottom: ").concat(coordinates.bottom, "px;\n position: absolute;\n display: block;"); - - if (coordinates.left === 'auto') { - this.tribute.menu.style.left = 'auto'; - } - - if (coordinates.top === 'auto') { - this.tribute.menu.style.top = 'auto'; - } - - if (scrollTo) this.scrollIntoView(); - window.setTimeout(function () { - var menuDimensions = { - width: _this.tribute.menu.offsetWidth, - height: _this.tribute.menu.offsetHeight - }; - - var menuIsOffScreen = _this.isMenuOffScreen(coordinates, menuDimensions); - - var menuIsOffScreenHorizontally = window.innerWidth > menuDimensions.width && (menuIsOffScreen.left || menuIsOffScreen.right); - var menuIsOffScreenVertically = window.innerHeight > menuDimensions.height && (menuIsOffScreen.top || menuIsOffScreen.bottom); - - if (menuIsOffScreenHorizontally || menuIsOffScreenVertically) { - _this.tribute.menu.style.cssText = 'display: none'; - - _this.positionMenuAtCaret(scrollTo); - } - }, 0); - } else { - this.tribute.menu.style.cssText = 'display: none'; - } - } - }, { - key: "selectElement", - value: function selectElement(targetElement, path, offset) { - var range; - var elem = targetElement; - - if (path) { - for (var i = 0; i < path.length; i++) { - elem = elem.childNodes[path[i]]; - - if (elem === undefined) { - return; - } - - while (elem.length < offset) { - offset -= elem.length; - elem = elem.nextSibling; - } - - if (elem.childNodes.length === 0 && !elem.length) { - elem = elem.previousSibling; - } - } - } - - var sel = this.getWindowSelection(); - range = this.getDocument().createRange(); - range.setStart(elem, offset); - range.setEnd(elem, offset); - range.collapse(true); - - try { - sel.removeAllRanges(); - } catch (error) {} - - sel.addRange(range); - targetElement.focus(); - } - }, { - key: "replaceTriggerText", - value: function replaceTriggerText(text, requireLeadingSpace, hasTrailingSpace, originalEvent, item) { - var info = this.getTriggerInfo(true, hasTrailingSpace, requireLeadingSpace, this.tribute.allowSpaces, this.tribute.autocompleteMode); - - if (info !== undefined) { - var context = this.tribute.current; - var replaceEvent = new CustomEvent('tribute-replaced', { - detail: { - item: item, - instance: context, - context: info, - event: originalEvent - } - }); - - if (!this.isContentEditable(context.element)) { - var myField = this.tribute.current.element; - var textSuffix = typeof this.tribute.replaceTextSuffix == 'string' ? this.tribute.replaceTextSuffix : ' '; - text += textSuffix; - var startPos = info.mentionPosition; - var endPos = info.mentionPosition + info.mentionText.length + textSuffix.length; - - if (!this.tribute.autocompleteMode) { - endPos += info.mentionTriggerChar.length - 1; - } - - myField.value = myField.value.substring(0, startPos) + text + myField.value.substring(endPos, myField.value.length); - myField.selectionStart = startPos + text.length; - myField.selectionEnd = startPos + text.length; - } else { - // add a space to the end of the pasted text - var _textSuffix = typeof this.tribute.replaceTextSuffix == 'string' ? this.tribute.replaceTextSuffix : '\xA0'; - - text += _textSuffix; - - var _endPos = info.mentionPosition + info.mentionText.length; - - if (!this.tribute.autocompleteMode) { - _endPos += info.mentionTriggerChar.length; - } - - this.pasteHtml(text, info.mentionPosition, _endPos); - } - - context.element.dispatchEvent(new CustomEvent('input', { - bubbles: true - })); - context.element.dispatchEvent(replaceEvent); - } - } - }, { - key: "pasteHtml", - value: function pasteHtml(html, startPos, endPos) { - var range, sel; - sel = this.getWindowSelection(); - range = this.getDocument().createRange(); - range.setStart(sel.anchorNode, startPos); - range.setEnd(sel.anchorNode, endPos); - range.deleteContents(); - var el = this.getDocument().createElement('div'); - el.innerHTML = html; - var frag = this.getDocument().createDocumentFragment(), - node, - lastNode; - - while (node = el.firstChild) { - lastNode = frag.appendChild(node); - } - - range.insertNode(frag); // Preserve the selection - - if (lastNode) { - range = range.cloneRange(); - range.setStartAfter(lastNode); - range.collapse(true); - sel.removeAllRanges(); - sel.addRange(range); - } - } - }, { - key: "getWindowSelection", - value: function getWindowSelection() { - if (this.tribute.collection.iframe) { - return this.tribute.collection.iframe.contentWindow.getSelection(); - } - - return window.getSelection(); - } - }, { - key: "getNodePositionInParent", - value: function getNodePositionInParent(element) { - if (element.parentNode === null) { - return 0; - } - - for (var i = 0; i < element.parentNode.childNodes.length; i++) { - var node = element.parentNode.childNodes[i]; - - if (node === element) { - return i; - } - } - } - }, { - key: "getContentEditableSelectedPath", - value: function getContentEditableSelectedPath(ctx) { - var sel = this.getWindowSelection(); - var selected = sel.anchorNode; - var path = []; - var offset; - - if (selected != null) { - var i; - var ce = selected.contentEditable; - - while (selected !== null && ce !== 'true') { - i = this.getNodePositionInParent(selected); - path.push(i); - selected = selected.parentNode; - - if (selected !== null) { - ce = selected.contentEditable; - } - } - - path.reverse(); // getRangeAt may not exist, need alternative - - offset = sel.getRangeAt(0).startOffset; - return { - selected: selected, - path: path, - offset: offset - }; - } - } - }, { - key: "getTextPrecedingCurrentSelection", - value: function getTextPrecedingCurrentSelection() { - var context = this.tribute.current, - text = ''; - - if (!this.isContentEditable(context.element)) { - var textComponent = this.tribute.current.element; - - if (textComponent) { - var startPos = textComponent.selectionStart; - - if (textComponent.value && startPos >= 0) { - text = textComponent.value.substring(0, startPos); - } - } - } else { - var selectedElem = this.getWindowSelection().anchorNode; - - if (selectedElem != null) { - var workingNodeContent = selectedElem.textContent; - var selectStartOffset = this.getWindowSelection().getRangeAt(0).startOffset; - - if (workingNodeContent && selectStartOffset >= 0) { - text = workingNodeContent.substring(0, selectStartOffset); - } - } - } - - return text; - } - }, { - key: "getLastWordInText", - value: function getLastWordInText(text) { - text = text.replace(/\u00A0/g, ' '); // https://stackoverflow.com/questions/29850407/how-do-i-replace-unicode-character-u00a0-with-a-space-in-javascript - - var wordsArray; - - if (this.tribute.autocompleteSeparator) { - wordsArray = text.split(this.tribute.autocompleteSeparator); - } else { - wordsArray = text.split(/\s+/); - } - - var worldsCount = wordsArray.length - 1; - return wordsArray[worldsCount].trim(); - } - }, { - key: "getTriggerInfo", - value: function getTriggerInfo(menuAlreadyActive, hasTrailingSpace, requireLeadingSpace, allowSpaces, isAutocomplete) { - var _this2 = this; - - var ctx = this.tribute.current; - var selected, path, offset; - - if (!this.isContentEditable(ctx.element)) { - selected = this.tribute.current.element; - } else { - var selectionInfo = this.getContentEditableSelectedPath(ctx); - - if (selectionInfo) { - selected = selectionInfo.selected; - path = selectionInfo.path; - offset = selectionInfo.offset; - } - } - - var effectiveRange = this.getTextPrecedingCurrentSelection(); - var lastWordOfEffectiveRange = this.getLastWordInText(effectiveRange); - - if (isAutocomplete) { - return { - mentionPosition: effectiveRange.length - lastWordOfEffectiveRange.length, - mentionText: lastWordOfEffectiveRange, - mentionSelectedElement: selected, - mentionSelectedPath: path, - mentionSelectedOffset: offset - }; - } - - if (effectiveRange !== undefined && effectiveRange !== null) { - var mostRecentTriggerCharPos = -1; - var triggerChar; - this.tribute.collection.forEach(function (config) { - var c = config.trigger; - var idx = config.requireLeadingSpace ? _this2.lastIndexWithLeadingSpace(effectiveRange, c) : effectiveRange.lastIndexOf(c); - - if (idx > mostRecentTriggerCharPos) { - mostRecentTriggerCharPos = idx; - triggerChar = c; - requireLeadingSpace = config.requireLeadingSpace; - } - }); - - if (mostRecentTriggerCharPos >= 0 && (mostRecentTriggerCharPos === 0 || !requireLeadingSpace || /[\xA0\s]/g.test(effectiveRange.substring(mostRecentTriggerCharPos - 1, mostRecentTriggerCharPos)))) { - var currentTriggerSnippet = effectiveRange.substring(mostRecentTriggerCharPos + triggerChar.length, effectiveRange.length); - triggerChar = effectiveRange.substring(mostRecentTriggerCharPos, mostRecentTriggerCharPos + triggerChar.length); - var firstSnippetChar = currentTriggerSnippet.substring(0, 1); - var leadingSpace = currentTriggerSnippet.length > 0 && (firstSnippetChar === ' ' || firstSnippetChar === '\xA0'); - - if (hasTrailingSpace) { - currentTriggerSnippet = currentTriggerSnippet.trim(); - } - - var regex = allowSpaces ? /[^\S ]/g : /[\xA0\s]/g; - this.tribute.hasTrailingSpace = regex.test(currentTriggerSnippet); - - if (!leadingSpace && (menuAlreadyActive || !regex.test(currentTriggerSnippet))) { - return { - mentionPosition: mostRecentTriggerCharPos, - mentionText: currentTriggerSnippet, - mentionSelectedElement: selected, - mentionSelectedPath: path, - mentionSelectedOffset: offset, - mentionTriggerChar: triggerChar - }; - } - } - } - } - }, { - key: "lastIndexWithLeadingSpace", - value: function lastIndexWithLeadingSpace(str, trigger) { - var reversedStr = str.split('').reverse().join(''); - var index = -1; - - for (var cidx = 0, len = str.length; cidx < len; cidx++) { - var firstChar = cidx === str.length - 1; - var leadingSpace = /\s/.test(reversedStr[cidx + 1]); - var match = true; - - for (var triggerIdx = trigger.length - 1; triggerIdx >= 0; triggerIdx--) { - if (trigger[triggerIdx] !== reversedStr[cidx - triggerIdx]) { - match = false; - break; - } - } - - if (match && (firstChar || leadingSpace)) { - index = str.length - 1 - cidx; - break; - } - } - - return index; - } - }, { - key: "isContentEditable", - value: function isContentEditable(element) { - return element.nodeName !== 'INPUT' && element.nodeName !== 'TEXTAREA'; - } - }, { - key: "isMenuOffScreen", - value: function isMenuOffScreen(coordinates, menuDimensions) { - var windowWidth = window.innerWidth; - var windowHeight = window.innerHeight; - var doc = document.documentElement; - var windowLeft = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0); - var windowTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); - var menuTop = typeof coordinates.top === 'number' ? coordinates.top : windowTop + windowHeight - coordinates.bottom - menuDimensions.height; - var menuRight = typeof coordinates.right === 'number' ? coordinates.right : coordinates.left + menuDimensions.width; - var menuBottom = typeof coordinates.bottom === 'number' ? coordinates.bottom : coordinates.top + menuDimensions.height; - var menuLeft = typeof coordinates.left === 'number' ? coordinates.left : windowLeft + windowWidth - coordinates.right - menuDimensions.width; - return { - top: menuTop < Math.floor(windowTop), - right: menuRight > Math.ceil(windowLeft + windowWidth), - bottom: menuBottom > Math.ceil(windowTop + windowHeight), - left: menuLeft < Math.floor(windowLeft) - }; - } - }, { - key: "getMenuDimensions", - value: function getMenuDimensions() { - // Width of the menu depends of its contents and position - // We must check what its width would be without any obstruction - // This way, we can achieve good positioning for flipping the menu - var dimensions = { - width: null, - height: null - }; - this.tribute.menu.style.cssText = "top: 0px;\n left: 0px;\n position: fixed;\n display: block;\n visibility; hidden;"; - dimensions.width = this.tribute.menu.offsetWidth; - dimensions.height = this.tribute.menu.offsetHeight; - this.tribute.menu.style.cssText = "display: none;"; - return dimensions; - } - }, { - key: "getTextAreaOrInputUnderlinePosition", - value: function getTextAreaOrInputUnderlinePosition(element, position, flipped) { - var properties = ['direction', 'boxSizing', 'width', 'height', 'overflowX', 'overflowY', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'fontSizeAdjust', 'lineHeight', 'fontFamily', 'textAlign', 'textTransform', 'textIndent', 'textDecoration', 'letterSpacing', 'wordSpacing']; - var isFirefox = window.mozInnerScreenX !== null; - var div = this.getDocument().createElement('div'); - div.id = 'input-textarea-caret-position-mirror-div'; - this.getDocument().body.appendChild(div); - var style = div.style; - var computed = window.getComputedStyle ? getComputedStyle(element) : element.currentStyle; - style.whiteSpace = 'pre-wrap'; - - if (element.nodeName !== 'INPUT') { - style.wordWrap = 'break-word'; - } // position off-screen - - - style.position = 'absolute'; - style.visibility = 'hidden'; // transfer the element's properties to the div - - properties.forEach(function (prop) { - style[prop] = computed[prop]; - }); - - if (isFirefox) { - style.width = "".concat(parseInt(computed.width) - 2, "px"); - if (element.scrollHeight > parseInt(computed.height)) style.overflowY = 'scroll'; - } else { - style.overflow = 'hidden'; - } - - div.textContent = element.value.substring(0, position); - - if (element.nodeName === 'INPUT') { - div.textContent = div.textContent.replace(/\s/g, ' '); - } - - var span = this.getDocument().createElement('span'); - span.textContent = element.value.substring(position) || '.'; - div.appendChild(span); - var rect = element.getBoundingClientRect(); - var doc = document.documentElement; - var windowLeft = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0); - var windowTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); - var top = 0; - var left = 0; - - if (this.menuContainerIsBody) { - top = rect.top; - left = rect.left; - } - - var coordinates = { - top: top + windowTop + span.offsetTop + parseInt(computed.borderTopWidth) + parseInt(computed.fontSize) - element.scrollTop, - left: left + windowLeft + span.offsetLeft + parseInt(computed.borderLeftWidth) - }; - var windowWidth = window.innerWidth; - var windowHeight = window.innerHeight; - var menuDimensions = this.getMenuDimensions(); - var menuIsOffScreen = this.isMenuOffScreen(coordinates, menuDimensions); - - if (menuIsOffScreen.right) { - coordinates.right = windowWidth - coordinates.left; - coordinates.left = 'auto'; - } - - var parentHeight = this.tribute.menuContainer ? this.tribute.menuContainer.offsetHeight : this.getDocument().body.offsetHeight; - - if (menuIsOffScreen.bottom) { - var parentRect = this.tribute.menuContainer ? this.tribute.menuContainer.getBoundingClientRect() : this.getDocument().body.getBoundingClientRect(); - var scrollStillAvailable = parentHeight - (windowHeight - parentRect.top); - coordinates.bottom = scrollStillAvailable + (windowHeight - rect.top - span.offsetTop); - coordinates.top = 'auto'; - } - - menuIsOffScreen = this.isMenuOffScreen(coordinates, menuDimensions); - - if (menuIsOffScreen.left) { - coordinates.left = windowWidth > menuDimensions.width ? windowLeft + windowWidth - menuDimensions.width : windowLeft; - delete coordinates.right; - } - - if (menuIsOffScreen.top) { - coordinates.top = windowHeight > menuDimensions.height ? windowTop + windowHeight - menuDimensions.height : windowTop; - delete coordinates.bottom; - } - - this.getDocument().body.removeChild(div); - return coordinates; - } - }, { - key: "getContentEditableCaretPosition", - value: function getContentEditableCaretPosition(selectedNodePosition) { - var range; - var sel = this.getWindowSelection(); - range = this.getDocument().createRange(); - range.setStart(sel.anchorNode, selectedNodePosition); - range.setEnd(sel.anchorNode, selectedNodePosition); - range.collapse(false); - var rect = range.getBoundingClientRect(); - var doc = document.documentElement; - var windowLeft = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0); - var windowTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); - var left = rect.left; - var top = rect.top; - var coordinates = { - left: left + windowLeft, - top: top + rect.height + windowTop - }; - var windowWidth = window.innerWidth; - var windowHeight = window.innerHeight; - var menuDimensions = this.getMenuDimensions(); - var menuIsOffScreen = this.isMenuOffScreen(coordinates, menuDimensions); - - if (menuIsOffScreen.right) { - coordinates.left = 'auto'; - coordinates.right = windowWidth - rect.left - windowLeft; - } - - var parentHeight = this.tribute.menuContainer ? this.tribute.menuContainer.offsetHeight : this.getDocument().body.offsetHeight; - - if (menuIsOffScreen.bottom) { - var parentRect = this.tribute.menuContainer ? this.tribute.menuContainer.getBoundingClientRect() : this.getDocument().body.getBoundingClientRect(); - var scrollStillAvailable = parentHeight - (windowHeight - parentRect.top); - coordinates.top = 'auto'; - coordinates.bottom = scrollStillAvailable + (windowHeight - rect.top); - } - - menuIsOffScreen = this.isMenuOffScreen(coordinates, menuDimensions); - - if (menuIsOffScreen.left) { - coordinates.left = windowWidth > menuDimensions.width ? windowLeft + windowWidth - menuDimensions.width : windowLeft; - delete coordinates.right; - } - - if (menuIsOffScreen.top) { - coordinates.top = windowHeight > menuDimensions.height ? windowTop + windowHeight - menuDimensions.height : windowTop; - delete coordinates.bottom; - } - - if (!this.menuContainerIsBody) { - coordinates.left = coordinates.left ? coordinates.left - this.tribute.menuContainer.offsetLeft : coordinates.left; - coordinates.top = coordinates.top ? coordinates.top - this.tribute.menuContainer.offsetTop : coordinates.top; - } - - return coordinates; - } - }, { - key: "scrollIntoView", - value: function scrollIntoView(elem) { - var reasonableBuffer = 20, - clientRect; - var maxScrollDisplacement = 100; - var e = this.menu; - if (typeof e === 'undefined') return; - - while (clientRect === undefined || clientRect.height === 0) { - clientRect = e.getBoundingClientRect(); - - if (clientRect.height === 0) { - e = e.childNodes[0]; - - if (e === undefined || !e.getBoundingClientRect) { - return; - } - } - } - - var elemTop = clientRect.top; - var elemBottom = elemTop + clientRect.height; - - if (elemTop < 0) { - window.scrollTo(0, window.pageYOffset + clientRect.top - reasonableBuffer); - } else if (elemBottom > window.innerHeight) { - var maxY = window.pageYOffset + clientRect.top - reasonableBuffer; - - if (maxY - window.pageYOffset > maxScrollDisplacement) { - maxY = window.pageYOffset + maxScrollDisplacement; - } - - var targetY = window.pageYOffset - (window.innerHeight - elemBottom); - - if (targetY > maxY) { - targetY = maxY; - } - - window.scrollTo(0, targetY); - } - } - }, { - key: "menuContainerIsBody", - get: function get() { - return this.tribute.menuContainer === document.body || !this.tribute.menuContainer; - } - }]); - - return TributeRange; - }(); - - // Thanks to https://github.com/mattyork/fuzzy - var TributeSearch = /*#__PURE__*/function () { - function TributeSearch(tribute) { - _classCallCheck(this, TributeSearch); - - this.tribute = tribute; - this.tribute.search = this; - } - - _createClass(TributeSearch, [{ - key: "simpleFilter", - value: function simpleFilter(pattern, array) { - var _this = this; - - return array.filter(function (string) { - return _this.test(pattern, string); - }); - } - }, { - key: "test", - value: function test(pattern, string) { - return this.match(pattern, string) !== null; - } - }, { - key: "match", - value: function match(pattern, string, opts) { - opts = opts || {}; - var len = string.length, - pre = opts.pre || '', - post = opts.post || '', - compareString = opts.caseSensitive && string || string.toLowerCase(); - - if (opts.skip) { - return { - rendered: string, - score: 0 - }; - } - - pattern = opts.caseSensitive && pattern || pattern.toLowerCase(); - var patternCache = this.traverse(compareString, pattern, 0, 0, []); - - if (!patternCache) { - return null; - } - - return { - rendered: this.render(string, patternCache.cache, pre, post), - score: patternCache.score - }; - } - }, { - key: "traverse", - value: function traverse(string, pattern, stringIndex, patternIndex, patternCache) { - if (this.tribute.autocompleteSeparator) { - // if the pattern search at end - pattern = pattern.split(this.tribute.autocompleteSeparator).splice(-1)[0]; - } - - if (pattern.length === patternIndex) { - // calculate score and copy the cache containing the indices where it's found - return { - score: this.calculateScore(patternCache), - cache: patternCache.slice() - }; - } // if string at end or remaining pattern > remaining string - - - if (string.length === stringIndex || pattern.length - patternIndex > string.length - stringIndex) { - return undefined; - } - - var c = pattern[patternIndex]; - var index = string.indexOf(c, stringIndex); - var best, temp; - - while (index > -1) { - patternCache.push(index); - temp = this.traverse(string, pattern, index + 1, patternIndex + 1, patternCache); - patternCache.pop(); // if downstream traversal failed, return best answer so far - - if (!temp) { - return best; - } - - if (!best || best.score < temp.score) { - best = temp; - } - - index = string.indexOf(c, index + 1); - } - - return best; - } - }, { - key: "calculateScore", - value: function calculateScore(patternCache) { - var score = 0; - var temp = 1; - patternCache.forEach(function (index, i) { - if (i > 0) { - if (patternCache[i - 1] + 1 === index) { - temp += temp + 1; - } else { - temp = 1; - } - } - - score += temp; - }); - return score; - } - }, { - key: "render", - value: function render(string, indices, pre, post) { - var rendered = string.substring(0, indices[0]); - indices.forEach(function (index, i) { - rendered += pre + string[index] + post + string.substring(index + 1, indices[i + 1] ? indices[i + 1] : string.length); - }); - return rendered; - } - }, { - key: "filter", - value: function filter(pattern, arr, opts) { - var _this2 = this; - - opts = opts || {}; - return arr.reduce(function (prev, element, idx, arr) { - var str = element; - - if (opts.extract) { - str = opts.extract(element); - - if (!str) { - // take care of undefineds / nulls / etc. - str = ''; - } - } - - var rendered = _this2.match(pattern, str, opts); - - if (rendered != null) { - prev[prev.length] = { - string: rendered.rendered, - score: rendered.score, - index: idx, - original: element - }; - } - - return prev; - }, []).sort(function (a, b) { - var compare = b.score - a.score; - if (compare) return compare; - return a.index - b.index; - }); - } - }]); - - return TributeSearch; - }(); - - var Tribute = /*#__PURE__*/function () { - function Tribute(_ref) { - var _this = this; - - var _ref$values = _ref.values, - values = _ref$values === void 0 ? null : _ref$values, - _ref$loadingItemTempl = _ref.loadingItemTemplate, - loadingItemTemplate = _ref$loadingItemTempl === void 0 ? null : _ref$loadingItemTempl, - _ref$iframe = _ref.iframe, - iframe = _ref$iframe === void 0 ? null : _ref$iframe, - _ref$selectClass = _ref.selectClass, - selectClass = _ref$selectClass === void 0 ? "highlight" : _ref$selectClass, - _ref$containerClass = _ref.containerClass, - containerClass = _ref$containerClass === void 0 ? "tribute-container" : _ref$containerClass, - _ref$itemClass = _ref.itemClass, - itemClass = _ref$itemClass === void 0 ? "" : _ref$itemClass, - _ref$trigger = _ref.trigger, - trigger = _ref$trigger === void 0 ? "@" : _ref$trigger, - _ref$autocompleteMode = _ref.autocompleteMode, - autocompleteMode = _ref$autocompleteMode === void 0 ? false : _ref$autocompleteMode, - _ref$autocompleteSepa = _ref.autocompleteSeparator, - autocompleteSeparator = _ref$autocompleteSepa === void 0 ? null : _ref$autocompleteSepa, - _ref$selectTemplate = _ref.selectTemplate, - selectTemplate = _ref$selectTemplate === void 0 ? null : _ref$selectTemplate, - _ref$menuItemTemplate = _ref.menuItemTemplate, - menuItemTemplate = _ref$menuItemTemplate === void 0 ? null : _ref$menuItemTemplate, - _ref$lookup = _ref.lookup, - lookup = _ref$lookup === void 0 ? "key" : _ref$lookup, - _ref$fillAttr = _ref.fillAttr, - fillAttr = _ref$fillAttr === void 0 ? "value" : _ref$fillAttr, - _ref$collection = _ref.collection, - collection = _ref$collection === void 0 ? null : _ref$collection, - _ref$menuContainer = _ref.menuContainer, - menuContainer = _ref$menuContainer === void 0 ? null : _ref$menuContainer, - _ref$noMatchTemplate = _ref.noMatchTemplate, - noMatchTemplate = _ref$noMatchTemplate === void 0 ? null : _ref$noMatchTemplate, - _ref$requireLeadingSp = _ref.requireLeadingSpace, - requireLeadingSpace = _ref$requireLeadingSp === void 0 ? true : _ref$requireLeadingSp, - _ref$allowSpaces = _ref.allowSpaces, - allowSpaces = _ref$allowSpaces === void 0 ? false : _ref$allowSpaces, - _ref$replaceTextSuffi = _ref.replaceTextSuffix, - replaceTextSuffix = _ref$replaceTextSuffi === void 0 ? null : _ref$replaceTextSuffi, - _ref$positionMenu = _ref.positionMenu, - positionMenu = _ref$positionMenu === void 0 ? true : _ref$positionMenu, - _ref$spaceSelectsMatc = _ref.spaceSelectsMatch, - spaceSelectsMatch = _ref$spaceSelectsMatc === void 0 ? false : _ref$spaceSelectsMatc, - _ref$searchOpts = _ref.searchOpts, - searchOpts = _ref$searchOpts === void 0 ? {} : _ref$searchOpts, - _ref$menuItemLimit = _ref.menuItemLimit, - menuItemLimit = _ref$menuItemLimit === void 0 ? null : _ref$menuItemLimit, - _ref$menuShowMinLengt = _ref.menuShowMinLength, - menuShowMinLength = _ref$menuShowMinLengt === void 0 ? 0 : _ref$menuShowMinLengt; - - _classCallCheck(this, Tribute); - - this.autocompleteMode = autocompleteMode; - this.autocompleteSeparator = autocompleteSeparator; - this.menuSelected = 0; - this.current = {}; - this.inputEvent = false; - this.isActive = false; - this.menuContainer = menuContainer; - this.allowSpaces = allowSpaces; - this.replaceTextSuffix = replaceTextSuffix; - this.positionMenu = positionMenu; - this.hasTrailingSpace = false; - this.spaceSelectsMatch = spaceSelectsMatch; - - if (this.autocompleteMode) { - trigger = ""; - allowSpaces = false; - } - - if (values) { - this.collection = [{ - // symbol that starts the lookup - trigger: trigger, - // is it wrapped in an iframe - iframe: iframe, - // class applied to selected item - selectClass: selectClass, - // class applied to the Container - containerClass: containerClass, - // class applied to each item - itemClass: itemClass, - // function called on select that retuns the content to insert - selectTemplate: (selectTemplate || Tribute.defaultSelectTemplate).bind(this), - // function called that returns content for an item - menuItemTemplate: (menuItemTemplate || Tribute.defaultMenuItemTemplate).bind(this), - // function called when menu is empty, disables hiding of menu. - noMatchTemplate: function (t) { - if (typeof t === "string") { - if (t.trim() === "") return null; - return t; - } - - if (typeof t === "function") { - return t.bind(_this); - } - - return noMatchTemplate || function () { - return "
  • No Match Found!
  • "; - }.bind(_this); - }(noMatchTemplate), - // column to search against in the object - lookup: lookup, - // column that contains the content to insert by default - fillAttr: fillAttr, - // array of objects or a function returning an array of objects - values: values, - // useful for when values is an async function - loadingItemTemplate: loadingItemTemplate, - requireLeadingSpace: requireLeadingSpace, - searchOpts: searchOpts, - menuItemLimit: menuItemLimit, - menuShowMinLength: menuShowMinLength - }]; - } else if (collection) { - if (this.autocompleteMode) console.warn("Tribute in autocomplete mode does not work for collections"); - this.collection = collection.map(function (item) { - return { - trigger: item.trigger || trigger, - iframe: item.iframe || iframe, - selectClass: item.selectClass || selectClass, - containerClass: item.containerClass || containerClass, - itemClass: item.itemClass || itemClass, - selectTemplate: (item.selectTemplate || Tribute.defaultSelectTemplate).bind(_this), - menuItemTemplate: (item.menuItemTemplate || Tribute.defaultMenuItemTemplate).bind(_this), - // function called when menu is empty, disables hiding of menu. - noMatchTemplate: function (t) { - if (typeof t === "string") { - if (t.trim() === "") return null; - return t; - } - - if (typeof t === "function") { - return t.bind(_this); - } - - return noMatchTemplate || function () { - return "
  • No Match Found!
  • "; - }.bind(_this); - }(noMatchTemplate), - lookup: item.lookup || lookup, - fillAttr: item.fillAttr || fillAttr, - values: item.values, - loadingItemTemplate: item.loadingItemTemplate, - requireLeadingSpace: item.requireLeadingSpace, - searchOpts: item.searchOpts || searchOpts, - menuItemLimit: item.menuItemLimit || menuItemLimit, - menuShowMinLength: item.menuShowMinLength || menuShowMinLength - }; - }); - } else { - throw new Error("[Tribute] No collection specified."); - } - - new TributeRange(this); - new TributeEvents(this); - new TributeMenuEvents(this); - new TributeSearch(this); - } - - _createClass(Tribute, [{ - key: "triggers", - value: function triggers() { - return this.collection.map(function (config) { - return config.trigger; - }); - } - }, { - key: "attach", - value: function attach(el) { - if (!el) { - throw new Error("[Tribute] Must pass in a DOM node or NodeList."); - } // Check if it is a jQuery collection - - - if (typeof jQuery !== "undefined" && el instanceof jQuery) { - el = el.get(); - } // Is el an Array/Array-like object? - - - if (el.constructor === NodeList || el.constructor === HTMLCollection || el.constructor === Array) { - var length = el.length; - - for (var i = 0; i < length; ++i) { - this._attach(el[i]); - } - } else { - this._attach(el); - } - } - }, { - key: "_attach", - value: function _attach(el) { - if (el.hasAttribute("data-tribute")) { - console.warn("Tribute was already bound to " + el.nodeName); - } - - this.ensureEditable(el); - this.events.bind(el); - el.setAttribute("data-tribute", true); - } - }, { - key: "ensureEditable", - value: function ensureEditable(element) { - if (Tribute.inputTypes().indexOf(element.nodeName) === -1) { - if (element.contentEditable) { - element.contentEditable = true; - } else { - throw new Error("[Tribute] Cannot bind to " + element.nodeName); - } - } - } - }, { - key: "createMenu", - value: function createMenu(containerClass) { - var wrapper = this.range.getDocument().createElement("div"), - ul = this.range.getDocument().createElement("ul"); - wrapper.className = containerClass; - wrapper.appendChild(ul); - - if (this.menuContainer) { - return this.menuContainer.appendChild(wrapper); - } - - return this.range.getDocument().body.appendChild(wrapper); - } - }, { - key: "showMenuFor", - value: function showMenuFor(element, scrollTo) { - var _this2 = this; - - // Only proceed if menu isn't already shown for the current element & mentionText - if (this.isActive && this.current.element === element && this.current.mentionText === this.currentMentionTextSnapshot) { - return; - } - - this.currentMentionTextSnapshot = this.current.mentionText; // create the menu if it doesn't exist. - - if (!this.menu) { - this.menu = this.createMenu(this.current.collection.containerClass); - element.tributeMenu = this.menu; - this.menuEvents.bind(this.menu); - } - - this.isActive = true; - this.menuSelected = 0; - - if (!this.current.mentionText) { - this.current.mentionText = ""; - } - - var processValues = function processValues(values) { - // Tribute may not be active any more by the time the value callback returns - if (!_this2.isActive) { - return; - } - - var items = _this2.search.filter(_this2.current.mentionText, values, { - pre: _this2.current.collection.searchOpts.pre || "", - post: _this2.current.collection.searchOpts.post || "", - skip: _this2.current.collection.searchOpts.skip, - extract: function extract(el) { - if (typeof _this2.current.collection.lookup === "string") { - return el[_this2.current.collection.lookup]; - } else if (typeof _this2.current.collection.lookup === "function") { - return _this2.current.collection.lookup(el, _this2.current.mentionText); - } else { - throw new Error("Invalid lookup attribute, lookup must be string or function."); - } - } - }); - - if (_this2.current.collection.menuItemLimit) { - items = items.slice(0, _this2.current.collection.menuItemLimit); - } - - _this2.current.filteredItems = items; - - var ul = _this2.menu.querySelector("ul"); - - _this2.range.positionMenuAtCaret(scrollTo); - - if (!items.length) { - var noMatchEvent = new CustomEvent("tribute-no-match", { - detail: _this2.menu - }); - - _this2.current.element.dispatchEvent(noMatchEvent); - - if (typeof _this2.current.collection.noMatchTemplate === "function" && !_this2.current.collection.noMatchTemplate() || !_this2.current.collection.noMatchTemplate) { - _this2.hideMenu(); - } else { - typeof _this2.current.collection.noMatchTemplate === "function" ? ul.innerHTML = _this2.current.collection.noMatchTemplate() : ul.innerHTML = _this2.current.collection.noMatchTemplate; - } - - return; - } - - ul.innerHTML = ""; - - var fragment = _this2.range.getDocument().createDocumentFragment(); - - items.forEach(function (item, index) { - var li = _this2.range.getDocument().createElement("li"); - - li.setAttribute("data-index", index); - li.className = _this2.current.collection.itemClass; - li.addEventListener("mousemove", function (e) { - var _this2$_findLiTarget = _this2._findLiTarget(e.target), - _this2$_findLiTarget2 = _slicedToArray(_this2$_findLiTarget, 2), - li = _this2$_findLiTarget2[0], - index = _this2$_findLiTarget2[1]; - - if (e.movementY !== 0) { - _this2.events.setActiveLi(index); - } - }); - - if (_this2.menuSelected === index) { - li.classList.add(_this2.current.collection.selectClass); - } - - li.innerHTML = _this2.current.collection.menuItemTemplate(item); - fragment.appendChild(li); - }); - ul.appendChild(fragment); - }; - - if (typeof this.current.collection.values === "function") { - if (this.current.collection.loadingItemTemplate) { - this.menu.querySelector("ul").innerHTML = this.current.collection.loadingItemTemplate; - this.range.positionMenuAtCaret(scrollTo); - } - - this.current.collection.values(this.current.mentionText, processValues); - } else { - processValues(this.current.collection.values); - } - } - }, { - key: "_findLiTarget", - value: function _findLiTarget(el) { - if (!el) return []; - var index = el.getAttribute("data-index"); - return !index ? this._findLiTarget(el.parentNode) : [el, index]; - } - }, { - key: "showMenuForCollection", - value: function showMenuForCollection(element, collectionIndex) { - if (element !== document.activeElement) { - this.placeCaretAtEnd(element); - } - - this.current.collection = this.collection[collectionIndex || 0]; - this.current.externalTrigger = true; - this.current.element = element; - if (element.isContentEditable) this.insertTextAtCursor(this.current.collection.trigger);else this.insertAtCaret(element, this.current.collection.trigger); - this.showMenuFor(element); - } // TODO: make sure this works for inputs/textareas - - }, { - key: "placeCaretAtEnd", - value: function placeCaretAtEnd(el) { - el.focus(); - - if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") { - var range = document.createRange(); - range.selectNodeContents(el); - range.collapse(false); - var sel = window.getSelection(); - sel.removeAllRanges(); - sel.addRange(range); - } else if (typeof document.body.createTextRange != "undefined") { - var textRange = document.body.createTextRange(); - textRange.moveToElementText(el); - textRange.collapse(false); - textRange.select(); - } - } // for contenteditable - - }, { - key: "insertTextAtCursor", - value: function insertTextAtCursor(text) { - var sel, range; - sel = window.getSelection(); - range = sel.getRangeAt(0); - range.deleteContents(); - var textNode = document.createTextNode(text); - range.insertNode(textNode); - range.selectNodeContents(textNode); - range.collapse(false); - sel.removeAllRanges(); - sel.addRange(range); - } // for regular inputs - - }, { - key: "insertAtCaret", - value: function insertAtCaret(textarea, text) { - var scrollPos = textarea.scrollTop; - var caretPos = textarea.selectionStart; - var front = textarea.value.substring(0, caretPos); - var back = textarea.value.substring(textarea.selectionEnd, textarea.value.length); - textarea.value = front + text + back; - caretPos = caretPos + text.length; - textarea.selectionStart = caretPos; - textarea.selectionEnd = caretPos; - textarea.focus(); - textarea.scrollTop = scrollPos; - } - }, { - key: "hideMenu", - value: function hideMenu() { - if (this.menu) { - this.menu.style.cssText = "display: none;"; - this.isActive = false; - this.menuSelected = 0; - this.current = {}; - } - } - }, { - key: "selectItemAtIndex", - value: function selectItemAtIndex(index, originalEvent) { - index = parseInt(index); - if (typeof index !== "number" || isNaN(index)) return; - var item = this.current.filteredItems[index]; - var content = this.current.collection.selectTemplate(item); - if (content !== null) this.replaceText(content, originalEvent, item); - } - }, { - key: "replaceText", - value: function replaceText(content, originalEvent, item) { - this.range.replaceTriggerText(content, true, true, originalEvent, item); - } - }, { - key: "_append", - value: function _append(collection, newValues, replace) { - if (typeof collection.values === "function") { - throw new Error("Unable to append to values, as it is a function."); - } else if (!replace) { - collection.values = collection.values.concat(newValues); - } else { - collection.values = newValues; - } - } - }, { - key: "append", - value: function append(collectionIndex, newValues, replace) { - var index = parseInt(collectionIndex); - if (typeof index !== "number") throw new Error("please provide an index for the collection to update."); - var collection = this.collection[index]; - - this._append(collection, newValues, replace); - } - }, { - key: "appendCurrent", - value: function appendCurrent(newValues, replace) { - if (this.isActive) { - this._append(this.current.collection, newValues, replace); - } else { - throw new Error("No active state. Please use append instead and pass an index."); - } - } - }, { - key: "detach", - value: function detach(el) { - if (!el) { - throw new Error("[Tribute] Must pass in a DOM node or NodeList."); - } // Check if it is a jQuery collection - - - if (typeof jQuery !== "undefined" && el instanceof jQuery) { - el = el.get(); - } // Is el an Array/Array-like object? - - - if (el.constructor === NodeList || el.constructor === HTMLCollection || el.constructor === Array) { - var length = el.length; - - for (var i = 0; i < length; ++i) { - this._detach(el[i]); - } - } else { - this._detach(el); - } - } - }, { - key: "_detach", - value: function _detach(el) { - var _this3 = this; - - this.events.unbind(el); - - if (el.tributeMenu) { - this.menuEvents.unbind(el.tributeMenu); - } - - setTimeout(function () { - el.removeAttribute("data-tribute"); - _this3.isActive = false; - - if (el.tributeMenu) { - el.tributeMenu.remove(); - } - }); - } - }, { - key: "isActive", - get: function get() { - return this._isActive; - }, - set: function set(val) { - if (this._isActive != val) { - this._isActive = val; - - if (this.current.element) { - var noMatchEvent = new CustomEvent("tribute-active-".concat(val)); - this.current.element.dispatchEvent(noMatchEvent); - } - } - } - }], [{ - key: "defaultSelectTemplate", - value: function defaultSelectTemplate(item) { - if (typeof item === "undefined") return "".concat(this.current.collection.trigger).concat(this.current.mentionText); - - if (this.range.isContentEditable(this.current.element)) { - return '' + (this.current.collection.trigger + item.original[this.current.collection.fillAttr]) + ""; - } - - return this.current.collection.trigger + item.original[this.current.collection.fillAttr]; - } - }, { - key: "defaultMenuItemTemplate", - value: function defaultMenuItemTemplate(matchItem) { - return matchItem.string; - } - }, { - key: "inputTypes", - value: function inputTypes() { - return ["TEXTAREA", "INPUT"]; - } - }]); - - return Tribute; - }(); - - /** - * Tribute.js - * Native ES6 JavaScript @mention Plugin - **/ - - return Tribute; - -}))); diff --git a/phpBB/assets/javascript/tribute.min.js b/phpBB/assets/javascript/tribute.min.js new file mode 100644 index 0000000000..4d11a82932 --- /dev/null +++ b/phpBB/assets/javascript/tribute.min.js @@ -0,0 +1,2 @@ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Tribute=t()}(this,(function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,i=new Array(t);n>>0,r=arguments[1],o=0;o container for the click");n.selectItemAtIndex(i.getAttribute("data-index"),t),n.hideMenu()}else n.current.element&&!n.current.externalTrigger&&(n.current.externalTrigger=!1,setTimeout((function(){return n.hideMenu()})))}},{key:"keyup",value:function(e,t){if(e.inputEvent&&(e.inputEvent=!1),e.updateSelection(this),27!==t.keyCode){if(!e.tribute.allowSpaces&&e.tribute.hasTrailingSpace)return e.tribute.hasTrailingSpace=!1,e.commandEvent=!0,void e.callbacks().space(t,this);if(!e.tribute.isActive)if(e.tribute.autocompleteMode)e.callbacks().triggerChar(t,this,"");else{var n=e.getKeyCode(e,this,t);if(isNaN(n)||!n)return;var i=e.tribute.triggers().find((function(e){return e.charCodeAt(0)===n}));void 0!==i&&e.callbacks().triggerChar(t,this,i)}e.tribute.current.mentionText.length=r.current.collection.menuShowMinLength&&r.inputEvent&&r.showMenuFor(n,!0)},enter:function(t,n){e.tribute.isActive&&e.tribute.current.filteredItems&&(t.preventDefault(),t.stopPropagation(),setTimeout((function(){e.tribute.selectItemAtIndex(e.tribute.menuSelected,t),e.tribute.hideMenu()}),0))},escape:function(t,n){e.tribute.isActive&&(t.preventDefault(),t.stopPropagation(),e.tribute.isActive=!1,e.tribute.hideMenu())},tab:function(t,n){e.callbacks().enter(t,n)},space:function(t,n){e.tribute.isActive&&(e.tribute.spaceSelectsMatch?e.callbacks().enter(t,n):e.tribute.allowSpaces||(t.stopPropagation(),setTimeout((function(){e.tribute.hideMenu(),e.tribute.isActive=!1}),0)))},up:function(t,n){if(e.tribute.isActive&&e.tribute.current.filteredItems){t.preventDefault(),t.stopPropagation();var i=e.tribute.current.filteredItems.length,r=e.tribute.menuSelected;i>r&&r>0?(e.tribute.menuSelected--,e.setActiveLi()):0===r&&(e.tribute.menuSelected=i-1,e.setActiveLi(),e.tribute.menu.scrollTop=e.tribute.menu.scrollHeight)}},down:function(t,n){if(e.tribute.isActive&&e.tribute.current.filteredItems){t.preventDefault(),t.stopPropagation();var i=e.tribute.current.filteredItems.length-1,r=e.tribute.menuSelected;i>r?(e.tribute.menuSelected++,e.setActiveLi()):i===r&&(e.tribute.menuSelected=0,e.setActiveLi(),e.tribute.menu.scrollTop=0)}},delete:function(t,n){e.tribute.isActive&&e.tribute.current.mentionText.length<1?e.tribute.hideMenu():e.tribute.isActive&&e.tribute.showMenuFor(n)}}}},{key:"setActiveLi",value:function(e){var t=this.tribute.menu.querySelectorAll("li"),n=t.length>>>0;e&&(this.tribute.menuSelected=parseInt(e));for(var i=0;iu.bottom){var l=o.bottom-u.bottom;this.tribute.menu.scrollTop+=l}else if(o.topi.width&&(r.left||r.right),u=window.innerHeight>i.height&&(r.top||r.bottom);(o||u)&&(n.tribute.menu.style.cssText="display: none",n.positionMenuAtCaret(e))}),0)}else this.tribute.menu.style.cssText="display: none"}},{key:"selectElement",value:function(e,t,n){var i,r=e;if(t)for(var o=0;o=0&&(t=i.substring(0,r))}}else{var o=this.tribute.current.element;if(o){var u=o.selectionStart;o.value&&u>=0&&(t=o.value.substring(0,u))}}return t}},{key:"getLastWordInText",value:function(e){var t;return e=e.replace(/\u00A0/g," "),(t=this.tribute.autocompleteSeparator?e.split(this.tribute.autocompleteSeparator):e.split(/\s+/))[t.length-1].trim()}},{key:"getTriggerInfo",value:function(e,t,n,i,r){var o,u,l,a=this,s=this.tribute.current;if(this.isContentEditable(s.element)){var c=this.getContentEditableSelectedPath(s);c&&(o=c.selected,u=c.path,l=c.offset)}else o=this.tribute.current.element;var h=this.getTextPrecedingCurrentSelection(),d=this.getLastWordInText(h);if(r)return{mentionPosition:h.length-d.length,mentionText:d,mentionSelectedElement:o,mentionSelectedPath:u,mentionSelectedOffset:l};if(null!=h){var f,m=-1;if(this.tribute.collection.forEach((function(e){var t=e.trigger,i=e.requireLeadingSpace?a.lastIndexWithLeadingSpace(h,t):h.lastIndexOf(t);i>m&&(m=i,f=t,n=e.requireLeadingSpace)})),m>=0&&(0===m||!n||/[\xA0\s]/g.test(h.substring(m-1,m)))){var p=h.substring(m+f.length,h.length);f=h.substring(m,m+f.length);var v=p.substring(0,1),g=p.length>0&&(" "===v||" "===v);t&&(p=p.trim());var b=i?/[^\S ]/g:/[\xA0\s]/g;if(this.tribute.hasTrailingSpace=b.test(p),!g&&(e||!b.test(p)))return{mentionPosition:m,mentionText:p,mentionSelectedElement:o,mentionSelectedPath:u,mentionSelectedOffset:l,mentionTriggerChar:f}}}}},{key:"lastIndexWithLeadingSpace",value:function(e,t){for(var n=e.split("").reverse().join(""),i=-1,r=0,o=e.length;r=0;s--)if(t[s]!==n[r-s]){a=!1;break}if(a&&(u||l)){i=e.length-1-r;break}}return i}},{key:"isContentEditable",value:function(e){return"INPUT"!==e.nodeName&&"TEXTAREA"!==e.nodeName}},{key:"isMenuOffScreen",value:function(e,t){var n=window.innerWidth,i=window.innerHeight,r=document.documentElement,o=(window.pageXOffset||r.scrollLeft)-(r.clientLeft||0),u=(window.pageYOffset||r.scrollTop)-(r.clientTop||0),l="number"==typeof e.top?e.top:u+i-e.bottom-t.height,a="number"==typeof e.right?e.right:e.left+t.width,s="number"==typeof e.bottom?e.bottom:e.top+t.height,c="number"==typeof e.left?e.left:o+n-e.right-t.width;return{top:lMath.ceil(o+n),bottom:s>Math.ceil(u+i),left:cparseInt(u.height)&&(o.overflowY="scroll")):o.overflow="hidden",r.textContent=e.value.substring(0,t),"INPUT"===e.nodeName&&(r.textContent=r.textContent.replace(/\s/g," "));var l=this.getDocument().createElement("span");l.textContent=e.value.substring(t)||".",r.appendChild(l);var a=e.getBoundingClientRect(),s=document.documentElement,c=(window.pageXOffset||s.scrollLeft)-(s.clientLeft||0),h=(window.pageYOffset||s.scrollTop)-(s.clientTop||0),d=0,f=0;this.menuContainerIsBody&&(d=a.top,f=a.left);var m={top:d+h+l.offsetTop+parseInt(u.borderTopWidth)+parseInt(u.fontSize)-e.scrollTop,left:f+c+l.offsetLeft+parseInt(u.borderLeftWidth)},p=window.innerWidth,v=window.innerHeight,g=this.getMenuDimensions(),b=this.isMenuOffScreen(m,g);b.right&&(m.right=p-m.left,m.left="auto");var y=this.tribute.menuContainer?this.tribute.menuContainer.offsetHeight:this.getDocument().body.offsetHeight;if(b.bottom){var w=y-(v-(this.tribute.menuContainer?this.tribute.menuContainer.getBoundingClientRect():this.getDocument().body.getBoundingClientRect()).top);m.bottom=w+(v-a.top-l.offsetTop),m.top="auto"}return(b=this.isMenuOffScreen(m,g)).left&&(m.left=p>g.width?c+p-g.width:c,delete m.right),b.top&&(m.top=v>g.height?h+v-g.height:h,delete m.bottom),this.getDocument().body.removeChild(r),m}},{key:"getContentEditableCaretPosition",value:function(e){var t,n=this.getWindowSelection();(t=this.getDocument().createRange()).setStart(n.anchorNode,e),t.setEnd(n.anchorNode,e),t.collapse(!1);var i=t.getBoundingClientRect(),r=document.documentElement,o=(window.pageXOffset||r.scrollLeft)-(r.clientLeft||0),u=(window.pageYOffset||r.scrollTop)-(r.clientTop||0),l={left:i.left+o,top:i.top+i.height+u},a=window.innerWidth,s=window.innerHeight,c=this.getMenuDimensions(),h=this.isMenuOffScreen(l,c);h.right&&(l.left="auto",l.right=a-i.left-o);var d=this.tribute.menuContainer?this.tribute.menuContainer.offsetHeight:this.getDocument().body.offsetHeight;if(h.bottom){var f=d-(s-(this.tribute.menuContainer?this.tribute.menuContainer.getBoundingClientRect():this.getDocument().body.getBoundingClientRect()).top);l.top="auto",l.bottom=f+(s-i.top)}return(h=this.isMenuOffScreen(l,c)).left&&(l.left=a>c.width?o+a-c.width:o,delete l.right),h.top&&(l.top=s>c.height?u+s-c.height:u,delete l.bottom),this.menuContainerIsBody||(l.left=l.left?l.left-this.tribute.menuContainer.offsetLeft:l.left,l.top=l.top?l.top-this.tribute.menuContainer.offsetTop:l.top),l}},{key:"scrollIntoView",value:function(e){var t,n=this.menu;if(void 0!==n){for(;void 0===t||0===t.height;)if(0===(t=n.getBoundingClientRect()).height&&(void 0===(n=n.childNodes[0])||!n.getBoundingClientRect))return;var i=t.top,r=i+t.height;if(i<0)window.scrollTo(0,window.pageYOffset+t.top-20);else if(r>window.innerHeight){var o=window.pageYOffset+t.top-20;o-window.pageYOffset>100&&(o=window.pageYOffset+100);var u=window.pageYOffset-(window.innerHeight-r);u>o&&(u=o),window.scrollTo(0,u)}}}},{key:"menuContainerIsBody",get:function(){return this.tribute.menuContainer===document.body||!this.tribute.menuContainer}}]),t}(),s=function(){function t(n){e(this,t),this.tribute=n,this.tribute.search=this}return n(t,[{key:"simpleFilter",value:function(e,t){var n=this;return t.filter((function(t){return n.test(e,t)}))}},{key:"test",value:function(e,t){return null!==this.match(e,t)}},{key:"match",value:function(e,t,n){n=n||{};t.length;var i=n.pre||"",r=n.post||"",o=n.caseSensitive&&t||t.toLowerCase();if(n.skip)return{rendered:t,score:0};e=n.caseSensitive&&e||e.toLowerCase();var u=this.traverse(o,e,0,0,[]);return u?{rendered:this.render(t,u.cache,i,r),score:u.score}:null}},{key:"traverse",value:function(e,t,n,i,r){if(this.tribute.autocompleteSeparator&&(t=t.split(this.tribute.autocompleteSeparator).splice(-1)[0]),t.length===i)return{score:this.calculateScore(r),cache:r.slice()};if(!(e.length===n||t.length-i>e.length-n)){for(var o,u,l=t[i],a=e.indexOf(l,n);a>-1;){if(r.push(a),u=this.traverse(e,t,a+1,i+1,r),r.pop(),!u)return o;(!o||o.score0&&(e[r-1]+1===i?n+=n+1:n=1),t+=n})),t}},{key:"render",value:function(e,t,n,i){var r=e.substring(0,t[0]);return t.forEach((function(o,u){r+=n+e[o]+i+e.substring(o+1,t[u+1]?t[u+1]:e.length)})),r}},{key:"filter",value:function(e,t,n){var i=this;return n=n||{},t.reduce((function(t,r,o,u){var l=r;n.extract&&((l=n.extract(r))||(l=""));var a=i.match(e,l,n);return null!=a&&(t[t.length]={string:a.rendered,score:a.score,index:o,original:r}),t}),[]).sort((function(e,t){var n=t.score-e.score;return n||e.index-t.index}))}}]),t}();return function(){function t(n){var i,r=this,o=n.values,c=void 0===o?null:o,h=n.loadingItemTemplate,d=void 0===h?null:h,f=n.iframe,m=void 0===f?null:f,p=n.selectClass,v=void 0===p?"highlight":p,g=n.containerClass,b=void 0===g?"tribute-container":g,y=n.itemClass,w=void 0===y?"":y,T=n.trigger,C=void 0===T?"@":T,S=n.autocompleteMode,E=void 0!==S&&S,k=n.autocompleteSeparator,x=void 0===k?null:k,M=n.selectTemplate,A=void 0===M?null:M,L=n.menuItemTemplate,I=void 0===L?null:L,N=n.lookup,O=void 0===N?"key":N,D=n.fillAttr,P=void 0===D?"value":D,R=n.collection,W=void 0===R?null:R,H=n.menuContainer,B=void 0===H?null:H,F=n.noMatchTemplate,_=void 0===F?null:F,j=n.requireLeadingSpace,Y=void 0===j||j,z=n.allowSpaces,K=void 0!==z&&z,q=n.replaceTextSuffix,U=void 0===q?null:q,X=n.positionMenu,Q=void 0===X||X,V=n.spaceSelectsMatch,$=void 0!==V&&V,G=n.searchOpts,J=void 0===G?{}:G,Z=n.menuItemLimit,ee=void 0===Z?null:Z,te=n.menuShowMinLength,ne=void 0===te?0:te;if(e(this,t),this.autocompleteMode=E,this.autocompleteSeparator=x,this.menuSelected=0,this.current={},this.inputEvent=!1,this.isActive=!1,this.menuContainer=B,this.allowSpaces=K,this.replaceTextSuffix=U,this.positionMenu=Q,this.hasTrailingSpace=!1,this.spaceSelectsMatch=$,this.autocompleteMode&&(C="",K=!1),c)this.collection=[{trigger:C,iframe:m,selectClass:v,containerClass:b,itemClass:w,selectTemplate:(A||t.defaultSelectTemplate).bind(this),menuItemTemplate:(I||t.defaultMenuItemTemplate).bind(this),noMatchTemplate:(i=_,"string"==typeof i?""===i.trim()?null:i:"function"==typeof i?i.bind(r):_||function(){return"
  • No Match Found!
  • "}.bind(r)),lookup:O,fillAttr:P,values:c,loadingItemTemplate:d,requireLeadingSpace:Y,searchOpts:J,menuItemLimit:ee,menuShowMinLength:ne}];else{if(!W)throw new Error("[Tribute] No collection specified.");this.autocompleteMode&&console.warn("Tribute in autocomplete mode does not work for collections"),this.collection=W.map((function(e){return{trigger:e.trigger||C,iframe:e.iframe||m,selectClass:e.selectClass||v,containerClass:e.containerClass||b,itemClass:e.itemClass||w,selectTemplate:(e.selectTemplate||t.defaultSelectTemplate).bind(r),menuItemTemplate:(e.menuItemTemplate||t.defaultMenuItemTemplate).bind(r),noMatchTemplate:function(e){return"string"==typeof e?""===e.trim()?null:e:"function"==typeof e?e.bind(r):_||function(){return"
  • No Match Found!
  • "}.bind(r)}(_),lookup:e.lookup||O,fillAttr:e.fillAttr||P,values:e.values,loadingItemTemplate:e.loadingItemTemplate,requireLeadingSpace:e.requireLeadingSpace,searchOpts:e.searchOpts||J,menuItemLimit:e.menuItemLimit||ee,menuShowMinLength:e.menuShowMinLength||ne}}))}new a(this),new u(this),new l(this),new s(this)}return n(t,[{key:"triggers",value:function(){return this.collection.map((function(e){return e.trigger}))}},{key:"attach",value:function(e){if(!e)throw new Error("[Tribute] Must pass in a DOM node or NodeList.");if("undefined"!=typeof jQuery&&e instanceof jQuery&&(e=e.get()),e.constructor===NodeList||e.constructor===HTMLCollection||e.constructor===Array)for(var t=e.length,n=0;n",post:n.current.collection.searchOpts.post||"
    ",skip:n.current.collection.searchOpts.skip,extract:function(e){if("string"==typeof n.current.collection.lookup)return e[n.current.collection.lookup];if("function"==typeof n.current.collection.lookup)return n.current.collection.lookup(e,n.current.mentionText);throw new Error("Invalid lookup attribute, lookup must be string or function.")}});n.current.collection.menuItemLimit&&(r=r.slice(0,n.current.collection.menuItemLimit)),n.current.filteredItems=r;var o=n.menu.querySelector("ul");if(n.range.positionMenuAtCaret(t),!r.length){var u=new CustomEvent("tribute-no-match",{detail:n.menu});return n.current.element.dispatchEvent(u),void("function"==typeof n.current.collection.noMatchTemplate&&!n.current.collection.noMatchTemplate()||!n.current.collection.noMatchTemplate?n.hideMenu():"function"==typeof n.current.collection.noMatchTemplate?o.innerHTML=n.current.collection.noMatchTemplate():o.innerHTML=n.current.collection.noMatchTemplate)}o.innerHTML="";var l=n.range.getDocument().createDocumentFragment();r.forEach((function(e,t){var r=n.range.getDocument().createElement("li");r.setAttribute("data-index",t),r.className=n.current.collection.itemClass,r.addEventListener("mousemove",(function(e){var t=i(n._findLiTarget(e.target),2),r=(t[0],t[1]);0!==e.movementY&&n.events.setActiveLi(r)})),n.menuSelected===t&&r.classList.add(n.current.collection.selectClass),r.innerHTML=n.current.collection.menuItemTemplate(e),l.appendChild(r)})),o.appendChild(l)}};"function"==typeof this.current.collection.values?(this.current.collection.loadingItemTemplate&&(this.menu.querySelector("ul").innerHTML=this.current.collection.loadingItemTemplate,this.range.positionMenuAtCaret(t)),this.current.collection.values(this.current.mentionText,r)):r(this.current.collection.values)}}},{key:"_findLiTarget",value:function(e){if(!e)return[];var t=e.getAttribute("data-index");return t?[e,t]:this._findLiTarget(e.parentNode)}},{key:"showMenuForCollection",value:function(e,t){e!==document.activeElement&&this.placeCaretAtEnd(e),this.current.collection=this.collection[t||0],this.current.externalTrigger=!0,this.current.element=e,e.isContentEditable?this.insertTextAtCursor(this.current.collection.trigger):this.insertAtCaret(e,this.current.collection.trigger),this.showMenuFor(e)}},{key:"placeCaretAtEnd",value:function(e){if(e.focus(),void 0!==window.getSelection&&void 0!==document.createRange){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();n.removeAllRanges(),n.addRange(t)}else if(void 0!==document.body.createTextRange){var i=document.body.createTextRange();i.moveToElementText(e),i.collapse(!1),i.select()}}},{key:"insertTextAtCursor",value:function(e){var t,n;(n=(t=window.getSelection()).getRangeAt(0)).deleteContents();var i=document.createTextNode(e);n.insertNode(i),n.selectNodeContents(i),n.collapse(!1),t.removeAllRanges(),t.addRange(n)}},{key:"insertAtCaret",value:function(e,t){var n=e.scrollTop,i=e.selectionStart,r=e.value.substring(0,i),o=e.value.substring(e.selectionEnd,e.value.length);e.value=r+t+o,i+=t.length,e.selectionStart=i,e.selectionEnd=i,e.focus(),e.scrollTop=n}},{key:"hideMenu",value:function(){this.menu&&(this.menu.style.cssText="display: none;",this.isActive=!1,this.menuSelected=0,this.current={})}},{key:"selectItemAtIndex",value:function(e,t){if("number"==typeof(e=parseInt(e))&&!isNaN(e)){var n=this.current.filteredItems[e],i=this.current.collection.selectTemplate(n);null!==i&&this.replaceText(i,t,n)}}},{key:"replaceText",value:function(e,t,n){this.range.replaceTriggerText(e,!0,!0,t,n)}},{key:"_append",value:function(e,t,n){if("function"==typeof e.values)throw new Error("Unable to append to values, as it is a function.");e.values=n?t:e.values.concat(t)}},{key:"append",value:function(e,t,n){var i=parseInt(e);if("number"!=typeof i)throw new Error("please provide an index for the collection to update.");var r=this.collection[i];this._append(r,t,n)}},{key:"appendCurrent",value:function(e,t){if(!this.isActive)throw new Error("No active state. Please use append instead and pass an index.");this._append(this.current.collection,e,t)}},{key:"detach",value:function(e){if(!e)throw new Error("[Tribute] Must pass in a DOM node or NodeList.");if("undefined"!=typeof jQuery&&e instanceof jQuery&&(e=e.get()),e.constructor===NodeList||e.constructor===HTMLCollection||e.constructor===Array)for(var t=e.length,n=0;n'+(this.current.collection.trigger+e.original[this.current.collection.fillAttr])+"":this.current.collection.trigger+e.original[this.current.collection.fillAttr]}},{key:"defaultMenuItemTemplate",value:function(e){return e.string}},{key:"inputTypes",value:function(){return["TEXTAREA","INPUT"]}}]),t}()})); +//# sourceMappingURL=tribute.min.js.map diff --git a/phpBB/styles/prosilver/template/posting_buttons.html b/phpBB/styles/prosilver/template/posting_buttons.html index a2e9920b9e..2a76bd272e 100644 --- a/phpBB/styles/prosilver/template/posting_buttons.html +++ b/phpBB/styles/prosilver/template/posting_buttons.html @@ -26,7 +26,7 @@ } - + diff --git a/phpBB/styles/prosilver/theme/bidi.css b/phpBB/styles/prosilver/theme/bidi.css index 7f9642b7cc..29fc0aac7c 100644 --- a/phpBB/styles/prosilver/theme/bidi.css +++ b/phpBB/styles/prosilver/theme/bidi.css @@ -374,7 +374,7 @@ /* Mention dropdown ---------------------------------------- */ -.rtl .atwho-view { /* mention-container */ +.rtl .mention-container { /* mention-container */ text-align: right; }