(function($){var style=document.documentElement.style,hasTextOverflow=('textOverflow'in style||'OTextOverflow'in style),domSplit=function(root,maxIndex){var index=0,result=[],domSplitAux=function(nodes){var i=0,tmp;if(index>maxIndex){return;} for(i=0;ioriginalWidth){while(low',item:'

'},full:{hints:'

',item:''},customizeClass:''},isTracked:true},_requestCounter:0,_prevValue:undefined,_timeouts:{show:undefined,hide:undefined,get:undefined},_timestamp:undefined,_init:function(){this.$this=this.element;this.$animations=$();this._addObserver();dp.core.binder(this.targets=this._gather(),this.handlers=this._handlers(),this.eventNamespace);},_destroy:function(){dp.core.unbinder(this.targets,this.handlers,this.eventNamespace);clearTimeout(this._timeouts.show);clearTimeout(this._timeouts.hide);this.$animations.each(function(){$(this).stop();});this.targets.$holder.remove();this.targets=this.handlers=undefined;},_gather:function(){return{$window:$(window),$holder:$(this.options.templates[this.options.mode].hints).addClass(this.options.templates.customizeClass),$item:$(this.options.templates[this.options.mode].item),$sizeObject:this.options.mode==='simple'?this.$this.closest(this.options.sizeObject):this.$this,$target:this.$this}},_handlers:function(){var _this=this;return{window:{handler:function(){_this._position();},events:'_resize'},holder:{handler:function(e,data){_this._onHolderSelectByIndex(e,data);},events:'selectByIndex'},item:{handler:function(e,data){e.stopPropagation();_this._onEvent(e,data,'Item',this);},events:['select','click','mouseenter']},target:{handler:function(e,data){_this._onEvent(e,data,'Target',this);},events:['blur','keydown','keyup','change'],run:function(){var $target=$(this);$target.prop('autocomplete','off');_this._prevValue=$target.val();}}}},_position:function(){var offset=this.targets.$sizeObject.offset();var height=this.targets.$sizeObject.outerHeight();var width=this.targets.$sizeObject.outerWidth();var bordersWidth=parseInt(this.targets.$sizeObject.css('borderLeftWidth'))-parseInt(this.targets.$sizeObject.css('borderRightWidth'));this.targets.$holder.css({top:offset.top+height+this.options.shift.top,left:offset.left+this.options.shift.left,width:this.options.width?this.options.width:(width-bordersWidth+this.options.shift.width)});},_onEvent:function(e,data,target,element){var handler='_on'+target+dp.tools.capitalize(e.type);if(typeof this[handler]==='function'){return this[handler](e,data,element);}},_onTargetBlur:function(e,data,el){var _this=this;clearTimeout(this._timeouts.hide);this._timeouts.hide=setTimeout(function(){_this._hide();},this.options.delays.hide);},_onTargetChange:function(e){e.stopImmediatePropagation();},_getSelectValue:function($target){if(this.options.mode==='full'){return $target.closest('.d_item').find('.d_image').text();}else{return $target.text();}},_setTarget:function(text,notrigger){this.targets.$target.focus().val(text);this.targets.$target.trigger('set');},_onTargetKeydown:function(e){switch(e.keyCode){case 13:this._requestCounter++;var $selected=this.targets.$holder.find('.d_selected');this._hide();if($selected.length){this._setTarget(this._getSelectValue($selected));}else{var text=this.targets.$target.val();if(text){this._setTarget(this.targets.$target.val());}} break;case 27:this._hide();break;case 38:case 40:e.preventDefault();var selectedIdx=this.targets.$holder.find('.d_selected').index();var itemsLength=this.targets.$holder.find('> *').length;if(e.keyCode===38)selectedIdx--;if(e.keyCode===40)selectedIdx++;if(selectedIdx>=itemsLength)selectedIdx=0;if(selectedIdx<0)selectedIdx=itemsLength-1;this.targets.$holder.trigger('selectByIndex',selectedIdx);break;}},_onTargetKeyup:function(e,data,element){var value=element.value;if(value===this._prevValue||e.keyCode===13||e.keyCode===38||e.keyCode===40){return false;} this._prevValue=value;if(value.length===0){return this._hide();} this._fill(++this._requestCounter);},_onHolderSelectByIndex:function(e,idx){var $selected=this.targets.$holder.find('> *').eq(idx);var value;if($selected.length>0){$selected.trigger('select');if(this.options.mode==='full'){value=$selected.find('.d_image').text();}else{value=$selected.text();} this.targets.$target.val(value);}},_onItemSelect:function(e,data,element){this.targets.$holder.find('> *').removeClass('d_selected');$(element).addClass('d_selected');},_onItemClick:function(e,data,element){this._setTarget(this._getSelectValue($(element)),!this.options.clickSubmit);},_onItemMouseenter:function(e,data,element){$(element).trigger('select');},_fill:function(counter){var _this=this;clearTimeout(this._timeouts.get);this._timestamp=new Date().getTime();var data={url:this.options.url,type:this.options.method,data:{need_hints_for:this.targets.$target.val(),lang:dp.config.lang,mode:this.options.mode},success:function(data){if(data&&data.data){_this._response(data.data,counter);}else{$.error('jquery.depositSearchHintsSimple.js. Bad data: '+JSON.stringify(data||{}));}},error:function(jqXHR,textStatus,errorThrown){$.error('jquery.depositSearchHintsSimple.js. Cannot load hints items.',jqXHR,textStatus,errorThrown)}};dp.core.ajax(data);},_response:function(data,counter){var _this=this;var handler='_render'+this.options.mode.charAt(0).toUpperCase()+this.options.mode.slice(1);if(counter!==this._requestCounter){return false;} if(data&&(data.hints&&data.hints.length>0)||data.length>0){var timestampDiff=this.options.delays.show-(this._timestamp-new Date().getTime());if(this.targets.$target.is(':focus')){if(timestampDiff>0&×tampDiff'+data.prefix+'');$item.html(text).appendTo(this.targets.$holder);}},_renderFull:function(data){this._show();for(var i=0;i'+tr("Online files")+': '+data[i].onlinePhotos);$item.appendTo(this.targets.$holder);}},_show:function(){var _this=this;if(!this.targets.$holder.is(':visible')){this.targets.$holder.appendTo(document.body);this._position();this.targets.$holder.stop(true,true).fadeIn(this.options.animationSpeed.show,function(){if(!_this.targets.$holder.is(':visible')){_this._hide(0);}else{dp.loader.run($(this));}});} this.targets.$holder.empty();this._cropCachedThumbs();if(this.options.isTracked){var hint=this.targets.$target.val();if(hint){if(this.options.mode==='full'){dp.track.fire('search_hints_old',[hint,false]);}else{dp.track.fire('search_hints',[hint,false]);}}}},_hide:function(timeout){var _this=this;if(!this.targets||!this.targets.$holder.length){return;} this.$animations.extend(this.targets.$holder.stop(true,true).fadeOut(typeof timeout==='undefined'?this.options.animationSpeed.hide:timeout,function(){_this.targets.$holder.detach();_this.targets.$holder.find('> *').removeClass('d_selected');}));},_cropCachedThumbs:function(){var $images=this.targets.$holder.find('.d_item img');$images.each(function(){if(this.width===38&&this.height===38){return false;} var $image=$(this);$image.on('load',function(){var imageWidth=this.width;var imageHeight=this.height;if(imageWidth>imageHeight){$image.css({height:38,left:(-1*Math.round(imageWidth/2))+'px'});}else{$image.css({width:38,top:(-1*Math.round(imageHeight/2))+'px'});}});});$images.each(function(){if(this.complete){$(this).trigger('load');}});},_addObserver:function(){dp.observer.add(this.eventNamespace,'inlineViewItemLoaded',(function(){this.$this.blur();this._hide(0);}).bind(this));}});})(jQuery); ;