2011-07-28 00:59:48 +02:00
jQuery ( document ) . ready ( function ( ) {
$ . ajaxSetup ( {
cache : false
} ) ;
2011-06-30 08:15:06 +02:00
2011-11-24 08:11:13 +01:00
bindAutoCompletes ( ) ;
2011-11-26 19:27:44 +01:00
$ ( document ) . bind ( 'keydown' , 'ctrl+shift+f' , function ( ) {
$ ( '#localSeriesLookup' ) . focus ( ) ;
} ) ;
2011-11-24 08:11:13 +01:00
} ) ;
$ ( '.folderLookup:not(.ui-autocomplete-input), .seriesLookup:not(.ui-autocomplete-input), .localSeriesLookup:not(.ui-autocomplete-input)' ) . live ( 'focus' , function ( event ) {
bindAutoCompletes ( ) ;
} ) ;
function bindAutoCompletes ( ) {
2011-09-09 05:26:48 +02:00
bindFolderAutoComplete ( ".folderLookup" ) ;
bindSeriesAutoComplete ( ".seriesLookup" ) ;
2011-11-24 08:11:13 +01:00
}
2011-07-28 00:59:48 +02:00
function bindFolderAutoComplete ( selector ) {
$ ( selector ) . each ( function ( index , element ) {
2011-09-09 05:26:48 +02:00
$ ( element ) . autocomplete ( {
//source: "/Directory/GetDirectories",
source : function ( request , response ) {
$ . ajax ( {
url : "/Directory/GetDirectories" ,
dataType : "json" ,
data : {
term : request . term
} ,
success : function ( data ) {
var re = $ . ui . autocomplete . escapeRegex ( request . term ) ;
var matcher = new RegExp ( "^" + re , "i" ) ;
response ( $ . grep ( data , function ( item ) { return matcher . test ( item ) ; } ) ) ;
}
} ) ;
} ,
minLength : 3
2011-06-30 08:15:06 +02:00
} ) ;
2011-07-28 00:59:48 +02:00
} ) ;
}
function bindSeriesAutoComplete ( selector ) {
$ ( selector ) . each ( function ( index , element ) {
2011-09-09 05:26:48 +02:00
$ ( element ) . autocomplete ( {
source : "/AddSeries/LookupSeries" ,
minLength : 3 ,
delay : 500 ,
select : function ( event , ui ) {
$ ( this ) . val ( ui . item . Title ) ;
2011-09-09 05:52:25 +02:00
$ ( this ) . siblings ( '.seriesId' ) . val ( ui . item . Id ) ;
2011-09-09 05:26:48 +02:00
return false ;
2012-02-25 08:42:30 +01:00
} ,
open : function ( event , ui ) {
$ ( '.ui-autocomplete' ) . addClass ( 'seriesLookupResults' ) ;
} ,
close : function ( event , ui ) {
$ ( '.ui-autocomplete' ) . removeClass ( 'seriesLookupResults' ) ;
2011-09-09 05:26:48 +02:00
}
2012-02-25 08:42:30 +01:00
2011-09-09 05:26:48 +02:00
} )
. data ( "autocomplete" ) . _renderItem = function ( ul , item ) {
return $ ( "<li></li>" )
. data ( "item.autocomplete" , item )
2012-03-03 20:37:03 +01:00
. append ( "<a>" + item . DisplayedTitle + "<img src='../../Content/Images/thetvdb.png' class='tvDbLink' title='Click to see series details from TheTVDB' rel='" + item . Url + "' /></a>" )
2011-09-09 05:26:48 +02:00
. appendTo ( ul ) ;
} ;
2011-07-28 00:59:48 +02:00
} ) ;
2011-10-21 01:36:47 +02:00
}