jQuery(function(a){var b={primaryStyles:["fontFamily","fontSize","fontWeight","fontVariant","fontStyle","paddingLeft","paddingTop","paddingBottom","paddingRight","marginLeft","marginTop","marginBottom","marginRight","borderLeftColor","borderTopColor","borderBottomColor","borderRightColor","borderLeftStyle","borderTopStyle","borderBottomStyle","borderRightStyle","borderLeftWidth","borderTopWidth","borderBottomWidth","borderRightWidth","line-height","outline","text-align"],specificStyle:{"word-wrap":"break-word","overflow-x":"hidden","overflow-y":"auto"},simulator:a('
').css({position:"absolute",top:0,left:0,visibility:"hidden"}).appendTo(document.body),toHtml:function(a){return a.replace(//g,">").replace(/\n/g,"
").split(" ").join(' ')},getCaretPosition:function(){var c=b,d=this,e=d[0],f=d.offset();if(a.browser.msie&&a.browser.version<=9){e.focus();var g=document.selection.createRange();return a("#hskeywords").val(e.scrollTop),{left:g.boundingLeft-f.left,top:parseInt(g.boundingTop)-f.top+e.scrollTop+document.documentElement.scrollTop+parseInt(d.getComputedStyle("fontSize"))}}c.simulator.empty(),a.each(c.primaryStyles,function(a,b){d.cloneStyle(c.simulator,b)}),c.simulator.css(a.extend({width:d.width(),height:d.height()},c.specificStyle));var h=d.val()||d.text(),i=d.getCursorPosition(),j=h.substring(0,i),k=h.substring(i),l=a('').html(c.toHtml(j)),m=a(''),n=a('').html(c.toHtml(k));c.simulator.append(l).append(m).append(n);var o=m.offset(),p=c.simulator.offset();return{top:o.top-p.top-e.scrollTop+(a.browser.mozilla?0:parseInt(d.getComputedStyle("fontSize"))),left:m[0].offsetLeft-c.simulator[0].offsetLeft-e.scrollLeft}}};a.fn.extend({setCursorPosition:function(b){return 0==this.length?this:a(this).setSelection(b,b)},setSelection:function(a,b){if(0==this.length)return this;if(input=this[0],input.createTextRange){var c=input.createTextRange();c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select()}else if(input.setSelectionRange)input.focus(),input.setSelectionRange(a,b);else{var d=this.get(0),c=document.createRange();c.collapse(!0),c.setStart(d.childNodes[0],a),c.setEnd(d.childNodes[0],b);var e=window.getSelection();e.removeAllRanges(),e.addRange(c)}return this},getComputedStyle:function(b){if(0!=this.length){var c=this[0],d=this.css(b);return d=d||(a.browser.msie?c.currentStyle[b]:document.defaultView.getComputedStyle(c,null)[b])}},cloneStyle:function(b,c){var d=this.getComputedStyle(c);d&&a(b).css(c,d)},cloneAllStyle:function(a){var c=this[0];for(var d in c.style){var e=c.style[d];"string"==typeof e||"number"==typeof e?this.cloneStyle(a,d):0/0}},getCursorPosition:function(){var a=input=this[0],b=input.value||input.innerText;this.data("lastCursorPosition")||this.data("lastCursorPosition",0);var c=this.data("lastCursorPosition");if(document.selection){input.focus();var d=document.selection.createRange(),e=document.selection.createRange().text.length;d.moveStart("character",-b.length),c=d.text.length-e}else{if(input.selectionStart||"0"==input.selectionStart)return input.selectionStart;if("undefined"!=typeof window.getSelection&&window.getSelection().rangeCount>0)try{var f=window.getSelection(),g=f.getRangeAt(0),h=g.cloneRange();h.selectNodeContents(a),h.setEnd(g.endContainer,g.endOffset),c=h.toString().length}catch(i){c=this.data("lastCursorPosition")}else if("undefined"!=typeof document.selection&&"Control"!=document.selection.type){var j=document.selection.createRange(),k=document.body.createTextRange();k.moveToElementText(a),k.setEndPoint("EndToEnd",j),c=k.text.length}}return this.data("lastCursorPosition",c),c},getCaretPosition:b.getCaretPosition})}),function(a,b,c){function g(b,c){this.element=b,this.$element=a(b),this.$itemList=a(g.MENU_TEMPLATE),this.options=a.extend({},f,c),this.reset(),this._defaults=f,this._name=e,this.expression=new RegExp("(^|\\b|\\s)"+this.options.token+"([\\w.]*)$"),this.cleanupHandle=null,this.init()}var d=function(a,b){a.text(b.val)},e="sew",f={token:"@",elementFactory:d,values:[],unique:!1,repeat:!0};g.MENU_TEMPLATE="",g.ITEM_TEMPLATE='',g.KEYS=[40,38,13,27,9],g.prototype.init=function(){this.options.values.length<1||this.$element.unbind().bind("keyup",a.proxy(this.onKeyUp,this)).bind("keydown",a.proxy(this.onKeyDown,this)).bind("focus",a.proxy(this.renderElements,this,this.options.values)).bind("blur",a.proxy(this.remove,this))},g.prototype.reset=function(){this.options.unique&&(this.options.values=g.getUniqueElements(this.options.values)),this.index=0,this.matched=!1,this.dontFilter=!1,this.lastFilter=c,this.filtered=this.options.values.slice(0)},g.prototype.next=function(){this.index=(this.index+1)%this.filtered.length,this.hightlightItem()},g.prototype.prev=function(){this.index=(this.index+this.filtered.length-1)%this.filtered.length,this.hightlightItem()},g.prototype.select=function(){this.replace(this.filtered[this.index].val),this.$element.trigger("mention-selected",this.filtered[this.index]),this.hideList()},g.prototype.remove=function(){this.$itemList.fadeOut("slow"),this.cleanupHandle=b.setTimeout(a.proxy(function(){this.$itemList.remove()},this),1e3)},g.prototype.replace=function(a){var b=this.$element.getCursorPosition(),c=this.getText(),d=c.substring(0,b);d=d.replace(this.expression,"$1"+this.options.token+a);var e=c.substring(b,c.length),f=e.match(/^\s/)?"":" ",g=d+f+e;this.setText(g),this.$element.setCursorPosition(d.length+1)},g.prototype.hightlightItem=function(){this.$itemList.find(".-sew-list-item").removeClass("selected");var a=this.$itemList.find(".-sew-list-item").parent(),b=this.filtered[this.index].element.addClass("selected"),c=b.position().top;a.scrollTop(a.scrollTop()+c)},g.prototype.renderElements=function(b){a("body").append(this.$itemList);var c=this.$itemList.find("ul").empty();b.forEach(a.proxy(function(b,d){var e=a(g.ITEM_TEMPLATE);this.options.elementFactory(e,b),b.element=e.appendTo(c).bind("click",a.proxy(this.onItemClick,this,b)).bind("mouseover",a.proxy(this.onItemHover,this,d))},this)),this.index=0,this.hightlightItem()},g.prototype.displayList=function(){if(this.filtered.length){this.$itemList.show();var a=this.$element,b=this.$element.offset(),c=a.getCaretPosition();this.$itemList.css({left:b.left+c.left,top:b.top+c.top})}},g.prototype.hideList=function(){this.$itemList.hide(),this.reset()},g.prototype.filterList=function(b){if(b!=this.lastFilter){this.lastFilter=b,this.$itemList.find(".-sew-list-item").remove();var c=this.options.values,d=this.filtered=c.filter(a.proxy(function(a){var c=new RegExp("\\W*"+this.options.token+a.val+"(\\W|$)");return!this.options.repeat&&this.getText().match(c)?!1:""===b||a.val.toLowerCase().indexOf(b.toLowerCase())>=0||(a.meta||"").toLowerCase().indexOf(b.toLowerCase())>=0},this));d.length?(this.renderElements(d),this.$itemList.show()):this.hideList()}},g.getUniqueElements=function(a){var b=[];return a.forEach(function(a){var c=b.map(function(a){return a.val}).indexOf(a.val)>=0;c||b.push(a)}),b},g.prototype.getText=function(){return this.$element.val()||this.$element.text()},g.prototype.setText=function(a){this.$element.is("input,textarea")?this.$element.val(a):this.$element.html(a)},g.prototype.onKeyUp=function(){var b=this.$element.getCursorPosition(),c=this.getText().substring(0,b),d=c.match(this.expression);return!d&&this.matched?(this.matched=!1,this.dontFilter=!1,this.hideList(),void 0):(d&&!this.matched&&(this.displayList(),this.lastFilter="\n",this.matched=!0),d&&!this.dontFilter&&this.filterList(d[2]),void 0)},g.prototype.onKeyDown=function(a){var b=this.$itemList.is(":visible");if(b&&!(g.KEYS.indexOf(a.keyCode)<0)){switch(a.keyCode){case 9:case 13:this.select();break;case 40:this.next();break;case 38:this.prev();break;case 27:this.$itemList.hide(),this.dontFilter=!0}a.preventDefault()}},g.prototype.onItemClick=function(a){this.cleanupHandle&&b.clearTimeout(this.cleanupHandle),this.replace(a.val),this.$element.trigger("mention-selected",this.filtered[this.index]),this.hideList()},g.prototype.onItemHover=function(a){this.index=a,this.hightlightItem()},a.fn.extend({sew:function(a){return this.each(function(){new g(this,a)})}})}(jQuery,window);