14 lines
67 KiB
JavaScript
14 lines
67 KiB
JavaScript
|
/**
|
||
|
* Ajax Autocomplete for jQuery, version 1.1.3
|
||
|
* (c) 2010 Tomas Kirda
|
||
|
*
|
||
|
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
|
||
|
* For details, see the web site: http://www.devbridge.com/projects/autocomplete/jquery/
|
||
|
*
|
||
|
* Last Review: 04/19/2010
|
||
|
*/
|
||
|
/*jslint onevar: true, evil: true, nomen: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
|
||
|
/*global window: true, document: true, clearInterval: true, setInterval: true, jQuery: true */
|
||
|
(function($){function fnFormatResult(a,b,c){if(c==="and"||c==="&"||c==="n'")var d="(and|&|n')";else var d="("+c.replace(reEscape,"\\$1")+")";return a.replace(new RegExp(d,"gi"),"<strong>$1</strong>")}function Autocomplete(a,b){this.el=$(a),this.el.attr("autocomplete","off"),this.suggestions=[],this.data=[],this.badQueries=[],this.selectedIndex=-1,this.currentValue=this.el.val(),this.intervalId=0,this.cachedResponse=[],this.onChangeInterval=null,this.ignoreValueChange=!1,this.serviceUrl=b.serviceUrl,this.isLocal=!1,this.containerId=b.containerId,this.containerItemsId=b.containerItemsId,this.options={autoSubmit:!1,minChars:1,maxHeight:300,deferRequestBy:0,width:0,highlight:!0,params:{},fnFormatResult:fnFormatResult,delimiter:null,zIndex:9999},this.initialize(),this.setOptions(b)}var reEscape=new RegExp("(\\"+["/",".","*","+","?","|","(",")","[","]","{","}","\\"].join("|\\")+")","g");$.fn.bh_autocomplete=function(a){return new Autocomplete(this.get(0)||$("<input />"),a)},Autocomplete.prototype={killerFn:null,initialize:function(){var a,b,c;a=this,b=Math.floor(Math.random()*1048576).toString(16),c="Autocomplete_"+b,this.killerFn=function(b){$(b.target).parents(".autocomplete").size()===0&&(a.killSuggestions(),a.disableKillerFn())},this.options.width||(this.options.width=this.el.width()),this.mainContainerId="AutocompleteContainter_"+b,this.mainContainerId=this.containerId,this.container=$("#"+c),this.container_items=$("#"+this.containerItemsId),this.fixPosition(),window.opera?this.el.keypress(function(b){a.onKeyPress(b)}):this.el.keydown(function(b){a.onKeyPress(b)}),this.el.keyup(function(b){a.onKeyUp(b)}),this.el.blur(function(){a.enableKillerFn()}),this.el.focus(function(){a.fixPosition()})},setOptions:function(a){var b=this.options;$.extend(b,a),b.lookup&&(this.isLocal=!0,$.isArray(b.lookup)&&(b.lookup={suggestions:b.lookup,data:[]}))},clearCache:function(){this.cachedResponse=[],this.badQueries=[]},disable:function(){this.disabled=!0},enable:function(){this.disabled=!1},fixPosition:function(){var a=this.el.offset()},enableKillerFn:function(){var a=this;$(document).bind("click",a.killerFn)},disableKillerFn:function(){var a=this;$(document).unbind("click",a.killerFn)},killSuggestions:function(){var a=this;this.stopKillSuggestions(),this.intervalId=window.setInterval(function(){a.hide(),a.stopKillSuggestions()},300)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},onKeyPress:function(a){if(this.disabled||!this.enabled)return;switch(a.keyCode){case 27:this.el.val(this.currentValue),this.hide();break;case 9:case 13:if(this.selectedIndex===-1){this.hide();return}this.select(this.selectedIndex);if(a.keyCode===9)return;break;case 38:this.moveUp();break;case 40:this.moveDown();break;default:return}a.stopImmediatePropagation(),a.preventDefault()},onKeyUp:function(a){if(this.disabled)return;switch(a.keyCode){case 38:case 40:return}clearInterval(this.onChangeInterval);if(this.currentValue!==this.el.val())if(this.options.deferRequestBy>0){var b=this;this.onChangeInterval=setInterval(function(){b.onValueChange()},this.options.deferRequestBy)}else this.onValueChange()},onValueChange:function(){clearInterval(this.onChangeInterval),this.currentValue=this.el.val();var a=this.getQuery(this.currentValue);this.selectedIndex=-1;if(this.ignoreValueChange){this.ignoreValueChange=!1;return}a===""||a.length<this.options.minChars?this.hide():this.getSuggestions(a)},getQuery:function(a){var b,c;return b=this.options.delimiter,b?(c=a.split(b),$.trim(c[c.length-1])):$.trim(a)},getSuggestionsLocal:function(a){var b,c,d,e,f;c=this.options.lookup,d=c.suggestions.length,b={suggestions:[],data:[]},a=a.toLowerCase();for(f=0;f<d;f++)e=c.suggestions[f],e.toLowerCase().indexOf(a)===0&&(b.suggestions.push(e),b.data.push(c.data[f]));return b},getSuggestions:function(a){var b,c;b=this.isLocal?this.getSuggestionsLocal(a):this.cachedResponse[a],b&&$.isArray(b.suggestions)?(this.suggestions=b.suggestions,this.data=b.data,this.suggest()):this.isBadQuery(a)||(c=this,c.options.params.query=a,$("#artist-load-spinner").show(),$.get(this.serviceUr
|
||
|
this.css.jq.unmute.length&&(this.status.noVolume?(this.css.jq.mute.hide(),this.css.jq.unmute.hide()):a?(this.css.jq.mute.hide(),this.css.jq.unmute.show()):(this.css.jq.mute.show(),this.css.jq.unmute.hide()))},volume:function(b){b=this._limitValue(b,0,1),this.options.volume=b,this.html.used&&this._html_volume(b),this.flash.used&&this._flash_volume(b),!this.html.video.gate&&!this.html.audio.gate&&(this._updateVolume(b),this._trigger(a.jPlayer.event.volumechange))},volumeBar:function(a){if(this.css.jq.volumeBar.length){var b=this.css.jq.volumeBar.offset(),c=a.pageX-b.left,d=this.css.jq.volumeBar.width(),a=this.css.jq.volumeBar.height()-a.pageY+b.top,b=this.css.jq.volumeBar.height();this.options.verticalVolume?this.volume(a/b):this.volume(c/d)}this.options.muted&&this._muted(!1)},volumeBarValue:function(a){this.volumeBar(a)},_updateVolume:function(a){a===b&&(a=this.options.volume),a=this.options.muted?0:a,this.status.noVolume?(this.css.jq.volumeBar.length&&this.css.jq.volumeBar.hide(),this.css.jq.volumeBarValue.length&&this.css.jq.volumeBarValue.hide(),this.css.jq.volumeMax.length&&this.css.jq.volumeMax.hide()):(this.css.jq.volumeBar.length&&this.css.jq.volumeBar.show(),this.css.jq.volumeBarValue.length&&(this.css.jq.volumeBarValue.show(),this.css.jq.volumeBarValue[this.options.verticalVolume?"height":"width"](a*100+"%")),this.css.jq.volumeMax.length&&this.css.jq.volumeMax.show())},volumeMax:function(){this.volume(1),this.options.muted&&this._muted(!1)},_cssSelectorAncestor:function(b){var c=this;this.options.cssSelectorAncestor=b,this._removeUiClass(),this.ancestorJq=b?a(b):[],b&&this.ancestorJq.length!==1&&this._warning({type:a.jPlayer.warning.CSS_SELECTOR_COUNT,context:b,message:a.jPlayer.warningMsg.CSS_SELECTOR_COUNT+this.ancestorJq.length+" found for cssSelectorAncestor.",hint:a.jPlayer.warningHint.CSS_SELECTOR_COUNT}),this._addUiClass(),a.each(this.options.cssSelector,function(a,b){c._cssSelector(a,b)})},_cssSelector:function(b,c){var d=this;typeof c=="string"?a.jPlayer.prototype.options.cssSelector[b]?(this.css.jq[b]&&this.css.jq[b].length&&this.css.jq[b].unbind(".jPlayer"),this.options.cssSelector[b]=c,this.css.cs[b]=this.options.cssSelectorAncestor+" "+c,this.css.jq[b]=c?a(this.css.cs[b]):[],this.css.jq[b].length&&this.css.jq[b].bind("click.jPlayer",function(c){return d[b](c),a(this).blur(),!1}),c&&this.css.jq[b].length!==1&&this._warning({type:a.jPlayer.warning.CSS_SELECTOR_COUNT,context:this.css.cs[b],message:a.jPlayer.warningMsg.CSS_SELECTOR_COUNT+this.css.jq[b].length+" found for "+b+" method.",hint:a.jPlayer.warningHint.CSS_SELECTOR_COUNT})):this._warning({type:a.jPlayer.warning.CSS_SELECTOR_METHOD,context:b,message:a.jPlayer.warningMsg.CSS_SELECTOR_METHOD,hint:a.jPlayer.warningHint.CSS_SELECTOR_METHOD}):this._warning({type:a.jPlayer.warning.CSS_SELECTOR_STRING,context:c,message:a.jPlayer.warningMsg.CSS_SELECTOR_STRING,hint:a.jPlayer.warningHint.CSS_SELECTOR_STRING})},seekBar:function(a){if(this.css.jq.seekBar){var b=this.css.jq.seekBar.offset(),a=a.pageX-b.left,b=this.css.jq.seekBar.width();this.playHead(100*a/b)}},playBar:function(a){this.seekBar(a)},repeat:function(){this._loop(!0)},repeatOff:function(){this._loop(!1)},_loop:function(b){this.options.loop!==b&&(this.options.loop=b,this._updateButtons(),this._trigger(a.jPlayer.event.repeat))},currentTime:function(){},duration:function(){},gui:function(){},noSolution:function(){},option:function(c,d){var e=c;if(arguments.length===0)return a.extend(!0,{},this.options);if(typeof c=="string"){var g=c.split(".");if(d===b){for(var e=a.extend(!0,{},this.options),h=0;h<g.length;h++)if(e[g[h]]!==b)e=e[g[h]];else return this._warning({type:a.jPlayer.warning.OPTION_KEY,context:c,message:a.jPlayer.warningMsg.OPTION_KEY,hint:a.jPlayer.warningHint.OPTION_KEY}),b;return e}for(var h=e={},i=0;i<g.length;i++)i<g.length-1?(h[g[i]]={},h=h[g[i]]):h[g[i]]=d}return this._setOptions(e),this},_setOptions:function(b){var c=this;return a.each(b,function(a,b){c._setOption(a,b)}),this},_setOption:function(b,c){var d=this;switch(b){case"volume":this.volume(c);break;case"muted":this._muted
|
||
|
,function(){return $(this).hasClass("active")||($("#settings-tabs li").removeClass("active"),$(this).addClass("active"),$("#settings-forms > div").hide(),$("#settings-forms > ."+$(this).find("a").attr("data-tab")).show()),!1}),$(".lastfm-connect").live("click",function(){return window.lastfm_popup=window.open(_session.getUser().lastfm_login_url,"lastfm_popup","status=1,width=960,height=585"),setTimeout(_settings.updateLastfmLogin,100),!1}),$("#settings-forms form").live("submit",function(){var a;return a={},$(this).find("input, select").each(function(){if($(this).attr("name"))return $(this).attr("type")==="checkbox"?a[$(this).attr("name")]=$(this).attr("checked")==="checked":a[$(this).attr("name")]=$(this).val()}),_session.query("/user/update/",{params:a}),!1}),$('#settings-forms input[type$="submit"]').live("mouseup",function(){return $(this).parent().parent().parent().submit(),!1}),$('#settings-forms input[type$="checkbox"]').live("click",function(a){return sorry,!1})}.call(this),function(){window._beathaven=null,window._session=null,window._vkontakte=null,window._vk_music=null,window._ajax=null,window._player=null,window._search=null,window._page=null,window._settings=null,$(function(){var a,b;return a=document.location,(b=a.hostname)!=="beathaven.org"&&b!=="dev.beathaven.org"&&(a.href="http://beathaven.org/"+a.hash),window._beathaven=new BeatHaven,window._beathaven.init()}),window.BeatHaven=function(){function a(){}return a.prototype.last_height=!1,a.prototype.lang="ru",a.prototype.init=function(){return window._vkontakte=new Vkontakte(2335068),window._vkontakte.init(),window._vk_music=new VkontakteMusic,window._ajax=new Ajax,window._player=new Player,window._player.initJplayer(),window._search=new Search,window._page=new Page,window._settings=new Settings,this.setupAutocomplete(),!1},a.prototype.setupAutocomplete=function(){return $("#search").first().bh_autocomplete({serviceUrl:"/artist/autocomplete",minChars:3,delimiter:/(,|;)\s*/,maxHeight:400,width:415,zIndex:9999,deferRequestBy:500,containerId:"autocomplete-container",containerItemsId:"autocomplete-items",onSelect:function(){return _search.loadArtistData($("#search").val())}})},a.prototype.localizeHTML=function(a,b){return a==null&&(a=$("body")),b==null&&(b=_beathaven.lang),$(a).find("[data-ls]").each(function(){if(_locale[$(this).attr("data-ls")]!=null&&_locale[$(this).attr("data-ls")][b]!=null)return this.nodeName==="INPUT"?$(this).val(_locale[$(this).attr("data-ls")][b]):$(this).text(_locale[$(this).attr("data-ls")][b])}),a},a.prototype.ls=function(a,b){return b==null&&(b=_beathaven.lang),_locale[a]!=null&&_locale[a][b]!=null?_locale[a][b]:a},a}(),String.prototype.htmlsafe=function(){var a,b,c,d,e;b=[["\\","\\\\"],['"',"""],["<","<"],[">",">"]],c=this;for(d=0,e=b.length;d<e;d++)a=b[d],c=c.replace(a[0],a[1]);return c},String.prototype.trim=function(){var a;a=this;while(a.indexOf(" ")!==-1)a=a.replace(" "," ");return a.charAt(0)===" "&&(a=a.substring(1)),a.charAt(a.length-1)===" "&&(a=a.substring(0,a.length-1)),a}}.call(this)
|