/* This includes 2 files: jquery.textcomplete.js, textcomplete.init.js */ !function(t){if("function"==typeof define&&define.amd)define(["jquery"],t);else if("object"==typeof module&&module.exports){var e=require("jquery");module.exports=t(e)}else t(jQuery)}(function(t){if(void 0===t)throw new Error("jQuery.textcomplete requires jQuery");var e,c,d,u;return function(s){"use strict";var r=1;s.fn.textcomplete=function(e,n){var o=Array.prototype.slice.call(arguments);return this.each(function(){var t=s(this),i=t.data("textComplete");if(i||((n=n||{})._oid=r++,i=new s.fn.textcomplete.Completer(this,n),t.data("textComplete",i)),"string"==typeof e){if(!i)return;o.shift(),i[e].apply(i,o),"destroy"===e&&t.removeData("textComplete")}else s.each(e,function(e){s.each(["header","footer","placement","maxCount"],function(t){e[t]&&(i.option[t]=e[t],function(t){console.warn&&console.warn(t)}(t+"as a strategy param is deprecated. Use option."),delete e[t])})}),i.register(s.fn.textcomplete.Strategy.parse(e,{el:this,$el:t}))})}}(t),function(a){"use strict";var n,o,s,r=0;function l(t,e){if(this.$el=a(t),this.id="textcomplete"+r++,this.strategies=[],this.views=[],this.option=a.extend({},l.defaults,e),!(this.$el.is("input[type=text]")||this.$el.is("input[type=search]")||this.$el.is("textarea")||t.isContentEditable||"true"==t.contentEditable))throw new Error("textcomplete must be called on a Textarea or a ContentEditable.");if(t===t.ownerDocument.activeElement)this.initialize();else{var i=this;this.$el.one("focus."+this.id,function(){i.initialize()}),this.option.adapter&&"CKEditor"!=this.option.adapter||"undefined"==typeof CKEDITOR||!this.$el.is("textarea")||CKEDITOR.on("instanceReady",function(e){e.editor.once("focus",function(t){i.$el=a(e.editor.editable().$),i.option.adapter||(i.option.adapter=a.fn.textcomplete.CKEditor,i.option.ckeditor_instance=e.editor),i.initialize()})})}}l.defaults={appendTo:"body",className:"",dropdownClassName:"dropdown-menu textcomplete-dropdown",maxCount:10,zIndex:"100",rightEdgeOffset:30},a.extend(l.prototype,{id:null,option:null,strategies:null,adapter:null,dropdown:null,$el:null,$iframe:null,initialize:function(){var t,e,i=this.$el.get(0);if(this.$el.prop("ownerDocument")!==document&&window.frames.length)for(var n=0;n").addClass(t.dropdownClassName).attr("id","textcomplete-dropdown-"+t._oid).css({display:"none",left:0,position:"absolute",zIndex:t.zIndex}).appendTo(e)}}),o.extend(l.prototype,{$el:null,$inputEl:null,completer:null,footer:null,header:null,id:null,maxCount:null,placement:"",shown:!1,data:[],className:"",destroy:function(){this.deactivate(),this.$el.off("."+this.id),this.$inputEl.off("."+this.id),this.clear(),this.$el.remove(),this.$el=this.$inputEl=this.completer=null,delete a[this.id]},render:function(t){var e=this._buildContents(t),i=o.map(t,function(t){return t.value});if(t.length){var n=t[0].strategy;n.id?this.$el.attr("data-strategy",n.id):this.$el.removeAttr("data-strategy"),this._renderHeader(i),this._renderFooter(i),e&&(this._renderContents(e),this._fitToBottom(),this._fitToRight(),this._activateIndexedItem()),this._setScroll()}else this.noResultsMessage?this._renderNoResultsMessage(i):this.shown&&this.deactivate()},setPosition:function(t){var e="absolute";return this.$inputEl.add(this.$inputEl.parents()).each(function(){return"absolute"!==o(this).css("position")&&("fixed"===o(this).css("position")?(t.top-=r.scrollTop(),t.left-=r.scrollLeft(),!(e="fixed")):void 0)}),this.$el.css(this._applyPlacement(t)),this.$el.css({position:e}),this},clear:function(){this.$el.html(""),this.data=[],this._index=0,this._$header=this._$footer=this._$noResultsMessage=null},activate:function(){return this.shown||(this.clear(),this.$el.show(),this.className&&this.$el.addClass(this.className),this.completer.fire("textComplete:show"),this.shown=!0),this},deactivate:function(){return this.shown&&(this.$el.hide(),this.className&&this.$el.removeClass(this.className),this.completer.fire("textComplete:hide"),this.shown=!1),this},isUp:function(t){return 38===t.keyCode||t.ctrlKey&&80===t.keyCode},isDown:function(t){return 40===t.keyCode||t.ctrlKey&&78===t.keyCode},isEnter:function(t){return!(t.ctrlKey||t.altKey||t.metaKey||t.shiftKey)&&(13===t.keyCode||9===t.keyCode||!0===this.option.completeOnSpace&&32===t.keyCode)},isPageup:function(t){return 33===t.keyCode},isPagedown:function(t){return 34===t.keyCode},isEscape:function(t){return 27===t.keyCode},_data:null,_index:null,_$header:null,_$noResultsMessage:null,_$footer:null,_bindEvents:function(){this.$el.on("mousedown."+this.id,".textcomplete-item",o.proxy(this._onClick,this)),this.$el.on("touchstart."+this.id,".textcomplete-item",o.proxy(this._onClick,this)),this.$el.on("mouseover."+this.id,".textcomplete-item",o.proxy(this._onMouseover,this)),this.$inputEl.on("keydown."+this.id,o.proxy(this._onKeydown,this))},_onClick:function(t){var e=o(t.target);t.preventDefault(),t.originalEvent.keepTextCompleteDropdown=this.id,e.hasClass("textcomplete-item")||(e=e.closest(".textcomplete-item"));var i=this.data[parseInt(e.data("index"),10)];this.completer.select(i.value,i.strategy,t);var n=this;setTimeout(function(){n.deactivate(),"touchstart"===t.type&&n.$inputEl.focus()},0)},_onMouseover:function(t){var e=o(t.target);t.preventDefault(),e.hasClass("textcomplete-item")||(e=e.closest(".textcomplete-item")),this._index=parseInt(e.data("index"),10),this._activateIndexedItem()},_onKeydown:function(t){var e;if(this.shown)switch(o.isFunction(this.option.onKeydown)&&(e=this.option.onKeydown(t,i)),null==e&&(e=this._defaultKeydown(t)),e){case i.KEY_UP:t.preventDefault(),this._up();break;case i.KEY_DOWN:t.preventDefault(),this._down();break;case i.KEY_ENTER:t.preventDefault(),this._enter(t);break;case i.KEY_PAGEUP:t.preventDefault(),this._pageup();break;case i.KEY_PAGEDOWN:t.preventDefault(),this._pagedown();break;case i.KEY_ESCAPE:t.preventDefault(),this.deactivate()}},_defaultKeydown:function(t){return this.isUp(t)?i.KEY_UP:this.isDown(t)?i.KEY_DOWN:this.isEnter(t)?i.KEY_ENTER:this.isPageup(t)?i.KEY_PAGEUP:this.isPagedown(t)?i.KEY_PAGEDOWN:this.isEscape(t)?i.KEY_ESCAPE:void 0},_up:function(){0===this._index?this._index=this.data.length-1:this._index-=1,this._activateIndexedItem(),this._setScroll()},_down:function(){this._index===this.data.length-1?this._index=0:this._index+=1,this._activateIndexedItem(),this._setScroll()},_enter:function(t){var e=this.data[parseInt(this._getActiveElement().data("index"),10)];this.completer.select(e.value,e.strategy,t),this.deactivate()},_pageup:function(){var e=0,i=this._getActiveElement().position().top-this.$el.innerHeight();this.$el.children().each(function(t){if(o(this).position().top+o(this).outerHeight()>i)return e=t,!1}),this._index=e,this._activateIndexedItem(),this._setScroll()},_pagedown:function(){var e=this.data.length-1,i=this._getActiveElement().position().top+this.$el.innerHeight();this.$el.children().each(function(t){if(o(this).position().top>i)return e=t,!1}),this._index=e,this._activateIndexedItem(),this._setScroll()},_activateIndexedItem:function(){this.$el.find(".textcomplete-item.active").removeClass("active"),this._getActiveElement().addClass("active")},_getActiveElement:function(){return this.$el.children(".textcomplete-item:nth("+this._index+")")},_setScroll:function(){var t=this._getActiveElement(),e=t.position().top,i=t.outerHeight(),n=this.$el.innerHeight(),o=this.$el.scrollTop();0===this._index||this._index==this.data.length-1||e<0?this.$el.scrollTop(e+o):n',o+=e.strategy.template(e.value,e.term),o+="");return o},_renderHeader:function(t){if(this.header){this._$header||(this._$header=o('
  • ').prependTo(this.$el));var e=o.isFunction(this.header)?this.header(t):this.header;this._$header.html(e)}},_renderFooter:function(t){if(this.footer){this._$footer||(this._$footer=o('').appendTo(this.$el));var e=o.isFunction(this.footer)?this.footer(t):this.footer;this._$footer.html(e)}},_renderNoResultsMessage:function(t){if(this.noResultsMessage){this._$noResultsMessage||(this._$noResultsMessage=o('
  • ').appendTo(this.$el));var e=o.isFunction(this.noResultsMessage)?this.noResultsMessage(t):this.noResultsMessage;this._$noResultsMessage.html(e)}},_renderContents:function(t){this._$footer?this._$footer.before(t):this.$el.append(t)},_fitToBottom:function(){var t=r.scrollTop()+r.height(),e=this.$el.height();this.$el.position().top+e>t&&(this.completer.$iframe||this.$el.offset({top:t-e}))},_fitToRight:function(){for(var t,e=this.option.rightEdgeOffset,i=this.$el.offset().left,n=this.$el.width(),o=r.width()-e;o吶").css({position:"absolute",top:-9999,left:-9999}).insertBefore(t)}l.extend(t.prototype,l.fn.textcomplete.Textarea.prototype,{select:function(t,e,i){var n,o=this.getTextFromHeadToCaret(),s=this.el.value.substring(o.length),r=e.replace(t,i);if(void 0!==r){l.isArray(r)&&(s=r[1]+s,r=r[0]),n=l.isFunction(e.match)?e.match(o):e.match,o=o.replace(n,r),this.$el.val(o+s),this.el.focus();var a=this.el.createTextRange();a.collapse(!0),a.moveEnd("character",o.length),a.moveStart("character",o.length),a.select()}},getTextFromHeadToCaret:function(){this.el.focus();var t=document.selection.createRange();t.moveStart("character",-this.el.value.length);var e=t.text.split("吶");return 1===e.length?e[0]:e[1]}}),l.fn.textcomplete.IETextarea=t}(t),function(m){"use strict";function t(t,e,i){this.initialize(t,e,i)}m.extend(t.prototype,m.fn.textcomplete.Adapter.prototype,{select:function(t,e,i){var n=this.getTextFromHeadToCaret(),o=this.el.ownerDocument.getSelection(),s=o.getRangeAt(0),r=s.cloneRange();r.selectNodeContents(s.startContainer);var a,l=r.toString().substring(s.startOffset),h=e.replace(t,i);if(void 0!==h){m.isArray(h)&&(l=h[1]+l,h=h[0]),a=m.isFunction(e.match)?e.match(n):e.match,n=n.replace(a,h).replace(/ $/," "),s.selectNodeContents(s.startContainer),s.deleteContents();var c=this.el.ownerDocument.createElement("div");c.innerHTML=n;var d=this.el.ownerDocument.createElement("div");d.innerHTML=l;for(var u,p,f=this.el.ownerDocument.createDocumentFragment();u=c.firstChild;)p=f.appendChild(u);for(;u=d.firstChild;)f.appendChild(u);s.insertNode(f),s.setStartAfter(p),s.collapse(!0),o.removeAllRanges(),o.addRange(s)}},_getCaretRelativePosition:function(){var t=this.el.ownerDocument.getSelection().getRangeAt(0).cloneRange(),e=this.el.ownerDocument.createElement("span");t.insertNode(e),t.selectNodeContents(e),t.deleteContents();var i=m(e),n=i.offset();if(n.left-=this.$el.offset().left,n.top+=i.height()-this.$el.offset().top,n.lineHeight=i.height(),this.completer.$iframe){var o=this.completer.$iframe.offset();n.top+=o.top,n.left+=o.left,n.top-=this.$el.scrollTop()}return i.remove(),n},getTextFromHeadToCaret:function(){var t=this.el.ownerDocument.getSelection().getRangeAt(0),e=t.cloneRange();return e.selectNodeContents(t.startContainer),e.toString().substring(0,t.startOffset)}}),m.fn.textcomplete.ContentEditable=t}(t),function(t){"use strict";function e(t,e,i){this.initialize(t,e,i)}t.extend(e.prototype,t.fn.textcomplete.ContentEditable.prototype,{_bindEvents:function(){var i=this;this.option.ckeditor_instance.on("key",function(t){var e=t.data;if(i._onKeyup(e),i.completer.dropdown.shown&&i._skipSearch(e))return!1},null,null,1),this.$el.on("keyup."+this.id,t.proxy(this._onKeyup,this))}}),t.fn.textcomplete.CKEditor=e}(t),e=t,c=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"],d="undefined"!=typeof window,u=d&&null!=window.mozInnerScreenX,e.fn.textcomplete.getCaretCoordinates=function(t,e,i){if(!d)throw new Error("textarea-caret-position#getCaretCoordinates should only be called in a browser");var n=i&&i.debug||!1;if(n){var o=document.querySelector("#input-textarea-caret-position-mirror-div");o&&o.parentNode.removeChild(o)}var s=document.createElement("div");s.id="input-textarea-caret-position-mirror-div",document.body.appendChild(s);var r=s.style,a=window.getComputedStyle?getComputedStyle(t):t.currentStyle;r.whiteSpace="pre-wrap","INPUT"!==t.nodeName&&(r.wordWrap="break-word"),r.position="absolute",n||(r.visibility="hidden"),c.forEach(function(t){r[t]=a[t]}),u?t.scrollHeight>parseInt(a.height)&&(r.overflowY="scroll"):r.overflow="hidden",s.textContent=t.value.substring(0,e),"INPUT"===t.nodeName&&(s.textContent=s.textContent.replace(/\s/g," "));var l=document.createElement("span");l.textContent=t.value.substring(e)||".",s.appendChild(l);var h={top:l.offsetTop+parseInt(a.borderTopWidth),left:l.offsetLeft+parseInt(a.borderLeftWidth)};return n?l.style.backgroundColor="#aaa":document.body.removeChild(s),h},t}),window.init_autocomplete_usernames=function(){var s=[];jQuery(".user.login, option[data-login]").each(function(){var t="OPTION"==jQuery(this).prop("tagName")?jQuery(this).data("login"):jQuery(this).text();""!=t&&-1==s.indexOf(t)&&("@"==t[0]&&(t=t.substr(1)),s.push(t))}),jQuery("textarea.autocomplete_usernames").textcomplete([{match:/\B@(\w+)$/,search:function(n,o){n.length<4?o(jQuery.map(s,function(t){return 0===t.indexOf(n)?t:null})):jQuery.ajax({type:"GET",dataType:"JSON",url:restapi_url+"users/autocomplete",data:{q:n,mentioned:s,blog:"undefined"==typeof blog?0:blog},success:function(t){if(void 0===t.users)return null;var e=[];for(var i in t.users)e.push(t.users[i].login);e=e.concat(s),o(jQuery.map(e,function(t){return 0===t.indexOf(n)?t:null}))}})},index:1,replace:function(t){return"@"+t+" "},cache:!0}])},jQuery(document).ready(function(){var t=!1;if("undefined"!=typeof navigator&&void 0!==navigator.appVersion){var e=navigator.appVersion.match(/msie (\d+)/i);e&&(t=parseInt(e[1]))}t&&t<=9||init_autocomplete_usernames()});