$(function(){$.widget("primeui.puiinputtextarea",{options:{autoResize:false,autoComplete:false,maxlength:null,counter:null,counterTemplate:"{0}",minQueryLength:3,queryDelay:700},_create:function(){var a=this;
this.id=this.element.attr("id");
if(!this.id){this.id=this.element.uniqueId().attr("id")
}this.element.puiinputtext();
if(this.options.autoResize){this.options.rowsDefault=this.element.attr("rows");
this.options.colsDefault=this.element.attr("cols");
this.element.addClass("pui-inputtextarea-resizable");
this.element.keyup(function(){a._resize()
}).focus(function(){a._resize()
}).blur(function(){a._resize()
})
}if(this.options.maxlength){this.element.keyup(function(d){var c=a.element.val(),b=c.length;
if(b>a.options.maxlength){a.element.val(c.substr(0,a.options.maxlength))
}if(a.options.counter){a._updateCounter()
}})
}if(this.options.counter){this._updateCounter()
}if(this.options.autoComplete){this._initAutoComplete()
}},_updateCounter:function(){var d=this.element.val(),c=d.length;
if(this.options.counter){var b=this.options.maxlength-c,a=this.options.counterTemplate.replace("{0}",b);
this.options.counter.text(a)
}},_resize:function(){var d=0,a=this.element.val().split("\n");
for(var b=a.length-1;
b>=0;
--b){d+=Math.floor((a[b].length/this.options.colsDefault)+1)
}var c=(d>=this.options.rowsDefault)?(d+1):this.options.rowsDefault;
this.element.attr("rows",c)
},_initAutoComplete:function(){var b='<div id="'+this.id+'_panel" class="pui-autocomplete-panel ui-widget-content ui-corner-all ui-helper-hidden pui-shadow"></div>',c=this;
this.panel=$(b).appendTo(document.body);
this.element.keyup(function(g){var f=$.ui.keyCode;
switch(g.which){case f.UP:case f.LEFT:case f.DOWN:case f.RIGHT:case f.ENTER:case f.NUMPAD_ENTER:case f.TAB:case f.SPACE:case f.CONTROL:case f.ALT:case f.ESCAPE:case 224:break;
default:var d=c._extractQuery();
if(d&&d.length>=c.options.minQueryLength){if(c.timeout){c._clearTimeout(c.timeout)
}c.timeout=window.setTimeout(function(){c.search(d)
},c.options.queryDelay)
}break
}}).keydown(function(j){var d=c.panel.is(":visible"),i=$.ui.keyCode,h;
switch(j.which){case i.UP:case i.LEFT:if(d){h=c.items.filter(".ui-state-highlight");
var g=h.length===0?c.items.eq(0):h.prev();
if(g.length==1){h.removeClass("ui-state-highlight");
g.addClass("ui-state-highlight");
if(c.options.scrollHeight){PUI.scrollInView(c.panel,g)
}}j.preventDefault()
}else{c._clearTimeout()
}break;
case i.DOWN:case i.RIGHT:if(d){h=c.items.filter(".ui-state-highlight");
var f=h.length===0?_self.items.eq(0):h.next();
if(f.length==1){h.removeClass("ui-state-highlight");
f.addClass("ui-state-highlight");
if(c.options.scrollHeight){PUI.scrollInView(c.panel,f)
}}j.preventDefault()
}else{c._clearTimeout()
}break;
case i.ENTER:case i.NUMPAD_ENTER:if(d){c.items.filter(".ui-state-highlight").trigger("click");
j.preventDefault()
}else{c._clearTimeout()
}break;
case i.SPACE:case i.CONTROL:case i.ALT:case i.BACKSPACE:case i.ESCAPE:case 224:c._clearTimeout();
if(d){c._hide()
}break;
case i.TAB:c._clearTimeout();
if(d){c.items.filter(".ui-state-highlight").trigger("click");
c._hide()
}break
}});
$(document.body).bind("mousedown.puiinputtextarea",function(d){if(c.panel.is(":hidden")){return
}var f=c.panel.offset();
if(d.target===c.element.get(0)){return
}if(d.pageX<f.left||d.pageX>f.left+c.panel.width()||d.pageY<f.top||d.pageY>f.top+c.panel.height()){c._hide()
}});
var a="resize."+this.id;
$(window).unbind(a).bind(a,function(){if(c.panel.is(":visible")){c._hide()
}})
},_bindDynamicEvents:function(){var a=this;
this.items.bind("mouseover",function(){var b=$(this);
if(!b.hasClass("ui-state-highlight")){a.items.filter(".ui-state-highlight").removeClass("ui-state-highlight");
b.addClass("ui-state-highlight")
}}).bind("click",function(d){var c=$(this),e=c.attr("data-item-value"),b=e.substring(a.query.length);
a.element.focus();
a.element.insertText(b,a.element.getSelection().start,true);
a._hide();
a._trigger("itemselect",d,c)
})
},_clearTimeout:function(){if(this.timeout){window.clearTimeout(this.timeout)
}this.timeout=null
},_extractQuery:function(){var b=this.element.getSelection().end,a=/\S+$/.exec(this.element.get(0).value.slice(0,b)),c=a?a[0]:null;
return c
},search:function(b){this.query=b;
var a={query:b};
if(this.options.completeSource){this.options.completeSource.call(this,a,this._handleResponse)
}},_handleResponse:function(c){this.panel.html("");
var d=$('<ul class="pui-autocomplete-items pui-autocomplete-list ui-widget-content ui-widget ui-corner-all ui-helper-reset"></ul>');
for(var a=0;
a<c.length;
a++){var b=$('<li class="pui-autocomplete-item pui-autocomplete-list-item ui-corner-all"></li>');
b.attr("data-item-value",c[a].value);
b.text(c[a].label);
d.append(b)
}this.panel.append(d);
this.items=this.panel.find(".pui-autocomplete-item");
this._bindDynamicEvents();
if(this.items.length>0){this.items.eq(0).addClass("ui-state-highlight");
if(this.options.scrollHeight&&this.panel.height()>this.options.scrollHeight){this.panel.height(this.options.scrollHeight)
}if(this.panel.is(":hidden")){this._show()
}else{this._alignPanel()
}}else{this.panel.hide()
}},_alignPanel:function(){var b=this.element.getCaretPosition(),a=this.element.offset();
this.panel.css({left:a.left+b.left,top:a.top+b.top,width:this.element.innerWidth()})
},_show:function(){this._alignPanel();
this.panel.show()
},_hide:function(){this.panel.hide()
},disable:function(){this.element.puiinputtext("disable")
},enable:function(){this.element.puiinputtext("enable")
}})
});